@Override public void onDrawerOpened(View drawerView) { if (Ref.alive(activityRef)) { UIUtils.hideKeyboardFromActivity(activityRef.get()); activityRef.get().invalidateOptionsMenu(); } }
private List<StorageMount> getSecondayExternals(Context context) { List<StorageMount> mounts = new ArrayList<StorageMount>(); String primaryPath = context.getExternalFilesDir(null).getParent(); int i = 0; for (File f : SystemUtils.getExternalFilesDirs(context)) { if (!f.getAbsolutePath().startsWith(primaryPath) && SystemUtils.isSecondaryExternalStorageMounted(f)) { String label = context.getString(R.string.sdcard_storage) + " " + (++i); String description = UIUtils.getBytesInHuman(SystemUtils.getAvailableStorageSize(f)) + " " + context.getString(R.string.available); String path = f.getAbsolutePath(); StorageMount mount = new StorageMount(label, description, path, false); mounts.add(mount); } } return mounts; }
@Override protected void onClick(Context context) { if (fileType != Constants.FILE_TYPE_RINGTONES) { UIUtils.openFile(context, path, mime); } else { MusicUtils.playSimple(path); } }
private void updateHeader() { if (finger == null) { if (peer == null) { LOG.warn("Something wrong, finger and peer are null"); return; } else { finger = peer.finger(); } } if (header != null) { byte fileType = adapter != null ? adapter.getFileType() : Constants.FILE_TYPE_AUDIO; int numTotal = 0; switch (fileType) { case Constants.FILE_TYPE_TORRENTS: numTotal = finger.numTotalTorrentFiles; break; case Constants.FILE_TYPE_AUDIO: numTotal = finger.numTotalAudioFiles; break; case Constants.FILE_TYPE_DOCUMENTS: numTotal = finger.numTotalDocumentFiles; break; case Constants.FILE_TYPE_PICTURES: numTotal = finger.numTotalPictureFiles; break; case Constants.FILE_TYPE_RINGTONES: numTotal = finger.numTotalRingtoneFiles; break; case Constants.FILE_TYPE_VIDEOS: numTotal = finger.numTotalVideoFiles; break; } String fileTypeStr = getString(R.string.my_filetype, UIUtils.getFileTypeAsString(getResources(), fileType)); TextView title = (TextView) header.findViewById(R.id.view_browse_peer_header_text_title); TextView total = (TextView) header.findViewById(R.id.view_browse_peer_header_text_total); title.setText(fileTypeStr); total.setText("(" + String.valueOf(numTotal) + ")"); } if (adapter == null) { browseFilesButtonClick(Constants.FILE_TYPE_AUDIO); } restoreListViewScrollPosition(); }
private void handleLastBackPressed() { trackDialog( UIUtils.showYesNoDialog( this, R.string.are_you_sure_you_wanna_leave, R.string.minimize_frostwire, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); } })); }
@Override public void onClick() { if (fd.fileType != Constants.FILE_TYPE_PICTURES) { return; } try { Bitmap bitmap = BitmapFactory.decodeFile(fd.filePath); WallpaperManager.getInstance(getContext()).setBitmap(bitmap); } catch (Throwable e) { UIUtils.showShortMessage(getContext(), R.string.failed_to_set_wallpaper); } }
private StorageMount getPrimaryExternal(Context context) { StorageMount mount = null; if (SystemUtils.isPrimaryExternalStorageMounted()) { File dir = Environment.getExternalStorageDirectory(); String label = context.getString(R.string.device_storage); String description = UIUtils.getBytesInHuman(SystemUtils.getAvailableStorageSize(dir)) + " " + context.getString(R.string.available); String path = dir.getAbsolutePath(); mount = new StorageMount(label, description, path, true); } return mount; }
@Override protected void onClick(Context context) { if (Ref.alive(poRef)) { PaymentOptions po = poRef.get(); if (po.paypalUrl == null) { return; } try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(po.paypalUrl)); context.startActivity(intent); } catch (Throwable e) { UIUtils.showLongMessage(getContext(), R.string.issue_with_tip_donation_uri); } } UXStats.instance().log(UXAction.DOWNLOAD_CLICK_PAYPAL_PAYMENT); }
@Override public void onSuccess(String arg0) { UIUtils.showLongMessage(context, R.string.donation_thanks); }
@Override protected void onNewIntent(Intent intent) { if (isShutdown(intent)) { return; } String action = intent.getAction(); // onResumeFragments(); if (action != null && action.equals(Constants.ACTION_SHOW_TRANSFERS)) { controller.showTransfers(TransferStatus.ALL); } else if (action != null && action.equals(Constants.ACTION_OPEN_TORRENT_URL)) { // Open a Torrent from a URL or from a local file :), say from Astro File Manager. /** * TODO: Ask @aldenml the best way to plug in NewTransferDialog. I've refactored this dialog * so that it is forced (no matter if the setting to not show it again has been used) and when * that happens the checkbox is hidden. * * <p>However that dialog requires some data about the download, data which is not obtained * until we have instantiated the Torrent object. * * <p>I'm thinking that we can either: a) Pass a parameter to the transfer manager, but this * would probably not be cool since the transfer manager (I think) should work independently * from the UI thread. * * <p>b) Pass a "listener" to the transfer manager, once the transfer manager has the torrent * it can notify us and wait for the user to decide whether or not to continue with the * transfer * * <p>c) Forget about showing that dialog, and just start the download, the user can cancel * it. */ // Show me the transfer tab Intent i = new Intent(this, MainActivity.class); i.setAction(Constants.ACTION_SHOW_TRANSFERS); i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(i); // go! final String uri = intent.getDataString(); if (uri != null) { TransferManager.instance().downloadTorrent(uri); } else { LOG.warn( "MainActivity.onNewIntent(): Couldn't start torrent download from Intent's URI, intent.getDataString() -> null"); LOG.warn("(maybe URI is coming in another property of the intent object - #fragmentation)"); } } // When another application wants to "Share" a file and has chosen FrostWire to do so. // We make the file "Shared" so it's visible for other FrostWire devices on the local network. else if (action != null && (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE))) { controller.handleSendAction(intent); intent.setAction(null); } else if (action != null && action.equals(Constants.ACTION_START_TRANSFER_FROM_PREVIEW)) { if (Ref.alive(NewTransferDialog.srRef)) { SearchFragment.startDownload( this, NewTransferDialog.srRef.get(), getString(R.string.download_added_to_queue)); UXStats.instance().log(UXAction.DOWNLOAD_CLOUD_FILE_FROM_PREVIEW); } } if (intent.hasExtra(Constants.EXTRA_DOWNLOAD_COMPLETE_NOTIFICATION)) { controller.showTransfers(TransferStatus.COMPLETED); TransferManager.instance().clearDownloadsToReview(); try { ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .cancel(Constants.NOTIFICATION_DOWNLOAD_TRANSFER_FINISHED); Bundle extras = intent.getExtras(); if (extras.containsKey(Constants.EXTRA_DOWNLOAD_COMPLETE_PATH)) { File file = new File(extras.getString(Constants.EXTRA_DOWNLOAD_COMPLETE_PATH)); if (file.isFile()) { UIUtils.openFile(this, file.getAbsoluteFile()); } } } catch (Throwable e) { LOG.warn("Error handling download complete notification", e); } } }