Search in sources :

Example 21 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Launcher3 by AOSPA.

the class AllAppsGridAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    switch(holder.getItemViewType()) {
        case VIEW_TYPE_ICON:
            AdapterItem adapterItem = mApps.getAdapterItems().get(position);
            BubbleTextView icon = (BubbleTextView) holder.itemView;
            icon.reset();
            if (adapterItem.itemInfo instanceof AppInfo) {
                icon.applyFromApplicationInfo((AppInfo) adapterItem.itemInfo);
            } else {
                icon.applyFromItemInfoWithIcon(adapterItem.itemInfo);
            }
            break;
        case VIEW_TYPE_EMPTY_SEARCH:
            TextView emptyViewText = (TextView) holder.itemView;
            emptyViewText.setText(mEmptySearchMessage);
            emptyViewText.setGravity(mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL);
            break;
        case VIEW_TYPE_SEARCH_MARKET:
            TextView searchView = (TextView) holder.itemView;
            if (mMarketSearchIntent != null) {
                searchView.setVisibility(View.VISIBLE);
            } else {
                searchView.setVisibility(View.GONE);
            }
            break;
        case VIEW_TYPE_ALL_APPS_DIVIDER:
            // nothing to do
            break;
        default:
            BaseAdapterProvider adapterProvider = getAdapterProvider(holder.getItemViewType());
            if (adapterProvider != null) {
                adapterProvider.onBindView(holder, position);
            }
    }
}
Also used : BubbleTextView(com.android.launcher3.BubbleTextView) TextView(android.widget.TextView) BubbleTextView(com.android.launcher3.BubbleTextView) AppInfo(com.android.launcher3.model.data.AppInfo)

Example 22 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Launcher3 by AOSPA.

the class AlphabeticalAppsList method onAppsUpdated.

/**
 * Updates internals when the set of apps are updated.
 */
@Override
public void onAppsUpdated() {
    // Sort the list of apps
    mApps.clear();
    for (AppInfo app : mAllAppsStore.getApps()) {
        if (mItemFilter == null || mItemFilter.matches(app, null) || hasFilter()) {
            mApps.add(app);
        }
    }
    Collections.sort(mApps, mAppNameComparator);
    // As a special case for some languages (currently only Simplified Chinese), we may need to
    // coalesce sections
    Locale curLocale = mLauncher.getResources().getConfiguration().locale;
    boolean localeRequiresSectionSorting = curLocale.equals(Locale.SIMPLIFIED_CHINESE);
    if (localeRequiresSectionSorting) {
        // Compute the section headers. We use a TreeMap with the section name comparator to
        // ensure that the sections are ordered when we iterate over it later
        TreeMap<String, ArrayList<AppInfo>> sectionMap = new TreeMap<>(new LabelComparator());
        for (AppInfo info : mApps) {
            // Add the section to the cache
            String sectionName = info.sectionName;
            // Add it to the mapping
            ArrayList<AppInfo> sectionApps = sectionMap.get(sectionName);
            if (sectionApps == null) {
                sectionApps = new ArrayList<>();
                sectionMap.put(sectionName, sectionApps);
            }
            sectionApps.add(info);
        }
        // Add each of the section apps to the list in order
        mApps.clear();
        for (Map.Entry<String, ArrayList<AppInfo>> entry : sectionMap.entrySet()) {
            mApps.addAll(entry.getValue());
        }
    }
    // Recompose the set of adapter items from the current set of apps
    if (mSearchResults == null) {
        updateAdapterItems();
    }
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) LabelComparator(com.android.launcher3.util.LabelComparator) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) AppInfo(com.android.launcher3.model.data.AppInfo)

Example 23 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Launcher3 by AOSPA.

the class AlphabeticalAppsList method refillAdapterItems.

private void refillAdapterItems() {
    String lastSectionName = null;
    FastScrollSectionInfo lastFastScrollerSectionInfo = null;
    int position = 0;
    int appIndex = 0;
    // Prepare to update the list of sections, filtered apps, etc.
    mAccessibilityResultsCount = 0;
    mFastScrollerSections.clear();
    mAdapterItems.clear();
    if (!hasFilter()) {
        mAccessibilityResultsCount = mApps.size();
        if (mWorkAdapterProvider != null) {
            position += mWorkAdapterProvider.addWorkItems(mAdapterItems);
            if (!mWorkAdapterProvider.shouldShowWorkApps()) {
                return;
            }
        }
        for (AppInfo info : mApps) {
            String sectionName = info.sectionName;
            // Create a new section if the section names do not match
            if (!sectionName.equals(lastSectionName)) {
                lastSectionName = sectionName;
                lastFastScrollerSectionInfo = new FastScrollSectionInfo(sectionName);
                mFastScrollerSections.add(lastFastScrollerSectionInfo);
            }
            // Create an app item
            AdapterItem appItem = AdapterItem.asApp(position++, sectionName, info, appIndex++);
            if (lastFastScrollerSectionInfo.fastScrollToItem == null) {
                lastFastScrollerSectionInfo.fastScrollToItem = appItem;
            }
            mAdapterItems.add(appItem);
        }
    } else {
        updateSearchAdapterItems(mSearchResults, 0);
        if (!FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
            // Append the search market item
            if (hasNoFilteredResults()) {
                mAdapterItems.add(AdapterItem.asEmptySearch(position++));
            } else {
                mAdapterItems.add(AdapterItem.asAllAppsDivider(position++));
            }
            mAdapterItems.add(AdapterItem.asMarketSearch(position++));
        }
    }
    if (mNumAppsPerRow != 0) {
        // Update the number of rows in the adapter after we do all the merging (otherwise, we
        // would have to shift the values again)
        int numAppsInSection = 0;
        int numAppsInRow = 0;
        int rowIndex = -1;
        for (AdapterItem item : mAdapterItems) {
            item.rowIndex = 0;
            if (AllAppsGridAdapter.isDividerViewType(item.viewType)) {
                numAppsInSection = 0;
            } else if (AllAppsGridAdapter.isIconViewType(item.viewType)) {
                if (numAppsInSection % mNumAppsPerRow == 0) {
                    numAppsInRow = 0;
                    rowIndex++;
                }
                item.rowIndex = rowIndex;
                item.rowAppIndex = numAppsInRow;
                numAppsInSection++;
                numAppsInRow++;
            }
        }
        mNumAppRowsInAdapter = rowIndex + 1;
        // Pre-calculate all the fast scroller fractions
        switch(mFastScrollDistributionMode) {
            case FAST_SCROLL_FRACTION_DISTRIBUTE_BY_ROWS_FRACTION:
                float rowFraction = 1f / mNumAppRowsInAdapter;
                for (FastScrollSectionInfo info : mFastScrollerSections) {
                    AdapterItem item = info.fastScrollToItem;
                    if (!AllAppsGridAdapter.isIconViewType(item.viewType)) {
                        info.touchFraction = 0f;
                        continue;
                    }
                    float subRowFraction = item.rowAppIndex * (rowFraction / mNumAppsPerRow);
                    info.touchFraction = item.rowIndex * rowFraction + subRowFraction;
                }
                break;
            case FAST_SCROLL_FRACTION_DISTRIBUTE_BY_NUM_SECTIONS:
                float perSectionTouchFraction = 1f / mFastScrollerSections.size();
                float cumulativeTouchFraction = 0f;
                for (FastScrollSectionInfo info : mFastScrollerSections) {
                    AdapterItem item = info.fastScrollToItem;
                    if (!AllAppsGridAdapter.isIconViewType(item.viewType)) {
                        info.touchFraction = 0f;
                        continue;
                    }
                    info.touchFraction = cumulativeTouchFraction;
                    cumulativeTouchFraction += perSectionTouchFraction;
                }
                break;
        }
    }
}
Also used : AdapterItem(com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem) AppInfo(com.android.launcher3.model.data.AppInfo)

Example 24 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Launcher3 by AOSPA.

the class WorkspaceAccessibilityHelper method intersectsValidDropTarget.

/**
 * Find the virtual view id corresponding to the top left corner of any drop region by which
 * the passed id is contained. For an icon, this is simply
 */
@Override
protected int intersectsValidDropTarget(int id) {
    int mCountX = mView.getCountX();
    int mCountY = mView.getCountY();
    int x = id % mCountX;
    int y = id / mCountX;
    LauncherAccessibilityDelegate.DragInfo dragInfo = mDelegate.getDragInfo();
    if (dragInfo.dragType == DragType.WIDGET && !mView.acceptsWidget()) {
        return INVALID_POSITION;
    }
    if (dragInfo.dragType == DragType.WIDGET) {
        // For a widget, every cell must be vacant. In addition, we will return any valid
        // drop target by which the passed id is contained.
        boolean fits = false;
        // These represent the amount that we can back off if we hit a problem. They
        // get consumed as we move up and to the right, trying new regions.
        int spanX = dragInfo.info.spanX;
        int spanY = dragInfo.info.spanY;
        for (int m = 0; m < spanX; m++) {
            for (int n = 0; n < spanY; n++) {
                fits = true;
                int x0 = x - m;
                int y0 = y - n;
                if (x0 < 0 || y0 < 0)
                    continue;
                for (int i = x0; i < x0 + spanX; i++) {
                    if (!fits)
                        break;
                    for (int j = y0; j < y0 + spanY; j++) {
                        if (i >= mCountX || j >= mCountY || mView.isOccupied(i, j)) {
                            fits = false;
                            break;
                        }
                    }
                }
                if (fits) {
                    return x0 + mCountX * y0;
                }
            }
        }
        return INVALID_POSITION;
    } else {
        // For an icon, we simply check the view directly below
        View child = mView.getChildAt(x, y);
        if (child == null || child == dragInfo.item) {
            // Empty cell. Good for an icon or folder.
            return id;
        } else if (dragInfo.dragType != DragType.FOLDER) {
            // For icons, we can consider cells that have another icon or a folder.
            ItemInfo info = (ItemInfo) child.getTag();
            if (info instanceof AppInfo || info instanceof FolderInfo || info instanceof WorkspaceItemInfo) {
                return id;
            }
        }
        return INVALID_POSITION;
    }
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) View(android.view.View) FolderInfo(com.android.launcher3.model.data.FolderInfo) AppInfo(com.android.launcher3.model.data.AppInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 25 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Launcher3 by AOSPA.

the class WorkspaceAccessibilityHelper method getConfirmationForIconDrop.

@Override
protected String getConfirmationForIconDrop(int id) {
    int x = id % mView.getCountX();
    int y = id / mView.getCountX();
    LauncherAccessibilityDelegate.DragInfo dragInfo = mDelegate.getDragInfo();
    View child = mView.getChildAt(x, y);
    if (child == null || child == dragInfo.item) {
        return mContext.getString(R.string.item_moved);
    } else {
        ItemInfo info = (ItemInfo) child.getTag();
        if (info instanceof AppInfo || info instanceof WorkspaceItemInfo) {
            return mContext.getString(R.string.folder_created);
        } else if (info instanceof FolderInfo) {
            return mContext.getString(R.string.added_to_folder);
        }
    }
    return "";
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) View(android.view.View) FolderInfo(com.android.launcher3.model.data.FolderInfo) AppInfo(com.android.launcher3.model.data.AppInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

AppInfo (com.android.launcher3.model.data.AppInfo)181 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)86 ItemInfo (com.android.launcher3.model.data.ItemInfo)46 ArrayList (java.util.ArrayList)46 ComponentName (android.content.ComponentName)36 AppInfo (com.android.launcher3.AppInfo)33 View (android.view.View)32 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)31 Intent (android.content.Intent)30 FolderInfo (com.android.launcher3.model.data.FolderInfo)30 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)30 UserHandle (android.os.UserHandle)21 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)21 PendingAddShortcutInfo (com.android.launcher3.widget.PendingAddShortcutInfo)21 Point (android.graphics.Point)19 BubbleTextView (com.android.launcher3.BubbleTextView)19 LauncherApps (android.content.pm.LauncherApps)17 ItemInfoWithIcon (com.android.launcher3.model.data.ItemInfoWithIcon)17 PendingAddItemInfo (com.android.launcher3.PendingAddItemInfo)15 AppWidgetHostView (android.appwidget.AppWidgetHostView)14