Commit 1c7dfad4 authored by 林生雨's avatar 林生雨

add buried

parent a2a102d0
......@@ -20,16 +20,5 @@
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
</activity>
<activity android:name=".flutter.base.FlutterPageActivity"
android:screenOrientation="portrait"/>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.gmalpha_flutter"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>
......@@ -3,7 +3,6 @@ package com.example.gmalpha_flutter
import android.app.Activity
import android.app.Application
import android.content.Context
import com.example.gmalpha_flutter.flutter.PageRouter
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin
import com.taobao.idlefish.flutterboost.interfaces.IPlatform
import io.flutter.BuildConfig
......@@ -20,36 +19,5 @@ class App : Application() {
override fun onCreate() {
super.onCreate()
FlutterMain.startInitialization(this)
FlutterBoostPlugin.init(object : IPlatform {
override fun getApplication(): Application {
return this@App
}
/**
* get the main activity, this activity should always at the bottom of task stack.
*/
override fun getMainActivity(): Activity? {
// return null
return MainActivity.Companion.sRef!!.get();
}
override fun isDebug(): Boolean {
return BuildConfig.DEBUG
}
/**
* start a new activity from flutter page, you may need a activity router.
*/
override fun startActivity(context: Context, url: String, requestCode: Int): Boolean {
Log.e("lsy", "$requestCode $url")
return true;
}
override fun getSettings(): Map<*, *> {
val base = HashMap<String, String>()
base["BASE"] = "BASEVALUE"
return base
}
})
}
}
\ No newline at end of file
......@@ -6,7 +6,6 @@ import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.View
import com.example.gmalpha_flutter.flutter.PageRouter
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin
import com.taobao.idlefish.flutterboost.containers.BoostFlutterActivity
......@@ -17,58 +16,18 @@ import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.GeneratedPluginRegistrant
import java.lang.ref.WeakReference
class MainActivity : AppCompatActivity() {
// override fun getContainerParams(): MutableMap<Any?, Any?>? {
// return null;
//// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
// }
//
// override fun onRegisterPlugins(registry: PluginRegistry?) {
// GeneratedPluginRegistrant.registerWith(registry)
//// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
// }
//
// override fun getContainerName(): String? {
// return "init";
//// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
// }
class MainActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
sRef = WeakReference(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// FlutterBoostPlugin.containerManager().onContainerCreate(this)
// GeneratedPluginRegistrant.registerWith(this)
// val methodChannel = MethodChannel(flutterView, "gengmei_flutter_native_channel")
// methodChannel.setMethodCallHandler(object : MethodChannel.MethodCallHandler {
// override fun onMethodCall(p0: MethodCall, p1: MethodChannel.Result) {
// if (p0.method.equals("get_native_data")) {
// Log.e("lsy", "ARGS ${p0.arguments}")
// p1.success("!!!")
// }
// }
// })
findViewById<View>(R.id.hello).setOnClickListener {
val intent = Intent()
intent.putExtra("name","prestige")
PageRouter.openPageByUrl(this, PageRouter.FLUTTER_PAGE_URL, intent)
startActivity(intent)
}
}
override fun onDestroy() {
super.onDestroy()
if (sRef != null) {
sRef!!.clear()
sRef = null
}
}
companion object{
var sRef: WeakReference<MainActivity>? = null
GeneratedPluginRegistrant.registerWith(this)
// setContentView(R.layout.activity_main)
// findViewById<View>(R.id.hello).setOnClickListener {
// val intent = Intent()
// intent.putExtra("name","prestige")
// PageRouter.openPageByUrl(this, PageRouter.FLUTTER_PAGE_URL, intent)
// startActivity(intent)
//
// }
}
}
package com.example.gmalpha_flutter.flutter;
import android.content.Context;
import android.content.Intent;
import com.example.gmalpha_flutter.flutter.base.FlutterFragmentPageActivity;
import com.example.gmalpha_flutter.flutter.base.FlutterPageActivity;
import com.example.gmalpha_flutter.flutter.base.NativePageActivity;
public class PageRouter {
public static final String NATIVE_PAGE_URL = "gmlike://nativePage";
public static final String FLUTTER_PAGE_URL = "gmlike://flutterPage";
public static final String FLUTTER_FRAGMENT_PAGE_URL = "gmlike://flutterFragmentPage";
public static boolean openPageByUrl(Context context, String url) {
return openPageByUrl(context, url, 0);
}
public static boolean openPageByUrl(Context context, String url,Intent intent) {
return openPageByUrl(context, url, 0,intent);
}
public static boolean openPageByUrl(Context context, String url, int requestCode,Intent intent) {
if (url.startsWith(FLUTTER_PAGE_URL)) {
intent.setClass(context, FlutterPageActivity.class);
context.startActivity(intent);
return true;
}
return false;
}
public static boolean openPageByUrl(Context context, String url, int requestCode) {
try {
if (url.startsWith(FLUTTER_PAGE_URL)) {
context.startActivity(new Intent(context, FlutterPageActivity.class));
return true;
} else if (url.startsWith(FLUTTER_FRAGMENT_PAGE_URL)) {
context.startActivity(new Intent(context, FlutterFragmentPageActivity.class));
return true;
} else if (url.startsWith(NATIVE_PAGE_URL)) {
context.startActivity(new Intent(context, NativePageActivity.class));
return true;
} else {
return false;
}
} catch (Throwable t) {
return false;
}
}
}
package com.example.gmalpha_flutter.flutter.base;
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.taobao.idlefish.flutterboost.containers.BoostFlutterFragment;
import java.util.HashMap;
import java.util.Map;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class FlutterFragment extends BoostFlutterFragment {
@Override
public void setArguments(@Nullable Bundle args) {
if(args == null) {
args = new Bundle();
args.putString("tag","");
}
super.setArguments(args);
}
public void setTabTag(String tag) {
Bundle args = new Bundle();
args.putString("tag",tag);
super.setArguments(args);
}
@Override
public void onRegisterPlugins(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
@Override
public String getContainerName() {
return "flutterFragment";
}
@Override
public Map getContainerParams() {
Map<String,String> params = new HashMap<>();
params.put("tag",getArguments().getString("tag"));
return params;
}
@Override
public void destroyContainer() {
}
public static FlutterFragment instance(String tag){
FlutterFragment fragment = new FlutterFragment();
fragment.setTabTag(tag);
return fragment;
}
}
package com.example.gmalpha_flutter.flutter.base;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;
import com.example.gmalpha_flutter.R;
import org.jetbrains.annotations.Nullable;
import io.flutter.plugin.platform.PlatformPlugin;
public class FlutterFragmentPageActivity extends AppCompatActivity {
private FlutterFragment mFragment;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(0x40000000);
window.getDecorView().setSystemUiVisibility(PlatformPlugin.DEFAULT_SYSTEM_UI);
}
super.onCreate(savedInstanceState);
final ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
actionBar.hide();
}
setContentView(R.layout.flutter_fragment_page);
mFragment = FlutterFragment.instance("hello");
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_stub,mFragment)
.commit();
}
}
package com.example.gmalpha_flutter.flutter.base;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import com.example.gmalpha_flutter.R;
import com.example.gmalpha_flutter.util.OSUtils;
import com.example.gmalpha_flutter.util.StatusBarUtil;
import com.taobao.idlefish.flutterboost.containers.BoostFlutterActivity;
import java.util.HashMap;
import java.util.Map;
import io.flutter.Log;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class FlutterPageActivity extends BoostFlutterActivity {
String name;
@Override
public void onRegisterPlugins(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
name = getIntent().getStringExtra("name");
setStatusBar();
if (OSUtils.isMiui()) {
setStatus();
}
new MethodChannel(getFlutterView(), "flutter_bury_channel").setMethodCallHandler((call, result) -> {
if (call.method.equals("FLUTTER_BURIED")) {
Map<String, Object> map = new HashMap<>();
map.put("ww", "ww");
map.put("qq", 1);
result.success(map);
}
});
// new MethodChannel(getFlutterView(), "flutter_bury_channel").setMethodCallHandler(
// (call, result) -> {
// Map<String, String> arguments = (Map<String, String>) call.arguments;
// if (call.method.equals("PAGE_START")) {
// String pageName = arguments.get("page_name");
// String refererName = arguments.get("referrer");
// } else if (call.method.equals("PAGE_END")) {
// Log.e("lsy"," PAGE_END");
// String pageName = arguments.get("page_name");
// String refererName = arguments.get("referrer");
// } else if (call.method.equals("CLICK_EVENT")) {
// Log.e("lsy"," CLICK_EVENT");
//
// String pageName = arguments.get("page_name");
// String buttonName = arguments.get("button_name");
// }else if(call.method.equals("FLUTTER_TO_H5")){
// Log.e("lsy"," FLUTTER_TO_H5");
//// String page_name = arguments.get("page_name");
//// Intent intent=new Intent(this, TempAct.class);
//// startActivity(intent);
// //TODO
// }else if(call.method.equals("FLUTTER_TO_SEARCH")){
//// Intent intent=new Intent(this, TempAct.class);
//// startActivity(intent);
// }
// else {
// result.notImplemented();
// }
// });
}
public void setStatusBar() {
if (isImageViewStatusBar()) {
//设置状态栏透明 为头部是 ImageView 的界面设置状态栏全透明
StatusBarUtil.transparencyBar(this);
} else {
//设置状态栏纯色 不加半透明效果 普通界面设置状态栏纯白色
StatusBarUtil.setColorNoTranslucent(this, ContextCompat.getColor(this, R.color.FFAA));
}
//设置状态栏黑色字体图标,适配4.4以上版本MIUIV、Flyme和6.0以上版本其他Android
StatusBarUtil.StatusBarLightMode(this, true, !isImageViewStatusBar());
//非小米,非魅族并且是5.0版本的适配
if (!StatusBarUtil.MIUISetStatusBarLightMode(getWindow(), true) && !StatusBarUtil.FlymeSetStatusBarLightMode(getWindow(), true) && (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP || Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1)) {
//设置状态栏纯色 不加半透明效果 普通界面设置状态栏灰色
StatusBarUtil.setColorNoTranslucent(this, ContextCompat.getColor(this, R.color.FFAA), true);
}
}
/**
* 设置MIUI状态栏
*/
private void setStatus() {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
/**
* 是否是头部是 ImageView 的界面设置状态栏
*
* @return
*/
public boolean isImageViewStatusBar() {
return false;
}
/**
* 是否需要设置StatusBar
*/
public boolean isSetUpStatusBar() {
return true;
}
/**
* 该方法返回当前Activity在Flutter层对应的name,
* 混合栈将会在flutter层根据这个名字,在注册的Route表中查找对应的Widget
* <p>
* 在flutter层有注册函数:
* FlutterBoost.singleton.registerPageBuilders({
* 'first': (pageName, params, _) => FirstRouteWidget(),
* 'second': (pageName, params, _) => SecondRouteWidget(),
* ...
* });
* <p>
* 该方法中返回的就是注册的key:first , second
*
* @return
*/
@Override
public String getContainerName() {
return name;
}
/**
* 该方法返回的参数将会传递给上层的flutter对应的Widget
* <p>
* 在flutter层有注册函数:
* FlutterBoost.singleton.registerPageBuilders({
* 'first': (pageName, params, _) => FirstRouteWidget(),
* 'second': (pageName, params, _) => SecondRouteWidget(),
* ...
* });
* <p>
* 该方法返回的参数就会封装成上面的params
*
* @return
*/
@Override
public Map getContainerParams() {
Map<String, Object> map = new HashMap<>();
// map.put("cookie", "sessionid=9odo0sov71x66ke9dlphibnq9i9gduxj; _gtid=3fbe9b78d2cb11e98bc1525400e82fab5270; _gm_token=db88861568285036");
map.put("cookie", "sessionid=i72bq75swus6okvk0k6aihbkb5s7g0hv; _gtid=51efc540de9411e9ac1f525400e82fab3414; _gm_token=1dd15b1569307596");
map.put("userId", "12345");
map.put("userName", "TTTTTTTTTT");
map.put("buildConfig", "debug");
map.put("fromPage", "fromm");
map.put("survey_record_id", "2");
map.put("template_id", "1");
map.put("needCamera", "0");
map.put("maxCount", "2");
return map;
}
}
package com.example.gmalpha_flutter.flutter.base;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import com.example.gmalpha_flutter.R;
import com.example.gmalpha_flutter.flutter.PageRouter;
public class NativePageActivity extends AppCompatActivity implements View.OnClickListener {
private TextView mOpenNative;
private TextView mOpenFlutter;
private TextView mOpenFlutterFragment;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.native_page);
mOpenNative = findViewById(R.id.open_native);
mOpenFlutter = findViewById(R.id.open_flutter);
mOpenFlutterFragment = findViewById(R.id.open_flutter_fragment);
mOpenNative.setOnClickListener(this);
mOpenFlutter.setOnClickListener(this);
mOpenFlutterFragment.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v == mOpenNative) {
PageRouter.openPageByUrl(this, PageRouter.NATIVE_PAGE_URL);
} else if (v == mOpenFlutter) {
PageRouter.openPageByUrl(this, PageRouter.FLUTTER_PAGE_URL);
} else if (v == mOpenFlutterFragment) {
PageRouter.openPageByUrl(this, PageRouter.FLUTTER_FRAGMENT_PAGE_URL);
}
}
}
\ No newline at end of file
package com.example.gmalpha_flutter.util;
import android.os.Build;
import android.text.TextUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @author apple
* @date 2019-09-19
*/
public class OSUtils {
public static final String ROM_MIUI = "MIUI";
public static final String ROM_EMUI = "EMUI";
public static final String ROM_FLYME = "FLYME";
public static final String ROM_OPPO = "OPPO";
public static final String ROM_SMARTISAN = "SMARTISAN";
public static final String ROM_VIVO = "VIVO";
public static final String ROM_QIKU = "QIKU";
private static final String KEY_VERSION_MIUI = "ro.miui.ui.version.name";
private static final String KEY_VERSION_EMUI = "ro.build.version.emui";
private static final String KEY_VERSION_OPPO = "ro.build.version.opporom";
private static final String KEY_VERSION_SMARTISAN = "ro.smartisan.version";
private static final String KEY_VERSION_VIVO = "ro.vivo.os.version";
private static String sName;
private static String sVersion;
public static boolean isEmui() {
return check(ROM_EMUI);
}
public static boolean isMiui() {
return check(ROM_MIUI);
}
public static boolean isVivo() {
return check(ROM_VIVO);
}
public static boolean isOppo() {
return check(ROM_OPPO);
}
public static boolean isFlyme() {
return check(ROM_FLYME);
}
public static boolean is360() {
return check(ROM_QIKU) || check("360");
}
public static boolean isSmartisan() {
return check(ROM_SMARTISAN);
}
public static String getName() {
if (sName == null) {
check("");
}
return sName;
}
public static String getVersion() {
if (sVersion == null) {
check("");
}
return sVersion;
}
public static boolean check(String rom) {
if (sName != null) {
return sName.equals(rom);
}
if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_MIUI))) {
sName = ROM_MIUI;
} else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_EMUI))) {
sName = ROM_EMUI;
} else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_OPPO))) {
sName = ROM_OPPO;
} else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_VIVO))) {
sName = ROM_VIVO;
} else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_SMARTISAN))) {
sName = ROM_SMARTISAN;
} else {
sVersion = Build.DISPLAY;
if (sVersion.toUpperCase().contains(ROM_FLYME)) {
sName = ROM_FLYME;
} else {
sVersion = Build.UNKNOWN;
sName = Build.MANUFACTURER.toUpperCase();
}
}
return sName.equals(rom);
}
public static String getProp(String name) {
String line = null;
BufferedReader input = null;
try {
Process p = Runtime.getRuntime().exec("getprop " + name);
input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
line = input.readLine();
input.close();
} catch (IOException ex) {
return null;
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return line;
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="FFAA">#CCFFFFFF</color>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<paths>
<!--path:需要临时授权访问的路径(.代表所有路径)-->
<!--name:就是你给这个访问路径起个名字-->
<external-path name="InstructiveRide" path="."/>
</paths>
\ No newline at end of file
......@@ -24,4 +24,9 @@ class BuriedImpl implements BuriedRouter {
referrer_tab_name: referrer_tab_name,
isPush: isPush);
}
@override
void onEvent(String type, Map<String, String> params) {
BuriedCenter.getInstance().onEvent(type, params);
}
}
......@@ -16,4 +16,6 @@ abstract class BuriedRouter extends RouterBaser {
String extra_param,
String referrer_tab_name,
String isPush});
void onEvent(String type, Map<String, String> params);
}
......@@ -39,6 +39,7 @@ class BuriedCenter {
if (page_name == null) {
print("$BURIED_TAG onPageStart page_name is null");
}
normalRequest.params.clear();
normalRequest.type = "page_view";
normalRequest.params["in"] = inPage ?? "";
normalRequest.params["out"] = outPage ?? "";
......@@ -51,4 +52,13 @@ class BuriedCenter {
normalRequest.params["isPush"] = isPush ?? "";
sendTask.sendBuried(normalRequest);
}
void onEvent(String type, Map<String, String> params) {
normalRequest.params.clear();
normalRequest.type = type;
if (params != null) {
normalRequest.params.addAll(params);
}
sendTask.sendBuried(normalRequest);
}
}
......@@ -99,6 +99,7 @@ class SendTask {
_appInfo.greyType =
CacheManager.getInstance().get(MEMORY_CACHE).get("grey_type") ?? "";
}
//TODO!!
_deviceInfo.netType =
CacheManager.getInstance().get(MEMORY_CACHE).get("net_type") ?? "";
request.userId =
......
......@@ -13,9 +13,7 @@ import 'package:gmalpha_flutter/messageModel/home/message_home.dart';
import 'comment_suggest.dart';
void main() async {
//create_at is_release
runApp(MyApp());
}
class MyApp extends StatefulWidget {
......@@ -85,27 +83,21 @@ class _MyAppState extends State<MyApp> {
return MaterialApp(
title: 'Flutter Boost example',
debugShowCheckedModeBanner: false,
// initialRoute: '/test',
//// 调试的时候可以打开
// routes: {
// // '/': (context) => CommentSuggest({"Cookie":" _gm_token=7e48641558699683; sessionid=nb3ze4ur7ucosln8sd8pzwojddenv9ym; _gtid=a1bc0a387e1911e996b9525400fa516d4094"}),
// '/': (context) {
//// Api.getInstance().initBuildConfig({
//// 'Cookie':
//// '_gm_token=72ee1c1569466411; _gtid=58d3cc14df8711e99736525400e82fab81; sessionid=vhksn66854pejzjwi8ljhrmcew3domh2',
//// "buildConfig": "debug"
//// });
//// return RouterCenterImpl()
//// .findActivityReportRouter()
//// ?.getActivityReportPage(279, 1, '');
routes: {
'/': (context) {
// Api.getInstance().initBuildConfig({
// 'Cookie':
// '_gm_token=72ee1c1569466411; _gtid=58d3cc14df8711e99736525400e82fab81; sessionid=vhksn66854pejzjwi8ljhrmcew3domh2',
// "buildConfig": "debug"
// });
// return RouterCenterImpl()
// .findAlbumRouter()
// .getAlbumPage("com.example.gengmei_flutter_plugin_example",true, 2, null);
// },
// },
//调试的时候可以打开
// .findActivityReportRouter()
// ?.getActivityReportPage(279, 1, '');
return RouterCenterImpl()
.findAlbumRouter()
.getAlbumPage("com.example.gengmei_flutter_plugin_example",true, 2, null);
},
},
builder: FlutterBoost.init(postPush: _onRoutePushed),
theme: new ThemeData(
primaryColor: Colors.white,
......
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