├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── styles.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── strings.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_info_black_24dp.xml
│ │ │ │ ├── main_background.xml
│ │ │ │ ├── rounded_background.xml
│ │ │ │ ├── ic_access_time_black_24dp.xml
│ │ │ │ ├── ic_notifications_black_24dp.xml
│ │ │ │ ├── ic_sync_black_24dp.xml
│ │ │ │ ├── ic_account_circle_black_36dp.xml
│ │ │ │ ├── ic_contacts_black_24dp.xml
│ │ │ │ ├── ic_sad.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── layout
│ │ │ │ ├── sms_category_layout.xml
│ │ │ │ ├── fragment_inbox.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── loader_layout.xml
│ │ │ │ └── single_sms_small_layout.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── lingaraj
│ │ │ │ └── hourglass
│ │ │ │ └── in
│ │ │ │ └── glass
│ │ │ │ ├── contracts
│ │ │ │ ├── BaseView.java
│ │ │ │ ├── HomeContracts.java
│ │ │ │ └── SMSDashboardContracts.java
│ │ │ │ ├── Constants.java
│ │ │ │ ├── injection
│ │ │ │ ├── ApplicationContext.java
│ │ │ │ ├── ActivityScope.java
│ │ │ │ ├── components
│ │ │ │ │ ├── AppComponent.java
│ │ │ │ │ ├── HomeActivityComponent.java
│ │ │ │ │ └── SMSDashboardComponent.java
│ │ │ │ └── modules
│ │ │ │ │ ├── HomeActivityModule.java
│ │ │ │ │ ├── SMSDashboardModule.java
│ │ │ │ │ └── AppModule.java
│ │ │ │ ├── database
│ │ │ │ └── BaseDatabase.java
│ │ │ │ ├── smshomescreen
│ │ │ │ ├── ShortMessage.java
│ │ │ │ ├── presenter
│ │ │ │ │ ├── HomeActivityPresenter.java
│ │ │ │ │ └── SMSDashBoardPresenter.java
│ │ │ │ ├── MessageDataModel.java
│ │ │ │ ├── adapters
│ │ │ │ │ └── InboxAdapter.java
│ │ │ │ ├── view
│ │ │ │ │ ├── HomeActivity.java
│ │ │ │ │ └── SMSDashboardFragment.java
│ │ │ │ └── tasks
│ │ │ │ │ └── ReadMobileSMSAsyncTask.java
│ │ │ │ ├── models
│ │ │ │ └── BaseAppSharedPreference.java
│ │ │ │ ├── GlassApp.java
│ │ │ │ └── recievers
│ │ │ │ └── SMSReceiver.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── lingaraj
│ │ │ └── hourglass
│ │ │ └── in
│ │ │ └── glass
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── lingaraj
│ │ └── hourglass
│ │ └── in
│ │ └── glass
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── glass.iml
├── .gitignore
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingarajsankaravelu/glass/master/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingarajsankaravelu/glass/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingarajsankaravelu/glass/master/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingarajsankaravelu/glass/master/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingarajsankaravelu/glass/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingarajsankaravelu/glass/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingarajsankaravelu/glass/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/contracts/BaseView.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.contracts;
2 |
3 | public interface BaseView {
4 | void showLoader();
5 | void showError();
6 | void showContent();
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/Constants.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass;
2 |
3 | public class Constants {
4 | public static final String BASE_URL = "http://yourbaseurl.com/";
5 | public static final String BASE_SHARED_PREF = "BASE_PREF";
6 | }
7 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/injection/ApplicationContext.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.injection;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 | import javax.inject.Qualifier;
6 |
7 | @Qualifier
8 | @Retention(RetentionPolicy.RUNTIME)
9 | public @interface ApplicationContext {
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/database/BaseDatabase.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.database;
2 |
3 | import com.raizlabs.android.dbflow.annotation.Database;
4 |
5 | @Database(name = BaseDatabase.NAME, version = BaseDatabase.VERSION)
6 | public class BaseDatabase {
7 |
8 | public static final String NAME = "Base";
9 | public static final int VERSION = 1;
10 |
11 |
12 |
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 15sp
4 | 16dp
5 | 16dp
6 | 16dp
7 | 16dp
8 | 14sp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_info_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/contracts/HomeContracts.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.contracts;
2 |
3 | public interface HomeContracts {
4 | interface View {
5 | void showLoading();
6 |
7 | void checkPermissions();
8 |
9 | void requestSMSAppPermissions();
10 |
11 | void permissionsGranted();
12 |
13 | void permissionsDenied();
14 |
15 | }
16 |
17 |
18 | interface Presenter {
19 |
20 | void handleInitialChecks();
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/main_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 | -
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/rounded_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
13 |
--------------------------------------------------------------------------------
/app/src/test/java/lingaraj/hourglass/in/glass/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test public void addition_isCorrect() {
14 | assertEquals(4, 2 + 2);
15 | }
16 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_access_time_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/injection/ActivityScope.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.injection;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 | import javax.inject.Scope;
6 |
7 | @Scope
8 | @Retention(RetentionPolicy.RUNTIME)
9 | public @interface ActivityScope {
10 | //provides runtime scope for any variable inside module. because you cannot combain scoped varaiable with unscoped
11 | // i.e @singleton cannot be combined with other things.
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_notifications_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_sync_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sms_category_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_account_circle_black_36dp.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/smshomescreen/ShortMessage.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.smshomescreen;
2 |
3 | public class ShortMessage {
4 | private String date;
5 | private String address;
6 | private String body;
7 |
8 |
9 | public ShortMessage(String date, String address, String body) {
10 | this.date = date;
11 | this.address = address;
12 | this.body = body;
13 | }
14 |
15 | public String getAddress() {
16 | return address;
17 | }
18 |
19 | public String getDate() {
20 | return date;
21 | }
22 |
23 |
24 | public String getBody() {
25 | return body;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/smshomescreen/presenter/HomeActivityPresenter.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.smshomescreen.presenter;
2 |
3 | import javax.inject.Inject;
4 | import lingaraj.hourglass.in.glass.contracts.HomeContracts;
5 |
6 | public class HomeActivityPresenter implements HomeContracts.Presenter {
7 |
8 | HomeContracts.View view;
9 |
10 | @Inject public HomeActivityPresenter(HomeContracts.View view){
11 | this.view = view;
12 | handleInitialChecks();
13 | }
14 |
15 | @Override public void handleInitialChecks() {
16 | view.showLoading();
17 | view.checkPermissions();
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_contacts_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #2196F3
4 | #1976D2
5 | #ff3f80
6 | #212121
7 | #ffffff
8 | #f5f5f5
9 | #eeeeee
10 | #dddddd
11 | #212121
12 | #757575
13 | #eeeeee
14 | #757575
15 | #eeeeee
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_inbox.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/injection/components/AppComponent.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.injection.components;
2 |
3 | import com.google.gson.Gson;
4 | import dagger.Component;
5 | import javax.inject.Singleton;
6 | import lingaraj.hourglass.in.glass.GlassApp;
7 | import lingaraj.hourglass.in.glass.injection.modules.AppModule;
8 | import lingaraj.hourglass.in.glass.models.BaseAppSharedPreference;
9 | import retrofit2.Retrofit;
10 |
11 | @Singleton @Component(modules = AppModule.class)
12 | public interface AppComponent {
13 | void inject(GlassApp app);
14 | GlassApp provideApp();
15 | BaseAppSharedPreference providesBaseSharedPreference();
16 | Retrofit providesRetrofit();
17 | Gson providesGson();
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Glass
3 | This is the preview of the full SMS. To read more click on the SMS.
4 | SENDER
5 | Retry
6 | Provide Permission
7 | Please provide requested permisions to view all your SMS here.
8 | Getting your SMS
9 | Error getting SMS from device
10 | No messages to show
11 | in last 1 hour
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/injection/components/HomeActivityComponent.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.injection.components;
2 |
3 | import dagger.Component;
4 | import lingaraj.hourglass.in.glass.contracts.HomeContracts;
5 | import lingaraj.hourglass.in.glass.injection.ActivityScope;
6 | import lingaraj.hourglass.in.glass.injection.modules.HomeActivityModule;
7 | import lingaraj.hourglass.in.glass.smshomescreen.presenter.HomeActivityPresenter;
8 | import lingaraj.hourglass.in.glass.smshomescreen.view.HomeActivity;
9 |
10 | @ActivityScope @Component(modules = HomeActivityModule.class)
11 | public interface HomeActivityComponent {
12 | HomeContracts.View view();
13 | HomeActivityPresenter presenter();
14 | void inject(HomeActivity activity);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/injection/modules/HomeActivityModule.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.injection.modules;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import lingaraj.hourglass.in.glass.contracts.HomeContracts;
6 | import lingaraj.hourglass.in.glass.smshomescreen.presenter.HomeActivityPresenter;
7 |
8 | @Module
9 | public class HomeActivityModule {
10 |
11 | HomeContracts.View view;
12 |
13 | public HomeActivityModule(HomeContracts.View view){
14 | this.view = view;
15 | }
16 |
17 | @Provides HomeContracts.View view(){
18 | return this.view;
19 | }
20 |
21 | @Provides HomeActivityPresenter presenter(HomeContracts.View view){
22 | return new HomeActivityPresenter(view);
23 |
24 | }
25 |
26 |
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/injection/modules/SMSDashboardModule.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.injection.modules;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import lingaraj.hourglass.in.glass.contracts.SMSDashboardContracts;
6 | import lingaraj.hourglass.in.glass.smshomescreen.presenter.SMSDashBoardPresenter;
7 |
8 | @Module
9 | public class SMSDashboardModule {
10 | public SMSDashboardContracts.View view;
11 |
12 | public SMSDashboardModule(SMSDashboardContracts.View view){
13 | this.view = view;
14 | }
15 |
16 | @Provides SMSDashboardContracts.View view(){
17 | return this.view;
18 | }
19 |
20 | @Provides SMSDashBoardPresenter presenter(SMSDashboardContracts.View view){
21 | return new SMSDashBoardPresenter(view);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/injection/components/SMSDashboardComponent.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.injection.components;
2 |
3 | import dagger.Component;
4 | import lingaraj.hourglass.in.glass.contracts.SMSDashboardContracts;
5 | import lingaraj.hourglass.in.glass.injection.ActivityScope;
6 | import lingaraj.hourglass.in.glass.injection.modules.SMSDashboardModule;
7 | import lingaraj.hourglass.in.glass.smshomescreen.presenter.SMSDashBoardPresenter;
8 | import lingaraj.hourglass.in.glass.smshomescreen.view.SMSDashboardFragment;
9 |
10 | @ActivityScope @Component (modules = SMSDashboardModule.class)
11 | public interface SMSDashboardComponent {
12 | SMSDashboardContracts.View view();
13 | SMSDashBoardPresenter presenter();
14 | void inject(SMSDashboardFragment fragment);
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/models/BaseAppSharedPreference.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.models;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import lingaraj.hourglass.in.glass.Constants;
6 |
7 | public class BaseAppSharedPreference {
8 |
9 | private SharedPreferences mSharedPreferences;
10 | final String TOKEN = "APITOKEN";
11 |
12 | public BaseAppSharedPreference(Context context) {
13 | this.mSharedPreferences = context.getSharedPreferences(Constants.BASE_SHARED_PREF,Context.MODE_PRIVATE) ;
14 | }
15 |
16 | public void setToken(String token){
17 | this.mSharedPreferences.edit().putString(TOKEN,token).apply();
18 | }
19 | public String getToken(){
20 | return this.mSharedPreferences.getString(TOKEN,"");
21 | }
22 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/lingaraj/hourglass/in/glass/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest {
18 | @Test public void useAppContext() {
19 | // Context of the app under test.
20 | Context appContext = InstrumentationRegistry.getTargetContext();
21 |
22 | assertEquals("lingaraj.hourglass.in.base", appContext.getPackageName());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_sad.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
12 |
13 |
16 |
17 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/contracts/SMSDashboardContracts.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.contracts;
2 |
3 | import android.support.annotation.Nullable;
4 | import java.util.ArrayList;
5 | import lingaraj.hourglass.in.glass.smshomescreen.MessageDataModel;
6 |
7 | public interface SMSDashboardContracts {
8 |
9 | interface View {
10 |
11 | void showLoader();
12 |
13 | void showError();
14 |
15 | void noMessagesToDisplay();
16 |
17 | void setMessages(ArrayList messages);
18 |
19 | void startFetchSMSAsyncTask(SMSDashboardContracts.Presenter.SmsContentProviderAccessCallbacks callbacks);
20 | }
21 |
22 | public interface Presenter {
23 |
24 | void getMessages();
25 |
26 | public interface SmsContentProviderAccessCallbacks {
27 | void onMessageRetrievalCompletion(@Nullable ArrayList messages);
28 | }
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/smshomescreen/MessageDataModel.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.smshomescreen;
2 |
3 | import android.support.annotation.Nullable;
4 | import java.io.Serializable;
5 |
6 | public class MessageDataModel implements Serializable {
7 | private boolean heading;
8 | @Nullable private String headingText;
9 | @Nullable private ShortMessage message;
10 |
11 |
12 | public MessageDataModel(@Nullable Boolean isHeading, @Nullable String headingText,@Nullable ShortMessage message) {
13 | this.heading = isHeading==null?false:isHeading;
14 | this.headingText = headingText;
15 | this.message = message;
16 | }
17 |
18 | public boolean isHeading() {
19 | return heading;
20 | }
21 |
22 | @Nullable public String getHeadingText() {
23 | return headingText;
24 | }
25 |
26 | @Nullable public ShortMessage getMessage() {
27 | return message;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/glass.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | /*/build/
3 |
4 | # Crashlytics configuations
5 | com_crashlytics_export_strings.xml
6 |
7 | # Local configuration file (sdk path, etc)
8 | local.properties
9 |
10 | # Gradle generated files
11 | .gradle/
12 |
13 | # Signing files
14 | .signing/
15 |
16 | # User-specific configurations
17 | .idea/libraries/
18 | .idea/workspace.xml
19 | .idea/tasks.xml
20 | .idea/.name
21 | .idea/compiler.xml
22 | .idea/copyright/profiles_settings.xml
23 | .idea/encodings.xml
24 | .idea/misc.xml
25 | .idea/modules.xml
26 | .idea/scopes/scope_settings.xml
27 | .idea/vcs.xml
28 | .idea/caches/
29 | .idea/codeStyles/
30 |
31 | # OS-specific files
32 | .DS_Store
33 | .DS_Store?
34 | ._*
35 | .Spotlight-V100
36 | .Trashes
37 | ehthumbs.db
38 | Thumbs.db
39 |
40 | app/.idea/workspace.xml
41 | build/intermediates/dex-cache/cache.xml
42 | build/android-profile/*
43 | build/generated/*
44 | build/intermediates/progurad-files/*
45 |
46 | /openCVLibrary310
47 | openCVLibrary310/build.gradle
48 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/smshomescreen/presenter/SMSDashBoardPresenter.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.smshomescreen.presenter;
2 |
3 | import android.support.annotation.Nullable;
4 | import java.util.ArrayList;
5 | import javax.inject.Inject;
6 | import lingaraj.hourglass.in.glass.contracts.SMSDashboardContracts;
7 | import lingaraj.hourglass.in.glass.smshomescreen.MessageDataModel;
8 |
9 | public class SMSDashBoardPresenter implements SMSDashboardContracts.Presenter,SMSDashboardContracts.Presenter.SmsContentProviderAccessCallbacks {
10 |
11 |
12 | SMSDashboardContracts.View view;
13 |
14 | @Inject
15 | public SMSDashBoardPresenter(SMSDashboardContracts.View view){
16 | this.view = view;
17 |
18 | }
19 |
20 | @Override
21 | public void onMessageRetrievalCompletion(@Nullable ArrayList messages) {
22 | if (messages==null){
23 | view.showError();
24 | }
25 | else {
26 | if (messages.size()==0){
27 | view.noMessagesToDisplay();
28 | }
29 | else {
30 | view.setMessages(messages);
31 | }
32 | }
33 | }
34 |
35 | @Override
36 | public void getMessages() {
37 | view.showLoader();
38 | view.startFetchSMSAsyncTask(this);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/GlassApp.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass;
2 |
3 | import android.app.Application;
4 | import android.content.ContentResolver;
5 | import android.content.Context;
6 | import android.net.ConnectivityManager;
7 | import lingaraj.hourglass.in.glass.injection.components.AppComponent;
8 | import lingaraj.hourglass.in.glass.injection.components.DaggerAppComponent;
9 | import lingaraj.hourglass.in.glass.injection.modules.AppModule;
10 |
11 | public class GlassApp extends Application {
12 |
13 | private ConnectivityManager mConnectivity;
14 | private ContentResolver contentResolver;
15 |
16 | public AppComponent getAppComponent() {
17 | return appComponent;
18 | }
19 |
20 | private AppComponent appComponent;
21 |
22 | @Override
23 | public void onCreate() {
24 | super.onCreate();
25 | appComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
26 | appComponent.inject(this);
27 | }
28 |
29 | public boolean isNetworkAvailable() {
30 | if (mConnectivity == null) {
31 | mConnectivity = ((ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE));
32 | return mConnectivity.getActiveNetworkInfo() != null && mConnectivity.getActiveNetworkInfo().isConnected();
33 | }
34 | else {
35 | return false;
36 | }
37 |
38 | }
39 |
40 | public ContentResolver getContentResolver(){
41 | if (this.contentResolver==null){
42 | this.contentResolver = this.getBaseContext().getContentResolver();
43 | }
44 | return contentResolver;
45 | }
46 |
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/loader_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
10 |
11 |
16 |
17 |
24 |
25 |
35 |
36 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/single_sms_small_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
10 |
11 |
17 |
18 |
28 |
29 |
40 |
41 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/injection/modules/AppModule.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.injection.modules;
2 |
3 | import com.google.gson.Gson;
4 | import dagger.Module;
5 | import dagger.Provides;
6 | import java.io.IOException;
7 | import java.util.concurrent.TimeUnit;
8 | import lingaraj.hourglass.in.glass.GlassApp;
9 | import lingaraj.hourglass.in.glass.BuildConfig;
10 | import lingaraj.hourglass.in.glass.Constants;
11 | import lingaraj.hourglass.in.glass.models.BaseAppSharedPreference;
12 | import okhttp3.Interceptor;
13 | import okhttp3.OkHttpClient;
14 | import okhttp3.Request;
15 | import okhttp3.Response;
16 | import okhttp3.logging.HttpLoggingInterceptor;
17 | import retrofit2.Retrofit;
18 | import retrofit2.converter.gson.GsonConverterFactory;
19 |
20 | @Module
21 | public class AppModule {
22 |
23 | GlassApp app;
24 | BaseAppSharedPreference baseSharedPreference;
25 | Gson gson;
26 |
27 | public AppModule(GlassApp glassApp){
28 | this.app = glassApp;
29 | this.baseSharedPreference = new BaseAppSharedPreference(this.app);
30 | this.gson = new Gson();
31 | }
32 |
33 | @Provides GlassApp provideApp(){
34 | return this.app;
35 | }
36 |
37 | @Provides BaseAppSharedPreference providesBaseSharedPreference(){
38 | return this.baseSharedPreference;
39 | }
40 |
41 | @Provides Retrofit providesRetrofit(final BaseAppSharedPreference sharedPreference){
42 | OkHttpClient.Builder okHttpClient = new OkHttpClient().newBuilder();
43 | okHttpClient.addInterceptor(new Interceptor() {
44 | @Override
45 | public Response intercept(Chain chain) throws IOException {
46 | Request original = chain.request();
47 | Request.Builder request_builder = original.newBuilder().addHeader("Authorization", "Bearer " +sharedPreference.getToken());
48 | Request request = request_builder.build();
49 | return chain.proceed(request);
50 | }
51 | })
52 | .connectTimeout(12, TimeUnit.SECONDS)
53 | .readTimeout(12,TimeUnit.SECONDS)
54 | .writeTimeout(12,TimeUnit.SECONDS)
55 | .addNetworkInterceptor(getLogInterceptor());
56 | //OkHttpClient okHttpClient = new OkHttpClient();
57 | return new Retrofit.Builder()
58 | .baseUrl(Constants.BASE_URL)
59 | .addConverterFactory(GsonConverterFactory.create())
60 | .client(okHttpClient.build()).build();
61 | }
62 |
63 | @Provides Gson providesGson(){
64 | return this.gson;
65 | }
66 |
67 |
68 | private HttpLoggingInterceptor getLogInterceptor(){
69 | HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
70 | if (BuildConfig.DEBUG){
71 | httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
72 | }
73 | else {
74 | httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.NONE);
75 |
76 | }
77 | return httpLoggingInterceptor;
78 |
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/smshomescreen/adapters/InboxAdapter.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.smshomescreen.adapters;
2 |
3 | import android.content.Context;
4 | import android.databinding.DataBindingUtil;
5 | import android.support.annotation.NonNull;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.LayoutInflater;
8 | import android.view.ViewGroup;
9 | import java.util.ArrayList;
10 | import lingaraj.hourglass.in.glass.R;
11 | import lingaraj.hourglass.in.glass.databinding.SingleSmsSmallLayoutBinding;
12 | import lingaraj.hourglass.in.glass.databinding.SmsCategoryLayoutBinding;
13 | import lingaraj.hourglass.in.glass.smshomescreen.MessageDataModel;
14 | import lingaraj.hourglass.in.glass.smshomescreen.ShortMessage;
15 |
16 | public class InboxAdapter extends RecyclerView.Adapter {
17 |
18 | private final int TYPE_SMS = 0;
19 | private final int TYPE_Heading = 1;
20 | private Context mContext;
21 | private ArrayList messages = new ArrayList<>();
22 |
23 | public InboxAdapter(Context context){
24 | this.mContext = context;
25 | }
26 |
27 |
28 | @NonNull @Override
29 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
30 | LayoutInflater inflater = LayoutInflater.from(this.mContext);
31 | if (viewType==TYPE_Heading){
32 | SmsCategoryLayoutBinding category_binding = DataBindingUtil.inflate(inflater,R.layout.sms_category_layout,parent,false);
33 | return new ViewHolder(category_binding);
34 | }
35 | else {
36 | SingleSmsSmallLayoutBinding sms_layout_binding = DataBindingUtil.inflate(inflater, R.layout.single_sms_small_layout,parent,false);
37 | return new ViewHolder(sms_layout_binding);
38 | }
39 | }
40 |
41 | @Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
42 | MessageDataModel record = messages.get(position);
43 | if (record.isHeading()){
44 | holder.catgory_binding.categoryText.setText(record.getHeadingText());
45 | }
46 | else {
47 | ShortMessage message = record.getMessage();
48 | if (message!=null){
49 | holder.sms_binding.smsSender.setText(message.getAddress());
50 | holder.sms_binding.smsContent.setText(message.getBody());
51 | holder.sms_binding.time.setText(message.getDate());
52 |
53 | }
54 | }
55 | }
56 |
57 | @Override public int getItemCount() {
58 | return this.messages.size();
59 | }
60 |
61 | @Override public int getItemViewType(int position) {
62 | if (messages.get(position).isHeading()){
63 | return TYPE_Heading;
64 |
65 | }
66 | else {
67 | return TYPE_SMS;
68 | }
69 | }
70 |
71 | public class ViewHolder extends RecyclerView.ViewHolder {
72 |
73 | SingleSmsSmallLayoutBinding sms_binding;
74 | SmsCategoryLayoutBinding catgory_binding;
75 |
76 | public ViewHolder(SingleSmsSmallLayoutBinding binding) {
77 | super(binding.getRoot());
78 | sms_binding = binding;
79 | }
80 |
81 | public ViewHolder(SmsCategoryLayoutBinding binding) {
82 | super(binding.getRoot());
83 | catgory_binding = binding;
84 | }
85 | }
86 |
87 | public void setData(@NonNull ArrayList data){
88 | this.messages = data;
89 | notifyDataSetChanged();
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 |
4 |
5 | android {
6 | compileSdkVersion 27
7 | buildToolsVersion '27.0.3'
8 | defaultConfig {
9 | applicationId "lingaraj.hourglass.in.base"
10 | minSdkVersion 19
11 | targetSdkVersion 27
12 | versionCode 1
13 | versionName "1.0"
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 | vectorDrawables.useSupportLibrary = true
16 |
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | dataBinding {
25 | enabled = true
26 | }
27 |
28 | }
29 |
30 | dependencies {
31 | //version declaration
32 | def dagger_version = 2.15
33 | def db_flow_version = "2.2.1"
34 | def retrofit_version = "2.4.0"
35 | implementation fileTree(include: ['*.jar'], dir: 'libs')
36 | implementation 'com.android.support:appcompat-v7:27.1.1'
37 | implementation 'com.android.support:design:27.1.1'
38 | implementation 'com.squareup.picasso:picasso:2.5.2'
39 | implementation 'com.android.support:cardview-v7:27.1.1'
40 | implementation 'com.android.support:recyclerview-v7:27.1.1'
41 | implementation 'com.android.support:support-v4:27.1.1'
42 | implementation 'com.pnikosis:materialish-progress:1.7'
43 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
44 | testImplementation 'junit:junit:4.12'
45 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
46 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
47 | implementation "com.raizlabs.android:DBFlow-Core:$db_flow_version"
48 | implementation "com.raizlabs.android:DBFlow:$db_flow_version"
49 | annotationProcessor "com.raizlabs.android:DBFlow-Compiler:$db_flow_version"
50 | implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
51 | implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
52 | implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
53 | implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
54 | implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
55 | annotationProcessor 'com.android.databinding:compiler:3.1.4'
56 | //dagger and mockito libraries inclusion
57 | implementation "com.google.dagger:dagger-android:$dagger_version"
58 | implementation "com.google.dagger:dagger-android-support:$dagger_version"
59 | annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version"
60 | annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
61 | testImplementation 'org.mockito:mockito-core:2.18.0'
62 | androidTestImplementation 'org.mockito:mockito-core:2.18.0'
63 | androidTestImplementation 'org.mockito:mockito-android:2.18.0'
64 | //dagger and mockito library for UI testing
65 | // dagger and mockito for Unit testing
66 | testAnnotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
67 | // UI Testing
68 | androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
69 | // RxJava
70 | implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
71 | // RxAndroid
72 | implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
73 | implementation 'com.google.code.gson:gson:2.2.4'
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/recievers/SMSReceiver.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.recievers;
2 |
3 | import android.app.NotificationManager;
4 | import android.app.PendingIntent;
5 | import android.content.BroadcastReceiver;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.graphics.Bitmap;
9 | import android.graphics.BitmapFactory;
10 | import android.os.Build;
11 | import android.os.Bundle;
12 | import android.support.v4.app.NotificationCompat;
13 | import android.support.v4.content.ContextCompat;
14 | import android.telephony.SmsMessage;
15 | import android.util.Log;
16 | import lingaraj.hourglass.in.glass.R;
17 | import lingaraj.hourglass.in.glass.smshomescreen.view.HomeActivity;
18 |
19 | public class SMSReceiver extends BroadcastReceiver {
20 |
21 |
22 | private String TAG = "SMSRECEIVER";
23 | private Bundle bundle;
24 | private SmsMessage currentSMS;
25 | private int mNotificationId = 101;
26 |
27 | @Override
28 | public void onReceive(Context context, Intent intent) {
29 |
30 | if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
31 |
32 |
33 |
34 | bundle = intent.getExtras();
35 | if (bundle != null) {
36 | Object[] pdu_Objects = (Object[]) bundle.get("pdus");
37 | if (pdu_Objects != null) {
38 |
39 | for (Object aObject : pdu_Objects) {
40 |
41 | currentSMS = getIncomingMessage(aObject, bundle);
42 |
43 | String senderNo = currentSMS.getDisplayOriginatingAddress();
44 | String message = currentSMS.getDisplayMessageBody();
45 |
46 | Log.d(TAG, "senderNum: " + senderNo + " :\n message: " + message);
47 |
48 | issueNotification(context, senderNo, message);
49 | }
50 | this.abortBroadcast();
51 | }
52 | }
53 |
54 | }
55 | }
56 |
57 |
58 | private void issueNotification(Context context, String senderNo, String message) {
59 |
60 | Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
61 | R.mipmap.ic_launcher);
62 |
63 | NotificationCompat.Builder mBuilder =
64 | new NotificationCompat.Builder(context)
65 | .setLargeIcon(icon)
66 | .setSmallIcon(R.mipmap.ic_launcher)
67 | .setContentTitle(senderNo)
68 | .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
69 | .setAutoCancel(true)
70 | .setContentText(message);
71 |
72 | Intent resultIntent = new Intent(context, HomeActivity.class);
73 | resultIntent.putExtra(HomeActivity.Keys.Sender,senderNo);
74 | PendingIntent resultPendingIntent =
75 | PendingIntent.getActivity(
76 | context,
77 | 0,
78 | resultIntent,
79 | PendingIntent.FLAG_UPDATE_CURRENT
80 | );
81 |
82 | mBuilder.setContentIntent(resultPendingIntent);
83 |
84 | try {
85 | NotificationManager mNotifyMgr =
86 | (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
87 | mNotifyMgr.notify(mNotificationId, mBuilder.build());
88 | }
89 | catch (Exception e){
90 | Log.d(TAG,e.toString());
91 | e.printStackTrace();
92 | }
93 |
94 |
95 | }
96 |
97 | private SmsMessage getIncomingMessage(Object aObject, Bundle bundle) {
98 | SmsMessage currentSMS;
99 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
100 | String format = bundle.getString("format");
101 | currentSMS = SmsMessage.createFromPdu((byte[]) aObject, format);
102 | } else {
103 | currentSMS = SmsMessage.createFromPdu((byte[]) aObject);
104 | }
105 | return currentSMS;
106 | }
107 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/smshomescreen/view/HomeActivity.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.smshomescreen.view;
2 |
3 | import android.Manifest;
4 | import android.content.pm.PackageManager;
5 | import android.databinding.DataBindingUtil;
6 | import android.os.Build;
7 | import android.support.annotation.NonNull;
8 | import android.support.v4.app.ActivityCompat;
9 | import android.support.v4.content.ContextCompat;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.os.Bundle;
12 | import android.util.Log;
13 | import android.view.View;
14 | import javax.inject.Inject;
15 | import lingaraj.hourglass.in.glass.R;
16 | import lingaraj.hourglass.in.glass.contracts.HomeContracts;
17 | import lingaraj.hourglass.in.glass.databinding.ActivityMainBinding;
18 | import lingaraj.hourglass.in.glass.injection.components.DaggerHomeActivityComponent;
19 | import lingaraj.hourglass.in.glass.injection.modules.HomeActivityModule;
20 | import lingaraj.hourglass.in.glass.smshomescreen.presenter.HomeActivityPresenter;
21 |
22 | public class HomeActivity extends AppCompatActivity implements HomeContracts.View,View.OnClickListener,ActivityCompat.OnRequestPermissionsResultCallback {
23 |
24 | public static class Keys {
25 | public static final String Sender = "sendername";
26 | }
27 |
28 | private final String TAG = "MAINACT";
29 | private ActivityMainBinding binding;
30 | @Inject HomeActivityPresenter presenter;
31 | private static final int SMS_PERMISSION_CODE = 103;
32 | private static final String[] SMS_PERMISSIONS = { Manifest.permission.READ_SMS, Manifest.permission.RECEIVE_SMS };
33 |
34 |
35 |
36 | @Override protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_main);
39 | binding = DataBindingUtil.setContentView(this,R.layout.activity_main);
40 | binding.progressContainer.retry.setOnClickListener(this);
41 | DaggerHomeActivityComponent.builder().homeActivityModule(new HomeActivityModule(this)).build().inject(this);
42 |
43 | }
44 |
45 | @Override public void showLoading() {
46 | Log.d(TAG,"Showing Loading");
47 | binding.progressContainer.progressBar.setVisibility(View.VISIBLE);
48 | binding.progressContainer.errorMesageView.setVisibility(View.VISIBLE);
49 | binding.progressContainer.errorMesageView.setText(this.getString(R.string.common_loading_message));
50 | binding.progressContainer.errorView.setVisibility(View.GONE);
51 | binding.progressContainer.retry.setVisibility(View.GONE);
52 | if (binding.viewSwitcher.getDisplayedChild()==1){
53 | binding.viewSwitcher.showPrevious();
54 | }
55 |
56 | }
57 |
58 |
59 |
60 | @Override public void onClick(View v) {
61 | switch (v.getId()){
62 | case R.id.retry:
63 | presenter.handleInitialChecks();
64 | break;
65 | default:
66 | break;
67 | }
68 |
69 | }
70 |
71 | @Override public void permissionsGranted() {
72 | SMSDashboardFragment dashboardFragment = new SMSDashboardFragment();
73 | getSupportFragmentManager().beginTransaction().add(binding.frame.getId(),dashboardFragment).commit();
74 | if (binding.viewSwitcher.getDisplayedChild()==0){
75 | binding.viewSwitcher.showNext();
76 | }
77 | Log.d(TAG,"Permissions Granted by user and message Dashboard set");
78 |
79 |
80 | }
81 |
82 | @Override public void permissionsDenied() {
83 |
84 | Log.d(TAG,"Showing Views for Permission Denied");
85 | binding.progressContainer.progressBar.setVisibility(View.GONE);
86 | binding.progressContainer.errorMesageView.setVisibility(View.VISIBLE);
87 | binding.progressContainer.errorMesageView.setText(this.getString(R.string.error_permission_denied));
88 | binding.progressContainer.errorView.setVisibility(View.VISIBLE);
89 | binding.progressContainer.retry.setVisibility(View.VISIBLE);
90 | if (binding.viewSwitcher.getDisplayedChild()==1){
91 | binding.viewSwitcher.showPrevious();
92 | }
93 | Log.d(TAG,"Permissions Denied By user");
94 |
95 | }
96 |
97 | @Override
98 | public void checkPermissions(){
99 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
100 | ||(isPermissionGranted(Manifest.permission.READ_SMS) && isPermissionGranted(
101 | Manifest.permission.RECEIVE_SMS))){
102 | permissionsGranted();
103 | }
104 | else {
105 | requestSMSAppPermissions();
106 | }
107 |
108 | }
109 |
110 | private boolean isPermissionGranted(String permissionName){
111 | int result = ContextCompat.checkSelfPermission(HomeActivity.this,permissionName);
112 | boolean PERMISSION_STATUS = (result == PackageManager.PERMISSION_GRANTED);
113 | Log.d(TAG,permissionName+":"+PERMISSION_STATUS);
114 | return PERMISSION_STATUS;
115 |
116 | }
117 |
118 |
119 | @Override
120 | public void requestSMSAppPermissions() {
121 | ActivityCompat.requestPermissions(HomeActivity.this, SMS_PERMISSIONS, SMS_PERMISSION_CODE);
122 | }
123 |
124 | @Override
125 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
126 | switch (requestCode){
127 | case SMS_PERMISSION_CODE:
128 | if (grantResults.length==2 && grantResults[0]==PackageManager.PERMISSION_GRANTED && grantResults[1]==PackageManager.PERMISSION_GRANTED){
129 | Log.d(TAG,"Permission Granted");
130 | permissionsGranted();
131 | }
132 | else {
133 | Log.d(TAG,"Permission Denied");
134 | permissionsDenied();
135 | }
136 | break;
137 | default:
138 | break;
139 | }
140 | }
141 |
142 |
143 |
144 | }
145 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/smshomescreen/view/SMSDashboardFragment.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.smshomescreen.view;
2 |
3 | import android.app.Activity;
4 | import android.content.ContentResolver;
5 | import android.content.Context;
6 | import android.databinding.DataBindingUtil;
7 | import android.os.AsyncTask;
8 | import android.os.Bundle;
9 | import android.support.annotation.NonNull;
10 | import android.support.annotation.Nullable;
11 | import android.support.v4.app.Fragment;
12 | import android.support.v7.widget.LinearLayoutManager;
13 | import android.util.Log;
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import java.util.ArrayList;
18 | import javax.inject.Inject;
19 | import lingaraj.hourglass.in.glass.R;
20 | import lingaraj.hourglass.in.glass.contracts.SMSDashboardContracts;
21 | import lingaraj.hourglass.in.glass.databinding.FragmentInboxBinding;
22 | import lingaraj.hourglass.in.glass.injection.components.DaggerSMSDashboardComponent;
23 | import lingaraj.hourglass.in.glass.injection.modules.SMSDashboardModule;
24 | import lingaraj.hourglass.in.glass.smshomescreen.MessageDataModel;
25 | import lingaraj.hourglass.in.glass.smshomescreen.adapters.InboxAdapter;
26 | import lingaraj.hourglass.in.glass.smshomescreen.presenter.SMSDashBoardPresenter;
27 | import lingaraj.hourglass.in.glass.smshomescreen.tasks.ReadMobileSMSAsyncTask;
28 |
29 | public class SMSDashboardFragment extends Fragment implements SMSDashboardContracts.View,
30 | View.OnClickListener {
31 |
32 | private final String TAG = "SMSHOMEFRAGMENT";
33 | private Activity mActivity;
34 | private FragmentInboxBinding binding;
35 | private InboxAdapter mAdapter;
36 | @Inject SMSDashBoardPresenter presenter;
37 |
38 | private AsyncTask> read_sms_task;
39 | private ContentResolver content_resolver;
40 |
41 | @Override public void onAttach(Context context) {
42 | super.onAttach(context);
43 | this.mActivity = (Activity) context;
44 | this.content_resolver = this.mActivity.getContentResolver();
45 | DaggerSMSDashboardComponent.builder().sMSDashboardModule(new SMSDashboardModule(this)).build().inject(this);
46 |
47 |
48 | }
49 |
50 | @Nullable @Override
51 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
52 | @Nullable Bundle savedInstanceState) {
53 | binding = DataBindingUtil.inflate(inflater, R.layout.fragment_inbox,container,false);
54 | binding.progressContainer.retry.setOnClickListener(this);
55 | return binding.getRoot();
56 |
57 | }
58 |
59 |
60 | @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) {
61 | super.onActivityCreated(savedInstanceState);
62 | presenter.getMessages();
63 | }
64 |
65 | @Override public void showLoader() {
66 | binding.progressContainer.progressBar.setVisibility(View.VISIBLE);
67 | binding.progressContainer.errorMesageView.setVisibility(View.VISIBLE);
68 | binding.progressContainer.errorView.setVisibility(View.GONE);
69 | binding.progressContainer.retry.setVisibility(View.GONE);
70 | binding.progressContainer.errorMesageView.setText(this.getString(R.string.common_loading_message));
71 | if (binding.viewSwitcher.getDisplayedChild()==1){
72 | binding.viewSwitcher.showPrevious();
73 | }
74 | Log.d(TAG,"Showing Loader");
75 |
76 | }
77 |
78 | @Override public void showError() {
79 | binding.progressContainer.progressBar.setVisibility(View.GONE);
80 | binding.progressContainer.errorMesageView.setVisibility(View.VISIBLE);
81 | binding.progressContainer.errorView.setVisibility(View.GONE);
82 | binding.progressContainer.retry.setVisibility(View.VISIBLE);
83 | binding.progressContainer.retry.setText(this.getString(R.string.retry));
84 | binding.progressContainer.errorMesageView.setText(this.getString(R.string.error_retrieving_messages));
85 | if (binding.viewSwitcher.getDisplayedChild()==1){
86 | binding.viewSwitcher.showPrevious();
87 | }
88 | Log.d(TAG,"Showing Loader");
89 |
90 |
91 | }
92 |
93 | @Override public void noMessagesToDisplay() {
94 | binding.progressContainer.progressBar.setVisibility(View.GONE);
95 | binding.progressContainer.errorMesageView.setVisibility(View.VISIBLE);
96 | binding.progressContainer.errorView.setVisibility(View.GONE);
97 | binding.progressContainer.retry.setVisibility(View.GONE);
98 | binding.progressContainer.errorMesageView.setText(this.getString(R.string.no_messages));
99 | if (binding.viewSwitcher.getDisplayedChild()==1){
100 | binding.viewSwitcher.showPrevious();
101 | }
102 |
103 |
104 | }
105 |
106 | @Override public void setMessages(ArrayList messages) {
107 | if (mAdapter==null){
108 | mAdapter = new InboxAdapter(mActivity);
109 | binding.messages.setLayoutManager(new LinearLayoutManager(mActivity,LinearLayoutManager.VERTICAL,false));
110 | binding.messages.setHasFixedSize(false);
111 | binding.messages.setNestedScrollingEnabled(false);
112 | binding.messages.setAdapter(mAdapter);
113 | }
114 | mAdapter.setData(messages);
115 | if (binding.viewSwitcher.getDisplayedChild()==0){
116 | binding.viewSwitcher.showNext();
117 | }
118 |
119 |
120 | }
121 |
122 | @Override public void startFetchSMSAsyncTask(SMSDashboardContracts.Presenter.SmsContentProviderAccessCallbacks callbacks) {
123 | read_sms_task = new ReadMobileSMSAsyncTask(callbacks,content_resolver).execute();
124 | }
125 |
126 | @Override public void onClick(View v) {
127 | switch (v.getId()){
128 | case R.id.retry:
129 | presenter.getMessages();break;
130 |
131 | default: break;
132 |
133 | }
134 |
135 | }
136 |
137 | @Override public void onPause() {
138 | super.onPause();
139 | if (read_sms_task!=null && read_sms_task.getStatus()==AsyncTask.Status.RUNNING){
140 | read_sms_task.cancel(true);
141 | showError();
142 | }
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/java/lingaraj/hourglass/in/glass/smshomescreen/tasks/ReadMobileSMSAsyncTask.java:
--------------------------------------------------------------------------------
1 | package lingaraj.hourglass.in.glass.smshomescreen.tasks;
2 |
3 | import android.content.ContentResolver;
4 | import android.database.Cursor;
5 | import android.database.DatabaseUtils;
6 | import android.os.AsyncTask;
7 | import android.provider.Telephony;
8 | import android.support.annotation.Nullable;
9 | import android.util.Log;
10 | import com.google.gson.Gson;
11 | import java.text.DateFormat;
12 | import java.text.ParseException;
13 | import java.text.SimpleDateFormat;
14 | import java.util.ArrayList;
15 | import java.util.Calendar;
16 | import java.util.Date;
17 | import lingaraj.hourglass.in.glass.BuildConfig;
18 | import lingaraj.hourglass.in.glass.contracts.SMSDashboardContracts;
19 | import lingaraj.hourglass.in.glass.smshomescreen.MessageDataModel;
20 | import lingaraj.hourglass.in.glass.smshomescreen.ShortMessage;
21 |
22 | public class ReadMobileSMSAsyncTask extends AsyncTask>{
23 |
24 | private final String TAG = "ReadMobileSMSAsync";
25 | private SMSDashboardContracts.Presenter.SmsContentProviderAccessCallbacks callbacks;
26 | private ContentResolver content_resolver;
27 | public ReadMobileSMSAsyncTask(SMSDashboardContracts.Presenter.SmsContentProviderAccessCallbacks contentProviderAccessCallbacks,ContentResolver contentResolver){
28 | this.callbacks = contentProviderAccessCallbacks;
29 | this.content_resolver = contentResolver;
30 | }
31 |
32 | @Override protected ArrayList doInBackground(Void... voids) {
33 |
34 | String [] columns = {"address","date","body","person"};
35 | int hours[] = {1,2,3,6,12,24};
36 | int length = hours.length;
37 | ArrayList messages = new ArrayList<>();
38 | try {
39 | for (int index = 0; index messageDataModels) {
64 | super.onPostExecute(messageDataModels);
65 | this.callbacks.onMessageRetrievalCompletion(messageDataModels);
66 |
67 | }
68 |
69 | /**
70 | *
71 | * @param cursor - cursor obtained from query
72 | * @param messages - variable to hold the read data
73 | * @param hour - difference in hours
74 | */
75 | private void parseCursor(@Nullable Cursor cursor, ArrayList messages,int hour) {
76 | String heading = "Recieved in last "+String.valueOf(hour)+"hour";
77 | ArrayList data = new ArrayList();
78 | if (cursor!=null){
79 | int count = cursor.getCount();
80 | Log.d(TAG,"Cursor Count:"+count);
81 | if (count>0){
82 | cursor.moveToFirst();
83 | do {
84 | long date_long = cursor.getLong(cursor.getColumnIndexOrThrow("date"));
85 | String date = convertLongToDate(date_long);
86 | String address = cursor.getString(cursor.getColumnIndexOrThrow("address"));
87 | String body = cursor.getString(cursor.getColumnIndexOrThrow("body"));
88 | ShortMessage message = new ShortMessage(date,address,body);
89 | MessageDataModel messageDataModel = new MessageDataModel(false,null,message);
90 | data.add(messageDataModel);
91 | }
92 | while (cursor.moveToNext());
93 | cursor.close();
94 | }
95 | if (data.size()>0){
96 | MessageDataModel messageDataModel = new MessageDataModel(true,heading,null);
97 | messages.add(messageDataModel);
98 | messages.addAll(data);
99 | }
100 | }
101 |
102 |
103 |
104 | }
105 |
106 |
107 | private long convertDateToLong(String dbDate) {
108 | long date_to_long = 0;
109 | try {
110 | // DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
111 | SimpleDateFormat date_formate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
112 | // date_formate.setTimeZone(TimeZone.getTimeZone("IST"));
113 | Date date = date_formate.parse(dbDate);
114 | date_to_long = date.getTime();
115 | }
116 | catch (ParseException e) {
117 | e.printStackTrace();
118 | }
119 |
120 |
121 | return date_to_long;
122 | }
123 |
124 | /**
125 | *
126 | * @param value - takes long value of date and time
127 | *
128 | */
129 | private String convertLongToDate(long value) {
130 | Date date=new Date(value);
131 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
132 | //sdf.setTimeZone(TimeZone.getTimeZone("IST"));
133 | return sdf.format(date);
134 | }
135 |
136 | /**
137 | *
138 | * @param hour -
139 | * @param lastProcessed
140 | * @return
141 | */
142 | private String query(int hour, int lastProcessed){
143 | String start_date = getDate(lastProcessed);
144 | String end_date = getDate(hour);
145 | Log.d(TAG,"Start Date:"+start_date);
146 | Log.d(TAG,"End Date:"+end_date);
147 | String whereAddress = "address = ?";
148 | String whereDate = "date >=" + convertDateToLong(end_date) +
149 | " AND date <" + convertDateToLong(start_date);
150 | String where = DatabaseUtils.concatenateWhere(whereAddress, whereDate);
151 | Log.d(TAG,"query:"+whereDate);
152 | return whereDate;
153 | }
154 |
155 | private String getDate(int minusHour){
156 | DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
157 | Date date = null;
158 | Calendar calendar = Calendar.getInstance();
159 | calendar.add(Calendar.HOUR_OF_DAY,-minusHour);
160 | date = calendar.getTime();
161 | return dateFormat.format(date);
162 |
163 | };
164 |
165 |
166 |
167 | }
168 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
--------------------------------------------------------------------------------