diff --git a/app/build.gradle b/app/build.gradle
index 7967765624..17af85cb83 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -92,6 +92,7 @@ dependencies {
implementation project(':modules:mogo-module-common')
implementation project(':modules:mogo-module-tanlu')
implementation project(':modules:mogo-module-search')
+ implementation project(':modules:mogo-module-back')
}
}
diff --git a/app/src/main/java/com/mogo/launcher/MogoApplication.java b/app/src/main/java/com/mogo/launcher/MogoApplication.java
index f7a41dd5ee..7a2288b8b8 100644
--- a/app/src/main/java/com/mogo/launcher/MogoApplication.java
+++ b/app/src/main/java/com/mogo/launcher/MogoApplication.java
@@ -8,6 +8,7 @@ import com.alibaba.android.arouter.launcher.ARouter;
import com.auto.zhidao.logsdk.CrashSystem;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.debug.DebugConfig;
+import com.mogo.module.back.BackToMainHomeManager;
import com.mogo.module.carchatting.card.CallChatConstant;
import com.mogo.module.common.MogoModule;
import com.mogo.module.common.MogoModulePaths;
@@ -49,6 +50,7 @@ public class MogoApplication extends AbsMogoApplication {
MogoModulePaths.addModule(new MogoModule(CallChatConstant.PROVIDER, CallChatConstant.MODULE_NAME));
MogoModulePaths.addModule(new MogoModule(MediaConstants.TAG, MediaConstants.MODULE_TYPE));
MogoModulePaths.addModule(new MogoModule(PushUIConstants.TAG, PushUIConstants.TAG));
+ // BackToMainHomeManager.addMainHomeView();
}
@Override
diff --git a/config.gradle b/config.gradle
index 9b22bd8d31..27008acf01 100644
--- a/config.gradle
+++ b/config.gradle
@@ -107,6 +107,8 @@ ext {
modulepush : "com.mogo.module:module-push:${MOGO_MODULE_PUSH_VERSION}",
//运营位卡片
moduleadcard : "com.mogo.module:module-adcard:${MOGO_MODULE_AD_CARD_VERSION}",
+ //统一返回键
+ mogomoduleback : "com.mogo.module:module-back:${MOGO_MODULE_BACK_VERSION}",
// 长链
socketsdk : 'com.zhidao.socketsdk:socketsdk:2.1.0',
socketsdkconnsvrprotoco : 'com.zhidao.ptech:connsvr-protoco:0.1.23',
diff --git a/gradle.properties b/gradle.properties
index fddb467c1d..299457c03c 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -53,5 +53,6 @@ MOGO_MODULE_MEDIA_VERSION=1.0.0-SNAPSHOT
MOGO_MODULE_PUSH_VERSION=1.0.0-SNAPSHOT
MOGO_MODULE_SEARCH_VERSION=1.0.0-SNAPSHOT
MOGO_MODULE_AD_CARD_VERSION=1.0.0-SNAPSHOT
+MOGO_MODULE_BACK_VERSION=1.0.0-SNAPSHOT
diff --git a/modules/mogo-module-back/.gitignore b/modules/mogo-module-back/.gitignore
new file mode 100644
index 0000000000..796b96d1c4
--- /dev/null
+++ b/modules/mogo-module-back/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/modules/mogo-module-back/build.gradle b/modules/mogo-module-back/build.gradle
new file mode 100644
index 0000000000..d4b9127efe
--- /dev/null
+++ b/modules/mogo-module-back/build.gradle
@@ -0,0 +1,68 @@
+apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android-extensions'
+apply plugin: 'kotlin-android'
+apply plugin: 'com.alibaba.arouter'
+
+android {
+ compileSdkVersion rootProject.ext.android.compileSdkVersion
+ // buildToolsVersion rootProject.ext.android.buildToolsVersion
+ defaultConfig {
+ minSdkVersion rootProject.ext.android.minSdkVersion
+ targetSdkVersion rootProject.ext.android.targetSdkVersion
+ versionCode Integer.valueOf(VERSION_CODE)
+ versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION")
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ consumerProguardFiles 'consumer-rules.pro'
+
+ javaCompileOptions {
+ annotationProcessorOptions {
+ arguments = [AROUTER_MODULE_NAME: project.getName()]
+ }
+ }
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+ implementation 'androidx.appcompat:appcompat:1.0.2'
+ implementation 'androidx.core:core-ktx:1.0.2'
+ implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ testImplementation 'junit:junit:4.12'
+ androidTestImplementation 'androidx.test:runner:1.2.0'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+ implementation rootProject.ext.dependencies.androidxappcompat
+ implementation rootProject.ext.dependencies.androidxconstraintlayout
+ implementation rootProject.ext.dependencies.arouter
+ annotationProcessor rootProject.ext.dependencies.aroutercompiler
+ implementation rootProject.ext.dependencies.rxjava
+ implementation rootProject.ext.dependencies.rxandroid
+
+ if (Boolean.valueOf(RELEASE)) {
+ implementation rootProject.ext.dependencies.mogoutils
+ implementation rootProject.ext.dependencies.mogocommons
+ implementation rootProject.ext.dependencies.modulecommon
+ } else {
+ implementation project(":foudations:mogo-utils")
+ api project(":foudations:mogo-commons")
+ implementation project(':modules:mogo-module-common')
+ }
+
+}
+apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()
+repositories {
+ mavenCentral()
+}
diff --git a/modules/mogo-module-back/consumer-rules.pro b/modules/mogo-module-back/consumer-rules.pro
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/modules/mogo-module-back/gradle.properties b/modules/mogo-module-back/gradle.properties
new file mode 100644
index 0000000000..370dc456b8
--- /dev/null
+++ b/modules/mogo-module-back/gradle.properties
@@ -0,0 +1,3 @@
+GROUP=com.mogo.module
+POM_ARTIFACT_ID=module-back
+VERSION_CODE=1
diff --git a/modules/mogo-module-back/proguard-rules.pro b/modules/mogo-module-back/proguard-rules.pro
new file mode 100644
index 0000000000..f1b424510d
--- /dev/null
+++ b/modules/mogo-module-back/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/modules/mogo-module-back/src/main/AndroidManifest.xml b/modules/mogo-module-back/src/main/AndroidManifest.xml
new file mode 100644
index 0000000000..a0a69cfe71
--- /dev/null
+++ b/modules/mogo-module-back/src/main/AndroidManifest.xml
@@ -0,0 +1,6 @@
+
+ * 向 window manager 添加 view + */ +public class WindowManagerViewHelper { + + public static void addView( View view ) { + + final Context context = view.getContext(); + if ( context == null || context.getApplicationContext() == null ) { + return; + } + WindowManager windowManager = ( WindowManager ) context.getApplicationContext().getSystemService( Context.WINDOW_SERVICE ); + if ( windowManager == null ) { + return; + } + WindowManager.LayoutParams params = new WindowManager.LayoutParams(); + params.height = WindowManager.LayoutParams.WRAP_CONTENT; + params.width = WindowManager.LayoutParams.WRAP_CONTENT; + params.gravity = Gravity.LEFT | Gravity.CENTER; + params.type = getFitWindowParamsType(); + params.format = PixelFormat.RGBA_8888; + params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; + windowManager.addView( view, params ); + + attachMovementEvent( view, params ); + } + + private static int getFitWindowParamsType() { + int type; + if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 ) { + // Need request permission. + type = WindowManager.LayoutParams.TYPE_PHONE; + } else if ( Build.MODEL.equalsIgnoreCase( "MI 5" ) ) { + // MI 5 phone not display crawler dot in android 7.0 + type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; + } else { + // It's will be dismissed automatically 3s after showing in Android 25. + type = WindowManager.LayoutParams.TYPE_TOAST; + } + return type; + } + + public static void removeView( View view ) { + if ( view == null || view.getContext() == null || view.getContext().getApplicationContext() == null ) { + return; + } + WindowManager windowManager = ( WindowManager ) view.getContext().getApplicationContext().getSystemService( Context.WINDOW_SERVICE ); + if ( windowManager == null ) { + return; + } + windowManager.removeViewImmediate( view ); + DispatchTouchEventWrapper.getInstance().release(); + + } + + public static void attachMovementEvent( View view, WindowManager.LayoutParams params ) { + if ( view == null ) { + return; + } + view.setOnTouchListener( ( v, event ) -> { + DispatchTouchEventWrapper.getInstance() + .attach( view, params ) + .handle( event ); + return false; + } ); + } + + static class DispatchTouchEventWrapper { + + private WindowViewHandler mWindowViewHandler; + + int mActionDownX = -1; + int mActionDownY = -1; + + /** + * Flag whether move after touch down. + */ + boolean mMoveFlag = false; + + private static volatile DispatchTouchEventWrapper INST; + + private DispatchTouchEventWrapper() { + } + + public static DispatchTouchEventWrapper getInstance() { + if ( INST == null ) { + synchronized ( DispatchTouchEventWrapper.class ) { + if ( INST == null ) { + INST = new DispatchTouchEventWrapper(); + } + } + } + return INST; + } + + public DispatchTouchEventWrapper attach( View windowView, WindowManager.LayoutParams params ) { + if ( mWindowViewHandler == null || mWindowViewHandler.getWindowView() != windowView ) { + mWindowViewHandler = new WindowViewHandler.DefaultHandler( windowView, params ); + } + return this; + } + + public boolean handle( MotionEvent event ) { + switch ( event.getAction() & MotionEvent.ACTION_MASK ) { + case MotionEvent.ACTION_DOWN: + if ( onActionDown( event ) ) { + return true; + } + break; + case MotionEvent.ACTION_MOVE: + if ( onActionMove( event ) ) { + return true; + } + break; + case MotionEvent.ACTION_UP: + if ( onActionUp( event ) ) { + return true; + } + break; + } + return false; + } + + private boolean onActionDown( MotionEvent event ) { + mActionDownX = ( ( int ) event.getRawX() ); + mActionDownY = ( ( int ) event.getRawY() ); + if ( mWindowViewHandler != null ) { + mWindowViewHandler.recordNewPosition(); + return true; + } + return false; + } + + private boolean onActionMove( MotionEvent event ) { + + if ( Math.abs( event.getRawX() - mActionDownX ) >= 20 + || Math.abs( event.getRawY() - mActionDownY ) >= 20 ) { + mMoveFlag = true; + } + + if ( isLastDownValueLegal() ) { + moveWindowView( event ); + return true; + } + return false; + } + + private boolean onActionUp( MotionEvent event ) { + if ( isClickEventLike() ) { + if ( mWindowViewHandler != null ) { + mWindowViewHandler.performClickLike(); + } + } else { + if ( mWindowViewHandler != null ) { + mWindowViewHandler.moveToEdge(); + mWindowViewHandler.recordNewPosition(); + } + } + mMoveFlag = false; + clearLastDownAxisValue(); + return true; + } + + private void clearLastDownAxisValue() { + mActionDownX = mActionDownY = -1; + } + + private boolean isLastDownValueLegal() { + return mActionDownX != -1 && mActionDownY != -1; + } + + private void moveWindowView( MotionEvent event ) { + if ( mWindowViewHandler != null ) { + mWindowViewHandler.move( event, mActionDownX, mActionDownY ); + } + } + + /** + * Simulate click event just like set {@link View.OnClickListener} + * + * @return + */ + private boolean isClickEventLike() { + System.out.println( mMoveFlag ); + return isLastDownValueLegal() && !mMoveFlag; + } + + public void release() { + if ( mWindowViewHandler != null ) { + mWindowViewHandler.release(); + } + mWindowViewHandler = null; + mActionDownX = -1; + mActionDownY = -1; + mMoveFlag = false; + INST = null; + } + } + +} diff --git a/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowViewHandler.java b/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowViewHandler.java new file mode 100644 index 0000000000..329ce1863e --- /dev/null +++ b/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowViewHandler.java @@ -0,0 +1,119 @@ +package com.mogo.module.back.utils; + +import android.content.Context; +import android.view.MotionEvent; +import android.view.View; +import android.view.WindowManager; + +import com.mogo.commons.AbsMogoApplication; +import com.mogo.utils.WindowUtils; + + +/** + * Created by congtaowang on 2017/6/20. + */ + +public interface WindowViewHandler { + + View getWindowView(); + + void recordNewPosition(); + + void move(MotionEvent event, int downX, int downY); + + void release(); + + void moveToEdge(); + + void performClickLike(); + + class DefaultHandler implements WindowViewHandler { + + protected View mWindowView; + + protected int mWindowViewLeft = -1; + protected int mWindowViewTop = -1; + + private WindowManager.LayoutParams mParams; + + public DefaultHandler( View windowView, WindowManager.LayoutParams params ) { + this.mWindowView = windowView; + mParams = params; + } + + @Override + public View getWindowView() { + return mWindowView; + } + + @Override + public void recordNewPosition() { + mWindowViewLeft = mParams.x; + mWindowViewTop = mParams.y; + } + + @Override + public void move( MotionEvent event, int downX, int downY ) { + move( ( ( int ) ( event.getRawX() - downX ) ), + ( ( int ) ( event.getRawY() - downY ) ) ); + } + + private void move( int distanceX, int distanceY ) { + if ( mWindowView == null ) { + return; + } + mParams.x = mWindowViewLeft + distanceX; + mParams.y = mWindowViewTop + distanceY; + WindowManager wm = ( ( WindowManager ) mWindowView.getContext().getSystemService( Context.WINDOW_SERVICE ) ); + + if ( wm == null ) { + return; + } + + if ( mWindowView instanceof WindowViewUIController ) { + if ( mParams.x > WindowUtils.getScreenWidth( AbsMogoApplication.getApp() ) / 2 ) { + ( ( WindowViewUIController ) mWindowView ).rightMode(); + } else { + ( ( WindowViewUIController ) mWindowView ).leftMode(); + } + } + + wm.updateViewLayout( mWindowView, alignLayoutParamsBoundary( mParams ) ); + } + + @Override + public void moveToEdge() { + if ( mWindowView == null ) { + return; + } + /* WindowManager wm = ( ( WindowManager ) mWindowView.getContext().getSystemService( Context.WINDOW_SERVICE ) ); + + if ( mParams.x > WindowUtils.getScreenWidth( AbsMogoApplication.getApp() ) / 2 ) { + mParams.x = WindowUtils.getScreenWidth( AbsMogoApplication.getApp() ) - mWindowView.getMeasuredWidth(); + } else { + mParams.x = 0; + } + + wm.updateViewLayout( mWindowView, alignLayoutParamsBoundary( mParams ) );*/ + } + + protected WindowManager.LayoutParams alignLayoutParamsBoundary( WindowManager.LayoutParams params ) { + return params; + } + + @Override + public void performClickLike() { + if ( mWindowView instanceof WindowViewUIController ) { + ( ( WindowViewUIController ) mWindowView ).performClickLike(); + } + } + + @Override + public void release() { + mWindowView = null; + mWindowViewLeft = -1; + mWindowViewTop = -1; + } + } + +} diff --git a/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowViewUIController.java b/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowViewUIController.java new file mode 100644 index 0000000000..e329cdea68 --- /dev/null +++ b/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowViewUIController.java @@ -0,0 +1,16 @@ +package com.mogo.module.back.utils; + +/** + * @author congtaowang + * @since 2019-05-12 + *
+ * 描述
+ */
+public interface WindowViewUIController {
+
+ void leftMode();
+
+ void rightMode();
+
+ void performClickLike();
+}
diff --git a/modules/mogo-module-back/src/main/res/drawable-xhdpi/module_back_home_selected_icon.png b/modules/mogo-module-back/src/main/res/drawable-xhdpi/module_back_home_selected_icon.png
new file mode 100644
index 0000000000..0bfdb4b26e
Binary files /dev/null and b/modules/mogo-module-back/src/main/res/drawable-xhdpi/module_back_home_selected_icon.png differ
diff --git a/modules/mogo-module-back/src/main/res/drawable-xhdpi/module_back_home_unselected_icon.png b/modules/mogo-module-back/src/main/res/drawable-xhdpi/module_back_home_unselected_icon.png
new file mode 100644
index 0000000000..b5d163d95e
Binary files /dev/null and b/modules/mogo-module-back/src/main/res/drawable-xhdpi/module_back_home_unselected_icon.png differ
diff --git a/modules/mogo-module-back/src/main/res/drawable/module_back_home_icon_selector.xml b/modules/mogo-module-back/src/main/res/drawable/module_back_home_icon_selector.xml
new file mode 100644
index 0000000000..0eeab259dd
--- /dev/null
+++ b/modules/mogo-module-back/src/main/res/drawable/module_back_home_icon_selector.xml
@@ -0,0 +1,12 @@
+
+