Commit 7e30fa0b authored by yangwu.jia's avatar yangwu.jia

boost1.9升级

parent 6afc509d
......@@ -39,6 +39,7 @@ dependencies {
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'android.arch.lifecycle:common-java8:1.1.1'
implementation 'com.alibaba:fastjson:1.2.41'
}
......
......@@ -35,14 +35,14 @@ import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import com.alibaba.fastjson.JSON;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
public class Utils {
......@@ -289,4 +289,55 @@ public class Utils {
}
}
public static String assembleUrl(String url,Map<String, Object> urlParams){
StringBuilder targetUrl = new StringBuilder(url);
if(urlParams != null && !urlParams.isEmpty()) {
if(!targetUrl.toString().contains("?")){
targetUrl.append("?");
}
for(Map.Entry entry:urlParams.entrySet()) {
if(entry.getValue() instanceof Map ) {
Map<String,Object> params = (Map<String,Object> )entry.getValue();
for(Map.Entry param:params.entrySet()) {
String key = (String)param.getKey();
String value = null;
if(param.getValue() instanceof Map || param.getValue() instanceof List) {
try {
value = URLEncoder.encode(JSON.toJSONString(param.getValue()), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}else{
value = (param.getValue()==null?null:URLEncoder.encode( String.valueOf(param.getValue())));
}
if(value==null){
continue;
}
if(targetUrl.toString().endsWith("?")){
targetUrl.append(key).append("=").append(value);
}else{
targetUrl.append("&").append(key).append("=").append(value);
}
}
}
}
}
return targetUrl.toString();
}
}
\ No newline at end of file
......@@ -7,7 +7,6 @@ import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
......@@ -16,7 +15,6 @@ import android.view.ViewGroup;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
......@@ -27,9 +25,7 @@ import io.flutter.Log;
import io.flutter.app.FlutterActivity;
import io.flutter.embedding.android.*;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener;
import io.flutter.plugin.platform.PlatformPlugin;
import io.flutter.view.FlutterMain;
......@@ -157,7 +153,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
// Our host did not provide a custom FlutterEngine. Create a FlutterEngine to back our
// FlutterView.
Log.d(TAG, "No preferred FlutterEngine was provided. Creating a new FlutterEngine for"
+ " this FlutterFragment.");
+ " this NewFlutterFragment.");
flutterEngine = new FlutterEngine(host.getContext());
isFlutterEngineFromHost = false;
}
......@@ -224,7 +220,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
platformPlugin.updateSystemUiOverlays();
}
} else {
Log.w(TAG, "onPostResume() invoked before FlutterFragment was attached to an Activity.");
Log.w(TAG, "onPostResume() invoked before NewFlutterFragment was attached to an Activity.");
}
}
......@@ -296,7 +292,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
// Log.v(TAG, "Forwarding onBackPressed() to FlutterEngine.");
// flutterEngine.getNavigationChannel().popRoute();
// } else {
// Log.w(TAG, "Invoked onBackPressed() before FlutterFragment was attached to an Activity.");
// Log.w(TAG, "Invoked onBackPressed() before NewFlutterFragment was attached to an Activity.");
// }
}
......@@ -312,7 +308,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
+ "grantResults: " + Arrays.toString(grantResults));
flutterEngine.getActivityControlSurface().onRequestPermissionsResult(requestCode, permissions, grantResults);
} else {
Log.w(TAG, "onRequestPermissionResult() invoked before FlutterFragment was attached to an Activity.");
Log.w(TAG, "onRequestPermissionResult() invoked before NewFlutterFragment was attached to an Activity.");
}
}
......@@ -325,7 +321,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
Log.v(TAG, "Forwarding onNewIntent() to FlutterEngine.");
flutterEngine.getActivityControlSurface().onNewIntent(intent);
} else {
Log.w(TAG, "onNewIntent() invoked before FlutterFragment was attached to an Activity.");
Log.w(TAG, "onNewIntent() invoked before NewFlutterFragment was attached to an Activity.");
}
}
......@@ -351,7 +347,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
+ "data: " + data);
flutterEngine.getActivityControlSurface().onActivityResult(requestCode, resultCode, data);
} else {
Log.w(TAG, "onActivityResult() invoked before FlutterFragment was attached to an Activity.");
Log.w(TAG, "onActivityResult() invoked before NewFlutterFragment was attached to an Activity.");
}
}
......@@ -362,7 +358,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
Log.v(TAG, "Forwarding onUserLeaveHint() to FlutterEngine.");
flutterEngine.getActivityControlSurface().onUserLeaveHint();
} else {
Log.w(TAG, "onUserLeaveHint() invoked before FlutterFragment was attached to an Activity.");
Log.w(TAG, "onUserLeaveHint() invoked before NewFlutterFragment was attached to an Activity.");
}
}
......@@ -379,7 +375,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
flutterEngine.getSystemChannel().sendMemoryPressureWarning();
}
} else {
Log.w(TAG, "onTrimMemory() invoked before FlutterFragment was attached to an Activity.");
Log.w(TAG, "onTrimMemory() invoked before NewFlutterFragment was attached to an Activity.");
}
}
......@@ -440,7 +436,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
}
/**
* The {@link FlutterActivity} or {@link FlutterFragment} that owns this
* The {@link FlutterActivity} or {@link NewFlutterFragment} that owns this
* {@code FlutterActivityAndFragmentDelegate}.
*/
/* package */ interface Host extends SplashScreenProvider, FlutterEngineProvider, FlutterEngineConfigurator {
......@@ -469,42 +465,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
@NonNull
FlutterShellArgs getFlutterShellArgs();
/**
* Returns the ID of a statically cached {@link FlutterEngine} to use within this
* delegate's host, or {@code null} if this delegate's host does not want to
* use a cached {@link FlutterEngine}.
*/
@Nullable
String getCachedEngineId();
/**
* Returns true if the {@link FlutterEngine} used in this delegate should be destroyed
* when the host/delegate are destroyed.
* <p>
* The default value is {@code true} in cases where {@code FlutterFragment} created its own
* {@link FlutterEngine}, and {@code false} in cases where a cached {@link FlutterEngine} was
* provided.
*/
boolean shouldDestroyEngineWithHost();
/**
* Returns the Dart entrypoint that should run when a new {@link FlutterEngine} is
* created.
*/
@NonNull
String getDartEntrypointFunctionName();
/**
* Returns the path to the app bundle where the Dart code exists.
*/
@NonNull
String getAppBundlePath();
/**
* Returns the initial route that Flutter renders.
*/
@Nullable
String getInitialRoute();
/**
* Returns the {@link FlutterView.RenderMode} used by the {@link FlutterView} that
......
......@@ -41,21 +41,19 @@ public class NewBoostFlutterActivity extends Activity
private static final String TAG = "NewBoostFlutterActivity";
// Meta-data arguments, processed from manifest XML.
protected static final String DART_ENTRYPOINT_META_DATA_KEY = "io.flutter.Entrypoint";
protected static final String INITIAL_ROUTE_META_DATA_KEY = "io.flutter.InitialRoute";
protected static final String SPLASH_SCREEN_META_DATA_KEY = "io.flutter.embedding.android.SplashScreenDrawable";
protected static final String NORMAL_THEME_META_DATA_KEY = "io.flutter.embedding.android.NormalTheme";
// Intent extra arguments.
protected static final String EXTRA_DART_ENTRYPOINT = "dart_entrypoint";
protected static final String EXTRA_INITIAL_ROUTE = "initial_route";
protected static final String EXTRA_BACKGROUND_MODE = "background_mode";
protected static final String EXTRA_CACHED_ENGINE_ID = "cached_engine_id";
protected static final String EXTRA_DESTROY_ENGINE_WITH_ACTIVITY = "destroy_engine_with_activity";
protected static final String EXTRA_URL = "url";
protected static final String EXTRA_PARAMS = "params";
// Default configuration.
protected static final String DEFAULT_DART_ENTRYPOINT = "main";
protected static final String DEFAULT_INITIAL_ROUTE = "/";
protected static final String DEFAULT_BACKGROUND_MODE = BackgroundMode.opaque.name();
......@@ -71,11 +69,9 @@ public class NewBoostFlutterActivity extends Activity
public static class NewEngineIntentBuilder {
private final Class<? extends NewBoostFlutterActivity> activityClass;
private String dartEntrypoint = DEFAULT_DART_ENTRYPOINT;
private String initialRoute = DEFAULT_INITIAL_ROUTE;
private String backgroundMode = DEFAULT_BACKGROUND_MODE;
private String url = "";
private Map params = null;
private HashMap params = new HashMap();
......@@ -84,10 +80,7 @@ public class NewBoostFlutterActivity extends Activity
}
public NewEngineIntentBuilder dartEntrypoint(@NonNull String dartEntrypoint) {
this.dartEntrypoint = dartEntrypoint;
return this;
}
public NewEngineIntentBuilder url (@NonNull String url) {
this.url = url;
......@@ -95,15 +88,11 @@ public class NewBoostFlutterActivity extends Activity
}
public NewEngineIntentBuilder params (@NonNull Map params) {
public NewEngineIntentBuilder params (@NonNull HashMap params) {
this.params = params;
return this;
}
public NewEngineIntentBuilder initialRoute(@NonNull String initialRoute) {
this.initialRoute = initialRoute;
return this;
}
public NewEngineIntentBuilder backgroundMode(@NonNull BackgroundMode backgroundMode) {
......@@ -114,12 +103,10 @@ public class NewBoostFlutterActivity extends Activity
public Intent build(@NonNull Context context) {
return new Intent(context, activityClass)
.putExtra(EXTRA_DART_ENTRYPOINT, dartEntrypoint)
.putExtra(EXTRA_INITIAL_ROUTE, initialRoute)
.putExtra(EXTRA_BACKGROUND_MODE, backgroundMode)
.putExtra(EXTRA_DESTROY_ENGINE_WITH_ACTIVITY, false)
.putExtra("url", url)
.putExtra("params", (HashMap)params);
.putExtra(EXTRA_URL, url)
.putExtra(EXTRA_PARAMS, (HashMap)params);
}
}
......@@ -365,129 +352,7 @@ public class NewBoostFlutterActivity extends Activity
return FlutterShellArgs.fromIntent(getIntent());
}
/**
* Returns the ID of a statically cached {@link FlutterEngine} to use within this
* {@code FlutterActivity}, or {@code null} if this {@code FlutterActivity} does not want to
* use a cached {@link FlutterEngine}.
*/
@Override
@Nullable
public String getCachedEngineId() {
return getIntent().getStringExtra(EXTRA_CACHED_ENGINE_ID);
}
/**
* Returns false if the {@link FlutterEngine} backing this {@code FlutterActivity} should
* outlive this {@code FlutterActivity}, or true to be destroyed when the {@code FlutterActivity}
* is destroyed.
* <p>
* The default value is {@code true} in cases where {@code FlutterActivity} created its own
* {@link FlutterEngine}, and {@code false} in cases where a cached {@link FlutterEngine} was
* provided.
*/
@Override
public boolean shouldDestroyEngineWithHost() {
return getIntent().getBooleanExtra(EXTRA_DESTROY_ENGINE_WITH_ACTIVITY, false);
}
/**
* The Dart entrypoint that will be executed as soon as the Dart snapshot is loaded.
* <p>
* This preference can be controlled with 2 methods:
* <ol>
* <li>Pass a {@code String} as {@link #EXTRA_DART_ENTRYPOINT} with the launching {@code Intent}, or</li>
* <li>Set a {@code <meta-data>} called {@link #DART_ENTRYPOINT_META_DATA_KEY} for this
* {@code Activity} in the Android manifest.</li>
* </ol>
* If both preferences are set, the {@code Intent} preference takes priority.
* <p>
* The reason that a {@code <meta-data>} preference is supported is because this {@code Activity}
* might be the very first {@code Activity} launched, which means the developer won't have
* control over the incoming {@code Intent}.
* <p>
* Subclasses may override this method to directly control the Dart entrypoint.
*/
@NonNull
public String getDartEntrypointFunctionName() {
if (getIntent().hasExtra(EXTRA_DART_ENTRYPOINT)) {
return getIntent().getStringExtra(EXTRA_DART_ENTRYPOINT);
}
try {
ActivityInfo activityInfo = getPackageManager().getActivityInfo(
getComponentName(),
PackageManager.GET_META_DATA | PackageManager.GET_ACTIVITIES
);
Bundle metadata = activityInfo.metaData;
String desiredDartEntrypoint = metadata != null ? metadata.getString(DART_ENTRYPOINT_META_DATA_KEY) : null;
return desiredDartEntrypoint != null ? desiredDartEntrypoint : DEFAULT_DART_ENTRYPOINT;
} catch (PackageManager.NameNotFoundException e) {
return DEFAULT_DART_ENTRYPOINT;
}
}
/**
* The initial route that a Flutter app will render upon loading and executing its Dart code.
* <p>
* This preference can be controlled with 2 methods:
* <ol>
* <li>Pass a boolean as {@link #EXTRA_INITIAL_ROUTE} with the launching {@code Intent}, or</li>
* <li>Set a {@code <meta-data>} called {@link #INITIAL_ROUTE_META_DATA_KEY} for this
* {@code Activity} in the Android manifest.</li>
* </ol>
* If both preferences are set, the {@code Intent} preference takes priority.
* <p>
* The reason that a {@code <meta-data>} preference is supported is because this {@code Activity}
* might be the very first {@code Activity} launched, which means the developer won't have
* control over the incoming {@code Intent}.
* <p>
* Subclasses may override this method to directly control the initial route.
*/
@NonNull
public String getInitialRoute() {
if (getIntent().hasExtra(EXTRA_INITIAL_ROUTE)) {
return getIntent().getStringExtra(EXTRA_INITIAL_ROUTE);
}
try {
ActivityInfo activityInfo = getPackageManager().getActivityInfo(
getComponentName(),
PackageManager.GET_META_DATA | PackageManager.GET_ACTIVITIES
);
Bundle metadata = activityInfo.metaData;
String desiredInitialRoute = metadata != null ? metadata.getString(INITIAL_ROUTE_META_DATA_KEY) : null;
return desiredInitialRoute != null ? desiredInitialRoute : DEFAULT_INITIAL_ROUTE;
} catch (PackageManager.NameNotFoundException e) {
return DEFAULT_INITIAL_ROUTE;
}
}
/**
* The path to the bundle that contains this Flutter app's resources, e.g., Dart code snapshots.
* <p>
* When this {@code FlutterActivity} is run by Flutter tooling and a data String is included
* in the launching {@code Intent}, that data String is interpreted as an app bundle path.
* <p>
* By default, the app bundle path is obtained from {@link FlutterMain#findAppBundlePath()}.
* <p>
* Subclasses may override this method to return a custom app bundle path.
*/
@NonNull
public String getAppBundlePath() {
// If this Activity was launched from tooling, and the incoming Intent contains
// a custom app bundle path, return that path.
// TODO(mattcarroll): determine if we should have an explicit FlutterTestActivity instead of conflating.
if (isDebuggable() && Intent.ACTION_RUN.equals(getIntent().getAction())) {
String appBundlePath = getIntent().getDataString();
if (appBundlePath != null) {
return appBundlePath;
}
}
// Return the default app bundle path.
// TODO(mattcarroll): move app bundle resolution into an appropriately named class.
return FlutterMain.findAppBundlePath();
}
/**
* Returns true if Flutter is running in "debug mode", and false otherwise.
......@@ -600,13 +465,22 @@ public class NewBoostFlutterActivity extends Activity
@Override
public String getContainerUrl() {
return "flutterPage";
if (getIntent().hasExtra(EXTRA_URL)) {
return getIntent().getStringExtra(EXTRA_URL);
}
return "";
}
@Override
public Map getContainerUrlParams() {
if (getIntent().hasExtra(EXTRA_PARAMS)) {
return (Map) getIntent().getSerializableExtra(EXTRA_PARAMS);
}
Map<String,String> params = new HashMap<>();
params.put("aaa","bbb");
return params;
}
......
......@@ -26,9 +26,9 @@ import java.util.HashMap;
import java.util.Map;
public class FlutterFragment extends Fragment implements FlutterActivityAndFragmentDelegate.Host {
public class NewFlutterFragment extends Fragment implements FlutterActivityAndFragmentDelegate.Host {
private static final String TAG = "FlutterFragment";
private static final String TAG = "NewFlutterFragment";
/**
* The Dart entrypoint method name that is executed upon initialization.
......@@ -48,12 +48,12 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
protected static final String ARG_FLUTTER_INITIALIZATION_ARGS = "initialization_args";
/**
* {@link FlutterView.RenderMode} to be used for the {@link FlutterView} in this
* {@code FlutterFragment}
* {@code NewFlutterFragment}
*/
protected static final String ARG_FLUTTERVIEW_RENDER_MODE = "flutterview_render_mode";
/**
* {@link FlutterView.TransparencyMode} to be used for the {@link FlutterView} in this
* {@code FlutterFragment}
* {@code NewFlutterFragment}
*/
protected static final String ARG_FLUTTERVIEW_TRANSPARENCY_MODE = "flutterview_transparency_mode";
/**
......@@ -61,21 +61,26 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
*/
protected static final String ARG_SHOULD_ATTACH_ENGINE_TO_ACTIVITY = "should_attach_engine_to_activity";
/**
* the created {@code FlutterFragment}.
* the created {@code NewFlutterFragment}.
*/
protected static final String ARG_CACHED_ENGINE_ID = "cached_engine_id";
/**
* True if the {@link FlutterEngine} in the created {@code FlutterFragment} should be destroyed
* when the {@code FlutterFragment} is destroyed, false if the {@link FlutterEngine} should
* outlive the {@code FlutterFragment}.
* True if the {@link FlutterEngine} in the created {@code NewFlutterFragment} should be destroyed
* when the {@code NewFlutterFragment} is destroyed, false if the {@link FlutterEngine} should
* outlive the {@code NewFlutterFragment}.
*/
protected static final String ARG_DESTROY_ENGINE_WITH_FRAGMENT = "destroy_engine_with_fragment";
protected static final String EXTRA_URL = "url";
protected static final String EXTRA_PARAMS = "params";
/**
* Creates a {@code FlutterFragment} with a default configuration.
* Creates a {@code NewFlutterFragment} with a default configuration.
* <p>
* {@code FlutterFragment}'s default configuration creates a new {@link FlutterEngine} within
* the {@code FlutterFragment} and uses the following settings:
* {@code NewFlutterFragment}'s default configuration creates a new {@link FlutterEngine} within
* the {@code NewFlutterFragment} and uses the following settings:
* <ul>
* <li>Dart entrypoint: "main"</li>
* <li>Initial route: "/"</li>
......@@ -88,12 +93,12 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
* To use a cached {@link FlutterEngine} instead of creating a new one, use
*/
@NonNull
public static FlutterFragment createDefault() {
public static NewFlutterFragment createDefault() {
return new NewEngineFragmentBuilder().build();
}
/**
* Returns a {@link NewEngineFragmentBuilder} to create a {@code FlutterFragment} with a new
* Returns a {@link NewEngineFragmentBuilder} to create a {@code NewFlutterFragment} with a new
* {@link FlutterEngine} and a desired engine configuration.
*/
@NonNull
......@@ -101,101 +106,33 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
return new NewEngineFragmentBuilder();
}
/**
* Builder that creates a new {@code FlutterFragment} with {@code arguments} that correspond
* to the values set on this {@code NewEngineFragmentBuilder}.
* <p>
* To create a {@code FlutterFragment} with default {@code arguments}, invoke
* {@link #createDefault()}.
* <p>
* Subclasses of {@code FlutterFragment} that do not introduce any new arguments can use this
* {@code NewEngineFragmentBuilder} to construct instances of the subclass without subclassing
* this {@code NewEngineFragmentBuilder}.
* {@code
* MyFlutterFragment f = new FlutterFragment.NewEngineFragmentBuilder(MyFlutterFragment.class)
* .someProperty(...)
* .someOtherProperty(...)
* .build<MyFlutterFragment>();
* }
* <p>
* Subclasses of {@code FlutterFragment} that introduce new arguments should subclass this
* {@code NewEngineFragmentBuilder} to add the new properties:
* <ol>
* <li>Ensure the {@code FlutterFragment} subclass has a no-arg constructor.</li>
* <li>Subclass this {@code NewEngineFragmentBuilder}.</li>
* <li>Override the new {@code NewEngineFragmentBuilder}'s no-arg constructor and invoke the
* super constructor to set the {@code FlutterFragment} subclass: {@code
* public MyBuilder() {
* super(MyFlutterFragment.class);
* }
* }</li>
* <li>Add appropriate property methods for the new properties.</li>
* <li>Override {@link NewEngineFragmentBuilder#createArgs()}, call through to the super method,
* then add the new properties as arguments in the {@link Bundle}.</li>
* </ol>
* Once a {@code NewEngineFragmentBuilder} subclass is defined, the {@code FlutterFragment}
* subclass can be instantiated as follows.
* {@code
* MyFlutterFragment f = new MyBuilder()
* .someExistingProperty(...)
* .someNewProperty(...)
* .build<MyFlutterFragment>();
* }
*/
public static class NewEngineFragmentBuilder {
private final Class<? extends FlutterFragment> fragmentClass;
private String dartEntrypoint = "main";
private String initialRoute = "/";
private String appBundlePath = null;
private final Class<? extends NewFlutterFragment> fragmentClass;
private FlutterShellArgs shellArgs = null;
private FlutterView.RenderMode renderMode = FlutterView.RenderMode.surface;
private FlutterView.TransparencyMode transparencyMode = FlutterView.TransparencyMode.transparent;
private boolean shouldAttachEngineToActivity = true;
private String url = "";
private HashMap params = new HashMap();
/**
* Constructs a {@code NewEngineFragmentBuilder} that is configured to construct an instance of
* {@code FlutterFragment}.
* {@code NewFlutterFragment}.
*/
public NewEngineFragmentBuilder() {
fragmentClass = FlutterFragment.class;
fragmentClass = NewFlutterFragment.class;
}
/**
* Constructs a {@code NewEngineFragmentBuilder} that is configured to construct an instance of
* {@code subclass}, which extends {@code FlutterFragment}.
* {@code subclass}, which extends {@code NewFlutterFragment}.
*/
public NewEngineFragmentBuilder(@NonNull Class<? extends FlutterFragment> subclass) {
public NewEngineFragmentBuilder(@NonNull Class<? extends NewFlutterFragment> subclass) {
fragmentClass = subclass;
}
/**
* The name of the initial Dart method to invoke, defaults to "main".
*/
@NonNull
public NewEngineFragmentBuilder dartEntrypoint(@NonNull String dartEntrypoint) {
this.dartEntrypoint = dartEntrypoint;
return this;
}
/**
* The initial route that a Flutter app will render in this {@link FlutterFragment},
* defaults to "/".
*/
@NonNull
public NewEngineFragmentBuilder initialRoute(@NonNull String initialRoute) {
this.initialRoute = initialRoute;
return this;
}
/**
* The path to the app bundle which contains the Dart app to execute, defaults
* to {@link FlutterMain#findAppBundlePath()}
*/
@NonNull
public NewEngineFragmentBuilder appBundlePath(@NonNull String appBundlePath) {
this.appBundlePath = appBundlePath;
return this;
}
/**
* Any special configuration arguments for the Flutter engine
......@@ -219,7 +156,16 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
this.renderMode = renderMode;
return this;
}
public NewEngineFragmentBuilder url (@NonNull String url) {
this.url = url;
return this;
}
public NewEngineFragmentBuilder params (@NonNull HashMap params) {
this.params = params;
return this;
}
/**
* Support a {@link FlutterView.TransparencyMode#transparent} background within {@link FlutterView},
* or force an {@link FlutterView.TransparencyMode#opaque} background.
......@@ -233,41 +179,34 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
}
@NonNull
public NewEngineFragmentBuilder shouldAttachEngineToActivity(boolean shouldAttachEngineToActivity) {
this.shouldAttachEngineToActivity = shouldAttachEngineToActivity;
return this;
}
@NonNull
protected Bundle createArgs() {
Bundle args = new Bundle();
args.putString(ARG_INITIAL_ROUTE, initialRoute);
args.putString(ARG_APP_BUNDLE_PATH, appBundlePath);
args.putString(ARG_DART_ENTRYPOINT, dartEntrypoint);
// TODO(mattcarroll): determine if we should have an explicit FlutterTestFragment instead of conflating.
if (null != shellArgs) {
args.putStringArray(ARG_FLUTTER_INITIALIZATION_ARGS, shellArgs.toArray());
}
args.putString(EXTRA_URL, url);
args.putSerializable(EXTRA_PARAMS, (HashMap)params);
args.putString(ARG_FLUTTERVIEW_RENDER_MODE, renderMode != null ? renderMode.name() : FlutterView.RenderMode.surface.name());
args.putString(ARG_FLUTTERVIEW_TRANSPARENCY_MODE, transparencyMode != null ? transparencyMode.name() : FlutterView.TransparencyMode.transparent.name());
args.putBoolean(ARG_SHOULD_ATTACH_ENGINE_TO_ACTIVITY, shouldAttachEngineToActivity);
args.putBoolean(ARG_DESTROY_ENGINE_WITH_FRAGMENT, true);
return args;
}
/**
* Constructs a new {@code FlutterFragment} (or a subclass) that is configured based on
* Constructs a new {@code NewFlutterFragment} (or a subclass) that is configured based on
* properties set on this {@code Builder}.
*/
@NonNull
public <T extends FlutterFragment> T build() {
public <T extends NewFlutterFragment> T build() {
try {
@SuppressWarnings("unchecked")
T frag = (T) fragmentClass.getDeclaredConstructor().newInstance();
if (frag == null) {
throw new RuntimeException("The FlutterFragment subclass sent in the constructor ("
throw new RuntimeException("The NewFlutterFragment subclass sent in the constructor ("
+ fragmentClass.getCanonicalName() + ") does not match the expected return type.");
}
......@@ -276,16 +215,14 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
return frag;
} catch (Exception e) {
throw new RuntimeException("Could not instantiate FlutterFragment subclass (" + fragmentClass.getName() + ")", e);
throw new RuntimeException("Could not instantiate NewFlutterFragment subclass (" + fragmentClass.getName() + ")", e);
}
}
}
// Delegate that runs all lifecycle and OS hook logic that is common between
// FlutterActivity and FlutterFragment. See the FlutterActivityAndFragmentDelegate
// FlutterActivity and NewFlutterFragment. See the FlutterActivityAndFragmentDelegate
// implementation for details about why it exists.
private FlutterActivityAndFragmentDelegate delegate;
......@@ -293,7 +230,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
@Override
public void onFirstFrameRendered() {
// Notify our subclasses that the first frame has been rendered.
FlutterFragment.this.onFirstFrameRendered();
NewFlutterFragment.this.onFirstFrameRendered();
// Notify our owning Activity that the first frame has been rendered.
FragmentActivity fragmentActivity = getActivity();
......@@ -304,7 +241,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
}
};
public FlutterFragment() {
public NewFlutterFragment() {
// Ensure that we at least have an empty Bundle of arguments so that we don't
// need to continually check for null arguments before grabbing one.
setArguments(new Bundle());
......@@ -448,76 +385,13 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
);
}
/**
* Returns the ID of a statically cached {@link FlutterEngine} to use within this
* {@code FlutterFragment}, or {@code null} if this {@code FlutterFragment} does not want to
* use a cached {@link FlutterEngine}.
*/
@Nullable
@Override
public String getCachedEngineId() {
return getArguments().getString(ARG_CACHED_ENGINE_ID, null);
}
/**
* Returns false if the {@link FlutterEngine} within this {@code FlutterFragment} should outlive
* the {@code FlutterFragment}, itself.
* <p>
* Defaults to true if no custom {@link FlutterEngine is provided}, false if a custom
* {@link FlutterEngine} is provided.
*/
@Override
public boolean shouldDestroyEngineWithHost() {
return getArguments().getBoolean(ARG_DESTROY_ENGINE_WITH_FRAGMENT, false);
}
/**
* Returns the name of the Dart method that this {@code FlutterFragment} should execute to
* start a Flutter app.
* <p>
* Defaults to "main".
* <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
*/
@Override
@NonNull
public String getDartEntrypointFunctionName() {
return getArguments().getString(ARG_DART_ENTRYPOINT, "main");
}
/**
* Returns the file path to the desired Flutter app's bundle of code.
* <p>
* Defaults to {@link FlutterMain#findAppBundlePath()}.
* <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
*/
@Override
@NonNull
public String getAppBundlePath() {
return getArguments().getString(ARG_APP_BUNDLE_PATH, FlutterMain.findAppBundlePath());
}
/**
* Returns the initial route that should be rendered within Flutter, once the Flutter app starts.
* <p>
* Defaults to {@code null}, which signifies a route of "/" in Flutter.
* <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
*/
@Override
@Nullable
public String getInitialRoute() {
return getArguments().getString(ARG_INITIAL_ROUTE);
}
/**
* Returns the desired {@link FlutterView.RenderMode} for the {@link FlutterView} displayed in
* this {@code FlutterFragment}.
* this {@code NewFlutterFragment}.
* <p>
* Defaults to {@link FlutterView.RenderMode#surface}.
* <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
* Used by this {@code NewFlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
*/
@Override
@NonNull
......@@ -531,11 +405,11 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
/**
* Returns the desired {@link FlutterView.TransparencyMode} for the {@link FlutterView} displayed in
* this {@code FlutterFragment}.
* this {@code NewFlutterFragment}.
* <p>
* Defaults to {@link FlutterView.TransparencyMode#transparent}.
* <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
* Used by this {@code NewFlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
*/
@Override
@NonNull
......@@ -565,18 +439,6 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
public FlutterEngine provideFlutterEngine(@NonNull Context context) {
return NewFlutterBoost.instance().engineProvider();
// // Defer to the FragmentActivity that owns us to see if it wants to provide a
// // FlutterEngine.
// FlutterEngine flutterEngine = null;
// FragmentActivity attachedActivity = getActivity();
// if (attachedActivity instanceof FlutterEngineProvider) {
// // Defer to the Activity that owns us to provide a FlutterEngine.
// Log.d(TAG, "Deferring to attached Activity to provide a FlutterEngine.");
// FlutterEngineProvider flutterEngineProvider = (FlutterEngineProvider) attachedActivity;
// flutterEngine = flutterEngineProvider.provideFlutterEngine(getContext());
// }
//
// return flutterEngine;
}
/**
......@@ -614,7 +476,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
* as a {@link FlutterEngineConfigurator}. Subclasses can override this method if the
* subclass needs to override the {@code FragmentActivity}'s behavior, or add to it.
* <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
* Used by this {@code NewFlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
*/
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
......@@ -627,7 +489,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
/**
* See {@link NewEngineFragmentBuilder#shouldAttachEngineToActivity()} and
* <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate}
* Used by this {@code NewFlutterFragment}'s {@link FlutterActivityAndFragmentDelegate}
*/
@Override
public boolean shouldAttachEngineToActivity() {
......@@ -635,7 +497,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
}
/**
* Invoked after the {@link FlutterView} within this {@code FlutterFragment} renders its first
* Invoked after the {@link FlutterView} within this {@code NewFlutterFragment} renders its first
* frame.
* <p>
* This method forwards {@code onFirstFrameRendered()} to its attached {@code Activity}, if
......@@ -643,7 +505,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
* <p>
* Subclasses that override this method must call through to the {@code super} method.
* <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
* Used by this {@code NewFlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
*/
@Override
public void onFirstFrameRendered() {
......@@ -655,25 +517,26 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
@Override
public void finishContainer(Map<String, Object> result) {
Activity activity= this.getActivity();
Activity activity = this.getActivity();
activity.finish();
}
@Override
public String getContainerUrl() {
return "flutterFragment";
return getArguments().getString(EXTRA_URL);
}
@Override
public Map getContainerUrlParams() {
Map<String,String> params = new HashMap<>();
params.put("aaa","bbb");
return params;
return (HashMap) getArguments().getSerializable(EXTRA_PARAMS);
}
/**
* Annotates methods in {@code FlutterFragment} that must be called by the containing
* Annotates methods in {@code NewFlutterFragment} that must be called by the containing
* {@code Activity}.
*/
@interface ActivityCallThrough {
......
......@@ -9,12 +9,12 @@ import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import com.idlefish.flutterboost.containers.FlutterFragment;
import com.idlefish.flutterboost.containers.NewFlutterFragment;
import io.flutter.plugin.platform.PlatformPlugin;
public class FlutterFragmentPageActivity extends AppCompatActivity implements View.OnClickListener {
private FlutterFragment mFragment;
private NewFlutterFragment mFragment;
private View mTab1;
private View mTab2;
......@@ -61,16 +61,18 @@ public class FlutterFragmentPageActivity extends AppCompatActivity implements Vi
if(mTab1 == v) {
mTab1.setBackgroundColor(Color.YELLOW);
mFragment = FlutterFragment.createDefault();
mFragment= new NewFlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
}else if(mTab2 == v) {
mTab2.setBackgroundColor(Color.YELLOW);
mFragment = FlutterFragment.createDefault();
mFragment= new NewFlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
}else if(mTab3 == v) {
mTab3.setBackgroundColor(Color.YELLOW);
mFragment = FlutterFragment.createDefault();
mFragment= new NewFlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
}else{
mTab4.setBackgroundColor(Color.YELLOW);
mFragment = FlutterFragment.createDefault();
mFragment= new NewFlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
}
getSupportFragmentManager()
......
......@@ -19,7 +19,8 @@ public class MyApplication extends FlutterApplication {
INativeRouter router =new INativeRouter() {
@Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) {
PageRouter.openPageByUrl(context,url, urlParams);
String assembleUrl=Utils.assembleUrl(url,urlParams);
PageRouter.openPageByUrl(context,assembleUrl, urlParams);
}
};
......
......@@ -5,6 +5,7 @@ import android.content.Intent;
import android.text.TextUtils;
import com.idlefish.flutterboost.containers.NewBoostFlutterActivity;
import java.util.HashMap;
import java.util.Map;
public class PageRouter {
......@@ -20,8 +21,12 @@ public class PageRouter {
public static boolean openPageByUrl(Context context, String url, Map params, int requestCode) {
try {
if (url.startsWith(FLUTTER_PAGE_URL)) {
HashMap p=new HashMap();
context.startActivity( NewBoostFlutterActivity.createDefaultIntent(context));
Intent intent= NewBoostFlutterActivity.withNewEngine().url("flutterPage").params(p)
.backgroundMode(NewBoostFlutterActivity.BackgroundMode.opaque).build(context);
context.startActivity( intent);
return true;
} else if (url.startsWith(FLUTTER_FRAGMENT_PAGE_URL)) {
context.startActivity(new Intent(context, FlutterFragmentPageActivity.class));
......
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