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

Commit 1bc98edc authored by Antoan Angelov's avatar Antoan Angelov Committed by Android (Google) Code Review
Browse files

Merge "Show "Doesn't support work profiles" text in Settings for launchers not...

Merge "Show "Doesn't support work profiles" text in Settings for launchers not supporting work profiles." into pi-dev
parents 2a6b9ff3 2c9d6200
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -20,7 +20,9 @@ import android.content.Context;
import android.support.v4.content.res.TypedArrayUtils;
import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import com.android.settings.R;
@@ -72,6 +74,12 @@ public class RadioButtonPreference extends CheckBoxPreference {
    public void onBindViewHolder(PreferenceViewHolder view) {
        super.onBindViewHolder(view);

        View summaryContainer = view.findViewById(R.id.summary_container);
        if (summaryContainer != null) {
            summaryContainer.setVisibility(
                TextUtils.isEmpty(getSummary()) ? View.GONE : View.VISIBLE);
        }

        TextView title = (TextView) view.findViewById(android.R.id.title);
        if (title != null) {
            title.setSingleLine(false);
+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.widget;

import static junit.framework.Assert.assertEquals;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.app.Application;
import android.support.v7.preference.PreferenceViewHolder;
import android.view.View;

import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;

@RunWith(SettingsRobolectricTestRunner.class)
public class RadioButtonPreferenceTest {

    private Application mContext;
    private RadioButtonPreference mPreference;

    @Before
    public void setUp() {
        mContext = RuntimeEnvironment.application;
        mPreference = new RadioButtonPreference(mContext);
    }

    @Test
    public void summary_containerShouldBeVisible() {
        mPreference.setSummary("some summary");
        View summaryContainer = new View(mContext);
        View view = mock(View.class);
        when(view.findViewById(R.id.summary_container)).thenReturn(summaryContainer);
        PreferenceViewHolder preferenceViewHolder =
                PreferenceViewHolder.createInstanceForTests(view);
        mPreference.onBindViewHolder(preferenceViewHolder);
        assertEquals(View.VISIBLE, summaryContainer.getVisibility());
    }

    @Test
    public void emptySummary_containerShouldBeGone() {
        mPreference.setSummary("");
        View summaryContainer = new View(mContext);
        View view = mock(View.class);
        when(view.findViewById(R.id.summary_container)).thenReturn(summaryContainer);
        PreferenceViewHolder preferenceViewHolder =
                PreferenceViewHolder.createInstanceForTests(view);
        mPreference.onBindViewHolder(preferenceViewHolder);
        assertEquals(View.GONE, summaryContainer.getVisibility());
    }

    @Test
    public void nullSummary_containerShouldBeGone() {
        mPreference.setSummary(null);
        View summaryContainer = new View(mContext);
        View view = mock(View.class);
        when(view.findViewById(R.id.summary_container)).thenReturn(summaryContainer);
        PreferenceViewHolder preferenceViewHolder =
                PreferenceViewHolder.createInstanceForTests(view);
        mPreference.onBindViewHolder(preferenceViewHolder);
        assertEquals(View.GONE, summaryContainer.getVisibility());
    }
}