KEYCODE_HOME源码实例Demo

android.view.KeyEvent#KEYCODE_HOME源码实例Demo

下面列出了android.view.KeyEvent#KEYCODE_HOME 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TurboLauncher   文件: Launcher.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
	if (event.getAction() == KeyEvent.ACTION_DOWN) {
		switch (event.getKeyCode()) {
		case KeyEvent.KEYCODE_HOME:
			return true;
		}
	} else if (event.getAction() == KeyEvent.ACTION_UP) {
		switch (event.getKeyCode()) {
		case KeyEvent.KEYCODE_HOME:
			return true;
		}
	}

	return super.dispatchKeyEvent(event);
}
 

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) {
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
源代码3 项目: xpay   文件: MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_BACK){
        keyCode = KeyEvent.KEYCODE_HOME;
    }
    return super.onKeyDown(keyCode, event);
}
 

private boolean processKeyEvent(KeyEvent event) {
  if (event == null) {
    return false;
  }

  if (event.getRepeatCount() > 1) {
    return false;
  }

  //noinspection SimplifiableIfStatement
  if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
      || event.getKeyCode() == KeyEvent.KEYCODE_HOME
      || event.getKeyCode() == KeyEvent.KEYCODE_CALL
      || event.getKeyCode() == KeyEvent.KEYCODE_ENDCALL) {
    return false;
  }

  // Enter and Esc are used to accept/dismiss dialogs. However, the default shortcuts
  // involve Enter and Esc (with modifiers), so we should only trap Enter and Esc without
  // modifiers.
  boolean isDialogNavigation =
      event.getKeyCode() == KeyEvent.KEYCODE_ENTER
          || event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE;
  if (isDialogNavigation && event.hasNoModifiers()) {
    return false;
  }

  return event.getAction() == KeyEvent.ACTION_DOWN;
}
 

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		tryAgain();
		return true;
	} else if (keyCode == KeyEvent.KEYCODE_HOME) {
		finish();
		return true;
	}
	
	return super.onKeyDown(keyCode, event);
}
 
源代码6 项目: TapUnlock   文件: LockActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_HOME) {
        activityManager.moveTaskToFront(taskId, 0);

        return true;
    }

    return false;
}
 

@Override
public void run() {
    Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(10);
    isLongPressedCancel = currentKeyCode == KeyEvent.KEYCODE_BACK;
    if (currentKeyCode == KeyEvent.KEYCODE_HOME) {
        isLongPressedHome = true;
    }
    if (currentKeyCode == KeyEvent.KEYCODE_APP_SWITCH) {
        isLongPressedRecent = true;
    }
    KeyPressedTipViewController.getInstance().show(null);
}
 
源代码8 项目: Pi-Locker   文件: Lock.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

	return keyCode == KeyEvent.KEYCODE_HOME
			|| keyCode == KeyEvent.KEYCODE_BACK
			|| keyCode == KeyEvent.KEYCODE_APP_SWITCH
			|| keyCode == KeyEvent.KEYCODE_SOFT_LEFT
			|| keyCode == KeyEvent.KEYCODE_SOFT_RIGHT;
	
}
 
源代码9 项目: NewsMe   文件: SplashActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) {
		return true;
	}
	return super.onKeyDown(keyCode, event);
}
 

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		tryAgain();
		return true;
	} else if (keyCode == KeyEvent.KEYCODE_HOME) {
		finish();
		return true;
	}
	
	return super.onKeyDown(keyCode, event);
}
 

/**
 * 开屏页最好禁止用户对返回按钮的控制
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) {
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
源代码12 项目: product-emm   文件: AppListActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        loadHomeScreen();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_HOME) {
        loadHomeScreen();
        return true;
    }
    else {
        return super.onKeyDown(keyCode, event);
    }
}
 
源代码13 项目: talkback   文件: KeyComboManager.java

/**
 * Returns converted key code. This method converts the following key events. - Convert
 * KEYCODE_HOME with meta to KEYCODE_ENTER. - Convert KEYCODE_BACK with meta to KEYCODE_DEL.
 *
 * @param event Key event to be converted.
 * @return Converted key code.
 */
static int getConvertedKeyCode(KeyEvent event) {
  // We care only when meta key is pressed with.
  if ((event.getModifiers() & KeyEvent.META_META_ON) == 0) {
    return event.getKeyCode();
  }

  if (event.getKeyCode() == KeyEvent.KEYCODE_HOME) {
    return KeyEvent.KEYCODE_ENTER;
  } else if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
    return KeyEvent.KEYCODE_DEL;
  } else {
    return event.getKeyCode();
  }
}
 

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		loadHomeScreen();
		return true;
	} else if (keyCode == KeyEvent.KEYCODE_HOME) {
		loadHomeScreen();
		return true;
	}
	else {
		return super.onKeyDown(keyCode, event);
	}
}
 
源代码15 项目: LaunchTime   文件: FeedbackActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode==KeyEvent.KEYCODE_HOME) {
        Intent home = new Intent(this, MainActivity.class);
        startActivity(home);
        finish();
    } else if (keyCode==KeyEvent.KEYCODE_MENU) {
        Intent sett = new Intent(this, SettingsActivity.class);
        startActivity(sett);
        finish();
    }
    return super.onKeyDown(keyCode, event);
}
 
源代码16 项目: LaunchTime   文件: AboutActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode==KeyEvent.KEYCODE_HOME) {
        Intent home = new Intent(this, MainActivity.class);
        startActivity(home);
        finish();
    } else if (keyCode==KeyEvent.KEYCODE_MENU) {
        Intent sett = new Intent(this, SettingsActivity.class);
        startActivity(sett);
        finish();
    }
    return super.onKeyDown(keyCode, event);
}
 
源代码17 项目: LaunchTime   文件: SettingsActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode==KeyEvent.KEYCODE_HOME || keyCode==KeyEvent.KEYCODE_MENU) {
        Intent main = new Intent(this, MainActivity.class);
        startActivity(main);
        setResult(RESULT_OK);
        finish();
    }
    return super.onKeyDown(keyCode, event);
}
 

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		Intent i = new Intent();
		i.setAction(Intent.ACTION_MAIN);
		i.addCategory(Intent.CATEGORY_HOME);
		this.startActivity(i);
		return true;
	} else if (keyCode == KeyEvent.KEYCODE_HOME) {
		this.finish();
		return true;
	}
	return super.onKeyDown(keyCode, event);
}
 
源代码19 项目: DoraemonKit   文件: AbsDokitView.java

/**
 * 执行floatPage create
 *
 * @param context 上下文环境
 */
@SuppressLint("ClickableViewAccessibility")
void performCreate(Context context) {
    try {
        //调用onCreate方法
        onCreate(context);
        if (!isNormalMode()) {
            DokitViewManager.getInstance().addDokitViewAttachedListener(this);
        }
        if (isNormalMode()) {
            mRootView = new DokitFrameLayout(context);
        } else {
            //系统悬浮窗的返回按键监听
            mRootView = new DokitFrameLayout(context) {
                @Override
                public boolean dispatchKeyEvent(KeyEvent event) {
                    if (event.getAction() == KeyEvent.ACTION_UP && shouldDealBackKey()) {
                        //监听返回键
                        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK || event.getKeyCode() == KeyEvent.KEYCODE_HOME) {
                            return onBackPressed();
                        }
                    }
                    return super.dispatchKeyEvent(event);
                }
            };
        }
        //添加根布局的layout回调
        addViewTreeObserverListener();


        //调用onCreateView抽象方法
        mChildView = onCreateView(context, mRootView);
        //将子View添加到rootview中
        mRootView.addView(mChildView);
        //设置根布局的手势拦截
        mRootView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (getRootView() != null) {
                    return mTouchProxy.onTouchEvent(v, event);
                } else {
                    return false;
                }
            }
        });
        //调用onViewCreated回调
        onViewCreated(mRootView);

        mDokitViewLayoutParams = new DokitViewLayoutParams();
        //分别创建对应的LayoutParams
        if (isNormalMode()) {
            mFrameLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
            mFrameLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
            mDokitViewLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
        } else {
            mWindowLayoutParams = new WindowManager.LayoutParams();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                //android 8.0
                mWindowLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
            } else {
                mWindowLayoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
            }
            if (!shouldDealBackKey()) {
                //参考:http://www.shirlman.com/tec/20160426/362
                //设置WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE会导致rootview监听不到返回按键的监听失效
                mWindowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
                mDokitViewLayoutParams.flags = DokitViewLayoutParams.FLAG_NOT_FOCUSABLE;
            }
            mWindowLayoutParams.format = PixelFormat.TRANSPARENT;
            mWindowLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
            mDokitViewLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
            //动态注册关闭系统弹窗的广播
            IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
            context.registerReceiver(mInnerReceiver, intentFilter);
        }
        initDokitViewLayoutParams(mDokitViewLayoutParams);
        if (isNormalMode()) {
            onNormalLayoutParamsCreated(mFrameLayoutParams);
        } else {
            onSystemLayoutParamsCreated(mWindowLayoutParams);
        }
    } catch (Exception e) {
        LogHelper.e(TAG, "e===>" + e.getMessage());
        e.printStackTrace();
    }

}
 
源代码20 项目: XposedNavigationBar   文件: BtnsNavbar.java

@Override
protected void longHome() {
    KeyEvent keyEvent = new KeyEvent(KeyEvent.FLAG_LONG_PRESS, KeyEvent.KEYCODE_HOME);
    mInst.sendKeySync(keyEvent);
}
 
源代码评论
动弹
沙发等你来抢
 方法所在类
 同类方法