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);
}
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);
}
}
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);
}
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();
}
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();
}
Aggregations