mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Remove use of activity.mojom (#6317)
Instead, we now interact with the system navigator via SystemNavigator.
This commit is contained in:
parent
e8168401e5
commit
6e5c192cef
@ -1 +1 @@
|
||||
50f1b8d9ca29e2fe70cd9012c5e3bf6eff29ce91
|
||||
da96a8bddda72f14b02a0afda871d126dfebdb17
|
||||
|
@ -1,25 +0,0 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
void main() {
|
||||
runApp(new GestureDetector(
|
||||
onTap: () {
|
||||
Intent intent = new Intent()
|
||||
..action = 'android.intent.action.VIEW'
|
||||
..url = 'http://flutter.io/';
|
||||
activity.startActivity(intent);
|
||||
},
|
||||
child: new Container(
|
||||
decoration: const BoxDecoration(
|
||||
backgroundColor: const Color(0xFF006600)
|
||||
),
|
||||
child: new Center(
|
||||
child: new Text('Tap to launch a URL!')
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
@ -14,7 +14,6 @@
|
||||
/// Flutter library.
|
||||
library services;
|
||||
|
||||
export 'src/services/activity.dart';
|
||||
export 'src/services/asset_bundle.dart';
|
||||
export 'src/services/binding.dart';
|
||||
export 'src/services/clipboard.dart';
|
||||
@ -30,5 +29,6 @@ export 'src/services/path_provider.dart';
|
||||
export 'src/services/platform_messages.dart';
|
||||
export 'src/services/shell.dart';
|
||||
export 'src/services/system_chrome.dart';
|
||||
export 'src/services/system_navigator.dart';
|
||||
export 'src/services/system_sound.dart';
|
||||
export 'src/services/url_launcher.dart';
|
||||
|
@ -1,65 +0,0 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter_services/activity.dart';
|
||||
|
||||
import 'shell.dart';
|
||||
|
||||
export 'package:flutter_services/activity.dart' show Activity, Intent, ComponentName, StringExtra;
|
||||
|
||||
|
||||
// Dart wrapper around Activity mojo service available in Flutter on Android.
|
||||
//
|
||||
// Most clients will want to use these methods instead of the activity service
|
||||
// directly.
|
||||
|
||||
// The constants below are from
|
||||
// http://developer.android.com/reference/android/content/Intent.html
|
||||
|
||||
/// Open a document into a new task rooted at the activity launched by
|
||||
/// this Intent.
|
||||
///
|
||||
/// See Android's Intent.FLAG_ACTIVITY_NEW_DOCUMENT.
|
||||
const int NEW_DOCUMENT = 0x00080000; // ignore: constant_identifier_names
|
||||
|
||||
/// Start a new task on this history stack.
|
||||
///
|
||||
/// See Android's Intent.FLAG_ACTIVITY_NEW_TASK.
|
||||
const int NEW_TASK = 0x10000000; // ignore: constant_identifier_names
|
||||
|
||||
/// Create a new task and launch an activity into it.
|
||||
///
|
||||
/// See Android's Intent.FLAG_ACTIVITY_MULTIPLE_TASK.
|
||||
const int MULTIPLE_TASK = 0x08000000; // ignore: constant_identifier_names
|
||||
|
||||
ActivityProxy _initActivityProxy() {
|
||||
return shell.connectToApplicationService('mojo:android', Activity.connectToService);
|
||||
}
|
||||
|
||||
final ActivityProxy _activityProxy = _initActivityProxy();
|
||||
|
||||
/// A singleton for interacting with the current Android activity.
|
||||
final Activity activity = _activityProxy;
|
||||
|
||||
Color _cachedPrimaryColor;
|
||||
String _cachedLabel;
|
||||
|
||||
/// Sets the TaskDescription for the current Activity.
|
||||
/// The color, if provided, must be opaque.
|
||||
void updateTaskDescription({ String label, Color color }) {
|
||||
assert(color == null || color.alpha == 0xFF);
|
||||
if (_cachedPrimaryColor == color && _cachedLabel == label)
|
||||
return;
|
||||
|
||||
_cachedPrimaryColor = color;
|
||||
_cachedLabel = label;
|
||||
|
||||
TaskDescription description = new TaskDescription()
|
||||
..label = label
|
||||
..primaryColor = color?.value ?? 0;
|
||||
|
||||
_activityProxy.setTaskDescription(description);
|
||||
}
|
@ -24,7 +24,7 @@ class HapticFeedback {
|
||||
static Future<Null> vibrate() async {
|
||||
await PlatformMessages.sendJSON('flutter/platform', <String, dynamic>{
|
||||
'method': 'HapticFeedback.vibrate',
|
||||
'args': <Null>[],
|
||||
'args': const <Null>[],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class PathProvider {
|
||||
Map<String, dynamic> result =
|
||||
await PlatformMessages.sendJSON('flutter/platform', <String, dynamic>{
|
||||
'method': 'PathProvider.getTemporaryDirectory',
|
||||
'args': <Null>[],
|
||||
'args': const <Null>[],
|
||||
});
|
||||
if (result == null)
|
||||
return null;
|
||||
@ -44,7 +44,7 @@ class PathProvider {
|
||||
Map<String, dynamic> result =
|
||||
await PlatformMessages.sendJSON('flutter/platform', <String, dynamic>{
|
||||
'method': 'PathProvider.getApplicationDocumentsDirectory',
|
||||
'args': <Null>[],
|
||||
'args': const <Null>[],
|
||||
});
|
||||
if (result == null)
|
||||
return null;
|
||||
|
26
packages/flutter/lib/src/services/system_navigator.dart
Normal file
26
packages/flutter/lib/src/services/system_navigator.dart
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'platform_messages.dart';
|
||||
|
||||
/// Controls specific aspects of the system navigation stack.
|
||||
class SystemNavigator {
|
||||
SystemNavigator._();
|
||||
|
||||
/// Instructs the system navigator to remove this activity from the stack and
|
||||
/// return to the previous activity.
|
||||
///
|
||||
/// Platform Specific Notes:
|
||||
///
|
||||
/// On iOS, this is a no-op because Apple's human interface guidelines state
|
||||
/// that applications should not exit themselves.
|
||||
static Future<Null> pop() async {
|
||||
await PlatformMessages.sendJSON('flutter/platform', <String, dynamic>{
|
||||
'method': 'SystemNavigator.pop',
|
||||
'args': const <Null>[],
|
||||
});
|
||||
}
|
||||
}
|
@ -164,7 +164,7 @@ abstract class WidgetsBinding extends BindingBase implements GestureBinding, Ren
|
||||
if (observer.didPopRoute())
|
||||
return;
|
||||
}
|
||||
activity.finishCurrentActivity();
|
||||
SystemNavigator.pop();
|
||||
}
|
||||
|
||||
/// Called when the application lifecycle state changes.
|
||||
|
@ -28,7 +28,12 @@ class Title extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
updateTaskDescription(label: title, color: color);
|
||||
SystemChrome.setApplicationSwitcherDescription(
|
||||
new ApplicationSwitcherDescription(
|
||||
label: title,
|
||||
primaryColor: color.value,
|
||||
)
|
||||
);
|
||||
return child;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user