This commit is contained in:
wangcongtao
2019-12-24 15:49:57 +08:00
parent 80cc1248b2
commit fea6d0bc61
133 changed files with 4878 additions and 194 deletions

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

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

View File

@@ -0,0 +1,34 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

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,27 @@
package com.mogo.module.common;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith( AndroidJUnit4.class )
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals( "com.mogo.module.common.test", appContext.getPackageName() );
}
}

View File

@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.module.common" />

View File

@@ -0,0 +1,20 @@
package com.mogo.module.common;
/**
* @author congtaowang
* @since 2019-12-23
* <p>
* 模块路由路径
*/
public class MogoModulePaths {
/**
* 地图模块 fragment 路径
*/
public static final String PATH_MODULE_MAP = "/module/map";
/**
* 测试模块
*/
public static final String PATH_MODULE_DEMO = "/demo/module/demo";
}

View File

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

View File

@@ -0,0 +1,17 @@
package com.mogo.module.common;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals( 4, 2 + 2 );
}
}

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

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

View File

@@ -0,0 +1,47 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":foudations:mogo-utils")
implementation project(":foudations:mogo-commons")
implementation project(':modules:mogo-module-common')
implementation project(':modules:mogo-module-map')
implementation project(':services:mogo-service-api')
implementation project(':services:mogo-service')
implementation project(':demo:demo-module-map')
implementation rootProject.ext.dependencies.androidxappcompat
implementation rootProject.ext.dependencies.androidxconstraintlayout
implementation rootProject.ext.dependencies.arouter
annotationProcessor rootProject.ext.dependencies.aroutercompiler
}

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,27 @@
package com.mogo.module.main;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith( AndroidJUnit4.class )
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals( "com.mogo.module.main.test", appContext.getPackageName() );
}
}

View File

@@ -0,0 +1,27 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.module.main">
<application>
<activity
android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|mcc|mnc|keyboard|navigation"
android:enabled="true"
android:launchMode="singleInstance"
android:resizeableActivity="true"
android:resumeWhilePausing="true"
android:screenOrientation="nosensor"
android:stateNotNeeded="true"
android:taskAffinity=""
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!--调试用暂时开启LAUNCHER这个属性-->
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER_APP" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,68 @@
package com.mogo.module.main;
import android.view.MotionEvent;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.commons.mvp.MvpActivity;
import com.mogo.map.listener.IMogoMapListener;
import com.mogo.map.model.MogoPoi;
import com.mogo.module.main.cards.MogoModulesHandler;
import com.mogo.module.main.cards.MogoModulesManager;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.map.IMogoMapService;
import com.mogo.service.module.IMogoModuleProvider;
import java.util.Collection;
/**
* @author congtaowang
* @since 2019-12-23
* <p>
* 描述
*/
public class MainActivity extends MvpActivity< MainView, MainPresenter > implements MainView {
IMogoMapService ims;
MogoModulesHandler handler;
@Override
protected int getLayoutId() {
return R.layout.module_main_activity_main;
}
@Override
protected void initViews() {
handler = new MogoModulesManager( this );
ims = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation();
if ( ims != null ) {
ims.registerHostMapListener( handler );
}
handler.loadMap( R.id.module_main_id_fragment_container );
Collection< IMogoModuleProvider > providers = handler.loadCards();
for ( IMogoModuleProvider provider : providers ) {
if ( provider == null ) {
continue;
}
if ( provider.getType() == IMogoModuleProvider.TYPE_FRAGMENT ) {
final Fragment fragment = provider.createFragment( this, null );
if ( fragment != null ) {
getSupportFragmentManager().beginTransaction()
.add( R.id.module_main_id_fragment_container, fragment )
.commitAllowingStateLoss();
}
}
}
handler.setEnable( providers.iterator().next().getModuleName() );
}
@NonNull
@Override
protected MainPresenter createPresenter() {
return new MainPresenter( this );
}
}

View File

@@ -0,0 +1,16 @@
package com.mogo.module.main;
import com.mogo.commons.mvp.Presenter;
/**
* @author congtaowang
* @since 2019-12-23
* <p>
* 描述
*/
public class MainPresenter extends Presenter< MainView > {
public MainPresenter( MainView view ) {
super( view );
}
}

View File

@@ -0,0 +1,12 @@
package com.mogo.module.main;
import com.mogo.commons.mvp.IView;
/**
* @author congtaowang
* @since 2019-12-23
* <p>
* 主页 view 接口
*/
public interface MainView extends IView {
}

View File

@@ -0,0 +1,50 @@
package com.mogo.module.main.cards;
import com.mogo.map.listener.IMogoMapListener;
import com.mogo.service.module.IMogoModuleProvider;
import java.util.Collection;
/**
* @author congtaowang
* @since 2019-12-24
* <p>
* 卡片管理
*/
public interface MogoModulesHandler extends IMogoMapListener {
/**
* 加载卡片
*
* @return
*/
Collection< IMogoModuleProvider > loadCards();
/**
* 加载小智语音
*
* @param containerId 容器id
*/
void loadAIAssist( int containerId );
/**
* 加载天气
*
* @param containerId 容器id
*/
void loadWeather( int containerId );
/**
* 加载地图
*
* @param containerId 容器id
*/
void loadMap( int containerId );
/**
* 设置某一个module可用
*
* @param module
*/
void setEnable( String module );
}

View File

@@ -0,0 +1,138 @@
package com.mogo.module.main.cards;
import android.content.Context;
import android.text.TextUtils;
import android.view.MotionEvent;
import androidx.fragment.app.Fragment;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.map.listener.IMogoMapListener;
import com.mogo.map.model.MogoPoi;
import com.mogo.module.common.MogoModulePaths;
import com.mogo.module.main.MainActivity;
import com.mogo.service.module.IMogoModuleProvider;
import com.mogo.utils.ResourcesHelper;
import com.mogo.utils.logger.Logger;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* @author congtaowang
* @since 2019-12-24
* <p>
* 卡片加载
*/
public class MogoModulesManager implements MogoModulesHandler, IMogoMapListener {
private static final String TAG = "MogoModulesManager";
private MainActivity mActivity;
private final Map< String, IMogoModuleProvider > mCardProviders = new HashMap<>();
private IMogoModuleProvider mMapProvider;
private String mEnableModuleName = null;
public MogoModulesManager( MainActivity activity ) {
if ( activity == null ) {
throw new NullPointerException( "activity can't be null." );
}
this.mActivity = activity;
}
private Context getContext() {
return mActivity;
}
private Context getApplicationContext() {
return mActivity.getApplicationContext();
}
@Override
public Collection< IMogoModuleProvider > loadCards() {
IMogoModuleProvider demo = load( MogoModulePaths.PATH_MODULE_DEMO );
mCardProviders.put( demo.getModuleName(), demo );
return mCardProviders.values();
}
@Override
public void loadAIAssist( int containerId ) {
}
@Override
public void loadWeather( int containerId ) {
}
@Override
public void loadMap( int containerId ) {
mMapProvider = load( MogoModulePaths.PATH_MODULE_MAP );
addFragment( mMapProvider, containerId );
}
private IMogoModuleProvider load( String path ) {
return ( IMogoModuleProvider ) ARouter.getInstance().build( path ).navigation( getContext() );
}
private void addFragment( IMogoModuleProvider provider, int containerId ) {
if ( provider == null ) {
Logger.e( TAG, "add fragment fail cause provider == null, container is %s", ResourcesHelper.getResNameById( getApplicationContext(), containerId ) );
return;
}
final Fragment fragment = provider.createFragment( getContext(), null );
if ( fragment == null ) {
Logger.e( TAG, "add fragment fail cause fragment == null, container is %s", ResourcesHelper.getResNameById( getApplicationContext(), containerId ) );
return;
}
mActivity.getSupportFragmentManager().beginTransaction()
.add( containerId, fragment, provider.getModuleName() )
.commitAllowingStateLoss();
}
@Override
public void setEnable( String module ) {
mEnableModuleName = module;
final Set< Map.Entry< String, IMogoModuleProvider > > entries = mCardProviders.entrySet();
if ( !entries.isEmpty() ) {
for ( Map.Entry< String, IMogoModuleProvider > entry : entries ) {
final String key = entry.getKey();
final IMogoModuleProvider provider = entry.getValue();
if ( TextUtils.equals( key, module ) ) {
provider.getCardLifecycle().onPerform();
} else {
provider.getCardLifecycle().onDisable();
}
}
}
}
@Override
public void onMapLoaded() {
if ( mEnableModuleName != null ) {
if ( mCardProviders.get( mEnableModuleName ) != null ) {
mCardProviders.get( mEnableModuleName ).getMapListener().onMapLoaded();
}
}
}
@Override
public void onTouch( MotionEvent motionEvent ) {
if ( mEnableModuleName != null ) {
if ( mCardProviders.get( mEnableModuleName ) != null ) {
mCardProviders.get( mEnableModuleName ).getMapListener().onTouch( motionEvent );
}
}
}
@Override
public void onPOIClick( MogoPoi poi ) {
if ( mEnableModuleName != null ) {
if ( mCardProviders.get( mEnableModuleName ) != null ) {
mCardProviders.get( mEnableModuleName ).getMapListener().onPOIClick( poi );
}
}
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/module_main_id_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

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

View File

@@ -0,0 +1,17 @@
package com.mogo.module.main;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals( 4, 2 + 2 );
}
}

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

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

View File

@@ -0,0 +1,46 @@
apply plugin: 'com.android.library'
apply plugin: 'com.alibaba.arouter'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
javaCompileOptions {
annotationProcessorOptions {
arguments = [AROUTER_MODULE_NAME: project.getName()]
}
}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":libraries:mogo-map")
implementation project(":foudations:mogo-utils")
api project(":foudations:mogo-commons")
implementation project(':services:mogo-service-api')
implementation project(':modules:mogo-module-common')
implementation rootProject.ext.dependencies.androidxappcompat
implementation rootProject.ext.dependencies.androidxconstraintlayout
implementation rootProject.ext.dependencies.arouter
annotationProcessor rootProject.ext.dependencies.aroutercompiler
}

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,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.module.map" />

View File

@@ -0,0 +1,98 @@
package com.mogo.module.map;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.map.IMogoMap;
import com.mogo.map.IUiSettings;
import com.mogo.map.MogoMapView;
import com.mogo.module.common.MogoModulePaths;
/**
* @author congtaowang
* @since 2019-12-23
* <p>
* 地图图层,地图操作都在这个图层完成
*/
public class MapFragment extends MvpFragment< MapView, MapPresenter > implements MapView {
private MogoMapView mMogoMapView;
private IMogoMap mMogoMap;
@Override
protected int getLayoutId() {
return R.layout.module_map_fragment_map;
}
@Override
protected void initViews() {
mMogoMapView = findViewById( R.id.module_map_id_map );
mMogoMap = mMogoMapView.getMap();
}
@NonNull
@Override
protected MapPresenter createPresenter() {
return new MapPresenter( this );
}
@Override
public void onActivityCreated( @Nullable Bundle savedInstanceState ) {
super.onActivityCreated( savedInstanceState );
if ( mMogoMapView != null ) {
mMogoMapView.onCreate( savedInstanceState );
}
initMapView();
}
@Override
public void onPause() {
super.onPause();
if ( mMogoMapView != null ) {
mMogoMapView.onPause();
}
}
@Override
public void onResume() {
super.onResume();
if ( mMogoMapView != null ) {
mMogoMapView.onResume();
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
if ( mMogoMapView != null ) {
mMogoMapView.onDestroy();
}
}
@Override
public void onLowMemory() {
super.onLowMemory();
if ( mMogoMapView != null ) {
mMogoMapView.onLowMemory();
}
}
private void initMapView() {
if ( mMogoMap != null ) {
IUiSettings settings = mMogoMap.getUiSettings();
if ( settings != null ) {
settings.setCompassEnabled( false );
settings.setLogoEnable( false );
settings.setMyLocationButtonEnabled( false );
settings.setRotateGesturesEnabled( false );
settings.setZoomControlsEnabled( false );
settings.setScaleControlsEnabled( false );
}
}
}
}

View File

@@ -0,0 +1,65 @@
package com.mogo.module.map;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.map.listener.IMogoMapListener;
import com.mogo.module.common.MogoModulePaths;
import com.mogo.service.module.IMogoModuleLifecycle;
import com.mogo.service.module.IMogoModuleProvider;
/**
* @author congtaowang
* @since 2019-12-24
* <p>
* 描述
*/
@Route( path = MogoModulePaths.PATH_MODULE_MAP )
public class MapFragmentProvider implements IMogoModuleProvider {
private MapFragment mMapFragment;
@Override
public Fragment createFragment( Context context, Bundle data ) {
mMapFragment = new MapFragment();
mMapFragment.setArguments( data );
return mMapFragment;
}
@NonNull
@Override
public String getModuleName() {
return MogoModulePaths.PATH_MODULE_MAP;
}
@Override
public void init( Context context ) {
}
@Override
public int getType() {
return IMogoModuleProvider.TYPE_FRAGMENT;
}
@Override
public View createView( Context context ) {
return null;
}
@Override
public IMogoModuleLifecycle getCardLifecycle() {
return null;
}
@Override
public IMogoMapListener getMapListener() {
return null;
}
}

View File

@@ -0,0 +1,18 @@
package com.mogo.module.map;
import com.mogo.commons.mvp.Presenter;
/**
* @author congtaowang
* @since 2019-12-23
* <p>
* 描述
*/
public class MapPresenter extends Presenter< MapView > {
public MapPresenter( MapView view ) {
super( view );
}
}

View File

@@ -0,0 +1,12 @@
package com.mogo.module.map;
import com.mogo.commons.mvp.IView;
/**
* @author congtaowang
* @since 2019-12-23
* <p>
* 地图view
*/
public interface MapView extends IView {
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mogo.map.MogoMapView
android:id="@+id/module_map_id_map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

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