OSDN Git Service

Turn refresh rate into a seek bar preference
authorBraden Farmer <farmerbb@gmail.com>
Mon, 26 Dec 2016 03:34:39 +0000 (20:34 -0700)
committerBraden Farmer <farmerbb@gmail.com>
Mon, 26 Dec 2016 03:34:39 +0000 (20:34 -0700)
app/src/main/java/com/farmerbb/taskbar/fragment/RecentAppsFragment.java
app/src/main/java/com/farmerbb/taskbar/fragment/SettingsFragment.java
app/src/main/java/com/farmerbb/taskbar/service/TaskbarService.java
app/src/main/res/layout/seekbar_pref.xml [moved from app/src/main/res/layout/max_num_of_recents.xml with 88% similarity]
app/src/main/res/values-ja/strings.xml
app/src/main/res/values-ru/strings.xml
app/src/main/res/values/donottranslate.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/pref_recent_apps.xml

index 3d4a8af..aa40407 100644 (file)
@@ -35,8 +35,8 @@ public class RecentAppsFragment extends SettingsFragment {
         // Set OnClickListeners for certain preferences
         findPreference("enable_recents").setOnPreferenceClickListener(this);
         findPreference("max_num_of_recents").setOnPreferenceClickListener(this);
+        findPreference("refresh_frequency").setOnPreferenceClickListener(this);
 
-        bindPreferenceSummaryToValue(findPreference("refresh_frequency"));
         bindPreferenceSummaryToValue(findPreference("recents_amount"));
         bindPreferenceSummaryToValue(findPreference("sort_order"));
         bindPreferenceSummaryToValue(findPreference("disable_scrolling_list"));
@@ -48,6 +48,7 @@ public class RecentAppsFragment extends SettingsFragment {
             actionBar.setDisplayHomeAsUpEnabled(true);
 
         updateMaxNumOfRecents(false);
+        updateRefreshFrequency(false);
 
         finishedLoadingPrefs = true;
     }
index ad4bc6e..5e9c440 100644 (file)
@@ -487,11 +487,13 @@ public class SettingsFragment extends PreferenceFragment implements OnPreference
                 final int max = 26;
 
                 AlertDialog.Builder builder6 = new AlertDialog.Builder(getActivity());
-                LinearLayout dialogLayout2 = (LinearLayout) View.inflate(getActivity(), R.layout.max_num_of_recents, null);
+                LinearLayout dialogLayout2 = (LinearLayout) View.inflate(getActivity(), R.layout.seekbar_pref, null);
 
                 String value = pref.getString("max_num_of_recents", "10");
 
                 final TextView textView = (TextView) dialogLayout2.findViewById(R.id.seekbar_value);
+                textView.setText("0");
+
                 final SeekBar seekBar = (SeekBar) dialogLayout2.findViewById(R.id.seekbar);
                 seekBar.setMax(max);
                 seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@@ -512,6 +514,9 @@ public class SettingsFragment extends PreferenceFragment implements OnPreference
 
                 seekBar.setProgress(Integer.parseInt(value));
 
+                TextView blurb = (TextView) dialogLayout2.findViewById(R.id.blurb);
+                blurb.setText(R.string.num_of_recents_blurb);
+
                 builder6.setView(dialogLayout2)
                         .setTitle(R.string.pref_max_num_of_recents)
                         .setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
@@ -529,6 +534,55 @@ public class SettingsFragment extends PreferenceFragment implements OnPreference
                 AlertDialog dialog6 = builder6.create();
                 dialog6.show();
                 break;
+            case "refresh_frequency":
+                final int max2 = 20;
+
+                AlertDialog.Builder builder7 = new AlertDialog.Builder(getActivity());
+                LinearLayout dialogLayout3 = (LinearLayout) View.inflate(getActivity(), R.layout.seekbar_pref, null);
+
+                String value2 = pref.getString("refresh_frequency", "2");
+
+                final TextView textView2 = (TextView) dialogLayout3.findViewById(R.id.seekbar_value);
+                textView2.setText(R.string.infinity);
+
+                final SeekBar seekBar2 = (SeekBar) dialogLayout3.findViewById(R.id.seekbar);
+                seekBar2.setMax(max2);
+                seekBar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+                    @Override
+                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+                        if(progress == 0)
+                            textView2.setText(R.string.infinity);
+                        else
+                            textView2.setText(Double.toString(progress * 0.5));
+                    }
+
+                    @Override
+                    public void onStartTrackingTouch(SeekBar seekBar) {}
+
+                    @Override
+                    public void onStopTrackingTouch(SeekBar seekBar) {}
+                });
+
+                seekBar2.setProgress((int) (Double.parseDouble(value2) * 2));
+
+                TextView blurb2 = (TextView) dialogLayout3.findViewById(R.id.blurb);
+                blurb2.setText(R.string.refresh_frequency_blurb);
+
+                builder7.setView(dialogLayout3)
+                        .setTitle(R.string.pref_title_recents_refresh_interval)
+                        .setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
+                            public void onClick(DialogInterface dialog, int id) {
+                                double progress = seekBar2.getProgress() * 0.5;
+
+                                pref.edit().putString("refresh_frequency", Double.toString(progress)).apply();
+                                updateRefreshFrequency(true);
+                            }
+                        })
+                        .setNegativeButton(R.string.action_cancel, null);
+
+                AlertDialog dialog7 = builder7.create();
+                dialog7.show();
+                break;
         }
 
         return true;
@@ -636,4 +690,22 @@ public class SettingsFragment extends PreferenceFragment implements OnPreference
 
         if(restartTaskbar) restartTaskbar();
     }
+
+    protected void updateRefreshFrequency(boolean restartTaskbar) {
+        SharedPreferences pref = U.getSharedPreferences(getActivity());
+        String value = pref.getString("refresh_frequency", "2");
+        double doubleValue = Double.parseDouble(value);
+        int intValue = (int) doubleValue;
+
+        if(doubleValue == 0)
+            findPreference("refresh_frequency").setSummary(R.string.refresh_frequency_continuous);
+        else if(doubleValue == 1)
+            findPreference("refresh_frequency").setSummary(R.string.refresh_frequency_singular);
+        else if(doubleValue == (double) intValue)
+            findPreference("refresh_frequency").setSummary(getString(R.string.refresh_frequency, Integer.toString(intValue)));
+        else
+            findPreference("refresh_frequency").setSummary(getString(R.string.refresh_frequency, value));
+
+        if(restartTaskbar) restartTaskbar();
+    }
 }
\ No newline at end of file
index 97169b1..fc6a04e 100644 (file)
@@ -318,7 +318,7 @@ public class TaskbarService extends Service {
             }
         });
 
-        refreshInterval = Integer.parseInt(pref.getString("refresh_frequency", "2")) * 1000;
+        refreshInterval = (int) (Float.parseFloat(pref.getString("refresh_frequency", "2")) * 1000);
         sortOrder = pref.getString("sort_order", "false");
 
         switch(pref.getString("recents_amount", "past_day")) {
similarity index 88%
rename from app/src/main/res/layout/max_num_of_recents.xml
rename to app/src/main/res/layout/seekbar_pref.xml
index 9a931a5..703f20d 100644 (file)
         <TextView
             android:id="@+id/seekbar_value"
             android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:text="0"/>
+            android:layout_height="wrap_content" />
 
     </LinearLayout>
 
     <TextView
+        android:id="@+id/blurb"
         android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/num_of_recents_blurb" />
+        android:layout_height="wrap_content" />
 
 </LinearLayout>
\ No newline at end of file
index 07818ae..64b897d 100644 (file)
 
     <string name="pref_title_enable_recents">使用状況アクセスを有効/無効にする</string>
     <string name="pref_title_recents_refresh_interval">リストのリフレッシュ間隔</string>
-    <string-array name="pref_refresh_frequency">
-        <item>1 秒</item>
-        <item>2 秒</item>
-        <item>5 秒</item>
-    </string-array>
 
     <string name="pref_title_amount_of_recents">起動したアプリの表示</string>
     <string-array name="pref_recents_amount">
     <string name="max_num_of_recents_singular">1 app</string>
     <string name="max_num_of_recents_unlimited">Unlimited</string>
 
+    <string name="refresh_frequency_blurb">Ensure that usage access is enabled before changing this setting.\n\nLower values will increase CPU usage and may decrease battery life.</string>
+    <string name="refresh_frequency">%1$s 秒</string>
+    <string name="refresh_frequency_singular">1 秒</string>
+    <string name="refresh_frequency_continuous">Continuous</string>
+
 </resources>
index e2c25c3..9145dfd 100644 (file)
 
     <string name="pref_title_enable_recents">Включить/выключить разрешение</string>
     <string name="pref_title_recents_refresh_interval">Обновлять список через</string>
-    <string-array name="pref_refresh_frequency">
-        <item>1 секунду</item>
-        <item>2 секунды</item>
-        <item>5 секунд</item>
-    </string-array>
 
     <string name="pref_title_amount_of_recents">Показывать список</string>
     <string-array name="pref_recents_amount">
     <string name="max_num_of_recents_singular">1 приложений</string>
     <string name="max_num_of_recents_unlimited">Без ограничений</string>
 
+    <string name="refresh_frequency_blurb">Ensure that usage access is enabled before changing this setting.\n\nLower values will increase CPU usage and may decrease battery life.</string>
+    <string name="refresh_frequency">%1$s секунд</string>
+    <string name="refresh_frequency_singular">1 секунду</string>
+    <string name="refresh_frequency_continuous">Continuous</string>
+
 </resources>
index 36d0b35..c1216ee 100644 (file)
     <string name="right_arrow" translatable="false">&#10095;</string>
     <string name="x" translatable="false">&#215;</string>
     <string name="dashboard_grid_description" translatable="false">%1$d &#215; %2$d</string>
-    <string name="infinity">&#8734;</string>
+    <string name="infinity" translatable="false">&#8734;</string>
 
     <string-array name="pref_start_menu_list_values">
         <item>list</item>
         <item>grid</item>
     </string-array>
 
-    <string-array name="pref_refresh_frequency_values">
-        <item>1</item>
-        <item>2</item>
-        <item>5</item>
-    </string-array>
-
     <string-array name="pref_recents_amount_values">
         <item>past_day</item>
         <item>app_start</item>
         <item>phone_size</item>
     </string-array>
 
-    <string-array name="pref_max_num_of_recents_list_values">
-        <item>10</item>
-        <item>15</item>
-        <item>20</item>
-        <item>2147483647</item>
-    </string-array>
-
     <string-array name="pref_show_search_bar_list_values">
         <item>always</item>
         <item>keyboard</item>
index b72d02e..9b55162 100644 (file)
     <string name="pref_header_recent_apps">Recent apps</string>
 
     <string name="pref_title_enable_recents">Enable/disable usage access</string>
-    <string name="pref_title_recents_refresh_interval">Refresh list every</string>
-    <string-array name="pref_refresh_frequency">
-        <item>1 second</item>
-        <item>2 seconds</item>
-        <item>5 seconds</item>
-    </string-array>
+    <string name="pref_title_recents_refresh_interval">Refresh rate</string>
 
     <string name="pref_title_amount_of_recents">Display apps launched</string>
     <string-array name="pref_recents_amount">
     <string name="max_num_of_recents_singular">1 app</string>
     <string name="max_num_of_recents_unlimited">Unlimited</string>
 
+    <string name="refresh_frequency_blurb">Ensure that usage access is enabled before changing this setting.\n\nLower values will increase CPU usage and may decrease battery life.</string>
+    <string name="refresh_frequency">%1$s seconds</string>
+    <string name="refresh_frequency_singular">1 second</string>
+    <string name="refresh_frequency_continuous">Continuous</string>
+
 </resources>
index 1049afd..9f7f24a 100644 (file)
         android:key="enable_recents"
         android:title="@string/pref_title_enable_recents"/>
 
-    <ListPreference
-        android:defaultValue="2"
-        android:entries="@array/pref_refresh_frequency"
-        android:entryValues="@array/pref_refresh_frequency_values"
+    <Preference
         android:key="refresh_frequency"
-        android:negativeButtonText="@null"
-        android:positiveButtonText="@null"
         android:title="@string/pref_title_recents_refresh_interval"/>
 
     <ListPreference