Unverified Commit fa82b9ae authored by Matt Carroll's avatar Matt Carroll Committed by GitHub

Updated flutter/examples to further conform to new embedding: removed...

Updated flutter/examples to further conform to new embedding: removed references to FlutterApplication, deleted all MainActivity's that were not necessary, removed all direct invocations of GeneratedPluginRegistrant. (#22529) (#44782)

parent a220809f
...@@ -7,14 +7,8 @@ ...@@ -7,14 +7,8 @@
--> -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that <application android:label="animated_list" android:icon="@mipmap/ic_launcher">
calls FlutterMain.startInitialization(this); in its onCreate method. <activity android:name="io.flutter.embedding.android.FlutterActivity"
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application android:name="io.flutter.app.FlutterApplication" android:label="animated_list" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar" android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
......
package com.yourcompany.animated_list;
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
...@@ -12,14 +12,8 @@ ...@@ -12,14 +12,8 @@
--> -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that <application android:label="Gallery" android:icon="@mipmap/ic_launcher">
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application android:name="io.flutter.app.FlutterApplication" android:label="Gallery" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity" <activity android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Light.NoTitleBar" android:theme="@android:style/Theme.Light.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
......
...@@ -7,7 +7,6 @@ package io.flutter.demo.gallery; ...@@ -7,7 +7,6 @@ package io.flutter.demo.gallery;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity { public class MainActivity extends FlutterActivity {
private FlutterGalleryInstrumentation instrumentation; private FlutterGalleryInstrumentation instrumentation;
...@@ -19,7 +18,6 @@ public class MainActivity extends FlutterActivity { ...@@ -19,7 +18,6 @@ public class MainActivity extends FlutterActivity {
@Override @Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
instrumentation = new FlutterGalleryInstrumentation(flutterEngine.getDartExecutor()); instrumentation = new FlutterGalleryInstrumentation(flutterEngine.getDartExecutor());
} }
} }
...@@ -6,12 +6,7 @@ ...@@ -6,12 +6,7 @@
--> -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that <application android:label="flutter_view" android:icon="@mipmap/ic_launcher">
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application android:name="io.flutter.app.FlutterApplication" android:label="flutter_view" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity" <activity android:name=".MainActivity"
android:launchMode="singleTop" android:launchMode="singleTop"
android:theme="@style/Theme.AppCompat" android:theme="@style/Theme.AppCompat"
......
...@@ -7,16 +7,19 @@ import android.widget.TextView; ...@@ -7,16 +7,19 @@ import android.widget.TextView;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import io.flutter.embedding.android.FlutterView;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.dart.DartExecutor.DartEntrypoint;
import io.flutter.plugin.common.BasicMessageChannel; import io.flutter.plugin.common.BasicMessageChannel;
import io.flutter.plugin.common.BasicMessageChannel.MessageHandler; import io.flutter.plugin.common.BasicMessageChannel.MessageHandler;
import io.flutter.plugin.common.BasicMessageChannel.Reply; import io.flutter.plugin.common.BasicMessageChannel.Reply;
import io.flutter.plugin.common.StringCodec; import io.flutter.plugin.common.StringCodec;
import io.flutter.view.FlutterMain;
import io.flutter.view.FlutterRunArguments;
import io.flutter.view.FlutterView;
import java.util.ArrayList; import java.util.ArrayList;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
private static FlutterEngine flutterEngine;
private FlutterView flutterView; private FlutterView flutterView;
private int counter; private int counter;
private static final String CHANNEL = "increment"; private static final String CHANNEL = "increment";
...@@ -45,28 +48,27 @@ public class MainActivity extends AppCompatActivity { ...@@ -45,28 +48,27 @@ public class MainActivity extends AppCompatActivity {
return null; return null;
} }
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
String[] args = getArgsFromIntent(getIntent()); String[] args = getArgsFromIntent(getIntent());
FlutterMain.ensureInitializationComplete(getApplicationContext(), args); if (flutterEngine == null) {
flutterEngine = new FlutterEngine(this, args);
flutterEngine.getDartExecutor().executeDartEntrypoint(
DartEntrypoint.createDefault()
);
}
setContentView(R.layout.flutter_view_layout); setContentView(R.layout.flutter_view_layout);
ActionBar supportActionBar = getSupportActionBar(); ActionBar supportActionBar = getSupportActionBar();
if (supportActionBar != null) { if (supportActionBar != null) {
supportActionBar.hide(); supportActionBar.hide();
} }
FlutterRunArguments runArguments = new FlutterRunArguments();
runArguments.bundlePath = FlutterMain.findAppBundlePath(getApplicationContext());
runArguments.entrypoint = "main";
flutterView = findViewById(R.id.flutter_view); flutterView = findViewById(R.id.flutter_view);
flutterView.runFromBundle(runArguments); flutterView.attachToFlutterEngine(flutterEngine);
messageChannel = new BasicMessageChannel<>(flutterView, CHANNEL, StringCodec.INSTANCE); messageChannel = new BasicMessageChannel<>(flutterEngine.getDartExecutor(), CHANNEL, StringCodec.INSTANCE);
messageChannel. messageChannel.
setMessageHandler(new MessageHandler<String>() { setMessageHandler(new MessageHandler<String>() {
@Override @Override
...@@ -97,22 +99,26 @@ public class MainActivity extends AppCompatActivity { ...@@ -97,22 +99,26 @@ public class MainActivity extends AppCompatActivity {
} }
@Override @Override
protected void onDestroy() { protected void onResume() {
if (flutterView != null) { super.onResume();
flutterView.destroy(); flutterEngine.getLifecycleChannel().appIsResumed();
}
super.onDestroy();
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
flutterView.onPause(); flutterEngine.getLifecycleChannel().appIsInactive();
}
@Override
protected void onStop() {
super.onStop();
flutterEngine.getLifecycleChannel().appIsPaused();
} }
@Override @Override
protected void onPostResume() { protected void onDestroy() {
super.onPostResume(); flutterView.detachFromFlutterEngine();
flutterView.onPostResume(); super.onDestroy();
} }
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
> >
<io.flutter.view.FlutterView <io.flutter.embedding.android.FlutterView
android:id="@+id/flutter_view" android:id="@+id/flutter_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
......
...@@ -12,14 +12,8 @@ ...@@ -12,14 +12,8 @@
--> -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that <application android:label="hello_world" android:icon="@mipmap/ic_launcher">
calls FlutterMain.startInitialization(this); in its onCreate method. <activity android:name="io.flutter.embedding.android.FlutterActivity"
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application android:name="io.flutter.app.FlutterApplication" android:label="hello_world" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar" android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
......
package io.flutter.examples.hello_world;
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.image_list"> package="com.example.image_list">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<application <application
android:name="io.flutter.app.FlutterApplication"
android:label="image_list" android:label="image_list"
android:icon="@mipmap/ic_launcher"> android:icon="@mipmap/ic_launcher">
<activity <activity
android:name=".MainActivity" android:name="io.flutter.embedding.android.FlutterActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme" android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
......
package com.example.image_list;
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
...@@ -7,14 +7,8 @@ ...@@ -7,14 +7,8 @@
--> -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that <application android:label="Flutter Layers" android:icon="@mipmap/ic_launcher">
calls FlutterMain.startInitialization(this); in its onCreate method. <activity android:name="io.flutter.embedding.android.FlutterActivity"
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application android:name="io.flutter.app.FlutterApplication" android:label="Flutter Layers" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar" android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
......
// Copyright 2017 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.
package io.flutter.examples.Layers;
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application android:name="io.flutter.app.FlutterApplication" android:label="@string/app_name"> <application android:label="@string/app_name">
<activity android:name=".MainActivity" <activity android:name=".MainActivity"
android:launchMode="singleTop" android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar" android:theme="@android:style/Theme.Black.NoTitleBar"
......
...@@ -31,8 +31,6 @@ public class MainActivity extends FlutterActivity { ...@@ -31,8 +31,6 @@ public class MainActivity extends FlutterActivity {
@Override @Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
new EventChannel(flutterEngine.getDartExecutor(), CHARGING_CHANNEL).setStreamHandler( new EventChannel(flutterEngine.getDartExecutor(), CHARGING_CHANNEL).setStreamHandler(
new StreamHandler() { new StreamHandler() {
private BroadcastReceiver chargingStateChangeReceiver; private BroadcastReceiver chargingStateChangeReceiver;
......
...@@ -7,18 +7,11 @@ ...@@ -7,18 +7,11 @@
--> -->
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application <application
android:name="io.flutter.app.FlutterApplication"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="platform_view"> android:label="platform_view">
<activity <activity
android:name="io.flutter.examples.platform_view.MainActivity" android:name="io.flutter.examples.platform_view.MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar" android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
......
...@@ -21,8 +21,6 @@ public class MainActivity extends FlutterActivity { ...@@ -21,8 +21,6 @@ public class MainActivity extends FlutterActivity {
@Override @Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
new MethodChannel(flutterEngine.getDartExecutor(), CHANNEL).setMethodCallHandler( new MethodChannel(flutterEngine.getDartExecutor(), CHANNEL).setMethodCallHandler(
new MethodChannel.MethodCallHandler() { new MethodChannel.MethodCallHandler() {
@Override @Override
......
...@@ -12,14 +12,8 @@ ...@@ -12,14 +12,8 @@
--> -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that <application android:label="Stocks" android:icon="@mipmap/ic_launcher">
calls FlutterMain.startInitialization(this); in its onCreate method. <activity android:name="io.flutter.embedding.android.FlutterActivity"
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application android:name="io.flutter.app.FlutterApplication" android:label="Stocks" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar" android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
......
// Copyright 2017 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.
package io.flutter.examples.stocks;
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment