fullscreen: added open action
This commit is contained in:
parent
e40136d646
commit
5571f9f236
5 changed files with 72 additions and 39 deletions
|
@ -29,6 +29,20 @@ public class AppAdapterHandler implements MethodChannel.MethodCallHandler {
|
|||
result.success(null);
|
||||
break;
|
||||
}
|
||||
case "open": {
|
||||
String title = call.argument("title");
|
||||
Uri uri = Uri.parse(call.argument("uri"));
|
||||
String mimeType = call.argument("mimeType");
|
||||
open(title, uri, mimeType);
|
||||
result.success(null);
|
||||
break;
|
||||
}
|
||||
case "openMap": {
|
||||
Uri geoUri = Uri.parse(call.argument("geoUri"));
|
||||
openMap(geoUri);
|
||||
result.success(null);
|
||||
break;
|
||||
}
|
||||
case "setAs": {
|
||||
String title = call.argument("title");
|
||||
Uri uri = Uri.parse(call.argument("uri"));
|
||||
|
@ -45,12 +59,6 @@ public class AppAdapterHandler implements MethodChannel.MethodCallHandler {
|
|||
result.success(null);
|
||||
break;
|
||||
}
|
||||
case "showOnMap": {
|
||||
Uri geoUri = Uri.parse(call.argument("geoUri"));
|
||||
showOnMap(geoUri);
|
||||
result.success(null);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
result.notImplemented();
|
||||
break;
|
||||
|
@ -63,6 +71,19 @@ public class AppAdapterHandler implements MethodChannel.MethodCallHandler {
|
|||
context.startActivity(Intent.createChooser(intent, title));
|
||||
}
|
||||
|
||||
private void open(String title, Uri uri, String mimeType) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, mimeType);
|
||||
context.startActivity(Intent.createChooser(intent, title));
|
||||
}
|
||||
|
||||
private void openMap(Uri geoUri) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, geoUri);
|
||||
if (intent.resolveActivity(context.getPackageManager()) != null) {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
private void setAs(String title, Uri uri, String mimeType) {
|
||||
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
|
||||
intent.setDataAndType(uri, mimeType);
|
||||
|
@ -75,11 +96,4 @@ public class AppAdapterHandler implements MethodChannel.MethodCallHandler {
|
|||
intent.setType(mimeType);
|
||||
context.startActivity(Intent.createChooser(intent, title));
|
||||
}
|
||||
|
||||
private void showOnMap(Uri geoUri) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, geoUri);
|
||||
if (intent.resolveActivity(context.getPackageManager()) != null) {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,12 @@ public class MediaStoreStreamHandler implements EventChannel.StreamHandler {
|
|||
|
||||
@Override
|
||||
public void onListen(Object args, final EventChannel.EventSink events) {
|
||||
Log.w(LOG_TAG, "onListen with args=" + args);
|
||||
eventSink = events;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(Object args) {
|
||||
Log.w(LOG_TAG, "onCancel with args=" + args);
|
||||
// nothing
|
||||
}
|
||||
|
||||
void fetchAll(Activity activity) {
|
||||
|
|
|
@ -7,7 +7,7 @@ class AndroidAppService {
|
|||
static edit(String uri, String mimeType) async {
|
||||
try {
|
||||
await platform.invokeMethod('edit', <String, dynamic>{
|
||||
'title': 'Edit',
|
||||
'title': 'Edit with:',
|
||||
'uri': uri,
|
||||
'mimeType': mimeType,
|
||||
});
|
||||
|
@ -16,10 +16,33 @@ class AndroidAppService {
|
|||
}
|
||||
}
|
||||
|
||||
static open(String uri, String mimeType) async {
|
||||
try {
|
||||
await platform.invokeMethod('open', <String, dynamic>{
|
||||
'title': 'Open with:',
|
||||
'uri': uri,
|
||||
'mimeType': mimeType,
|
||||
});
|
||||
} on PlatformException catch (e) {
|
||||
debugPrint('open failed with exception=${e.message}');
|
||||
}
|
||||
}
|
||||
|
||||
static openMap(String geoUri) async {
|
||||
if (geoUri == null) return;
|
||||
try {
|
||||
await platform.invokeMethod('openMap', <String, dynamic>{
|
||||
'geoUri': geoUri,
|
||||
});
|
||||
} on PlatformException catch (e) {
|
||||
debugPrint('openMap failed with exception=${e.message}');
|
||||
}
|
||||
}
|
||||
|
||||
static setAs(String uri, String mimeType) async {
|
||||
try {
|
||||
await platform.invokeMethod('setAs', <String, dynamic>{
|
||||
'title': 'Set as',
|
||||
'title': 'Set as:',
|
||||
'uri': uri,
|
||||
'mimeType': mimeType,
|
||||
});
|
||||
|
@ -39,15 +62,4 @@ class AndroidAppService {
|
|||
debugPrint('share failed with exception=${e.message}');
|
||||
}
|
||||
}
|
||||
|
||||
static showOnMap(String geoUri) async {
|
||||
if (geoUri == null) return;
|
||||
try {
|
||||
await platform.invokeMethod('showOnMap', <String, dynamic>{
|
||||
'geoUri': geoUri,
|
||||
});
|
||||
} on PlatformException catch (e) {
|
||||
debugPrint('share failed with exception=${e.message}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -261,20 +261,23 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
|
|||
case FullscreenAction.rename:
|
||||
showRenameDialog(entry);
|
||||
break;
|
||||
case FullscreenAction.open:
|
||||
AndroidAppService.open(entry.uri, entry.mimeType);
|
||||
break;
|
||||
case FullscreenAction.openMap:
|
||||
AndroidAppService.openMap(entry.geoUri);
|
||||
break;
|
||||
case FullscreenAction.setAs:
|
||||
AndroidAppService.setAs(entry.uri, entry.mimeType);
|
||||
break;
|
||||
case FullscreenAction.share:
|
||||
AndroidAppService.share(entry.uri, entry.mimeType);
|
||||
break;
|
||||
case FullscreenAction.showOnMap:
|
||||
AndroidAppService.showOnMap(entry.geoUri);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum FullscreenAction { edit, info, rename, setAs, share, showOnMap }
|
||||
enum FullscreenAction { edit, info, open, openMap, rename, setAs, share }
|
||||
|
||||
class ImagePage extends StatefulWidget {
|
||||
final List<ImageEntry> entries;
|
||||
|
|
|
@ -52,22 +52,27 @@ class FullscreenTopOverlay extends StatelessWidget {
|
|||
value: FullscreenAction.info,
|
||||
child: Text("Info"),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: FullscreenAction.edit,
|
||||
child: Text("Edit"),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: FullscreenAction.rename,
|
||||
child: Text("Rename"),
|
||||
),
|
||||
PopupMenuDivider(),
|
||||
PopupMenuItem(
|
||||
value: FullscreenAction.edit,
|
||||
child: Text("Edit with…"),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: FullscreenAction.open,
|
||||
child: Text("Open with…"),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: FullscreenAction.setAs,
|
||||
child: Text("Set as"),
|
||||
child: Text("Set as…"),
|
||||
),
|
||||
if (entry.hasGps)
|
||||
PopupMenuItem(
|
||||
value: FullscreenAction.showOnMap,
|
||||
child: Text("Show on map"),
|
||||
value: FullscreenAction.openMap,
|
||||
child: Text("Show on map…"),
|
||||
),
|
||||
],
|
||||
onSelected: onActionSelected,
|
||||
|
|
Loading…
Reference in a new issue