Android Open Source - fullscreen-popupmenu Home Watcher






From Project

Back to project page fullscreen-popupmenu.

License

The source code is released under:

MIT License

If you think the Android project fullscreen-popupmenu listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lion.homewatcher;
/* w w  w. ja va 2s . com*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

public class HomeWatcher {
  private Context mContext;
  private IntentFilter mFilter;
  private OnHomePressedListener mListener;
  private InnerRecevier mRecevier;

  public interface OnHomePressedListener {
    public void onHomePressed();

    public void onHomeLongPressed();
  }

  public HomeWatcher(Context context) {
    mContext = context;
    mFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
  }

  public void setOnHomePressedListener(OnHomePressedListener listener) {
    mListener = listener;
    mRecevier = new InnerRecevier();
  }

  public void startWatch() {
    if (mRecevier != null) {
      mContext.registerReceiver(mRecevier, mFilter);
    }
  }

  public void stopWatch() {
    if (mRecevier != null) {
      mContext.unregisterReceiver(mRecevier);
    }
  }

  class InnerRecevier extends BroadcastReceiver {
    final String SYSTEM_DIALOG_REASON_KEY = "reason";
    final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
    final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
    final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";

    @Override
    public void onReceive(Context context, Intent intent) {
      String action = intent.getAction();
      if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
        String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
        if (reason != null) {
          if (mListener != null) {
            if (reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {
              mListener.onHomePressed();
            } else if (reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
              mListener.onHomeLongPressed();
            }
          }
        }
      }
    }
  }

}




Java Source Code List

com.example.popupmenudemo.MainActivity.java
com.lion.homewatcher.HomeWatcher.java
com.lion.pupupmenu.FullScreenPopupMenu.java
com.lion.pupupmenu.PopupMenuArrayAdapter.java
com.lion.pupupmenu.PopupMenuListener.java