@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;
      }
    }
  }
Example #2
0
  /**
   * Request or remove the focus from this window.
   *
   * @param focus Whether we want to gain or lose focus.
   * @return True if focus changed successfully, false if it failed.
   */
  public boolean onFocus(boolean focus) {
    if (!Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_FOCUSABLE_DISABLE)) {
      // window is focusable

      if (focus == focused) {
        // window already focused/unfocused
        return false;
      }

      focused = focus;

      // alert callbacks and cancel if instructed
      if (mContext.onFocusChange(id, this, focus)) {
        Log.d(
            TAG,
            "Window "
                + id
                + " focus change "
                + (focus ? "(true)" : "(false)")
                + " cancelled by implementation.");
        focused = !focus;
        return false;
      }

      if (!Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_FOCUS_INDICATOR_DISABLE)) {
        // change visual state
        View content = findViewById(R.id.content);
        if (focus) {
          // gaining focus
          content.setBackgroundResource(R.drawable.border_focused);
        } else {
          // losing focus
          if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_SYSTEM)) {
            // system decorations
            content.setBackgroundResource(R.drawable.border);
          } else {
            // no decorations
            content.setBackgroundResource(0);
          }
        }
      }

      // set window manager params
      StandOutLayoutParams params = getLayoutParams();
      params.setFocusFlag(focus);
      mContext.updateViewLayout(id, params);

      if (focus) {
        mContext.setFocusedWindow(this);
      } else {
        if (mContext.getFocusedWindow() == this) {
          mContext.setFocusedWindow(null);
        }
      }

      return true;
    }
    return false;
  }
Example #3
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();
 }
Example #4
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // handle touching outside
    switch (event.getAction()) {
      case MotionEvent.ACTION_OUTSIDE:
        // unfocus window
        if (mContext.getFocusedWindow() == this) {
          mContext.unfocus(this);
        }

        // notify implementation that ACTION_OUTSIDE occurred
        mContext.onTouchBody(id, this, this, event);
        break;
    }

    // handle multitouch
    if (event.getPointerCount() >= 2
        && Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_PINCH_RESIZE_ENABLE)) {
      // 2 fingers or more

      float x0 = event.getX(0);
      float y0 = event.getY(0);
      float x1 = event.getX(1);
      float y1 = event.getY(1);

      double dist = Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2));

      switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_MOVE:
          if (touchInfo.dist == -1) {
            touchInfo.dist = dist;
          }
          touchInfo.scale *= dist / touchInfo.dist;
          touchInfo.dist = dist;

          // scale the window with anchor point set to middle
          edit()
              .setAnchorPoint(.5f, .5f)
              .setSize(
                  (int) (touchInfo.firstWidth * touchInfo.scale),
                  (int) (touchInfo.firstHeight * touchInfo.scale))
              .commit();
          break;
      }
      mContext.onResize(id, this, this, event);
    }

    return true;
  }
Example #5
0
 @Override
 public boolean onClose(int id, Window window) {
   super.onClose(id, window);
   stopService(getShowIntent(this, getClass(), id));
   mShowingStatus = STATUS_CLOSE;
   return false;
 }
Example #6
0
  @Override
  public boolean dispatchKeyEvent(KeyEvent event) {
    if (mContext.onKeyEvent(id, this, event)) {
      Log.d(TAG, "Window " + id + " key event " + event + " cancelled by implementation.");
      return false;
    }

    if (event.getAction() == KeyEvent.ACTION_UP) {
      switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_BACK:
          mContext.unfocus(this);
          return true;
      }
    }

    return super.dispatchKeyEvent(event);
  }
 public Notification getPersistentNotification() {
   if (persistentNotification == null) {
     Notification.Builder n = new Notification.Builder(this);
     n.setSmallIcon(this.getAppIcon());
     n.setContentTitle(this.getAppName());
     n.setContentIntent(
         PendingIntent.getService(
             this,
             0,
             StandOutWindow.getCloseAllIntent(this, LauncherWindow.class),
             PendingIntent.FLAG_UPDATE_CURRENT));
     persistentNotification = n.getNotification();
   }
   return persistentNotification;
 }
Example #8
0
  @Override
  public boolean onInterceptTouchEvent(MotionEvent event) {
    StandOutLayoutParams params = getLayoutParams();

    // focus window
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      if (mContext.getFocusedWindow() != this) {
        mContext.focus(id);
      }
    }

    // multitouch
    if (event.getPointerCount() >= 2
        && Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_PINCH_RESIZE_ENABLE)
        && (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) {
      touchInfo.scale = 1;
      touchInfo.dist = -1;
      touchInfo.firstWidth = params.width;
      touchInfo.firstHeight = params.height;
      return true;
    }

    return false;
  }
  @Override
  public void onCreate() {
    super.onCreate();

    mPackageManager = getPackageManager();
    mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    iconSize = (int) getResources().getDimension(android.R.dimen.app_icon_size);
    squareWidth = iconSize + 8 * 8;

    mFadeOut = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
    mFadeIn = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);

    int duration = 100;
    mFadeOut.setDuration(duration);
    mFadeIn.setDuration(duration);
  }
Example #10
0
 @Override
 protected Intent getPersistentNotificationIntent(int id) {
   return StandOutWindow.getCloseIntent(this, SimpleWindow.class, id);
 }
 public Intent getPersistentNotificationIntent(int id) {
   return StandOutWindow.getCloseAllIntent(this, FloatingFolder.class);
 }
Example #12
0
 @Override
 public void onMove(int id, Window window, View view, MotionEvent event) {
   super.onMove(id, window, view, event);
   mSettings.setWindow(window.getLayoutParams().x, window.getLayoutParams().y);
 }
Example #13
0
 @Override
 public Intent getPersistentNotificationIntent(int id) {
   return StandOutWindow.getCloseIntent(this, FloatWindow.class, id);
 }
Example #14
0
  public Window(final StandOutWindow context, final int id) {
    super(context);
    context.setTheme(context.getThemeStyle());

    mContext = context;
    mLayoutInflater = LayoutInflater.from(context);

    this.cls = context.getClass();
    this.id = id;
    this.originalParams = context.getParams(id, this);
    this.flags = context.getFlags(id);
    this.touchInfo = new TouchInfo();
    touchInfo.ratio = (float) originalParams.width / originalParams.height;
    this.data = new Bundle();
    DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
    displayWidth = metrics.widthPixels;
    displayHeight = (int) (metrics.heightPixels - 25 * metrics.density);

    // create the window contents
    View content;
    FrameLayout body;

    if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_SYSTEM)) {
      // requested system window decorations
      content = getSystemDecorations();
      body = (FrameLayout) content.findViewById(R.id.body);
    } else {
      // did not request decorations. will provide own implementation
      content = new FrameLayout(context);
      content.setId(R.id.content);
      body = (FrameLayout) content;
    }

    addView(content);

    body.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            // pass all touch events to the implementation
            boolean consumed = false;

            // handle move and bring to front
            consumed = context.onTouchHandleMove(id, Window.this, v, event) || consumed;

            // alert implementation
            consumed = context.onTouchBody(id, Window.this, v, event) || consumed;

            return consumed;
          }
        });

    // attach the view corresponding to the id from the
    // implementation
    context.createAndAttachView(id, body);

    // make sure the implementation attached the view
    if (body.getChildCount() == 0) {
      throw new RuntimeException(
          "You must attach your view to the given frame in createAndAttachView()");
    }

    // implement StandOut specific workarounds
    if (!Utils.isSet(flags, StandOutFlags.FLAG_FIX_COMPATIBILITY_ALL_DISABLE)) {
      fixCompatibility(body);
    }
    // implement StandOut specific additional functionality
    if (!Utils.isSet(flags, StandOutFlags.FLAG_ADD_FUNCTIONALITY_ALL_DISABLE)) {
      addFunctionality(body);
    }

    // attach the existing tag from the frame to the window
    setTag(body.getTag());
  }
Example #15
0
  /**
   * Returns the system window decorations if the implementation sets {@link
   * #FLAG_DECORATION_SYSTEM}.
   *
   * <p>The system window decorations support hiding, closing, moving, and resizing.
   *
   * @return The frame view containing the system window decorations.
   */
  private View getSystemDecorations() {
    final View decorations = mLayoutInflater.inflate(R.layout.system_window_decorators, null);

    // icon
    final ImageView icon = (ImageView) decorations.findViewById(R.id.window_icon);

    if (mContext.getAppIcon() > 0) {
      icon.setImageResource(mContext.getAppIcon());
      icon.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              PopupWindow dropDown = mContext.getDropDown(id);
              if (dropDown != null) {
                dropDown.showAsDropDown(icon);
              }
            }
          });
    } else {
      icon.setVisibility(View.GONE);
    }

    // title
    TextView title = (TextView) decorations.findViewById(R.id.title);
    title.setText(mContext.getTitle(id));

    // hide
    View hide = decorations.findViewById(R.id.hide);
    hide.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            mContext.hide(id);
          }
        });
    hide.setVisibility(View.GONE);

    // maximize
    View maximize = decorations.findViewById(R.id.maximize);
    maximize.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            StandOutLayoutParams params = getLayoutParams();
            boolean isMaximized = data.getBoolean(WindowDataKeys.IS_MAXIMIZED);
            if (isMaximized
                && params.width == displayWidth
                && params.height == displayHeight
                && params.x == 0
                && params.y == 0) {
              data.putBoolean(WindowDataKeys.IS_MAXIMIZED, false);
              int oldWidth = data.getInt(WindowDataKeys.WIDTH_BEFORE_MAXIMIZE, -1);
              int oldHeight = data.getInt(WindowDataKeys.HEIGHT_BEFORE_MAXIMIZE, -1);
              int oldX = data.getInt(WindowDataKeys.X_BEFORE_MAXIMIZE, -1);
              int oldY = data.getInt(WindowDataKeys.Y_BEFORE_MAXIMIZE, -1);
              edit().setSize(oldWidth, oldHeight).setPosition(oldX, oldY).commit();
            } else {
              data.putBoolean(WindowDataKeys.IS_MAXIMIZED, true);
              data.putInt(WindowDataKeys.WIDTH_BEFORE_MAXIMIZE, params.width);
              data.putInt(WindowDataKeys.HEIGHT_BEFORE_MAXIMIZE, params.height);
              data.putInt(WindowDataKeys.X_BEFORE_MAXIMIZE, params.x);
              data.putInt(WindowDataKeys.Y_BEFORE_MAXIMIZE, params.y);
              edit().setSize(1f, 1f).setPosition(0, 0).commit();
            }
          }
        });

    // close
    View close = decorations.findViewById(R.id.close);
    close.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            mContext.close(id);
          }
        });

    // move
    View titlebar = decorations.findViewById(R.id.titlebar);
    titlebar.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            // handle dragging to move
            return mContext.onTouchHandleMove(id, Window.this, v, event);
          }
        });

    // resize
    View corner = decorations.findViewById(R.id.corner);
    corner.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            // handle dragging to move
            boolean consumed = mContext.onTouchHandleResize(id, Window.this, v, event);

            return consumed;
          }
        });

    // set window appearance and behavior based on flags
    if (Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_HIDE_ENABLE)) {
      hide.setVisibility(View.VISIBLE);
    }
    if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_MAXIMIZE_DISABLE)) {
      maximize.setVisibility(View.GONE);
    }
    if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_CLOSE_DISABLE)) {
      close.setVisibility(View.GONE);
    }
    if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_MOVE_DISABLE)) {
      titlebar.setOnTouchListener(null);
    }
    if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_RESIZE_DISABLE)) {
      corner.setVisibility(View.GONE);
    }

    return decorations;
  }
Example #16
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());
        }
      }
    }
  }