@Override
  public void onReceive(Context context, Intent intent) {
    String intentAction = intent.getAction();
    if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
      KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);

      if (event == null) {
        return;
      }

      int keycode = event.getKeyCode();
      if (firstElapsed == -1) {
        firstElapsed = System.currentTimeMillis();
        count = 0;
      }
      currentElapsed = System.currentTimeMillis();
      long duration = currentElapsed - firstElapsed;
      if (duration > 0 && duration < MAX_DELAY && keycode == KeyEvent.KEYCODE_HEADSETHOOK) count++;
      if (duration > MAX_DELAY) {
        firstElapsed = -1;
        count = 0;
      }
      Log.d("EVENT", "" + keycode + " " + count);
      if (count == 3) {
        StandOutWindow.show(context, LockScreenNowService.class, StandOutWindow.DEFAULT_ID);
        count = 0;
        firstElapsed = -1;
      }
    }
  }
Exemplo n.º 2
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   if (!BootReceiver.boot_up || Corner.running) {
     Intent i = new Intent(this, Settings.class);
     startActivity(i);
   }
   StandOutWindow.show(this, Corner.class, 0);
   StandOutWindow.show(this, Corner.class, 1);
   StandOutWindow.show(this, Corner.class, 2);
   StandOutWindow.show(this, Corner.class, 3);
   finish();
 }
Exemplo n.º 3
0
  @Override
  public void onAccessibilityEvent(AccessibilityEvent event) {
    // Load DrawerSettings pref data
    final boolean draweron =
        getSharedPreferences("pref", Context.MODE_PRIVATE).getBoolean("toggledata", true);

    // Load BlackList
    mHelper = new AppBlackListDBhelper(this);
    mCursor =
        mHelper
            .getWritableDatabase()
            .rawQuery("SELECT _ID, pkgname FROM appblacklist ORDER BY pkgname", null);

    List<String> array = new ArrayList<String>();
    while (mCursor.moveToNext()) {
      String uname = mCursor.getString(mCursor.getColumnIndex("pkgname"));
      array.add(uname);
    }
    mCursor.close();
    mHelper.close();

    Log.d("DBVALUES", array.toString());
    System.out.println("onAccessibilityEvent");
    if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
      System.out.println("notification: " + event.getText());

      String pkgnameforfilter = event.getPackageName().toString();
      String pkgitself = "com.simpleminds.popbell";

      // Filtering Package Name from Notification
      if (pkgnameforfilter.equals(pkgitself)) {
        // Do Nothing
        Log.d("SYSNOTIDETECTOR", "BLOCKED : PKG_ITSELF");
      } else if (array.toString().contains(pkgnameforfilter)) {
        // Do Nothing
        Log.d("SYSNOTIDETECTOR", "BLOCKED : PKG_BLACKLISTED");
      } else {
        try {
          // Get app name
          final PackageManager pm = getApplicationContext().getPackageManager();
          ApplicationInfo ai;
          try {
            ai = pm.getApplicationInfo((String) event.getPackageName().toString(), 0);
          } catch (final NameNotFoundException e) {
            ai = null;
          }
          final String applicationName =
              (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");

          // put values to db
          mHelper2 = new NotiListDBhelper(this);
          mCursor2 =
              mHelper2
                  .getWritableDatabase()
                  .rawQuery("SELECT _ID, title, desc FROM notilist ORDER BY title", null);
          ContentValues values = new ContentValues();
          values.put(NotiListDBhelper.TITLE, applicationName.toString());
          values.put(NotiListDBhelper.DESC, event.getText().toString());
          mHelper2.getWritableDatabase().insert("notilist", NotiListDBhelper.TITLE, values);
          mCursor2.requery();
          mCursor2.close();
          mHelper2.close();

          // Close and Open Dialog Window
          StandOutWindow.closeAll(this, DialogWindow.class);
          StandOutWindow.closeAll(this, TouchTrigger.class);
          StandOutWindow.show(this, DialogWindow.class, StandOutWindow.DEFAULT_ID);
          if (draweron) {
            StandOutWindow.show(this, TouchTrigger.class, StandOutWindow.DEFAULT_ID);
          } else {
          }

          // Create Bundle and put data
          Bundle dataBundle = new Bundle();
          // Get and Put Notification text
          dataBundle.putString("sysnotitext", event.getText().toString());
          // Put App Name
          dataBundle.putString("pkgname", event.getPackageName().toString());
          dataBundle.putParcelable("ParcelableData", event.getParcelableData());
          // Send data to DialogWindow
          StandOutWindow.sendData(
              this, DialogWindow.class, StandOutWindow.DEFAULT_ID, 1, dataBundle, null, 0);
          // Close DialogWindow in a few seconds
          mTask =
              new TimerTask() {
                @Override
                public void run() {
                  stopService(new Intent(NotiDetector.this, DialogWindow.class));
                  stopService(new Intent(NotiDetector.this, TouchTrigger.class));
                  StandOutWindow.closeAll(NotiDetector.this, DialogWindow.class);
                  StandOutWindow.closeAll(NotiDetector.this, TouchTrigger.class);
                }
              };
          mTimer = new Timer();
          mTimer.schedule(mTask, 5000);
        } catch (Exception e) {
          Log.e("SYSNOTIDETECTOR", "ERROR IN CODE:" + e.toString());
        }
      }
    }
  }