use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.
the class StartMenuAdapter method getView.
@Override
@NonNull
public View getView(int position, View convertView, @NonNull final ViewGroup parent) {
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(isGrid ? R.layout.tb_row_alt : R.layout.tb_row, parent, false);
convertView.setBackgroundColor(0);
}
final AppEntry entry = getItem(position);
assert entry != null;
final SharedPreferences pref = U.getSharedPreferences(getContext());
TextView textView = convertView.findViewById(R.id.name);
textView.setText(pref.getBoolean(PREF_HIDE_ICON_LABELS, false) ? "" : entry.getLabel());
textView.setTypeface(null, isTopApp(entry) ? Typeface.BOLD : Typeface.NORMAL);
textView.setTextColor(ContextCompat.getColor(getContext(), U.isDarkTheme(getContext()) ? R.color.tb_text_color_dark : R.color.tb_text_color));
ImageView imageView = convertView.findViewById(R.id.icon);
imageView.setImageDrawable(entry.getIcon(getContext()));
LinearLayout layout = convertView.findViewById(R.id.entry);
layout.setOnClickListener(view -> {
U.sendBroadcast(getContext(), ACTION_HIDE_START_MENU);
U.launchApp(getContext(), entry, null, false, false, view);
});
layout.setOnLongClickListener(view -> {
int[] location = new int[2];
view.getLocationOnScreen(location);
openContextMenu(entry, location);
return true;
});
boolean visualFeedbackEnabled = pref.getBoolean(PREF_VISUAL_FEEDBACK, 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 && visualFeedbackEnabled)
view.setBackgroundColor(0);
return false;
});
if (visualFeedbackEnabled) {
layout.setOnHoverListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
int backgroundTint = pref.getBoolean(PREF_TRANSPARENT_START_MENU, false) ? U.getAccentColor(getContext()) : U.getBackgroundTint(getContext());
// noinspection ResourceAsColor
backgroundTint = ColorUtils.setAlphaComponent(backgroundTint, Color.alpha(backgroundTint) / 2);
v.setBackgroundColor(backgroundTint);
}
if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT)
v.setBackgroundColor(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
v.setPointerIcon(PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_DEFAULT));
return false;
});
}
if (pref.getBoolean(PREF_VISUAL_FEEDBACK, true)) {
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 StartMenuAdapter method updateList.
private void updateList(List<AppEntry> list, boolean firstUpdate) {
if (!firstUpdate) {
clear();
sections.clear();
gsfpCache.clear();
gpfsCache.clear();
topAppsCache.clear();
addAll(list);
}
SharedPreferences pref = U.getSharedPreferences(getContext());
if (pref.getBoolean(PREF_SCROLLBAR, false)) {
for (AppEntry entry : list) {
char firstLetter = getSectionForAppEntry(entry);
if (!sections.contains(firstLetter))
sections.add(firstLetter);
}
}
}
use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.
the class PersistentShortcutLaunchActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
UserManager userManager = (UserManager) getSystemService(USER_SERVICE);
String packageName = getIntent().getStringExtra("package_name");
String componentName = getIntent().getStringExtra("component_name");
String windowSize = getIntent().getStringExtra("window_size");
long userId = getIntent().getLongExtra("user_id", userManager.getSerialNumberForUser(Process.myUserHandle()));
if (!U.canDrawOverlays(this) && windowSize != null) {
Intent intent = new Intent(this, DummyActivity.class);
intent.putExtra("show_permission_dialog", true);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else if (packageName != null && componentName != null) {
final AppEntry entry = new AppEntry(packageName, componentName, null, null, false);
entry.setUserId(userId);
U.launchApp(this, entry, windowSize, () -> {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + packageName));
try {
startActivity(intent, U.getActivityOptionsBundle(this, ApplicationType.APP_PORTRAIT, null));
} catch (ActivityNotFoundException | IllegalArgumentException ignored) {
}
});
} else
U.showToast(this, R.string.tb_invalid_shortcut);
finish();
}
use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.
the class TaskbarController method getAppEntriesUsingActivityManager.
@SuppressWarnings({ "deprecation", "JavaReflectionMemberAccess" })
@TargetApi(Build.VERSION_CODES.M)
private List<AppEntry> getAppEntriesUsingActivityManager(int maxNum) {
ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.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);
U.allowReflection();
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 TaskbarController method getAppEntriesUsingUsageStats.
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private List<AppEntry> getAppEntriesUsingUsageStats() {
UsageStatsManager mUsageStatsManager = (UsageStatsManager) context.getSystemService(Context.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;
}
Aggregations