Bug 1100742 - Pleasant vibration on long back press. r=bnicholson
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -526,17 +526,17 @@ public class BrowserApp extends GeckoApp
tabHistoryController = new TabHistoryController(new OnShowTabHistory() {
@Override
public void onShowHistory(final List<TabHistoryPage> historyPageList, final int toIndex) {
runOnUiThread(new Runnable() {
@Override
public void run() {
final TabHistoryFragment fragment = TabHistoryFragment.newInstance(historyPageList, toIndex);
final FragmentManager fragmentManager = getSupportFragmentManager();
- GeckoAppShell.vibrateOnHapticFeedbackEnabled(getResources().getInteger(R.integer.long_press_vibrate_msec));
+ GeckoAppShell.vibrateOnHapticFeedbackEnabled(getResources().getIntArray(R.array.long_press_vibrate_msec));
fragment.show(R.id.tab_history_panel, fragmentManager.beginTransaction(), TAB_HISTORY_FRAGMENT_TAG);
}
});
}
});
mBrowserToolbar.setTabHistoryController(tabHistoryController);
final String action = intent.getAction();
--- a/mobile/android/base/GeckoAppShell.java
+++ b/mobile/android/base/GeckoAppShell.java
@@ -1411,20 +1411,29 @@ public class GeckoAppShell
}
}
private static Vibrator vibrator() {
LayerView layerView = getLayerView();
return (Vibrator) layerView.getContext().getSystemService(Context.VIBRATOR_SERVICE);
}
+ // Helper method to convert integer array to long array.
+ private static long[] convertIntToLongArray(int[] input) {
+ long[] output = new long[input.length];
+ for (int i = 0; i < input.length; i++) {
+ output[i] = input[i];
+ }
+ return output;
+ }
+
// Vibrate only if haptic feedback is enabled.
- public static void vibrateOnHapticFeedbackEnabled(long milliseconds) {
+ public static void vibrateOnHapticFeedbackEnabled(int[] milliseconds) {
if (Settings.System.getInt(getContext().getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) > 0) {
- vibrate(milliseconds);
+ vibrate(convertIntToLongArray(milliseconds), -1);
}
}
@WrapElementForJNI(stubName = "Vibrate1")
public static void vibrate(long milliseconds) {
sVibrationEndTime = System.nanoTime() + milliseconds * 1000000;
sVibrationMaybePlaying = true;
vibrator().vibrate(milliseconds);
--- a/mobile/android/base/resources/values/arrays.xml
+++ b/mobile/android/base/resources/values/arrays.xml
@@ -142,9 +142,16 @@
<string-array name="pref_titlebar_mode_entries">
<item>@string/pref_titlebar_mode_title</item>
<item>@string/pref_titlebar_mode_url</item>
</string-array>
<string-array name="pref_titlebar_mode_values">
<item>0</item>
<item>1</item>
</string-array>
+ <!-- This value is similar to config_longPressVibePattern in android frameworks/base/core/res/res/values/config.xml-->
+ <integer-array name="long_press_vibrate_msec">
+ <item>0</item>
+ <item>1</item>
+ <item>20</item>
+ <item>21</item>
+ </integer-array>
</resources>
--- a/mobile/android/base/resources/values/integers.xml
+++ b/mobile/android/base/resources/values/integers.xml
@@ -3,11 +3,10 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<resources>
<integer name="number_of_top_sites">6</integer>
<integer name="number_of_top_sites_cols">2</integer>
<integer name="max_icon_grid_columns">4</integer>
- <integer name="long_press_vibrate_msec">100</integer>
</resources>