Search in sources :

Example 66 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.

the class AppDataUsagePreferenceTest method createPref_progressBarShouldSetPercentageContentDescription.

@Test
public void createPref_progressBarShouldSetPercentageContentDescription() {
    when(mUidDetailProvider.getUidDetail(mAppItem.key, true)).thenReturn(mUidDetail);
    mPreference = new AppDataUsagePreference(RuntimeEnvironment.application, mAppItem, 50, /* percent */
    mUidDetailProvider);
    final View view = LayoutInflater.from(RuntimeEnvironment.application).inflate(com.android.settingslib.R.layout.preference_app, null);
    final PreferenceViewHolder preferenceViewHolder = PreferenceViewHolder.createInstanceForTests(view);
    final ProgressBar progressBar = (ProgressBar) preferenceViewHolder.findViewById(android.R.id.progress);
    mPreference.onBindViewHolder(preferenceViewHolder);
    assertThat(progressBar.getContentDescription()).isEqualTo(FIFTY_PERCENT);
}
Also used : View(android.view.View) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) ProgressBar(android.widget.ProgressBar) Test(org.junit.Test)

Example 67 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.

the class DataUsageSummaryPreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    ProgressBar bar = getProgressBar(holder);
    if (mChartEnabled && (!TextUtils.isEmpty(mStartLabel) || !TextUtils.isEmpty(mEndLabel))) {
        bar.setVisibility(View.VISIBLE);
        getLabelBar(holder).setVisibility(View.VISIBLE);
        bar.setProgress((int) (mProgress * 100));
        (getLabel1(holder)).setText(mStartLabel);
        (getLabel2(holder)).setText(mEndLabel);
    } else {
        bar.setVisibility(View.GONE);
        getLabelBar(holder).setVisibility(View.GONE);
    }
    updateDataUsageLabels(holder);
    TextView usageTitle = getUsageTitle(holder);
    TextView carrierInfo = getCarrierInfo(holder);
    Button launchButton = getLaunchButton(holder);
    TextView limitInfo = getDataLimits(holder);
    if (mWifiMode && mSingleWifi) {
        updateCycleTimeText(holder);
        usageTitle.setVisibility(View.GONE);
        launchButton.setVisibility(View.GONE);
        carrierInfo.setVisibility(View.GONE);
        limitInfo.setVisibility(TextUtils.isEmpty(mLimitInfoText) ? View.GONE : View.VISIBLE);
        limitInfo.setText(mLimitInfoText);
    } else if (mWifiMode) {
        usageTitle.setText(R.string.data_usage_wifi_title);
        usageTitle.setVisibility(View.VISIBLE);
        TextView cycleTime = getCycleTime(holder);
        cycleTime.setText(mUsagePeriod);
        carrierInfo.setVisibility(View.GONE);
        limitInfo.setVisibility(View.GONE);
        final long usageLevel = getHistoricalUsageLevel();
        if (usageLevel > 0L) {
            launchButton.setOnClickListener((view) -> {
                launchWifiDataUsage(getContext());
            });
        } else {
            launchButton.setEnabled(false);
        }
        launchButton.setText(R.string.launch_wifi_text);
        launchButton.setVisibility(View.VISIBLE);
    } else {
        usageTitle.setVisibility(mNumPlans > 1 ? View.VISIBLE : View.GONE);
        updateCycleTimeText(holder);
        updateCarrierInfo(carrierInfo);
        if (mLaunchIntent != null) {
            launchButton.setOnClickListener((view) -> {
                getContext().startActivity(mLaunchIntent);
            });
            launchButton.setVisibility(View.VISIBLE);
        } else {
            launchButton.setVisibility(View.GONE);
        }
        limitInfo.setVisibility(TextUtils.isEmpty(mLimitInfoText) ? View.GONE : View.VISIBLE);
        limitInfo.setText(mLimitInfoText);
    }
}
Also used : Typeface(android.graphics.Typeface) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) Spannable(android.text.Spannable) Intent(android.content.Intent) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) AttributeSet(android.util.AttributeSet) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) StringUtil(com.android.settingslib.utils.StringUtil) View(android.view.View) Button(android.widget.Button) Formatter(android.text.format.Formatter) R(com.android.settings.R) ConnectivityManager(android.net.ConnectivityManager) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) SpannableString(android.text.SpannableString) Utils(com.android.settingslib.Utils) SettingsEnums(android.app.settings.SettingsEnums) TextUtils(android.text.TextUtils) DataUsageController(com.android.settingslib.net.DataUsageController) Preference(androidx.preference.Preference) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) TextView(android.widget.TextView) AttrRes(android.annotation.AttrRes) VisibleForTesting(androidx.annotation.VisibleForTesting) NetworkTemplate(android.net.NetworkTemplate) Button(android.widget.Button) TextView(android.widget.TextView) ProgressBar(android.widget.ProgressBar)

Example 68 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.

the class StorageItemPreferenceTest method testProgressBarPercentageSet.

@Test
public void testProgressBarPercentageSet() {
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext).inflate(R.layout.storage_item, null));
    final ProgressBar progressBar = holder.itemView.findViewById(android.R.id.progress);
    mPreference.onBindViewHolder(holder);
    mPreference.setStorageSize(MEGABYTE_IN_BYTES, MEGABYTE_IN_BYTES * 10);
    assertThat(progressBar).isNotNull();
    assertThat(progressBar.getProgress()).isEqualTo(10);
}
Also used : PreferenceViewHolder(androidx.preference.PreferenceViewHolder) ProgressBar(android.widget.ProgressBar) Test(org.junit.Test)

Example 69 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.

the class RecentConversationsPreferenceControllerTest method testRemoveConversations.

@Test
public void testRemoveConversations() throws Exception {
    ShortcutInfo si = mock(ShortcutInfo.class);
    when(si.getId()).thenReturn("person");
    when(si.getPackage()).thenReturn("pkg");
    ConversationChannel ccw = new ConversationChannel(si, 6, new NotificationChannel("hi", "hi", 4), new NotificationChannelGroup("hi", "group"), 7, false);
    ConversationChannel ccw2 = new ConversationChannel(si, 6, new NotificationChannel("bye", "bye", 4), new NotificationChannelGroup("hi", "group"), 7, true);
    PreferenceCategory group = new PreferenceCategory(mContext);
    PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
    screen.addPreference(group);
    RecentConversationPreference pref = mController.createConversationPref(new PreferenceCategory(mContext), ccw, 100);
    final View view = View.inflate(mContext, pref.getLayoutResource(), null);
    PreferenceViewHolder holder = spy(PreferenceViewHolder.createInstanceForTests(view));
    View delete = View.inflate(mContext, pref.getSecondTargetResId(), null);
    when(holder.findViewById(pref.getClearId())).thenReturn(delete);
    group.addPreference(pref);
    RecentConversationPreference pref2 = mController.createConversationPref(new PreferenceCategory(mContext), ccw2, 100);
    final View view2 = View.inflate(mContext, pref2.getLayoutResource(), null);
    PreferenceViewHolder holder2 = spy(PreferenceViewHolder.createInstanceForTests(view2));
    View delete2 = View.inflate(mContext, pref2.getSecondTargetResId(), null);
    when(holder2.findViewById(pref.getClearId())).thenReturn(delete2);
    group.addPreference(pref2);
    LayoutPreference clearAll = mController.getClearAll(group);
    group.addPreference(clearAll);
    clearAll.findViewById(R.id.conversation_settings_clear_recents).performClick();
    verify(mPs).removeAllRecentConversations();
    assertThat((Preference) group.findPreference("hi:person")).isNull();
    assertThat((Preference) group.findPreference("bye:person")).isNotNull();
}
Also used : NotificationChannel(android.app.NotificationChannel) LayoutPreference(com.android.settingslib.widget.LayoutPreference) NotificationChannelGroup(android.app.NotificationChannelGroup) ShortcutInfo(android.content.pm.ShortcutInfo) ConversationChannel(android.app.people.ConversationChannel) PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceCategory(androidx.preference.PreferenceCategory) LayoutPreference(com.android.settingslib.widget.LayoutPreference) Preference(androidx.preference.Preference) PreferenceManager(androidx.preference.PreferenceManager) View(android.view.View) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Test(org.junit.Test)

Example 70 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.

the class PrimaryCheckBoxPreferenceTest method setEnabled_shouldUpdateCheckBoxEnabledState.

@Test
public void setEnabled_shouldUpdateCheckBoxEnabledState() {
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext).inflate(R.layout.preference_widget_primary_checkbox, null));
    final CheckBox checkBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
    mPreference.onBindViewHolder(holder);
    mPreference.setEnabled(true);
    assertThat(checkBox.isEnabled()).isTrue();
    mPreference.setEnabled(false);
    assertThat(checkBox.isEnabled()).isFalse();
}
Also used : CheckBox(android.widget.CheckBox) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Test(org.junit.Test)

Aggregations

PreferenceViewHolder (androidx.preference.PreferenceViewHolder)79 Test (org.junit.Test)61 View (android.view.View)33 LayoutInflater (android.view.LayoutInflater)29 LinearLayout (android.widget.LinearLayout)17 Switch (android.widget.Switch)16 TextView (android.widget.TextView)16 CheckBox (android.widget.CheckBox)14 Preference (androidx.preference.Preference)12 PreferenceCategory (androidx.preference.PreferenceCategory)7 Drawable (android.graphics.drawable.Drawable)6 ProgressBar (android.widget.ProgressBar)5 OnPreferenceChangeListener (androidx.preference.Preference.OnPreferenceChangeListener)5 ImportancePreference (com.android.settings.notification.app.ImportancePreference)5 Before (org.junit.Before)5 ImageView (android.widget.ImageView)4 Context (android.content.Context)3 Button (android.widget.Button)3 ListPreference (androidx.preference.ListPreference)3 PreferenceGroupAdapter (androidx.preference.PreferenceGroupAdapter)3