Support autoclick secondary action (3/n)

Changeed autoclick preference summary unit from ms to second.

Bug: 146019277
Test: manual
Change-Id: Ib5dcc2459716277cd278c1e19dbb99bb540b25ce
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ad56f21..f03c465 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5028,28 +5028,28 @@
 
     <!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] -->
     <plurals name="accessibilty_autoclick_preference_subtitle_extremely_short_delay">
-        <item quantity="one">Extremely short delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
-        <item quantity="other">Extremely short delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
+        <item quantity="one">Extremely short delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> second)</item>
+        <item quantity="other">Extremely short delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> seconds)</item>
     </plurals>
     <!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] -->
     <plurals name="accessibilty_autoclick_preference_subtitle_very_short_delay">
-        <item quantity="one">Very short delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
-        <item quantity="other">Very short delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
+        <item quantity="one">Very short delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> second)</item>
+        <item quantity="other">Very short delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> seconds)</item>
     </plurals>
     <!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] -->
     <plurals name="accessibilty_autoclick_preference_subtitle_short_delay">
-        <item quantity="one">Short delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
-        <item quantity="other">Short delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
+        <item quantity="one">Short delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> second)</item>
+        <item quantity="other">Short delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> seconds)</item>
     </plurals>
     <!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] -->
     <plurals name="accessibilty_autoclick_preference_subtitle_long_delay">
-        <item quantity="one">Long delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
-        <item quantity="other">Long delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
+        <item quantity="one">Long delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> second)</item>
+        <item quantity="other">Long delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> seconds)</item>
     </plurals>
     <!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] -->
     <plurals name="accessibilty_autoclick_preference_subtitle_very_long_delay">
-        <item quantity="one">Very long delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
-        <item quantity="other">Very long delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
+        <item quantity="one">Very long delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> second)</item>
+        <item quantity="other">Very long delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> seconds)</item>
     </plurals>
 
     <!-- Summary for autoclick seekbar settings preference when user selected custom item. [CHAR LIMIT=35] -->
diff --git a/src/com/android/settings/accessibility/ToggleAutoclickCustomSeekbarController.java b/src/com/android/settings/accessibility/ToggleAutoclickCustomSeekbarController.java
index 9079c31..301d8dc 100644
--- a/src/com/android/settings/accessibility/ToggleAutoclickCustomSeekbarController.java
+++ b/src/com/android/settings/accessibility/ToggleAutoclickCustomSeekbarController.java
@@ -19,10 +19,8 @@
 import static android.content.Context.MODE_PRIVATE;
 
 import static com.android.settings.accessibility.ToggleAutoclickPreferenceController.KEY_DELAY_MODE;
+import static com.android.settings.accessibility.ToggleAutoclickPreferenceFragment.Quantity;
 
-import static java.lang.annotation.RetentionPolicy.SOURCE;
-
-import android.annotation.IntDef;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.SharedPreferences;
@@ -42,8 +40,6 @@
 import com.android.settingslib.core.lifecycle.events.OnResume;
 import com.android.settingslib.widget.LayoutPreference;
 
-import java.lang.annotation.Retention;
-
 /**
  * Controller class that controls accessibility autoclick seekbar settings.
  */
@@ -51,16 +47,6 @@
         implements LifecycleObserver, OnResume, OnPause,
         SharedPreferences.OnSharedPreferenceChangeListener {
 
-    @Retention(SOURCE)
-    @IntDef({
-            Quantity.OTHER,
-            Quantity.ONE
-    })
-    @interface Quantity {
-        int OTHER = 0;
-        int ONE = 1;
-    }
-
     private static final String CONTROL_AUTOCLICK_DELAY_SECURE =
             Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY;
     private static final String KEY_CUSTOM_DELAY_VALUE = "custom_delay_value";
diff --git a/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java
index 4a88956..5e09b2a 100644
--- a/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java
@@ -19,6 +19,9 @@
 import static com.android.settings.accessibility.ToggleAutoclickCustomSeekbarController.MAX_AUTOCLICK_DELAY_MS;
 import static com.android.settings.accessibility.ToggleAutoclickCustomSeekbarController.MIN_AUTOCLICK_DELAY_MS;
 
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+import android.annotation.IntDef;
 import android.app.settings.SettingsEnums;
 import android.content.Context;
 import android.content.res.Resources;
@@ -32,6 +35,7 @@
 import com.android.settingslib.core.lifecycle.Lifecycle;
 import com.android.settingslib.search.SearchIndexable;
 
+import java.lang.annotation.Retention;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -46,6 +50,16 @@
     private static final String TAG = "AutoclickPrefFragment";
     private static final List<AbstractPreferenceController> sControllers = new ArrayList<>();
 
+    @Retention(SOURCE)
+    @IntDef({
+            Quantity.OTHER,
+            Quantity.ONE
+    })
+    @interface Quantity {
+        int OTHER = 0;
+        int ONE = 1;
+    }
+
     /**
      * Resource ids from which autoclick preference summaries should be derived. The strings have
      * placeholder for integer delay value.
@@ -63,12 +77,17 @@
      * delay.
      *
      * @param resources Resources from which string should be retrieved.
-     * @param delay     Delay for whose value summary should be retrieved.
+     * @param delayMillis Delay for whose value summary should be retrieved.
      */
-    static CharSequence getAutoclickPreferenceSummary(Resources resources, int delay) {
-        int summaryIndex = getAutoclickPreferenceSummaryIndex(delay);
-        return resources.getQuantityString(
-                mAutoclickPreferenceSummaries[summaryIndex], delay, delay);
+    static CharSequence getAutoclickPreferenceSummary(Resources resources, int delayMillis) {
+        final int summaryIndex = getAutoclickPreferenceSummaryIndex(delayMillis);
+        final int quantity = (delayMillis == 1000) ? Quantity.ONE : Quantity.OTHER;
+        final float delaySecond =  (float) delayMillis / 1000;
+        // Only show integer when delay time is 1.
+        final String decimalFormat = (delaySecond == 1) ? "%.0f" : "%.1f";
+
+        return resources.getQuantityString(mAutoclickPreferenceSummaries[summaryIndex],
+                quantity, String.format(decimalFormat, delaySecond));
     }
 
     /**