Delete io.flutter.app android v1 embedding (flutter/engine#32074)

This commit is contained in:
Gary Qian 2022-03-23 20:22:54 -07:00 committed by GitHub
parent 626fde74c4
commit 08cef2ee55
14 changed files with 9 additions and 977 deletions

View File

@ -1182,11 +1182,6 @@ FILE: ../../../flutter/shell/platform/android/flutter_main.h
FILE: ../../../flutter/shell/platform/android/flutter_shell_native_unittests.cc
FILE: ../../../flutter/shell/platform/android/io/flutter/FlutterInjector.java
FILE: ../../../flutter/shell/platform/android/io/flutter/Log.java
FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterActivity.java
FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java
FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterActivityEvents.java
FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterApplication.java
FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterFragmentActivity.java
FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterPlayStoreSplitApplication.java
FILE: ../../../flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java

View File

@ -3,25 +3,11 @@
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.flutter.app" android:versionCode="1" android:versionName="0.0.1">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.flutter.embedding" android:versionCode="1" android:versionName="0.0.1">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="31" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
<application android:label="Flutter Shell" android:name="FlutterApplication" android:debuggable="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
android:hardwareAccelerated="true"
android:launchMode="standard"
android:name="FlutterActivity"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -153,11 +153,6 @@ embedding_source_jar_path = "$root_out_dir/$embedding_sources_jar_filename"
android_java_sources = [
"io/flutter/FlutterInjector.java",
"io/flutter/Log.java",
"io/flutter/app/FlutterActivity.java",
"io/flutter/app/FlutterActivityDelegate.java",
"io/flutter/app/FlutterActivityEvents.java",
"io/flutter/app/FlutterApplication.java",
"io/flutter/app/FlutterFragmentActivity.java",
"io/flutter/app/FlutterPlayStoreSplitApplication.java",
"io/flutter/app/FlutterPluginRegistry.java",
"io/flutter/embedding/android/AndroidTouchProcessor.java",

View File

@ -1,175 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package io.flutter.app;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import androidx.annotation.NonNull;
import io.flutter.app.FlutterActivityDelegate.ViewFactory;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.view.FlutterNativeView;
import io.flutter.view.FlutterView;
/**
* Deprecated base class for activities that use Flutter.
*
* @deprecated {@link io.flutter.embedding.android.FlutterActivity} is the new API that now replaces
* this class. See https://flutter.dev/go/android-project-migration for more migration details.
*/
@Deprecated
public class FlutterActivity extends Activity
implements FlutterView.Provider, PluginRegistry, ViewFactory {
private static final String TAG = "FlutterActivity";
private final FlutterActivityDelegate delegate = new FlutterActivityDelegate(this, this);
// These aliases ensure that the methods we forward to the delegate adhere
// to relevant interfaces versus just existing in FlutterActivityDelegate.
private final FlutterActivityEvents eventDelegate = delegate;
private final FlutterView.Provider viewProvider = delegate;
private final PluginRegistry pluginRegistry = delegate;
/**
* Returns the Flutter view used by this activity; will be null before {@link #onCreate(Bundle)}
* is called.
*/
@Override
public FlutterView getFlutterView() {
return viewProvider.getFlutterView();
}
/**
* Hook for subclasses to customize the creation of the {@code FlutterView}.
*
* <p>The default implementation returns {@code null}, which will cause the activity to use a
* newly instantiated full-screen view.
*/
@Override
public FlutterView createFlutterView(Context context) {
return null;
}
/**
* Hook for subclasses to customize the creation of the {@code FlutterNativeView}.
*
* <p>The default implementation returns {@code null}, which will cause the activity to use a
* newly instantiated native view object.
*/
@Override
public FlutterNativeView createFlutterNativeView() {
return null;
}
@Override
public boolean retainFlutterNativeView() {
return false;
}
@Override
public final boolean hasPlugin(String key) {
return pluginRegistry.hasPlugin(key);
}
@Override
public final <T> T valuePublishedByPlugin(String pluginKey) {
return pluginRegistry.valuePublishedByPlugin(pluginKey);
}
@Override
public final Registrar registrarFor(String pluginKey) {
return pluginRegistry.registrarFor(pluginKey);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
eventDelegate.onCreate(savedInstanceState);
}
@Override
protected void onStart() {
super.onStart();
eventDelegate.onStart();
}
@Override
protected void onResume() {
super.onResume();
eventDelegate.onResume();
}
@Override
protected void onDestroy() {
eventDelegate.onDestroy();
super.onDestroy();
}
@Override
public void onBackPressed() {
if (!eventDelegate.onBackPressed()) {
super.onBackPressed();
}
}
@Override
protected void onStop() {
eventDelegate.onStop();
super.onStop();
}
@Override
protected void onPause() {
super.onPause();
eventDelegate.onPause();
}
@Override
protected void onPostResume() {
super.onPostResume();
eventDelegate.onPostResume();
}
// @Override - added in API level 23
public void onRequestPermissionsResult(
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
eventDelegate.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!eventDelegate.onActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
protected void onNewIntent(Intent intent) {
eventDelegate.onNewIntent(intent);
}
@Override
public void onUserLeaveHint() {
eventDelegate.onUserLeaveHint();
}
@Override
public void onTrimMemory(int level) {
eventDelegate.onTrimMemory(level);
}
@Override
public void onLowMemory() {
eventDelegate.onLowMemory();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
eventDelegate.onConfigurationChanged(newConfig);
}
}

View File

@ -1,483 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package io.flutter.app;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import io.flutter.Log;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.platform.PlatformPlugin;
import io.flutter.util.Preconditions;
import io.flutter.view.FlutterMain;
import io.flutter.view.FlutterNativeView;
import io.flutter.view.FlutterRunArguments;
import io.flutter.view.FlutterView;
import java.util.ArrayList;
/**
* Deprecated class that performs the actual work of tying Android {@link android.app.Activity}
* instances to Flutter.
*
* <p>This exists as a dedicated class (as opposed to being integrated directly into {@link
* FlutterActivity}) to facilitate applications that don't wish to subclass {@code FlutterActivity}.
* The most obvious example of when this may come in handy is if an application wishes to subclass
* the Android v4 support library's {@code FragmentActivity}.
*
* <p><b>Usage:</b>
*
* <p>To wire this class up to your activity, simply forward the events defined in {@link
* FlutterActivityEvents} from your activity to an instance of this class. Optionally, you can make
* your activity implement {@link PluginRegistry} and/or {@link
* io.flutter.view.FlutterView.Provider} and forward those methods to this class as well.
*
* @deprecated {@link io.flutter.embedding.android.FlutterActivity} is the new API that now replaces
* this class and {@link io.flutter.app.FlutterActivity}. See
* https://flutter.dev/go/android-project-migration for more migration details.
*/
@Deprecated
public final class FlutterActivityDelegate
implements FlutterActivityEvents, FlutterView.Provider, PluginRegistry {
private static final String SPLASH_SCREEN_META_DATA_KEY =
"io.flutter.app.android.SplashScreenUntilFirstFrame";
private static final String TAG = "FlutterActivityDelegate";
private static final LayoutParams matchParent =
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
/**
* Specifies the mechanism by which Flutter views are created during the operation of a {@code
* FlutterActivityDelegate}.
*
* <p>A delegate's view factory will be consulted during {@link #onCreate(Bundle)}. If it returns
* {@code null}, then the delegate will fall back to instantiating a new full-screen {@code
* FlutterView}.
*
* <p>A delegate's native view factory will be consulted during {@link #onCreate(Bundle)}. If it
* returns {@code null}, then the delegate will fall back to instantiating a new {@code
* FlutterNativeView}. This is useful for applications to override to reuse the FlutterNativeView
* held e.g. by a pre-existing background service.
*/
public interface ViewFactory {
FlutterView createFlutterView(Context context);
FlutterNativeView createFlutterNativeView();
/**
* Hook for subclasses to indicate that the {@code FlutterNativeView} returned by {@link
* #createFlutterNativeView()} should not be destroyed when this activity is destroyed.
*
* @return Whether the FlutterNativeView is retained.
*/
boolean retainFlutterNativeView();
}
private final Activity activity;
private final ViewFactory viewFactory;
private FlutterView flutterView;
private View launchView;
public FlutterActivityDelegate(Activity activity, ViewFactory viewFactory) {
this.activity = Preconditions.checkNotNull(activity);
this.viewFactory = Preconditions.checkNotNull(viewFactory);
}
@Override
public FlutterView getFlutterView() {
return flutterView;
}
// The implementation of PluginRegistry forwards to flutterView.
@Override
public boolean hasPlugin(String key) {
return flutterView.getPluginRegistry().hasPlugin(key);
}
@Override
@SuppressWarnings("unchecked")
public <T> T valuePublishedByPlugin(String pluginKey) {
return (T) flutterView.getPluginRegistry().valuePublishedByPlugin(pluginKey);
}
@Override
public Registrar registrarFor(String pluginKey) {
return flutterView.getPluginRegistry().registrarFor(pluginKey);
}
@Override
public boolean onRequestPermissionsResult(
int requestCode, String[] permissions, int[] grantResults) {
return flutterView
.getPluginRegistry()
.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
return flutterView.getPluginRegistry().onActivityResult(requestCode, resultCode, data);
}
@Override
public void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();
window.addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(0x40000000);
window.getDecorView().setSystemUiVisibility(PlatformPlugin.DEFAULT_SYSTEM_UI);
}
String[] args = getArgsFromIntent(activity.getIntent());
FlutterMain.ensureInitializationComplete(activity.getApplicationContext(), args);
flutterView = viewFactory.createFlutterView(activity);
if (flutterView == null) {
FlutterNativeView nativeView = viewFactory.createFlutterNativeView();
flutterView = new FlutterView(activity, null, nativeView);
flutterView.setLayoutParams(matchParent);
activity.setContentView(flutterView);
launchView = createLaunchView();
if (launchView != null) {
addLaunchView();
}
}
if (loadIntent(activity.getIntent())) {
return;
}
String appBundlePath = FlutterMain.findAppBundlePath();
if (appBundlePath != null) {
runBundle(appBundlePath);
}
}
@Override
public void onNewIntent(Intent intent) {
// Only attempt to reload the Flutter Dart code during development. Use
// the debuggable flag as an indicator that we are in development mode.
if (!isDebuggable() || !loadIntent(intent)) {
flutterView.getPluginRegistry().onNewIntent(intent);
}
}
private boolean isDebuggable() {
return (activity.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}
@Override
public void onPause() {
Application app = (Application) activity.getApplicationContext();
if (app instanceof FlutterApplication) {
FlutterApplication flutterApp = (FlutterApplication) app;
if (activity.equals(flutterApp.getCurrentActivity())) {
flutterApp.setCurrentActivity(null);
}
}
if (flutterView != null) {
flutterView.onPause();
}
}
@Override
public void onStart() {
if (flutterView != null) {
flutterView.onStart();
}
}
@Override
public void onResume() {
Application app = (Application) activity.getApplicationContext();
if (app instanceof FlutterApplication) {
FlutterApplication flutterApp = (FlutterApplication) app;
flutterApp.setCurrentActivity(activity);
}
}
@Override
public void onStop() {
flutterView.onStop();
}
@Override
public void onPostResume() {
if (flutterView != null) {
flutterView.onPostResume();
}
}
@Override
public void onDestroy() {
Application app = (Application) activity.getApplicationContext();
if (app instanceof FlutterApplication) {
FlutterApplication flutterApp = (FlutterApplication) app;
if (activity.equals(flutterApp.getCurrentActivity())) {
flutterApp.setCurrentActivity(null);
}
}
if (flutterView != null) {
final boolean detach =
flutterView.getPluginRegistry().onViewDestroy(flutterView.getFlutterNativeView());
if (detach || viewFactory.retainFlutterNativeView()) {
// Detach, but do not destroy the FlutterView if a plugin
// expressed interest in its FlutterNativeView.
flutterView.detach();
} else {
flutterView.destroy();
}
}
}
@Override
public boolean onBackPressed() {
if (flutterView != null) {
flutterView.popRoute();
return true;
}
return false;
}
@Override
public void onUserLeaveHint() {
flutterView.getPluginRegistry().onUserLeaveHint();
}
@Override
public void onTrimMemory(int level) {
// Use a trim level delivered while the application is running so the
// framework has a chance to react to the notification.
if (level == TRIM_MEMORY_RUNNING_LOW) {
flutterView.onMemoryPressure();
}
}
@Override
public void onLowMemory() {
flutterView.onMemoryPressure();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {}
private static String[] getArgsFromIntent(Intent intent) {
// Before adding more entries to this list, consider that arbitrary
// Android applications can generate intents with extra data and that
// there are many security-sensitive args in the binary.
ArrayList<String> args = new ArrayList<>();
if (intent.getBooleanExtra("trace-startup", false)) {
args.add("--trace-startup");
}
if (intent.getBooleanExtra("start-paused", false)) {
args.add("--start-paused");
}
if (intent.getBooleanExtra("disable-service-auth-codes", false)) {
args.add("--disable-service-auth-codes");
}
if (intent.getBooleanExtra("use-test-fonts", false)) {
args.add("--use-test-fonts");
}
if (intent.getBooleanExtra("enable-dart-profiling", false)) {
args.add("--enable-dart-profiling");
}
if (intent.getBooleanExtra("enable-software-rendering", false)) {
args.add("--enable-software-rendering");
}
if (intent.getBooleanExtra("skia-deterministic-rendering", false)) {
args.add("--skia-deterministic-rendering");
}
if (intent.getBooleanExtra("trace-skia", false)) {
args.add("--trace-skia");
}
if (intent.getBooleanExtra("trace-systrace", false)) {
args.add("--trace-systrace");
}
if (intent.getBooleanExtra("dump-skp-on-shader-compilation", false)) {
args.add("--dump-skp-on-shader-compilation");
}
if (intent.getBooleanExtra("cache-sksl", false)) {
args.add("--cache-sksl");
}
if (intent.getBooleanExtra("purge-persistent-cache", false)) {
args.add("--purge-persistent-cache");
}
if (intent.getBooleanExtra("verbose-logging", false)) {
args.add("--verbose-logging");
}
final int observatoryPort = intent.getIntExtra("observatory-port", 0);
if (observatoryPort > 0) {
args.add("--observatory-port=" + Integer.toString(observatoryPort));
}
if (intent.getBooleanExtra("endless-trace-buffer", false)) {
args.add("--endless-trace-buffer");
}
// NOTE: all flags provided with this argument are subject to filtering
// based on a a list of allowed flags in shell/common/switches.cc. If any
// flag provided is not allowed, the process will immediately terminate.
if (intent.hasExtra("dart-flags")) {
args.add("--dart-flags=" + intent.getStringExtra("dart-flags"));
}
if (!args.isEmpty()) {
String[] argsArray = new String[args.size()];
return args.toArray(argsArray);
}
return null;
}
private boolean loadIntent(Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_RUN.equals(action)) {
String route = intent.getStringExtra("route");
String appBundlePath = intent.getDataString();
if (appBundlePath == null) {
// Fall back to the installation path if no bundle path was specified.
appBundlePath = FlutterMain.findAppBundlePath();
}
if (route != null) {
flutterView.setInitialRoute(route);
}
runBundle(appBundlePath);
return true;
}
return false;
}
private void runBundle(String appBundlePath) {
if (!flutterView.getFlutterNativeView().isApplicationRunning()) {
FlutterRunArguments args = new FlutterRunArguments();
args.bundlePath = appBundlePath;
args.entrypoint = "main";
flutterView.runFromBundle(args);
}
}
/**
* Creates a {@link View} containing the same {@link Drawable} as the one set as the {@code
* windowBackground} of the parent activity for use as a launch splash view.
*
* <p>Returns null if no {@code windowBackground} is set for the activity.
*/
private View createLaunchView() {
if (!showSplashScreenUntilFirstFrame()) {
return null;
}
final Drawable launchScreenDrawable = getLaunchScreenDrawableFromActivityTheme();
if (launchScreenDrawable == null) {
return null;
}
final View view = new View(activity);
view.setLayoutParams(matchParent);
view.setBackground(launchScreenDrawable);
return view;
}
/**
* Extracts a {@link Drawable} from the parent activity's {@code windowBackground}.
*
* <p>{@code android:windowBackground} is specifically reused instead of a other attributes
* because the Android framework can display it fast enough when launching the app as opposed to
* anything defined in the Activity subclass.
*
* <p>Returns null if no {@code windowBackground} is set for the activity.
*/
@SuppressWarnings("deprecation")
private Drawable getLaunchScreenDrawableFromActivityTheme() {
TypedValue typedValue = new TypedValue();
if (!activity.getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true)) {
return null;
}
if (typedValue.resourceId == 0) {
return null;
}
try {
return activity.getResources().getDrawable(typedValue.resourceId);
} catch (NotFoundException e) {
Log.e(TAG, "Referenced launch screen windowBackground resource does not exist");
return null;
}
}
/**
* Let the user specify whether the activity's {@code windowBackground} is a launch screen and
* should be shown until the first frame via a <meta-data> tag in the activity.
*/
private Boolean showSplashScreenUntilFirstFrame() {
try {
ActivityInfo activityInfo =
activity
.getPackageManager()
.getActivityInfo(activity.getComponentName(), PackageManager.GET_META_DATA);
Bundle metadata = activityInfo.metaData;
return metadata != null && metadata.getBoolean(SPLASH_SCREEN_META_DATA_KEY);
} catch (NameNotFoundException e) {
return false;
}
}
/**
* Show and then automatically animate out the launch view.
*
* <p>If a launch screen is defined in the user application's AndroidManifest.xml as the
* activity's {@code windowBackground}, display it on top of the {@link FlutterView} and remove
* the activity's {@code windowBackground}.
*
* <p>Fade it out and remove it when the {@link FlutterView} renders its first frame.
*/
private void addLaunchView() {
if (launchView == null) {
return;
}
activity.addContentView(launchView, matchParent);
flutterView.addFirstFrameListener(
new FlutterView.FirstFrameListener() {
@Override
public void onFirstFrame() {
FlutterActivityDelegate.this
.launchView
.animate()
.alpha(0f)
// Use Android's default animation duration.
.setListener(
new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// Views added to an Activity's addContentView is always added to its
// root FrameLayout.
((ViewGroup) FlutterActivityDelegate.this.launchView.getParent())
.removeView(FlutterActivityDelegate.this.launchView);
FlutterActivityDelegate.this.launchView = null;
}
});
FlutterActivityDelegate.this.flutterView.removeFirstFrameListener(this);
}
});
// Resets the activity theme from the one containing the launch screen in the window
// background to a blank one since the launch screen is now in a view in front of the
// FlutterView.
//
// We can make this configurable if users want it.
activity.setTheme(android.R.style.Theme_Black_NoTitleBar);
}
}

View File

@ -1,67 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package io.flutter.app;
import android.content.ComponentCallbacks2;
import android.content.Intent;
import android.os.Bundle;
import io.flutter.plugin.common.PluginRegistry.ActivityResultListener;
import io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener;
/**
* A collection of Android {@code Activity} methods that are relevant to the core operation of
* Flutter applications.
*
* <p>Application authors that use an activity other than {@link FlutterActivity} should forward all
* events herein from their activity to an instance of {@link FlutterActivityDelegate} in order to
* wire the activity up to the Flutter framework. This forwarding is already provided in {@code
* FlutterActivity}.
*/
public interface FlutterActivityEvents
extends ComponentCallbacks2, ActivityResultListener, RequestPermissionsResultListener {
/**
* @param savedInstanceState If the activity is being re-initialized after previously being shut
* down then this Bundle contains the data it most recently supplied in {@code
* onSaveInstanceState(Bundle)}.
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
void onCreate(Bundle savedInstanceState);
/**
* @param intent The new intent that was started for the activity.
* @see android.app.Activity#onNewIntent(Intent)
*/
void onNewIntent(Intent intent);
/** @see android.app.Activity#onPause() */
void onPause();
/** @see android.app.Activity#onStart() */
void onStart();
/** @see android.app.Activity#onResume() */
void onResume();
/** @see android.app.Activity#onPostResume() */
void onPostResume();
/** @see android.app.Activity#onDestroy() */
void onDestroy();
/** @see android.app.Activity#onStop() */
void onStop();
/**
* Invoked when the activity has detected the user's press of the back key.
*
* @return {@code true} if the listener handled the event; {@code false} to let the activity
* continue with its default back button handling.
* @see android.app.Activity#onBackPressed()
*/
boolean onBackPressed();
/** @see android.app.Activity#onUserLeaveHint() */
void onUserLeaveHint();
}

View File

@ -1,36 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package io.flutter.app;
import android.app.Activity;
import android.app.Application;
import androidx.annotation.CallSuper;
import io.flutter.FlutterInjector;
/**
* Flutter implementation of {@link android.app.Application}, managing application-level global
* initializations.
*
* <p>Using this {@link android.app.Application} is not required when using APIs in the package
* {@code io.flutter.embedding.android} since they self-initialize on first use.
*/
public class FlutterApplication extends Application {
@Override
@CallSuper
public void onCreate() {
super.onCreate();
FlutterInjector.instance().flutterLoader().startInitialization(this);
}
private Activity mCurrentActivity = null;
public Activity getCurrentActivity() {
return mCurrentActivity;
}
public void setCurrentActivity(Activity mCurrentActivity) {
this.mCurrentActivity = mCurrentActivity;
}
}

View File

@ -1,173 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package io.flutter.app;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;
import io.flutter.app.FlutterActivityDelegate.ViewFactory;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.view.FlutterNativeView;
import io.flutter.view.FlutterView;
/**
* Deprecated class for activities that use Flutter who also require the use of the Android v4
* Support library's {@link FragmentActivity}.
*
* <p>Applications that don't have this need will likely want to use {@link FlutterActivity}
* instead.
*
* <p><strong>Important!</strong> Flutter does not bundle the necessary Android v4 Support library
* classes for this class to work at runtime. It is the responsibility of the app developer using
* this class to ensure that they link against the v4 support library .jar file when creating their
* app to ensure that {@link FragmentActivity} is available at runtime.
*
* @see <a target="_new"
* href="https://developer.android.com/training/testing/set-up-project">https://developer.android.com/training/testing/set-up-project</a>
* @deprecated this class is replaced by {@link
* io.flutter.embedding.android.FlutterFragmentActivity}.
*/
@Deprecated
public class FlutterFragmentActivity extends FragmentActivity
implements FlutterView.Provider, PluginRegistry, ViewFactory {
private final FlutterActivityDelegate delegate = new FlutterActivityDelegate(this, this);
// These aliases ensure that the methods we forward to the delegate adhere
// to relevant interfaces versus just existing in FlutterActivityDelegate.
private final FlutterActivityEvents eventDelegate = delegate;
private final FlutterView.Provider viewProvider = delegate;
private final PluginRegistry pluginRegistry = delegate;
/**
* Returns the Flutter view used by this activity; will be null before {@link #onCreate(Bundle)}
* is called.
*/
@Override
public FlutterView getFlutterView() {
return viewProvider.getFlutterView();
}
/**
* Hook for subclasses to customize the creation of the {@code FlutterView}.
*
* <p>The default implementation returns {@code null}, which will cause the activity to use a
* newly instantiated full-screen view.
*/
@Override
public FlutterView createFlutterView(Context context) {
return null;
}
@Override
public FlutterNativeView createFlutterNativeView() {
return null;
}
@Override
public boolean retainFlutterNativeView() {
return false;
}
@Override
public final boolean hasPlugin(String key) {
return pluginRegistry.hasPlugin(key);
}
@Override
public final <T> T valuePublishedByPlugin(String pluginKey) {
return pluginRegistry.valuePublishedByPlugin(pluginKey);
}
@Override
public final Registrar registrarFor(String pluginKey) {
return pluginRegistry.registrarFor(pluginKey);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
eventDelegate.onCreate(savedInstanceState);
}
@Override
protected void onDestroy() {
eventDelegate.onDestroy();
super.onDestroy();
}
@Override
public void onBackPressed() {
if (!eventDelegate.onBackPressed()) {
super.onBackPressed();
}
}
@Override
protected void onStart() {
super.onStart();
eventDelegate.onStart();
}
@Override
protected void onStop() {
eventDelegate.onStop();
super.onStop();
}
@Override
protected void onPause() {
super.onPause();
eventDelegate.onPause();
}
@Override
protected void onPostResume() {
super.onPostResume();
eventDelegate.onPostResume();
}
@Override
public void onRequestPermissionsResult(
int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
eventDelegate.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!eventDelegate.onActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
eventDelegate.onNewIntent(intent);
}
@Override
public void onUserLeaveHint() {
eventDelegate.onUserLeaveHint();
}
@Override
public void onTrimMemory(int level) {
eventDelegate.onTrimMemory(level);
}
@Override
public void onLowMemory() {
eventDelegate.onLowMemory();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
eventDelegate.onConfigurationChanged(newConfig);
}
}

View File

@ -25,8 +25,7 @@ import io.flutter.view.TextureRegistry;
* <p>In v1 Android applications, an auto-generated and auto-updated plugin registrant class
* (GeneratedPluginRegistrant) makes use of a {@link PluginRegistry} to register contributions from
* each plugin mentioned in the application's pubspec file. The generated registrant class is, again
* by default, called from the application's main {@link android.app.Activity}, which defaults to an
* instance of {@link io.flutter.app.FlutterActivity}, itself a {@link PluginRegistry}.
* by default, called from the application's main {@link android.app.Activity}.
*/
public interface PluginRegistry {
/**
@ -82,9 +81,7 @@ public interface PluginRegistry {
* Returns the {@link android.app.Activity} that forms the plugin's operating context.
*
* <p>Plugin authors should not assume the type returned by this method is any specific subclass
* of {@code Activity} (such as {@link io.flutter.app.FlutterActivity} or {@link
* io.flutter.app.FlutterFragmentActivity}), as applications are free to use any activity
* subclass.
* of {@code Activity}, as applications are free to use any activity subclass.
*
* <p>When there is no foreground activity in the application, this will return null. If a
* {@link Context} is needed, use context() to get the application's context.

View File

@ -83,10 +83,10 @@ public class FlutterView extends SurfaceView
* Interface for those objects that maintain and expose a reference to a {@code FlutterView} (such
* as a full-screen Flutter activity).
*
* <p>This indirection is provided to support applications that use an activity other than {@link
* io.flutter.app.FlutterActivity} (e.g. Android v4 support library's {@code FragmentActivity}).
* It allows Flutter plugins to deal in this interface and not require that the activity be a
* subclass of {@code FlutterActivity}.
* <p>This indirection is provided to support applications that use an activity other than
* io.flutter.app.FlutterActivity (no longer available) (e.g. Android v4 support library's {@code
* FragmentActivity}). It allows Flutter plugins to deal in this interface and not require that
* the activity be a subclass of {@code FlutterActivity}.
*/
public interface Provider {
/**

View File

@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.flutter.app.test">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.flutter.embedding.test">
<application>

View File

@ -3,7 +3,6 @@
package="dev.flutter.android_background_image">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="io.flutter.app.FlutterApplication"
android:allowBackup="false"
android:label="Background Image Tester"
android:supportsRtl="true">

View File

@ -3,7 +3,6 @@
package="dev.flutter.scenarios">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="io.flutter.app.FlutterApplication"
android:allowBackup="false"
android:label="Scenarios App"
android:supportsRtl="true"

View File

@ -56,13 +56,8 @@
<src file="../../../flutter/shell/platform/android/test/io/flutter/view/VsyncWaiterTest.java" />
<src file="../../../flutter/shell/platform/android/test/io/flutter/FlutterInjectorTest.java" />
<src file="../../../flutter/shell/platform/android/test/io/flutter/external/FlutterLaunchTests.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/app/FlutterPlayStoreSplitApplication.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/app/FlutterFragmentActivity.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/app/FlutterActivity.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/app/FlutterActivityEvents.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/app/FlutterApplication.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/util/Preconditions.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/util/ViewUtils.java" />
<src file="../../../flutter/shell/platform/android/io/flutter/util/Predicate.java" />