@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(); } }
@Override protected void onDestroy() { super.onDestroy(); if (isFinishing()) { downloadFileHelper.setInterruptDownloading(true); } if (textWatcher != null) { EditText filterText = (EditText) findViewById(R.id.search_box); filterText.removeTextChangedListener(textWatcher); } downloadListIndexThread.setUiActivity(null); }
@Override protected void onPrepareDialog(int id, Dialog dialog) { switch (id) { case DIALOG_PROGRESS_FILE: DownloadIndexesAsyncTask task = new DownloadIndexesAsyncTask(new ProgressDialogImplementation(progressFileDlg, true)); task.execute(entriesToDownload.keySet().toArray(new String[0])); break; case DIALOG_PROGRESS_LIST: downloadListIndexThread.setUiActivity(this); if (downloadListIndexThread.getState() == Thread.State.NEW) { downloadListIndexThread.start(); } else if (downloadListIndexThread.getState() == Thread.State.TERMINATED) { // possibly exception occurred we don't have cache of files downloadListIndexThread = new DownloadIndexListThread(); downloadListIndexThread.setUiActivity(this); downloadListIndexThread.start(); } break; } }
@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(); } }