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

boost1.9升级

parent 6afc509d
...@@ -39,6 +39,7 @@ dependencies { ...@@ -39,6 +39,7 @@ dependencies {
implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.support:support-v4:28.0.0'
implementation 'android.arch.lifecycle:common-java8:1.1.1' implementation 'android.arch.lifecycle:common-java8:1.1.1'
implementation 'com.alibaba:fastjson:1.2.41'
} }
......
...@@ -35,14 +35,14 @@ import android.view.View; ...@@ -35,14 +35,14 @@ import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import com.alibaba.fastjson.JSON;
import java.io.BufferedReader; import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
public class Utils { public class Utils {
...@@ -289,4 +289,55 @@ 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; ...@@ -7,7 +7,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -16,7 +15,6 @@ import android.view.ViewGroup; ...@@ -16,7 +15,6 @@ import android.view.ViewGroup;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -27,9 +25,7 @@ import io.flutter.Log; ...@@ -27,9 +25,7 @@ import io.flutter.Log;
import io.flutter.app.FlutterActivity; import io.flutter.app.FlutterActivity;
import io.flutter.embedding.android.*; import io.flutter.embedding.android.*;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.FlutterShellArgs; import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener; import io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener;
import io.flutter.plugin.platform.PlatformPlugin; import io.flutter.plugin.platform.PlatformPlugin;
import io.flutter.view.FlutterMain; import io.flutter.view.FlutterMain;
...@@ -157,7 +153,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine ...@@ -157,7 +153,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
// Our host did not provide a custom FlutterEngine. Create a FlutterEngine to back our // Our host did not provide a custom FlutterEngine. Create a FlutterEngine to back our
// FlutterView. // FlutterView.
Log.d(TAG, "No preferred FlutterEngine was provided. Creating a new FlutterEngine for" Log.d(TAG, "No preferred FlutterEngine was provided. Creating a new FlutterEngine for"
+ " this FlutterFragment."); + " this NewFlutterFragment.");
flutterEngine = new FlutterEngine(host.getContext()); flutterEngine = new FlutterEngine(host.getContext());
isFlutterEngineFromHost = false; isFlutterEngineFromHost = false;
} }
...@@ -224,7 +220,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine ...@@ -224,7 +220,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
platformPlugin.updateSystemUiOverlays(); platformPlugin.updateSystemUiOverlays();
} }
} else { } 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 ...@@ -296,7 +292,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
// Log.v(TAG, "Forwarding onBackPressed() to FlutterEngine."); // Log.v(TAG, "Forwarding onBackPressed() to FlutterEngine.");
// flutterEngine.getNavigationChannel().popRoute(); // flutterEngine.getNavigationChannel().popRoute();
// } else { // } 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 ...@@ -312,7 +308,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
+ "grantResults: " + Arrays.toString(grantResults)); + "grantResults: " + Arrays.toString(grantResults));
flutterEngine.getActivityControlSurface().onRequestPermissionsResult(requestCode, permissions, grantResults); flutterEngine.getActivityControlSurface().onRequestPermissionsResult(requestCode, permissions, grantResults);
} else { } 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 ...@@ -325,7 +321,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
Log.v(TAG, "Forwarding onNewIntent() to FlutterEngine."); Log.v(TAG, "Forwarding onNewIntent() to FlutterEngine.");
flutterEngine.getActivityControlSurface().onNewIntent(intent); flutterEngine.getActivityControlSurface().onNewIntent(intent);
} else { } 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 ...@@ -351,7 +347,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
+ "data: " + data); + "data: " + data);
flutterEngine.getActivityControlSurface().onActivityResult(requestCode, resultCode, data); flutterEngine.getActivityControlSurface().onActivityResult(requestCode, resultCode, data);
} else { } 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 ...@@ -362,7 +358,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
Log.v(TAG, "Forwarding onUserLeaveHint() to FlutterEngine."); Log.v(TAG, "Forwarding onUserLeaveHint() to FlutterEngine.");
flutterEngine.getActivityControlSurface().onUserLeaveHint(); flutterEngine.getActivityControlSurface().onUserLeaveHint();
} else { } 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 ...@@ -379,7 +375,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
flutterEngine.getSystemChannel().sendMemoryPressureWarning(); flutterEngine.getSystemChannel().sendMemoryPressureWarning();
} }
} else { } 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 ...@@ -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}. * {@code FlutterActivityAndFragmentDelegate}.
*/ */
/* package */ interface Host extends SplashScreenProvider, FlutterEngineProvider, FlutterEngineConfigurator { /* package */ interface Host extends SplashScreenProvider, FlutterEngineProvider, FlutterEngineConfigurator {
...@@ -469,42 +465,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine ...@@ -469,42 +465,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
@NonNull @NonNull
FlutterShellArgs getFlutterShellArgs(); 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 * Returns the {@link FlutterView.RenderMode} used by the {@link FlutterView} that
......
...@@ -41,21 +41,19 @@ public class NewBoostFlutterActivity extends Activity ...@@ -41,21 +41,19 @@ public class NewBoostFlutterActivity extends Activity
private static final String TAG = "NewBoostFlutterActivity"; private static final String TAG = "NewBoostFlutterActivity";
// Meta-data arguments, processed from manifest XML. // 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 SPLASH_SCREEN_META_DATA_KEY = "io.flutter.embedding.android.SplashScreenDrawable";
protected static final String NORMAL_THEME_META_DATA_KEY = "io.flutter.embedding.android.NormalTheme"; protected static final String NORMAL_THEME_META_DATA_KEY = "io.flutter.embedding.android.NormalTheme";
// Intent extra arguments. // Intent extra arguments.
protected static final String EXTRA_DART_ENTRYPOINT = "dart_entrypoint"; 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_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_DESTROY_ENGINE_WITH_ACTIVITY = "destroy_engine_with_activity";
protected static final String EXTRA_URL = "url";
protected static final String EXTRA_PARAMS = "params";
// Default configuration. // 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(); protected static final String DEFAULT_BACKGROUND_MODE = BackgroundMode.opaque.name();
...@@ -71,11 +69,9 @@ public class NewBoostFlutterActivity extends Activity ...@@ -71,11 +69,9 @@ public class NewBoostFlutterActivity extends Activity
public static class NewEngineIntentBuilder { public static class NewEngineIntentBuilder {
private final Class<? extends NewBoostFlutterActivity> activityClass; 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 backgroundMode = DEFAULT_BACKGROUND_MODE;
private String url = ""; private String url = "";
private Map params = null; private HashMap params = new HashMap();
...@@ -84,10 +80,7 @@ public class NewBoostFlutterActivity extends Activity ...@@ -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) { public NewEngineIntentBuilder url (@NonNull String url) {
this.url = url; this.url = url;
...@@ -95,15 +88,11 @@ public class NewBoostFlutterActivity extends Activity ...@@ -95,15 +88,11 @@ public class NewBoostFlutterActivity extends Activity
} }
public NewEngineIntentBuilder params (@NonNull Map params) { public NewEngineIntentBuilder params (@NonNull HashMap params) {
this.params = params; this.params = params;
return this; return this;
} }
public NewEngineIntentBuilder initialRoute(@NonNull String initialRoute) {
this.initialRoute = initialRoute;
return this;
}
public NewEngineIntentBuilder backgroundMode(@NonNull BackgroundMode backgroundMode) { public NewEngineIntentBuilder backgroundMode(@NonNull BackgroundMode backgroundMode) {
...@@ -114,12 +103,10 @@ public class NewBoostFlutterActivity extends Activity ...@@ -114,12 +103,10 @@ public class NewBoostFlutterActivity extends Activity
public Intent build(@NonNull Context context) { public Intent build(@NonNull Context context) {
return new Intent(context, activityClass) return new Intent(context, activityClass)
.putExtra(EXTRA_DART_ENTRYPOINT, dartEntrypoint)
.putExtra(EXTRA_INITIAL_ROUTE, initialRoute)
.putExtra(EXTRA_BACKGROUND_MODE, backgroundMode) .putExtra(EXTRA_BACKGROUND_MODE, backgroundMode)
.putExtra(EXTRA_DESTROY_ENGINE_WITH_ACTIVITY, false) .putExtra(EXTRA_DESTROY_ENGINE_WITH_ACTIVITY, false)
.putExtra("url", url) .putExtra(EXTRA_URL, url)
.putExtra("params", (HashMap)params); .putExtra(EXTRA_PARAMS, (HashMap)params);
} }
} }
...@@ -365,129 +352,7 @@ public class NewBoostFlutterActivity extends Activity ...@@ -365,129 +352,7 @@ public class NewBoostFlutterActivity extends Activity
return FlutterShellArgs.fromIntent(getIntent()); 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. * Returns true if Flutter is running in "debug mode", and false otherwise.
...@@ -600,13 +465,22 @@ public class NewBoostFlutterActivity extends Activity ...@@ -600,13 +465,22 @@ public class NewBoostFlutterActivity extends Activity
@Override @Override
public String getContainerUrl() { public String getContainerUrl() {
return "flutterPage"; if (getIntent().hasExtra(EXTRA_URL)) {
return getIntent().getStringExtra(EXTRA_URL);
}
return "";
} }
@Override @Override
public Map getContainerUrlParams() { public Map getContainerUrlParams() {
if (getIntent().hasExtra(EXTRA_PARAMS)) {
return (Map) getIntent().getSerializableExtra(EXTRA_PARAMS);
}
Map<String,String> params = new HashMap<>(); Map<String,String> params = new HashMap<>();
params.put("aaa","bbb");
return params; return params;
} }
......
...@@ -26,9 +26,9 @@ import java.util.HashMap; ...@@ -26,9 +26,9 @@ import java.util.HashMap;
import java.util.Map; 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. * The Dart entrypoint method name that is executed upon initialization.
...@@ -48,12 +48,12 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -48,12 +48,12 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
protected static final String ARG_FLUTTER_INITIALIZATION_ARGS = "initialization_args"; protected static final String ARG_FLUTTER_INITIALIZATION_ARGS = "initialization_args";
/** /**
* {@link FlutterView.RenderMode} to be used for the {@link FlutterView} in this * {@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"; protected static final String ARG_FLUTTERVIEW_RENDER_MODE = "flutterview_render_mode";
/** /**
* {@link FlutterView.TransparencyMode} to be used for the {@link FlutterView} in this * {@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"; protected static final String ARG_FLUTTERVIEW_TRANSPARENCY_MODE = "flutterview_transparency_mode";
/** /**
...@@ -61,21 +61,26 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -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"; 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"; protected static final String ARG_CACHED_ENGINE_ID = "cached_engine_id";
/** /**
* True if the {@link FlutterEngine} in the created {@code FlutterFragment} should be destroyed * True if the {@link FlutterEngine} in the created {@code NewFlutterFragment} should be destroyed
* when the {@code FlutterFragment} is destroyed, false if the {@link FlutterEngine} should * when the {@code NewFlutterFragment} is destroyed, false if the {@link FlutterEngine} should
* outlive the {@code FlutterFragment}. * outlive the {@code NewFlutterFragment}.
*/ */
protected static final String ARG_DESTROY_ENGINE_WITH_FRAGMENT = "destroy_engine_with_fragment"; 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> * <p>
* {@code FlutterFragment}'s default configuration creates a new {@link FlutterEngine} within * {@code NewFlutterFragment}'s default configuration creates a new {@link FlutterEngine} within
* the {@code FlutterFragment} and uses the following settings: * the {@code NewFlutterFragment} and uses the following settings:
* <ul> * <ul>
* <li>Dart entrypoint: "main"</li> * <li>Dart entrypoint: "main"</li>
* <li>Initial route: "/"</li> * <li>Initial route: "/"</li>
...@@ -88,12 +93,12 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -88,12 +93,12 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
* To use a cached {@link FlutterEngine} instead of creating a new one, use * To use a cached {@link FlutterEngine} instead of creating a new one, use
*/ */
@NonNull @NonNull
public static FlutterFragment createDefault() { public static NewFlutterFragment createDefault() {
return new NewEngineFragmentBuilder().build(); 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. * {@link FlutterEngine} and a desired engine configuration.
*/ */
@NonNull @NonNull
...@@ -101,101 +106,33 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -101,101 +106,33 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
return new NewEngineFragmentBuilder(); 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 { public static class NewEngineFragmentBuilder {
private final Class<? extends FlutterFragment> fragmentClass; private final Class<? extends NewFlutterFragment> fragmentClass;
private String dartEntrypoint = "main";
private String initialRoute = "/";
private String appBundlePath = null;
private FlutterShellArgs shellArgs = null; private FlutterShellArgs shellArgs = null;
private FlutterView.RenderMode renderMode = FlutterView.RenderMode.surface; private FlutterView.RenderMode renderMode = FlutterView.RenderMode.surface;
private FlutterView.TransparencyMode transparencyMode = FlutterView.TransparencyMode.transparent; private FlutterView.TransparencyMode transparencyMode = FlutterView.TransparencyMode.transparent;
private boolean shouldAttachEngineToActivity = true; private boolean shouldAttachEngineToActivity = true;
private String url = "";
private HashMap params = new HashMap();
/** /**
* Constructs a {@code NewEngineFragmentBuilder} that is configured to construct an instance of * Constructs a {@code NewEngineFragmentBuilder} that is configured to construct an instance of
* {@code FlutterFragment}. * {@code NewFlutterFragment}.
*/ */
public NewEngineFragmentBuilder() { public NewEngineFragmentBuilder() {
fragmentClass = FlutterFragment.class; fragmentClass = NewFlutterFragment.class;
} }
/** /**
* Constructs a {@code NewEngineFragmentBuilder} that is configured to construct an instance of * 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; 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 * Any special configuration arguments for the Flutter engine
...@@ -219,7 +156,16 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -219,7 +156,16 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
this.renderMode = renderMode; this.renderMode = renderMode;
return this; 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}, * Support a {@link FlutterView.TransparencyMode#transparent} background within {@link FlutterView},
* or force an {@link FlutterView.TransparencyMode#opaque} background. * or force an {@link FlutterView.TransparencyMode#opaque} background.
...@@ -233,41 +179,34 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -233,41 +179,34 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
} }
@NonNull
public NewEngineFragmentBuilder shouldAttachEngineToActivity(boolean shouldAttachEngineToActivity) {
this.shouldAttachEngineToActivity = shouldAttachEngineToActivity;
return this;
}
@NonNull @NonNull
protected Bundle createArgs() { protected Bundle createArgs() {
Bundle args = new Bundle(); 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. // TODO(mattcarroll): determine if we should have an explicit FlutterTestFragment instead of conflating.
if (null != shellArgs) { if (null != shellArgs) {
args.putStringArray(ARG_FLUTTER_INITIALIZATION_ARGS, shellArgs.toArray()); 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_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.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); args.putBoolean(ARG_DESTROY_ENGINE_WITH_FRAGMENT, true);
return args; 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}. * properties set on this {@code Builder}.
*/ */
@NonNull @NonNull
public <T extends FlutterFragment> T build() { public <T extends NewFlutterFragment> T build() {
try { try {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
T frag = (T) fragmentClass.getDeclaredConstructor().newInstance(); T frag = (T) fragmentClass.getDeclaredConstructor().newInstance();
if (frag == null) { 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."); + fragmentClass.getCanonicalName() + ") does not match the expected return type.");
} }
...@@ -276,16 +215,14 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -276,16 +215,14 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
return frag; return frag;
} catch (Exception e) { } 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 // 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. // implementation for details about why it exists.
private FlutterActivityAndFragmentDelegate delegate; private FlutterActivityAndFragmentDelegate delegate;
...@@ -293,7 +230,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -293,7 +230,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
@Override @Override
public void onFirstFrameRendered() { public void onFirstFrameRendered() {
// Notify our subclasses that the first frame has been rendered. // 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. // Notify our owning Activity that the first frame has been rendered.
FragmentActivity fragmentActivity = getActivity(); FragmentActivity fragmentActivity = getActivity();
...@@ -304,7 +241,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -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 // 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. // need to continually check for null arguments before grabbing one.
setArguments(new Bundle()); setArguments(new Bundle());
...@@ -448,76 +385,13 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -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 * Returns the desired {@link FlutterView.RenderMode} for the {@link FlutterView} displayed in
* this {@code FlutterFragment}. * this {@code NewFlutterFragment}.
* <p> * <p>
* Defaults to {@link FlutterView.RenderMode#surface}. * Defaults to {@link FlutterView.RenderMode#surface}.
* <p> * <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host} * Used by this {@code NewFlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
*/ */
@Override @Override
@NonNull @NonNull
...@@ -531,11 +405,11 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -531,11 +405,11 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
/** /**
* Returns the desired {@link FlutterView.TransparencyMode} for the {@link FlutterView} displayed in * Returns the desired {@link FlutterView.TransparencyMode} for the {@link FlutterView} displayed in
* this {@code FlutterFragment}. * this {@code NewFlutterFragment}.
* <p> * <p>
* Defaults to {@link FlutterView.TransparencyMode#transparent}. * Defaults to {@link FlutterView.TransparencyMode#transparent}.
* <p> * <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host} * Used by this {@code NewFlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
*/ */
@Override @Override
@NonNull @NonNull
...@@ -565,18 +439,6 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -565,18 +439,6 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
public FlutterEngine provideFlutterEngine(@NonNull Context context) { public FlutterEngine provideFlutterEngine(@NonNull Context context) {
return NewFlutterBoost.instance().engineProvider(); 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 ...@@ -614,7 +476,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
* as a {@link FlutterEngineConfigurator}. Subclasses can override this method if the * as a {@link FlutterEngineConfigurator}. Subclasses can override this method if the
* subclass needs to override the {@code FragmentActivity}'s behavior, or add to it. * subclass needs to override the {@code FragmentActivity}'s behavior, or add to it.
* <p> * <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host} * Used by this {@code NewFlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
*/ */
@Override @Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
...@@ -627,7 +489,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -627,7 +489,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
/** /**
* See {@link NewEngineFragmentBuilder#shouldAttachEngineToActivity()} and * See {@link NewEngineFragmentBuilder#shouldAttachEngineToActivity()} and
* <p> * <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate} * Used by this {@code NewFlutterFragment}'s {@link FlutterActivityAndFragmentDelegate}
*/ */
@Override @Override
public boolean shouldAttachEngineToActivity() { public boolean shouldAttachEngineToActivity() {
...@@ -635,7 +497,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -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. * frame.
* <p> * <p>
* This method forwards {@code onFirstFrameRendered()} to its attached {@code Activity}, if * This method forwards {@code onFirstFrameRendered()} to its attached {@code Activity}, if
...@@ -643,7 +505,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -643,7 +505,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
* <p> * <p>
* Subclasses that override this method must call through to the {@code super} method. * Subclasses that override this method must call through to the {@code super} method.
* <p> * <p>
* Used by this {@code FlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host} * Used by this {@code NewFlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
*/ */
@Override @Override
public void onFirstFrameRendered() { public void onFirstFrameRendered() {
...@@ -655,25 +517,26 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -655,25 +517,26 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
@Override @Override
public void finishContainer(Map<String, Object> result) { public void finishContainer(Map<String, Object> result) {
Activity activity= this.getActivity(); Activity activity = this.getActivity();
activity.finish(); activity.finish();
} }
@Override @Override
public String getContainerUrl() { public String getContainerUrl() {
return "flutterFragment";
return getArguments().getString(EXTRA_URL);
} }
@Override @Override
public Map getContainerUrlParams() { public Map getContainerUrlParams() {
Map<String,String> params = new HashMap<>(); return (HashMap) getArguments().getSerializable(EXTRA_PARAMS);
params.put("aaa","bbb");
return 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}. * {@code Activity}.
*/ */
@interface ActivityCallThrough { @interface ActivityCallThrough {
......
...@@ -9,12 +9,12 @@ import android.support.v7.app.AppCompatActivity; ...@@ -9,12 +9,12 @@ import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import com.idlefish.flutterboost.containers.FlutterFragment; import com.idlefish.flutterboost.containers.NewFlutterFragment;
import io.flutter.plugin.platform.PlatformPlugin; import io.flutter.plugin.platform.PlatformPlugin;
public class FlutterFragmentPageActivity extends AppCompatActivity implements View.OnClickListener { public class FlutterFragmentPageActivity extends AppCompatActivity implements View.OnClickListener {
private FlutterFragment mFragment; private NewFlutterFragment mFragment;
private View mTab1; private View mTab1;
private View mTab2; private View mTab2;
...@@ -61,16 +61,18 @@ public class FlutterFragmentPageActivity extends AppCompatActivity implements Vi ...@@ -61,16 +61,18 @@ public class FlutterFragmentPageActivity extends AppCompatActivity implements Vi
if(mTab1 == v) { if(mTab1 == v) {
mTab1.setBackgroundColor(Color.YELLOW); mTab1.setBackgroundColor(Color.YELLOW);
mFragment = FlutterFragment.createDefault();
mFragment= new NewFlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
}else if(mTab2 == v) { }else if(mTab2 == v) {
mTab2.setBackgroundColor(Color.YELLOW); mTab2.setBackgroundColor(Color.YELLOW);
mFragment = FlutterFragment.createDefault(); mFragment= new NewFlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
}else if(mTab3 == v) { }else if(mTab3 == v) {
mTab3.setBackgroundColor(Color.YELLOW); mTab3.setBackgroundColor(Color.YELLOW);
mFragment = FlutterFragment.createDefault(); mFragment= new NewFlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
}else{ }else{
mTab4.setBackgroundColor(Color.YELLOW); mTab4.setBackgroundColor(Color.YELLOW);
mFragment = FlutterFragment.createDefault(); mFragment= new NewFlutterFragment.NewEngineFragmentBuilder().url("flutterFragment").build();
} }
getSupportFragmentManager() getSupportFragmentManager()
......
...@@ -19,7 +19,8 @@ public class MyApplication extends FlutterApplication { ...@@ -19,7 +19,8 @@ public class MyApplication extends FlutterApplication {
INativeRouter router =new INativeRouter() { INativeRouter router =new INativeRouter() {
@Override @Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) { 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; ...@@ -5,6 +5,7 @@ import android.content.Intent;
import android.text.TextUtils; import android.text.TextUtils;
import com.idlefish.flutterboost.containers.NewBoostFlutterActivity; import com.idlefish.flutterboost.containers.NewBoostFlutterActivity;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class PageRouter { public class PageRouter {
...@@ -20,8 +21,12 @@ public class PageRouter { ...@@ -20,8 +21,12 @@ public class PageRouter {
public static boolean openPageByUrl(Context context, String url, Map params, int requestCode) { public static boolean openPageByUrl(Context context, String url, Map params, int requestCode) {
try { try {
if (url.startsWith(FLUTTER_PAGE_URL)) { 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; return true;
} else if (url.startsWith(FLUTTER_FRAGMENT_PAGE_URL)) { } else if (url.startsWith(FLUTTER_FRAGMENT_PAGE_URL)) {
context.startActivity(new Intent(context, FlutterFragmentPageActivity.class)); 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