use of com.farmerbb.taskbar.widget.StartMenuLayout 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.widget.StartMenuLayout in project Taskbar by farmerbb.
the class StartMenuService method drawStartMenu.
@SuppressLint("RtlHardcoded")
private void drawStartMenu() {
IconCache.getInstance(this).clearCache();
final SharedPreferences pref = U.getSharedPreferences(this);
final boolean hasHardwareKeyboard = getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;
switch(pref.getString("show_search_bar", "keyboard")) {
case "always":
shouldShowSearchBox = true;
break;
case "keyboard":
shouldShowSearchBox = hasHardwareKeyboard;
break;
case "never":
shouldShowSearchBox = false;
break;
}
// Initialize layout params
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
U.setCachedRotation(windowManager.getDefaultDisplay().getRotation());
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, CompatUtils.getOverlayType(), shouldShowSearchBox ? 0 : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, PixelFormat.TRANSLUCENT);
// Determine where to show the start menu on screen
switch(U.getTaskbarPosition(this)) {
case "bottom_left":
layoutId = R.layout.start_menu_left;
params.gravity = Gravity.BOTTOM | Gravity.LEFT;
break;
case "bottom_vertical_left":
layoutId = R.layout.start_menu_vertical_left;
params.gravity = Gravity.BOTTOM | Gravity.LEFT;
break;
case "bottom_right":
layoutId = R.layout.start_menu_right;
params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
break;
case "bottom_vertical_right":
layoutId = R.layout.start_menu_vertical_right;
params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
break;
case "top_left":
layoutId = R.layout.start_menu_top_left;
params.gravity = Gravity.TOP | Gravity.LEFT;
break;
case "top_vertical_left":
layoutId = R.layout.start_menu_vertical_left;
params.gravity = Gravity.TOP | Gravity.LEFT;
break;
case "top_right":
layoutId = R.layout.start_menu_top_right;
params.gravity = Gravity.TOP | Gravity.RIGHT;
break;
case "top_vertical_right":
layoutId = R.layout.start_menu_vertical_right;
params.gravity = Gravity.TOP | Gravity.RIGHT;
break;
}
// Initialize views
layout = (StartMenuLayout) LayoutInflater.from(U.wrapContext(this)).inflate(layoutId, null);
startMenu = U.findViewById(layout, R.id.start_menu);
if ((shouldShowSearchBox && !hasHardwareKeyboard) || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
layout.viewHandlesBackButton();
boolean scrollbar = pref.getBoolean("scrollbar", false);
startMenu.setFastScrollEnabled(scrollbar);
startMenu.setFastScrollAlwaysVisible(scrollbar);
startMenu.setScrollBarStyle(scrollbar ? View.SCROLLBARS_OUTSIDE_INSET : View.SCROLLBARS_INSIDE_OVERLAY);
if (pref.getBoolean("transparent_start_menu", false))
startMenu.setBackgroundColor(0);
if (U.visualFeedbackEnabled(this))
startMenu.setRecyclerListener(view -> view.setBackgroundColor(0));
searchView = U.findViewById(layout, R.id.search);
int backgroundTint = U.getBackgroundTint(this);
FrameLayout startMenuFrame = U.findViewById(layout, R.id.start_menu_frame);
FrameLayout searchViewLayout = U.findViewById(layout, R.id.search_view_layout);
startMenuFrame.setBackgroundColor(backgroundTint);
searchViewLayout.setBackgroundColor(backgroundTint);
if (shouldShowSearchBox) {
if (!hasHardwareKeyboard)
searchView.setIconifiedByDefault(true);
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 = U.findViewById(view, R.id.entry);
layout.performClick();
} else {
if (U.shouldCollapse(StartMenuService.this, true))
LocalBroadcastManager.getInstance(StartMenuService.this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_TASKBAR"));
else
LocalBroadcastManager.getInstance(StartMenuService.this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
Intent intent;
if (Patterns.WEB_URL.matcher(query).matches()) {
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(URLUtil.guessUrl(query)));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} else {
intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, query);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
if (intent.resolveActivity(getPackageManager()) != null)
startActivity(intent);
else {
Uri uri = new Uri.Builder().scheme("https").authority("www.google.com").path("search").appendQueryParameter("q", query).build();
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
/* Gracefully fail */
}
}
}
}
}
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) {
new Handler().postDelayed(() -> {
EditText editText = U.findViewById(searchView, R.id.search_src_text);
if (editText != null) {
editText.requestFocus();
editText.setSelection(editText.getText().length());
}
}, 50);
}
return true;
}
});
searchView.setOnQueryTextFocusChangeListener((view, b) -> {
if (!hasHardwareKeyboard) {
ViewGroup.LayoutParams params1 = startMenu.getLayoutParams();
params1.height = getResources().getDimensionPixelSize(b && !isSecondScreenDisablingKeyboard() ? R.dimen.start_menu_height_half : R.dimen.start_menu_height);
startMenu.setLayoutParams(params1);
}
if (!b) {
if (hasHardwareKeyboard && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1)
LocalBroadcastManager.getInstance(StartMenuService.this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
else {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
});
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
LinearLayout powerButton = U.findViewById(layout, 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((parent, view, position, id) -> {
hideStartMenu(true);
AppEntry entry = (AppEntry) parent.getAdapter().getItem(position);
U.launchApp(StartMenuService.this, entry.getPackageName(), entry.getComponentName(), entry.getUserId(StartMenuService.this), null, false, false);
});
if (pref.getBoolean("transparent_start_menu", false))
layout.findViewById(R.id.search_view_child_layout).setBackgroundColor(0);
} else
searchViewLayout.setVisibility(View.GONE);
textView = U.findViewById(layout, R.id.no_apps_found);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.unregisterReceiver(toggleReceiver);
lbm.unregisterReceiver(hideReceiver);
lbm.unregisterReceiver(hideReceiverNoReset);
lbm.unregisterReceiver(showSpaceReceiver);
lbm.unregisterReceiver(hideSpaceReceiver);
lbm.unregisterReceiver(resetReceiver);
lbm.registerReceiver(toggleReceiver, new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU"));
lbm.registerReceiver(hideReceiver, new IntentFilter("com.farmerbb.taskbar.HIDE_START_MENU"));
lbm.registerReceiver(hideReceiverNoReset, new IntentFilter("com.farmerbb.taskbar.HIDE_START_MENU_NO_RESET"));
lbm.registerReceiver(showSpaceReceiver, new IntentFilter("com.farmerbb.taskbar.SHOW_START_MENU_SPACE"));
lbm.registerReceiver(hideSpaceReceiver, new IntentFilter("com.farmerbb.taskbar.HIDE_START_MENU_SPACE"));
lbm.registerReceiver(resetReceiver, new IntentFilter("com.farmerbb.taskbar.RESET_START_MENU"));
handler = new Handler();
refreshApps(true);
windowManager.addView(layout, params);
}
Aggregations