Пример #1
0
 @Override
 public void onConfigurationChanged(Configuration newConfig) {
   setKeyboardVisibility(newConfig);
   super.onConfigurationChanged(newConfig);
   if (actionBarCompat != null) {
     // ActionBar's capacity (width) has probably changed, so work around
     // http://code.google.com/p/android/issues/detail?id=20493
     // (invalidateOptionsMenu() does not help here)
     if (actionBarCompat != null) {
       // Just cautiously fix the common case: if >850dip then force
       // show everything, else let the platform decide
       DisplayMetrics dm = getResources().getDisplayMetrics();
       int screenWidthDIP = (int) Math.round(((double) dm.widthPixels) / dm.density);
       boolean reallyWide = screenWidthDIP > 850;
       int state =
           reallyWide
               ? ActionBarCompat.SHOW_AS_ACTION_ALWAYS
               : ActionBarCompat.SHOW_AS_ACTION_IF_ROOM;
       actionBarCompat.menuItemSetShowAsAction(menu.findItem(R.id.settings), state);
       actionBarCompat.menuItemSetShowAsAction(menu.findItem(R.id.solve), state);
       actionBarCompat.menuItemSetShowAsAction(menu.findItem(R.id.help), state);
       state |= ActionBarCompat.SHOW_AS_ACTION_WITH_TEXT;
       actionBarCompat.menuItemSetShowAsAction(menu.findItem(R.id.game), state);
       actionBarCompat.menuItemSetShowAsAction(menu.findItem(R.id.type), state);
       actionBarCompat.menuItemSetShowAsAction(menu.findItem(R.id.other), state);
     }
   }
 }
Пример #2
0
 @Override
 public boolean onPrepareOptionsMenu(Menu menu) {
   super.onPrepareOptionsMenu(menu);
   hackForSubmenus = menu;
   if (progress != null && (actionBarCompat == null || actionBarCompat.hasMenuButton()))
     return false; // not safe/useful until game is loaded
   MenuItem item;
   item = menu.findItem(R.id.solve);
   item.setEnabled(solveEnabled);
   if (actionBarCompat != null) item.setVisible(solveEnabled);
   MenuItem undoItem = menu.findItem(R.id.undo), redoItem = menu.findItem(R.id.redo);
   undoItem.setEnabled(undoEnabled);
   redoItem.setEnabled(redoEnabled);
   undoItem.setIcon(
       undoEnabled ? R.drawable.sym_keyboard_undo : R.drawable.sym_keyboard_undo_disabled);
   redoItem.setIcon(
       redoEnabled ? R.drawable.sym_keyboard_redo : R.drawable.sym_keyboard_redo_disabled);
   item = menu.findItem(R.id.type);
   item.setEnabled(!gameTypes.isEmpty() || customVisible);
   if (actionBarCompat != null) item.setVisible(item.isEnabled());
   typeMenu = item.getSubMenu();
   for (Integer i : gameTypes.keySet()) {
     if (menu.findItem(i) == null) typeMenu.add(R.id.typeGroup, i, Menu.NONE, gameTypes.get(i));
   }
   MenuItem customItem = menu.findItem(R.id.custom);
   customItem.setVisible(customVisible);
   typeMenu.setGroupCheckable(R.id.typeGroup, true, true);
   if (currentType < 0) customItem.setChecked(true);
   else if (currentType < gameTypes.size())
     menu.findItem((Integer) gameTypes.keySet().toArray()[currentType]).setChecked(true);
   menu.findItem(R.id.thisgame)
       .setTitle(
           MessageFormat.format(getString(R.string.help_on_game), new Object[] {this.getTitle()}));
   return true;
 }
Пример #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.registerOnSharedPreferenceChangeListener(this);
    state = getSharedPreferences(STATE_PREFS_NAME, MODE_PRIVATE);
    prefsSaver = PrefsSaver.get(this);
    games = getResources().getStringArray(R.array.games);
    gameTypes = new LinkedHashMap<Integer, String>();

    applyFullscreen(false); // must precede super.onCreate and setContentView
    cachedFullscreen = startedFullscreen = prefs.getBoolean(FULLSCREEN_KEY, false);
    applyStayAwake();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mainLayout = (RelativeLayout) findViewById(R.id.mainLayout);
    statusBar = (TextView) findViewById(R.id.statusBar);
    gameView = (GameView) findViewById(R.id.game);
    keyboard = (SmallKeyboard) findViewById(R.id.keyboard);
    actionBarCompat = ActionBarCompat.get(this);
    try {
      actionBarHomeId = android.R.id.class.getField("home").getInt(null);
    } catch (Exception e) {
    }
    setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);
    gameView.requestFocus();
    onNewIntent(getIntent());
  }
Пример #4
0
 void applyFullscreen(boolean alreadyStarted) {
   boolean hasActionBar = ActionBarCompat.earlyHasActionBar();
   cachedFullscreen = prefs.getBoolean(FULLSCREEN_KEY, false);
   if (cachedFullscreen) {
     if (hasActionBar) {
       handler.post(
           new Runnable() {
             public void run() {
               actionBarCompat.lightsOut(getWindow(), gameView, true);
             }
           });
     } else if (alreadyStarted) {
       // This is the only way to change the theme
       if (!startedFullscreen) restartOnResume = true;
     } else {
       setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
     }
   } else {
     if (hasActionBar) {
       final boolean fAlreadyStarted = alreadyStarted;
       handler.post(
           new Runnable() {
             public void run() {
               actionBarCompat.lightsOut(getWindow(), gameView, false);
               // This shouldn't be necessary but is on Galaxy Tab 10.1
               if (fAlreadyStarted && startedFullscreen) restartOnResume = true;
             }
           });
     } else if (alreadyStarted && startedFullscreen) {
       // This is the only way to change the theme
       restartOnResume = true;
     } // else leave it as default non-fullscreen
   }
 }
Пример #5
0
 void sendKey(int x, int y, int k) {
   if (!gameRunning || progress != null) return;
   if (k == '\f') {
     // menu button hack
     openOptionsMenu();
     return;
   }
   keyEvent(x, y, k);
   if (actionBarCompat != null && startedFullscreen) {
     actionBarCompat.lightsOut(getWindow(), gameView, true);
   }
 }
Пример #6
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   prefsSaver = PrefsSaver.get(this);
   addPreferencesFromResource(R.xml.preferences);
   updateSummary((ListPreference) findPreference(SGTPuzzles.ARROW_KEYS_KEY));
   if (ActionBarCompat.get(this) != null) {
     getPreferenceScreen().removePreference(findPreference("gameChooser"));
   } else {
     updateSummary((ListPreference) findPreference(GameChooser.CHOOSER_STYLE_KEY));
   }
 }
Пример #7
0
 void startGame(final int which, final String savedGame) {
   Log.d(
       TAG,
       "startGame: "
           + which
           + ", "
           + ((savedGame == null) ? "null" : (savedGame.length() + " bytes")));
   if (progress != null) {
     Log.e(TAG, "startGame while already starting!");
     return;
   }
   showProgress((savedGame == null) ? R.string.starting : R.string.resuming);
   if (gameRunning) {
     gameView.clear();
     stopNative();
     solveEnabled = false;
     changedState(false, false);
     customVisible = false;
     setStatusBarVisibility(false);
   }
   if (ActionBarCompat.earlyHasActionBar() && !prefs.getBoolean(UNDO_REDO_KBD_KEY, false)) {
     maybeUndoRedo = "";
   }
   setKeys("", SmallKeyboard.ARROWS_LEFT_RIGHT_CLICK);
   if (typeMenu != null) for (Integer i : gameTypes.keySet()) typeMenu.removeItem(i);
   gameTypes.clear();
   gameRunning = true;
   gameView.keysHandled = 0;
   (worker =
           new Thread("startGame") {
             public void run() {
               init(gameView, which, savedGame);
               if (!gameRunning) return; // stopNative or abort was called
               helpTopic = htmlHelpTopic();
               handler.obtainMessage(MsgType.DONE.ordinal(), htmlHelpTopic()).sendToTarget();
             }
           })
       .start();
 }
Пример #8
0
 void handleMessage(Message msg) {
   switch (MsgType.values()[msg.what]) {
     case TIMER:
       if (progress == null) timerTick();
       if (gameWantsTimer) {
         handler.sendMessageDelayed(handler.obtainMessage(MsgType.TIMER.ordinal()), timerInterval);
       }
       break;
     case DONE:
       if (resizeOnDone) {
         resizeEvent(gameView.w, gameView.h);
         resizeOnDone = false;
       }
       // set ActionBar icon to the one for this puzzle
       if (msg.obj != null && actionBarCompat != null) {
         int iconId = getResources().getIdentifier((String) msg.obj, "drawable", getPackageName());
         homeAsUpNoticeable =
             actionBarCompat.setIconAsShortcut(iconId > 0 ? iconId : R.drawable.icon);
         if (menu != null) menu.findItem(R.id.other).setVisible(!homeAsUpNoticeable);
       }
       dismissProgress();
       if (menu != null) onPrepareOptionsMenu(menu);
       save();
       break;
     case ABORT:
       stopNative();
       dismissProgress();
       startChooser();
       if (msg.obj != null) {
         messageBox(getString(R.string.Error), (String) msg.obj, 2, false);
       } else {
         finish();
       }
       break;
   }
 }