استخدام إيماءات المعصم على Wear OS
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يمكن أن تتيح إيماءات المعصم إجراء تفاعلات سريعة بيد واحدة مع تطبيقك
عندما تكون الشاشة التي تعمل باللمس غير مريحة.
على سبيل المثال، يمكن للمستخدم الانتقال للأعلى أو للأسفل
من خلال الإشعارات بيد واحدة أثناء حمل كوب من الماء
آخر. تشمل حالات الاستخدام الأخرى لإيماءات المعصم ما يلي:
- في تطبيق للركض، التنقل عبر الشاشات العمودية التي تعرض
الخطوات التي تم اتخاذها والوقت المنقضي والوتيرة الحالية
- في أحد تطبيقات السفر، التمرير عبر معلومات الرحلة الجوية والبوابة
- التنقّل بين المقالات في تطبيق للأخبار
لمراجعة إيماءات المعصم على ساعة
جهازك، فتأكد من أن الإيماءات
عن طريق اختيار الإعدادات > الميزات المتقدّمة > الإيماءات > إيماءات المعصم
تفعيل ثم أكمل
الدليل التوجيهي عن الإيماءات على الساعة من خلال اختيار تشغيل البرنامج التعليمي
ملاحظة: هز المعصم هو إيماءة الرجوع إلى الخلف أو التراجع على مستوى النظام.
ولا يتوفّر للتطبيقات لتخصيصها
يمكن استخدام إيماءات المعصم بالطرق التالية، كما هو موضح في هذا الدليل:
يتم ربط كل إيماءة معصم بالعدد الثابت int
من
KeyEvent
كما هو موضح في الجدول التالي:
الإيماءة
|
الحدث الرئيسي
|
الوصف
|
تدوير المعصم بسرعة إلى اليسار ثم تدويره ببطء إلى اليمين
|
KEYCODE_NAVIGATE_NEXT
|
ينتقل رمز المفتاح هذا إلى العنصر التالي.
|
تدوير المعصم ببطء إلى اليسار ثم تدويره بسرعة إلى اليمين
|
KEYCODE_NAVIGATE_PREVIOUS
|
ينتقل رمز المفتاح هذا إلى العنصر السابق.
|
استخدام تصميم منحنٍ لدعم إيماءات المعصم
وتوفر الفئة
WearableRecyclerView
خطًا منحنيًا
للقوائم ويدعم تلقائيًا
إيماءات المعصم. تضم الفئة إجراءات محددة مسبقًا لمرات ورود
إيماءات المعصم عندما يتم التركيز على العرض. للحصول على معلومات حول استخدام
لفئة WearableRecyclerView
، يُرجى الاطّلاع على إنشاء قوائم على Wear OS. راجع أيضًا
قسم أفضل الممارسات في هذا الدليل.
ملاحظة: تحلّ الفئة WearableRecyclerView
محلّ فئة
نهائيًا في مكتبة الدعم القابل للارتداء.
حتى إذا كنت تستخدم WearableRecyclerView
، يمكنك استخدام
الثوابت من KeyEvent
الصف. يمكن إلغاء الإجراءات المحددة مسبقًا من خلال تصنيف
WearableRecyclerView
وإعادة تنفيذ
معاودة الاتصال onKeyDown()
. يمكن إيقاف السلوك تمامًا
باستخدام setEnableGestureNavigation(false)
.
لمزيد من المعلومات، يُرجى مراجعة
التعامل مع إجراءات لوحة المفاتيح
استخدام الأحداث الرئيسية مباشرةً
يمكنك استخدام الأحداث الرئيسية خارج "
WearableRecyclerView
" لتنفيذ إجراءات جديدة استجابةً للإيماءة.
أحداث. الأهم من ذلك أنّه يتم التعرّف على أحداث الإيماءات هذه عندما يكون الجهاز قيد التشغيل.
ووضع النشاط، ويتم تقديمها بالطريقة نفسها مثل جميع الأحداث الرئيسية.
يشير هذا المصطلح إلى فئة تتعلق بتفاعل المستخدم، مثل View
أو
Activity
، وهذا يؤدي إلى تنفيذ
يمكن لـ "
KeyEvent.Callback
" الاستماع إلى الأحداث الرئيسية ذات الصلة
إيماءات المعصم كما يمكن إدراجها في أي حدث رئيسي آخر إطار عمل Android
تستدعي View
أو Activity
الذي يتضمن
بالأحداث الرئيسية. بالنسبة إلى الإيماءات، يجب ضبط onKeyDown()
عند حدوث الإيماءات.
على سبيل المثال، يمكن أن يلغي أحد التطبيقات الإجراءات المحدّدة مسبقًا في View
.
أو Activity
التي تنفِّذ KeyEvent.Callback
على النحو التالي:
Kotlin
class GesturesActivity : Activity() {
/* KeyEvent.Callback */
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
return when (keyCode) {
KeyEvent.KEYCODE_NAVIGATE_NEXT ->
// Do something that advances a user View to the next item in an ordered list.
moveToNextItem()
KeyEvent.KEYCODE_NAVIGATE_PREVIOUS ->
// Do something that advances a user View to the previous item in an ordered list.
moveToPreviousItem()
else -> {
// If you did not handle it, let it be handled by the next possible element as determined
// by the Activity.
super.onKeyDown(keyCode, event)
}
}
}
/** Shows the next item in the custom list. */
private fun moveToNextItem(): Boolean {
...
// Return true if handled successfully, otherwise return false.
return false
}
/** Shows the previous item in the custom list. */
private fun moveToPreviousItem(): Boolean {
...
// Return true if handled successfully, otherwise return false.
return false
}
}
Java
public final class GesturesActivity extends Activity {
@Override /* KeyEvent.Callback */
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_NAVIGATE_NEXT:
// Do something that advances a user View to the next item in an ordered list.
return moveToNextItem();
case KeyEvent.KEYCODE_NAVIGATE_PREVIOUS:
// Do something that advances a user View to the previous item in an ordered list.
return moveToPreviousItem();
}
// If you did not handle it, let it be handled by the next possible element as determined by the Activity.
return super.onKeyDown(keyCode, event);
}
/** Shows the next item in the custom list. */
private boolean moveToNextItem() {
boolean handled = false;
...
// Return true if handled successfully, otherwise return false.
return handled;
}
/** Shows the previous item in the custom list. */
private boolean moveToPreviousItem() {
boolean handled = false;
...
// Return true if handled successfully, otherwise return false.
return handled;
}
}
أفضل الممارسات
- مراجعة
KeyEvent
و
KeyEvent.Callback
صفحة لتسليم الأحداث الرئيسية إلى
View
وActivity
.
- الحفاظ على القدرة على الاتجاهات الثابتة: استخدام "تدوير المعصم للخارج" حيث
التالي و"تدوير المعصم في" السابقة.
- يمكنك إجراء لمس موازٍ لإيماءة.
- تقديم ملاحظات مرئية.
- لا تستخدم رمز مفتاح لتنفيذ وظائف من شأنها
معارضة لبقية النظام. على سبيل المثال، لا تستخدم
KEYCODE_NAVIGATE_NEXT
لإلغاء إجراء أو الانتقال إلى
المحور الأيسر والأيمن مع عمليات النقر.
- لا تعترض الأحداث الرئيسية على العناصر التي ليست جزءًا من
واجهة المستخدم، مثل طرق العرض التي تظهر خارج الشاشة أو بشكل جزئي
. الأمر نفسه ينطبق على أيّ حدث رئيسي.
- يجب عدم إعادة تفسير الإيماءات المتكررة من خلال تدوير المعصم في إيماءة جديدة.
وقد يتعارض هذا مع طريقة "اهتزاز المعصم" في النظام. إيماءة.
لتلقّي الأحداث الرئيسية بالإيماءات، يجب أن يحتوي العرض على
التركيز راجِع
View.setFocusable()
.
ونظرًا لأنه يتم التعامل مع الإيماءات كأحداث رئيسية،
تؤدي إلى الانتقال من "وضع اللمس" قد يحدث ذلك بشكل غير متوقع
باستمرار. نظرًا لتمكّن المستخدمين من التبديل بين استخدام اللمس
الإيماءات، قد يكون استخدام طريقة
View::setFocusableInTouchmode()
ضروريًا. في بعض
الحالات، قد يكون من الضروري أيضًا استخدام
setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS)
إذن
أنه عندما يتغير التركيز بعد تغيير إلى أو من وضع اللمس،
العرض المقصود يحصل على التركيز.
- استخدام
requestFocus()
و
clearFocus()
بعناية:
- عند الاتصال بـ
requestFocus()
، تأكّد من أنّه مناسب
التركيز عليها. إذا كان العرض خارج الشاشة أو مغطى بطريقة عرض أخرى،
مفاجآت عندما تقوم الإيماءات بتشغيل استدعاءات.
- تبدأ الطريقة
clearFocus()
في البحث عن تركيز للعثور على عنصر آخر.
طريقة العرض المناسبة. واعتمادًا على التسلسل الهرمي للعرض، قد يؤدي هذا البحث
تتطلب عمليات حسابية غير بسيطة. يمكن أن ينتهي أيضًا بتخصيص التركيز
إلى طريقة عرض لا تتوقّع أن تجذب التركيز
يتم عرض الأحداث الرئيسية أولاً في قسم العرض مع التركيز على طريقة العرض.
التسلسل الهرمي. إذا لم تعالج طريقة العرض محل التركيز الحدث، وبمعنى آخر، سيتم عرضها
false
: لا يتم تسليم الحدث إلى العرض الرئيسي، حتى
إذا كان بإمكانه التركيز على المحتوى ويتضمّن
KeyListener
وبدلاً من ذلك، يتم تسليم الحدث إلى النشاط الحالي
الضغط مع الاستمرار على التسلسل الهرمي للعرض مع التركيز.
لذلك، قد يكون من الضروري
مشاهدة جميع الأحداث على المستوى الأعلى، ثم تمرير الرموز ذات الصلة إلى أسفل.
وبدلاً من ذلك، يمكنك تصنيف النشاط فرعيًا وإلغاء
طريقة
dispatchKeyEvent(KeyEvent event)
لاعتراض المفاتيح
عند الضرورة أو التعامل معها عندما لا يتم التعامل معها في
والطبقات السفلية.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Use wrist gestures on Wear\n\nWrist gestures can enable quick, one-handed interactions with your app\nwhen a touch screen is inconvenient.\n\n\nFor example, a user can scroll\nthrough notifications with one hand while holding a cup of water with the\nother. Other use cases for wrist gestures include the following:\n\n- In a jogging app, navigating through vertical screens that show the steps taken, time elapsed, and current pace\n- In a travel app, scrolling through flight and gate information\n- In a news app, scrolling through articles\n\n\nTo review the [wrist gestures](https://support.google.com/androidwear/answer/6312406) on a watch\ndevice, confirm that gestures are\nturned on by selecting **Settings \\\u003e Advanced features \\\u003e Gestures \\\u003e Wrist Gestures\nOn** . Then complete the\nGestures tutorial on the watch by selecting **Launch Tutorial**.\n\n\n**Note:** Shaking the wrist is the system-wide back or undo gesture\nand is not available for apps to customize.\n\n\nWrist gestures can be used in the following ways, as described in this guide:\n\n- With a [curved layout](#using_wrv), which has predefined gesture actions\n- By using [key events directly](#using_key_events) to define new user actions\n\n\nEach wrist gesture is mapped to an `int` constant from the\n[KeyEvent](/reference/android/view/KeyEvent)\nclass, as shown in the following table:\n\n| Gesture | KeyEvent | Description |\n|-----------------|-------------------------------------------------------------------------------------------|------------------------------------------|\n| Flick wrist out | [`KEYCODE_NAVIGATE_NEXT`](/reference/android/view/KeyEvent#KEYCODE_NAVIGATE_NEXT) | This key code goes to the next item. |\n| Flick wrist in | [`KEYCODE_NAVIGATE_PREVIOUS`](/reference/android/view/KeyEvent#KEYCODE_NAVIGATE_PREVIOUS) | This key code goes to the previous item. |\n\nUse a curved layout to support wrist gestures\n---------------------------------------------\n\n\nThe [WearableRecyclerView](/reference/androidx/wear/widget/WearableRecyclerView) class provides a curved\nlayout for lists and automatically supports\nwrist gestures. The class has predefined actions for occurrences of\nwrist gestures when the view has focus. For information about using\nthe `WearableRecyclerView` class, see [Create lists on Wear OS](/training/wearables/ui/lists). Also, see the\n[Best practices](#best_practices) section of this guide.\n\n\n**Note:** The `WearableRecyclerView` class replaces a similar,\n[deprecated](/training/wearables/ui/wear-ui-library#deprecations) class in the Wearable Support Library.\n\n\nEven if you use a `WearableRecyclerView`, you might want to use\nconstants from the [KeyEvent](/reference/android/view/KeyEvent)\nclass. The predefined actions can be overridden by subclassing the\n`WearableRecyclerView` and re-implementing the\n`onKeyDown()` callback. The behavior can be disabled entirely\nby using [`setEnableGestureNavigation(false)`](/reference/android/support/wearable/view/WearableListView#setEnableGestureNavigation(boolean)).\nFor more information, see\n[Handle keyboard actions](/training/keyboard-input/commands).\n\nUse key events directly\n-----------------------\n\n\nYou can use key events outside of a [WearableRecyclerView](/reference/androidx/wear/widget/WearableRecyclerView) to trigger new actions in response to gesture\nevents. Importantly, these gesture events are recognized when a device is in\nactive mode, and they are delivered in the same way as all key events.\n\n\nA class that relates to user interaction, such as a `View` or an\n`Activity`, and that implements\n[KeyEvent.Callback](/reference/android/view/KeyEvent.Callback) can listen to key events that relate to\nwrist gestures just as it can listed to any other key event. The Android framework\ncalls the `View` or `Activity` that has\nfocus with the key events. For gestures, the `onKeyDown()`\nmethod callback is called when gestures occur.\n\n\nAs an example, an app can override predefined actions in a `View`\nor `Activity` that implements `KeyEvent.Callback` as follows: \n\n### Kotlin\n\n```kotlin\nclass GesturesActivity : Activity() {\n\n /* KeyEvent.Callback */\n override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {\n return when (keyCode) {\n KeyEvent.KEYCODE_NAVIGATE_NEXT -\u003e\n // Do something that advances a user View to the next item in an ordered list.\n moveToNextItem()\n KeyEvent.KEYCODE_NAVIGATE_PREVIOUS -\u003e\n // Do something that advances a user View to the previous item in an ordered list.\n moveToPreviousItem()\n else -\u003e {\n // If you did not handle it, let it be handled by the next possible element as determined\n // by the Activity.\n super.onKeyDown(keyCode, event)\n }\n }\n }\n\n /** Shows the next item in the custom list. */\n private fun moveToNextItem(): Boolean {\n ...\n // Return true if handled successfully, otherwise return false.\n return false\n }\n\n /** Shows the previous item in the custom list. */\n private fun moveToPreviousItem(): Boolean {\n ...\n // Return true if handled successfully, otherwise return false.\n return false\n }\n}\n```\n\n### Java\n\n```java\npublic final class GesturesActivity extends Activity {\n\n @Override /* KeyEvent.Callback */\n public boolean onKeyDown(int keyCode, KeyEvent event) {\n switch (keyCode) {\n case KeyEvent.KEYCODE_NAVIGATE_NEXT:\n // Do something that advances a user View to the next item in an ordered list.\n return moveToNextItem();\n case KeyEvent.KEYCODE_NAVIGATE_PREVIOUS:\n // Do something that advances a user View to the previous item in an ordered list.\n return moveToPreviousItem();\n }\n // If you did not handle it, let it be handled by the next possible element as determined by the Activity.\n return super.onKeyDown(keyCode, event);\n }\n\n /** Shows the next item in the custom list. */\n private boolean moveToNextItem() {\n boolean handled = false;\n ...\n // Return true if handled successfully, otherwise return false.\n return handled;\n }\n\n /** Shows the previous item in the custom list. */\n private boolean moveToPreviousItem() {\n boolean handled = false;\n ...\n // Return true if handled successfully, otherwise return false.\n return handled;\n }\n}\n```\n\nBest practices\n--------------\n\n- Review the [KeyEvent](/reference/android/view/KeyEvent) and [KeyEvent.Callback](/reference/android/view/KeyEvent.Callback) pages for the delivery of key events to your `View` and `Activity`.\n- Keep a consistent directional affordance: use \"flick wrist out\" for next and \"flick wrist in\" for previous.\n- Have a touch parallel for a gesture.\n- Provide visual feedback.\n- Don't use a keycode to implement functionality that would be counterintuitive to the rest of the system. For example, don't use `KEYCODE_NAVIGATE_NEXT` to cancel an action or to navigate the left-right axis with flicks.\n- Don't intercept the key events on elements that are not part of the user interface, such as views that are offscreen or partially covered. This is the same as for any key event.\n- Don't reinterpret repeated flick gestures into your own novel gesture. This might conflict with the system's \"shaking the wrist\" gesture.\n- For a view to receive gesture key events, it must have [focus](/reference/android/view/View#attr_android:focusable); see [`\n View.setFocusable()`](/reference/android/view/View#setFocusable(boolean)).\n\n Because gestures are treated as key events,\n they trigger a transition out of \"touch mode\" that might do unexpected\n things. Since users may alternate between using touch and\n gestures, the [`\n View::setFocusableInTouchmode()`](/reference/android/view/View#setFocusableInTouchMode(boolean)) method could be necessary. In some\n cases, it also could be necessary to use\n `setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS)` so\n that when focus changes after a change to or from touch mode, your\n intended view gets the focus.\n- Use [requestFocus()](/reference/android/view/View#requestFocus()) and [clearFocus()](/reference/android/view/View#clearFocus()) carefully:\n - When calling `requestFocus()`, make sure it's appropriate for the view to have focus. If the view is offscreen or is covered by another view, surprises can occur when gestures trigger callbacks.\n - The `clearFocus()` method initiates a focus search to find another suitable view. Depending on the view hierarchy, this search might require nontrivial computation. It can also end up assigning focus to a view you don't expect to receive focus.\n- Key events are delivered first to the view with focus in the view\n hierarchy. If the focused view does not handle the event---in other words, it returns\n `false`---the event is not delivered to the parent view, even\n if it can receive focus and has a [`\n KeyListener`](/reference/android/text/method/KeyListener). Rather, the event is delivered to the current activity\n holding the view hierarchy with focus.\n\n Therefore, it might be necessary to\n catch all events at the higher level, then pass relevant codes down.\n Alternatively, you might subclass the activity and override the\n [dispatchKeyEvent(KeyEvent event)](/reference/android/app/Activity#dispatchKeyEvent(android.view.KeyEvent)) method to intercept keys\n when necessary or handle them when they are not handled at\n lower layers."]]