Search in sources :

Example 41 with LayoutPreference

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;
}
Also used : LayoutPreference(com.android.settingslib.widget.LayoutPreference) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) TextView(android.widget.TextView) Intent(android.content.Intent) Before(org.junit.Before)

Example 42 with LayoutPreference

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();
            }
        }
    }
}
Also used : LayoutPreference(com.android.settingslib.widget.LayoutPreference)

Example 43 with LayoutPreference

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();
            }
        }
    }
}
Also used : LayoutPreference(com.android.settingslib.widget.LayoutPreference)

Example 44 with LayoutPreference

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();
}
Also used : LayoutPreference(com.android.settingslib.widget.LayoutPreference)

Example 45 with LayoutPreference

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);
}
Also used : LayoutPreference(com.android.settingslib.widget.LayoutPreference) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Aggregations

LayoutPreference (com.android.settingslib.widget.LayoutPreference)61 Before (org.junit.Before)10 Preference (androidx.preference.Preference)8 Activity (android.app.Activity)5 View (android.view.View)5 Button (android.widget.Button)5 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)5 Test (org.junit.Test)5 ImageView (android.widget.ImageView)3 PreferenceManager (androidx.preference.PreferenceManager)3 PreferenceScreen (androidx.preference.PreferenceScreen)3 Intent (android.content.Intent)2 UserInfo (android.content.pm.UserInfo)2 Resources (android.content.res.Resources)2 Bundle (android.os.Bundle)2 RemoteException (android.os.RemoteException)2 UserManager (android.os.UserManager)2 TextView (android.widget.TextView)2 PreferenceFragmentCompat (androidx.preference.PreferenceFragmentCompat)2 WifiDataUsageSummaryPreferenceController (com.android.settings.datausage.WifiDataUsageSummaryPreferenceController)2