卡片横向滑动效果

This commit is contained in:
zhangyuanzhen
2020-03-18 17:11:52 +08:00
parent 78f87fbfd6
commit ef21bef683
10 changed files with 224 additions and 21 deletions

View File

@@ -21,10 +21,10 @@ android {
multiDexEnabled true
externalNativeBuild {
ndk {
// 设置支持的SO库架构
abiFilters 'armeabi-v7a'
}
// ndk {
// // 设置支持的SO库架构
// abiFilters 'armeabi-v7a'
// }
}
}
signingConfigs {
@@ -165,3 +165,4 @@ def getGitCommit() {
assert !gitCommit.isEmpty()
gitCommit
}

View File

@@ -17,7 +17,7 @@
<dimen name="module_apps_navigation_icon_container_height">174px</dimen>
<dimen name="apps_id_scroller_width">523px</dimen>
<dimen name="apps_margin_top">18px</dimen>
<dimen name="apps_margin_left">37px</dimen>
<dimen name="module_apps_all_icon_width">120px</dimen>
<dimen name="module_apps_all_icon_height">120px</dimen>
<dimen name="apps_margin_left">35px</dimen>
<dimen name="module_apps_all_icon_width">94px</dimen>
<dimen name="module_apps_all_icon_height">94px</dimen>
</resources>

View File

@@ -14,7 +14,7 @@
android:stateNotNeeded="true"
android:taskAffinity=""
android:theme="@style/Main"
android:windowSoftInputMode="adjustPan">
android:windowSoftInputMode="adjustPan|stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!--调试用暂时开启LAUNCHER这个属性-->

View File

@@ -24,6 +24,7 @@ import com.mogo.module.common.MogoModule;
import com.mogo.module.common.MogoModulePaths;
import com.mogo.module.main.assist.MapBroadCastHelper;
import com.mogo.module.main.cards.CardModulesAdapter;
import com.mogo.module.main.cards.HorizentalStackTransformer;
import com.mogo.module.main.cards.MogoModulesHandler;
import com.mogo.module.main.cards.MogoModulesManager;
import com.mogo.module.main.cards.OnPageChangeListenerAdapter;
@@ -70,7 +71,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
private IMogoStatusManager mMogoStatusManager;
private OrientedViewPager mCardsContainer;
//private VerticalStackTransformer mTransformer;
private HorizentalStackTransformer mTransformer;
private CardModulesAdapter mCardModulesAdapter;
private View mHeader;
@@ -102,7 +103,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
protected void initViews() {
mCardsContainer = findViewById( R.id.module_main_id_cards_container );
mCardsContainer.setOrientation( OrientedViewPager.Orientation.HORIZONTAL );
//mTransformer = new VerticalStackTransformer( this );
mTransformer = new HorizentalStackTransformer( this );
mCardsContainer.setOnPageChangeListener( mOnPageChangeListener = new OnPageChangeListenerAdapter() {
private boolean mIsLast = true;
private boolean mCardFlipStatus = false;
@@ -139,7 +140,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
}
} else if ( state == ViewPager.SCROLL_STATE_IDLE ) {
mCardFlipStatus = false;
//mTransformer.resetOffsetScroll();
mTransformer.resetOffsetScroll();
}
int cardSize = mCardModulesAdapter.getCount();
@@ -164,7 +165,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
int positionOffsetPixels ) {
super.onPageScrolled( position, positionOffset, positionOffsetPixels );
Logger.d( TAG, "pageScrolled : offset --- " + positionOffset );
//mTransformer.offsetScrollChanged( positionOffset );
mTransformer.offsetScrollChanged( positionOffset );
}
} );
@@ -305,7 +306,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
List< IMogoModuleProvider > providers = mMogoModuleHandler.loadCardsModule();
mCardModulesAdapter = new CardModulesAdapter( this, providers );
mCardsContainer.setOffscreenPageLimit( providers.size() );
//mCardsContainer.setPageTransformer( true, mTransformer );
mCardsContainer.setPageTransformer( true, mTransformer );
mCardsContainer.setAdapter( mCardModulesAdapter );
}

View File

@@ -2,14 +2,18 @@ package com.mogo.module.main.assist;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import com.mogo.map.navi.MogoNaviInfo;
import com.mogo.module.service.receiver.MogoReceiver;
import com.mogo.service.impl.intent.IntentManager;
import com.mogo.service.intent.IMogoIntentListener;
/**
* @author zyz
* 2020-01-17.
*/
public class MapBroadCastHelper {
public class MapBroadCastHelper implements IMogoIntentListener {
private static volatile MapBroadCastHelper sInstance;
private static final String ACTION_NAV_SEND = "AUTONAVI_STANDARD_BROADCAST_SEND";
@@ -21,6 +25,8 @@ public class MapBroadCastHelper {
private MapBroadCastHelper(Context context) {
this.context = context;
IntentManager.getInstance().registerIntentListener(MogoReceiver.ACTION_VOICE_READY,this);
}
public static MapBroadCastHelper getInstance( Context context ) {
@@ -71,6 +77,9 @@ public class MapBroadCastHelper {
notifyXizhiNavStatus(STATUS_NAV_STOP);
}
@Override public void onIntentReceived(String intentStr, Intent intent) {
if (TextUtils.equals(intentStr, MogoReceiver.ACTION_VOICE_READY)) {
mapFrount();
}
}
}

View File

@@ -0,0 +1,110 @@
package com.mogo.module.main.cards;
import android.view.View;
import androidx.viewpager.widget.ViewPager;
/**
* Created by Nate on 2016/7/22.
*/
public abstract class HorizentalBaseTransformer implements ViewPager.PageTransformer {
/**
* Called each {@link #transformPage(View, float)}.
*
* @param page Apply the transformation to this page
* @param position Position of page relative to the current front-and-center position of the pager. 0 is front and
* center. 1 is one full page position to the right, and -1 is one page position to the left.
*/
protected abstract void onTransform(View page, float position);
/**
* Apply a property transformation to the given page. For most use cases, this method should not be overridden.
* Instead use {@link #transformPage(View, float)} to perform typical transformations.
*
* @param page Apply the transformation to this page
* @param position Position of page relative to the current front-and-center position of the pager. 0 is front and
* center. 1 is one full page position to the right, and -1 is one page position to the left.
*/
@Override
public void transformPage(View page, float position) {
onPreTransform(page, position);
onTransform(page, position);
onPostTransform(page, position);
}
/**
* If the position offset of a fragment is less than negative one or greater than one, returning true will set the
* fragment alpha to 0f. Otherwise fragment alpha is always defaulted to 1f.
*
* @return
*/
protected boolean hideOffscreenPages() {
return true;
}
/**
* Indicates if the default animations of the view pager should be used.
*
* @return
*/
protected boolean isPagingEnabled() {
return false;
}
/**
* Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)}.
* <p/>
* The default implementation attempts to reset all view properties. This is useful when toggling transforms that do
* not modify the same page properties. For instance changing from a transformation that applies rotation to a
* transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied
* alpha.
*
* @param page Apply the transformation to this page
* @param position Position of page relative to the current front-and-center position of the pager. 0 is front and
* center. 1 is one full page position to the right, and -1 is one page position to the left.
*/
protected void onPreTransform(View page, float position) {
final float width = page.getWidth();
//final float height = page.getHeight();
page.setRotationX(0);
page.setRotationY(0);
page.setRotation(0);
page.setScaleX(1);
page.setScaleY(1);
page.setPivotX(0);
page.setPivotY(0);
page.setTranslationY(0);
page.setTranslationX(isPagingEnabled() ? 0f : -width * position);
if (hideOffscreenPages()) {
page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
} else {
page.setAlpha(1f);
}
/*final float normalizedposition = Math.abs(Math.abs(position) - 1);
page.setAlpha(normalizedposition);*/
}
/**
* Called each {@link #transformPage(View, float)} after {@link #onTransform(View, float)}.
*
* @param page Apply the transformation to this page
* @param position Position of page relative to the current front-and-center position of the pager. 0 is front and
* center. 1 is one full page position to the right, and -1 is one page position to the left.
*/
protected void onPostTransform(View page, float position) {
}
/**
* Same as {@link Math#min(double, double)} without double casting, zero closest to infinity handling, or NaN support.
*
* @param val
* @param min
* @return
*/
protected static final float min(float val, float min) {
return val < min ? min : val;
}
}

View File

@@ -0,0 +1,73 @@
package com.mogo.module.main.cards;
import android.content.Context;
import android.view.View;
import com.mogo.module.main.R;
import com.mogo.utils.logger.Logger;
public class HorizentalStackTransformer extends HorizentalBaseTransformer {
private Context context;
private int spaceBetweenFirAndSecWith;//第一张卡片和第二张卡片宽度差
private int spaceBetweenFirAndSecHeight;//第一张卡片和第二张卡片高度差
private float offsetScroll = 0.0f;//ViewPager滑动时变化幅度
public HorizentalStackTransformer( Context context ) {
this.context = context;
spaceBetweenFirAndSecHeight = 0;
spaceBetweenFirAndSecWith = context.getResources().getDimensionPixelSize( R.dimen.module_main_card_card_shadow_width_div );
}
public HorizentalStackTransformer( Context context, int spaceBetweenFirAndSecWith, int spaceBetweenFirAndSecHeight ) {
this.context = context;
this.spaceBetweenFirAndSecWith = spaceBetweenFirAndSecWith;
this.spaceBetweenFirAndSecHeight = spaceBetweenFirAndSecHeight;
}
public void offsetScrollChanged(float offset){
if(offset ==0){
return;
}
offsetScroll = offset;
}
public void resetOffsetScroll(){
offsetScroll = 0.0f;
}
@Override
protected void onTransform( View page, float position ) {
if ( position == 0.0f ) {
page.setAlpha( 1.0f );
page.setTranslationX( 0f );
//控制停止滑动切换的时候,只有最上面的一张卡片可以点击
page.setClickable( true );
} else if(position>0){
float scale = ( float ) ( page.getWidth() - spaceBetweenFirAndSecWith * position ) / ( float ) ( page.getWidth() );
Logger.d("VerticalStackTransformer","scale :" + scale);
//控制下面卡片的可见度
page.setAlpha( 1.0f );
//控制停止滑动切换的时候,只有最上面的一张卡片可以点击
page.setClickable( false );
page.setPivotX( page.getWidth() / 2f );
page.setPivotY( page.getHeight() / 2f );
page.setScaleX( scale );
page.setScaleY( scale );
page.setTranslationX( -page.getHeight() * position + ( page.getHeight() * 0.5f ) * ( 1 - scale ) + spaceBetweenFirAndSecHeight * position );
}else{
float currentPage;
if(offsetScroll > 0.2f){
currentPage = 0.2f;
}else{
currentPage = offsetScroll;
}
page.setAlpha( 1 );
page.setScaleX(1-currentPage);
page.setScaleY(1-currentPage);
page.setPivotX( page.getWidth() / 2f );
page.setPivotY( page.getHeight() / 2f );
page.setTranslationX( 0f );
page.setClickable( false );
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 68 KiB

View File

@@ -82,9 +82,14 @@ public class MapPresenter extends Presenter<MapView> implements
mView.getUIController().changeMapMode(EnumMapUI.CarUp_2D);
} else if (opera_type == 1) {
mView.getUIController().changeMapMode(EnumMapUI.NorthUP_2D);
AIAssist.getInstance(getContext()).speakTTSVoice("已切换", null);
} else if (opera_type == 2) {
mView.getUIController().changeMapMode(EnumMapUI.CarUp_3D);
AIAssist.getInstance(getContext()).speakTTSVoice("已切换", null);
}
}
} else if (key_type == 10048) {
//* @param type 0:自动; 1白天; 2黑夜
@@ -111,11 +116,11 @@ public class MapPresenter extends Presenter<MapView> implements
int extra_is_show = intent.getIntExtra("EXTRA_IS_SHOW", 0);
if (extra_is_show == 0) {
mView.getUIController().displayOverview();
} else {
mView.getUIController().recoverLockMode();
}
//if (extra_is_show == 0) {
// mView.getUIController().displayOverview();
//} else {
// mView.getUIController().recoverLockMode();
//}
}else if (key_type == 10005){
int navi_route_prefer = intent.getIntExtra("NAVI_ROUTE_PREFER", type);
@@ -247,11 +252,15 @@ public class MapPresenter extends Presenter<MapView> implements
AIAssist.getInstance(getContext()).speakTTSVoice("已切换", null);
case VoiceConstants.CMD_MAP_NORTH_UP_MODE:
mView.getUIController().changeMapMode(EnumMapUI.NorthUP_2D);
AIAssist.getInstance(getContext()).speakTTSVoice("已切换", null);
break;
case VoiceConstants.CMD_MAP_3D_UN_WAKEUP:
AIAssist.getInstance(getContext()).speakTTSVoice("已切换", null);
case VoiceConstants.CMD_MAP_3D:
mView.getUIController().changeMapMode(EnumMapUI.CarUp_3D);
AIAssist.getInstance(getContext()).speakTTSVoice("已切换", null);
break;
case VoiceConstants.CMD_MAP_DAY_TIME_MODE_UN_WAKEUP:
AIAssist.getInstance(getContext()).speakTTSVoice("已切换", null);