void changedState(boolean canUndo, boolean canRedo) { undoEnabled = canUndo; redoEnabled = canRedo; if (keyboard != null) { keyboard.setUndoRedoEnabled(false, canUndo); keyboard.setUndoRedoEnabled(true, canRedo); } if (actionBarCompat != null && menu != null) { runOnUiThread( new Runnable() { @Override public void run() { MenuItem mi; mi = menu.findItem(R.id.undo); if (mi != null) { mi.setEnabled(undoEnabled); mi.setIcon( undoEnabled ? R.drawable.sym_keyboard_undo : R.drawable.sym_keyboard_undo_disabled); } mi = menu.findItem(R.id.redo); if (mi != null) { mi.setEnabled(redoEnabled); mi.setIcon( redoEnabled ? R.drawable.sym_keyboard_redo : R.drawable.sym_keyboard_redo_disabled); } } }); } }
void setKeyboardVisibility(Configuration c) { boolean landscape = (c.orientation == Configuration.ORIENTATION_LANDSCAPE); if (landscape != prevLandscape || keyboard == null) { // Must recreate KeyboardView on orientation change because it // caches the x,y for its preview popups // http://code.google.com/p/android/issues/detail?id=4559 if (keyboard != null) mainLayout.removeView(keyboard); keyboard = new SmallKeyboard(this, undoEnabled, redoEnabled); keyboard.setId(R.id.keyboard); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams glp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); if (landscape) { lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); lp.addRule(RelativeLayout.ALIGN_PARENT_TOP); lp.addRule(RelativeLayout.ABOVE, R.id.statusBar); glp.addRule(RelativeLayout.ABOVE, R.id.statusBar); glp.addRule(RelativeLayout.LEFT_OF, R.id.keyboard); } else { lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); lp.addRule(RelativeLayout.ABOVE, R.id.statusBar); glp.addRule(RelativeLayout.ABOVE, R.id.keyboard); } mainLayout.updateViewLayout(gameView, glp); mainLayout.addView(keyboard, lp); } keyboard.setKeys( (c.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) ? (maybeUndoRedo + maybeMenu) : lastKeys, lastArrowMode); prevLandscape = landscape; mainLayout.requestLayout(); }