Search in sources :

Example 1 with GearPreference

use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by LineageOS.

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) ListPreference(android.support.v7.preference.ListPreference) LayoutPreference(com.android.settings.applications.LayoutPreference) GearPreference(com.android.settings.widget.GearPreference) Preference(android.support.v7.preference.Preference) SettingsActivity(com.android.settings.SettingsActivity) ContentResolver(android.content.ContentResolver)

Example 2 with GearPreference

use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by LineageOS.

the class CurrentDreamPreferenceControllerTest method gearHidesIfActiveDreamInfoHasNoOptions.

@Test
public void gearHidesIfActiveDreamInfoHasNoOptions() {
    mDreamInfo.settingsComponentName = null;
    mDreamInfo.isActive = true;
    when(mBackend.getDreamInfos()).thenReturn(new ArrayList<>(Arrays.asList(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 3 with GearPreference

use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by omnirom.

the class CurrentDreamPreferenceController method setGearClickListenerForPreference.

private void setGearClickListenerForPreference(Preference preference) {
    if (!(preference instanceof GearPreference))
        return;
    GearPreference gearPreference = (GearPreference) preference;
    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 4 with GearPreference

use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by omnirom.

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) ListPreference(android.support.v7.preference.ListPreference) LayoutPreference(com.android.settings.applications.LayoutPreference) GearPreference(com.android.settings.widget.GearPreference) Preference(android.support.v7.preference.Preference) SettingsActivity(com.android.settings.SettingsActivity) ContentResolver(android.content.ContentResolver)

Example 5 with GearPreference

use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by crdroidandroid.

the class CurrentDreamPreferenceControllerTest method gearHidesIfActiveDreamInfoHasNoOptions.

@Test
public void gearHidesIfActiveDreamInfoHasNoOptions() {
    mDreamInfo.settingsComponentName = null;
    mDreamInfo.isActive = true;
    when(mBackend.getDreamInfos()).thenReturn(new ArrayList<>(Arrays.asList(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)

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