示例#1
0
 private void updateApplicationDirTextAndSummary() {
   if (applicationDir != null) {
     String storageDir = osmandSettings.getExternalStorageDirectory().getAbsolutePath();
     applicationDir.setText(storageDir);
     applicationDir.setSummary(storageDir);
   }
 }
 private Collection<String> listAlreadyDownloadedWithAlternatives() {
   Set<String> files = new TreeSet<String>();
   File externalStorageDirectory = settings.getExternalStorageDirectory();
   // files.addAll(listWithAlternatives(new File(externalStorageDirectory,
   // ResourceManager.POI_PATH),POI_INDEX_EXT,POI_INDEX_EXT_ZIP,POI_TABLE_VERSION));
   files.addAll(
       listWithAlternatives(
           new File(externalStorageDirectory, ResourceManager.APP_DIR),
           BINARY_MAP_INDEX_EXT,
           BINARY_MAP_INDEX_EXT_ZIP,
           BINARY_MAP_VERSION));
   files.addAll(
       listWithAlternatives(
           new File(externalStorageDirectory, ResourceManager.BACKUP_PATH),
           BINARY_MAP_INDEX_EXT,
           BINARY_MAP_INDEX_EXT_ZIP,
           BINARY_MAP_VERSION));
   files.addAll(
       listWithAlternatives(
           new File(externalStorageDirectory, ResourceManager.VOICE_PATH),
           "",
           VOICE_INDEX_EXT_ZIP,
           VOICE_VERSION));
   files.addAll(
       listWithAlternatives(
           new File(externalStorageDirectory, ResourceManager.VOICE_PATH),
           "",
           TTSVOICE_INDEX_EXT_ZIP,
           TTSVOICE_VERSION));
   return files;
 }
 @Override
 public void setup(OsmandApplication app) {
   super.setup(app);
   originalSettings = createSettings(app.getSettings().getSettingsAPI());
   selectedTourPref = originalSettings.registerStringPreference(SELECTED_TOUR, null).makeGlobal();
   accessCodePref = originalSettings.registerStringPreference(ACCESS_CODE, "").makeGlobal();
   toursFolder = new File(originalSettings.getExternalStorageDirectory(), "osmand/tours");
 }
 private void copyFilesForAndroid19() {
   final String newLoc = settings.getDefaultExternalStorageLocation();
   MoveFilesToDifferentDirectory task =
       new MoveFilesToDifferentDirectory(
           DownloadIndexActivity.this,
           new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR),
           new File(newLoc, IndexConstants.APP_DIR)) {
         protected Boolean doInBackground(Void[] params) {
           Boolean result = super.doInBackground(params);
           if (result) {
             settings.setExternalStorageDirectory(newLoc);
             getMyApplication().getResourceManager().resetStoreDirectory();
             getMyApplication().getResourceManager().reloadIndexes(progress);
           }
           return result;
         };
       };
   task.execute();
 }
示例#5
0
  @Override
  public void onCreate() {
    long timeToStart = System.currentTimeMillis();
    if (Version.getAppName(this).equals("OsmAnd~")) {
      if (android.os.Build.VERSION.SDK_INT >= 9) {
        try {
          Class.forName("net.osmand.plus.base.EnableStrictMode").newInstance();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    super.onCreate();
    createInUiThread();
    uiHandler = new Handler();
    appCustomization = new OsmAndAppCustomization();
    appCustomization.setup(this);
    osmandSettings = appCustomization.getOsmandSettings();
    externalStorageDirectory = osmandSettings.getExternalStorageDirectory();

    checkPreferredLocale();
    appInitializer.onCreateApplication();
    //		if(!osmandSettings.FOLLOW_THE_ROUTE.get()) {
    //			targetPointsHelper.clearPointToNavigate(false);
    //		}
    startApplication();
    System.out.println(
        "Time to start application "
            + (System.currentTimeMillis() - timeToStart)
            + " ms. Should be less < 800 ms");
    timeToStart = System.currentTimeMillis();
    OsmandPlugin.initPlugins(this);
    System.out.println(
        "Time to init plugins "
            + (System.currentTimeMillis() - timeToStart)
            + " ms. Should be less < 800 ms");

    osmandSettings.NUMBER_OF_APPLICATION_STARTS.set(
        osmandSettings.NUMBER_OF_APPLICATION_STARTS.get() + 1);
  }
示例#6
0
 public void setExternalStorageDirectory(int type, String directory) {
   osmandSettings.setExternalStorageDirectory(type, directory);
   externalStorageDirectory = osmandSettings.getExternalStorageDirectory();
   getResourceManager().resetStoreDirectory();
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    settings = ((OsmandApplication) getApplication()).getSettings();
    if (downloadListIndexThread == null) {
      downloadListIndexThread = new DownloadIndexesThread(this);
    }
    setContentView(R.layout.download_index);
    indeterminateProgressBar = (ProgressBar) findViewById(R.id.IndeterminateProgressBar);
    determinateProgressBar = (ProgressBar) findViewById(R.id.DeterminateProgressBar);
    progressView = findViewById(R.id.ProgressView);
    progressMessage = (TextView) findViewById(R.id.ProgressMessage);
    progressPercent = (TextView) findViewById(R.id.ProgressPercent);
    cancel = (ImageView) findViewById(R.id.Cancel);
    int d =
        settings.isLightContent()
            ? R.drawable.a_1_navigation_cancel_small_light
            : R.drawable.a_1_navigation_cancel_small_dark;
    cancel.setImageDrawable(getResources().getDrawable(d));
    cancel.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            makeSureUserCancelDownload();
          }
        });
    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    getSupportActionBar().setTitle(R.string.local_index_download);
    // recreation upon rotation is prevented in manifest file
    findViewById(R.id.DownloadButton)
        .setOnClickListener(
            new View.OnClickListener() {

              @Override
              public void onClick(View v) {
                downloadFilesCheckFreeVersion();
              }
            });

    filterText = (EditText) findViewById(R.id.search_box);
    textWatcher =
        new TextWatcher() {
          @Override
          public void afterTextChanged(Editable s) {}

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            DownloadIndexAdapter adapter = ((DownloadIndexAdapter) getExpandableListAdapter());
            if (adapter != null) {
              adapter.getFilter().filter(s);
            }
          }
        };
    filterText.addTextChangedListener(textWatcher);
    final Intent intent = getIntent();
    if (intent != null && intent.getExtras() != null) {
      final String filter = intent.getExtras().getString(FILTER_KEY);
      if (filter != null) {
        filterText.setText(filter);
      }
    }
    List<IndexItem> list = new ArrayList<IndexItem>();
    downloadListIndexThread.setUiActivity(this);
    if (downloadListIndexThread.getCachedIndexFiles() != null
        && downloadListIndexThread.isDownloadedFromInternet()) {
      downloadListIndexThread.runCategorization(type);
    } else {
      downloadListIndexThread.runReloadIndexFiles();
    }
    DownloadIndexAdapter adapter = new DownloadIndexAdapter(this, list);
    setListAdapter(adapter);
    if (getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) {
      boolean showedDialog = false;
      if (Build.VERSION.SDK_INT < OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
        SuggestExternalDirectoryDialog.showDialog(this, null, null);
      }
      if (!showedDialog) {
        showDialogOfFreeDownloadsIfNeeded();
      }
    } else {
      showDialogOfFreeDownloadsIfNeeded();
    }
    final DownloadActivityType[] downloadTypes = getDownloadTypes();
    spinnerAdapter =
        new ArrayAdapter<String>(
            getSupportActionBar().getThemedContext(),
            R.layout.sherlock_spinner_item,
            new ArrayList<String>(Arrays.asList(toString(downloadTypes))));
    spinnerAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
    getSupportActionBar()
        .setListNavigationCallbacks(
            spinnerAdapter,
            new OnNavigationListener() {

              @Override
              public boolean onNavigationItemSelected(int itemPosition, long itemId) {
                changeType(downloadTypes[itemPosition]);
                return true;
              }
            });
    if (Build.VERSION.SDK_INT >= OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
      if (!settings
          .getExternalStorageDirectory()
          .getAbsolutePath()
          .equals(settings.getDefaultExternalStorageLocation())) {
        AccessibleAlertBuilder ab = new AccessibleAlertBuilder(this);
        ab.setMessage(
            getString(
                R.string.android_19_location_disabled, settings.getExternalStorageDirectory()));
        ab.setPositiveButton(
            R.string.default_buttons_yes,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                copyFilesForAndroid19();
              }
            });
        ab.setNegativeButton(R.string.default_buttons_cancel, null);
        ab.show();
      }
    }
  }