use of rocks.tbog.tblauncher.utils.KeyboardTriggerBehaviour in project TBLauncher by TBog.
the class Behaviour method onCreateActivity.
public void onCreateActivity(TBLauncherActivity tbLauncherActivity) {
mTBLauncherActivity = tbLauncherActivity;
mPref = PreferenceManager.getDefaultSharedPreferences(mTBLauncherActivity);
Window window = mTBLauncherActivity.getWindow();
mDecorView = window.getDecorView();
KeyboardTriggerBehaviour keyboardListener = new KeyboardTriggerBehaviour(mTBLauncherActivity);
keyboardListener.observe(mTBLauncherActivity, status -> {
LauncherState state = TBApplication.state();
if (status == KeyboardTriggerBehaviour.Status.CLOSED) {
boolean keyboardClosedByUser = true;
if (state.getSearchBarVisibility() == LauncherState.AnimatedVisibility.ANIM_TO_VISIBLE) {
Log.i(TAG, "keyboard closed - app start");
// don't call onKeyboardClosed() when we start the app
keyboardClosedByUser = false;
} else if (mRecycleScrollListener.isClosedOnScroll()) {
Log.i(TAG, "keyboard closed - scrolling results");
// keyboard closed because the result list was scrolled
keyboardClosedByUser = false;
} else if (isFragmentDialogVisible()) {
Log.i(TAG, "keyboard closed - fragment dialog");
// don't send keyboard close event while we have a dialog open
keyboardClosedByUser = false;
}
if (keyboardClosedByUser) {
Log.i(TAG, "keyboard closed - user");
onKeyboardClosed();
}
if (state.isSearchBarVisible()) {
int duration = 0;
if (mPref.getBoolean("search-bar-animation", true))
duration = UI_ANIMATION_DURATION;
mTBLauncherActivity.customizeUI.collapseSearchPill(duration);
}
} else {
if (state.isSearchBarVisible()) {
int duration = 0;
if (mPref.getBoolean("search-bar-animation", true))
duration = UI_ANIMATION_DURATION;
mTBLauncherActivity.customizeUI.expandSearchPill(duration);
mSearchEditText.requestFocus();
}
}
});
initKeyboardScrollHider();
initResultLayout();
initSearchBarContainer();
mNotificationBackground = findViewById(R.id.notificationBackground);
mWidgetContainer = findViewById(R.id.widgetContainer);
// mSearchBarContainer = findViewById(R.id.searchBarContainer);
// mLauncherButton = mSearchBarContainer.findViewById(R.id.launcherButton);
// mSearchEditText = mSearchBarContainer.findViewById(R.id.launcherSearch);
// mClearButton = mSearchBarContainer.findViewById(R.id.clearButton);
// mMenuButton = mSearchBarContainer.findViewById(R.id.menuButton);
// WindowCompat.setDecorFitsSystemWindows(window, false);
// ViewCompat.setOnApplyWindowInsetsListener(window.getDecorView(), (v, insets) -> {
// int left = v.getPaddingLeft();
// int top = v.getPaddingTop();
// int right = v.getPaddingRight();
// int bottom = v.getPaddingBottom();
// @WindowInsetsCompat.Type.InsetsType
// int type = WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.ime();
// v.setPadding(left, top, right, insets.getInsets(type).bottom);
// return insets;
// });
initLauncherButton();
initLauncherSearchEditText();
// menu button / 3 dot button actions
mMenuButton.setOnClickListener(v -> {
Context ctx = v.getContext();
ListPopup menu = getMenuPopup(ctx);
registerPopup(menu);
menu.showCenter(v);
});
mMenuButton.setOnLongClickListener(v -> {
Context ctx = v.getContext();
ListPopup menu = getMenuPopup(ctx);
// check if menu contains elements and if yes show it
if (!menu.getAdapter().isEmpty()) {
registerPopup(menu);
menu.show(v, 0f);
return true;
}
return false;
});
// clear button actions
mClearButton.setOnClickListener(v -> clearSearch());
mClearButton.setOnLongClickListener(v -> {
clearSearch();
Context ctx = v.getContext();
ListPopup menu = getMenuPopup(ctx);
// check if menu contains elements and if yes show it
if (!menu.getAdapter().isEmpty()) {
registerPopup(menu);
menu.show(v);
return true;
}
return false;
});
}
Aggregations