Ejemplo n.º 1
0
 public void run() {
   settingsSync =
       ActorSystem.system()
           .actorOf(
               Props.create(
                   new ActorCreator() {
                     @Override
                     public SettingsSyncActor create() {
                       return new SettingsSyncActor(context());
                     }
                   }),
               "actor/settings");
 }
Ejemplo n.º 2
0
 public void run() {
   actorRef =
       system()
           .actorOf(
               Props.create(
                   SearchActor.class,
                   new ActorCreator<SearchActor>() {
                     @Override
                     public SearchActor create() {
                       return new SearchActor(context());
                     }
                   }),
               "actor/search");
 }
Ejemplo n.º 3
0
  public JsIdleModule(final JsMessenger messenger, final ModuleContext context) {
    super(context);

    this.messenger = messenger;

    this.messenger.onAppVisible();

    idleActor =
        system()
            .actorOf(
                Props.create(
                    new ActorCreator() {
                      @Override
                      public IdleActor create() {
                        return new IdleActor(messenger, context);
                      }
                    }),
                "js/idle_timer");
  }
  public AndroidMessenger(Context context, im.actor.core.Configuration configuration) {
    super(configuration);

    this.context = context;

    this.appStateActor =
        system()
            .actorOf(
                Props.create(
                    new ActorCreator() {
                      @Override
                      public AppStateActor create() {
                        return new AppStateActor(AndroidMessenger.this);
                      }
                    }),
                "actor/android/state");

    // Catch all phone book changes
    context
        .getContentResolver()
        .registerContentObserver(
            ContactsContract.Contacts.CONTENT_URI,
            true,
            new ContentObserver(null) {
              @Override
              public void onChange(boolean selfChange) {
                onPhoneBookChanged();
              }
            });

    // Catch network change
    context.registerReceiver(
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            ConnectivityManager cm =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

            NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
            boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

            NetworkState state;
            if (isConnected) {
              switch (activeNetwork.getType()) {
                case ConnectivityManager.TYPE_WIFI:
                case ConnectivityManager.TYPE_WIMAX:
                case ConnectivityManager.TYPE_ETHERNET:
                  state = NetworkState.WI_FI;
                  break;
                case ConnectivityManager.TYPE_MOBILE:
                  state = NetworkState.MOBILE;
                  break;
                default:
                  state = NetworkState.UNKNOWN;
              }
            } else {
              state = NetworkState.NO_CONNECTION;
            }
            onNetworkChanged(state);
          }
        },
        new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));

    // Screen change processor
    IntentFilter screenFilter = new IntentFilter();
    screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
    screenFilter.addAction(Intent.ACTION_SCREEN_ON);
    context.registerReceiver(
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
              appStateActor.send(new AppStateActor.OnScreenOn());
            } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
              appStateActor.send(new AppStateActor.OnScreenOff());
            }
          }
        },
        screenFilter);
    if (isScreenOn()) {
      appStateActor.send(new AppStateActor.OnScreenOn());
    } else {
      appStateActor.send(new AppStateActor.OnScreenOff());
    }

    modules
        .getAppStateModule()
        .getAppStateVM()
        .getGlobalCounter()
        .subscribe(
            new ValueChangedListener<Integer>() {
              @Override
              public void onChanged(Integer val, Value<Integer> valueModel) {
                ShortcutBadger.with(AndroidContext.getContext()).count(val);
              }
            });
    //        modules.getAppStateModule().getAppStateVM().getGlobalCounter().subscribe(new
    // ValueChangedListener<Integer>() {
    //            @Override
    //            public void onChanged(Integer val, ValueModel<Integer> valueModel) {
    //                ShortcutBadger.with(AndroidContext.getContext()).count(val);
    //            }
    //        });
  }