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

Commit 8866301b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update logic to build slider slice" into qt-dev

parents 99162f2a 2837d010
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -300,6 +300,10 @@ public class SliceBuilderUtils {
    private static Slice buildSliderSlice(Context context, SliceData sliceData,
            BasePreferenceController controller) {
        final SliderPreferenceController sliderController = (SliderPreferenceController) controller;
        if (sliderController.getMax() <= sliderController.getMin()) {
            Log.e(TAG, "Invalid sliderController: " + sliderController.getPreferenceKey());
            return null;
        }
        final PendingIntent actionIntent = getSliderAction(context, sliceData);
        final PendingIntent contentIntent = getContentPendingIntent(context, sliceData);
        final IconCompat icon = getSafeIcon(context, sliceData);
+10 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.FakeCopyableController;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.FakeInvalidSliderController;
import com.android.settings.testutils.FakeSliderController;
import com.android.settings.testutils.FakeToggleController;
import com.android.settings.testutils.FakeUnavailablePreferenceController;
@@ -67,6 +68,7 @@ public class SliceBuilderUtilsTest {
    private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
    private final Class TOGGLE_CONTROLLER = FakeToggleController.class;
    private final Class SLIDER_CONTROLLER = FakeSliderController.class;
    private final Class INVALID_SLIDER_CONTROLLER = FakeInvalidSliderController.class;
    private final Class COPYABLE_CONTROLLER = FakeCopyableController.class;
    private final Class CONTEXT_CONTROLLER = FakeContextOnlyPreferenceController.class;

@@ -470,6 +472,14 @@ public class SliceBuilderUtilsTest {
        assertThat(actualIconResource).isEqualTo(expectedIconResource);
    }

    @Test
    public void buildSliderSlice_invalidSlider_returnNull() {
        final SliceData data = getDummyData(INVALID_SLIDER_CONTROLLER, SliceData.SliceType.SLIDER,
                0x0 /* icon */);

        assertThat(SliceBuilderUtils.buildSlice(mContext, data)).isNull();
    }

    @Test
    public void getSafeIcon_replacesEmptyIconWithSettingsIcon() {
        final int settingsIcon = R.drawable.ic_settings_accent;
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.testutils;

import android.content.Context;

public class FakeInvalidSliderController extends FakeSliderController {

    public FakeInvalidSliderController(Context context, String key) {
        super(context, key);
    }

    @Override
    public int getMax() {
        // Return 0 to make it invalid
        return 0;
    }
}