Пример #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // recreation upon rotation is prevented in manifest file
    setContentView(R.layout.download_index);
    downloadFileHelper = new DownloadFileHelper(this);
    findViewById(R.id.DownloadButton)
        .setOnClickListener(
            new View.OnClickListener() {

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

    indexFileNames =
        ((OsmandApplication) getApplication()).getResourceManager().getIndexFileNames();

    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) getListAdapter());
            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);
      }
    }

    if (downloadListIndexThread.getCachedIndexFiles() != null) {
      setListAdapter(new DownloadIndexAdapter(downloadListIndexThread.getCachedIndexFiles()));
    } else {
      downloadIndexList();
    }
  }
Пример #2
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   if (item.getItemId() == RELOAD_ID) {
     // re-create the thread
     downloadListIndexThread = new DownloadIndexListThread();
     downloadIndexList();
   } else {
     final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter) getListAdapter();
     if (item.getItemId() == SELECT_ALL_ID) {
       int selected = 0;
       for (int i = 0; i < listAdapter.getCount(); i++) {
         IndexItem es = listAdapter.getItem(i);
         if (!entriesToDownload.containsKey(es.getFileName())) {
           selected++;
           entriesToDownload.put(es.getFileName(), createDownloadEntry(es));
         }
       }
       Toast.makeText(
               this,
               MessageFormat.format(getString(R.string.items_were_selected), selected),
               Toast.LENGTH_SHORT)
           .show();
       listAdapter.notifyDataSetInvalidated();
       if (selected > 0) {
         findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
       }
     } else if (item.getItemId() == FILTER_EXISTING_REGIONS) {
       final Collection<String> listAlreadyDownloaded = listAlreadyDownloadedWithAlternatives();
       final List<IndexItem> filtered = new ArrayList<IndexItem>();
       for (String file : listAlreadyDownloaded) {
         IndexItem fileItem = listAdapter.getIndexFiles().get(file);
         if (fileItem != null) {
           filtered.add(fileItem);
         }
       }
       listAdapter.clear();
       for (IndexItem fileItem : filtered) {
         listAdapter.add(fileItem);
       }
     } else if (item.getItemId() == DESELECT_ALL_ID) {
       entriesToDownload.clear();
       listAdapter.notifyDataSetInvalidated();
       findViewById(R.id.DownloadButton).setVisibility(View.GONE);
     } else {
       return false;
     }
   }
   return true;
 }
Пример #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    settings = ((OsmandApplication) getApplication()).getSettings();
    if (downloadListIndexThread == null) {
      downloadListIndexThread = new DownloadIndexListThread(this);
    }
    // recreation upon rotation is prevented in manifest file
    CustomTitleBar titleBar =
        new CustomTitleBar(
            this, R.string.local_index_download, R.drawable.tab_download_screen_icon);
    setContentView(R.layout.download_index);
    titleBar.afterSetContentView();

    downloadFileHelper = new DownloadFileHelper(this);
    findViewById(R.id.DownloadButton)
        .setOnClickListener(
            new View.OnClickListener() {

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

    updateLoadedFiles();

    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);
      }
    }

    if (downloadListIndexThread.getCachedIndexFiles() != null) {
      setListAdapter(new DownloadIndexAdapter(downloadListIndexThread.getCachedIndexFiles()));
    } else {
      downloadIndexList();
    }
    if (Version.isFreeVersion(this) && settings.checkFreeDownloadsNumberZero()) {
      Builder msg = new AlertDialog.Builder(this);
      msg.setTitle(R.string.free_version_title);
      msg.setMessage(
          getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "", ""));
      msg.show();
    }
  }