├── .gitignore ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── android ├── .gitignore ├── build.gradle ├── gradle.properties ├── settings.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ ├── com │ │ └── vdian │ │ │ └── flutter │ │ │ └── hybridrouter │ │ │ ├── FlutterManager.java │ │ │ ├── FlutterStackManagerUtil.java │ │ │ ├── HybridRouterPlugin.java │ │ │ ├── SafeMethodCallHandler.java │ │ │ ├── ScreenshotManager.java │ │ │ ├── engine │ │ │ └── FixFlutterView.java │ │ │ └── page │ │ │ ├── EmptyFlutterHook.java │ │ │ ├── EmptyFlutterWrapConfig.java │ │ │ ├── FlutterLaunchHelper.java │ │ │ ├── FlutterNativePageDelegate.java │ │ │ ├── FlutterRouteOptions.java │ │ │ ├── FlutterSplashView.java │ │ │ ├── HybridFlutterActivity.java │ │ │ ├── HybridFlutterFragment.java │ │ │ ├── IFlutterHook.java │ │ │ ├── IFlutterNativePage.java │ │ │ ├── IFlutterWrapConfig.java │ │ │ ├── IPageResultCallback.java │ │ │ └── NativeRouteOptions.java │ └── io │ │ └── flutter │ │ └── view │ │ └── FixAccessibilityBridge.java │ └── res │ └── anim │ ├── flutter_hybrid_enter_bottom.xml │ ├── flutter_hybrid_enter_left.xml │ ├── flutter_hybrid_enter_right.xml │ ├── flutter_hybrid_exit_left.xml │ └── flutter_hybrid_exit_right.xml ├── example ├── .flutter-plugins-dependencies ├── .gitignore ├── .metadata ├── README.md ├── android │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── vdian │ │ │ │ └── flutter │ │ │ │ └── hybridrouterexample │ │ │ │ ├── FlutterDemoApp.java │ │ │ │ ├── FlutterExampleActivity.java │ │ │ │ ├── IllegalResultActivity.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── NativeExampleActivity.java │ │ │ │ ├── TabExampleActivity.java │ │ │ │ └── translucent │ │ │ │ ├── NoTranslucentActivity.java │ │ │ │ ├── SetResultActivity.java │ │ │ │ └── TranslucentActivity.java │ │ │ └── res │ │ │ ├── drawable-v21 │ │ │ ├── bg_click_dark.xml │ │ │ └── bg_click_dark_mask.xml │ │ │ ├── drawable │ │ │ ├── bg_click_dark.xml │ │ │ ├── bg_click_dark_mask.xml │ │ │ ├── ic_svg_arrow_back_black_24dp.xml │ │ │ └── launch_background.xml │ │ │ ├── layout │ │ │ ├── activity_illegal_result.xml │ │ │ ├── activity_main.xml │ │ │ ├── activity_native_example.xml │ │ │ ├── activity_notranslucent.xml │ │ │ ├── activity_setresult.xml │ │ │ ├── activity_tab_example.xml │ │ │ ├── activity_translucent.xml │ │ │ └── rec_main_item.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ └── settings.gradle ├── ios │ ├── Flutter │ │ ├── AppFrameworkInfo.plist │ │ ├── Debug.xcconfig │ │ ├── Flutter.podspec │ │ ├── Release.xcconfig │ │ └── flutter_export_environment.sh │ ├── Podfile │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── Runner │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ ├── Icon-App-20x20@1x.png │ │ │ ├── Icon-App-20x20@2x.png │ │ │ ├── Icon-App-20x20@3x.png │ │ │ ├── Icon-App-29x29@1x.png │ │ │ ├── Icon-App-29x29@2x.png │ │ │ ├── Icon-App-29x29@3x.png │ │ │ ├── Icon-App-40x40@1x.png │ │ │ ├── Icon-App-40x40@2x.png │ │ │ ├── Icon-App-40x40@3x.png │ │ │ ├── Icon-App-60x60@2x.png │ │ │ ├── Icon-App-60x60@3x.png │ │ │ ├── Icon-App-76x76@1x.png │ │ │ ├── Icon-App-76x76@2x.png │ │ │ └── Icon-App-83.5x83.5@2x.png │ │ └── LaunchImage.imageset │ │ │ ├── Contents.json │ │ │ ├── LaunchImage.png │ │ │ ├── LaunchImage@2x.png │ │ │ ├── LaunchImage@3x.png │ │ │ └── README.md │ │ ├── Base.lproj │ │ └── LaunchScreen.storyboard │ │ ├── DemoViewController.h │ │ ├── DemoViewController.m │ │ ├── Info.plist │ │ ├── MyFlutterViewController.h │ │ ├── MyFlutterViewController.m │ │ └── main.m ├── lib │ ├── example.dart │ └── main.dart ├── pubspec.yaml └── test │ └── widget_test.dart ├── ios ├── .gitignore ├── Assets │ └── .gitkeep ├── Classes │ ├── WDFlutterEngine.h │ ├── WDFlutterEngine.m │ ├── WDFlutterEngineProvider.h │ ├── WDFlutterRouteEventHandler.h │ ├── WDFlutterRouteEventHandler.m │ ├── WDFlutterRouter.h │ ├── WDFlutterRouter.m │ ├── controller │ │ ├── WDFlutterPageLifeCircle.h │ │ ├── WDFlutterViewContainer+FlutterPage.h │ │ ├── WDFlutterViewContainer+FlutterPage.m │ │ ├── WDFlutterViewContainer.h │ │ ├── WDFlutterViewContainer.m │ │ ├── WDFlutterViewContainerManager.h │ │ └── WDFlutterViewContainerManager.m │ └── plugin │ │ ├── HybridRouterPlugin.h │ │ ├── HybridRouterPlugin.m │ │ ├── WDFlutterPluginRigstrant.h │ │ └── WDFlutterPluginRigstrant.m └── hybrid_router.podspec ├── lib ├── hybrid_router.dart └── src │ ├── hybrid_plugin.dart │ ├── manager.dart │ ├── model.dart │ ├── navigator.dart │ ├── observer.dart │ └── utils.dart └── pubspec.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | pubspec.lock 7 | 8 | build/ 9 | 10 | .idea/ 11 | *.iml 12 | .vscode 13 | 14 | .classpath 15 | .project 16 | .settings/ 17 | 18 | # flutter version manager 19 | fvm 20 | flutterw 21 | flutter -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 5391447fae6209bb21a89e6a5a6583cac1af9b4b 8 | channel: unknown 9 | 10 | project_type: plugin 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.0.1 2 | 3 | * init project 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | ----------- 3 | 4 | Copyright (c) 2019 WeiDian Group 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without 8 | restriction, including without limitation the rights to use, 9 | copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | OTHER DEALINGS IN THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hybrid_router 2 | 3 | 一个 Flutter 混合栈插件,无需修改业务中 `Navigator` 相关代码,可以帮你轻松的将 Flutter 混合栈能力加入到现有的 flutter 工程,你可以像开发原生 flutter app 一样开发混合栈 app 4 | 5 | # 特点 6 | * android 无需使用截图 7 | * 可以直接使用系统原生的 api,包括打开页面结果获取,入侵程度小 8 | * 支持原生的 Flutter 跳转方式(不借助 native 容器跳转) 9 | 10 | # Flutter SDK 要求 11 | master 分支需要 `v1.3.0` 以上,`v1.2.2` 无法工作(flutter engine android 部分有 bug)。如果你是使用 `v1.0.0` 版本的,请切换到 **support/v1.0.0** 分支,此分支下默认的 `pushNamed` 无法传递参数,不过可以使用混合栈的 `HybridNavigator` 12 | 13 | # Dart 集成 14 | ## 初始化 15 | ```dart 16 | void main() { 17 | // 创建 root navigator 需要的 observer,混合栈是根据此 observer 来完成 18 | // 一些生命周期监听的 19 | final GlobalKey managerKey = GlobalKey(); 20 | NativeContainerManager manager = HybridNavigator.init( 21 | key: managerKey, 22 | backgroundBuilder: (context) { 23 | return EmptyPage(); 24 | }, 25 | // 调用系统 api 的默认打开行为(通过新的 native 容器打开) 26 | defaultPushType: HybridPushType.Native, 27 | // 可以监听所有 HybridNavigator 中的 Route 28 | pageObserver: [], 29 | routes: { 30 | // 路由表 31 | "example": (context, argument) { 32 | return ExamplePage( 33 | title: argument as String, 34 | ); 35 | } 36 | }, 37 | // 404 页面 38 | unknownRouteBuilder: (RouteSettings settings) { 39 | return MaterialPageRoute( 40 | builder: (context) { 41 | return PageNotFound(); 42 | }, 43 | settings: settings, 44 | ); 45 | }); 46 | 47 | runApp(MaterialApp( 48 | theme: ThemeData( 49 | brightness: Brightness.light, 50 | ), 51 | // 这里设置 home 为 创建好的 manager 52 | home: manager, 53 | )); 54 | } 55 | ``` 56 | ## 使用 57 | ### 打开 Flutter 页面 58 | #### 1. 通过 `pushNamed` 跳转 59 | ```dart 60 | Navigator.of(context).pushNamed('example', arguments: 'message'); 61 | ``` 62 | #### 2. 通过 `push` 跳转 63 | ```dart 64 | Navigator.of(context).push( 65 | MaterialPageRoute( 66 | builder: (context) { 67 | return ExamplePage(title: "Jump from flutter",); 68 | } 69 | ) 70 | ); 71 | ``` 72 | ### 指定跳转方式(Native or Flutter) 73 | ```dart 74 | // 通过 push 指定跳转方式,需要使用 HybridPageRoute 75 | Navigator.of(context).push(HybridPageRoute( 76 | pushType: HybridPushType.Flutter, 77 | builder: (context) { 78 | return ExamplePage(title: 'Jump from flutter',); 79 | } 80 | )); 81 | // 使用 pushNamed 来实现指定,需要使用 HybridNavigator 82 | HybridNavigator.of(context).pushNamed('example', arguments: 'message', 83 | pushType: HybridPushType.Flutter); 84 | ``` 85 | ### 处理页面返回结果 86 | ```dart 87 | // 普通的 pop 就行 88 | Navigator.of(context).pop('message'); 89 | ``` 90 | ### 跳转到 Native 页面 91 | ```dart 92 | // 需要使用混合栈接口 93 | HybridNavigator.of(context) 94 | .openNativePage(url: 'https://www.baidu.com', args: 'message'); 95 | ``` 96 | 97 | 98 | # Android 集成 99 | ## 接入 100 | 初始化定制行为:用于定制一些行为,比如 Flutter 请求打开 native page route 的时候定制路由行为。不设置表示使用默认的配置 101 | ```java 102 | // 可以添加一些自定义的行为 103 | FlutterManager.getInstance().setFlutterWrapConfig(new EmptyFlutterWrapConfig() { 104 | 105 | @Override 106 | public void postFlutterApplyTheme(@NonNull IFlutterNativePage nativePage) { 107 | // 修改当前沉浸式主题的背景色为透明 108 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && 109 | nativePage.getContext() instanceof Activity) { 110 | Window window = ((Activity)nativePage.getContext()).getWindow(); 111 | window.setStatusBarColor(Color.TRANSPARENT); 112 | } 113 | } 114 | 115 | @Override 116 | public boolean onFlutterPageRoute(@NonNull IFlutterNativePage nativePage, 117 | @Nullable FlutterRouteOptions routeOptions, int requestCode) { 118 | // 自定义flutter 页面的跳转 119 | Intent intent = HybridFlutterActivity.newBuilder().route(routeOptions) 120 | .buildIntent(nativePage.getContext()); 121 | nativePage.startActivityForResult(intent, requestCode); 122 | return true; 123 | } 124 | }); 125 | ``` 126 | ## 使用 127 | ### 打开 flutter 页面 128 | ```java 129 | // example 为 flutter 中 routes 对应的 key 130 | Intent intent = HybridFlutterActivity.newBuilder() 131 | .route(new FlutterRouteOptions.Builder("example") 132 | .setArgs("Jump From Main").build()) 133 | .buildIntent(MainActivity.this); 134 | startActivity(intent); 135 | ``` 136 | 137 | # iOS 集成 138 | ## 初始化 139 | 初始化的时候设置WDFlutterRouter代理类 140 | ```objc 141 | /** 142 | 初始化 143 | 144 | @param delegate 实现的代理 145 | */ 146 | @property(nonatomic, weak) id delegate; 147 | ``` 148 | 在代理类中实现以下方法 149 | ```objc 150 | /** 151 | 返回导航对象的回调,用于打开flutter页面 152 | 153 | @return 导航对象 154 | */ 155 | - (UINavigationController *)appNavigationController; 156 | ``` 157 | ```objc 158 | /** 159 | flutter打开native页面的回调 160 | 161 | @param page native的页面名 162 | @param params 页面参数 163 | @parms type present/push 164 | */ 165 | - (void)openNativePage:(NSString *)page params:(id)params transitionType:(WDFlutterRouterTransitionType)type; 166 | ``` 167 | 可选的代理方法: 168 | ```objc 169 | /** 170 | 获取flutter页面的容器,可以通过继承WDFlutterViewContainer来定制容器。默认使用WDFlutterViewContainer。 171 | @return flutter页面容器 172 | */ 173 | - (WDFlutterViewContainer *)flutterViewContainer; 174 | ``` 175 | ## 使用 176 | ### 打开flutter页面 177 | ```objc 178 | /** 179 | 打开flutter页面 180 | 181 | @param page flutter页面名 182 | @param params 传给页面的参数 183 | @param result 页面返回时的回调 184 | */ 185 | + (void)openFlutterPage:(NSString *)page params:(NSDictionary *)params result:(void (^)(id))result; 186 | ``` 187 | 188 | # License 189 | This project is licensed under the MIT License - see the [LICENSE.md](LICENSE) file for details -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | group 'com.vdian.flutter.hybridrouter' 2 | version '1.0-SNAPSHOT' 3 | 4 | buildscript { 5 | ext.support_version = '28.0.0' 6 | repositories { 7 | google() 8 | jcenter() 9 | } 10 | 11 | dependencies { 12 | classpath 'com.android.tools.build:gradle:3.5.2' 13 | } 14 | } 15 | 16 | rootProject.allprojects { 17 | repositories { 18 | google() 19 | jcenter() 20 | } 21 | } 22 | 23 | apply plugin: 'com.android.library' 24 | 25 | android { 26 | compileSdkVersion 29 27 | 28 | defaultConfig { 29 | minSdkVersion 16 30 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 31 | } 32 | lintOptions { 33 | disable 'InvalidPackage' 34 | } 35 | 36 | resourcePrefix 'flutter_hybrid' 37 | } 38 | 39 | dependencies { 40 | api "androidx.appcompat:appcompat:1.1.0-rc01" 41 | compileOnly "android.arch.lifecycle:runtime:2.1.0" 42 | 43 | } 44 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'hybrid_router' 2 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /android/src/main/java/com/vdian/flutter/hybridrouter/SafeMethodCallHandler.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | 26 | package com.vdian.flutter.hybridrouter; 27 | 28 | 29 | import androidx.annotation.RestrictTo; 30 | 31 | import io.flutter.plugin.common.MethodCall; 32 | import io.flutter.plugin.common.MethodChannel; 33 | 34 | /** 35 | * ┏┛ ┻━━━━━┛ ┻┓ 36 | * ┃       ┃ 37 | * ┃   ━   ┃ 38 | * ┃ ┳┛  ┗┳ ┃ 39 | * ┃       ┃ 40 | * ┃   ┻   ┃ 41 | * ┃       ┃ 42 | * ┗━┓   ┏━━━┛ 43 | * * ┃   ┃ 神兽保佑 44 | * * ┃   ┃ 代码无BUG! 45 | * * ┃   ┗━━━━━━━━━┓ 46 | * * ┃        ┣┓ 47 | * * ┃     ┏┛ 48 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 49 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 50 | * * * ┗━┻━┛ ┗━┻━┛ 51 | * 52 | * @author qigengxin 53 | * @since 2019/2/5 2:00 PM 54 | */ 55 | @RestrictTo(RestrictTo.Scope.LIBRARY) 56 | abstract public class SafeMethodCallHandler implements MethodChannel.MethodCallHandler { 57 | 58 | /** 59 | * 安全的结果回调 60 | */ 61 | static class SafeResult implements MethodChannel.Result { 62 | final MethodChannel.Result result; 63 | 64 | SafeResult(MethodChannel.Result result) { 65 | this.result = result; 66 | } 67 | 68 | boolean isReturn = false; 69 | 70 | @Override 71 | public void success(Object result) { 72 | if (isReturn) { 73 | return; 74 | } 75 | isReturn = true; 76 | this.result.success(result); 77 | } 78 | 79 | @Override 80 | public void error(String errorCode, String errorMessage, Object errorDetail) { 81 | if (isReturn) { 82 | return; 83 | } 84 | isReturn = true; 85 | this.result.error(errorCode, errorMessage, errorDetail); 86 | } 87 | 88 | @Override 89 | public void notImplemented() { 90 | if (isReturn) { 91 | return; 92 | } 93 | isReturn = true; 94 | this.result.notImplemented(); 95 | } 96 | } 97 | 98 | @Override 99 | public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) { 100 | if (methodCall == null) { 101 | result.notImplemented(); 102 | return; 103 | } 104 | SafeResult sr = new SafeResult(result); 105 | try { 106 | // protect exception from method call 107 | onSafeMethodCall(methodCall, sr); 108 | } catch (Throwable throwable) { 109 | throwable.printStackTrace(); 110 | sr.error("-1", throwable.getMessage(), null); 111 | } 112 | } 113 | 114 | abstract protected void onSafeMethodCall(MethodCall methodCall, SafeResult result); 115 | } 116 | -------------------------------------------------------------------------------- /android/src/main/java/com/vdian/flutter/hybridrouter/ScreenshotManager.java: -------------------------------------------------------------------------------- 1 | package com.vdian.flutter.hybridrouter; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | 7 | import androidx.annotation.NonNull; 8 | import androidx.annotation.Nullable; 9 | import androidx.collection.LruCache; 10 | 11 | import java.io.File; 12 | import java.io.FileNotFoundException; 13 | import java.io.FileOutputStream; 14 | 15 | /** 16 | * ┏┛ ┻━━━━━┛ ┻┓ 17 | * ┃       ┃ 18 | * ┃   ━   ┃ 19 | * ┃ ┳┛  ┗┳ ┃ 20 | * ┃       ┃ 21 | * ┃   ┻   ┃ 22 | * ┃       ┃ 23 | * ┗━┓   ┏━━━┛ 24 | * * ┃   ┃ 神兽保佑 25 | * * ┃   ┃ 代码无BUG! 26 | * * ┃   ┗━━━━━━━━━┓ 27 | * * ┃        ┣┓ 28 | * * ┃     ┏┛ 29 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 30 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 31 | * * * ┗━┻━┛ ┗━┻━┛ 32 | * 33 | * 截图管理类,为了优化页面切换体验,提供截图显示占位图功能 34 | * 35 | * @author qigengxin 36 | * @since 2019-07-03 13:57 37 | */ 38 | public class ScreenshotManager { 39 | // 上下文 40 | private final Context appContext; 41 | /** 42 | * 是否启用文件缓存,暂时关闭 43 | * TODO 是否有必要启用文件缓存 44 | */ 45 | private final boolean enableFileCache = false; 46 | 47 | // 允许的 flutter 保存截图最大个数,默认是 2 48 | private LruCache screenshotCache = new LruCache(2) { 49 | @Override 50 | protected void entryRemoved(boolean evicted, @NonNull String key, 51 | @NonNull Bitmap oldValue, Bitmap newValue) { 52 | super.entryRemoved(evicted, key, oldValue, newValue); 53 | if (evicted) { 54 | // need save bitmap to local file 55 | saveBitmap(key, newValue); 56 | } 57 | } 58 | }; 59 | 60 | 61 | public ScreenshotManager(Context appContext) { 62 | this.appContext = appContext.getApplicationContext(); 63 | } 64 | 65 | /** 66 | * 设置 bitmap 缓存个数 67 | * @param maxSize bitmap 缓存个数 68 | */ 69 | public void setMaxSize(int maxSize) { 70 | maxSize = maxSize < 0 ? 0 : maxSize; 71 | if (maxSize != screenshotCache.maxSize()) { 72 | screenshotCache.resize(maxSize); 73 | } 74 | } 75 | 76 | /** 77 | * 添加截图管理 78 | * @param nativePageId 79 | * @param bitmap 80 | * @return 81 | */ 82 | public void addBitmap(String nativePageId, Bitmap bitmap) { 83 | screenshotCache.put(nativePageId, bitmap); 84 | } 85 | 86 | public Bitmap getBitmap(String nativePageId) { 87 | Bitmap bitmap = screenshotCache.get(nativePageId); 88 | if (bitmap == null) { 89 | bitmap = readBitmap(nativePageId); 90 | if (bitmap != null) { 91 | addBitmap(nativePageId, bitmap); 92 | } 93 | } 94 | return bitmap; 95 | } 96 | 97 | public void removeCache(String nativePageId) { 98 | screenshotCache.remove(nativePageId); 99 | deleteBitmap(nativePageId); 100 | } 101 | 102 | @Nullable 103 | private Bitmap readBitmap(String nativePageId) { 104 | if (!enableFileCache) return null; 105 | File dir = appContext.getExternalCacheDir(); 106 | if (dir != null && dir.exists()) { 107 | File imageFile = new File(dir, getSaveFile(nativePageId)); 108 | if (imageFile.exists()) { 109 | return BitmapFactory.decodeFile(imageFile.getAbsolutePath()); 110 | } 111 | } 112 | return null; 113 | } 114 | 115 | private void saveBitmap(String nativePageId, Bitmap bitmap) { 116 | if (!enableFileCache) return ; 117 | File dir = appContext.getExternalCacheDir(); 118 | if (dir != null && dir.exists()) { 119 | File imageFile = new File(dir, getSaveFile(nativePageId)); 120 | if (imageFile.getParentFile().mkdirs()) { 121 | try { 122 | FileOutputStream outputStream = new FileOutputStream(imageFile); 123 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream); 124 | } catch (FileNotFoundException ignore) { 125 | } 126 | } 127 | } 128 | } 129 | 130 | private void deleteBitmap(String nativePageId) { 131 | if (!enableFileCache) return ; 132 | File dir = appContext.getExternalCacheDir(); 133 | if (dir != null && dir.exists()) { 134 | File imageFile = new File(dir, getSaveFile(nativePageId)); 135 | if (imageFile.exists()) { 136 | imageFile.delete(); 137 | } 138 | } 139 | } 140 | 141 | private String getSaveFile(String nativePageId) { 142 | return new File("flutter_screen_shot", nativePageId).getPath(); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /android/src/main/java/com/vdian/flutter/hybridrouter/page/EmptyFlutterHook.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouter.page; 26 | 27 | 28 | import androidx.annotation.NonNull; 29 | 30 | import io.flutter.embedding.android.FlutterView; 31 | import io.flutter.embedding.engine.FlutterEngine; 32 | import io.flutter.plugin.common.PluginRegistry; 33 | 34 | /** 35 | * ┏┛ ┻━━━━━┛ ┻┓ 36 | * ┃       ┃ 37 | * ┃   ━   ┃ 38 | * ┃ ┳┛  ┗┳ ┃ 39 | * ┃       ┃ 40 | * ┃   ┻   ┃ 41 | * ┃       ┃ 42 | * ┗━┓   ┏━━━┛ 43 | * * ┃   ┃ 神兽保佑 44 | * * ┃   ┃ 代码无BUG! 45 | * * ┃   ┗━━━━━━━━━┓ 46 | * * ┃        ┣┓ 47 | * * ┃     ┏┛ 48 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 49 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 50 | * * * ┗━┻━┛ ┗━┻━┛ 51 | * 52 | * @author qigengxin 53 | * @since 2019-10-17 17:08 54 | */ 55 | public class EmptyFlutterHook implements IFlutterHook{ 56 | 57 | @Override 58 | public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { 59 | 60 | } 61 | 62 | @Override 63 | public void cleanUpFlutterEngine(@NonNull FlutterEngine flutterEngine) { 64 | 65 | } 66 | 67 | @Override 68 | public void onFlutterInitFailure(@NonNull Throwable error) { 69 | 70 | } 71 | 72 | @Override 73 | public void onRegisterPlugin(PluginRegistry pluginRegistry) { 74 | 75 | } 76 | 77 | @Override 78 | public void afterFlutterViewAttachToEngine(@NonNull FlutterView flutterView, @NonNull FlutterEngine flutterEngine) { 79 | 80 | } 81 | 82 | @Override 83 | public void beforeFlutterViewDetachFromEngine(@NonNull FlutterView flutterView, @NonNull FlutterEngine flutterEngine) { 84 | 85 | } 86 | 87 | @Override 88 | public void afterUpdateSystemUiOverlays(FlutterView flutterView) { 89 | 90 | } 91 | 92 | @Override 93 | public void onFirstFrameRendered(@NonNull FlutterView flutterView) { 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /android/src/main/java/com/vdian/flutter/hybridrouter/page/EmptyFlutterWrapConfig.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouter.page; 26 | 27 | import android.content.Intent; 28 | import android.os.Bundle; 29 | 30 | import androidx.annotation.NonNull; 31 | import androidx.annotation.Nullable; 32 | 33 | /** 34 | * ┏┛ ┻━━━━━┛ ┻┓ 35 | * ┃       ┃ 36 | * ┃   ━   ┃ 37 | * ┃ ┳┛  ┗┳ ┃ 38 | * ┃       ┃ 39 | * ┃   ┻   ┃ 40 | * ┃       ┃ 41 | * ┗━┓   ┏━━━┛ 42 | * * ┃   ┃ 神兽保佑 43 | * * ┃   ┃ 代码无BUG! 44 | * * ┃   ┗━━━━━━━━━┓ 45 | * * ┃        ┣┓ 46 | * * ┃     ┏┛ 47 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 48 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 49 | * * * ┗━┻━┛ ┗━┻━┛ 50 | * 51 | * @author qigengxin 52 | * @since 2019-04-25 15:22 53 | */ 54 | public class EmptyFlutterWrapConfig implements IFlutterWrapConfig { 55 | 56 | @Override 57 | public void postFlutterApplyTheme(@NonNull IFlutterNativePage nativePage) { 58 | 59 | } 60 | 61 | @Override 62 | public boolean onFlutterPageRoute(@NonNull IFlutterNativePage nativePage, 63 | @Nullable FlutterRouteOptions routeOptions, int requestCode) { 64 | return false; 65 | } 66 | 67 | @Override 68 | public boolean onNativePageRoute(@NonNull IFlutterNativePage nativePage, 69 | @NonNull NativeRouteOptions routeOptions, int requestCode) { 70 | return false; 71 | } 72 | 73 | @Override 74 | public FlutterRouteOptions parseFlutterRouteFromBundle(@NonNull IFlutterNativePage nativePage) { 75 | return null; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /android/src/main/java/com/vdian/flutter/hybridrouter/page/FlutterLaunchHelper.java: -------------------------------------------------------------------------------- 1 | package com.vdian.flutter.hybridrouter.page; 2 | 3 | import android.content.Intent; 4 | 5 | import androidx.annotation.NonNull; 6 | import androidx.annotation.Nullable; 7 | 8 | import io.flutter.embedding.engine.FlutterShellArgs; 9 | 10 | /** 11 | * ┏┛ ┻━━━━━┛ ┻┓ 12 | * ┃       ┃ 13 | * ┃   ━   ┃ 14 | * ┃ ┳┛  ┗┳ ┃ 15 | * ┃       ┃ 16 | * ┃   ┻   ┃ 17 | * ┃       ┃ 18 | * ┗━┓   ┏━━━┛ 19 | * * ┃   ┃ 神兽保佑 20 | * * ┃   ┃ 代码无BUG! 21 | * * ┃   ┗━━━━━━━━━┓ 22 | * * ┃        ┣┓ 23 | * * ┃     ┏┛ 24 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 25 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 26 | * * * ┗━┻━┛ ┗━┻━┛ 27 | * 28 | * launch flutter app 用的辅助类 29 | * 30 | * 混合栈的 activity 和 fragment 是自己开发的,但是 flutter_tools 用的还是原生的, 31 | * 这里需要匹配下原生 flutter_tools 的参数解析,像:--trace-skia。需要解析的 intent 32 | * 有以下几个类型: 33 | * * FlutterShellArgs 34 | * * AppBundlePath 35 | * * Dart enter point 36 | * * init route 37 | * 38 | * @author qigengxin 39 | * @since 2019-11-18 15:03 40 | */ 41 | public class FlutterLaunchHelper { 42 | 43 | /** 44 | * 从启动参数 intent 中解析出 flutter shell args 45 | */ 46 | @NonNull 47 | public static FlutterShellArgs parseFlutterShellArgs(@NonNull Intent intent) { 48 | return FlutterShellArgs.fromIntent(intent); 49 | } 50 | 51 | /** 52 | * 从启动参数中解析出当前的 dart main 函数入口 53 | */ 54 | @Nullable 55 | public static String getDartEntrypointName(@NonNull Intent intent) { 56 | if (intent.hasExtra("dart_entrypoint")) { 57 | return intent.getStringExtra("dart_entrypoint"); 58 | } 59 | return null; 60 | } 61 | 62 | /** 63 | * 从启动参数中解析当前 flutter 的启动路由 64 | */ 65 | @Nullable 66 | public static String getInitRoute(@NonNull Intent intent) { 67 | if (intent.hasExtra("initial_route")) { 68 | return intent.getStringExtra("initial_route"); 69 | } 70 | return null; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /android/src/main/java/com/vdian/flutter/hybridrouter/page/FlutterRouteOptions.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouter.page; 26 | 27 | import android.os.Parcel; 28 | import android.os.Parcelable; 29 | 30 | import androidx.annotation.NonNull; 31 | import androidx.annotation.Nullable; 32 | 33 | import java.io.Serializable; 34 | 35 | /** 36 | * ┏┛ ┻━━━━━┛ ┻┓ 37 | * ┃       ┃ 38 | * ┃   ━   ┃ 39 | * ┃ ┳┛  ┗┳ ┃ 40 | * ┃       ┃ 41 | * ┃   ┻   ┃ 42 | * ┃       ┃ 43 | * ┗━┓   ┏━━━┛ 44 | * * ┃   ┃ 神兽保佑 45 | * * ┃   ┃ 代码无BUG! 46 | * * ┃   ┗━━━━━━━━━┓ 47 | * * ┃        ┣┓ 48 | * * ┃     ┏┛ 49 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 50 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 51 | * * * ┗━┻━┛ ┗━┻━┛ 52 | *

53 | * 打开 flutter 页面需要的参数 54 | * 55 | * @author qigengxin 56 | * @since 2019/2/25 10:36 AM 57 | */ 58 | public class FlutterRouteOptions implements Parcelable { 59 | 60 | public static final FlutterRouteOptions home = new Builder("/").build(); 61 | 62 | // 默认的 切换动画 63 | public static final int TRANSITION_TYPE_DEFAULT = 0; 64 | // 底部弹出动画 65 | public static final int TRANSITION_TYPE_BOTTOM_TOP = 1; 66 | // 从右往左的动画 67 | public static final int TRANSITION_TYPE_RIGHT_LEFT = 2; 68 | 69 | 70 | protected FlutterRouteOptions(Parcel in) { 71 | pageName = in.readString(); 72 | args = in.readSerializable(); 73 | transitionType = in.readInt(); 74 | } 75 | 76 | public static final Creator CREATOR = new Creator() { 77 | @Override 78 | public FlutterRouteOptions createFromParcel(Parcel in) { 79 | return new FlutterRouteOptions(in); 80 | } 81 | 82 | @Override 83 | public FlutterRouteOptions[] newArray(int size) { 84 | return new FlutterRouteOptions[size]; 85 | } 86 | }; 87 | 88 | @Override 89 | public int describeContents() { 90 | return 0; 91 | } 92 | 93 | @Override 94 | public void writeToParcel(Parcel dest, int flags) { 95 | dest.writeString(pageName); 96 | if (args instanceof Serializable) { 97 | dest.writeSerializable((Serializable) args); 98 | } else { 99 | dest.writeSerializable(null); 100 | } 101 | dest.writeInt(transitionType); 102 | } 103 | 104 | public static class Builder { 105 | /** 106 | * 路由参数 107 | */ 108 | @Nullable 109 | Object args; 110 | 111 | /** 112 | * 当前 flutter 的路由名 113 | */ 114 | @NonNull 115 | String pageName; 116 | 117 | /** 118 | * 页面切换动画 119 | */ 120 | int transitionType = TRANSITION_TYPE_DEFAULT; 121 | 122 | public Builder(@NonNull String pageName) { 123 | this.pageName = pageName; 124 | } 125 | 126 | @Nullable 127 | public Object getArgs() { 128 | return args; 129 | } 130 | 131 | public Builder setArgs(@Nullable Object args) { 132 | this.args = args; 133 | return this; 134 | } 135 | 136 | @NonNull 137 | public String getPageName() { 138 | return pageName; 139 | } 140 | 141 | public Builder setPageName(@NonNull String pageName) { 142 | this.pageName = pageName; 143 | return this; 144 | } 145 | 146 | public int getTransitionType() { 147 | return transitionType; 148 | } 149 | 150 | /** 151 | * @param transitionType {@link Builder#TRANSITION_TYPE_DEFAULT} 152 | * @return 153 | */ 154 | public Builder setTransitionType(int transitionType) { 155 | this.transitionType = transitionType; 156 | return this; 157 | } 158 | 159 | public FlutterRouteOptions build() { 160 | return new FlutterRouteOptions( 161 | pageName, 162 | args, 163 | transitionType 164 | ); 165 | } 166 | } 167 | 168 | /** 169 | * 路由参数 170 | */ 171 | @Nullable 172 | public final Object args; 173 | 174 | /** 175 | * 当前 flutter 的路由名 176 | */ 177 | @NonNull 178 | public final String pageName; 179 | 180 | /** 181 | * native 页面切换动画 182 | * @link() 183 | */ 184 | public final int transitionType; 185 | 186 | public FlutterRouteOptions(@NonNull String pageName, @Nullable Object args, 187 | int transitionType) { 188 | this.args = args; 189 | this.pageName = pageName; 190 | this.transitionType = transitionType; 191 | } 192 | 193 | /** 194 | * 从当前参数复制一份 builder 195 | * @return 196 | */ 197 | public Builder withBuilder() { 198 | return new Builder(pageName) 199 | .setArgs(args) 200 | .setTransitionType(transitionType); 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /android/src/main/java/com/vdian/flutter/hybridrouter/page/FlutterSplashView.java: -------------------------------------------------------------------------------- 1 | package com.vdian.flutter.hybridrouter.page; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | import android.widget.FrameLayout; 8 | 9 | import androidx.annotation.NonNull; 10 | import androidx.annotation.Nullable; 11 | 12 | import io.flutter.embedding.android.FlutterView; 13 | import io.flutter.embedding.engine.FlutterEngine; 14 | import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener; 15 | 16 | /** 17 | * ┏┛ ┻━━━━━┛ ┻┓ 18 | * ┃       ┃ 19 | * ┃   ━   ┃ 20 | * ┃ ┳┛  ┗┳ ┃ 21 | * ┃       ┃ 22 | * ┃   ┻   ┃ 23 | * ┃       ┃ 24 | * ┗━┓   ┏━━━┛ 25 | * * ┃   ┃ 神兽保佑 26 | * * ┃   ┃ 代码无BUG! 27 | * * ┃   ┗━━━━━━━━━┓ 28 | * * ┃        ┣┓ 29 | * * ┃     ┏┛ 30 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 31 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 32 | * * * ┗━┻━┛ ┗━┻━┛ 33 | * 34 | * @author qigengxin 35 | * @since 2019-10-16 16:37 36 | */ 37 | public class FlutterSplashView extends FrameLayout { 38 | 39 | public FlutterSplashView(@NonNull Context context) { 40 | super(context); 41 | } 42 | 43 | public FlutterSplashView(@NonNull Context context, @Nullable AttributeSet attrs) { 44 | super(context, attrs); 45 | } 46 | 47 | public FlutterSplashView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 48 | super(context, attrs, defStyleAttr); 49 | } 50 | 51 | @TargetApi(21) 52 | public FlutterSplashView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { 53 | super(context, attrs, defStyleAttr, defStyleRes); 54 | } 55 | 56 | public void displayFlutterViewWithSplash( 57 | @NonNull FlutterView flutterView, View splashScreen) { 58 | // If we were displaying a previous FlutterView, remove it1 59 | if (this.flutterView != null) { 60 | this.flutterView.removeOnFirstFrameRenderedListener(firstFrameListener); 61 | removeView(this.flutterView); 62 | } 63 | 64 | // If we were displaying a previous splash screen view, remove it 65 | if (this.splashScreen != null) { 66 | removeView(this.splashScreen); 67 | } 68 | 69 | // Display the new FlutterView. 70 | this.flutterView = flutterView; 71 | addView(flutterView); 72 | 73 | this.splashScreen = splashScreen; 74 | 75 | // Display the new splash screen if needed. 76 | if (splashScreen != null) { 77 | if (isSplashScreenNeededNow(flutterView)) { 78 | addView(splashScreen); 79 | flutterView.addOnFirstFrameRenderedListener(firstFrameListener); 80 | } else if (!flutterView.isAttachedToFlutterEngine()) { 81 | flutterView.addFlutterEngineAttachmentListener(attachmentListener); 82 | } 83 | } 84 | } 85 | 86 | private View splashScreen; 87 | private FlutterView flutterView; 88 | 89 | private final FlutterUiDisplayListener firstFrameListener = new FlutterUiDisplayListener() { 90 | @Override 91 | public void onFlutterUiDisplayed() { 92 | transitionToFlutter(); 93 | } 94 | 95 | @Override 96 | public void onFlutterUiNoLongerDisplayed() { 97 | 98 | } 99 | }; 100 | 101 | private void transitionToFlutter() { 102 | if (splashScreen != null) { 103 | removeView(splashScreen); 104 | } 105 | } 106 | 107 | private final FlutterView.FlutterEngineAttachmentListener attachmentListener = 108 | new FlutterView.FlutterEngineAttachmentListener() { 109 | @Override 110 | public void onFlutterEngineAttachedToFlutterView(@NonNull FlutterEngine flutterEngine) { 111 | flutterView.removeFlutterEngineAttachmentListener(this); 112 | displayFlutterViewWithSplash(flutterView, splashScreen); 113 | } 114 | 115 | @Override 116 | public void onFlutterEngineDetachedFromFlutterView() { 117 | } 118 | }; 119 | 120 | /** 121 | * Returns true if current conditions require a splash UI to be displayed. 122 | *

123 | * This method does not evaluate whether a previously interrupted splash transition needs 124 | * to resume 125 | */ 126 | private boolean isSplashScreenNeededNow(@NonNull FlutterView flutterView) { 127 | return flutterView.isAttachedToFlutterEngine() 128 | && !flutterView.hasRenderedFirstFrame(); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /android/src/main/java/com/vdian/flutter/hybridrouter/page/IFlutterHook.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouter.page; 26 | 27 | 28 | import androidx.annotation.NonNull; 29 | 30 | import io.flutter.embedding.android.FlutterView; 31 | import io.flutter.embedding.engine.FlutterEngine; 32 | import io.flutter.plugin.common.PluginRegistry; 33 | import io.flutter.plugin.platform.PlatformPlugin; 34 | 35 | /** 36 | * ┏┛ ┻━━━━━┛ ┻┓ 37 | * ┃       ┃ 38 | * ┃   ━   ┃ 39 | * ┃ ┳┛  ┗┳ ┃ 40 | * ┃       ┃ 41 | * ┃   ┻   ┃ 42 | * ┃       ┃ 43 | * ┗━┓   ┏━━━┛ 44 | * * ┃   ┃ 神兽保佑 45 | * * ┃   ┃ 代码无BUG! 46 | * * ┃   ┗━━━━━━━━━┓ 47 | * * ┃        ┣┓ 48 | * * ┃     ┏┛ 49 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 50 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 51 | * * * ┗━┻━┛ ┗━┻━┛ 52 | * 53 | * Flutter engine hook 54 | * 55 | * @author qigengxin 56 | * @since 2019-10-16 16:15 57 | */ 58 | public interface IFlutterHook { 59 | 60 | 61 | /** 62 | * Hook for the host to configure the {@link FlutterEngine} as desired. 63 | */ 64 | void configureFlutterEngine(@NonNull FlutterEngine flutterEngine); 65 | 66 | /** 67 | * Hook for the host to cleanup references that were established in 68 | * {@link #configureFlutterEngine(FlutterEngine)} before the host is destroyed or detached. 69 | */ 70 | void cleanUpFlutterEngine(@NonNull FlutterEngine flutterEngine); 71 | 72 | /** 73 | * flutter engine initialize error 74 | */ 75 | void onFlutterInitFailure(@NonNull Throwable error); 76 | 77 | /** 78 | * This method will invoke after register GeneratedPluginRegistrant 79 | * @param pluginRegistry 80 | */ 81 | void onRegisterPlugin(PluginRegistry pluginRegistry); 82 | 83 | /** 84 | * This method will invoke after flutterView attach to flutter engine. 85 | */ 86 | void afterFlutterViewAttachToEngine(@NonNull FlutterView flutterView, 87 | @NonNull FlutterEngine flutterEngine); 88 | 89 | /** 90 | * This method will invoke before flutterView detach from flutter engine. 91 | */ 92 | void beforeFlutterViewDetachFromEngine(@NonNull FlutterView flutterView, 93 | @NonNull FlutterEngine flutterEngine); 94 | 95 | 96 | /** 97 | * This method will invoke after {@link PlatformPlugin#updateSystemUiOverlays()} 98 | * @param flutterView 99 | */ 100 | void afterUpdateSystemUiOverlays(FlutterView flutterView); 101 | 102 | /** 103 | * FlutterView 首帧渲染完毕 104 | */ 105 | void onFirstFrameRendered(@NonNull FlutterView flutterView); 106 | } 107 | -------------------------------------------------------------------------------- /android/src/main/java/com/vdian/flutter/hybridrouter/page/IFlutterNativePage.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouter.page; 26 | 27 | import android.app.Activity; 28 | import android.content.Context; 29 | import android.content.Intent; 30 | import android.view.View; 31 | 32 | import androidx.annotation.NonNull; 33 | import androidx.annotation.Nullable; 34 | import androidx.lifecycle.Lifecycle; 35 | 36 | import java.util.Map; 37 | 38 | import io.flutter.embedding.android.FlutterView; 39 | import io.flutter.embedding.engine.FlutterEngine; 40 | import io.flutter.embedding.engine.FlutterShellArgs; 41 | import io.flutter.plugin.common.MethodChannel; 42 | import io.flutter.plugin.platform.PlatformPlugin; 43 | 44 | /** 45 | * ┏┛ ┻━━━━━┛ ┻┓ 46 | * ┃       ┃ 47 | * ┃   ━   ┃ 48 | * ┃ ┳┛  ┗┳ ┃ 49 | * ┃       ┃ 50 | * ┃   ┻   ┃ 51 | * ┃       ┃ 52 | * ┗━┓   ┏━━━┛ 53 | * * ┃   ┃ 神兽保佑 54 | * * ┃   ┃ 代码无BUG! 55 | * * ┃   ┗━━━━━━━━━┓ 56 | * * ┃        ┣┓ 57 | * * ┃     ┏┛ 58 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 59 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 60 | * * * ┗━┻━┛ ┗━┻━┛ 61 | * 62 | * @author qigengxin 63 | * @since 2019/2/5 2:13 PM 64 | */ 65 | public interface IFlutterNativePage { 66 | /** 67 | * 是否 attach 到了 flutter engine 68 | */ 69 | boolean isAttachToFlutter(); 70 | 71 | /** 72 | * request attach to flutter 73 | * 1.12.13开始 把attach放到了resume,因为官方的bug ,导致engine.isResume 之前attachEngine会引起无法渲染的bug 74 | */ 75 | void attachFlutter(); 76 | 77 | /** 78 | * request detach from flutter 79 | */ 80 | void detachFlutter(); 81 | 82 | /** 83 | * 请求 flutter native view 断开与 window 的连接 84 | */ 85 | void requestDetachFromWindow(); 86 | 87 | /** 88 | * 页面收到新的 intent 信息 89 | * @param intent 90 | */ 91 | void onNewIntent(Intent intent); 92 | 93 | /** 94 | * flutter 内 请求打开 native page 95 | */ 96 | void openNativePage(@NonNull NativeRouteOptions routeOptions, @NonNull MethodChannel.Result result); 97 | 98 | /** 99 | * flutter 内请求通过一个新的 native 页面打开一个 flutter 页面 100 | * @param routeOptions 打开 flutter 页面需要的路由参数 101 | * @param result channel 回调方法 102 | */ 103 | void openFlutterPage(@NonNull FlutterRouteOptions routeOptions, @NonNull MethodChannel.Result result); 104 | 105 | /** 106 | * flutter 请求结束 native 页面 107 | */ 108 | void finishNativePage(@Nullable Object result); 109 | 110 | /** 111 | * 获取 native page id,传给 flutter 绑定关键用 112 | */ 113 | String getNativePageId(); 114 | 115 | /** 116 | * 获取初始路由 117 | */ 118 | Map getInitRoute(); 119 | 120 | /** 121 | * 通过一个 channel 生成一个 result code 122 | * @param result 123 | * @return 124 | */ 125 | int generateRequestCodeByChannel(MethodChannel.Result result); 126 | 127 | /** 128 | * 通过 page result callback 生成一个 request code 129 | * @param callback 130 | * @return 131 | */ 132 | int generateRequestCodeByCallback(@NonNull IPageResultCallback callback); 133 | 134 | /** 135 | * 打开一个第三方页面 136 | * @param intent 137 | * @param requestCode 138 | */ 139 | void startActivityForResult(Intent intent, int requestCode); 140 | 141 | /** 142 | * 获取当前页面的上下文环境, 如果当前容器是 activity 的话这里就是本身 143 | * @return 144 | */ 145 | @Nullable 146 | Context getContext(); 147 | 148 | 149 | /** 150 | * 获取当前页面所在的 activity,如果当前容器是 activity 的话这里就是本身 151 | * @return 152 | */ 153 | @Nullable 154 | Activity getActivity(); 155 | 156 | 157 | /** 158 | * 获取到当前页面的路由信息 159 | * must call after onCreate 160 | */ 161 | FlutterRouteOptions getStartRouteOptions(); 162 | 163 | /** 164 | * Returns the {@link Lifecycle} that backs the host {@link Activity} or {@code Fragment}. 165 | */ 166 | @NonNull 167 | Lifecycle getLifecycle(); 168 | 169 | /** 170 | * flutter route 事件 171 | * @param name 172 | * @param eventId 173 | */ 174 | void onFlutterRouteEvent(String name, int eventId, Map extra); 175 | 176 | /** 177 | * 当前页面是否是一个 tab 页面 178 | * 这里要注意下 fragment默认写死的true 179 | */ 180 | boolean isTab(); 181 | 182 | /** 183 | * Returns the {@link FlutterShellArgs} that should be used when initializing Flutter. 184 | */ 185 | @NonNull 186 | FlutterShellArgs getFlutterShellArgs(); 187 | 188 | /** 189 | * Returns the Dart entrypoint that should run when a new {@link FlutterEngine} is 190 | * created. 191 | */ 192 | @NonNull 193 | String getDartEntrypointFunctionName(); 194 | 195 | /** 196 | * Returns the path to the app bundle where the Dart code exists. 197 | */ 198 | @NonNull 199 | String getAppBundlePath(); 200 | 201 | /** 202 | * Returns the {@link FlutterView.RenderMode} used by the {@link FlutterView} that 203 | * displays the {@link FlutterEngine}'s content. 204 | */ 205 | @NonNull 206 | FlutterView.RenderMode getRenderMode(); 207 | 208 | /** 209 | * Returns the {@link FlutterView.TransparencyMode} used by the {@link FlutterView} that 210 | * displays the {@link FlutterEngine}'s content. 211 | */ 212 | @NonNull 213 | FlutterView.TransparencyMode getTransparencyMode(); 214 | 215 | /** 216 | * Hook for the host to create/provide a {@link PlatformPlugin} if the associated 217 | * Flutter experience should control system chrome. 218 | */ 219 | @Nullable 220 | PlatformPlugin providePlatformPlugin(@Nullable Activity activity, @NonNull FlutterEngine flutterEngine); 221 | 222 | @Nullable 223 | View provideSplashScreen(); 224 | } 225 | -------------------------------------------------------------------------------- /android/src/main/java/com/vdian/flutter/hybridrouter/page/IFlutterWrapConfig.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouter.page; 26 | 27 | import android.content.Intent; 28 | import android.os.Bundle; 29 | 30 | import androidx.annotation.NonNull; 31 | import androidx.annotation.Nullable; 32 | 33 | /** 34 | * ┏┛ ┻━━━━━┛ ┻┓ 35 | * ┃       ┃ 36 | * ┃   ━   ┃ 37 | * ┃ ┳┛  ┗┳ ┃ 38 | * ┃       ┃ 39 | * ┃   ┻   ┃ 40 | * ┃       ┃ 41 | * ┗━┓   ┏━━━┛ 42 | * * ┃   ┃ 神兽保佑 43 | * * ┃   ┃ 代码无BUG! 44 | * * ┃   ┗━━━━━━━━━┓ 45 | * * ┃        ┣┓ 46 | * * ┃     ┏┛ 47 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 48 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 49 | * * * ┗━┻━┛ ┗━┻━┛ 50 | * 51 | * flutter wrap activity 的一些配置信息 52 | * 53 | * @author qigengxin 54 | * @since 2019/3/23 3:29 PM 55 | */ 56 | public interface IFlutterWrapConfig { 57 | 58 | /** 59 | * 在 flutter 更新 native 状态栏主题之后调用 60 | */ 61 | void postFlutterApplyTheme(@NonNull IFlutterNativePage nativePage); 62 | 63 | /** 64 | * 请求打开 flutter page route 65 | * @param routeOptions 66 | * @param requestCode 67 | */ 68 | boolean onFlutterPageRoute(@NonNull IFlutterNativePage nativePage, 69 | @NonNull FlutterRouteOptions routeOptions, int requestCode); 70 | 71 | /** 72 | * 请求打开 native 页面 73 | * @param routeOptions 74 | * @param requestCode 75 | */ 76 | boolean onNativePageRoute(@NonNull IFlutterNativePage nativePage, 77 | @NonNull NativeRouteOptions routeOptions, int requestCode); 78 | 79 | /** 80 | * 从 FlutterNativePage 中解析 flutterRouteOptions 81 | */ 82 | @Nullable 83 | FlutterRouteOptions parseFlutterRouteFromBundle(@NonNull IFlutterNativePage nativePage); 84 | } 85 | -------------------------------------------------------------------------------- /android/src/main/java/com/vdian/flutter/hybridrouter/page/IPageResultCallback.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouter.page; 26 | 27 | import android.content.Intent; 28 | 29 | /** 30 | * ┏┛ ┻━━━━━┛ ┻┓ 31 | * ┃       ┃ 32 | * ┃   ━   ┃ 33 | * ┃ ┳┛  ┗┳ ┃ 34 | * ┃       ┃ 35 | * ┃   ┻   ┃ 36 | * ┃       ┃ 37 | * ┗━┓   ┏━━━┛ 38 | * * ┃   ┃ 神兽保佑 39 | * * ┃   ┃ 代码无BUG! 40 | * * ┃   ┗━━━━━━━━━┓ 41 | * * ┃        ┣┓ 42 | * * ┃     ┏┛ 43 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 44 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 45 | * * * ┗━┻━┛ ┗━┻━┛ 46 | * 47 | * 页面数据回调 48 | * 49 | * @author qigengxin 50 | * @since 2019/3/25 7:10 PM 51 | */ 52 | public interface IPageResultCallback { 53 | void onPageResult(int requestCode, int resultCode, Intent data); 54 | } 55 | -------------------------------------------------------------------------------- /android/src/main/java/com/vdian/flutter/hybridrouter/page/NativeRouteOptions.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouter.page; 26 | 27 | 28 | import androidx.annotation.NonNull; 29 | import androidx.annotation.Nullable; 30 | 31 | import java.util.Map; 32 | 33 | /** 34 | * ┏┛ ┻━━━━━┛ ┻┓ 35 | * ┃       ┃ 36 | * ┃   ━   ┃ 37 | * ┃ ┳┛  ┗┳ ┃ 38 | * ┃       ┃ 39 | * ┃   ┻   ┃ 40 | * ┃       ┃ 41 | * ┗━┓   ┏━━━┛ 42 | * * ┃   ┃ 神兽保佑 43 | * * ┃   ┃ 代码无BUG! 44 | * * ┃   ┗━━━━━━━━━┓ 45 | * * ┃        ┣┓ 46 | * * ┃     ┏┛ 47 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 48 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 49 | * * * ┗━┻━┛ ┗━┻━┛ 50 | * 51 | * flutter 请求打开 native 页面需要的 参数 52 | * 53 | * @author qigengxin 54 | * @since 2019/2/28 10:54 AM 55 | */ 56 | public class NativeRouteOptions { 57 | 58 | public static class Builder { 59 | 60 | /** 61 | * 路由地址 62 | */ 63 | @NonNull 64 | String url; 65 | 66 | /** 67 | * 路由参数 68 | */ 69 | @Nullable 70 | Map args; 71 | 72 | /** 73 | * 切换动画类型 74 | * {@link FlutterRouteOptions#TRANSITION_TYPE_DEFAULT} 75 | */ 76 | int transitionType; 77 | 78 | @NonNull 79 | public String getUrl() { 80 | return url; 81 | } 82 | 83 | public Builder setUrl(@NonNull String url) { 84 | this.url = url; 85 | return this; 86 | } 87 | 88 | @Nullable 89 | public Map getArgs() { 90 | return args; 91 | } 92 | 93 | public Builder setArgs(@Nullable Map args) { 94 | this.args = args; 95 | return this; 96 | } 97 | 98 | public int getTransitionType() { 99 | return transitionType; 100 | } 101 | 102 | public Builder setTransitionType(int transitionType) { 103 | this.transitionType = transitionType; 104 | return this; 105 | } 106 | 107 | public NativeRouteOptions build() { 108 | return new NativeRouteOptions( 109 | url, args, transitionType 110 | ); 111 | } 112 | } 113 | 114 | public NativeRouteOptions(@NonNull String url, @Nullable Map args, int transitionType) { 115 | this.url = url; 116 | this.args = args; 117 | this.transitionType = transitionType; 118 | } 119 | 120 | /** 121 | * 路由地址 122 | */ 123 | @NonNull 124 | public final String url; 125 | 126 | /** 127 | * 路由参数 128 | */ 129 | @Nullable 130 | public final Map args; 131 | 132 | /** 133 | * 切换动画类型 134 | * {@link #TRANSITION_TYPE_DEFAULT} 135 | */ 136 | public final int transitionType; 137 | } 138 | -------------------------------------------------------------------------------- /android/src/main/java/io/flutter/view/FixAccessibilityBridge.java: -------------------------------------------------------------------------------- 1 | package io.flutter.view; 2 | 3 | import android.content.ContentResolver; 4 | import android.view.View; 5 | import android.view.accessibility.AccessibilityManager; 6 | 7 | import androidx.annotation.NonNull; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import io.flutter.embedding.engine.systemchannels.AccessibilityChannel; 12 | import io.flutter.plugin.platform.PlatformViewsAccessibilityDelegate; 13 | 14 | public class FixAccessibilityBridge extends AccessibilityBridge { 15 | public FixAccessibilityBridge(@NonNull View rootAccessibilityView, @NonNull AccessibilityChannel accessibilityChannel, @NonNull AccessibilityManager accessibilityManager, @NonNull ContentResolver contentResolver, PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) { 16 | super(rootAccessibilityView, accessibilityChannel, accessibilityManager, contentResolver, platformViewsAccessibilityDelegate); 17 | } 18 | 19 | @Override 20 | public boolean isAccessibilityEnabled() { 21 | return false; 22 | } 23 | 24 | @Override 25 | public boolean isTouchExplorationEnabled() { 26 | return false; 27 | } 28 | 29 | @Override 30 | void updateSemantics(@NonNull ByteBuffer buffer, @NonNull String[] strings) { 31 | // do nothing 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /android/src/main/res/anim/flutter_hybrid_enter_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /android/src/main/res/anim/flutter_hybrid_enter_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /android/src/main/res/anim/flutter_hybrid_enter_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | -------------------------------------------------------------------------------- /android/src/main/res/anim/flutter_hybrid_exit_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /android/src/main/res/anim/flutter_hybrid_exit_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | -------------------------------------------------------------------------------- /example/.flutter-plugins-dependencies: -------------------------------------------------------------------------------- 1 | {"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"hybrid_router","dependencies":[]}]} -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.lock 4 | *.log 5 | *.pyc 6 | *.swp 7 | .DS_Store 8 | .atom/ 9 | .buildlog/ 10 | .history 11 | .svn/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # Visual Studio Code related 20 | .vscode/ 21 | 22 | # Flutter/Dart/Pub related 23 | **/doc/api/ 24 | .dart_tool/ 25 | .flutter-plugins 26 | .flutter-plugins-dependencies 27 | .packages 28 | .pub-cache/ 29 | .pub/ 30 | build/ 31 | 32 | # Android related 33 | **/android/**/gradle-wrapper.jar 34 | **/android/.gradle 35 | **/android/captures/ 36 | **/android/gradlew 37 | **/android/gradlew.bat 38 | **/android/local.properties 39 | **/android/**/GeneratedPluginRegistrant.java 40 | 41 | # iOS/XCode related 42 | **/ios/**/*.mode1v3 43 | **/ios/**/*.mode2v3 44 | **/ios/**/*.moved-aside 45 | **/ios/**/*.pbxuser 46 | **/ios/**/*.perspectivev3 47 | **/ios/**/*sync/ 48 | **/ios/**/.sconsign.dblite 49 | **/ios/**/.tags* 50 | **/ios/**/.vagrant/ 51 | **/ios/**/DerivedData/ 52 | **/ios/**/Icon? 53 | **/ios/**/Pods/ 54 | **/ios/**/.symlinks/ 55 | **/ios/**/profile 56 | **/ios/**/xcuserdata 57 | **/ios/.generated/ 58 | **/ios/Flutter/App.framework 59 | **/ios/Flutter/Flutter.framework 60 | **/ios/Flutter/Generated.xcconfig 61 | **/ios/Flutter/flutter_export_environment.sh 62 | **/ios/Flutter/app.flx 63 | **/ios/Flutter/app.zip 64 | **/ios/Flutter/flutter_assets/ 65 | **/ios/ServiceDefinitions.json 66 | **/ios/Runner/GeneratedPluginRegistrant.* 67 | 68 | # Exceptions to above rules. 69 | !**/ios/**/default.mode1v3 70 | !**/ios/**/default.mode2v3 71 | !**/ios/**/default.pbxuser 72 | !**/ios/**/default.perspectivev3 73 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 74 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 5391447fae6209bb21a89e6a5a6583cac1af9b4b 8 | channel: unknown 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # hybrid_router_example 2 | 3 | Demonstrates how to use the hybrid_router plugin. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://flutter.io/docs/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://flutter.io/docs/cookbook) 13 | 14 | For help getting started with Flutter, view our 15 | [online documentation](https://flutter.io/docs), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 26 | 27 | android { 28 | compileSdkVersion 29 29 | 30 | lintOptions { 31 | disable 'InvalidPackage' 32 | } 33 | 34 | defaultConfig { 35 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 36 | applicationId "com.vdian.flutter.hybridrouterxample" 37 | minSdkVersion 16 38 | targetSdkVersion 28 39 | versionCode flutterVersionCode.toInteger() 40 | versionName flutterVersionName 41 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 42 | } 43 | 44 | buildTypes { 45 | release { 46 | // TODO: Add your own signing config for the release build. 47 | // Signing with the debug keys for now, so `flutter run --release` works. 48 | signingConfig signingConfigs.debug 49 | } 50 | } 51 | 52 | // Configure only for each module that uses Java 8 53 | // language features (either in its source code or 54 | // through dependencies). 55 | compileOptions { 56 | sourceCompatibility JavaVersion.VERSION_1_8 57 | targetCompatibility JavaVersion.VERSION_1_8 58 | } 59 | } 60 | 61 | flutter { 62 | source '../..' 63 | } 64 | 65 | dependencies { 66 | testImplementation 'junit:junit:4.12' 67 | androidTestImplementation "androidx.test:runner:1.1.0" 68 | androidTestImplementation "androidx.test.espresso:espresso-core:3.1.0" 69 | implementation "androidx.appcompat:appcompat:1.1.0-rc01" 70 | implementation "androidx.constraintlayout:constraintlayout:1.1.3" 71 | implementation "androidx.lifecycle:lifecycle-common-java8:2.0.0" 72 | def voiddog_android_lib_version = 'v0.0.6' 73 | implementation "com.github.voiddog.AndroidLib:baselib:${voiddog_android_lib_version}" 74 | implementation "com.github.voiddog.AndroidLib:designlib:${voiddog_android_lib_version}" 75 | implementation "com.github.voiddog.AndroidLib:rxlib:${voiddog_android_lib_version}" 76 | } 77 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 10 | 11 | 12 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 44 | 45 | 46 | 47 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/vdian/flutter/hybridrouterexample/FlutterDemoApp.java: -------------------------------------------------------------------------------- 1 | package com.vdian.flutter.hybridrouterexample; 2 | 3 | import android.app.Activity; 4 | import android.app.Application; 5 | import android.content.Intent; 6 | import android.graphics.Color; 7 | import android.os.Build; 8 | import androidx.annotation.NonNull; 9 | import androidx.annotation.Nullable; 10 | import android.view.Window; 11 | 12 | import com.vdian.flutter.hybridrouter.FlutterManager; 13 | import com.vdian.flutter.hybridrouter.page.EmptyFlutterWrapConfig; 14 | import com.vdian.flutter.hybridrouter.page.FlutterRouteOptions; 15 | import com.vdian.flutter.hybridrouter.page.IFlutterNativePage; 16 | 17 | import io.flutter.view.FlutterMain; 18 | 19 | /** 20 | * ┏┛ ┻━━━━━┛ ┻┓ 21 | * ┃       ┃ 22 | * ┃   ━   ┃ 23 | * ┃ ┳┛  ┗┳ ┃ 24 | * ┃       ┃ 25 | * ┃   ┻   ┃ 26 | * ┃       ┃ 27 | * ┗━┓   ┏━━━┛ 28 | * * ┃   ┃ 神兽保佑 29 | * * ┃   ┃ 代码无BUG! 30 | * * ┃   ┗━━━━━━━━━┓ 31 | * * ┃        ┣┓ 32 | * * ┃     ┏┛ 33 | * * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛ 34 | * * * ┃ ┫ ┫ ┃ ┫ ┫ 35 | * * * ┗━┻━┛ ┗━┻━┛ 36 | * 37 | * @author qigengxin 38 | * @since 2019/2/11 12:08 PM 39 | */ 40 | public class FlutterDemoApp extends Application { 41 | @Override 42 | public void onCreate() { 43 | super.onCreate(); 44 | // 提前初始化 45 | FlutterMain.startInitialization(this); 46 | // 可以添加一些自定义的行为 47 | FlutterManager.getInstance().setFlutterWrapConfig(new EmptyFlutterWrapConfig() { 48 | 49 | @Override 50 | public void postFlutterApplyTheme(@NonNull IFlutterNativePage nativePage) { 51 | // 修改当前沉浸式主题的背景色为透明 52 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && 53 | nativePage.getContext() instanceof Activity) { 54 | Window window = ((Activity) nativePage.getContext()).getWindow(); 55 | window.setStatusBarColor(Color.TRANSPARENT); 56 | } 57 | } 58 | 59 | @Override 60 | public boolean onFlutterPageRoute(@NonNull IFlutterNativePage nativePage, 61 | @Nullable FlutterRouteOptions routeOptions, int requestCode) { 62 | // 自定义flutter 页面的跳转 63 | Intent intent = FlutterExampleActivity.builder().route(routeOptions) 64 | .buildIntent(nativePage.getContext()); 65 | nativePage.startActivityForResult(intent, requestCode); 66 | return true; 67 | } 68 | }); 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/vdian/flutter/hybridrouterexample/FlutterExampleActivity.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouterexample; 26 | 27 | import android.os.Build; 28 | import android.os.Bundle; 29 | import androidx.annotation.NonNull; 30 | import androidx.annotation.Nullable; 31 | import android.util.Log; 32 | 33 | import com.vdian.flutter.hybridrouter.page.HybridFlutterActivity; 34 | import com.vdian.flutter.hybridrouter.page.IFlutterHook; 35 | 36 | import io.flutter.embedding.android.FlutterView; 37 | import io.flutter.embedding.engine.FlutterEngine; 38 | import io.flutter.plugin.common.PluginRegistry; 39 | 40 | public class FlutterExampleActivity extends HybridFlutterActivity implements IFlutterHook { 41 | public static final String TAG = "FlutterLifecycle" + Build.VERSION.SDK_INT; 42 | 43 | public static FlutterExampleActivity.IntentBuilder builder() { 44 | return new FlutterExampleActivity.IntentBuilder(); 45 | } 46 | 47 | public static class IntentBuilder extends GenericIntentBuilder { 48 | 49 | protected IntentBuilder() { 50 | super(FlutterExampleActivity.class); 51 | } 52 | } 53 | 54 | 55 | @Override 56 | public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { 57 | 58 | } 59 | 60 | @Override 61 | public void cleanUpFlutterEngine(@NonNull FlutterEngine flutterEngine) { 62 | 63 | } 64 | 65 | @Override 66 | public void onFlutterInitFailure(@NonNull Throwable error) { 67 | 68 | } 69 | 70 | @Override 71 | public void onRegisterPlugin(PluginRegistry pluginRegistry) { 72 | 73 | } 74 | 75 | @Override 76 | public void afterFlutterViewAttachToEngine(@NonNull FlutterView flutterView, @NonNull FlutterEngine flutterEngine) { 77 | 78 | } 79 | 80 | @Override 81 | public void beforeFlutterViewDetachFromEngine(@NonNull FlutterView flutterView, @NonNull FlutterEngine flutterEngine) { 82 | 83 | } 84 | 85 | @Override 86 | public void afterUpdateSystemUiOverlays(FlutterView flutterView) { 87 | 88 | } 89 | 90 | @Override 91 | public void onFirstFrameRendered(@NonNull FlutterView flutterView) { 92 | 93 | } 94 | 95 | @Override 96 | public void onCreate(@Nullable Bundle savedInstanceState) { 97 | super.onCreate(savedInstanceState); 98 | Log.e(TAG, "onCreate:" + this); 99 | } 100 | 101 | 102 | @Override 103 | public void onStart() { 104 | super.onStart(); 105 | Log.e(TAG, "onStart:" + this); 106 | } 107 | 108 | @Override 109 | public void onResume() { 110 | super.onResume(); 111 | Log.e(TAG, "onResume:" + this); 112 | } 113 | 114 | @Override 115 | public void onPause() { 116 | super.onPause(); 117 | Log.e(TAG, "onPause:" + this); 118 | } 119 | 120 | @Override 121 | public void onStop() { 122 | super.onStop(); 123 | Log.e(TAG, "onStop:" + this); 124 | } 125 | 126 | @Override 127 | public void onDestroy() { 128 | super.onDestroy(); 129 | Log.e(TAG, "onDestroy:" + this); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/vdian/flutter/hybridrouterexample/IllegalResultActivity.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouterexample; 26 | 27 | import android.content.Intent; 28 | import androidx.appcompat.app.AppCompatActivity; 29 | import android.os.Bundle; 30 | import android.view.View; 31 | 32 | import java.io.Serializable; 33 | import java.util.ArrayList; 34 | import java.util.HashMap; 35 | 36 | public class IllegalResultActivity extends AppCompatActivity { 37 | 38 | public static class TestResult implements Serializable { 39 | private String fieldA; 40 | private String fieldB; 41 | 42 | public String getFieldA() { 43 | return fieldA; 44 | } 45 | 46 | public void setFieldA(String fieldA) { 47 | this.fieldA = fieldA; 48 | } 49 | 50 | public String getFieldB() { 51 | return fieldB; 52 | } 53 | 54 | public void setFieldB(String fieldB) { 55 | this.fieldB = fieldB; 56 | } 57 | } 58 | 59 | @Override 60 | protected void onCreate(Bundle savedInstanceState) { 61 | super.onCreate(savedInstanceState); 62 | setContentView(R.layout.activity_illegal_result); 63 | findViewById(R.id.btn_return).setOnClickListener(new View.OnClickListener() { 64 | @Override 65 | public void onClick(View v) { 66 | Intent data = new Intent(); 67 | data.putExtra("illegal", new TestResult()); 68 | data.putExtra("message", "我是合法数据"); 69 | data.putExtra("int", 0); 70 | data.putExtra("bool", true); 71 | data.putExtra("double", 0.0); 72 | data.putExtra("float", 0.0f); 73 | data.putExtra("long", 123L); 74 | ArrayList list = new ArrayList(); 75 | list.add("我是合法数据"); 76 | list.add(new TestResult()); 77 | list.add(true); 78 | data.putExtra("list", list); 79 | HashMap map = new HashMap(); 80 | map.put("message", "我是合法数据"); 81 | map.put("illegal", new TestResult()); 82 | map.put("int", 0); 83 | data.putExtra("map", map); 84 | setResult(RESULT_OK, data); 85 | finish(); 86 | } 87 | }); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/vdian/flutter/hybridrouterexample/MainActivity.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouterexample; 26 | 27 | import android.content.Intent; 28 | import android.os.Bundle; 29 | import androidx.annotation.NonNull; 30 | import androidx.appcompat.app.AppCompatActivity; 31 | import androidx.recyclerview.widget.LinearLayoutManager; 32 | import androidx.recyclerview.widget.RecyclerView; 33 | import android.view.View; 34 | import android.view.ViewGroup; 35 | import android.widget.TextView; 36 | 37 | import com.vdian.flutter.hybridrouter.page.FlutterLaunchHelper; 38 | import com.vdian.flutter.hybridrouter.page.FlutterRouteOptions; 39 | 40 | import org.voiddog.android.lib.base.recycler.adapter.ListMultiTypeBindAdapter; 41 | import org.voiddog.android.lib.base.recycler.adapter.MultiTypeBindAdapter; 42 | import org.voiddog.android.lib.base.recycler.viewholder.BindViewHolder; 43 | 44 | import java.util.ArrayList; 45 | import java.util.List; 46 | 47 | public class MainActivity extends AppCompatActivity { 48 | 49 | public static class MenuItem { 50 | private String title; 51 | private View.OnClickListener clickListener; 52 | 53 | public String getTitle() { 54 | return title; 55 | } 56 | 57 | public void setTitle(String title) { 58 | this.title = title; 59 | } 60 | 61 | public View.OnClickListener getClickListener() { 62 | return clickListener; 63 | } 64 | 65 | public void setClickListener(View.OnClickListener clickListener) { 66 | this.clickListener = clickListener; 67 | } 68 | 69 | public MenuItem() { 70 | } 71 | 72 | public MenuItem(String title, View.OnClickListener clickListener) { 73 | this.title = title; 74 | this.clickListener = clickListener; 75 | } 76 | } 77 | 78 | public static class MenuVH extends BindViewHolder { 79 | 80 | private TextView txtContent; 81 | 82 | public MenuVH(@NonNull ViewGroup parent) { 83 | super(parent, R.layout.rec_main_item); 84 | txtContent = itemView.findViewById(R.id.txt_content); 85 | } 86 | 87 | @Override 88 | public void onBindData(@NonNull MenuItem data) { 89 | txtContent.setText(data.title); 90 | itemView.setOnClickListener(data.clickListener); 91 | } 92 | } 93 | 94 | @Override 95 | protected void onCreate(Bundle savedInstanceState) { 96 | super.onCreate(savedInstanceState); 97 | setContentView(R.layout.activity_main); 98 | ListMultiTypeBindAdapter adapter = new ListMultiTypeBindAdapter<>(); 99 | adapter.registerItemProvider(new MultiTypeBindAdapter.ItemProvider() { 100 | @Override 101 | public BindViewHolder onCreateViewHolder(@NonNull ViewGroup parent) { 102 | return new MenuVH(parent); 103 | } 104 | }); 105 | RecyclerView recList = findViewById(R.id.rec_list); 106 | // data 107 | List dataList = new ArrayList<>(); 108 | dataList.add(new MenuItem( 109 | "跳转到 flutter 页面", new View.OnClickListener() { 110 | @Override 111 | public void onClick(View v) { 112 | Intent intent = FlutterExampleActivity.builder() 113 | // flutter_tools 会把参数传递到 intent 中 114 | .initializationArgs(FlutterLaunchHelper.parseFlutterShellArgs(getIntent())) 115 | .dartEntrypoint(FlutterLaunchHelper.getDartEntrypointName(getIntent())) 116 | .route(new FlutterRouteOptions.Builder("example") 117 | .setArgs("Jump From Main").build()) 118 | .buildIntent(MainActivity.this); 119 | startActivity(intent); 120 | } 121 | })); 122 | dataList.add(new MenuItem( 123 | "跳转到 native 页面", new View.OnClickListener() { 124 | @Override 125 | public void onClick(View v) { 126 | Intent intent = new Intent(v.getContext(), NativeExampleActivity.class); 127 | intent.putExtra("title", "Jump from main"); 128 | startActivity(intent); 129 | } 130 | } 131 | )); 132 | dataList.add(new MenuItem( 133 | "跳转到 tab 页面", new View.OnClickListener() { 134 | @Override 135 | public void onClick(View v) { 136 | Intent intent = new Intent(v.getContext(), TabExampleActivity.class); 137 | startActivity(intent); 138 | } 139 | } 140 | )); 141 | adapter.set(dataList); 142 | recList.setLayoutManager(new LinearLayoutManager(this)); 143 | recList.setAdapter(adapter); 144 | 145 | // Intent intent = FlutterExampleActivity.builder() 146 | // // flutter_tools 会把参数传递到 intent 中 147 | // .initializationArgs(FlutterLaunchHelper.parseFlutterShellArgs(getIntent())) 148 | // .dartEntrypoint(FlutterLaunchHelper.getDartEntrypointName(getIntent())) 149 | // .route(new FlutterRouteOptions.Builder("example") 150 | // .setArgs("Jump From Main").build()) 151 | // .buildIntent(MainActivity.this); 152 | // startActivity(intent); 153 | 154 | 155 | // Intent intent = new Intent(MainActivity.this, TabExampleActivity.class); 156 | // startActivity(intent); 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/vdian/flutter/hybridrouterexample/NativeExampleActivity.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouterexample; 26 | 27 | import android.content.Intent; 28 | import android.os.Bundle; 29 | import androidx.appcompat.app.AppCompatActivity; 30 | import androidx.appcompat.widget.Toolbar; 31 | import android.text.TextUtils; 32 | import android.view.View; 33 | import android.widget.Button; 34 | import android.widget.TextView; 35 | 36 | import com.vdian.flutter.hybridrouter.page.FlutterRouteOptions; 37 | 38 | public class NativeExampleActivity extends AppCompatActivity { 39 | 40 | private static final int REQUEST_FLUTTER = 10; 41 | private static final int REQUEST_NATIVE = 11; 42 | 43 | private TextView txtRet; 44 | private Button btnJumpToFlutter; 45 | private Button btnJumpToNative; 46 | private Toolbar toolbar; 47 | 48 | @Override 49 | protected void onCreate(Bundle savedInstanceState) { 50 | super.onCreate(savedInstanceState); 51 | setContentView(R.layout.activity_native_example); 52 | toolbar = findViewById(R.id.tool_bar); 53 | txtRet = findViewById(R.id.txt_ret); 54 | btnJumpToFlutter = findViewById(R.id.btn_jump_to_flutter); 55 | btnJumpToNative = findViewById(R.id.btn_jump_to_native); 56 | 57 | Intent data = getIntent(); 58 | if (data != null) { 59 | String title = data.getStringExtra("title"); 60 | if (!TextUtils.isEmpty(title)) { 61 | toolbar.setTitle(title); 62 | } 63 | } 64 | 65 | btnJumpToFlutter.setOnClickListener(new View.OnClickListener() { 66 | @Override 67 | public void onClick(View v) { 68 | Intent intent = FlutterExampleActivity.builder().route(new FlutterRouteOptions.Builder("example") 69 | .setArgs("Jump from native example") 70 | .build()).buildIntent(v.getContext()); 71 | startActivityForResult(intent, REQUEST_FLUTTER); 72 | } 73 | }); 74 | 75 | btnJumpToNative.setOnClickListener(new View.OnClickListener() { 76 | @Override 77 | public void onClick(View v) { 78 | Intent intent = new Intent(v.getContext(), NativeExampleActivity.class); 79 | intent.putExtra("title", "Jump from native example"); 80 | startActivityForResult(intent, REQUEST_NATIVE); 81 | } 82 | }); 83 | 84 | findViewById(R.id.btn_jump_to_tab_flutter).setOnClickListener(new View.OnClickListener() { 85 | @Override 86 | public void onClick(View v) { 87 | Intent intent = new Intent(v.getContext(), TabExampleActivity.class); 88 | startActivityForResult(intent, REQUEST_FLUTTER); 89 | } 90 | }); 91 | 92 | toolbar.setNavigationOnClickListener(new View.OnClickListener() { 93 | @Override 94 | public void onClick(View v) { 95 | Intent data = new Intent(); 96 | data.putExtra("message", "Return message from native example"); 97 | setResult(RESULT_OK, data); 98 | finish(); 99 | } 100 | }); 101 | } 102 | 103 | @Override 104 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 105 | super.onActivityResult(requestCode, resultCode, data); 106 | switch (requestCode) { 107 | case REQUEST_NATIVE: { 108 | String message = null; 109 | if (data != null && data.hasExtra("message")) { 110 | message = data.getStringExtra("message"); 111 | } 112 | message = message == null ? "No message from native example" : message; 113 | txtRet.setText(message); 114 | break; 115 | } 116 | case REQUEST_FLUTTER: { 117 | String message = null; 118 | if (data != null) { 119 | message = (String) FlutterExampleActivity.getFlutterResult(data); 120 | } 121 | message = message == null ? "No message from flutter example" : message; 122 | txtRet.setText(message); 123 | break; 124 | } 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/vdian/flutter/hybridrouterexample/TabExampleActivity.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouterexample; 26 | 27 | import android.os.Bundle; 28 | import androidx.annotation.NonNull; 29 | import androidx.annotation.Nullable; 30 | import com.google.android.material.tabs.TabLayout; 31 | import androidx.fragment.app.Fragment; 32 | import androidx.fragment.app.FragmentTransaction; 33 | import androidx.appcompat.app.AppCompatActivity; 34 | import android.util.TypedValue; 35 | import android.view.Gravity; 36 | import android.view.LayoutInflater; 37 | import android.view.View; 38 | import android.view.ViewGroup; 39 | import android.widget.FrameLayout; 40 | import android.widget.TextView; 41 | 42 | import com.vdian.flutter.hybridrouter.page.FlutterRouteOptions; 43 | import com.vdian.flutter.hybridrouter.page.HybridFlutterFragment; 44 | 45 | import io.flutter.embedding.android.FlutterView; 46 | 47 | public class TabExampleActivity extends AppCompatActivity { 48 | 49 | public static class NativeFragment extends Fragment { 50 | 51 | @Nullable 52 | @Override 53 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, 54 | @Nullable Bundle savedInstanceState) { 55 | FrameLayout frameLayout = new FrameLayout(container.getContext()); 56 | TextView textView = new TextView(frameLayout.getContext()); 57 | textView.setText("我是 native fragment"); 58 | textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28); 59 | FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( 60 | ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT 61 | ); 62 | lp.gravity = Gravity.CENTER; 63 | frameLayout.addView(textView, lp); 64 | return frameLayout; 65 | } 66 | } 67 | 68 | HybridFlutterFragment hybridFlutterFragmentA; 69 | HybridFlutterFragment hybridFlutterFragmentB; 70 | Fragment nativeFragment; 71 | TabLayout tabLayout; 72 | 73 | @Override 74 | protected void onCreate(Bundle savedInstanceState) { 75 | super.onCreate(savedInstanceState); 76 | setContentView(R.layout.activity_tab_example); 77 | hybridFlutterFragmentA = new HybridFlutterFragment.Builder() 78 | .renderMode(FlutterView.RenderMode.texture) 79 | .route(new FlutterRouteOptions.Builder("tab_example").build()) 80 | .build(); 81 | hybridFlutterFragmentB = new HybridFlutterFragment.Builder() 82 | .renderMode(FlutterView.RenderMode.texture) 83 | .route(new FlutterRouteOptions.Builder("tab_example").build()) 84 | .build(); 85 | nativeFragment = new NativeFragment(); 86 | tabLayout = findViewById(R.id.tab); 87 | tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { 88 | @Override 89 | public void onTabSelected(TabLayout.Tab tab) { 90 | show(tab.getPosition()); 91 | } 92 | 93 | @Override 94 | public void onTabUnselected(TabLayout.Tab tab) { } 95 | 96 | @Override 97 | public void onTabReselected(TabLayout.Tab tab) { } 98 | }); 99 | show(0); 100 | } 101 | 102 | Fragment preFragment; 103 | boolean[] isAdded = new boolean[]{false, false, false}; 104 | 105 | private void show(int index) { 106 | Fragment[] fragments = new Fragment[]{hybridFlutterFragmentA, nativeFragment, hybridFlutterFragmentB}; 107 | Fragment fragment = fragments[index]; 108 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 109 | if (preFragment != null) { 110 | transaction.detach(preFragment); 111 | preFragment = null; 112 | } 113 | if (isAdded[index]) { 114 | transaction.attach(fragment); 115 | } else { 116 | isAdded[index] = true; 117 | transaction.add(R.id.fra_content, fragment); 118 | } 119 | transaction.commit(); 120 | preFragment = fragment; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/vdian/flutter/hybridrouterexample/translucent/NoTranslucentActivity.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouterexample.translucent; 26 | 27 | import android.app.Activity; 28 | import android.content.Intent; 29 | import android.os.Build; 30 | import android.os.Bundle; 31 | import androidx.appcompat.app.AppCompatActivity; 32 | import android.util.Log; 33 | import android.view.View; 34 | 35 | import com.vdian.flutter.hybridrouter.page.FlutterRouteOptions; 36 | import com.vdian.flutter.hybridrouterexample.FlutterExampleActivity; 37 | import com.vdian.flutter.hybridrouterexample.R; 38 | 39 | public class NoTranslucentActivity extends AppCompatActivity { 40 | 41 | public static final String TAG = "FlutterLifecycle" + Build.VERSION.SDK_INT; 42 | 43 | private static final int REQUEST_CODE = 1000; 44 | 45 | @Override 46 | protected void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | Log.e(TAG, "onCreate:" + this); 49 | setContentView(R.layout.activity_notranslucent); 50 | 51 | findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { 52 | @Override 53 | public void onClick(View v) { 54 | startActivityForResult(new Intent(NoTranslucentActivity.this, SetResultActivity.class), REQUEST_CODE); 55 | } 56 | }); 57 | } 58 | 59 | @Override 60 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 61 | super.onActivityResult(requestCode, resultCode, data); 62 | if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) { 63 | Intent intent = FlutterExampleActivity.builder().route(new FlutterRouteOptions.Builder("example") 64 | .setArgs("Jump from no translucent theme activity") 65 | .build()).buildIntent(getApplicationContext()); 66 | startActivity(intent); 67 | finish(); 68 | } 69 | } 70 | 71 | 72 | @Override 73 | public void onStart() { 74 | super.onStart(); 75 | Log.e(TAG, "onStart:" + this); 76 | } 77 | 78 | @Override 79 | public void onResume() { 80 | super.onResume(); 81 | Log.e(TAG, "onResume:" + this); 82 | } 83 | 84 | @Override 85 | public void onPause() { 86 | super.onPause(); 87 | Log.e(TAG, "onPause:" + this); 88 | } 89 | 90 | @Override 91 | public void onStop() { 92 | super.onStop(); 93 | Log.e(TAG, "onStop:" + this); 94 | } 95 | 96 | @Override 97 | public void onDestroy() { 98 | super.onDestroy(); 99 | Log.e(TAG, "onDestroy:" + this); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/vdian/flutter/hybridrouterexample/translucent/SetResultActivity.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouterexample.translucent; 26 | 27 | import android.app.Activity; 28 | import android.os.Build; 29 | import android.os.Bundle; 30 | import androidx.appcompat.app.AppCompatActivity; 31 | import android.util.Log; 32 | import android.view.View; 33 | 34 | import com.vdian.flutter.hybridrouterexample.R; 35 | 36 | public class SetResultActivity extends AppCompatActivity { 37 | public static final String TAG = "FlutterLifecycle" + Build.VERSION.SDK_INT; 38 | 39 | @Override 40 | protected void onCreate(Bundle savedInstanceState) { 41 | super.onCreate(savedInstanceState); 42 | Log.e(TAG, "onCreate:" + this); 43 | setContentView(R.layout.activity_setresult); 44 | findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { 45 | @Override 46 | public void onClick(View v) { 47 | setResult(Activity.RESULT_OK); 48 | finish(); 49 | } 50 | }); 51 | } 52 | 53 | @Override 54 | public void onStart() { 55 | super.onStart(); 56 | Log.e(TAG, "onStart:" + this); 57 | } 58 | 59 | @Override 60 | public void onResume() { 61 | super.onResume(); 62 | Log.e(TAG, "onResume:" + this); 63 | } 64 | 65 | @Override 66 | public void onPause() { 67 | super.onPause(); 68 | Log.e(TAG, "onPause:" + this); 69 | } 70 | 71 | @Override 72 | public void onStop() { 73 | super.onStop(); 74 | Log.e(TAG, "onStop:" + this); 75 | } 76 | 77 | @Override 78 | public void onDestroy() { 79 | super.onDestroy(); 80 | Log.e(TAG, "onDestroy:" + this); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/vdian/flutter/hybridrouterexample/translucent/TranslucentActivity.java: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // ----------- 3 | 4 | // Copyright (c) 2019 WeiDian Group 5 | // Permission is hereby granted, free of charge, to any person 6 | // obtaining a copy of this software and associated documentation 7 | // files (the "Software"), to deal in the Software without 8 | // restriction, including without limitation the rights to use, 9 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the 11 | // Software is furnished to do so, subject to the following 12 | // conditions: 13 | 14 | // The above copyright notice and this permission notice shall be 15 | // included in all copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | package com.vdian.flutter.hybridrouterexample.translucent; 26 | 27 | import android.app.Activity; 28 | import android.content.Intent; 29 | import android.os.Build; 30 | import android.os.Bundle; 31 | import androidx.appcompat.app.AppCompatActivity; 32 | import android.util.Log; 33 | import android.view.View; 34 | 35 | import com.vdian.flutter.hybridrouter.page.FlutterRouteOptions; 36 | import com.vdian.flutter.hybridrouterexample.FlutterExampleActivity; 37 | import com.vdian.flutter.hybridrouterexample.R; 38 | 39 | public class TranslucentActivity extends AppCompatActivity { 40 | public static final String TAG = "FlutterLifecycle" + Build.VERSION.SDK_INT; 41 | 42 | private static final int REQUEST_CODE = 1000; 43 | 44 | @Override 45 | protected void onCreate(Bundle savedInstanceState) { 46 | super.onCreate(savedInstanceState); 47 | Log.e(TAG, "onCreate:" + this); 48 | setContentView(R.layout.activity_translucent); 49 | 50 | findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { 51 | @Override 52 | public void onClick(View v) { 53 | startActivityForResult(new Intent(TranslucentActivity.this, SetResultActivity.class), REQUEST_CODE); 54 | } 55 | }); 56 | } 57 | 58 | @Override 59 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 60 | super.onActivityResult(requestCode, resultCode, data); 61 | if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) { 62 | Intent intent = FlutterExampleActivity.builder().route(new FlutterRouteOptions.Builder("example") 63 | .setArgs("Jump from translucent theme activity") 64 | .build()).buildIntent(getApplicationContext()); 65 | startActivity(intent); 66 | finish(); 67 | } 68 | } 69 | 70 | 71 | @Override 72 | public void onStart() { 73 | super.onStart(); 74 | Log.e(TAG, "onStart:" + this); 75 | } 76 | 77 | @Override 78 | public void onResume() { 79 | super.onResume(); 80 | Log.e(TAG, "onResume:" + this); 81 | } 82 | 83 | @Override 84 | public void onPause() { 85 | super.onPause(); 86 | Log.e(TAG, "onPause:" + this); 87 | } 88 | 89 | @Override 90 | public void onStop() { 91 | super.onStop(); 92 | Log.e(TAG, "onStop:" + this); 93 | } 94 | 95 | @Override 96 | public void onDestroy() { 97 | super.onDestroy(); 98 | Log.e(TAG, "onDestroy:" + this); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-v21/bg_click_dark.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-v21/bg_click_dark_mask.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/bg_click_dark.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/bg_click_dark_mask.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/ic_svg_arrow_back_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/layout/activity_illegal_result.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 23 | 24 |