Search in sources :

Example 1 with ShakeSensorUtil

use of com.example.test.andlang.util.ShakeSensorUtil in project AndLang by wugemu.

the class BaseLangActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getLayoutId());
    ButterKnife.bind(this);
    ActivityUtil.getInstance().pushOneActivity(this);
    LogUtil.d("当前创建的Activity:" + getClass().getSimpleName());
    LogUtil.d("当前activity数量:" + ActivityUtil.getInstance().getActivitySize());
    Intent intent = getIntent();
    if (intent != null) {
        boolean noChangeStatus = intent.getBooleanExtra("noChangeStatus", false);
        if (!noChangeStatus) {
            setStatusBar(1, R.color.lang_colorWhite);
        }
    }
    initView();
    initLoading();
    initPresenter();
    initData();
    initModel();
    // 测试配置
    if (BaseLangUtil.isApkInDebug()) {
        // debug 摇一摇
        if (ActivityUtil.getInstance().isFirstActivity()) {
            // 只创建和注册一次
            if (mShakeSensor == null) {
                mShakeSensor = new ShakeSensorUtil(BaseLangActivity.this, 2200);
                mShakeSensor.setShakeListener(new ShakeSensorUtil.OnShakeListener() {

                    @Override
                    public void onShakeComplete(SensorEvent event) {
                        if (!ActivityUtil.getInstance().isTopActivity(LangTestActivity.class)) {
                            // 防止重复跳转
                            Intent intent = new Intent(BaseLangActivity.this, LangTestActivity.class);
                            ActivityUtil.getInstance().start(BaseLangActivity.this, intent);
                        }
                    }
                });
            }
            if (mShakeSensor != null) {
                LogUtil.d("0.0", "注册摇一摇");
                mShakeSensor.register();
            }
        }
    }
}
Also used : ShakeSensorUtil(com.example.test.andlang.util.ShakeSensorUtil) Intent(android.content.Intent) SensorEvent(android.hardware.SensorEvent) LangTestActivity(com.example.test.andlang.test.LangTestActivity)

Aggregations

Intent (android.content.Intent)1 SensorEvent (android.hardware.SensorEvent)1 LangTestActivity (com.example.test.andlang.test.LangTestActivity)1 ShakeSensorUtil (com.example.test.andlang.util.ShakeSensorUtil)1