ActionMenuItemView.java revision 7bc3ca0dc52be52ecad1c0de8c62a6a4bf8141ca
196675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell/* 296675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * Copyright (C) 2010 The Android Open Source Project 396675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * 496675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 596675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * you may not use this file except in compliance with the License. 696675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * You may obtain a copy of the License at 796675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * 896675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * http://www.apache.org/licenses/LICENSE-2.0 996675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * 1096675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * Unless required by applicable law or agreed to in writing, software 1196675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * distributed under the License is distributed on an "AS IS" BASIS, 1296675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1396675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * See the License for the specific language governing permissions and 1496675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * limitations under the License. 1596675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell */ 1696675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell 1796675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powellpackage com.android.internal.view.menu; 1896675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell 1996675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powellimport android.content.Context; 2035aecd5884a5ccfe380903e39f30f468315e8f92Adam Powellimport android.content.res.Resources; 217b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powellimport android.graphics.Rect; 2296675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powellimport android.graphics.drawable.Drawable; 23c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunneimport android.text.TextUtils; 2496675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powellimport android.util.AttributeSet; 257b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powellimport android.view.Gravity; 267bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powellimport android.view.MotionEvent; 2796675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powellimport android.view.View; 287bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powellimport android.view.accessibility.AccessibilityEvent; 291f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powellimport android.widget.Button; 3096675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powellimport android.widget.ImageButton; 31d8404b23739b135060ab9a04317a9f8b990cf8caAdam Powellimport android.widget.LinearLayout; 327b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powellimport android.widget.Toast; 3396675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell 3496675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell/** 3596675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell * @hide 3696675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell */ 37d8404b23739b135060ab9a04317a9f8b990cf8caAdam Powellpublic class ActionMenuItemView extends LinearLayout 387b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell implements MenuView.ItemView, View.OnClickListener, View.OnLongClickListener, 397b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell ActionMenuView.ActionMenuChildView { 4096675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell private static final String TAG = "ActionMenuItemView"; 41a8a72c38fec3879f5d346840b0d186d5903931b8Jeff Sharkey 4296675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell private MenuItemImpl mItemData; 4396675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell private CharSequence mTitle; 4496675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell private MenuBuilder.ItemInvoker mItemInvoker; 45a8a72c38fec3879f5d346840b0d186d5903931b8Jeff Sharkey 461f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell private ImageButton mImageButton; 471f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell private Button mTextButton; 4835aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell private boolean mAllowTextWithIcon; 4935aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell private boolean mShowTextAllCaps; 5035aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell private boolean mExpandedFormat; 511f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell 5296675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public ActionMenuItemView(Context context) { 5396675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell this(context, null); 5496675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 55a8a72c38fec3879f5d346840b0d186d5903931b8Jeff Sharkey 5696675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public ActionMenuItemView(Context context, AttributeSet attrs) { 5735aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell this(context, attrs, 0); 5896675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 59a8a72c38fec3879f5d346840b0d186d5903931b8Jeff Sharkey 6096675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public ActionMenuItemView(Context context, AttributeSet attrs, int defStyle) { 6196675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell super(context, attrs, defStyle); 6235aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell final Resources res = context.getResources(); 6335aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell mAllowTextWithIcon = res.getBoolean( 6435aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell com.android.internal.R.bool.config_allowActionMenuItemTextWithIcon); 6535aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell mShowTextAllCaps = res.getBoolean(com.android.internal.R.bool.config_actionMenuItemAllCaps); 6696675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 6796675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell 681f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell @Override 691f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell public void onFinishInflate() { 701f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell mImageButton = (ImageButton) findViewById(com.android.internal.R.id.imageButton); 711f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell mTextButton = (Button) findViewById(com.android.internal.R.id.textButton); 721f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell mImageButton.setOnClickListener(this); 731f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell mTextButton.setOnClickListener(this); 747b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell mImageButton.setOnLongClickListener(this); 756bddd8771d05889024778caa78fb1eaae68a0802Adam Powell setOnClickListener(this); 767b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell setOnLongClickListener(this); 771f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell } 781f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell 7996675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public MenuItemImpl getItemData() { 8096675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell return mItemData; 8196675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 8296675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell 8396675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public void initialize(MenuItemImpl itemData, int menuType) { 8496675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell mItemData = itemData; 85a8a72c38fec3879f5d346840b0d186d5903931b8Jeff Sharkey 8696675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell setIcon(itemData.getIcon()); 87e7d468410b3a783560d5158a5798cef1b4b67702Adam Powell setTitle(itemData.getTitleForItemView(this)); // Title only takes effect if there is no icon 8896675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell setId(itemData.getItemId()); 89a8a72c38fec3879f5d346840b0d186d5903931b8Jeff Sharkey 9096675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell setVisibility(itemData.isVisible() ? View.VISIBLE : View.GONE); 9196675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell setEnabled(itemData.isEnabled()); 9296675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 93a8a72c38fec3879f5d346840b0d186d5903931b8Jeff Sharkey 9400df32d4396a65752b7b9a2f8ceb6292ed2384cfAdam Powell @Override 9500df32d4396a65752b7b9a2f8ceb6292ed2384cfAdam Powell public void setEnabled(boolean enabled) { 9600df32d4396a65752b7b9a2f8ceb6292ed2384cfAdam Powell super.setEnabled(enabled); 9700df32d4396a65752b7b9a2f8ceb6292ed2384cfAdam Powell mImageButton.setEnabled(enabled); 9800df32d4396a65752b7b9a2f8ceb6292ed2384cfAdam Powell mTextButton.setEnabled(enabled); 9900df32d4396a65752b7b9a2f8ceb6292ed2384cfAdam Powell } 10000df32d4396a65752b7b9a2f8ceb6292ed2384cfAdam Powell 1011f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell public void onClick(View v) { 1021f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell if (mItemInvoker != null) { 1031f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell mItemInvoker.invokeItem(mItemData); 10496675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 10596675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 106a8a72c38fec3879f5d346840b0d186d5903931b8Jeff Sharkey 10796675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public void setItemInvoker(MenuBuilder.ItemInvoker invoker) { 10896675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell mItemInvoker = invoker; 10996675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 11096675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell 11196675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public boolean prefersCondensedTitle() { 112e7d468410b3a783560d5158a5798cef1b4b67702Adam Powell return true; 11396675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 11496675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell 11596675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public void setCheckable(boolean checkable) { 11696675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell // TODO Support checkable action items 11796675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 11896675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell 11996675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public void setChecked(boolean checked) { 12096675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell // TODO Support checkable action items 12196675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 12296675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell 12335aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell public void setExpandedFormat(boolean expandedFormat) { 12435aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell if (mExpandedFormat != expandedFormat) { 12535aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell mExpandedFormat = expandedFormat; 12635aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell if (mItemData != null) { 12735aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell mItemData.actionFormatChanged(); 12835aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell } 12935aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell } 13035aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell } 13135aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell 132c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne private void updateTextButtonVisibility() { 133c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne boolean visible = !TextUtils.isEmpty(mTextButton.getText()); 13435aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell visible &= mImageButton.getDrawable() == null || 13535aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell (mItemData.showsTextAsAction() && (mAllowTextWithIcon || mExpandedFormat)); 13635aecd5884a5ccfe380903e39f30f468315e8f92Adam Powell 137c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne mTextButton.setVisibility(visible ? VISIBLE : GONE); 138c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne } 139c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne 14096675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public void setIcon(Drawable icon) { 1411f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell mImageButton.setImageDrawable(icon); 1421f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell if (icon != null) { 1431f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell mImageButton.setVisibility(VISIBLE); 1441f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell } else { 1451f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell mImageButton.setVisibility(GONE); 1461f9c7afc5a06576e327a4b1c12688202f53d9462Adam Powell } 1479f125d341521efc8535e32e35a641be50d405c36Adam Powell 148c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne updateTextButtonVisibility(); 14996675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 150c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne 151be4d68e7b238b8ee879de0481e39c40d3f1683b6Adam Powell public boolean hasText() { 152be4d68e7b238b8ee879de0481e39c40d3f1683b6Adam Powell return mTextButton.getVisibility() != GONE; 153be4d68e7b238b8ee879de0481e39c40d3f1683b6Adam Powell } 15496675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell 15596675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public void setShortcut(boolean showShortcut, char shortcutKey) { 15696675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell // Action buttons don't show text for shortcut keys. 15796675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 15896675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell 15996675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public void setTitle(CharSequence title) { 16096675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell mTitle = title; 161a8a72c38fec3879f5d346840b0d186d5903931b8Jeff Sharkey 1627f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell mTextButton.setText(mTitle); 163c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne 1647bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell setContentDescription(mTitle); 165c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne updateTextButtonVisibility(); 16696675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 16796675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell 1687bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell @Override 1697bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { 1707bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell onPopulateAccessibilityEvent(event); 1717bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell return true; 1727bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell } 1737bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell 1747bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell @Override 1757bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell public void onPopulateAccessibilityEvent(AccessibilityEvent event) { 1767bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell super.onPopulateAccessibilityEvent(event); 1777bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell final CharSequence cdesc = getContentDescription(); 1787bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell if (!TextUtils.isEmpty(cdesc)) { 1797bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell event.getText().add(cdesc); 1807bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell } 1817bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell } 1827bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell 1837bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell @Override 1847bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell public boolean dispatchHoverEvent(MotionEvent event) { 1857bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell // Don't allow children to hover; we want this to be treated as a single component. 1867bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell return onHoverEvent(event); 1877bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell } 1887bc3ca0dc52be52ecad1c0de8c62a6a4bf8141caAdam Powell 18996675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell public boolean showsIcon() { 19096675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell return true; 19196675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell } 192696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell 193696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell public boolean needsDividerBefore() { 194696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell return hasText() && mItemData.getIcon() == null; 195696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell } 196696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell 197696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell public boolean needsDividerAfter() { 198696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell return hasText(); 199696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell } 2007b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell 2017b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell @Override 2027b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell public boolean onLongClick(View v) { 2037b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell if (hasText()) { 2047b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell // Don't show the cheat sheet for items that already show text. 2057b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell return false; 2067b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell } 2077b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell 2087b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell final int[] screenPos = new int[2]; 2097b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell final Rect displayFrame = new Rect(); 2107b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell getLocationOnScreen(screenPos); 2117b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell getWindowVisibleDisplayFrame(displayFrame); 2127b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell 2137b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell final Context context = getContext(); 2147b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell final int width = getWidth(); 2157b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell final int height = getHeight(); 2167b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell final int midy = screenPos[1] + height / 2; 2177b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; 2187b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell 2197b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT); 2207b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell if (midy < displayFrame.height()) { 2217b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell // Show along the top; follow action buttons 2227b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell cheatSheet.setGravity(Gravity.TOP | Gravity.RIGHT, 2237b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell screenWidth - screenPos[0] - width / 2, height); 2247b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell } else { 2257b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell // Show along the bottom center 2267b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); 2277b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell } 2287b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell cheatSheet.show(); 2297b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell return true; 2307b5e9e6c1c7098b6d7b2c6f9ab0c316f0f66109eAdam Powell } 23196675b1df3969f2d313b68f60ed9fa36805db8ceAdam Powell} 232