Search in sources :

Example 6 with AppEntry

use of com.farmerbb.taskbar.util.AppEntry 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);
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) GridView(android.widget.GridView) PackageManager(android.content.pm.PackageManager) TaskbarPosition(com.farmerbb.taskbar.util.TaskbarPosition) Uri(android.net.Uri) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) Drawable(android.graphics.drawable.Drawable) IconCache(com.farmerbb.taskbar.util.IconCache) Patterns(android.util.Patterns) TopApps(com.farmerbb.taskbar.util.TopApps) Handler(android.os.Handler) View(android.view.View) TargetApi(android.annotation.TargetApi) InvisibleActivityAlt(com.farmerbb.taskbar.activity.InvisibleActivityAlt) U(com.farmerbb.taskbar.util.U) AppEntry(com.farmerbb.taskbar.util.AppEntry) SearchView(androidx.appcompat.widget.SearchView) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) LauncherHelper(com.farmerbb.taskbar.helper.LauncherHelper) LauncherApps(android.content.pm.LauncherApps) FreeformHackHelper(com.farmerbb.taskbar.helper.FreeformHackHelper) List(java.util.List) TextView(android.widget.TextView) MenuHelper(com.farmerbb.taskbar.helper.MenuHelper) ListAdapter(android.widget.ListAdapter) ActivityNotFoundException(android.content.ActivityNotFoundException) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) SearchManager(android.app.SearchManager) EditorInfo(android.view.inputmethod.EditorInfo) Context(android.content.Context) Intent(android.content.Intent) InvisibleActivity(com.farmerbb.taskbar.activity.InvisibleActivity) InputMethodManager(android.view.inputmethod.InputMethodManager) ArrayList(java.util.ArrayList) Blacklist(com.farmerbb.taskbar.util.Blacklist) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) StartMenuLayout(com.farmerbb.taskbar.widget.StartMenuLayout) UserHandle(android.os.UserHandle) Build(android.os.Build) Collator(java.text.Collator) UserManager(android.os.UserManager) URLUtil(android.webkit.URLUtil) R(com.farmerbb.taskbar.R) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) StartMenuAdapter(com.farmerbb.taskbar.adapter.StartMenuAdapter) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) Configuration(android.content.res.Configuration) Comparator(java.util.Comparator) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) EditText(android.widget.EditText) Constants(com.farmerbb.taskbar.util.Constants) EditText(android.widget.EditText) SharedPreferences(android.content.SharedPreferences) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) GridView(android.widget.GridView) View(android.view.View) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) WindowManager(android.view.WindowManager) SearchView(androidx.appcompat.widget.SearchView) AppEntry(com.farmerbb.taskbar.util.AppEntry) ActivityNotFoundException(android.content.ActivityNotFoundException) FrameLayout(android.widget.FrameLayout) ListAdapter(android.widget.ListAdapter) LinearLayout(android.widget.LinearLayout)

Example 7 with AppEntry

use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.

the class StartMenuController method generateAppEntries.

@VisibleForTesting
List<AppEntry> generateAppEntries(Context context, UserManager userManager, PackageManager pm, List<LauncherActivityInfo> queryList) {
    final List<AppEntry> entries = new ArrayList<>();
    Drawable defaultIcon = pm.getDefaultActivityIcon();
    for (LauncherActivityInfo appInfo : queryList) {
        // Attempt to work around frequently reported OutOfMemoryErrors
        String label;
        Drawable icon;
        try {
            label = appInfo.getLabel().toString();
            icon = IconCache.getInstance(context).getIcon(context, pm, appInfo);
        } catch (OutOfMemoryError e) {
            System.gc();
            label = appInfo.getApplicationInfo().packageName;
            icon = defaultIcon;
        }
        String packageName = appInfo.getApplicationInfo().packageName;
        ComponentName componentName = new ComponentName(packageName, appInfo.getName());
        AppEntry newEntry = new AppEntry(packageName, componentName.flattenToString(), label, icon, false);
        newEntry.setUserId(userManager.getSerialNumberForUser(appInfo.getUser()));
        entries.add(newEntry);
    }
    return entries;
}
Also used : AppEntry(com.farmerbb.taskbar.util.AppEntry) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) ComponentName(android.content.ComponentName) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 8 with AppEntry

use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.

the class BackupUtils method restore.

public static void restore(Context context, BackupAgent agent) {
    // Get pinned and blocked apps
    PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context);
    pba.clear(context);
    String[] pinnedAppsPackageNames = agent.getStringArray(BACKUP_KEY_PINNED_APPS_PACKAGE_NAMES);
    String[] pinnedAppsComponentNames = agent.getStringArray(BACKUP_KEY_PINNED_APPS_COMPONENT_NAMES);
    String[] pinnedAppsLabels = agent.getStringArray(BACKUP_KEY_PINNED_APPS_LABELS);
    long[] pinnedAppsUserIds = agent.getLongArray(BACKUP_KEY_PINNED_APPS_USER_IDS);
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
    if (pinnedAppsPackageNames != null && pinnedAppsComponentNames != null && pinnedAppsLabels != null)
        for (int i = 0; i < pinnedAppsPackageNames.length; i++) {
            Intent throwaway = new Intent();
            throwaway.setComponent(ComponentName.unflattenFromString(pinnedAppsComponentNames[i]));
            long userId;
            if (pinnedAppsUserIds != null)
                userId = pinnedAppsUserIds[i];
            else
                userId = userManager.getSerialNumberForUser(Process.myUserHandle());
            AppEntry newEntry = new AppEntry(pinnedAppsPackageNames[i], pinnedAppsComponentNames[i], pinnedAppsLabels[i], IconCache.getInstance(context).getIcon(context, launcherApps.resolveActivity(throwaway, userManager.getUserForSerialNumber(userId))), true);
            newEntry.setUserId(userId);
            pba.addPinnedApp(context, newEntry);
        }
    String[] blockedAppsPackageNames = agent.getStringArray(BACKUP_KEY_BLOCKED_APPS_PACKAGE_NAMES);
    String[] blockedAppsComponentNames = agent.getStringArray(BACKUP_KEY_BLOCKED_APPS_COMPONENT_NAMES);
    String[] blockedAppsLabels = agent.getStringArray(BACKUP_KEY_BLOCKED_APPS_LABELS);
    if (blockedAppsPackageNames != null && blockedAppsComponentNames != null && blockedAppsLabels != null)
        for (int i = 0; i < blockedAppsPackageNames.length; i++) {
            pba.addBlockedApp(context, new AppEntry(blockedAppsPackageNames[i], blockedAppsComponentNames[i], blockedAppsLabels[i], null, false));
        }
    // Get blacklist
    Blacklist blacklist = Blacklist.getInstance(context);
    blacklist.clear(context);
    String[] blacklistPackageNames = agent.getStringArray(BACKUP_KEY_BLACKLIST_PACKAGE_NAMES);
    String[] blacklistLabels = agent.getStringArray(BACKUP_KEY_BLACKLIST_LABELS);
    if (blacklistPackageNames != null && blacklistLabels != null)
        for (int i = 0; i < blacklistPackageNames.length; i++) {
            blacklist.addBlockedApp(context, new BlacklistEntry(blacklistPackageNames[i], blacklistLabels[i]));
        }
    // Get top apps
    TopApps topApps = TopApps.getInstance(context);
    topApps.clear(context);
    String[] topAppsPackageNames = agent.getStringArray(BACKUP_KEY_TOP_APPS_PACKAGE_NAMES);
    String[] topAppsLabels = agent.getStringArray(BACKUP_KEY_TOP_APPS_LABELS);
    if (topAppsPackageNames != null && topAppsLabels != null)
        for (int i = 0; i < topAppsPackageNames.length; i++) {
            topApps.addTopApp(context, new BlacklistEntry(topAppsPackageNames[i], topAppsLabels[i]));
        }
    // Get saved window sizes
    if (U.canEnableFreeform(context)) {
        SavedWindowSizes savedWindowSizes = SavedWindowSizes.getInstance(context);
        savedWindowSizes.clear(context);
        String[] savedWindowSizesComponentNames = agent.getStringArray(BACKUP_KEY_SAVED_WINDOW_SIZES_COMPONENT_NAMES);
        String[] savedWindowSizesWindowSizes = agent.getStringArray(BACKUP_KEY_SAVED_WINDOW_SIZES_WINDOW_SIZES);
        if (savedWindowSizesComponentNames != null && savedWindowSizesWindowSizes != null)
            for (int i = 0; i < savedWindowSizesComponentNames.length; i++) {
                savedWindowSizes.setWindowSize(context, savedWindowSizesComponentNames[i], savedWindowSizesWindowSizes[i]);
            }
    }
    // Get shared preferences
    String contents = agent.getString(BACKUP_KEY_PREFERENCE);
    if (contents.length() > 0)
        try {
            File file = new File(getSharedPreferencePath(context));
            FileOutputStream output = new FileOutputStream(file);
            output.write(contents.getBytes());
            output.close();
        } catch (IOException ignored) {
        }
}
Also used : SavedWindowSizes(com.farmerbb.taskbar.util.SavedWindowSizes) LauncherApps(android.content.pm.LauncherApps) Intent(android.content.Intent) IOException(java.io.IOException) AppEntry(com.farmerbb.taskbar.util.AppEntry) BlacklistEntry(com.farmerbb.taskbar.util.BlacklistEntry) UserManager(android.os.UserManager) FileOutputStream(java.io.FileOutputStream) TopApps(com.farmerbb.taskbar.util.TopApps) Blacklist(com.farmerbb.taskbar.util.Blacklist) PinnedBlockedApps(com.farmerbb.taskbar.util.PinnedBlockedApps) File(java.io.File)

Example 9 with AppEntry

use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.

the class BackupUtils method backup.

public static void backup(Context context, BackupAgent agent) {
    // Get pinned and blocked apps
    PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context);
    List<AppEntry> pinnedAppsList = pba.getPinnedApps();
    String[] pinnedAppsPackageNames = new String[pinnedAppsList.size()];
    String[] pinnedAppsComponentNames = new String[pinnedAppsList.size()];
    String[] pinnedAppsLabels = new String[pinnedAppsList.size()];
    long[] pinnedAppsUserIds = new long[pinnedAppsList.size()];
    for (int i = 0; i < pinnedAppsList.size(); i++) {
        AppEntry entry = pinnedAppsList.get(i);
        pinnedAppsPackageNames[i] = entry.getPackageName();
        pinnedAppsComponentNames[i] = entry.getComponentName();
        pinnedAppsLabels[i] = entry.getLabel();
        pinnedAppsUserIds[i] = entry.getUserId(context);
    }
    agent.putStringArray(BACKUP_KEY_PINNED_APPS_PACKAGE_NAMES, pinnedAppsPackageNames);
    agent.putStringArray(BACKUP_KEY_PINNED_APPS_COMPONENT_NAMES, pinnedAppsComponentNames);
    agent.putStringArray(BACKUP_KEY_PINNED_APPS_LABELS, pinnedAppsLabels);
    agent.putLongArray(BACKUP_KEY_PINNED_APPS_USER_IDS, pinnedAppsUserIds);
    List<AppEntry> blockedAppsList = pba.getBlockedApps();
    String[] blockedAppsPackageNames = new String[blockedAppsList.size()];
    String[] blockedAppsComponentNames = new String[blockedAppsList.size()];
    String[] blockedAppsLabels = new String[blockedAppsList.size()];
    for (int i = 0; i < blockedAppsList.size(); i++) {
        AppEntry entry = blockedAppsList.get(i);
        blockedAppsPackageNames[i] = entry.getPackageName();
        blockedAppsComponentNames[i] = entry.getComponentName();
        blockedAppsLabels[i] = entry.getLabel();
    }
    agent.putStringArray(BACKUP_KEY_BLOCKED_APPS_PACKAGE_NAMES, blockedAppsPackageNames);
    agent.putStringArray(BACKUP_KEY_BLOCKED_APPS_COMPONENT_NAMES, blockedAppsComponentNames);
    agent.putStringArray(BACKUP_KEY_BLOCKED_APPS_LABELS, blockedAppsLabels);
    // Get blacklist
    Blacklist blacklist = Blacklist.getInstance(context);
    List<BlacklistEntry> blacklistList = blacklist.getBlockedApps();
    String[] blacklistPackageNames = new String[blacklistList.size()];
    String[] blacklistLabels = new String[blacklistList.size()];
    for (int i = 0; i < blacklistList.size(); i++) {
        BlacklistEntry entry = blacklistList.get(i);
        blacklistPackageNames[i] = entry.getPackageName();
        blacklistLabels[i] = entry.getLabel();
    }
    agent.putStringArray(BACKUP_KEY_BLACKLIST_PACKAGE_NAMES, blacklistPackageNames);
    agent.putStringArray(BACKUP_KEY_BLACKLIST_LABELS, blacklistLabels);
    // Get top apps
    TopApps topApps = TopApps.getInstance(context);
    List<BlacklistEntry> topAppsList = topApps.getTopApps();
    String[] topAppsPackageNames = new String[topAppsList.size()];
    String[] topAppsLabels = new String[topAppsList.size()];
    for (int i = 0; i < topAppsList.size(); i++) {
        BlacklistEntry entry = topAppsList.get(i);
        topAppsPackageNames[i] = entry.getPackageName();
        topAppsLabels[i] = entry.getLabel();
    }
    agent.putStringArray(BACKUP_KEY_TOP_APPS_PACKAGE_NAMES, topAppsPackageNames);
    agent.putStringArray(BACKUP_KEY_TOP_APPS_LABELS, topAppsLabels);
    // Get saved window sizes
    if (U.canEnableFreeform(context)) {
        SavedWindowSizes savedWindowSizes = SavedWindowSizes.getInstance(context);
        List<SavedWindowSizesEntry> savedWindowSizesList = savedWindowSizes.getSavedWindowSizes();
        String[] savedWindowSizesComponentNames = new String[savedWindowSizesList.size()];
        String[] savedWindowSizesWindowSizes = new String[savedWindowSizesList.size()];
        for (int i = 0; i < savedWindowSizesList.size(); i++) {
            SavedWindowSizesEntry entry = savedWindowSizesList.get(i);
            savedWindowSizesComponentNames[i] = entry.getComponentName();
            savedWindowSizesWindowSizes[i] = entry.getWindowSize();
        }
        agent.putStringArray(BACKUP_KEY_SAVED_WINDOW_SIZES_COMPONENT_NAMES, savedWindowSizesComponentNames);
        agent.putStringArray(BACKUP_KEY_SAVED_WINDOW_SIZES_WINDOW_SIZES, savedWindowSizesWindowSizes);
    }
    // Get shared preferences
    StringBuilder preferences = new StringBuilder();
    try {
        File file = new File(getSharedPreferencePath(context));
        FileInputStream input = new FileInputStream(file);
        InputStreamReader reader = new InputStreamReader(input);
        BufferedReader buffer = new BufferedReader(reader);
        String line = buffer.readLine();
        while (line != null) {
            preferences.append(line);
            line = buffer.readLine();
            if (line != null)
                preferences.append("\n");
        }
        reader.close();
    } catch (IOException ignored) {
    }
    agent.putString(BACKUP_KEY_PREFERENCE, preferences.toString());
}
Also used : InputStreamReader(java.io.InputStreamReader) SavedWindowSizes(com.farmerbb.taskbar.util.SavedWindowSizes) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) AppEntry(com.farmerbb.taskbar.util.AppEntry) BlacklistEntry(com.farmerbb.taskbar.util.BlacklistEntry) SavedWindowSizesEntry(com.farmerbb.taskbar.util.SavedWindowSizesEntry) BufferedReader(java.io.BufferedReader) TopApps(com.farmerbb.taskbar.util.TopApps) Blacklist(com.farmerbb.taskbar.util.Blacklist) PinnedBlockedApps(com.farmerbb.taskbar.util.PinnedBlockedApps) File(java.io.File)

Example 10 with AppEntry

use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.

the class UninstallReceiver method onReceive.

@SuppressWarnings("Convert2streamapi")
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_PACKAGE_FULLY_REMOVED)) {
        String packageName = intent.getData().getEncodedSchemeSpecificPart();
        PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context);
        List<AppEntry> pinnedApps = pba.getPinnedApps();
        List<String> componentNames = new ArrayList<>();
        for (AppEntry entry : pinnedApps) {
            if (entry.getPackageName().equals(packageName)) {
                componentNames.add(entry.getComponentName());
            }
        }
        for (String componentName : componentNames) {
            pba.removePinnedApp(context, componentName);
        }
    }
}
Also used : AppEntry(com.farmerbb.taskbar.util.AppEntry) ArrayList(java.util.ArrayList) PinnedBlockedApps(com.farmerbb.taskbar.util.PinnedBlockedApps)

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