use of com.android.settingslib.widget.LayoutPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatteryHeaderPreferenceControllerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
mContext = spy(RuntimeEnvironment.application);
mBatteryMeterView = new BatteryMeterView(mContext);
mBatteryPercentText = new TextView(mContext);
mSummary = new TextView(mContext);
ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
mBatteryIntent = new Intent();
mBatteryIntent.putExtra(BatteryManager.EXTRA_LEVEL, BATTERY_LEVEL);
mBatteryIntent.putExtra(BatteryManager.EXTRA_SCALE, 100);
mBatteryIntent.putExtra(BatteryManager.EXTRA_PLUGGED, 1);
doReturn(mBatteryIntent).when(mContext).registerReceiver(any(), any());
mBatteryLayoutPref = new LayoutPreference(mContext, R.layout.battery_header);
doReturn(mBatteryLayoutPref).when(mPreferenceScreen).findPreference(BatteryHeaderPreferenceController.KEY_BATTERY_HEADER);
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mController = new BatteryHeaderPreferenceController(mContext, PREF_KEY);
mLifecycle.addObserver(mController);
mController.setActivity(mActivity);
mController.setFragment(mPreferenceFragment);
mController.setLifecycle(mLifecycle);
mController.mBatteryMeterView = mBatteryMeterView;
mController.mBatteryPercentText = mBatteryPercentText;
mController.mSummary1 = mSummary;
}
use of com.android.settingslib.widget.LayoutPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class PreventRingingSwitchPreferenceController method displayPreference.
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
if (isAvailable()) {
LayoutPreference pref = screen.findPreference(getPreferenceKey());
if (pref != null) {
mSettingObserver = new SettingObserver(pref);
pref.setOnPreferenceClickListener(preference -> {
int preventRinging = Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_VIBRATE);
boolean isChecked = preventRinging != Settings.Secure.VOLUME_HUSH_OFF;
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE, isChecked ? Settings.Secure.VOLUME_HUSH_OFF : Settings.Secure.VOLUME_HUSH_VIBRATE);
return true;
});
mSwitch = pref.findViewById(R.id.switch_bar);
if (mSwitch != null) {
mSwitch.addOnSwitchChangeListener(this);
mSwitch.show();
}
}
}
}
use of com.android.settingslib.widget.LayoutPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AdaptivePlaybackSwitchPreferenceController method displayPreference.
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
if (isAvailable()) {
LayoutPreference pref = screen.findPreference(getPreferenceKey());
if (pref != null) {
mSettingObserver = new SettingObserver(pref);
pref.setOnPreferenceClickListener(preference -> {
int adaptivePlayback = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.ADAPTIVE_PLAYBACK_ENABLED, 0, UserHandle.USER_CURRENT);
boolean isChecked = adaptivePlayback != 0;
Settings.System.putIntForUser(mContext.getContentResolver(), Settings.System.ADAPTIVE_PLAYBACK_ENABLED, isChecked ? 0 : 1, UserHandle.USER_CURRENT);
return true;
});
mSwitch = pref.findViewById(R.id.switch_bar);
if (mSwitch != null) {
mSwitch.addOnSwitchChangeListener(this);
mSwitch.show();
}
}
}
}
use of com.android.settingslib.widget.LayoutPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MobileNetworkSwitchController method displayPreference.
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
final LayoutPreference pref = screen.findPreference(mPreferenceKey);
mSwitchBar = pref.findViewById(R.id.switch_bar);
mSwitchBar.setSwitchBarText(R.string.mobile_network_use_sim_on, R.string.mobile_network_use_sim_off);
mSwitchBar.addOnSwitchChangeListener((switchView, isChecked) -> {
if (mSubscriptionManager.isSubscriptionEnabled(mSubId) != isChecked && (!mSubscriptionManager.setSubscriptionEnabled(mSubId, isChecked))) {
mSwitchBar.setChecked(!isChecked);
}
});
update();
}
use of com.android.settingslib.widget.LayoutPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class UsbDetailsHeaderControllerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
mPreferenceManager = new PreferenceManager(mContext);
mScreen = mPreferenceManager.createPreferenceScreen(mContext);
when(mFragment.getActivity()).thenReturn(mActivity);
when(mActivity.getApplicationContext()).thenReturn(mContext);
when(mFragment.getContext()).thenReturn(mContext);
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
ShadowEntityHeaderController.setUseMock(mHeaderController);
mDetailsHeaderController = new UsbDetailsHeaderController(mContext, mFragment, mUsbBackend);
mPreference = new LayoutPreference(mContext, R.layout.settings_entity_header);
mPreference.setKey(mDetailsHeaderController.getPreferenceKey());
mScreen.addPreference(mPreference);
}
Aggregations