Search in sources :

Example 96 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by SudaMod.

the class DashboardAdapter method onSaveInstanceState.

void onSaveInstanceState(Bundle outState) {
    final List<Tile> suggestions = mDashboardData.getSuggestions();
    final DashboardCategory category = mDashboardData.getCategory();
    if (suggestions != null) {
        outState.putParcelableArrayList(STATE_SUGGESTION_LIST, new ArrayList<>(suggestions));
    }
    if (category != null) {
        outState.putParcelable(STATE_CATEGORY_LIST, category);
    }
    outState.putStringArrayList(STATE_SUGGESTIONS_SHOWN_LOGGED, mSuggestionsShownLogged);
    outState.putInt(STATE_SUGGESTION_CONDITION_MODE, mDashboardData.getSuggestionConditionMode());
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Tile(com.android.settingslib.drawer.Tile)

Example 97 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by SudaMod.

the class DashboardAdapter method setCategoriesAndSuggestions.

public void setCategoriesAndSuggestions(DashboardCategory category, List<Tile> suggestions) {
    tintIcons(category, suggestions);
    final DashboardData prevData = mDashboardData;
    mDashboardData = new DashboardData.Builder(prevData).setSuggestions(suggestions.subList(0, Math.min(suggestions.size(), MAX_SUGGESTION_TO_SHOW))).setCategory(category).build();
    notifyDashboardDataChanged(prevData);
    List<Tile> shownSuggestions = null;
    final int mode = mDashboardData.getSuggestionConditionMode();
    if (mode == DashboardData.HEADER_MODE_DEFAULT) {
        shownSuggestions = suggestions.subList(0, Math.min(suggestions.size(), DashboardData.DEFAULT_SUGGESTION_COUNT));
    } else if (mode != DashboardData.HEADER_MODE_COLLAPSED) {
        shownSuggestions = suggestions;
    }
    if (shownSuggestions != null) {
        for (Tile suggestion : shownSuggestions) {
            final String identifier = mSuggestionFeatureProvider.getSuggestionIdentifier(mContext, suggestion);
            mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, identifier, getSuggestionTaggedData());
            mSuggestionsShownLogged.add(identifier);
        }
    }
}
Also used : Tile(com.android.settingslib.drawer.Tile)

Example 98 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by SudaMod.

the class DashboardAdapter method tintIcons.

private void tintIcons(DashboardCategory category, List<Tile> suggestions) {
    if (!mDashboardFeatureProvider.shouldTintIcon()) {
        return;
    }
    // TODO: Better place for tinting?
    final TypedArray a = mContext.obtainStyledAttributes(new int[] { android.R.attr.colorControlNormal });
    final int tintColor = a.getColor(0, mContext.getColor(R.color.fallback_tintColor));
    a.recycle();
    if (category != null) {
        for (Tile tile : category.tiles) {
            if (tile.isIconTintable) {
                // If this drawable is tintable, tint it to match the color.
                tile.icon.setTint(tintColor);
            }
        }
    }
    if (suggestions != null) {
        for (Tile suggestion : suggestions) {
            if (suggestion.isIconTintable) {
                suggestion.icon.setTint(tintColor);
            }
        }
    }
}
Also used : TypedArray(android.content.res.TypedArray) Tile(com.android.settingslib.drawer.Tile)

Example 99 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by SudaMod.

the class DashboardAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(DashboardItemHolder holder, int position) {
    final int type = mDashboardData.getItemTypeByPosition(position);
    switch(type) {
        case R.layout.dashboard_tile:
            final Tile tile = (Tile) mDashboardData.getItemEntityByPosition(position);
            onBindTile(holder, tile);
            holder.itemView.setTag(tile);
            holder.itemView.setOnClickListener(mTileClickListener);
            break;
        case R.layout.suggestion_condition_container:
            onBindConditionAndSuggestion((SuggestionAndConditionContainerHolder) holder, position);
            break;
        case R.layout.suggestion_condition_header:
            onBindSuggestionConditionHeader((SuggestionAndConditionHeaderHolder) holder, (SuggestionConditionHeaderData) mDashboardData.getItemEntityByPosition(position));
            break;
        case R.layout.suggestion_condition_footer:
            holder.itemView.setOnClickListener(v -> {
                mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND, false);
                DashboardData prevData = mDashboardData;
                mDashboardData = new DashboardData.Builder(prevData).setSuggestionConditionMode(DashboardData.HEADER_MODE_COLLAPSED).build();
                notifyDashboardDataChanged(prevData);
                mRecyclerView.scrollToPosition(SUGGESTION_CONDITION_HEADER_POSITION);
            });
            break;
    }
}
Also used : Tile(com.android.settingslib.drawer.Tile)

Example 100 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by SudaMod.

the class DashboardFeatureProviderImpl method getPreferencesForCategory.

@Override
public List<Preference> getPreferencesForCategory(Activity activity, Context context, int sourceMetricsCategory, String key) {
    final DashboardCategory category = getTilesForCategory(key);
    if (category == null) {
        Log.d(TAG, "NO dashboard tiles for " + TAG);
        return null;
    }
    final List<Tile> tiles = category.tiles;
    if (tiles == null || tiles.isEmpty()) {
        Log.d(TAG, "tile list is empty, skipping category " + category.title);
        return null;
    }
    final List<Preference> preferences = new ArrayList<>();
    for (Tile tile : tiles) {
        final Preference pref = new Preference(context);
        bindPreferenceToTile(activity, sourceMetricsCategory, pref, tile, null, /* key */
        Preference.DEFAULT_ORDER);
        preferences.add(pref);
    }
    return preferences;
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Preference(android.support.v7.preference.Preference) ArrayList(java.util.ArrayList) Tile(com.android.settingslib.drawer.Tile)

Aggregations

Tile (com.android.settingslib.drawer.Tile)506 Test (org.junit.Test)345 Intent (android.content.Intent)160 DashboardCategory (com.android.settingslib.drawer.DashboardCategory)117 Bundle (android.os.Bundle)108 Preference (android.support.v7.preference.Preference)98 ComponentName (android.content.ComponentName)93 ArrayList (java.util.ArrayList)87 Context (android.content.Context)70 ActivityTile (com.android.settingslib.drawer.ActivityTile)50 ProviderTile (com.android.settingslib.drawer.ProviderTile)45 UserHandle (android.os.UserHandle)39 Preference (androidx.preference.Preference)39 RecyclerView (android.support.v7.widget.RecyclerView)31 View (android.view.View)31 Icon (android.graphics.drawable.Icon)30 Activity (android.app.Activity)29 VisibleForTesting (android.support.annotation.VisibleForTesting)29 PackageManager (android.content.pm.PackageManager)25 ViewGroup (android.view.ViewGroup)24