1 // Copyright 2011 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 package com.hughes.android.dictionary;
17 import android.Manifest;
18 import android.app.AlertDialog;
19 import android.app.DownloadManager;
20 import android.app.DownloadManager.Request;
21 import android.content.BroadcastReceiver;
22 import android.content.ContentResolver;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.content.IntentFilter;
26 import android.content.SharedPreferences;
27 import android.content.SharedPreferences.Editor;
28 import android.content.pm.PackageManager;
29 import android.database.Cursor;
30 import android.net.Uri;
31 import android.os.Bundle;
32 import android.os.Environment;
33 import android.os.Handler;
34 import android.preference.PreferenceManager;
35 import android.support.v4.app.ActivityCompat;
36 import android.support.v4.content.ContextCompat;
37 import android.support.v4.view.MenuItemCompat;
38 import android.support.v7.app.ActionBar;
39 import android.support.v7.app.ActionBarActivity;
40 import android.support.v7.widget.SearchView;
41 import android.support.v7.widget.SearchView.OnQueryTextListener;
42 import android.support.v7.widget.Toolbar;
43 import android.text.InputType;
44 import android.util.Log;
45 import android.util.TypedValue;
46 import android.view.ContextMenu;
47 import android.view.ContextMenu.ContextMenuInfo;
48 import android.view.LayoutInflater;
49 import android.view.Menu;
50 import android.view.MenuItem;
51 import android.view.View;
52 import android.view.View.OnClickListener;
53 import android.view.ViewGroup;
54 import android.view.inputmethod.EditorInfo;
55 import android.view.inputmethod.InputMethodManager;
56 import android.widget.AdapterView.AdapterContextMenuInfo;
57 import android.widget.BaseAdapter;
58 import android.widget.Button;
59 import android.widget.CompoundButton;
60 import android.widget.CompoundButton.OnCheckedChangeListener;
61 import android.widget.FrameLayout;
62 import android.widget.LinearLayout;
63 import android.widget.ListAdapter;
64 import android.widget.ListView;
65 import android.widget.TextView;
66 import android.widget.Toast;
67 import android.widget.ToggleButton;
69 import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
70 import com.hughes.android.util.IntentLauncher;
73 import java.io.FileInputStream;
74 import java.io.FileOutputStream;
75 import java.io.IOException;
76 import java.io.InputStream;
77 import java.io.OutputStream;
78 import java.net.MalformedURLException;
80 import java.util.Collections;
81 import java.util.HashSet;
82 import java.util.List;
84 import java.util.zip.ZipEntry;
85 import java.util.zip.ZipFile;
86 import java.util.zip.ZipInputStream;
89 // Delete, move to top.
91 public class DictionaryManagerActivity extends ActionBarActivity {
93 static final String LOG = "QuickDic";
94 static boolean blockAutoLaunch = false;
96 private ListView listView;
97 private ListView getListView() {
98 if (listView == null) {
99 listView = (ListView)findViewById(android.R.id.list);
103 private void setListAdapter(ListAdapter adapter) {
104 getListView().setAdapter(adapter);
106 private ListAdapter getListAdapter() {
107 return getListView().getAdapter();
110 // For DownloadManager bug workaround
111 private Set<Long> finishedDownloadIds = new HashSet<Long>();
113 DictionaryApplication application;
115 SearchView filterSearchView;
116 ToggleButton showDownloadable;
118 LinearLayout dictionariesOnDeviceHeaderRow;
119 LinearLayout downloadableDictionariesHeaderRow;
123 Runnable dictionaryUpdater = new Runnable() {
126 if (uiHandler == null) {
129 uiHandler.post(new Runnable() {
138 final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
140 public synchronized void onReceive(Context context, Intent intent) {
141 final String action = intent.getAction();
143 if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
144 final long downloadId = intent.getLongExtra(
145 DownloadManager.EXTRA_DOWNLOAD_ID, 0);
146 if (finishedDownloadIds.contains(downloadId)) return; // ignore double notifications
147 final DownloadManager.Query query = new DownloadManager.Query();
148 query.setFilterById(downloadId);
149 final DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
150 final Cursor cursor = downloadManager.query(query);
152 if (cursor == null || !cursor.moveToFirst()) {
153 Log.e(LOG, "Couldn't find download.");
157 final String dest = cursor
158 .getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
159 final int status = cursor
161 .getColumnIndex(DownloadManager.COLUMN_STATUS));
162 if (DownloadManager.STATUS_SUCCESSFUL != status) {
163 final int reason = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON));
165 "Download failed: status=" + status +
166 ", reason=" + reason);
167 String msg = Integer.toString(reason);
169 case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
172 case DownloadManager.ERROR_FILE_ERROR:
175 case DownloadManager.ERROR_INSUFFICIENT_SPACE:
176 msg = "Not enough space";
179 new AlertDialog.Builder(context).setTitle(getString(R.string.error)).setMessage(getString(R.string.downloadFailed, msg)).setNeutralButton("Close", null).show();
183 Log.w(LOG, "Download finished: " + dest + " Id: " + downloadId);
184 Toast.makeText(context, getString(R.string.unzippingDictionary, dest),
185 Toast.LENGTH_LONG).show();
188 final Uri zipUri = Uri.parse(dest);
189 File localZipFile = null;
190 InputStream zipFileStream = null;
191 ZipInputStream zipFile = null;
192 OutputStream zipOut = null;
194 if (zipUri.getScheme().equals("content")) {
195 zipFileStream = context.getContentResolver().openInputStream(zipUri);
198 localZipFile = new File(zipUri.getPath());
199 zipFileStream = new FileInputStream(localZipFile);
201 zipFile = new ZipInputStream(zipFileStream);
202 final ZipEntry zipEntry = zipFile.getNextEntry();
203 Log.d(LOG, "Unzipping entry: " + zipEntry.getName());
204 File targetFile = new File(application.getDictDir(), zipEntry.getName());
205 if (targetFile.exists()) {
206 targetFile.renameTo(new File(targetFile.getAbsolutePath().replace(".quickdic", ".bak.quickdic")));
207 targetFile = new File(application.getDictDir(), zipEntry.getName());
209 zipOut = new FileOutputStream(targetFile);
210 copyStream(zipFile, zipOut);
211 application.backgroundUpdateDictionaries(dictionaryUpdater);
212 Toast.makeText(context, getString(R.string.installationFinished, dest),
213 Toast.LENGTH_LONG).show();
214 finishedDownloadIds.add(downloadId);
215 Log.w(LOG, "Unzipping finished: " + dest + " Id: " + downloadId);
216 } catch (Exception e) {
217 String msg = getString(R.string.unzippingFailed, dest);
218 File dir = application.getDictDir();
219 if (!dir.canWrite() || !application.checkFileCreate(dir)) {
220 msg = getString(R.string.notWritable, dir.getAbsolutePath());
222 new AlertDialog.Builder(context).setTitle(getString(R.string.error)).setMessage(msg).setNeutralButton("Close", null).show();
223 Log.e(LOG, "Failed to unzip.", e);
226 if (zipOut != null) zipOut.close();
227 } catch (IOException e) {}
229 if (zipFile != null) zipFile.close();
230 } catch (IOException e) {}
232 if (zipFileStream != null) zipFileStream.close();
233 } catch (IOException e) {}
234 if (localZipFile != null) localZipFile.delete();
240 public static Intent getLaunchIntent(Context c) {
241 final Intent intent = new Intent(c, DictionaryManagerActivity.class);
242 intent.putExtra(C.CAN_AUTO_LAUNCH_DICT, false);
246 public void readableCheckAndError(boolean requestPermission) {
247 final File dictDir = application.getDictDir();
248 if (dictDir.canRead() && dictDir.canExecute()) return;
249 blockAutoLaunch = true;
250 if (requestPermission &&
251 ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
252 ActivityCompat.requestPermissions(this,
253 new String[] {Manifest.permission.READ_EXTERNAL_STORAGE,
254 Manifest.permission.WRITE_EXTERNAL_STORAGE
258 blockAutoLaunch = true;
260 AlertDialog.Builder builder = new AlertDialog.Builder(getListView().getContext());
261 builder.setTitle(getString(R.string.error));
262 builder.setMessage(getString(
263 R.string.unableToReadDictionaryDir,
264 dictDir.getAbsolutePath(),
265 Environment.getExternalStorageDirectory()));
266 builder.setNeutralButton("Close", null);
267 builder.create().show();
271 public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
272 readableCheckAndError(false);
274 application.backgroundUpdateDictionaries(dictionaryUpdater);
280 public void onCreate(Bundle savedInstanceState) {
281 // This must be first, otherwise the actiona bar doesn't get
283 setTheme(((DictionaryApplication) getApplication()).getSelectedTheme().themeId);
285 super.onCreate(savedInstanceState);
286 Log.d(LOG, "onCreate:" + this);
288 application = (DictionaryApplication) getApplication();
290 blockAutoLaunch = false;
293 setContentView(R.layout.dictionary_manager_activity);
295 dictionariesOnDeviceHeaderRow = (LinearLayout) LayoutInflater.from(
296 getListView().getContext()).inflate(
297 R.layout.dictionary_manager_header_row_on_device, getListView(), false);
299 downloadableDictionariesHeaderRow = (LinearLayout) LayoutInflater.from(
300 getListView().getContext()).inflate(
301 R.layout.dictionary_manager_header_row_downloadable, getListView(), false);
303 showDownloadable = (ToggleButton) downloadableDictionariesHeaderRow
304 .findViewById(R.id.hideDownloadable);
305 showDownloadable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
307 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
308 onShowDownloadableChanged();
312 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
313 final String thanksForUpdatingLatestVersion = getString(R.string.thanksForUpdatingVersion);
314 if (!prefs.getString(C.THANKS_FOR_UPDATING_VERSION, "").equals(
315 thanksForUpdatingLatestVersion)) {
316 blockAutoLaunch = true;
317 startActivity(HtmlDisplayActivity.getWhatsNewLaunchIntent(getApplicationContext()));
318 prefs.edit().putString(C.THANKS_FOR_UPDATING_VERSION, thanksForUpdatingLatestVersion)
322 registerReceiver(broadcastReceiver, new IntentFilter(
323 DownloadManager.ACTION_DOWNLOAD_COMPLETE));
326 registerForContextMenu(getListView());
327 getListView().setItemsCanFocus(true);
329 readableCheckAndError(true);
331 onCreateSetupActionBar();
334 private void onCreateSetupActionBar() {
335 ActionBar actionBar = getSupportActionBar();
336 actionBar.setDisplayShowTitleEnabled(false);
337 actionBar.setDisplayShowHomeEnabled(false);
338 actionBar.setDisplayHomeAsUpEnabled(false);
340 filterSearchView = new SearchView(getSupportActionBar().getThemedContext());
341 filterSearchView.setIconifiedByDefault(false);
342 // filterSearchView.setIconified(false); // puts the magnifying glass in
345 filterSearchView.setQueryHint(getString(R.string.searchText));
346 filterSearchView.setSubmitButtonEnabled(false);
347 FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
348 FrameLayout.LayoutParams.WRAP_CONTENT);
349 filterSearchView.setLayoutParams(lp);
350 filterSearchView.setInputType(InputType.TYPE_CLASS_TEXT);
351 filterSearchView.setImeOptions(
352 EditorInfo.IME_ACTION_DONE |
353 EditorInfo.IME_FLAG_NO_EXTRACT_UI |
354 // EditorInfo.IME_FLAG_NO_FULLSCREEN | // Requires API
356 EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
358 filterSearchView.setOnQueryTextListener(new OnQueryTextListener() {
360 public boolean onQueryTextSubmit(String query) {
361 filterSearchView.clearFocus();
366 public boolean onQueryTextChange(String filterText) {
371 filterSearchView.setFocusable(true);
373 actionBar.setCustomView(filterSearchView);
374 actionBar.setDisplayShowCustomEnabled(true);
376 // Avoid wasting space on large left inset
377 Toolbar tb = (Toolbar)filterSearchView.getParent();
378 tb.setContentInsetsRelative(0, 0);
382 public void onDestroy() {
384 unregisterReceiver(broadcastReceiver);
387 private static int copyStream(final InputStream in, final OutputStream out)
390 final byte[] bytes = new byte[1024 * 16];
391 while ((bytesRead = in.read(bytes)) != -1) {
392 out.write(bytes, 0, bytesRead);
400 protected void onStart() {
402 uiHandler = new Handler();
406 protected void onStop() {
412 protected void onResume() {
415 if (PreferenceActivity.prefsMightHaveChanged) {
416 PreferenceActivity.prefsMightHaveChanged = false;
418 startActivity(getIntent());
421 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
422 showDownloadable.setChecked(prefs.getBoolean(C.SHOW_DOWNLOADABLE, true));
424 if (!blockAutoLaunch &&
425 getIntent().getBooleanExtra(C.CAN_AUTO_LAUNCH_DICT, true) &&
426 prefs.contains(C.DICT_FILE) &&
427 prefs.contains(C.INDEX_SHORT_NAME)) {
428 Log.d(LOG, "Skipping DictionaryManager, going straight to dictionary.");
429 startActivity(DictionaryActivity.getLaunchIntent(getApplicationContext(),
430 new File(prefs.getString(C.DICT_FILE, "")),
431 prefs.getString(C.INDEX_SHORT_NAME, ""),
432 prefs.getString(C.SEARCH_TOKEN, "")));
437 // Remove the active dictionary from the prefs so we won't autolaunch
439 final Editor editor = prefs.edit();
440 editor.remove(C.DICT_FILE);
441 editor.remove(C.INDEX_SHORT_NAME);
442 editor.remove(C.SEARCH_TOKEN);
445 application.backgroundUpdateDictionaries(dictionaryUpdater);
451 public boolean onCreateOptionsMenu(final Menu menu) {
452 final MenuItem sort = menu.add(getString(R.string.sortDicts));
453 MenuItemCompat.setShowAsAction(sort, MenuItem.SHOW_AS_ACTION_NEVER);
454 sort.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
455 public boolean onMenuItemClick(final MenuItem menuItem) {
456 application.sortDictionaries();
462 application.onCreateGlobalOptionsMenu(this, menu);
467 public void onCreateContextMenu(final ContextMenu menu, final View view,
468 final ContextMenuInfo menuInfo) {
469 super.onCreateContextMenu(menu, view, menuInfo);
470 Log.d(LOG, "onCreateContextMenu, " + menuInfo);
472 final AdapterContextMenuInfo adapterContextMenuInfo =
473 (AdapterContextMenuInfo) menuInfo;
474 final int position = adapterContextMenuInfo.position;
475 final MyListAdapter.Row row = (MyListAdapter.Row) getListAdapter().getItem(position);
477 if (row.dictionaryInfo == null) {
481 if (position > 0 && row.onDevice) {
482 final android.view.MenuItem moveToTopMenuItem =
483 menu.add(R.string.moveToTop);
484 moveToTopMenuItem.setOnMenuItemClickListener(new
485 android.view.MenuItem.OnMenuItemClickListener() {
487 public boolean onMenuItemClick(android.view.MenuItem item) {
488 application.moveDictionaryToTop(row.dictionaryInfo);
496 final android.view.MenuItem deleteMenuItem = menu.add(R.string.deleteDictionary);
498 .setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
500 public boolean onMenuItemClick(android.view.MenuItem item) {
501 application.deleteDictionary(row.dictionaryInfo);
509 private void onShowDownloadableChanged() {
511 Editor prefs = PreferenceManager.getDefaultSharedPreferences(this).edit();
512 prefs.putBoolean(C.SHOW_DOWNLOADABLE, showDownloadable.isChecked());
516 class MyListAdapter extends BaseAdapter {
518 List<DictionaryInfo> dictionariesOnDevice;
519 List<DictionaryInfo> downloadableDictionaries;
522 DictionaryInfo dictionaryInfo;
525 private Row(DictionaryInfo dictionaryInfo, boolean onDevice) {
526 this.dictionaryInfo = dictionaryInfo;
527 this.onDevice = onDevice;
531 private MyListAdapter(final String[] filters) {
532 dictionariesOnDevice = application.getDictionariesOnDevice(filters);
533 if (showDownloadable.isChecked()) {
534 downloadableDictionaries = application.getDownloadableDictionaries(filters);
536 downloadableDictionaries = Collections.emptyList();
541 public int getCount() {
542 return 2 + dictionariesOnDevice.size() + downloadableDictionaries.size();
546 public Row getItem(int position) {
548 return new Row(null, true);
552 if (position < dictionariesOnDevice.size()) {
553 return new Row(dictionariesOnDevice.get(position), true);
555 position -= dictionariesOnDevice.size();
558 return new Row(null, false);
562 assert position < downloadableDictionaries.size();
563 return new Row(downloadableDictionaries.get(position), false);
567 public long getItemId(int position) {
572 public View getView(int position, View convertView, ViewGroup parent) {
573 if (convertView instanceof LinearLayout &&
574 convertView != dictionariesOnDeviceHeaderRow &&
575 convertView != downloadableDictionariesHeaderRow) {
577 * This is done to try to avoid leaking memory that used to
578 * happen on Android 4.0.3
580 ((LinearLayout) convertView).removeAllViews();
583 final Row row = getItem(position);
586 if (row.dictionaryInfo == null) {
587 return dictionariesOnDeviceHeaderRow;
589 return createDictionaryRow(row.dictionaryInfo, parent, true);
592 if (row.dictionaryInfo == null) {
593 return downloadableDictionariesHeaderRow;
595 return createDictionaryRow(row.dictionaryInfo, parent, false);
600 private void setMyListAdapater() {
601 final String filter = filterSearchView == null ? "" : filterSearchView.getQuery()
603 final String[] filters = filter.trim().toLowerCase().split("(\\s|-)+");
604 setListAdapter(new MyListAdapter(filters));
607 private View createDictionaryRow(final DictionaryInfo dictionaryInfo,
608 final ViewGroup parent, boolean canLaunch) {
610 View row = LayoutInflater.from(parent.getContext()).inflate(
611 R.layout.dictionary_manager_row, parent, false);
612 final TextView name = (TextView) row.findViewById(R.id.dictionaryName);
613 final TextView details = (TextView) row.findViewById(R.id.dictionaryDetails);
614 name.setText(application.getDictionaryName(dictionaryInfo.uncompressedFilename));
616 final boolean updateAvailable = application.updateAvailable(dictionaryInfo);
617 final Button downloadButton = (Button) row.findViewById(R.id.downloadButton);
618 final DictionaryInfo downloadable = application.getDownloadable(dictionaryInfo.uncompressedFilename);
619 boolean broken = false;
620 if (!dictionaryInfo.isValid()) {
624 if (downloadable != null && (!canLaunch || updateAvailable)) {
627 R.string.downloadButton,
628 downloadable.zipBytes / 1024.0 / 1024.0));
629 downloadButton.setMinWidth(application.languageButtonPixels * 3 / 2);
630 downloadButton.setOnClickListener(new OnClickListener() {
632 public void onClick(View arg0) {
633 downloadDictionary(downloadable.downloadUrl, downloadable.zipBytes, downloadButton);
637 downloadButton.setVisibility(View.INVISIBLE);
640 LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons);
641 final List<IndexInfo> sortedIndexInfos = application
642 .sortedIndexInfos(dictionaryInfo.indexInfos);
643 final StringBuilder builder = new StringBuilder();
644 if (updateAvailable) {
645 builder.append(getString(R.string.updateAvailable));
647 for (IndexInfo indexInfo : sortedIndexInfos) {
648 final View button = application.createButton(buttons.getContext(), dictionaryInfo,
650 buttons.addView(button);
653 button.setOnClickListener(
654 new IntentLauncher(buttons.getContext(),
655 DictionaryActivity.getLaunchIntent(getApplicationContext(),
656 application.getPath(dictionaryInfo.uncompressedFilename),
657 indexInfo.shortName, "")));
660 button.setEnabled(false);
661 button.setFocusable(false);
663 if (builder.length() != 0) {
664 builder.append("; ");
666 builder.append(getString(R.string.indexInfo, indexInfo.shortName,
667 indexInfo.mainTokenCount));
669 builder.append("; ");
670 builder.append(getString(R.string.downloadButton, dictionaryInfo.uncompressedBytes / 1024.0 / 1024.0));
672 name.setText("Broken: " + application.getDictionaryName(dictionaryInfo.uncompressedFilename));
673 builder.append("; Cannot be used, redownload, check hardware/file system");
674 // Allow deleting, but cannot open
675 row.setLongClickable(true);
677 details.setText(builder.toString());
680 row.setClickable(true);
681 row.setOnClickListener(new IntentLauncher(parent.getContext(),
682 DictionaryActivity.getLaunchIntent(getApplicationContext(),
683 application.getPath(dictionaryInfo.uncompressedFilename),
684 dictionaryInfo.indexInfos.get(0).shortName, "")));
685 // do not setFocusable, for keyboard navigation
686 // offering only the index buttons is better.
687 row.setLongClickable(true);
689 row.setBackgroundResource(android.R.drawable.menuitem_background);
694 private synchronized void downloadDictionary(final String downloadUrl, long bytes, Button downloadButton) {
697 destFile = new File(new URL(downloadUrl).getPath()).getName();
698 } catch (MalformedURLException e) {
699 throw new RuntimeException("Invalid download URL!", e);
701 DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
702 final DownloadManager.Query query = new DownloadManager.Query();
703 query.setFilterByStatus(DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING);
704 final Cursor cursor = downloadManager.query(query);
706 // Due to a bug, cursor is null instead of empty when
707 // the download manager is disabled.
708 if (cursor == null) {
709 new AlertDialog.Builder(DictionaryManagerActivity.this).setTitle(getString(R.string.error))
710 .setMessage(getString(R.string.downloadFailed, R.string.downloadManagerQueryFailed))
711 .setNeutralButton("Close", null).show();
715 while (cursor.moveToNext()) {
716 if (downloadUrl.equals(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_URI))))
718 if (destFile.equals(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_TITLE))))
721 if (!cursor.isAfterLast()) {
722 downloadManager.remove(cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_ID)));
725 R.string.downloadButton,
726 bytes / 1024.0 / 1024.0));
731 Request request = new Request(
732 Uri.parse(downloadUrl));
734 Log.d(LOG, "Downloading to: " + destFile);
735 request.setTitle(destFile);
737 File destFilePath = new File(application.getDictDir(), destFile);
738 destFilePath.delete();
740 request.setDestinationUri(Uri.fromFile(destFilePath));
741 } catch (Exception e) {
745 downloadManager.enqueue(request);
746 } catch (SecurityException e) {
747 request = new Request(Uri.parse(downloadUrl));
748 request.setTitle(destFile);
749 downloadManager.enqueue(request);
751 Log.w(LOG, "Download started: " + destFile);
752 downloadButton.setText("X");