use of com.farmerbb.taskbar.util.AppEntry 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);
}
use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.
the class TaskbarService method getAppEntriesUsingUsageStats.
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private List<AppEntry> getAppEntriesUsingUsageStats() {
UsageStatsManager mUsageStatsManager = (UsageStatsManager) getSystemService(USAGE_STATS_SERVICE);
List<UsageStats> usageStatsList = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, searchInterval, System.currentTimeMillis());
List<AppEntry> entries = new ArrayList<>();
for (UsageStats usageStats : usageStatsList) {
AppEntry newEntry = new AppEntry(usageStats.getPackageName(), null, null, null, false);
newEntry.setTotalTimeInForeground(usageStats.getTotalTimeInForeground());
newEntry.setLastTimeUsed(usageStats.getLastTimeUsed());
entries.add(newEntry);
}
return entries;
}
use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.
the class TaskbarService method getAppEntriesUsingActivityManager.
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.M)
private List<AppEntry> getAppEntriesUsingActivityManager(int maxNum) {
ActivityManager mActivityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RecentTaskInfo> usageStatsList = mActivityManager.getRecentTasks(maxNum, 0);
List<AppEntry> entries = new ArrayList<>();
for (int i = 0; i < usageStatsList.size(); i++) {
ActivityManager.RecentTaskInfo recentTaskInfo = usageStatsList.get(i);
if (recentTaskInfo.id != -1) {
String packageName = recentTaskInfo.baseActivity.getPackageName();
AppEntry newEntry = new AppEntry(packageName, null, null, null, false);
try {
Field field = ActivityManager.RecentTaskInfo.class.getField("firstActiveTime");
newEntry.setLastTimeUsed(field.getLong(recentTaskInfo));
} catch (Exception e) {
newEntry.setLastTimeUsed(i);
}
entries.add(newEntry);
}
}
return entries;
}
use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.
the class TaskbarService method getView.
private View getView(List<AppEntry> list, int position) {
View convertView = View.inflate(this, R.layout.icon, null);
final AppEntry entry = list.get(position);
final SharedPreferences pref = U.getSharedPreferences(this);
ImageView imageView = U.findViewById(convertView, R.id.icon);
ImageView imageView2 = U.findViewById(convertView, R.id.shortcut_icon);
imageView.setImageDrawable(entry.getIcon(this));
imageView2.setBackgroundColor(pref.getInt("accent_color", getResources().getInteger(R.integer.translucent_white)));
String taskbarPosition = U.getTaskbarPosition(this);
if (pref.getBoolean("shortcut_icon", true)) {
boolean shouldShowShortcutIcon;
if (taskbarPosition.contains("vertical"))
shouldShowShortcutIcon = position >= list.size() - numOfPinnedApps;
else
shouldShowShortcutIcon = position < numOfPinnedApps;
if (shouldShowShortcutIcon)
imageView2.setVisibility(View.VISIBLE);
}
if (taskbarPosition.equals("bottom_right") || taskbarPosition.equals("top_right")) {
imageView.setRotationY(180);
imageView2.setRotationY(180);
}
FrameLayout layout = U.findViewById(convertView, R.id.entry);
layout.setOnClickListener(view -> U.launchApp(TaskbarService.this, entry.getPackageName(), entry.getComponentName(), entry.getUserId(TaskbarService.this), null, true, false));
layout.setOnLongClickListener(view -> {
int[] location = new int[2];
view.getLocationOnScreen(location);
openContextMenu(entry, location);
return true;
});
layout.setOnGenericMotionListener((view, motionEvent) -> {
int action = motionEvent.getAction();
if (action == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
int[] location = new int[2];
view.getLocationOnScreen(location);
openContextMenu(entry, location);
}
if (action == MotionEvent.ACTION_SCROLL && pref.getBoolean("visual_feedback", true))
view.setBackgroundColor(0);
return false;
});
if (pref.getBoolean("visual_feedback", true)) {
layout.setOnHoverListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
int accentColor = U.getAccentColor(TaskbarService.this);
accentColor = ColorUtils.setAlphaComponent(accentColor, Color.alpha(accentColor) / 2);
v.setBackgroundColor(accentColor);
}
if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT)
v.setBackgroundColor(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
v.setPointerIcon(PointerIcon.getSystemIcon(TaskbarService.this, PointerIcon.TYPE_DEFAULT));
return false;
});
layout.setOnTouchListener((v, event) -> {
v.setAlpha(event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE ? 0.5f : 1);
return false;
});
}
return convertView;
}
use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.
the class DesktopIconAppListAdapter method getView.
@Override
public View getView(int position, View convertView, final ViewGroup parent) {
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null)
convertView = LayoutInflater.from(getContext()).inflate(R.layout.tb_desktop_icon_row, parent, false);
final AppEntry entry = getItem(position);
assert entry != null;
TextView textView = convertView.findViewById(R.id.name);
textView.setText(entry.getLabel());
ImageView imageView = convertView.findViewById(R.id.icon);
imageView.setImageDrawable(entry.getIcon(getContext()));
LinearLayout layout = convertView.findViewById(R.id.entry);
layout.setOnClickListener(view -> {
AbstractSelectAppActivity activity = (AbstractSelectAppActivity) getContext();
activity.selectApp(entry);
});
return convertView;
}
Aggregations