Java Code Examples for com.android.launcher3.util.ComponentKey

The following are top voted examples for showing how to use com.android.launcher3.util.ComponentKey. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: FlickLauncher   File: UserEventDispatcher.java   Source Code and License 6 votes vote down vote up
protected LauncherEvent createLauncherEvent(View v, Intent intent) {
    LauncherEvent event = LoggerUtils.initLauncherEvent(
            Action.TOUCH, v, Target.CONTAINER);
    event.action.touch = Action.TAP;

    // Fill in grid(x,y), pageIndex of the child and container type of the parent
    // TODO: make this percolate up the view hierarchy if needed.
    int idx = 0;
    LaunchSourceProvider provider = getLaunchProviderRecursive(v);
    if (v == null || !(v.getTag() instanceof ItemInfo) || provider == null) {
        return null;
    }
    ItemInfo itemInfo = (ItemInfo) v.getTag();
    provider.fillInLaunchSourceData(v, itemInfo, event.srcTarget[idx], event.srcTarget[idx + 1]);

    event.srcTarget[idx].intentHash = intent.hashCode();
    ComponentName cn = intent.getComponent();
    if (cn != null) {
        event.srcTarget[idx].packageNameHash = cn.getPackageName().hashCode();
        event.srcTarget[idx].componentHash = cn.hashCode();
        if (mPredictedApps != null) {
            event.srcTarget[idx].predictedRank = mPredictedApps.indexOf(
                    new ComponentKey(cn, itemInfo.user));
        }
    }
    return event;
}
 
Example 2
Project: FlickLauncher   File: IconCache.java   Source Code and License 6 votes vote down vote up
@Thunk ContentValues updateCacheAndGetContentValues(LauncherActivityInfoCompat app,
        boolean replaceExisting) {
    final ComponentKey key = new ComponentKey(app.getComponentName(), app.getUser());
    CacheEntry entry = null;
    if (!replaceExisting) {
        entry = mCache.get(key);
        // We can't reuse the entry if the high-res icon is not present.
        if (entry == null || entry.isLowResIcon || entry.icon == null) {
            entry = null;
        }
    }
    if (entry == null) {
        entry = new CacheEntry();
        entry.icon = Utilities.createBadgedIconBitmap(
                mIconProvider.getIcon(app, mIconDpi), app.getUser(),
                mContext);
    }
    entry.title = app.getLabel();
    entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser());
    mCache.put(new ComponentKey(app.getComponentName(), app.getUser()), entry);

    Bitmap lowResIcon = generateLowResIcon(entry.icon, mActivityBgColor);
    return newContentValues(entry.icon, lowResIcon, entry.title.toString(),
            app.getApplicationInfo().packageName);
}
 
Example 3
Project: FlickLauncher   File: IconCache.java   Source Code and License 6 votes vote down vote up
/**
 * Adds a default package entry in the cache. This entry is not persisted and will be removed
 * when the cache is flushed.
 */
public synchronized void cachePackageInstallInfo(String packageName, UserHandleCompat user,
        Bitmap icon, CharSequence title) {
    removeFromMemCacheLocked(packageName, user);

    ComponentKey cacheKey = getPackageKey(packageName, user);
    CacheEntry entry = mCache.get(cacheKey);

    // For icon caching, do not go through DB. Just update the in-memory entry.
    if (entry == null) {
        entry = new CacheEntry();
        mCache.put(cacheKey, entry);
    }
    if (!TextUtils.isEmpty(title)) {
        entry.title = title;
    }
    if (icon != null) {
        entry.icon = Utilities.createIconBitmap(icon, mContext);
    }
}
 
Example 4
Project: FlickLauncher   File: LauncherModel.java   Source Code and License 6 votes vote down vote up
/**
 * Clear all the shortcuts for the given package, and re-add the new shortcuts.
 */
private void updateDeepShortcutMap(
        String packageName, UserHandleCompat user, List<ShortcutInfoCompat> shortcuts) {
    if (packageName != null) {
        Iterator<ComponentKey> keysIter = mBgDeepShortcutMap.keySet().iterator();
        while (keysIter.hasNext()) {
            ComponentKey next = keysIter.next();
            if (next.componentName.getPackageName().equals(packageName)
                    && next.user.equals(user)) {
                keysIter.remove();
            }
        }
    }

    // Now add the new shortcuts to the map.
    for (ShortcutInfoCompat shortcut : shortcuts) {
        boolean shouldShowInContainer = shortcut.isEnabled()
                && (shortcut.isDeclaredInManifest() || shortcut.isDynamic());
        if (shouldShowInContainer) {
            ComponentKey targetComponent
                    = new ComponentKey(shortcut.getActivity(), shortcut.getUserHandle());
            mBgDeepShortcutMap.addToList(targetComponent, shortcut.getId());
        }
    }
}
 
Example 5
Project: SimpleUILauncher   File: UserEventDispatcher.java   Source Code and License 6 votes vote down vote up
protected LauncherEvent createLauncherEvent(View v, Intent intent) {
    LauncherEvent event = LoggerUtils.initLauncherEvent(
            Action.TOUCH, v, Target.CONTAINER);
    event.action.touch = Action.TAP;

    // Fill in grid(x,y), pageIndex of the child and container type of the parent
    // TODO: make this percolate up the view hierarchy if needed.
    int idx = 0;
    LaunchSourceProvider provider = getLaunchProviderRecursive(v);
    if (v == null || !(v.getTag() instanceof ItemInfo) || provider == null) {
        return null;
    }
    ItemInfo itemInfo = (ItemInfo) v.getTag();
    provider.fillInLaunchSourceData(v, itemInfo, event.srcTarget[idx], event.srcTarget[idx + 1]);

    event.srcTarget[idx].intentHash = intent.hashCode();
    ComponentName cn = intent.getComponent();
    if (cn != null) {
        event.srcTarget[idx].packageNameHash = cn.getPackageName().hashCode();
        event.srcTarget[idx].componentHash = cn.hashCode();
        if (mPredictedApps != null) {
            event.srcTarget[idx].predictedRank = mPredictedApps.indexOf(
                    new ComponentKey(cn, itemInfo.user));
        }
    }
    return event;
}
 
Example 6
Project: SimpleUILauncher   File: IconCache.java   Source Code and License 6 votes vote down vote up
@Thunk ContentValues updateCacheAndGetContentValues(LauncherActivityInfoCompat app,
        boolean replaceExisting) {
    final ComponentKey key = new ComponentKey(app.getComponentName(), app.getUser());
    CacheEntry entry = null;
    if (!replaceExisting) {
        entry = mCache.get(key);
        // We can't reuse the entry if the high-res icon is not present.
        if (entry == null || entry.isLowResIcon || entry.icon == null) {
            entry = null;
        }
    }
    if (entry == null) {
        entry = new CacheEntry();
        entry.icon = Utilities.createBadgedIconBitmap(
                mIconProvider.getIcon(app, mIconDpi), app.getUser(),
                mContext);
    }
    entry.title = app.getLabel();
    entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser());
    mCache.put(new ComponentKey(app.getComponentName(), app.getUser()), entry);

    Bitmap lowResIcon = generateLowResIcon(entry.icon, mActivityBgColor);
    return newContentValues(entry.icon, lowResIcon, entry.title.toString(),
            app.getApplicationInfo().packageName);
}
 
Example 7
Project: SimpleUILauncher   File: IconCache.java   Source Code and License 6 votes vote down vote up
/**
 * Adds a default package entry in the cache. This entry is not persisted and will be removed
 * when the cache is flushed.
 */
public synchronized void cachePackageInstallInfo(String packageName, UserHandleCompat user,
        Bitmap icon, CharSequence title) {
    removeFromMemCacheLocked(packageName, user);

    ComponentKey cacheKey = getPackageKey(packageName, user);
    CacheEntry entry = mCache.get(cacheKey);

    // For icon caching, do not go through DB. Just update the in-memory entry.
    if (entry == null) {
        entry = new CacheEntry();
        mCache.put(cacheKey, entry);
    }
    if (!TextUtils.isEmpty(title)) {
        entry.title = title;
    }
    if (icon != null) {
        entry.icon = Utilities.createIconBitmap(icon, mContext);
    }
}
 
Example 8
Project: SimpleUILauncher   File: LauncherModel.java   Source Code and License 6 votes vote down vote up
/**
 * Clear all the shortcuts for the given package, and re-add the new shortcuts.
 */
private void updateDeepShortcutMap(
        String packageName, UserHandleCompat user, List<ShortcutInfoCompat> shortcuts) {
    if (packageName != null) {
        Iterator<ComponentKey> keysIter = mBgDeepShortcutMap.keySet().iterator();
        while (keysIter.hasNext()) {
            ComponentKey next = keysIter.next();
            if (next.componentName.getPackageName().equals(packageName)
                    && next.user.equals(user)) {
                keysIter.remove();
            }
        }
    }

    // Now add the new shortcuts to the map.
    for (ShortcutInfoCompat shortcut : shortcuts) {
        boolean shouldShowInContainer = shortcut.isEnabled()
                && (shortcut.isDeclaredInManifest() || shortcut.isDynamic());
        if (shouldShowInContainer) {
            ComponentKey targetComponent
                    = new ComponentKey(shortcut.getActivity(), shortcut.getUserHandle());
            mBgDeepShortcutMap.addToList(targetComponent, shortcut.getId());
        }
    }
}
 
Example 9
Project: Trebuchet   File: IconCache.java   Source Code and License 6 votes vote down vote up
@Thunk ContentValues updateCacheAndGetContentValues(LauncherActivityInfoCompat app,
        boolean replaceExisting) {
    final ComponentKey key = new ComponentKey(app.getComponentName(), app.getUser());
    CacheEntry entry = null;
    if (!replaceExisting) {
        entry = mCache.get(key);
        // We can't reuse the entry if the high-res icon is not present.
        if (entry == null || entry.isLowResIcon || entry.icon == null) {
            entry = null;
        }
    }
    if (entry == null) {
        entry = new CacheEntry();
        entry.icon = Utilities.createIconBitmap(app.getBadgedIcon(mIconDpi), mContext);
    }
    entry.title = app.getLabel();
    entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser());
    mCache.put(new ComponentKey(app.getComponentName(), app.getUser()), entry);

    return newContentValues(entry.icon, entry.title.toString(), mActivityBgColor);
}
 
Example 10
Project: Trebuchet   File: IconCache.java   Source Code and License 6 votes vote down vote up
/**
 * Adds a default package entry in the cache. This entry is not persisted and will be removed
 * when the cache is flushed.
 */
public synchronized void cachePackageInstallInfo(String packageName, UserHandleCompat user,
        Bitmap icon, CharSequence title) {
    removeFromMemCacheLocked(packageName, user);

    ComponentKey cacheKey = getPackageKey(packageName, user);
    CacheEntry entry = mCache.get(cacheKey);

    // For icon caching, do not go through DB. Just update the in-memory entry.
    if (entry == null) {
        entry = new CacheEntry();
        mCache.put(cacheKey, entry);
    }
    if (!TextUtils.isEmpty(title)) {
        entry.title = title;
    }
    if (icon != null) {
        entry.icon = Utilities.createIconBitmap(icon, mContext);
    }
}
 
Example 11
Project: FlickLauncher   File: Launcher.java   Source Code and License 5 votes vote down vote up
/**
 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
 * resumed.
 */
public void tryAndUpdatePredictedApps() {
    List<ComponentKey> apps;
    if (mLauncherCallbacks != null) {
        apps = mLauncherCallbacks.getPredictedApps();
    } else {
        apps = predictiveAppsProvider.getPredictions();
        predictiveAppsProvider.updateTopPredictedApps();
    }

    if (apps != null) {
        mAppsView.setPredictedApps(apps);
    }
}
 
Example 12
Project: FlickLauncher   File: Launcher.java   Source Code and License 5 votes vote down vote up
public List<String> getShortcutIdsForItem(ItemInfo info) {
    if (!DeepShortcutManager.supportsShortcuts(info)) {
        return Collections.EMPTY_LIST;
    }
    ComponentName component = info.getTargetComponent();
    if (component == null) {
        return Collections.EMPTY_LIST;
    }

    List<String> ids = mDeepShortcutMap.get(new ComponentKey(component, info.user));
    return ids == null ? Collections.EMPTY_LIST : ids;
}
 
Example 13
Project: FlickLauncher   File: AppWidgetManagerCompatV16.java   Source Code and License 5 votes vote down vote up
@Override
public HashMap<ComponentKey, AppWidgetProviderInfo> getAllProvidersMap() {
    HashMap<ComponentKey, AppWidgetProviderInfo> result = new HashMap<>();
    UserHandleCompat user = UserHandleCompat.myUserHandle();
    for (AppWidgetProviderInfo info : mAppWidgetManager.getInstalledProviders()) {
        result.put(new ComponentKey(info.provider, user), info);
    }
    return result;
}
 
Example 14
Project: FlickLauncher   File: AppWidgetManagerCompatVL.java   Source Code and License 5 votes vote down vote up
@Override
public HashMap<ComponentKey, AppWidgetProviderInfo> getAllProvidersMap() {
    HashMap<ComponentKey, AppWidgetProviderInfo> result = new HashMap<>();
    for (UserHandle user : mUserManager.getUserProfiles()) {
        UserHandleCompat userHandle = UserHandleCompat.fromUser(user);
        for (AppWidgetProviderInfo info :
                mAppWidgetManager.getInstalledProvidersForProfile(user)) {
            result.put(new ComponentKey(info.provider, userHandle), info);
        }
    }
    return result;
}
 
Example 15
Project: FlickLauncher   File: DefaultAppSearchAlgorithm.java   Source Code and License 5 votes vote down vote up
public void doSearch(final String query,
        final AllAppsSearchBarController.Callbacks callback) {
    final ArrayList<ComponentKey> result = getTitleMatchResult(query);
    mResultHandler.post(new Runnable() {

        @Override
        public void run() {
            callback.onSearchResult(query, result);
        }
    });
}
 
Example 16
Project: FlickLauncher   File: DefaultAppSearchAlgorithm.java   Source Code and License 5 votes vote down vote up
protected ArrayList<ComponentKey> getTitleMatchResult(String query) {
    // Do an intersection of the words in the query and each title, and filter out all the
    // apps that don't match all of the words in the query.
    final String queryTextLower = query.toLowerCase();
    final ArrayList<ComponentKey> result = new ArrayList<>();
    for (AppInfo info : mApps) {
        if (matches(info, queryTextLower)) {
            result.add(info.toComponentKey());
        }
    }
    return result;
}
 
Example 17
Project: FlickLauncher   File: PredictiveAppsProvider.java   Source Code and License 5 votes vote down vote up
public List<ComponentKey> getPredictions() {
    String predictions = sharedPreferences.getString(TOP_PREDICTIVE_APPS_KEY, "");
    if (predictions.isEmpty()) {
        return new ArrayList<>();
    }

    String[] topPredictions = predictions.split(" ");
    List<ComponentKey> keys = new ArrayList<>();

    for (int i = 0; i < topPredictions.length - 1; i++) {
        keys.add(buildComponentKey(topPredictions[i] + " " + topPredictions[i + 1]));
    }

    return keys;
}
 
Example 18
Project: FlickLauncher   File: AlphabeticalAppsList.java   Source Code and License 5 votes vote down vote up
/**
 * Sets the sorted list of filtered components.
 */
public boolean setOrderedFilter(ArrayList<ComponentKey> f) {
    if (mSearchResults != f) {
        boolean same = mSearchResults != null && mSearchResults.equals(f);
        mSearchResults = f;
        updateAdapterItems();
        return !same;
    }
    return false;
}
 
Example 19
Project: FlickLauncher   File: AlphabeticalAppsList.java   Source Code and License 5 votes vote down vote up
private List<AppInfo> getFiltersAppInfos() {
    if (mSearchResults == null) {
        return mApps;
    }

    ArrayList<AppInfo> result = new ArrayList<>();
    for (ComponentKey key : mSearchResults) {
        AppInfo match = mComponentToAppMap.get(key);
        if (match != null) {
            result.add(match);
        }
    }
    return result;
}
 
Example 20
Project: FlickLauncher   File: AllAppsContainerView.java   Source Code and License 5 votes vote down vote up
@Override
public void onSearchResult(String query, ArrayList<ComponentKey> apps) {
    if (apps != null) {
        if (mApps.setOrderedFilter(apps)) {
            mAppsRecyclerView.onSearchResultsChanged();
        }
        mAdapter.setLastSearchQuery(query);
    }
}
 
Example 21
Project: FlickLauncher   File: IconCache.java   Source Code and License 5 votes vote down vote up
/**
 * Remove any records for the supplied package name from memory.
 */
private void removeFromMemCacheLocked(String packageName, UserHandleCompat user) {
    HashSet<ComponentKey> forDeletion = new HashSet<ComponentKey>();
    for (ComponentKey key: mCache.keySet()) {
        if (key.componentName.getPackageName().equals(packageName)
                && key.user.equals(user)) {
            forDeletion.add(key);
        }
    }
    for (ComponentKey condemned: forDeletion) {
        mCache.remove(condemned);
    }
}
 
Example 22
Project: FlickLauncher   File: IconCache.java   Source Code and License 5 votes vote down vote up
private boolean getEntryFromDB(ComponentKey cacheKey, CacheEntry entry, boolean lowRes) {
    Cursor c = null;
    try {
        c = mIconDb.query(
            new String[]{lowRes ? IconDB.COLUMN_ICON_LOW_RES : IconDB.COLUMN_ICON,
                    IconDB.COLUMN_LABEL},
            IconDB.COLUMN_COMPONENT + " = ? AND " + IconDB.COLUMN_USER + " = ?",
            new String[]{cacheKey.componentName.flattenToString(),
                    Long.toString(mUserManager.getSerialNumberForUser(cacheKey.user))});
        if (c.moveToNext()) {
            entry.icon = loadIconNoResize(c, 0, lowRes ? mLowResOptions : null);
            entry.isLowResIcon = lowRes;
            entry.title = c.getString(1);
            if (entry.title == null) {
                entry.title = "";
                entry.contentDescription = "";
            } else {
                entry.contentDescription = mUserManager.getBadgedLabelForUser(
                        entry.title, cacheKey.user);
            }
            return true;
        }
    } catch (SQLiteException e) {
        Log.d(TAG, "Error reading icon cache", e);
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return false;
}
 
Example 23
Project: FlickLauncher   File: LauncherModel.java   Source Code and License 5 votes vote down vote up
public void bindDeepShortcuts() {
    final MultiHashMap<ComponentKey, String> shortcutMapCopy = mBgDeepShortcutMap.clone();
    Runnable r = new Runnable() {
        @Override
        public void run() {
            Callbacks callbacks = getCallback();
            if (callbacks != null) {
                callbacks.bindDeepShortcutMap(shortcutMapCopy);
            }
        }
    };
    runOnMainThread(r);
}
 
Example 24
Project: SimpleUILauncher   File: Launcher.java   Source Code and License 5 votes vote down vote up
/**
 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
 * resumed.
 */
public void tryAndUpdatePredictedApps() {
    if (mLauncherCallbacks != null) {
        List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
        if (apps != null) {
            mAppsView.setPredictedApps(apps);
            getUserEventDispatcher().setPredictedApps(apps);
        }
    }
}
 
Example 25
Project: SimpleUILauncher   File: Launcher.java   Source Code and License 5 votes vote down vote up
public List<String> getShortcutIdsForItem(ItemInfo info) {
    if (!DeepShortcutManager.supportsShortcuts(info)) {
        return Collections.EMPTY_LIST;
    }
    ComponentName component = info.getTargetComponent();
    if (component == null) {
        return Collections.EMPTY_LIST;
    }

    List<String> ids = mDeepShortcutMap.get(new ComponentKey(component, info.user));
    return ids == null ? Collections.EMPTY_LIST : ids;
}
 
Example 26
Project: SimpleUILauncher   File: AppWidgetManagerCompatV16.java   Source Code and License 5 votes vote down vote up
@Override
public HashMap<ComponentKey, AppWidgetProviderInfo> getAllProvidersMap() {
    HashMap<ComponentKey, AppWidgetProviderInfo> result = new HashMap<>();
    UserHandleCompat user = UserHandleCompat.myUserHandle();
    for (AppWidgetProviderInfo info : mAppWidgetManager.getInstalledProviders()) {
        result.put(new ComponentKey(info.provider, user), info);
    }
    return result;
}
 
Example 27
Project: SimpleUILauncher   File: AppWidgetManagerCompatVL.java   Source Code and License 5 votes vote down vote up
@Override
public HashMap<ComponentKey, AppWidgetProviderInfo> getAllProvidersMap() {
    HashMap<ComponentKey, AppWidgetProviderInfo> result = new HashMap<>();
    for (UserHandle user : mUserManager.getUserProfiles()) {
        UserHandleCompat userHandle = UserHandleCompat.fromUser(user);
        for (AppWidgetProviderInfo info :
                mAppWidgetManager.getInstalledProvidersForProfile(user)) {
            result.put(new ComponentKey(info.provider, userHandle), info);
        }
    }
    return result;
}
 
Example 28
Project: SimpleUILauncher   File: DefaultAppSearchAlgorithm.java   Source Code and License 5 votes vote down vote up
public void doSearch(final String query,
        final AllAppsSearchBarController.Callbacks callback) {
    final ArrayList<ComponentKey> result = getTitleMatchResult(query);
    mResultHandler.post(new Runnable() {

        @Override
        public void run() {
            callback.onSearchResult(query, result);
        }
    });
}
 
Example 29
Project: SimpleUILauncher   File: DefaultAppSearchAlgorithm.java   Source Code and License 5 votes vote down vote up
protected ArrayList<ComponentKey> getTitleMatchResult(String query) {
    // Do an intersection of the words in the query and each title, and filter out all the
    // apps that don't match all of the words in the query.
    final String queryTextLower = query.toLowerCase();
    final ArrayList<ComponentKey> result = new ArrayList<>();
    for (AppInfo info : mApps) {
        if (matches(info, queryTextLower)) {
            result.add(info.toComponentKey());
        }
    }
    return result;
}
 
Example 30
Project: SimpleUILauncher   File: AlphabeticalAppsList.java   Source Code and License 5 votes vote down vote up
/**
 * Sets the sorted list of filtered components.
 */
public boolean setOrderedFilter(ArrayList<ComponentKey> f) {
    if (mSearchResults != f) {
        boolean same = mSearchResults != null && mSearchResults.equals(f);
        mSearchResults = f;
        updateAdapterItems();
        return !same;
    }
    return false;
}
 
Example 31
Project: SimpleUILauncher   File: AlphabeticalAppsList.java   Source Code and License 5 votes vote down vote up
private List<AppInfo> getFiltersAppInfos() {
    if (mSearchResults == null) {
        return mApps;
    }

    ArrayList<AppInfo> result = new ArrayList<>();
    for (ComponentKey key : mSearchResults) {
        AppInfo match = mComponentToAppMap.get(key);
        if (match != null) {
            result.add(match);
        }
    }
    return result;
}
 
Example 32
Project: SimpleUILauncher   File: AllAppsContainerView.java   Source Code and License 5 votes vote down vote up
@Override
public void onSearchResult(String query, ArrayList<ComponentKey> apps) {
    if (apps != null) {
        if (mApps.setOrderedFilter(apps)) {
            mAppsRecyclerView.onSearchResultsChanged();
        }
        mAdapter.setLastSearchQuery(query);
    }
}
 
Example 33
Project: SimpleUILauncher   File: IconCache.java   Source Code and License 5 votes vote down vote up
/**
 * Remove any records for the supplied package name from memory.
 */
private void removeFromMemCacheLocked(String packageName, UserHandleCompat user) {
    HashSet<ComponentKey> forDeletion = new HashSet<ComponentKey>();
    for (ComponentKey key: mCache.keySet()) {
        if (key.componentName.getPackageName().equals(packageName)
                && key.user.equals(user)) {
            forDeletion.add(key);
        }
    }
    for (ComponentKey condemned: forDeletion) {
        mCache.remove(condemned);
    }
}
 
Example 34
Project: SimpleUILauncher   File: IconCache.java   Source Code and License 5 votes vote down vote up
private boolean getEntryFromDB(ComponentKey cacheKey, CacheEntry entry, boolean lowRes) {
    Cursor c = null;
    try {
        c = mIconDb.query(
            new String[]{lowRes ? IconDB.COLUMN_ICON_LOW_RES : IconDB.COLUMN_ICON,
                    IconDB.COLUMN_LABEL},
            IconDB.COLUMN_COMPONENT + " = ? AND " + IconDB.COLUMN_USER + " = ?",
            new String[]{cacheKey.componentName.flattenToString(),
                    Long.toString(mUserManager.getSerialNumberForUser(cacheKey.user))});
        if (c.moveToNext()) {
            entry.icon = loadIconNoResize(c, 0, lowRes ? mLowResOptions : null);
            entry.isLowResIcon = lowRes;
            entry.title = c.getString(1);
            if (entry.title == null) {
                entry.title = "";
                entry.contentDescription = "";
            } else {
                entry.contentDescription = mUserManager.getBadgedLabelForUser(
                        entry.title, cacheKey.user);
            }
            return true;
        }
    } catch (SQLiteException e) {
        Log.d(TAG, "Error reading icon cache", e);
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return false;
}
 
Example 35
Project: SimpleUILauncher   File: LauncherModel.java   Source Code and License 5 votes vote down vote up
public void bindDeepShortcuts() {
    final MultiHashMap<ComponentKey, String> shortcutMapCopy = mBgDeepShortcutMap.clone();
    Runnable r = new Runnable() {
        @Override
        public void run() {
            Callbacks callbacks = getCallback();
            if (callbacks != null) {
                callbacks.bindDeepShortcutMap(shortcutMapCopy);
            }
        }
    };
    runOnMainThread(r);
}
 
Example 36
Project: Trebuchet   File: Launcher.java   Source Code and License 5 votes vote down vote up
/**
 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
 * resumed.
 */
private void tryAndUpdatePredictedApps() {
    boolean mRemoteDrawerEnabled = SettingsProvider.getBoolean(this,
            SettingsProvider.SETTINGS_UI_DRAWER_REMOTE_APPS,
            R.bool.preferences_interface_drawer_remote_apps_default);
    if (!mRemoteDrawerEnabled) {
        if (mLauncherCallbacks != null) {
            List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
            if (apps != null) {
                mAppsView.setPredictedAppComponents(apps);
            }
        }
    }
}
 
Example 37
Project: Trebuchet   File: WidgetsAndShortcutNameComparator.java   Source Code and License 5 votes vote down vote up
@Override
public final int compare(Object objA, Object objB) {
    ComponentKey keyA = getComponentKey(objA);
    ComponentKey keyB = getComponentKey(objB);

    // Independent of how the labels compare, if only one of the two widget info belongs to
    // work profile, put that one in the back.
    boolean aWorkProfile = !mMainHandle.equals(keyA.user);
    boolean bWorkProfile = !mMainHandle.equals(keyB.user);
    if (aWorkProfile && !bWorkProfile) {
        return 1;
    }
    if (!aWorkProfile && bWorkProfile) {
        return -1;
    }

    // Get the labels for comparison
    String labelA = mLabelCache.get(keyA);
    String labelB = mLabelCache.get(keyB);
    if (labelA == null) {
        labelA = getLabel(objA);
        mLabelCache.put(keyA, labelA);
    }
    if (labelB == null) {
        labelB = getLabel(objB);
        mLabelCache.put(keyB, labelB);
    }
    return mCollator.compare(labelA, labelB);
}
 
Example 38
Project: Trebuchet   File: WidgetsAndShortcutNameComparator.java   Source Code and License 5 votes vote down vote up
/**
 * @return a component key for the given widget or shortcut info.
 */
private ComponentKey getComponentKey(Object o) {
    if (o instanceof LauncherAppWidgetProviderInfo) {
        LauncherAppWidgetProviderInfo widgetInfo = (LauncherAppWidgetProviderInfo) o;
        return new ComponentKey(widgetInfo.provider, mManager.getUser(widgetInfo));
    } else {
        ResolveInfo shortcutInfo = (ResolveInfo) o;
        ComponentName cn = new ComponentName(shortcutInfo.activityInfo.packageName,
                shortcutInfo.activityInfo.name);
        // Currently, there are no work profile shortcuts
        return new ComponentKey(cn, UserHandleCompat.myUserHandle());
    }
}
 
Example 39
Project: Trebuchet   File: DefaultAppSearchAlgorithm.java   Source Code and License 5 votes vote down vote up
public void doSearch(final String query,
        final AllAppsSearchBarController.Callbacks callback) {
    final ArrayList<ComponentKey> result = getTitleMatchResult(query);
    mResultHandler.post(new Runnable() {

        @Override
        public void run() {
            callback.onSearchResult(query, result);
        }
    });
}
 
Example 40
Project: Trebuchet   File: DefaultAppSearchAlgorithm.java   Source Code and License 5 votes vote down vote up
protected ArrayList<ComponentKey> getTitleMatchResult(String query) {
    // Do an intersection of the words in the query and each title, and filter out all the
    // apps that don't match all of the words in the query.
    final String queryTextLower = query.toLowerCase();
    final String[] queryWords = SPLIT_PATTERN.split(queryTextLower);

    final ArrayList<ComponentKey> result = new ArrayList<>();
    for (AppInfo info : mApps) {
        if (matches(info, queryWords)) {
            result.add(info.toComponentKey());
        }
    }
    return result;
}