Search in sources :

Example 21 with Condition

use of com.android.settings.dashboard.conditional.Condition in project android_packages_apps_Settings by omnirom.

the class DashboardData method buildItemsData.

/**
 * Build the mItems list using mConditions, mSuggestions, mCategories data
 * and mIsShowingAll, mSuggestionConditionMode flag.
 */
private void buildItemsData() {
    final boolean hasSuggestions = sizeOf(mSuggestions) > 0;
    final List<Condition> conditions = getConditionsToShow(mConditions);
    final boolean hasConditions = sizeOf(conditions) > 0;
    final List<Tile> suggestions = getSuggestionsToShow(mSuggestions);
    final int hiddenSuggestion = hasSuggestions ? sizeOf(mSuggestions) - sizeOf(suggestions) : 0;
    final boolean hasSuggestionAndCollapsed = hasSuggestions && mSuggestionConditionMode == HEADER_MODE_COLLAPSED;
    final boolean onlyHasConditionAndCollapsed = !hasSuggestions && hasConditions && mSuggestionConditionMode != HEADER_MODE_FULLY_EXPANDED;
    /* Top suggestion/condition header. This will be present when there is any suggestion
         * and the mode is collapsed */
    addToItemList(new SuggestionConditionHeaderData(conditions, hiddenSuggestion), R.layout.suggestion_condition_header, STABLE_ID_SUGGESTION_CONDITION_TOP_HEADER, hasSuggestionAndCollapsed);
    /* Use mid header if there is only condition & it's in collapsed mode */
    addToItemList(new SuggestionConditionHeaderData(conditions, hiddenSuggestion), R.layout.suggestion_condition_header, STABLE_ID_SUGGESTION_CONDITION_MIDDLE_HEADER, onlyHasConditionAndCollapsed);
    /* Suggestion container. This is the card view that contains the list of suggestions.
         * This will be added whenever the suggestion list is not empty */
    addToItemList(suggestions, R.layout.suggestion_condition_container, STABLE_ID_SUGGESTION_CONTAINER, sizeOf(suggestions) > 0);
    /* Second suggestion/condition header. This will be added when there is at least one
         * suggestion or condition that is not currently displayed, and the user can expand the
         * section to view more items. */
    addToItemList(new SuggestionConditionHeaderData(conditions, hiddenSuggestion), R.layout.suggestion_condition_header, STABLE_ID_SUGGESTION_CONDITION_MIDDLE_HEADER, mSuggestionConditionMode != HEADER_MODE_COLLAPSED && mSuggestionConditionMode != HEADER_MODE_FULLY_EXPANDED && (hiddenSuggestion > 0 || hasConditions && hasSuggestions));
    /* Condition container. This is the card view that contains the list of conditions.
             * This will be added whenever the condition list is not empty */
    addToItemList(conditions, R.layout.suggestion_condition_container, STABLE_ID_CONDITION_CONTAINER, hasConditions && mSuggestionConditionMode == HEADER_MODE_FULLY_EXPANDED);
    /* Suggestion/condition footer. This will be present when the section is fully expanded
             * or when there is no conditions and no hidden suggestions */
    addToItemList(null, /* item */
    R.layout.suggestion_condition_footer, STABLE_ID_SUGGESTION_CONDITION_FOOTER, (hasConditions || hasSuggestions) && mSuggestionConditionMode == HEADER_MODE_FULLY_EXPANDED || hasSuggestions && !hasConditions && hiddenSuggestion == 0);
    if (mCategory != null) {
        for (int j = 0; j < mCategory.tiles.size(); j++) {
            final Tile tile = mCategory.tiles.get(j);
            addToItemList(tile, R.layout.dashboard_tile, Objects.hash(tile.title), true);
        }
    }
}
Also used : Condition(com.android.settings.dashboard.conditional.Condition) Tile(com.android.settingslib.drawer.Tile)

Example 22 with Condition

use of com.android.settings.dashboard.conditional.Condition in project android_packages_apps_Settings by omnirom.

the class DashboardSummary method onPause.

@Override
public void onPause() {
    super.onPause();
    ((SettingsDrawerActivity) getActivity()).remCategoryListener(this);
    mSummaryLoader.setListening(false);
    for (Condition c : mConditionManager.getConditions()) {
        if (c.shouldShow()) {
            mMetricsFeatureProvider.hidden(getContext(), c.getMetricsConstant());
        }
    }
    if (!getActivity().isChangingConfigurations()) {
        mAdapter.onPause();
    }
}
Also used : Condition(com.android.settings.dashboard.conditional.Condition) SettingsDrawerActivity(com.android.settingslib.drawer.SettingsDrawerActivity)

Example 23 with Condition

use of com.android.settings.dashboard.conditional.Condition in project android_packages_apps_Settings by omnirom.

the class DashboardSummary method onResume.

@Override
public void onResume() {
    long startTime = System.currentTimeMillis();
    super.onResume();
    mAppPreferences.registerOnSharedPreferenceChangeListener(mAppPreferencesListener);
    ((SettingsDrawerActivity) getActivity()).addCategoryListener(this);
    mSummaryLoader.setListening(true);
    final int metricsCategory = getMetricsCategory();
    for (Condition c : mConditionManager.getConditions()) {
        if (c.shouldShow()) {
            mMetricsFeatureProvider.visible(getContext(), metricsCategory, c.getMetricsConstant());
        }
    }
    if (DEBUG_TIMING) {
        Log.d(TAG, "onResume took " + (System.currentTimeMillis() - startTime) + " ms");
    }
}
Also used : Condition(com.android.settings.dashboard.conditional.Condition) SettingsDrawerActivity(com.android.settingslib.drawer.SettingsDrawerActivity)

Example 24 with Condition

use of com.android.settings.dashboard.conditional.Condition in project android_packages_apps_Settings by DirtyUnicorns.

the class DashboardDataTest method testGetPositionByEntity_notExisted_returnNotFound.

@Test
public void testGetPositionByEntity_notExisted_returnNotFound() {
    final Condition condition = mock(AirplaneModeCondition.class);
    final int position = mDashboardDataWithOneConditions.getPositionByEntity(condition);
    assertThat(position).isEqualTo(DashboardData.POSITION_NOT_FOUND);
}
Also used : Condition(com.android.settings.dashboard.conditional.Condition) AirplaneModeCondition(com.android.settings.dashboard.conditional.AirplaneModeCondition) Test(org.junit.Test)

Example 25 with Condition

use of com.android.settings.dashboard.conditional.Condition in project android_packages_apps_Settings by DirtyUnicorns.

the class DashboardData method buildItemsData.

/**
 * Build the mItems list using mConditions, mSuggestions, mCategories data
 * and mIsShowingAll, mSuggestionConditionMode flag.
 */
private void buildItemsData() {
    final boolean hasSuggestions = sizeOf(mSuggestions) > 0;
    final List<Condition> conditions = getConditionsToShow(mConditions);
    final boolean hasConditions = sizeOf(conditions) > 0;
    final List<Tile> suggestions = getSuggestionsToShow(mSuggestions);
    final int hiddenSuggestion = hasSuggestions ? sizeOf(mSuggestions) - sizeOf(suggestions) : 0;
    final boolean hasSuggestionAndCollapsed = hasSuggestions && mSuggestionConditionMode == HEADER_MODE_COLLAPSED;
    final boolean onlyHasConditionAndCollapsed = !hasSuggestions && hasConditions && mSuggestionConditionMode != HEADER_MODE_FULLY_EXPANDED;
    /* Top suggestion/condition header. This will be present when there is any suggestion
         * and the mode is collapsed */
    addToItemList(new SuggestionConditionHeaderData(conditions, hiddenSuggestion), R.layout.suggestion_condition_header, STABLE_ID_SUGGESTION_CONDITION_TOP_HEADER, hasSuggestionAndCollapsed);
    /* Use mid header if there is only condition & it's in collapsed mode */
    addToItemList(new SuggestionConditionHeaderData(conditions, hiddenSuggestion), R.layout.suggestion_condition_header, STABLE_ID_SUGGESTION_CONDITION_MIDDLE_HEADER, onlyHasConditionAndCollapsed);
    /* Suggestion container. This is the card view that contains the list of suggestions.
         * This will be added whenever the suggestion list is not empty */
    addToItemList(suggestions, R.layout.suggestion_condition_container, STABLE_ID_SUGGESTION_CONTAINER, sizeOf(suggestions) > 0);
    /* Second suggestion/condition header. This will be added when there is at least one
         * suggestion or condition that is not currently displayed, and the user can expand the
         * section to view more items. */
    addToItemList(new SuggestionConditionHeaderData(conditions, hiddenSuggestion), R.layout.suggestion_condition_header, STABLE_ID_SUGGESTION_CONDITION_MIDDLE_HEADER, mSuggestionConditionMode != HEADER_MODE_COLLAPSED && mSuggestionConditionMode != HEADER_MODE_FULLY_EXPANDED && (hiddenSuggestion > 0 || hasConditions && hasSuggestions));
    /* Condition container. This is the card view that contains the list of conditions.
             * This will be added whenever the condition list is not empty */
    addToItemList(conditions, R.layout.suggestion_condition_container, STABLE_ID_CONDITION_CONTAINER, hasConditions && mSuggestionConditionMode == HEADER_MODE_FULLY_EXPANDED);
    /* Suggestion/condition footer. This will be present when the section is fully expanded
             * or when there is no conditions and no hidden suggestions */
    addToItemList(null, /* item */
    R.layout.suggestion_condition_footer, STABLE_ID_SUGGESTION_CONDITION_FOOTER, (hasConditions || hasSuggestions) && mSuggestionConditionMode == HEADER_MODE_FULLY_EXPANDED || hasSuggestions && !hasConditions && hiddenSuggestion == 0);
    if (mCategory != null) {
        for (int j = 0; j < mCategory.tiles.size(); j++) {
            final Tile tile = mCategory.tiles.get(j);
            addToItemList(tile, R.layout.dashboard_tile, Objects.hash(tile.title), true);
        }
    }
}
Also used : Condition(com.android.settings.dashboard.conditional.Condition) Tile(com.android.settingslib.drawer.Tile)

Aggregations

Condition (com.android.settings.dashboard.conditional.Condition)38 SettingsDrawerActivity (com.android.settingslib.drawer.SettingsDrawerActivity)14 Tile (com.android.settingslib.drawer.Tile)14 ArrayList (java.util.ArrayList)12 VisibleForTesting (android.support.annotation.VisibleForTesting)6 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 AirplaneModeCondition (com.android.settings.dashboard.conditional.AirplaneModeCondition)6 ConditionAdapter (com.android.settings.dashboard.conditional.ConditionAdapter)6 SuggestionAdapter (com.android.settings.dashboard.suggestions.SuggestionAdapter)6 SuggestionDismissController (com.android.settings.dashboard.suggestions.SuggestionDismissController)6 List (java.util.List)6 Test (org.junit.Test)6