private void updateLocalVersions() { if (NavigineApp.Navigation == null) return; for (int i = 0; i < mInfoList.size(); ++i) { LocationInfo info = mInfoList.get(i); String versionStr = LocationLoader.getLocalVersion(NavigineApp.AppContext, info.title); if (versionStr != null) { // Log.d(TAG, info.title + ": " + versionStr); info.localModified = versionStr.endsWith("+"); if (info.localModified) versionStr = versionStr.substring(0, versionStr.length() - 1); try { info.localVersion = Integer.parseInt(versionStr); } catch (Throwable e) { } } else { info.localVersion = -1; String mapFile = NavigineApp.Settings.getString("map_file", ""); if (mapFile.equals(info.archiveFile)) { NavigineApp.Navigation.loadArchive(null); SharedPreferences.Editor editor = NavigineApp.Settings.edit(); editor.putString("map_file", ""); editor.commit(); } } } mAdapter.updateList(); }
private void deleteLocation(LocationInfo info) { if (NavigineApp.Navigation == null) return; if (info != null) { try { (new File(info.archiveFile)).delete(); info.localVersion = -1; info.localModified = false; String locationDir = LocationLoader.getLocationDir(mContext, info.title); File dir = new File(locationDir); File[] files = dir.listFiles(); for (int i = 0; i < files.length; ++i) files[i].delete(); dir.delete(); String mapFile = NavigineApp.Settings.getString("map_file", ""); if (mapFile.equals(info.archiveFile)) { NavigineApp.Navigation.loadArchive(null); SharedPreferences.Editor editor = NavigineApp.Settings.edit(); editor.putString("map_file", ""); editor.commit(); } mAdapter.updateList(); } catch (Throwable e) { Log.e(TAG, Log.getStackTraceString(e)); } } }
private void selectLocation(LocationInfo info) { if (NavigineApp.Navigation == null) return; if (info != null && NavigineApp.Navigation.loadArchive(info.archiveFile)) { SharedPreferences.Editor editor = NavigineApp.Settings.edit(); editor.putString("map_file", info.archiveFile); editor.commit(); mAdapter.updateList(); } }
private void updateLocationLoaders() { if (NavigineApp.Navigation == null) return; long timeNow = DateTimeUtils.currentTimeMillis(); mUpdateLocationLoadersTime = timeNow; synchronized (mLoaderMap) { Iterator<Map.Entry<String, LoaderState>> iter = mLoaderMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, LoaderState> entry = iter.next(); LoaderState loader = entry.getValue(); if (loader.state < 100) { loader.timeLabel = timeNow; if (loader.type == DOWNLOAD) loader.state = LocationLoader.checkLocationLoader(loader.id); if (loader.type == UPLOAD) loader.state = LocationLoader.checkLocationUploader(loader.id); } else if (loader.state == 100) { String archivePath = NavigineApp.Navigation.getArchivePath(); String locationFile = LocationLoader.getLocationFile(NavigineApp.AppContext, loader.location); if (archivePath != null && archivePath.equals(locationFile)) { Log.d(TAG, "Reloading archive " + archivePath); if (NavigineApp.Navigation.loadArchive(archivePath)) { SharedPreferences.Editor editor = NavigineApp.Settings.edit(); editor.putString("map_file", archivePath); editor.commit(); } } if (loader.type == DOWNLOAD) LocationLoader.stopLocationLoader(loader.id); if (loader.type == UPLOAD) LocationLoader.stopLocationUploader(loader.id); iter.remove(); } else { // Load failed if (Math.abs(timeNow - loader.timeLabel) > 5000) { if (loader.type == DOWNLOAD) LocationLoader.stopLocationLoader(loader.id); if (loader.type == UPLOAD) LocationLoader.stopLocationUploader(loader.id); iter.remove(); } } } } updateLocalVersions(); mAdapter.updateList(); }
// code which handles the action for each menu item public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.settings: { Intent preferences_intent = new Intent(); preferences_intent.setComponent( new ComponentName(download_photos.this, preferences.class)); preferences_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplicationContext().startActivity(preferences_intent); return true; } case R.id.logout: { try { download_photos.this.facebook.logout(getApplicationContext()); } catch (IOException e) { e.printStackTrace(); } mPrefs = getSharedPreferences("COMMON", MODE_PRIVATE); SharedPreferences.Editor editor = mPrefs.edit(); editor.putString("access_token", null); editor.putLong("access_expires", 0); editor.putBoolean("logout", true); editor.commit(); finish(); return true; } case R.id.about: { // shows our customized about dialog AboutDialog about = new AboutDialog(this); about.show(); return true; } // lets deal with default case default: return super.onOptionsItemSelected(item); } }
@Override protected void onStop() { SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putInt("level", this.level); editor.putString("map", game.getLabyrinth().getJsonMap()); editor.putString("howdy", game.getJsonHowdy()); String allDoneLevelsString = ""; for (String s : allDoneLevels) { allDoneLevelsString += s + ","; } if (allDoneLevelsString.length() > 0) { editor.putString( "doneLevels", allDoneLevelsString.substring(0, allDoneLevelsString.length() - 1)); } editor.commit(); super.onStop(); }