opt: main page, add polyline api, add back to launcher logic; bugfix: map resume when back to mainactivity
This commit is contained in:
@@ -1,33 +1,31 @@
|
||||
package com.mogo.module.back;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.alibaba.idst.nls.internal.utils.L;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
import com.mogo.service.intent.IMogoIntentListener;
|
||||
import com.mogo.service.intent.IMogoIntentManager;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
import com.mogo.service.module.ModuleType;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-02-26
|
||||
@@ -35,7 +33,12 @@ import java.util.Map;
|
||||
* 描述
|
||||
*/
|
||||
@Route( path = BackToLauncherConst.MODULE_PATH )
|
||||
public class BackToLauncherModuleProvider implements IMogoModuleProvider {
|
||||
public class BackToLauncherModuleProvider implements IMogoModuleProvider, IMogoIntentListener {
|
||||
|
||||
private IMogoServiceApis mServiceApis;
|
||||
private IMogoIntentManager mIntentManager;
|
||||
|
||||
public static final String COMMAND_BACK = "com.ileja.launcher.back";
|
||||
|
||||
private static final String TAG = "BackToLauncherModuleProvider";
|
||||
|
||||
@@ -98,54 +101,17 @@ public class BackToLauncherModuleProvider implements IMogoModuleProvider {
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
BackToMainHomeManager.addMainHomeView();
|
||||
// final Activity activity = getTopActivity(context.getPackageName());
|
||||
// if ( activity instanceof FragmentActivity ) {
|
||||
// Logger.d( TAG, "init." );
|
||||
// FragmentManager fragmentManager = ( ( FragmentActivity ) activity ).getSupportFragmentManager();
|
||||
// fragmentManager.beginTransaction()
|
||||
// .add( new Back2LauncherFragment(), BackToLauncherConst.MODULE_NAME )
|
||||
// .commitAllowingStateLoss();
|
||||
// fragmentManager.executePendingTransactions();
|
||||
// }
|
||||
mServiceApis = ( IMogoServiceApis ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICE_APIS ).navigation();
|
||||
mIntentManager = mServiceApis.getIntentManagerApi();
|
||||
mIntentManager.registerIntentListener( COMMAND_BACK, this );
|
||||
BackToMainHomeManager.init( mServiceApis.getFragmentManagerApi() );
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 获取当前运行的activity
|
||||
// */
|
||||
// private Activity getTopActivity(String process) {
|
||||
// Log.i("activity", "[getTopActivity]");
|
||||
// try {
|
||||
// Class activityThreadClass = Class.forName("android.app.ActivityThread");
|
||||
// Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null);
|
||||
// Field activitiesField = activityThreadClass.getDeclaredField("mActivities");
|
||||
// activitiesField.setAccessible(true);
|
||||
// //16~18 HashMap
|
||||
// //19~27 ArrayMap
|
||||
// Map<Object, Object> activities;
|
||||
// if ( Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
// activities = ( HashMap<Object, Object> ) activitiesField.get(activityThread);
|
||||
// } else {
|
||||
// activities = ( ArrayMap<Object, Object> ) activitiesField.get(activityThread);
|
||||
// }
|
||||
// if (activities.size() < 1) {
|
||||
// return null;
|
||||
// }
|
||||
// for (Object activityRecord : activities.values()) {
|
||||
// Class activityRecordClass = activityRecord.getClass();
|
||||
// Field pausedField = activityRecordClass.getDeclaredField("paused");
|
||||
// pausedField.setAccessible(true);
|
||||
// if (!pausedField.getBoolean(activityRecord)) {
|
||||
// Field activityField = activityRecordClass.getDeclaredField("activity");
|
||||
// activityField.setAccessible(true);
|
||||
// Activity activity = (Activity) activityField.get(activityRecord);
|
||||
// if ( TextUtils.equals( process, activity.getPackageName() ) ) {
|
||||
// return activity;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
@Override
|
||||
public void onIntentReceived( String intentStr, Intent intent ) {
|
||||
if ( COMMAND_BACK.equals( intentStr ) ) {
|
||||
Logger.d( TAG, "received back to home command." );
|
||||
BackToMainHomeManager.backToLauncher();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,15 +14,35 @@ import android.view.WindowManager;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.module.back.utils.Utils;
|
||||
import com.mogo.module.back.utils.WindowManagerViewHelper;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
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);
|
||||
|
||||
private static IMogoFragmentManager mFragmentManager;
|
||||
|
||||
public static void init( IMogoFragmentManager manager ) {
|
||||
mFragmentManager = manager;
|
||||
}
|
||||
|
||||
public static void backToLauncher(){
|
||||
Intent intent = new Intent();
|
||||
intent.setAction( Intent.ACTION_MAIN );
|
||||
intent.addCategory( Intent.CATEGORY_HOME );
|
||||
intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
AbsMogoApplication.getApp().startActivity( intent );
|
||||
|
||||
if ( mFragmentManager != null ) {
|
||||
mFragmentManager.clearAll();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -31,32 +51,24 @@ public class BackToMainHomeManager {
|
||||
if ( windowManager == null ) {
|
||||
return;
|
||||
}
|
||||
mBackView.setOnClickListener(view -> {
|
||||
if (Utils.isActivityExits("com.mogo.launcher","com.mogo.module.main.MainActivity")){
|
||||
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);
|
||||
}
|
||||
});
|
||||
mBackView.setOnClickListener( view -> {
|
||||
backToLauncher();
|
||||
} );
|
||||
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.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);
|
||||
WindowManagerViewHelper.attachMovementEvent( mBackView, params );
|
||||
}
|
||||
|
||||
public static void removeMainHomeView(){
|
||||
WindowManagerViewHelper.removeView(mBackView);
|
||||
public static void removeMainHomeView() {
|
||||
WindowManagerViewHelper.removeView( mBackView );
|
||||
}
|
||||
|
||||
private static int getFitWindowParamsType() {
|
||||
|
||||
@@ -7,13 +7,13 @@ import android.content.pm.ResolveInfo;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
|
||||
public class Utils {
|
||||
public static boolean isActivityExits(String packageName,String classStr){
|
||||
public static boolean isActivityExits( String packageName, String classStr ) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName(packageName, classStr);
|
||||
ResolveInfo resolveInfo = AbsMogoApplication.getApp().getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||
if(resolveInfo != null) {
|
||||
intent.setClassName( packageName, classStr );
|
||||
ResolveInfo resolveInfo = AbsMogoApplication.getApp().getPackageManager().resolveActivity( intent, PackageManager.MATCH_DEFAULT_ONLY );
|
||||
if ( resolveInfo != null ) {
|
||||
return true;
|
||||
}else{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user