Java Code Examples for android.view.KeyCharacterMap#load()

The following examples show how to use android.view.KeyCharacterMap#load() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Instrumentation.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
/**
 * Sends the key events corresponding to the text to the app being
 * instrumented.
 * 
 * @param text The text to be sent. 
 */
public void sendStringSync(String text) {
    if (text == null) {
        return;
    }
    KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);

    KeyEvent[] events = keyCharacterMap.getEvents(text.toCharArray());

    if (events != null) {
        for (int i = 0; i < events.length; i++) {
            // We have to change the time of an event before injecting it because
            // all KeyEvents returned by KeyCharacterMap.getEvents() have the same
            // time stamp and the system rejects too old events. Hence, it is
            // possible for an event to become stale before it is injected if it
            // takes too long to inject the preceding ones.
            sendKeySync(KeyEvent.changeTimeRepeat(events[i], SystemClock.uptimeMillis(), 0));
        }
    }
}
 
Example 2
Source File: Instrumentation.java    From droidel with Apache License 2.0 6 votes vote down vote up
/**
 * Sends the key events corresponding to the text to the app being
 * instrumented.
 * 
 * @param text The text to be sent. 
 */
public void sendStringSync(String text) {
    if (text == null) {
        return;
    }
    KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);

    KeyEvent[] events = keyCharacterMap.getEvents(text.toCharArray());

    if (events != null) {
        for (int i = 0; i < events.length; i++) {
            // We have to change the time of an event before injecting it because
            // all KeyEvents returned by KeyCharacterMap.getEvents() have the same
            // time stamp and the system rejects too old events. Hence, it is
            // possible for an event to become stale before it is injected if it
            // takes too long to inject the preceding ones.
            sendKeySync(KeyEvent.changeTimeRepeat(events[i], SystemClock.uptimeMillis(), 0));
        }
    }
}
 
Example 3
Source File: Instrumentation.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Sends the key events corresponding to the text to the app being
 * instrumented.
 * 
 * @param text The text to be sent. 
 */
public void sendStringSync(String text) {
    if (text == null) {
        return;
    }
    KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);

    KeyEvent[] events = keyCharacterMap.getEvents(text.toCharArray());

    if (events != null) {
        for (int i = 0; i < events.length; i++) {
            // We have to change the time of an event before injecting it because
            // all KeyEvents returned by KeyCharacterMap.getEvents() have the same
            // time stamp and the system rejects too old events. Hence, it is
            // possible for an event to become stale before it is injected if it
            // takes too long to inject the preceding ones.
            sendKeySync(KeyEvent.changeTimeRepeat(events[i], SystemClock.uptimeMillis(), 0));
        }
    }
}
 
Example 4
Source File: PjSipService.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Send a dtmf signal to a call
 * 
 * @param callId the call to send the signal
 * @param keyCode the keyCode to send (android style)
 * @return
 */
public int sendDtmf(int callId, int keyCode) throws SameThreadException {
    if (!created) {
        return -1;
    }
    String keyPressed = "";
    // Since some device (xoom...) are apparently buggy with key character
    // map loading...
    // we have to do crappy thing here
    if (keyCode >= KeyEvent.KEYCODE_0 && keyCode <= KeyEvent.KEYCODE_9) {
        keyPressed = Integer.toString(keyCode - KeyEvent.KEYCODE_0);
    } else if (keyCode == KeyEvent.KEYCODE_POUND) {
        keyPressed = "#";
    } else if (keyCode == KeyEvent.KEYCODE_STAR) {
        keyPressed = "*";
    } else {
        // Fallback... should never be there if using visible dialpad, but
        // possible using keyboard
        KeyCharacterMap km = KeyCharacterMap.load(KeyCharacterMap.NUMERIC);
        keyPressed = Integer.toString(km.getNumber(keyCode));
    }
    return sendDtmf(callId, keyPressed);
}
 
Example 5
Source File: Instrumentation.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Sends the key events corresponding to the text to the app being
 * instrumented.
 * 
 * @param text The text to be sent. 
 */
public void sendStringSync(String text) {
    if (text == null) {
        return;
    }
    KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
    
    KeyEvent[] events = keyCharacterMap.getEvents(text.toCharArray());
    
    if (events != null) {
        for (int i = 0; i < events.length; i++) {
            sendKeySync(events[i]);
        }
    }        
}
 
Example 6
Source File: UiControllerImpl.java    From android-test with Apache License 2.0 5 votes vote down vote up
@SuppressLint("InlinedApi")
@VisibleForTesting
@SuppressWarnings("deprecation")
public static KeyCharacterMap getKeyCharacterMap() {
  KeyCharacterMap keyCharacterMap = null;

  // KeyCharacterMap.VIRTUAL_KEYBOARD is present from API11.
  // For earlier APIs we use KeyCharacterMap.BUILT_IN_KEYBOARD
  if (Build.VERSION.SDK_INT < 11) {
    keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
  } else {
    keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
  }
  return keyCharacterMap;
}
 
Example 7
Source File: TimePickerDialog.java    From Conquer with Apache License 2.0 5 votes vote down vote up
/**
 * Get the keycode value for AM and PM in the current language.
 */
private int getAmOrPmKeyCode(int amOrPm) {
    // Cache the codes.
    if (mAmKeyCode == -1 || mPmKeyCode == -1) {
        // Find the first character in the AM/PM text that is unique.
        KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
        char amChar;
        char pmChar;
        for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
            amChar = mAmText.toLowerCase(Locale.getDefault()).charAt(i);
            pmChar = mPmText.toLowerCase(Locale.getDefault()).charAt(i);
            if (amChar != pmChar) {
                KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
                // There should be 4 events: a down and up for both AM and PM.
                if (events != null && events.length == 4) {
                    mAmKeyCode = events[0].getKeyCode();
                    mPmKeyCode = events[2].getKeyCode();
                } else {
                    Log.e(TAG, "Unable to find keycodes for AM and PM.");
                }
                break;
            }
        }
    }
    if (amOrPm == AM) {
        return mAmKeyCode;
    } else if (amOrPm == PM) {
        return mPmKeyCode;
    }

    return -1;
}
 
Example 8
Source File: SublimeTimePicker.java    From SublimePicker with Apache License 2.0 5 votes vote down vote up
/**
 * Get the keycode value for AM and PM in the current language.
 */
private int getAmOrPmKeyCode(int amOrPm) {
    // Cache the codes.
    if (mAmKeyCode == -1 || mPmKeyCode == -1) {
        // Find the first character in the AM/PM text that is unique.
        final KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
        final CharSequence amText = mAmText.toLowerCase(mCurrentLocale);
        final CharSequence pmText = mPmText.toLowerCase(mCurrentLocale);
        final int N = Math.min(amText.length(), pmText.length());
        for (int i = 0; i < N; i++) {
            final char amChar = amText.charAt(i);
            final char pmChar = pmText.charAt(i);
            if (amChar != pmChar) {
                // There should be 4 events: a down and up for both AM and PM.
                final KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
                if (events != null && events.length == 4) {
                    mAmKeyCode = events[0].getKeyCode();
                    mPmKeyCode = events[2].getKeyCode();
                } else {
                    Log.e(TAG, "Unable to find keycodes for AM and PM.");
                }
                break;
            }
        }
    }

    if (amOrPm == AM) {
        return mAmKeyCode;
    } else if (amOrPm == PM) {
        return mPmKeyCode;
    }

    return -1;
}
 
Example 9
Source File: TimePickerDialog.java    From date_picker_converter with Apache License 2.0 5 votes vote down vote up
/**
 * Get the keycode value for AM and PM in the current language.
 */
private int getAmOrPmKeyCode(int amOrPm) {
    // Cache the codes.
    if (mAmKeyCode == -1 || mPmKeyCode == -1) {
        // Find the first character in the AM/PM text that is unique.
        KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
        char amChar;
        char pmChar;
        for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
            amChar = mAmText.toLowerCase(mLocale).charAt(i);
            pmChar = mPmText.toLowerCase(mLocale).charAt(i);
            if (amChar != pmChar) {
                KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
                // There should be 4 events: a down and up for both AM and PM.
                if (events != null && events.length == 4) {
                    mAmKeyCode = events[0].getKeyCode();
                    mPmKeyCode = events[2].getKeyCode();
                } else {
                    Log.e(TAG, "Unable to find keycodes for AM and PM.");
                }
                break;
            }
        }
    }
    if (amOrPm == AM) {
        return mAmKeyCode;
    } else if (amOrPm == PM) {
        return mPmKeyCode;
    }

    return -1;
}
 
Example 10
Source File: TimePickerDialog.java    From MaterialDateRangePicker with Apache License 2.0 5 votes vote down vote up
/**
 * Get the keycode value for AM and PM in the current language.
 */
private int getAmOrPmKeyCode(int amOrPm) {
    // Cache the codes.
    if (mAmKeyCode == -1 || mPmKeyCode == -1) {
        // Find the first character in the AM/PM text that is unique.
        KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
        char amChar;
        char pmChar;
        for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
            amChar = mAmText.toLowerCase(Locale.getDefault()).charAt(i);
            pmChar = mPmText.toLowerCase(Locale.getDefault()).charAt(i);
            if (amChar != pmChar) {
                KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
                // There should be 4 events: a down and up for both AM and PM.
                if (events != null && events.length == 4) {
                    mAmKeyCode = events[0].getKeyCode();
                    mPmKeyCode = events[2].getKeyCode();
                } else {
                    Log.e(TAG, "Unable to find keycodes for AM and PM.");
                }
                break;
            }
        }
    }
    if (amOrPm == AM) {
        return mAmKeyCode;
    } else if (amOrPm == PM) {
        return mPmKeyCode;
    }

    return -1;
}
 
Example 11
Source File: TimePickerDialog.java    From Blackbulb with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the keycode value for AM and PM in the current language.
 */
private int getAmOrPmKeyCode(int amOrPm) {
    // Cache the codes.
    if (mAmKeyCode == -1 || mPmKeyCode == -1) {
        // Find the first character in the AM/PM text that is unique.
        KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
        char amChar;
        char pmChar;
        for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
            amChar = mAmText.toLowerCase(Locale.getDefault()).charAt(i);
            pmChar = mPmText.toLowerCase(Locale.getDefault()).charAt(i);
            if (amChar != pmChar) {
                KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
                // There should be 4 events: a down and up for both AM and PM.
                if (events != null && events.length == 4) {
                    mAmKeyCode = events[0].getKeyCode();
                    mPmKeyCode = events[2].getKeyCode();
                } else {
                    Log.e(TAG, "Unable to find keycodes for AM and PM.");
                }
                break;
            }
        }
    }
    if (amOrPm == AM) {
        return mAmKeyCode;
    } else if (amOrPm == PM) {
        return mPmKeyCode;
    }

    return -1;
}
 
Example 12
Source File: GridTimePickerDialog.java    From BottomSheetPickers with Apache License 2.0 5 votes vote down vote up
/**
 * Get the keycode value for AM and PM in the current language.
 */
private int getAmOrPmKeyCode(int amOrPm) {
    // Cache the codes.
    if (mAmKeyCode == -1 || mPmKeyCode == -1) {
        // Find the first character in the AM/PM text that is unique.
        KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
        char amChar;
        char pmChar;
        for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
            amChar = mAmText.toLowerCase(Locale.getDefault()).charAt(i);
            pmChar = mPmText.toLowerCase(Locale.getDefault()).charAt(i);
            if (amChar != pmChar) {
                KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
                // There should be 4 events: a down and up for both AM and PM.
                if (events != null && events.length == 4) {
                    mAmKeyCode = events[0].getKeyCode();
                    mPmKeyCode = events[2].getKeyCode();
                } else {
                    Log.e(TAG, "Unable to find keycodes for AM and PM.");
                }
                break;
            }
        }
    }
    if (amOrPm == HALF_DAY_1) {
        return mAmKeyCode;
    } else if (amOrPm == HALF_DAY_2) {
        return mPmKeyCode;
    }

    return -1;
}
 
Example 13
Source File: TimePickerDialog.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
/**
 * Get the keycode value for AM and PM in the current language.
 */
private int getAmOrPmKeyCode(int amOrPm) {
    // Cache the codes.
    if (mAmKeyCode == -1 || mPmKeyCode == -1) {
        // Find the first character in the AM/PM text that is unique.
        KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
        char amChar;
        char pmChar;
        for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
            amChar = mAmText.toLowerCase(Locale.getDefault()).charAt(i);
            pmChar = mPmText.toLowerCase(Locale.getDefault()).charAt(i);
            if (amChar != pmChar) {
                KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
                // There should be 4 events: a down and up for both AM and PM.
                if (events != null && events.length == 4) {
                    mAmKeyCode = events[0].getKeyCode();
                    mPmKeyCode = events[2].getKeyCode();
                } else {
                    Log.e(TAG, "Unable to find keycodes for AM and PM.");
                }
                break;
            }
        }
    }
    if (amOrPm == AM) {
        return mAmKeyCode;
    } else if (amOrPm == PM) {
        return mPmKeyCode;
    }

    return -1;
}
 
Example 14
Source File: TimePickerDialog.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
/**
 * Get the keycode value for AM and PM in the current language.
 */
private int getAmOrPmKeyCode(int amOrPm) {
    // Cache the codes.
    if (mAmKeyCode == -1 || mPmKeyCode == -1) {
        // Find the first character in the AM/PM text that is unique.
        KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
        char amChar;
        char pmChar;
        for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
            amChar = mAmText.toLowerCase(Locale.getDefault()).charAt(i);
            pmChar = mPmText.toLowerCase(Locale.getDefault()).charAt(i);
            if (amChar != pmChar) {
                KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
                // There should be 4 events: a down and up for both AM and PM.
                if (events != null && events.length == 4) {
                    mAmKeyCode = events[0].getKeyCode();
                    mPmKeyCode = events[2].getKeyCode();
                } else {
                    Log.e(TAG, "Unable to find keycodes for AM and PM.");
                }
                break;
            }
        }
    }
    if (amOrPm == AM) {
        return mAmKeyCode;
    } else if (amOrPm == PM) {
        return mPmKeyCode;
    }

    return -1;
}
 
Example 15
Source File: InputHelper.java    From XposedSmsCode with GNU General Public License v3.0 5 votes vote down vote up
/**
 * refer: com.android.commands.input.Input#sendText()
 *
 * @throws Throwable throwable throws if the caller has no android.permission.INJECT_EVENTS permission
 */
public static void sendText(String text) throws Throwable {
    int source = InputDevice.SOURCE_KEYBOARD;

    StringBuilder sb = new StringBuilder(text);

    boolean escapeFlag = false;
    for (int i = 0; i < sb.length(); i++) {
        if (escapeFlag) {
            escapeFlag = false;
            if (sb.charAt(i) == 's') {
                sb.setCharAt(i, ' ');
                sb.deleteCharAt(--i);
            }
        }
        if (sb.charAt(i) == '%') {
            escapeFlag = true;
        }
    }

    char[] chars = sb.toString().toCharArray();

    KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
    KeyEvent[] events = kcm.getEvents(chars);
    for (KeyEvent keyEvent : events) {
        if (source != keyEvent.getSource()) {
            keyEvent.setSource(source);
        }
        injectKeyEvent(keyEvent);
    }
}
 
Example 16
Source File: PersianTimePickerDialog.java    From PersianDateRangePicker with Apache License 2.0 5 votes vote down vote up
/**
 * Get the keycode value for AM and PM in the current language.
 */
private int getAmOrPmKeyCode(int amOrPm) {
  // Cache the codes.
  if (mAmKeyCode == -1 || mPmKeyCode == -1) {
    // Find the first character in the AM/PM text that is unique.
    KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
    char amChar;
    char pmChar;
    for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
      amChar = mAmText.toLowerCase(Locale.getDefault()).charAt(i);
      pmChar = mPmText.toLowerCase(Locale.getDefault()).charAt(i);
      if (amChar != pmChar) {
        KeyEvent[] events = kcm.getEvents(new char[] {amChar, pmChar});
        // There should be 4 events: a down and up for both AM and PM.
        if (events != null && events.length == 4) {
          mAmKeyCode = events[0].getKeyCode();
          mPmKeyCode = events[2].getKeyCode();
        } else {
          Log.e(TAG, "Unable to find keycodes for AM and PM.");
        }
        break;
      }
    }
  }
  if (amOrPm == AM) {
    return mAmKeyCode;
  } else if (amOrPm == PM) {
    return mPmKeyCode;
  }

  return -1;
}
 
Example 17
Source File: TimePickerDialog.java    From DateTimepicker with Apache License 2.0 5 votes vote down vote up
/**
 * Get the keycode value for AM and PM in the current language.
 */
private int getAmOrPmKeyCode(int amOrPm) {
    // Cache the codes.
    if (mAmKeyCode == -1 || mPmKeyCode == -1) {
        // Find the first character in the AM/PM text that is unique.
        KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
        char amChar;
        char pmChar;
        for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
            amChar = mAmText.toLowerCase(Locale.getDefault()).charAt(i);
            pmChar = mPmText.toLowerCase(Locale.getDefault()).charAt(i);
            if (amChar != pmChar) {
                KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
                // There should be 4 events: a down and up for both AM and PM.
                if (events != null && events.length == 4) {
                    mAmKeyCode = events[0].getKeyCode();
                    mPmKeyCode = events[2].getKeyCode();
                } else {
                    Log.e(TAG, "Unable to find keycodes for AM and PM.");
                }
                break;
            }
        }
    }
    if (amOrPm == AM) {
        return mAmKeyCode;
    } else if (amOrPm == PM) {
        return mPmKeyCode;
    }

    return -1;
}
 
Example 18
Source File: ActionBarSherlockCompat.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
private boolean preparePanel() {
    // Already prepared (isPrepared will be reset to false later)
    if (mMenuIsPrepared) {
        return true;
    }

    // Init the panel state's menu--return false if init failed
    if (mMenu == null || mMenuRefreshContent) {
        if (mMenu == null) {
            if (!initializePanelMenu() || (mMenu == null)) {
                return false;
            }
        }

        if (wActionBar != null) {
            wActionBar.setMenu(mMenu, this);
        }

        // Call callback, and return if it doesn't want to display menu.

        // Creating the panel menu will involve a lot of manipulation;
        // don't dispatch change events to presenters until we're done.
        mMenu.stopDispatchingItemsChanged();
        if (!callbackCreateOptionsMenu(mMenu)) {
            // Ditch the menu created above
            mMenu = null;

            if (wActionBar != null) {
                // Don't show it in the action bar either
                wActionBar.setMenu(null, this);
            }

            return false;
        }

        mMenuRefreshContent = false;
    }

    // Callback and return if the callback does not want to show the menu

    // Preparing the panel menu can involve a lot of manipulation;
    // don't dispatch change events to presenters until we're done.
    mMenu.stopDispatchingItemsChanged();

    // Restore action view state before we prepare. This gives apps
    // an opportunity to override frozen/restored state in onPrepare.
    if (mMenuFrozenActionViewState != null) {
        mMenu.restoreActionViewStates(mMenuFrozenActionViewState);
        mMenuFrozenActionViewState = null;
    }

    if (!callbackPrepareOptionsMenu(mMenu)) {
        if (wActionBar != null) {
            // The app didn't want to show the menu for now but it still exists.
            // Clear it out of the action bar.
            wActionBar.setMenu(null, this);
        }
        mMenu.startDispatchingItemsChanged();
        return false;
    }

    // Set the proper keymap
    KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
    mMenu.setQwertyMode(kmap.getKeyboardType() != KeyCharacterMap.NUMERIC);
    mMenu.startDispatchingItemsChanged();

    // Set other state
    mMenuIsPrepared = true;

    return true;
}
 
Example 19
Source File: ActionsExecutor.java    From appium-uiautomator2-server with Apache License 2.0 4 votes vote down vote up
public ActionsExecutor(ActionTokens actionTokens) {
    this.actionTokens = actionTokens;
    this.keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
    this.interactionController = UiAutomatorBridge.getInstance().getInteractionController();
}
 
Example 20
Source File: ActionBarSherlockCompat.java    From zen4android with MIT License 4 votes vote down vote up
private boolean preparePanel() {
    // Already prepared (isPrepared will be reset to false later)
    if (mMenuIsPrepared) {
        return true;
    }

    // Init the panel state's menu--return false if init failed
    if (mMenu == null || mMenuRefreshContent) {
        if (mMenu == null) {
            if (!initializePanelMenu() || (mMenu == null)) {
                return false;
            }
        }

        if (wActionBar != null) {
            wActionBar.setMenu(mMenu, this);
        }

        // Call callback, and return if it doesn't want to display menu.

        // Creating the panel menu will involve a lot of manipulation;
        // don't dispatch change events to presenters until we're done.
        mMenu.stopDispatchingItemsChanged();
        if (!callbackCreateOptionsMenu(mMenu)) {
            // Ditch the menu created above
            mMenu = null;

            if (wActionBar != null) {
                // Don't show it in the action bar either
                wActionBar.setMenu(null, this);
            }

            return false;
        }

        mMenuRefreshContent = false;
    }

    // Callback and return if the callback does not want to show the menu

    // Preparing the panel menu can involve a lot of manipulation;
    // don't dispatch change events to presenters until we're done.
    mMenu.stopDispatchingItemsChanged();

    // Restore action view state before we prepare. This gives apps
    // an opportunity to override frozen/restored state in onPrepare.
    if (mMenuFrozenActionViewState != null) {
        mMenu.restoreActionViewStates(mMenuFrozenActionViewState);
        mMenuFrozenActionViewState = null;
    }

    if (!callbackPrepareOptionsMenu(mMenu)) {
        if (wActionBar != null) {
            // The app didn't want to show the menu for now but it still exists.
            // Clear it out of the action bar.
            wActionBar.setMenu(null, this);
        }
        mMenu.startDispatchingItemsChanged();
        return false;
    }

    // Set the proper keymap
    KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
    mMenu.setQwertyMode(kmap.getKeyboardType() != KeyCharacterMap.NUMERIC);
    mMenu.startDispatchingItemsChanged();

    // Set other state
    mMenuIsPrepared = true;

    return true;
}