Merge remote-tracking branch 'origin/feature/v1.0.0' into feature/v1.0.0
# Conflicts: # app/src/main/java/com/mogo/launcher/MogoApplication.java
This commit is contained in:
@@ -4,7 +4,6 @@ import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.mvp.MvpActivity;
|
||||
@@ -19,6 +18,7 @@ import com.mogo.module.extensions.ExtensionsModuleConst;
|
||||
import com.mogo.module.main.cards.CardModulesAdapter;
|
||||
import com.mogo.module.main.cards.MogoModulesHandler;
|
||||
import com.mogo.module.main.cards.MogoModulesManager;
|
||||
import com.mogo.module.main.cards.OnPageChangeListenerAdapter;
|
||||
import com.mogo.module.main.cards.OrientedViewPager;
|
||||
import com.mogo.module.main.cards.VerticalStackTransformer;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
@@ -35,7 +35,7 @@ import java.util.List;
|
||||
* @author congtaowang
|
||||
* @since 2019-12-23
|
||||
* <p>
|
||||
* 描述
|
||||
* 描述:加载各个模块
|
||||
*/
|
||||
public class MainActivity extends MvpActivity< MainView, MainPresenter > implements MainView,
|
||||
IMogoLocationListener,
|
||||
@@ -68,13 +68,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mCardsContainer = findViewById( R.id.module_main_id_cards_container );
|
||||
mCardsContainer.setOrientation( OrientedViewPager.Orientation.VERTICAL );
|
||||
|
||||
mCardsContainer.setOnPageChangeListener( new ViewPager.OnPageChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels ) {
|
||||
Logger.i( TAG, "position = " + position );
|
||||
}
|
||||
|
||||
mCardsContainer.setOnPageChangeListener( new OnPageChangeListenerAdapter() {
|
||||
@Override
|
||||
public void onPageSelected( int position ) {
|
||||
try {
|
||||
@@ -84,19 +78,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged( int state ) {
|
||||
if ( state == ViewPager.SCROLL_STATE_IDLE ) {
|
||||
// if ( mCurrentPosition == 0 ) {
|
||||
// mCurrentPosition = mCardModulesAdapter.getCount() - 3;
|
||||
// mCardsContainer.setCurrentItem( mCurrentPosition, false );
|
||||
// } else if ( mCurrentPosition == mCardModulesAdapter.getCount() - 2 ) {
|
||||
// mCurrentPosition = 1;
|
||||
// mCardsContainer.setCurrentItem( mCurrentPosition, false );
|
||||
// }
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
@@ -108,6 +89,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
MogoModulePaths.addModule( new MogoModule( MogoModulePaths.PATH_MODULE_MAP, MogoModulePaths.PATH_MODULE_MAP ) );
|
||||
MogoModulePaths.addModule( new MogoModule( ServiceConst.PATH_REFRESH_STRATEGY, ServiceConst.PATH_REFRESH_STRATEGY ) );
|
||||
MogoModulePaths.addModule( new MogoModule( ExtensionsModuleConst.PATH_EXTENSION, ExtensionsModuleConst.TYPE ) );
|
||||
MogoModulePaths.addModule( new MogoModule( ExtensionsModuleConst.PATH_ENTRANCE, ExtensionsModuleConst.TYPE_ENTRANCE ) );
|
||||
|
||||
mMogoModuleHandler = new MogoModulesManager( this );
|
||||
mMogoMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation();
|
||||
@@ -129,6 +111,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mMogoModuleHandler.loadMap( R.id.module_main_id_map_fragment_container );
|
||||
mMogoModuleHandler.loadAppsList( R.id.module_main_id_fragment_container );
|
||||
mMogoModuleHandler.loadExtensions( R.id.module_main_id_header_fragment_container );
|
||||
mMogoModuleHandler.loadEntrances( R.id.module_main_id_entrance_fragment_container );
|
||||
|
||||
mLocationClient = mMogoMapService.getSingletonLocationClient( getApplicationContext() );
|
||||
mLocationClient.addLocationListener( this );
|
||||
@@ -164,11 +147,22 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
|
||||
@Override
|
||||
public boolean onMarkerClicked( IMogoMarker marker ) {
|
||||
// int mappedCardPosition = mCardModulesAdapter.getNextCardPosition( marker.getOwner(), mCurrentPosition );
|
||||
// mCardsContainer.setCurrentItem( mappedCardPosition, true );
|
||||
switch2( marker.getOwner() );
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switch2( String cardType ) {
|
||||
if ( mCardModulesAdapter != null ) {
|
||||
int position = mCardModulesAdapter.getProviderPosition( cardType );
|
||||
if ( position != -1 ) {
|
||||
mCardsContainer.setCurrentItem( position, false );
|
||||
} else {
|
||||
Logger.e( TAG, "Can't find type of %s's position", cardType );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
package com.mogo.module.main;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.module.main.livedata.CardSwitchLiveData;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -13,4 +20,18 @@ public class MainPresenter extends Presenter< MainView > {
|
||||
public MainPresenter( MainView view ) {
|
||||
super( view );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate( @NonNull LifecycleOwner owner ) {
|
||||
super.onCreate( owner );
|
||||
CardSwitchLiveData.getInstance().observeForever( new Observer< String >() {
|
||||
@Override
|
||||
public void onChanged( String s ) {
|
||||
if ( TextUtils.isEmpty( s ) ) {
|
||||
return;
|
||||
}
|
||||
mView.switch2( s );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,6 @@ import com.mogo.commons.mvp.IView;
|
||||
* 主页 view 接口
|
||||
*/
|
||||
public interface MainView extends IView {
|
||||
|
||||
void switch2( String cardType );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mogo.module.main;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.module.main.livedata.CardSwitchLiveData;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.cardmanager.IMogoCardManager;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-06
|
||||
* <p>
|
||||
* 卡片控制
|
||||
*/
|
||||
@Route( path = MogoServicePaths.PATH_CARD_MANAGER )
|
||||
public class MogoCardManager implements IMogoCardManager {
|
||||
|
||||
@Override
|
||||
public void switch2( String cardType ) {
|
||||
CardSwitchLiveData.getInstance().postValue( cardType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -65,34 +65,23 @@ public class CardModulesAdapter extends FragmentStatePagerAdapter {
|
||||
}
|
||||
|
||||
/**
|
||||
* marker、卡片、语音等通过 launcher 切换到其他卡片。
|
||||
* 获取对应卡片类型在列表中的位置
|
||||
*
|
||||
* @param providerTag 卡片类型
|
||||
* @param currentPosition 当前卡片位置
|
||||
* @return 需要跳转到的卡片实际位置
|
||||
* @param tag 卡片类型
|
||||
* @return 列表中的位置
|
||||
*/
|
||||
public int getNextCardPosition( String providerTag, int currentPosition ) {
|
||||
int position = 0;
|
||||
int currentFactPosition = getFactPosition( currentPosition );
|
||||
for ( IMogoModuleProvider provider : mProviders ) {
|
||||
if ( TextUtils.equals( providerTag, provider.getModuleName() ) ) {
|
||||
break;
|
||||
public int getProviderPosition( String tag ) {
|
||||
if ( mProviders != null ) {
|
||||
for ( int i = 0; i < mProviders.size(); i++ ) {
|
||||
IMogoModuleProvider provider = mProviders.get( i );
|
||||
if ( provider != null ) {
|
||||
if ( TextUtils.equals( provider.getModuleName(), tag ) ) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
position++;
|
||||
}
|
||||
int offset = 0;
|
||||
if ( currentFactPosition > position ) {
|
||||
// 下一个卡片在当前卡片前面
|
||||
offset = position - mProviders.size();
|
||||
} else if ( currentFactPosition < position ) {
|
||||
// 下一个卡片在当前卡片后面
|
||||
offset = mProviders.size() - position;
|
||||
}
|
||||
return currentPosition + offset;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishUpdate( @NonNull ViewGroup container ) {
|
||||
super.finishUpdate( container );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,13 @@ public interface MogoModulesHandler extends IMogoMapListener,
|
||||
*/
|
||||
void loadExtensions( int containerId );
|
||||
|
||||
/**
|
||||
* 加载快捷操作
|
||||
*
|
||||
* @param containerId
|
||||
*/
|
||||
void loadEntrances( int containerId );
|
||||
|
||||
/**
|
||||
* 设置某一个module可用
|
||||
*
|
||||
|
||||
@@ -119,6 +119,11 @@ public class MogoModulesManager implements MogoModulesHandler,
|
||||
loadModuleByType( ModuleType.TYPE_EXTENSION, containerId );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadEntrances( int containerId ) {
|
||||
loadModuleByType( ModuleType.TYPE_ENTRANCE, containerId );
|
||||
}
|
||||
|
||||
private void loadModuleByType( int type, int containerId ) {
|
||||
if ( mModuleProviders.isEmpty() ) {
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.mogo.module.main.cards;
|
||||
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-06
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class OnPageChangeListenerAdapter implements ViewPager.OnPageChangeListener {
|
||||
|
||||
@Override
|
||||
public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected( int position ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged( int state ) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.mogo.module.main.cards;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.module.main.R;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-31
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class PlaceholderFragment extends UnDestroyedViewFragment {
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.module_main_fragement_placeholder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate( @Nullable Bundle savedInstanceState ) {
|
||||
super.onCreate( savedInstanceState );
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
package com.mogo.module.main.cards;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.mogo.commons.mvp.IView;
|
||||
import com.mogo.commons.mvp.MvpFragment;
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.module.main.R;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
import com.mogo.service.module.ModuleType;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-31
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class PlaceholderFragmentProvider implements IMogoModuleProvider {
|
||||
|
||||
private Fragment mCopyTarget;
|
||||
private PlaceholderFragment mUi;
|
||||
|
||||
public void setCopyTarget( Fragment mUICopyTarget ) {
|
||||
this.mCopyTarget = mUICopyTarget;
|
||||
}
|
||||
|
||||
public void renderTargetUI() {
|
||||
if ( mCopyTarget == null ) {
|
||||
return;
|
||||
}
|
||||
final View target = mCopyTarget.getView();
|
||||
if ( target == null ) {
|
||||
return;
|
||||
}
|
||||
target.setDrawingCacheEnabled( true );
|
||||
Bitmap result = target.getDrawingCache();
|
||||
result = target.getDrawingCache() != null ? result.copy( Bitmap.Config.ARGB_8888, false ) : null;
|
||||
if ( mUi.getView() != null ) {
|
||||
mUi.getView().setBackgroundDrawable( new BitmapDrawable( result ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment createFragment( Context context, Bundle data ) {
|
||||
mUi = new PlaceholderFragment();
|
||||
return mUi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView( Context context ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getModuleName() {
|
||||
return "placeholder";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoModuleLifecycle getCardLifecycle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMapListener getMapListener() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return ModuleType.TYPE_CARD_FRAGMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoNaviListener getNaviListener() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoLocationListener getLocationListener() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.mogo.module.main.cards;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.commons.mvp.IView;
|
||||
import com.mogo.commons.mvp.MvpFragment;
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.module.main.R;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-31
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public abstract class UnDestroyedViewFragment extends MvpFragment< IView, Presenter< IView > > implements IView {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView( @NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState ) {
|
||||
if ( mRootView == null ) {
|
||||
return super.onCreateView( inflater, container, savedInstanceState );
|
||||
}
|
||||
return mRootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected Presenter< IView > createPresenter() {
|
||||
return new Presenter< IView >( this ) {
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -26,12 +26,10 @@ public class VerticalStackTransformer extends VerticalBaseTransformer {
|
||||
protected void onTransform( View page, float position ) {
|
||||
if ( position <= 0.0f ) {
|
||||
page.setAlpha( 1.0f );
|
||||
Log.e( "onTransform", "position <= 0.0f ==>" + position );
|
||||
page.setTranslationY( 0f );
|
||||
//控制停止滑动切换的时候,只有最上面的一张卡片可以点击
|
||||
page.setClickable( true );
|
||||
} else {
|
||||
Log.e( "onTransform", "position <= 3.0f ==>" + position );
|
||||
float scale = ( float ) ( page.getWidth() - WindowUtils.dip2px( context, spaceBetweenFirAndSecWith * position ) ) / ( float ) ( page.getWidth() );
|
||||
//控制下面卡片的可见度
|
||||
page.setAlpha( 1.0f );
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.mogo.module.main.cards;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
|
||||
private static final float MAX_SCALE = 1.0f;
|
||||
private static final float MIN_SCALE = 0.85f;//0.85f
|
||||
|
||||
@Override
|
||||
public void transformPage( View view, float position ) {
|
||||
// //setScaleY只支持api11以上
|
||||
if ( position < -1 ) {
|
||||
view.setScaleX( MIN_SCALE );
|
||||
view.setScaleY( MIN_SCALE );
|
||||
} else if ( position <= 1 ) //a页滑动至b页 ; a页从 0.0 -1 ;b页从1 ~ 0.0
|
||||
{ // [-1,1]
|
||||
// Log.e("TAG", view + " , " + position + "");
|
||||
float scaleFactor = MIN_SCALE + ( 1 - Math.abs( position ) ) * ( MAX_SCALE - MIN_SCALE );
|
||||
view.setScaleX( scaleFactor );
|
||||
//每次滑动后进行微小的移动目的是为了防止在三星的某些手机上出现两边的页面为显示的情况
|
||||
if ( position > 0 ) {
|
||||
view.setTranslationX( -scaleFactor * 2 );
|
||||
} else if ( position < 0 ) {
|
||||
view.setTranslationX( scaleFactor * 2 );
|
||||
}
|
||||
view.setScaleY( scaleFactor );
|
||||
|
||||
} else { // (1,+Infinity]
|
||||
|
||||
view.setScaleX( MIN_SCALE );
|
||||
view.setScaleY( MIN_SCALE );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.mogo.module.main.livedata;
|
||||
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-06
|
||||
* <p>
|
||||
* 切换卡片
|
||||
*/
|
||||
public class CardSwitchLiveData extends MutableLiveData< String > {
|
||||
|
||||
private CardSwitchLiveData() {
|
||||
// private constructor
|
||||
}
|
||||
|
||||
private static final class InstanceHolder {
|
||||
private static final CardSwitchLiveData INSTANCE = new CardSwitchLiveData();
|
||||
}
|
||||
|
||||
public static CardSwitchLiveData getInstance() {
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user