Search in sources :

Example 31 with GearPreference

use of com.android.settings.widget.GearPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class TextToSpeechSettings method initSettings.

private void initSettings() {
    final ContentResolver resolver = getContentResolver();
    // Set up the default rate and pitch.
    mDefaultRate = android.provider.Settings.Secure.getInt(resolver, TTS_DEFAULT_RATE, TextToSpeech.Engine.DEFAULT_RATE);
    mDefaultPitch = android.provider.Settings.Secure.getInt(resolver, TTS_DEFAULT_PITCH, TextToSpeech.Engine.DEFAULT_PITCH);
    mDefaultRatePref.setProgress(getSeekBarProgressFromValue(KEY_DEFAULT_RATE, mDefaultRate));
    mDefaultRatePref.setOnPreferenceChangeListener(this);
    mDefaultRatePref.setMax(getSeekBarProgressFromValue(KEY_DEFAULT_RATE, MAX_SPEECH_RATE));
    mDefaultPitchPref.setProgress(getSeekBarProgressFromValue(KEY_DEFAULT_PITCH, mDefaultPitch));
    mDefaultPitchPref.setOnPreferenceChangeListener(this);
    mDefaultPitchPref.setMax(getSeekBarProgressFromValue(KEY_DEFAULT_PITCH, MAX_SPEECH_PITCH));
    if (mTts != null) {
        mCurrentEngine = mTts.getCurrentEngine();
        mTts.setSpeechRate(mDefaultRate / 100.0f);
        mTts.setPitch(mDefaultPitch / 100.0f);
    }
    SettingsActivity activity = null;
    if (getActivity() instanceof SettingsActivity) {
        activity = (SettingsActivity) getActivity();
    } else {
        throw new IllegalStateException("TextToSpeechSettings used outside a " + "Settings");
    }
    if (mCurrentEngine != null) {
        EngineInfo info = mEnginesHelper.getEngineInfo(mCurrentEngine);
        Preference mEnginePreference = findPreference(KEY_TTS_ENGINE_PREFERENCE);
        ((GearPreference) mEnginePreference).setOnGearClickListener(this);
        mEnginePreference.setSummary(info.label);
    }
    checkVoiceData(mCurrentEngine);
}
Also used : GearPreference(com.android.settings.widget.GearPreference) EngineInfo(android.speech.tts.TextToSpeech.EngineInfo) SeekBarPreference(com.android.settings.widget.SeekBarPreference) GearPreference(com.android.settings.widget.GearPreference) ActionButtonsPreference(com.android.settingslib.widget.ActionButtonsPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) SettingsActivity(com.android.settings.SettingsActivity) ContentResolver(android.content.ContentResolver)

Example 32 with GearPreference

use of com.android.settings.widget.GearPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CurrentDreamPreferenceController method setGearClickListenerForPreference.

private void setGearClickListenerForPreference(Preference preference) {
    if (!(preference instanceof GearPreference)) {
        return;
    }
    final GearPreference gearPreference = (GearPreference) preference;
    final Optional<DreamInfo> info = getActiveDreamInfo();
    if (!info.isPresent() || info.get().settingsComponentName == null) {
        gearPreference.setOnGearClickListener(null);
        return;
    }
    gearPreference.setOnGearClickListener(gearPref -> launchScreenSaverSettings());
}
Also used : GearPreference(com.android.settings.widget.GearPreference) DreamInfo(com.android.settingslib.dream.DreamBackend.DreamInfo)

Example 33 with GearPreference

use of com.android.settings.widget.GearPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CurrentDreamPreferenceControllerTest method gearHidesIfActiveDreamInfoHasNoOptions.

@Test
public void gearHidesIfActiveDreamInfoHasNoOptions() {
    mDreamInfo.settingsComponentName = null;
    mDreamInfo.isActive = true;
    when(mBackend.getDreamInfos()).thenReturn(Collections.singletonList(mDreamInfo));
    GearPreference mockPref = mock(GearPreference.class);
    ArgumentCaptor<GearPreference.OnGearClickListener> captor = ArgumentCaptor.forClass(GearPreference.OnGearClickListener.class);
    // setting a null onGearClickListener removes the gear from view
    mController.updateState(mockPref);
    verify(mockPref).setOnGearClickListener(captor.capture());
    captor.getAllValues().forEach(listener -> assertThat(listener).isNull());
}
Also used : GearPreference(com.android.settings.widget.GearPreference) Test(org.junit.Test)

Example 34 with GearPreference

use of com.android.settings.widget.GearPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ChangeScreenLockPreferenceControllerTest method mockGearPreferenceAndViewHolder.

private void mockGearPreferenceAndViewHolder() {
    mGearPreference = new GearPreference(mContext, null);
    mGearView = new View(mContext);
    PreferenceViewHolder viewHolder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext).inflate(mGearPreference.getLayoutResource(), null, false));
    mPreferenceViewHolder = spy(viewHolder);
    doReturn(mGearView).when(mPreferenceViewHolder).findViewById(R.id.settings_button);
    when(mPreferenceScreen.findPreference(anyString())).thenReturn(mGearPreference);
}
Also used : GearPreference(com.android.settings.widget.GearPreference) View(android.view.View) PreferenceViewHolder(androidx.preference.PreferenceViewHolder)

Aggregations

GearPreference (com.android.settings.widget.GearPreference)34 Test (org.junit.Test)14 Preference (android.support.v7.preference.Preference)11 ComponentName (android.content.ComponentName)7 ContentResolver (android.content.ContentResolver)7 EngineInfo (android.speech.tts.TextToSpeech.EngineInfo)7 SettingsActivity (com.android.settings.SettingsActivity)7 SeekBarPreference (com.android.settings.widget.SeekBarPreference)7 DreamInfo (com.android.settingslib.dream.DreamBackend.DreamInfo)7 ListPreference (android.support.v7.preference.ListPreference)6 LayoutPreference (com.android.settings.applications.LayoutPreference)6 Activity (android.app.Activity)5 PersistableBundle (android.os.PersistableBundle)5 UserManager (android.os.UserManager)5 SwitchPreference (android.support.v14.preference.SwitchPreference)5 PreferenceGroup (android.support.v7.preference.PreferenceGroup)5 PreferenceScreen (android.support.v7.preference.PreferenceScreen)5 CarrierConfigManager (android.telephony.CarrierConfigManager)5 TelephonyManager (android.telephony.TelephonyManager)5 RestrictedPreference (com.android.settingslib.RestrictedPreference)5