Merge branch 'seekbar' into 'master'

Seekbar updates

See merge request fdroid/fdroidclient!689
This commit is contained in:
Hans-Christoph Steiner 2018-06-08 20:59:43 +00:00
commit a41d64df4a
10 changed files with 146 additions and 11 deletions

View File

@ -0,0 +1,77 @@
package org.fdroid.fdroid.views;
import android.content.Context;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.preference.SeekBarPreference;
import android.util.AttributeSet;
import android.widget.SeekBar;
import org.fdroid.fdroid.R;
public class LiveSeekBarPreference extends SeekBarPreference {
private Runnable progressChangedListener;
private boolean trackingTouch;
private int value = -1;
@SuppressWarnings("unused")
public LiveSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@SuppressWarnings("unused")
public LiveSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@SuppressWarnings("unused")
public LiveSeekBarPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@SuppressWarnings("unused")
public LiveSeekBarPreference(Context context) {
super(context);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
SeekBar seekbar = holder.itemView.findViewById(R.id.seekbar);
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
value = progress;
if (progressChangedListener != null) {
progressChangedListener.run();
}
value = progress;
if (fromUser && !trackingTouch) {
persistInt(value);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
trackingTouch = true;
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
trackingTouch = false;
persistInt(value);
}
});
seekbar.setProgress(value);
}
public int getValue() {
if (value == -1) {
value = super.getValue();
}
return value;
}
public void setProgressChangedListener(Runnable listener) {
progressChangedListener = listener;
}
}

View File

@ -53,6 +53,7 @@ import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.RepoProvider;
import org.fdroid.fdroid.installer.InstallHistoryService;
import org.fdroid.fdroid.installer.PrivilegedInstaller;
import org.fdroid.fdroid.views.LiveSeekBarPreference;
public class PreferencesFragment extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -90,9 +91,9 @@ public class PreferencesFragment extends PreferenceFragment
private static final int REQUEST_INSTALL_ORBOT = 0x1234;
private SeekBarPreference overWifiSeekBar;
private SeekBarPreference overDataSeekBar;
private SeekBarPreference updateIntervalSeekBar;
private LiveSeekBarPreference overWifiSeekBar;
private LiveSeekBarPreference overDataSeekBar;
private LiveSeekBarPreference updateIntervalSeekBar;
private SwitchPreference enableProxyCheckPref;
private SwitchPreference useTorCheckPref;
private Preference updateAutoDownloadPref;
@ -113,12 +114,30 @@ public class PreferencesFragment extends PreferenceFragment
updateAutoDownloadPref = findPreference(Preferences.PREF_AUTO_DOWNLOAD_INSTALL_UPDATES);
updatePrivilegedExtensionPref = findPreference(Preferences.PREF_UNINSTALL_PRIVILEGED_APP);
overWifiSeekBar = (SeekBarPreference) findPreference(Preferences.PREF_OVER_WIFI);
overWifiSeekBar = (LiveSeekBarPreference) findPreference(Preferences.PREF_OVER_WIFI);
overWifiPrevious = overWifiSeekBar.getValue();
overDataSeekBar = (SeekBarPreference) findPreference(Preferences.PREF_OVER_DATA);
overWifiSeekBar.setProgressChangedListener(new Runnable() {
@Override
public void run() {
updateSummary(overWifiSeekBar.getKey(), false);
}
});
overDataSeekBar = (LiveSeekBarPreference) findPreference(Preferences.PREF_OVER_DATA);
overDataPrevious = overDataSeekBar.getValue();
updateIntervalSeekBar = (SeekBarPreference) findPreference(Preferences.PREF_UPDATE_INTERVAL);
overDataSeekBar.setProgressChangedListener(new Runnable() {
@Override
public void run() {
updateSummary(overDataSeekBar.getKey(), false);
}
});
updateIntervalSeekBar = (LiveSeekBarPreference) findPreference(Preferences.PREF_UPDATE_INTERVAL);
updateIntervalPrevious = updateIntervalSeekBar.getValue();
updateIntervalSeekBar.setProgressChangedListener(new Runnable() {
@Override
public void run() {
updateSummary(updateIntervalSeekBar.getKey(), false);
}
});
ListPreference languagePref = (ListPreference) findPreference(Preferences.PREF_LANGUAGE);
if (Build.VERSION.SDK_INT >= 24) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background">
<nine-patch android:src="@drawable/seekbar_bg" android:dither="true"/>
</item>
<item android:id="@android:id/progress">
<clip android:clipOrientation="horizontal"
android:gravity="left">
<nine-patch android:src="@drawable/seekbar_fill" android:dither="true"/>
</clip>
</item>
</layer-list>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/fdroid_green"/>
<size
android:width="20dp"
android:height="20dp"/>
</shape>
</item>
</layer-list>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/fdroid_green"/>
<size
android:width="10dp"
android:height="10dp"/>
</shape>
</item>
</layer-list>

View File

@ -46,8 +46,9 @@
android:layout_below="@android:id/summary"
android:layout_alignStart="@android:id/summary"
android:layout_alignLeft="@android:id/summary"
android:thumb="@android:drawable/radiobutton_off_background"
android:progressDrawable="@drawable/seekbar_progress"
android:thumb="@drawable/seekbar_thumb"
android:padding="16dip"
android:theme="@style/Widget.AppCompat.SeekBar.Discrete"/>
android:theme="@style/DiscreteSeekBar"/>
</RelativeLayout>

View File

@ -317,4 +317,8 @@
<style name="AppThemeLight.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppThemeLight.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
<style name="DiscreteSeekBar" parent="Base.Widget.AppCompat.SeekBar.Discrete">
<item name="tickMark">@drawable/seekbar_tickmark</item>
</style>
</resources>

View File

@ -27,11 +27,11 @@
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory android:title="@string/updates">
<android.support.v7.preference.SeekBarPreference
<org.fdroid.fdroid.views.LiveSeekBarPreference
android:key="overWifi"
android:title="@string/over_wifi"
android:layout="@layout/preference_seekbar"/>
<android.support.v7.preference.SeekBarPreference
<org.fdroid.fdroid.views.LiveSeekBarPreference
android:key="overData"
android:title="@string/over_data"
android:layout="@layout/preference_seekbar"/>
@ -40,7 +40,7 @@
android:summary="@string/update_auto_download_summary"
android:defaultValue="false"
android:key="updateAutoDownload"/>
<android.support.v7.preference.SeekBarPreference
<org.fdroid.fdroid.views.LiveSeekBarPreference
android:key="updateIntervalSeekBarPosition"
android:title="@string/update_interval"
android:layout="@layout/preference_seekbar"/>