コード例 #1
0
 /**
  * Setup missing application files into the "home directory".
  *
  * @param targetDir
  * @throws IOException
  * @return true on success
  */
 private boolean restoreMissingFiles(final File targetDir) throws IOException {
   Debug.enter();
   boolean success = false;
   final SharedPreferences prefs = Settings.INSTANCE.getSharedPreferences();
   final String oldTarball = prefs.getString(SettingsStorage.FIELD_TARBALL, null);
   final String newTarball = getString(R.string.build_tarball);
   final boolean keepOldFiles = newTarball.equals(oldTarball);
   try {
     // extract the tar-ball to recover any missing file, if any
     final TarArchive tarball = new TarArchive(new GZIPInputStream(tarballFile()));
     tarball.keepOldFiles = keepOldFiles;
     tarball.extract(targetDir);
     tarball.close();
     // once the restore is completed successfully,
     // we need to update the shared preference, if necessary
     if (!keepOldFiles) {
       final SharedPreferences.Editor edit = prefs.edit();
       edit.putString(SettingsStorage.FIELD_TARBALL, newTarball);
       success = edit.commit();
     } else {
       success = true;
     }
   } catch (final Resources.NotFoundException ex) {
     // this exception usually would happen from the unit-tests
     Debug.error(ex, "tarball resources not found", keepOldFiles);
     // not really a fatal error if keepOldFiles is true
     if (!keepOldFiles) {
       Debug.leave();
       throw new IOException("Tarball resources missing");
     }
   } catch (final TarArchive.TarHeaderException ex) {
     Debug.error(ex, "invalid tarball header", keepOldFiles);
     Debug.leave();
     throw new IOException("Invalid tarball format");
   } catch (final IOException ex) {
     Debug.error(ex, "unable to install tarball", keepOldFiles);
     // not really a fatal error if keepOldFiles is true
     if (!keepOldFiles) {
       Debug.leave();
       throw ex;
     }
   }
   Debug.leave(success);
   return success;
 }
コード例 #2
0
 /** {@inheritDoc} */
 @Override
 public void onConfigurationChanged(final Configuration newConfig) {
   super.onConfigurationChanged(newConfig);
   {
     Debug.enter();
     try {
       Debug.print(tag, "configurationChanged", newConfig.locale);
       Android.App.setLocale(newConfig.locale);
     } catch (final IOException ex) {
       Debug.error(ex, tag, "unable to set new locale", newConfig.locale);
     }
     Debug.leave();
   }
 }