Commit c82a12ae authored by Alexandre Perraud's avatar Alexandre Perraud

Preferences : Simplify and factorize code

parent cb1b88a1
......@@ -362,6 +362,7 @@
<string name="set_locale_popup">Quit and restart VLC for changes to take effect.</string>
<string name="network_caching">Network caching value</string>
<string name="network_caching_summary">The amount of time to buffer network media (in ms). Does not work with hardware decoding. Leave blank to reset.</string>
<string name="network_caching_popup">This value have to be between 0 and 6000 ms</string>
<string name="quit">Quit and restart application</string>
<string name="developer_prefs_category">Developer</string>
......
......@@ -37,6 +37,9 @@
<PreferenceCategory android:title="@string/advanced_prefs_category">
<ListPreference
android:defaultValue="0"
android:entries="@array/aouts"
android:entryValues="@array/aouts_values"
android:key="aout"
android:summary="@string/aout_summary"
android:title="@string/aout" />
......
......@@ -29,7 +29,6 @@ import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.EditTextPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceManager;
import android.text.TextUtils;
import org.videolan.vlc.BuildConfig;
......@@ -55,6 +54,7 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (TextUtils.equals(BuildConfig.FLAVOR_target, "chrome")) {
findPreference("quit_app").setEnabled(false);
}
......@@ -68,35 +68,6 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
// voutPref.setEntryValues(voutEntriesIdValues);
// if (voutPref.getValue() == null)
// voutPref.setValue("0" VOUT_ANDROID_SURFACE );
// Network caching
EditTextPreference networkCachingPref = (EditTextPreference) findPreference("network_caching");
networkCachingPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor editor = sharedPrefs.edit();
try {
editor.putInt("network_caching_value", Integer.parseInt((String)newValue));
} catch(NumberFormatException e) {
editor.putInt("network_caching_value", 0);
editor.putString("network_caching", "0");
}
editor.apply();
return true;
}
});
// Set locale
EditTextPreference setLocalePref = (EditTextPreference) findPreference("set_locale");
setLocalePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
UiTools.snacker(getView(), R.string.set_locale_popup);
return true;
}
});
}
@Override
......@@ -148,7 +119,21 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
switch (key){
case "set_locale":
UiTools.snacker(getView(), R.string.set_locale_popup);
break;
case "network_caching":
SharedPreferences.Editor editor = sharedPreferences.edit();
try {
editor.putInt("network_caching_value", Integer.parseInt(sharedPreferences.getString(key,"0")));
} catch(NumberFormatException e) {
editor.putInt("network_caching_value", 0);
EditTextPreference networkCachingPref = (EditTextPreference) findPreference(key);
networkCachingPref.setText("");
UiTools.snacker(getView(), R.string.network_caching_popup);
}
editor.apply();
// No break because need VLCInstance.restart();
case "vout":
case "chroma_format":
case "deblocking":
......@@ -157,6 +142,7 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
VLCInstance.restart();
if (getActivity() != null )
((PreferencesActivity)getActivity()).restartMediaPlayer();
break;
}
}
}
......@@ -24,7 +24,6 @@ package org.videolan.vlc.gui.preferences;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.TwoStatePreference;
......@@ -32,7 +31,6 @@ import org.videolan.libvlc.util.HWDecoderUtil;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.util.VLCInstance;
import org.videolan.vlc.util.VLCOptions;
public class PreferencesAudio extends BasePreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
......@@ -56,27 +54,10 @@ public class PreferencesAudio extends BasePreferenceFragment implements SharedPr
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
findPreference("enable_play_on_headset_insertion").setVisible(((TwoStatePreference) findPreference("enable_headset_detection")).isChecked());
// Audio output
ListPreference aoutPref = (ListPreference) findPreference("aout");
final HWDecoderUtil.AudioOutput aout = HWDecoderUtil.getAudioOutputFromDevice();
if (aout == HWDecoderUtil.AudioOutput.AUDIOTRACK || aout == HWDecoderUtil.AudioOutput.OPENSLES) {
if (aout != HWDecoderUtil.AudioOutput.ALL) {
/* no AudioOutput choice */
findPreference("aout").setVisible(false);
} else {
int aoutEntriesId = R.array.aouts;
int aoutEntriesIdValues = R.array.aouts_values;
aoutPref.setEntries(aoutEntriesId);
aoutPref.setEntryValues(aoutEntriesIdValues);
final String value = aoutPref.getValue();
if (value == null)
aoutPref.setValue(String.valueOf(VLCOptions.AOUT_AUDIOTRACK));
else {
/* number of entries decreased, handle old values */
final int intValue = Integer.parseInt(value);
if (intValue != VLCOptions.AOUT_AUDIOTRACK && intValue != VLCOptions.AOUT_OPENSLES)
aoutPref.setValue(String.valueOf(VLCOptions.AOUT_AUDIOTRACK));
}
}
}
......
......@@ -26,9 +26,7 @@ package org.videolan.vlc.gui.preferences;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceManager;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
......@@ -51,26 +49,15 @@ public class PreferencesFragment extends BasePreferenceFragment implements Share
return R.string.preferences;
}
@Override
public void onStart() {
super.onStart();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Screen orientation
ListPreference screenOrientationPref = (ListPreference) findPreference("screen_orientation");
screenOrientationPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putString("screen_orientation_value", (String) newValue);
editor.apply();
return true;
}
});
/*** SharedPreferences Listener to apply changes ***/
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
sharedPrefs.registerOnSharedPreferenceChangeListener(this);
}
@Override
......
......@@ -428,7 +428,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
mVerticalBarProgress = findViewById(R.id.verticalbar_progress);
mScreenOrientation = Integer.valueOf(
mSettings.getString("screen_orientation_value", "99" /*SCREEN ORIENTATION SENSOR*/));
mSettings.getString("screen_orientation", "99" /*SCREEN ORIENTATION SENSOR*/));
mPlayPause = (ImageView) findViewById(R.id.player_overlay_play);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment