|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +package io.flutter.app; |
| 6 | + |
| 7 | +import android.app.Activity; |
| 8 | +import android.content.Context; |
| 9 | +import android.content.Intent; |
| 10 | +import android.content.res.Configuration; |
| 11 | +import android.os.Bundle; |
| 12 | +import androidx.annotation.NonNull; |
| 13 | +import io.flutter.app.FlutterActivityDelegate.ViewFactory; |
| 14 | +import io.flutter.plugin.common.PluginRegistry; |
| 15 | +import io.flutter.view.FlutterNativeView; |
| 16 | +import io.flutter.view.FlutterView; |
| 17 | + |
| 18 | +/** |
| 19 | + * Deprecated base class for activities that use Flutter. |
| 20 | + * |
| 21 | + * @deprecated {@link io.flutter.embedding.android.FlutterActivity} is the new API that now replaces |
| 22 | + * this class. See https://flutter.dev/go/android-project-migration for more migration details. |
| 23 | + */ |
| 24 | +@Deprecated |
| 25 | +public class FlutterActivity extends Activity |
| 26 | + implements FlutterView.Provider, PluginRegistry, ViewFactory { |
| 27 | + private static final String TAG = "FlutterActivity"; |
| 28 | + |
| 29 | + private final FlutterActivityDelegate delegate = new FlutterActivityDelegate(this, this); |
| 30 | + |
| 31 | + // These aliases ensure that the methods we forward to the delegate adhere |
| 32 | + // to relevant interfaces versus just existing in FlutterActivityDelegate. |
| 33 | + private final FlutterActivityEvents eventDelegate = delegate; |
| 34 | + private final FlutterView.Provider viewProvider = delegate; |
| 35 | + private final PluginRegistry pluginRegistry = delegate; |
| 36 | + |
| 37 | + /** |
| 38 | + * Returns the Flutter view used by this activity; will be null before {@link #onCreate(Bundle)} |
| 39 | + * is called. |
| 40 | + */ |
| 41 | + @Override |
| 42 | + public FlutterView getFlutterView() { |
| 43 | + return viewProvider.getFlutterView(); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Hook for subclasses to customize the creation of the {@code FlutterView}. |
| 48 | + * |
| 49 | + * <p>The default implementation returns {@code null}, which will cause the activity to use a |
| 50 | + * newly instantiated full-screen view. |
| 51 | + */ |
| 52 | + @Override |
| 53 | + public FlutterView createFlutterView(Context context) { |
| 54 | + return null; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Hook for subclasses to customize the creation of the {@code FlutterNativeView}. |
| 59 | + * |
| 60 | + * <p>The default implementation returns {@code null}, which will cause the activity to use a |
| 61 | + * newly instantiated native view object. |
| 62 | + */ |
| 63 | + @Override |
| 64 | + public FlutterNativeView createFlutterNativeView() { |
| 65 | + return null; |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public boolean retainFlutterNativeView() { |
| 70 | + return false; |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public final boolean hasPlugin(String key) { |
| 75 | + return pluginRegistry.hasPlugin(key); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public final <T> T valuePublishedByPlugin(String pluginKey) { |
| 80 | + return pluginRegistry.valuePublishedByPlugin(pluginKey); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public final Registrar registrarFor(String pluginKey) { |
| 85 | + return pluginRegistry.registrarFor(pluginKey); |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + protected void onCreate(Bundle savedInstanceState) { |
| 90 | + super.onCreate(savedInstanceState); |
| 91 | + eventDelegate.onCreate(savedInstanceState); |
| 92 | + } |
| 93 | + |
| 94 | + @Override |
| 95 | + protected void onStart() { |
| 96 | + super.onStart(); |
| 97 | + eventDelegate.onStart(); |
| 98 | + } |
| 99 | + |
| 100 | + @Override |
| 101 | + protected void onResume() { |
| 102 | + super.onResume(); |
| 103 | + eventDelegate.onResume(); |
| 104 | + } |
| 105 | + |
| 106 | + @Override |
| 107 | + protected void onDestroy() { |
| 108 | + eventDelegate.onDestroy(); |
| 109 | + super.onDestroy(); |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + public void onBackPressed() { |
| 114 | + if (!eventDelegate.onBackPressed()) { |
| 115 | + super.onBackPressed(); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + @Override |
| 120 | + protected void onStop() { |
| 121 | + eventDelegate.onStop(); |
| 122 | + super.onStop(); |
| 123 | + } |
| 124 | + |
| 125 | + @Override |
| 126 | + protected void onPause() { |
| 127 | + super.onPause(); |
| 128 | + eventDelegate.onPause(); |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + protected void onPostResume() { |
| 133 | + super.onPostResume(); |
| 134 | + eventDelegate.onPostResume(); |
| 135 | + } |
| 136 | + |
| 137 | + // @Override - added in API level 23 |
| 138 | + public void onRequestPermissionsResult( |
| 139 | + int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
| 140 | + eventDelegate.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 145 | + if (!eventDelegate.onActivityResult(requestCode, resultCode, data)) { |
| 146 | + super.onActivityResult(requestCode, resultCode, data); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + @Override |
| 151 | + protected void onNewIntent(Intent intent) { |
| 152 | + eventDelegate.onNewIntent(intent); |
| 153 | + } |
| 154 | + |
| 155 | + @Override |
| 156 | + public void onUserLeaveHint() { |
| 157 | + eventDelegate.onUserLeaveHint(); |
| 158 | + } |
| 159 | + |
| 160 | + @Override |
| 161 | + public void onTrimMemory(int level) { |
| 162 | + eventDelegate.onTrimMemory(level); |
| 163 | + } |
| 164 | + |
| 165 | + @Override |
| 166 | + public void onLowMemory() { |
| 167 | + eventDelegate.onLowMemory(); |
| 168 | + } |
| 169 | + |
| 170 | + @Override |
| 171 | + public void onConfigurationChanged(Configuration newConfig) { |
| 172 | + super.onConfigurationChanged(newConfig); |
| 173 | + eventDelegate.onConfigurationChanged(newConfig); |
| 174 | + } |
| 175 | +} |
0 commit comments