Eric Kok
12 years ago
5 changed files with 223 additions and 13 deletions
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
package org.transdroid.core.gui.search; |
||||
|
||||
import org.transdroid.core.R; |
||||
|
||||
import android.app.AlertDialog; |
||||
import android.content.DialogInterface; |
||||
import android.content.DialogInterface.OnClickListener; |
||||
import android.content.Intent; |
||||
import android.net.Uri; |
||||
import android.support.v4.app.DialogFragment; |
||||
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity; |
||||
|
||||
public class FilePickerHelper { |
||||
|
||||
public static final int ACTIVITY_FILEPICKER = 0x0000c0df; // A 'random' ID to identify file picker intents
|
||||
public static final Uri FILEMANAGER_MARKET_URI = Uri.parse("market://search?q=pname:org.openintents.filemanager"); |
||||
|
||||
/** |
||||
* Call this to start a file picker intent. The calling activity will receive an Intent result with ID |
||||
* {@link #ACTIVITY_FILEPICKER} with an Intent that contains the selected local file as data Intent. |
||||
* @param activity The calling activity, to which the result is returned or a dialog is bound that asks to install |
||||
* the file picker |
||||
*/ |
||||
public static void startFilePicker(final SherlockFragmentActivity activity) { |
||||
try { |
||||
// Start a file manager that can handle the PICK_FILE intent (specifically IO File Manager)
|
||||
activity.startActivityForResult(new Intent("org.openintents.action.PICK_FILE"), ACTIVITY_FILEPICKER); |
||||
} catch (Exception e) { |
||||
// Can't start the file manager, for example with a SecurityException or when IO File Manager is not present
|
||||
new DialogFragment() { |
||||
public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { |
||||
return new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) |
||||
.setMessage(activity.getString(R.string.search_filemanagernotfound)) |
||||
.setPositiveButton(android.R.string.yes, new OnClickListener() { |
||||
@Override |
||||
public void onClick(DialogInterface dialog, int which) { |
||||
if (activity != null) |
||||
activity.startActivity(new Intent(Intent.ACTION_VIEW, FILEMANAGER_MARKET_URI)); |
||||
} |
||||
}).setNegativeButton(android.R.string.no, null).create(); |
||||
}; |
||||
}.show(activity.getSupportFragmentManager(), "installfilemanager"); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
package org.transdroid.core.gui.search; |
||||
|
||||
import org.transdroid.core.gui.TorrentsActivity; |
||||
|
||||
import android.app.AlertDialog; |
||||
import android.content.DialogInterface; |
||||
import android.content.DialogInterface.OnClickListener; |
||||
import android.support.v4.app.DialogFragment; |
||||
import android.text.InputType; |
||||
import android.text.TextUtils; |
||||
import android.widget.EditText; |
||||
|
||||
public class UrlEntryDialog { |
||||
|
||||
/** |
||||
* Opens a dialog that allows entry of a single URL string, which (on confirmation) will be supplied to the calling |
||||
* activity's {@link TorrentsActivity#addTorrentByUrl(String, String) method}. |
||||
* @param activity The activity that opens (and owns) this dialog |
||||
*/ |
||||
public static void startUrlEntry(final TorrentsActivity activity) { |
||||
new DialogFragment() { |
||||
public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { |
||||
final EditText urlInput = new EditText(activity); |
||||
urlInput.setInputType(InputType.TYPE_TEXT_VARIATION_URI); |
||||
return new AlertDialog.Builder(activity).setView(urlInput) |
||||
.setPositiveButton(android.R.string.ok, new OnClickListener() { |
||||
@Override |
||||
public void onClick(DialogInterface dialog, int which) { |
||||
// Assume text entry box input as URL and treat the filename (after the last /) as title
|
||||
String url = urlInput.getText().toString(); |
||||
if (activity != null && !TextUtils.isEmpty(url)) |
||||
activity.addTorrentByUrl(url, url.substring(url.lastIndexOf("/"))); |
||||
} |
||||
}).setNegativeButton(android.R.string.cancel, null).create(); |
||||
}; |
||||
}.show(activity.getSupportFragmentManager(), "urlentry"); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue