dev
This commit is contained in:
@@ -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() );
|
||||
}
|
||||
}
|
||||
27
modules/mogo-module-main/src/main/AndroidManifest.xml
Normal file
27
modules/mogo-module-main/src/main/AndroidManifest.xml
Normal 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>
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -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 );
|
||||
}
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
3
modules/mogo-module-main/src/main/res/values/strings.xml
Normal file
3
modules/mogo-module-main/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">mogo-module-main</string>
|
||||
</resources>
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user