Search in sources :

Example 16 with AppEntry

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;
}
Also used : AppEntry(com.farmerbb.taskbar.util.AppEntry) SharedPreferences(android.content.SharedPreferences) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout) NonNull(androidx.annotation.NonNull)

Example 17 with AppEntry

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);
        }
    }
}
Also used : AppEntry(com.farmerbb.taskbar.util.AppEntry) SharedPreferences(android.content.SharedPreferences)

Example 18 with AppEntry

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();
}
Also used : AppEntry(com.farmerbb.taskbar.util.AppEntry) UserManager(android.os.UserManager) Intent(android.content.Intent)

Example 19 with AppEntry

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;
}
Also used : Field(java.lang.reflect.Field) AppEntry(com.farmerbb.taskbar.util.AppEntry) ArrayList(java.util.ArrayList) ActivityManager(android.app.ActivityManager) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) ActivityNotFoundException(android.content.ActivityNotFoundException) TargetApi(android.annotation.TargetApi)

Example 20 with AppEntry

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;
}
Also used : AppEntry(com.farmerbb.taskbar.util.AppEntry) ArrayList(java.util.ArrayList) UsageStatsManager(android.app.usage.UsageStatsManager) UsageStats(android.app.usage.UsageStats) TargetApi(android.annotation.TargetApi)

Aggregations

AppEntry (com.farmerbb.taskbar.util.AppEntry)25 SuppressLint (android.annotation.SuppressLint)13 ArrayList (java.util.ArrayList)12 SharedPreferences (android.content.SharedPreferences)11 TargetApi (android.annotation.TargetApi)10 Point (android.graphics.Point)10 UserManager (android.os.UserManager)10 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)9 Intent (android.content.Intent)8 LauncherApps (android.content.pm.LauncherApps)8 View (android.view.View)7 ComponentName (android.content.ComponentName)6 PackageManager (android.content.pm.PackageManager)6 ImageView (android.widget.ImageView)6 ActivityNotFoundException (android.content.ActivityNotFoundException)5 Drawable (android.graphics.drawable.Drawable)5 Handler (android.os.Handler)5 TextView (android.widget.TextView)5 PinnedBlockedApps (com.farmerbb.taskbar.util.PinnedBlockedApps)5 Context (android.content.Context)4