Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8b30f531 authored by Fan Zhang's avatar Fan Zhang
Browse files

Remove DashboardTilePreference.

It's not needed for now.

Bug: 32554506
Test: RunSettingsRoboTests
Change-Id: I325a07896e88db97c9d3a461c8cb4c42a6c44737
parent 80d1ec7d
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -288,7 +288,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
    void refreshDashboardTiles(final String TAG) {
        final PreferenceScreen screen = getPreferenceScreen();

        final Context context = getContext();
        final DashboardCategory category =
                mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
        if (category == null) {
@@ -324,7 +323,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
                        getActivity(), preference, tile, key);
            } else {
                // Don't have this key, add it.
                final Preference pref = new DashboardTilePreference(context);
                final Preference pref = new Preference(getPrefContext());
                mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), pref, tile, key);
                mProgressiveDisclosureMixin.addPreference(screen, pref);
                mDashboardTilePrefKeys.add(key);
+21 −11
Original line number Diff line number Diff line
@@ -16,13 +16,11 @@
package com.android.settings.dashboard;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.SettingsActivity;

import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.PreferenceController;
@@ -31,8 +29,7 @@ import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.Tile;
import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -42,6 +39,9 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;

import java.util.ArrayList;
import java.util.List;

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
@@ -101,14 +101,14 @@ public class DashboardFragmentTest {
        mTestFragment.onCreatePreferences(new Bundle(), "rootKey");

        verify(mDisclosureMixin).addPreference(any(PreferenceScreen.class),
                any(DashboardTilePreference.class));
                any(Preference.class));
    }

    @Test
    public void displayTilesAsPreference_shouldNotAddTilesWithoutIntent() {
        mTestFragment.onCreatePreferences(new Bundle(), "rootKey");

        verify(mTestFragment.mScreen, never()).addPreference(any(DashboardTilePreference.class));
        verify(mTestFragment.mScreen, never()).addPreference(any(Preference.class));
    }

    @Test
@@ -116,7 +116,7 @@ public class DashboardFragmentTest {
        mDashboardCategory.tiles = null;
        mTestFragment.onCreatePreferences(new Bundle(), "rootKey");

        verify(mTestFragment.mScreen, never()).addPreference(any(DashboardTilePreference.class));
        verify(mTestFragment.mScreen, never()).addPreference(any(Preference.class));
    }

    @Test
@@ -163,14 +163,19 @@ public class DashboardFragmentTest {

    public static class TestFragment extends DashboardFragment {

        private final PreferenceManager mPreferenceManager;
        private final Context mContext;
        public PreferenceScreen mScreen;
        private List<PreferenceController> mControllers;
        private final List<PreferenceController> mControllers;

        public final PreferenceScreen mScreen;

        public TestFragment(Context context) {
            mContext = context;
            mPreferenceManager = mock(PreferenceManager.class);
            mScreen = mock(PreferenceScreen.class);
            mControllers = new ArrayList<>();

            when(mPreferenceManager.getContext()).thenReturn(mContext);
        }

        @Override
@@ -207,6 +212,11 @@ public class DashboardFragmentTest {
        protected List<PreferenceController> getPreferenceControllers(Context context) {
            return mControllers;
        }

        @Override
        public PreferenceManager getPreferenceManager() {
            return mPreferenceManager;
        }
    }

}
+0 −76
Original line number Diff line number Diff line
/**
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.settings.dashboard.conditional;


import android.content.Context;
import android.support.v7.preference.PreferenceViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.dashboard.DashboardTilePreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;

import static com.google.common.truth.Truth.assertThat;

@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DashboardTilePreferenceTest {

    private ShadowApplication mShadowApplication;
    private Context mContext;
    private PreferenceViewHolder mHolder;
    private DashboardTilePreference mPreference;

    @Before
    public void setUp() {
        mShadowApplication = ShadowApplication.getInstance();
        mContext = mShadowApplication.getApplicationContext();
        mPreference = new DashboardTilePreference(mContext);

        LayoutInflater inflater = LayoutInflater.from(mContext);
        final View view = inflater.inflate(mPreference.getLayoutResource(),
                new LinearLayout(mContext), false);

        mHolder = new PreferenceViewHolder(view);
    }

    @Test
    public void setHasDivider_shouldShowDivider() {
        mPreference.setDividerAllowedAbove(true);
        mPreference.setDividerAllowedBelow(true);
        mPreference.onBindViewHolder(mHolder);

        assertThat(mHolder.isDividerAllowedAbove()).isTrue();
        assertThat(mHolder.isDividerAllowedBelow()).isTrue();
    }

    @Test
    public void setHasNoDivider_shouldHideDivider() {
        mPreference.setDividerAllowedAbove(false);
        mPreference.setDividerAllowedBelow(false);
        mPreference.onBindViewHolder(mHolder);

        assertThat(mHolder.isDividerAllowedAbove()).isFalse();
        assertThat(mHolder.isDividerAllowedBelow()).isFalse();
    }
}