use of com.farmerbb.taskbar.util.TaskbarPosition in project Taskbar by farmerbb.
the class StartMenuController method drawStartMenu.
private void drawStartMenu(UIHost host) {
IconCache.getInstance(context).clearCache();
final SharedPreferences pref = U.getSharedPreferences(context);
boolean shouldShowSearchBox = shouldShowSearchBox(pref, hasHardwareKeyboard);
// Initialize layout params
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
TaskbarPosition.setCachedRotation(windowManager.getDefaultDisplay().getRotation());
final ViewParams params = new ViewParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, -1, shouldShowSearchBox ? 0 : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, getBottomMargin(context));
// Determine where to show the start menu on screen
String taskbarPosition = TaskbarPosition.getTaskbarPosition(context);
int layoutId = getStartMenuLayoutId(taskbarPosition);
params.gravity = getStartMenuGravity(taskbarPosition);
// Initialize views
layout = (StartMenuLayout) LayoutInflater.from(U.wrapContext(context)).inflate(layoutId, null);
layout.setAlpha(0);
startMenu = layout.findViewById(R.id.start_menu);
if ((shouldShowSearchBox && !hasHardwareKeyboard) || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
layout.viewHandlesBackButton();
boolean scrollbar = pref.getBoolean(PREF_SCROLLBAR, false);
startMenu.setFastScrollEnabled(scrollbar);
startMenu.setFastScrollAlwaysVisible(scrollbar);
startMenu.setScrollBarStyle(scrollbar ? View.SCROLLBARS_OUTSIDE_INSET : View.SCROLLBARS_INSIDE_OVERLAY);
if (pref.getBoolean(PREF_TRANSPARENT_START_MENU, false))
startMenu.setBackgroundColor(0);
if (pref.getBoolean(PREF_VISUAL_FEEDBACK, true))
startMenu.setRecyclerListener(view -> view.setBackgroundColor(0));
int columns = context.getResources().getInteger(R.integer.tb_start_menu_columns);
boolean isGrid = pref.getString(PREF_START_MENU_LAYOUT, "grid").equals("grid");
if (isGrid) {
ViewGroup.LayoutParams startMenuParams = startMenu.getLayoutParams();
startMenuParams.width = (int) (startMenuParams.width * (columns / 3f));
startMenu.setLayoutParams(startMenuParams);
}
searchView = layout.findViewById(R.id.search);
searchViewClicked = false;
int backgroundTint = U.getBackgroundTint(context);
FrameLayout startMenuFrame = layout.findViewById(R.id.start_menu_frame);
FrameLayout searchViewLayout = layout.findViewById(R.id.search_view_layout);
startMenuFrame.setBackgroundColor(backgroundTint);
searchViewLayout.setBackgroundColor(backgroundTint);
if (shouldShowSearchBox) {
if (!hasHardwareKeyboard)
searchView.setIconifiedByDefault(true);
searchView.setOnTouchListener((v, event) -> {
searchViewClicked = true;
return false;
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (!hasSubmittedQuery) {
ListAdapter adapter = startMenu.getAdapter();
if (adapter != null) {
hasSubmittedQuery = true;
if (adapter.getCount() > 0) {
View view = adapter.getView(0, null, startMenu);
LinearLayout layout = view.findViewById(R.id.entry);
layout.performClick();
} else {
if (U.shouldCollapse(context, true)) {
U.sendBroadcast(context, ACTION_HIDE_TASKBAR);
} else {
hideStartMenu(true);
}
Intent intent = generateQueryWebSearchIntent(query);
if (intent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(intent);
} else {
intent = generateQueryGoogleIntent(query);
try {
context.startActivity(intent);
} catch (ActivityNotFoundException ignored) {
}
}
}
}
}
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
searchView.setIconified(false);
View closeButton = searchView.findViewById(R.id.search_close_btn);
if (closeButton != null)
closeButton.setVisibility(View.GONE);
refreshApps(newText, false);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
U.newHandler().postDelayed(() -> {
EditText editText = searchView.findViewById(R.id.search_src_text);
if (editText != null) {
editText.requestFocus();
editText.setSelection(editText.getText().length());
}
}, 50);
}
return true;
}
});
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
LinearLayout powerButton = layout.findViewById(R.id.power_button);
powerButton.setOnClickListener(view -> {
int[] location = new int[2];
view.getLocationOnScreen(location);
openContextMenu(location);
});
powerButton.setOnGenericMotionListener((view, motionEvent) -> {
if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
int[] location = new int[2];
view.getLocationOnScreen(location);
openContextMenu(location);
}
return false;
});
searchViewLayout.setOnClickListener(view -> searchView.setIconified(false));
startMenu.setOnItemClickListener((viewParent, view, position, id) -> {
hideStartMenu(true);
AppEntry entry = (AppEntry) viewParent.getAdapter().getItem(position);
U.launchApp(context, entry, null, false, false, view);
});
View childLayout = layout.findViewById(R.id.search_view_child_layout);
if (pref.getBoolean(PREF_TRANSPARENT_START_MENU, false))
childLayout.setBackgroundColor(0);
if (isGrid) {
ViewGroup.LayoutParams childLayoutParams = childLayout.getLayoutParams();
childLayoutParams.width = (int) (childLayoutParams.width * (columns / 3f));
childLayout.setLayoutParams(childLayoutParams);
}
} else
searchViewLayout.setVisibility(View.GONE);
applyMarginFix(host, layout, params);
textView = layout.findViewById(R.id.no_apps_found);
U.registerReceiver(context, toggleReceiver, ACTION_TOGGLE_START_MENU);
U.registerReceiver(context, hideReceiver, ACTION_HIDE_START_MENU);
U.registerReceiver(context, hideReceiverNoReset, ACTION_HIDE_START_MENU_NO_RESET);
U.registerReceiver(context, showSpaceReceiver, ACTION_SHOW_START_MENU_SPACE);
U.registerReceiver(context, hideSpaceReceiver, ACTION_HIDE_START_MENU_SPACE);
U.registerReceiver(context, resetReceiver, ACTION_RESET_START_MENU);
handler = U.newHandler();
refreshApps(true);
host.addView(layout, params);
}
use of com.farmerbb.taskbar.util.TaskbarPosition in project Taskbar by farmerbb.
the class TaskbarController method drawTaskbar.
private void drawTaskbar(UIHost host) {
IconCache.getInstance(context).clearCache();
// Initialize layout params
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
TaskbarPosition.setCachedRotation(windowManager.getDefaultDisplay().getRotation());
final ViewParams params = new ViewParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, -1, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, getBottomMargin(context));
// Determine where to show the taskbar on screen
String taskbarPosition = TaskbarPosition.getTaskbarPosition(context);
params.gravity = getTaskbarGravity(taskbarPosition);
int layoutId = getTaskbarLayoutId(taskbarPosition);
positionIsVertical = TaskbarPosition.isVertical(taskbarPosition);
// Initialize views
SharedPreferences pref = U.getSharedPreferences(context);
boolean altButtonConfig = pref.getBoolean(PREF_ALT_BUTTON_CONFIG, false);
layout = (LinearLayout) LayoutInflater.from(U.wrapContext(context)).inflate(layoutId, null);
taskbar = layout.findViewById(R.id.taskbar);
scrollView = layout.findViewById(R.id.taskbar_scrollview);
int backgroundTint = U.getBackgroundTint(context);
int accentColor = U.getAccentColor(context);
if (altButtonConfig) {
space = layout.findViewById(R.id.space_alt);
layout.findViewById(R.id.space).setVisibility(View.GONE);
} else {
space = layout.findViewById(R.id.space);
layout.findViewById(R.id.space_alt).setVisibility(View.GONE);
}
space.setOnClickListener(v -> toggleTaskbar(true));
startButton = layout.findViewById(R.id.start_button);
drawStartButton(context, startButton, pref);
refreshInterval = (int) (Float.parseFloat(pref.getString(PREF_REFRESH_FREQUENCY, "1")) * 1000);
if (refreshInterval == 0)
refreshInterval = 100;
sortOrder = pref.getString(PREF_SORT_ORDER, "false");
runningAppsOnly = PREF_RECENTS_AMOUNT_RUNNING_APPS_ONLY.equals(pref.getString(PREF_RECENTS_AMOUNT, PREF_RECENTS_AMOUNT_PAST_DAY));
searchInterval = getSearchInterval(pref);
U.sendBroadcast(context, ACTION_HIDE_START_MENU);
U.sendBroadcast(context, ACTION_UPDATE_HOME_SCREEN_MARGINS);
if (altButtonConfig) {
button = layout.findViewById(R.id.hide_taskbar_button_alt);
layout.findViewById(R.id.hide_taskbar_button).setVisibility(View.GONE);
} else {
button = layout.findViewById(R.id.hide_taskbar_button);
layout.findViewById(R.id.hide_taskbar_button_alt).setVisibility(View.GONE);
}
try {
button.setTypeface(Typeface.createFromFile("/system/fonts/Roboto-Regular.ttf"));
} catch (RuntimeException ignored) {
}
updateButton(false);
button.setOnClickListener(v -> toggleTaskbar(true));
LinearLayout buttonLayout = layout.findViewById(altButtonConfig ? R.id.hide_taskbar_button_layout_alt : R.id.hide_taskbar_button_layout);
if (buttonLayout != null)
buttonLayout.setOnClickListener(v -> toggleTaskbar(true));
LinearLayout buttonLayoutToHide = layout.findViewById(altButtonConfig ? R.id.hide_taskbar_button_layout : R.id.hide_taskbar_button_layout_alt);
if (buttonLayoutToHide != null)
buttonLayoutToHide.setVisibility(View.GONE);
dashboardButton = layout.findViewById(R.id.dashboard_button);
navbarButtons = layout.findViewById(R.id.navbar_buttons);
dashboardEnabled = drawDashboardButton(context, layout, dashboardButton, accentColor);
navbarButtonsEnabled = drawNavbarButtons(context, layout, pref, accentColor);
if (!navbarButtonsEnabled)
navbarButtons.setVisibility(View.GONE);
sysTrayEnabled = U.isSystemTrayEnabled(context);
if (sysTrayEnabled) {
drawSysTray(context, layoutId, layout);
}
layout.setBackgroundColor(backgroundTint);
layout.findViewById(R.id.divider).setBackgroundColor(pref.getBoolean(PREF_CENTERED_ICONS, false) ? 0 : accentColor);
button.setTextColor(accentColor);
applyMarginFix(host, layout, params);
if (isFirstStart && FreeformHackHelper.getInstance().isInFreeformWorkspace())
showTaskbar(false);
else if (!pref.getBoolean(PREF_COLLAPSED, false) && pref.getBoolean(PREF_TASKBAR_ACTIVE, false))
toggleTaskbar(false);
if (pref.getBoolean(PREF_AUTO_HIDE_NAVBAR, false))
U.showHideNavigationBar(context, false);
if (FreeformHackHelper.getInstance().isTouchAbsorberActive()) {
U.sendBroadcast(context, ACTION_FINISH_FREEFORM_ACTIVITY);
U.newHandler().postDelayed(() -> U.startTouchAbsorberActivity(context), 500);
}
U.registerReceiver(context, showReceiver, ACTION_SHOW_TASKBAR);
U.registerReceiver(context, hideReceiver, ACTION_HIDE_TASKBAR);
U.registerReceiver(context, tempShowReceiver, ACTION_TEMP_SHOW_TASKBAR);
U.registerReceiver(context, tempHideReceiver, ACTION_TEMP_HIDE_TASKBAR);
U.registerReceiver(context, startMenuAppearReceiver, ACTION_START_MENU_APPEARING);
U.registerReceiver(context, startMenuDisappearReceiver, ACTION_START_MENU_DISAPPEARING);
if (sysTrayEnabled) {
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
manager.listen(listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
U.registerReceiver(context, notificationCountReceiver, ACTION_NOTIFICATION_COUNT_CHANGED);
U.sendBroadcast(context, ACTION_REQUEST_NOTIFICATION_COUNT);
}
matchParent = false;
updateParamsRunnable = () -> {
ViewParams newParams;
if (TaskbarPosition.isVertical(context)) {
newParams = matchParent ? params.updateHeight(WindowManager.LayoutParams.MATCH_PARENT) : params.updateHeight(WindowManager.LayoutParams.WRAP_CONTENT);
} else {
newParams = matchParent ? params.updateWidth(WindowManager.LayoutParams.MATCH_PARENT) : params.updateWidth(WindowManager.LayoutParams.WRAP_CONTENT);
}
try {
host.updateViewLayout(layout, newParams);
} catch (IllegalArgumentException ignored) {
}
};
startRefreshingRecents();
host.addView(layout, params);
isFirstStart = false;
}
Aggregations