Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How long is the event onLongPress in the Android?

Android supports an event onLongPress. The question I have is 'how long' (in milliseconds) is the 'press' to trigger the event?

like image 687
mobibob Avatar asked Dec 18 '09 21:12

mobibob


People also ask

How many seconds is a long press?

To "long press" a Control Center remote button simply find the button you'd like to use, and then press down and hold the button for 2 seconds. To double-press a Control Center remote button simply find the button you'd like to use, and then tap that button twice.


3 Answers

The standard long press time is what is returned by getLongPressTimeout(), which is currently 500ms but may change (in 1.0 it was 1000ms but changed in a later release; maybe in the future it will be user-customizable).

The browser uses its own long press time because it has some more complicated interactions. I believe this should be 1000, though again it may change in the future. It is not adding the different timeouts together.

like image 95
hackbod Avatar answered Oct 18 '22 23:10

hackbod


You can use the getLongPressTimeout method in android.view.ViewConfiguration to programmatically determine this value.

See the docs for details.

like image 32
Roman Nurik Avatar answered Oct 18 '22 21:10

Roman Nurik


Generally, like Roman Nurik mentioned, you can use ViewConfiguration.getLongPressTimeout() to programmatically obtain long press value value. The default value is 500ms.

/**
 * Defines the default duration in milliseconds before a press turns into
 * a long press
 */
private static final int DEFAULT_LONG_PRESS_TIMEOUT = 500;

But, the long press duration is customizable globally by setting it in accessibility. Values are Short (400 ms), Medium (1000 ms) or Long (1500 ms). You can see its source code in Settings:

// Long press timeout.
mSelectLongPressTimeoutPreference =
        (ListPreference) findPreference(SELECT_LONG_PRESS_TIMEOUT_PREFERENCE);
mSelectLongPressTimeoutPreference.setOnPreferenceChangeListener(this);
if (mLongPressTimeoutValueToTitleMap.size() == 0) {
    String[] timeoutValues = getResources().getStringArray(
            R.array.long_press_timeout_selector_values);
    mLongPressTimeoutDefault = Integer.parseInt(timeoutValues[0]);
    String[] timeoutTitles = getResources().getStringArray(
            R.array.long_press_timeout_selector_titles);
    final int timeoutValueCount = timeoutValues.length;
    for (int i = 0; i < timeoutValueCount; i++) {
        mLongPressTimeoutValueToTitleMap.put(timeoutValues[i], timeoutTitles[i]);
    }
}
like image 5
Viking Den Avatar answered Oct 18 '22 22:10

Viking Den