add back home

This commit is contained in:
lidongxiu
2020-02-10 09:47:09 +08:00
parent 903f9a3e5c
commit 8ad2135be7
26 changed files with 600 additions and 0 deletions

View File

@@ -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')
}
}

View File

@@ -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

View File

@@ -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',

View File

@@ -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

1
modules/mogo-module-back/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -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()
}

View File

@@ -0,0 +1,3 @@
GROUP=com.mogo.module
POM_ARTIFACT_ID=module-back
VERSION_CODE=1

View File

@@ -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

View File

@@ -0,0 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.module.back" >
<uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" />
<uses-permission android:name="android.permission.TYPE_APPLICATION_OVERLAY" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
</manifest>

View File

@@ -0,0 +1,73 @@
package com.mogo.module.back;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Build;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.module.back.utils.WindowManagerViewHelper;
import com.mogo.utils.logger.Logger;
public class BackToMainHomeManager {
private static View mBackView;
public static void addMainHomeView(){
Logger.d("BackToMainHomeManager","addMainHomeView");
if (mBackView != null)WindowManagerViewHelper.removeView(mBackView);
mBackView = LayoutInflater.from(AbsMogoApplication.getApp()).inflate(R.layout.mogo_module_back_home_back_layout, null);
final Context context = mBackView.getContext();
if ( context == null || context.getApplicationContext() == null ) {
return;
}
WindowManager windowManager = ( WindowManager ) context.getApplicationContext().getSystemService( Context.WINDOW_SERVICE );
if ( windowManager == null ) {
return;
}
mBackView.setOnClickListener(view -> {
ComponentName cn = new ComponentName("com.mogo.launcher", "com.mogo.module.main.MainActivity") ;
Intent intent = new Intent() ;
intent.setComponent(cn) ;
if (!(AbsMogoApplication.getApp().getApplicationContext() instanceof Activity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
AbsMogoApplication.getApp().startActivity(intent);
});
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.x = AbsMogoApplication.getApp().getResources().getDimensionPixelOffset(R.dimen.module_back_main_home_icon_left);
params.y = AbsMogoApplication.getApp().getResources().getDimensionPixelOffset(R.dimen.module_back_main_home_icon_top);
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( mBackView, params );
WindowManagerViewHelper.attachMovementEvent(mBackView,params);
}
public static void removeMainHomeView(){
WindowManagerViewHelper.removeView(mBackView);
}
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;
}
}

View File

@@ -0,0 +1,213 @@
package com.mogo.module.back.utils;
import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Build;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
/**
* @author congtaowang
* @since 2019-04-30
* <p>
* 向 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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,16 @@
package com.mogo.module.back.utils;
/**
* @author congtaowang
* @since 2019-05-12
* <p>
* 描述
*/
public interface WindowViewUIController {
void leftMode();
void rightMode();
void performClickLike();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/module_back_home_unselected_icon"
android:state_pressed="true" />
<item android:drawable="@drawable/module_back_home_selected_icon"
android:state_pressed="false" />
<item android:drawable="@drawable/module_back_home_unselected_icon" />
</selector>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/module_back_main_home_icon_size"
android:layout_height="@dimen/module_back_main_home_icon_size">
<ImageView
android:layout_width="@dimen/module_back_main_home_icon_size"
android:layout_height="@dimen/module_back_main_home_icon_size"
android:scaleType="centerCrop"
android:src="@drawable/module_back_home_icon_selector">
</ImageView>
</FrameLayout>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="module_back_main_home_icon_size">80px</dimen>
<dimen name="module_back_main_home_icon_left">0px</dimen>
<dimen name="module_back_main_home_icon_top">100px</dimen>
</resources>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="module_back_main_home_icon_size">140px</dimen>
<dimen name="module_back_main_home_icon_left">0px</dimen>
<dimen name="module_back_main_home_icon_top">190px</dimen>
</resources>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">back</string>
</resources>

View File

@@ -0,0 +1,4 @@
<resources xmlns:tools="http://schemas.android.com/tools">
</resources>

View File

@@ -0,0 +1,17 @@
package com.example.mogo_module_share
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

View File

@@ -12,6 +12,7 @@ include ':modules:mogo-module-search'
include ':modules:mogo-module-tanlu'
include ':modules:mogo-module-share'
include ':modules:mogo-module-service'
include ':modules:mogo-module-back'
include ':libraries:map-amap'
//include ':libraries:map-baidu'
include ':libraries:mogo-map-api'