Merge remote-tracking branch 'origin/feature/v2.0.0' into feature/v2.0.0
This commit is contained in:
@@ -492,7 +492,7 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveToCenter( MogoLatLng latLng ) {
|
||||
public void moveToCenter( MogoLatLng latLng, boolean animate ) {
|
||||
Logger.d( TAG, "move to center %s", latLng );
|
||||
if ( latLng == null || latLng.lat == 0.0d || latLng.lng == 0.0d ) {
|
||||
Logger.e( TAG, "latlng = null or is illegal" );
|
||||
@@ -502,7 +502,11 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
}
|
||||
loseLockMode();
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.newLatLng( new LatLng( latLng.lat, latLng.lng ) ) );
|
||||
if ( animate ) {
|
||||
mMapView.getMap().animateCamera( CameraUpdateFactory.newLatLng( new LatLng( latLng.lat, latLng.lng ) ) );
|
||||
} else {
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.newLatLng( new LatLng( latLng.lat, latLng.lng ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -85,9 +85,9 @@ public class AMapUIController implements IMogoMapUIController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveToCenter(MogoLatLng latLng) {
|
||||
public void moveToCenter(MogoLatLng latLng, boolean animate) {
|
||||
if (mClient != null) {
|
||||
mClient.moveToCenter(latLng);
|
||||
mClient.moveToCenter(latLng, animate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,14 @@ public interface IMogoMapUIController {
|
||||
/**
|
||||
* 将地图移动至当前位置
|
||||
*/
|
||||
void moveToCenter( MogoLatLng latLng );
|
||||
default void moveToCenter( MogoLatLng latLng ){
|
||||
moveToCenter(latLng, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将地图移动至当前位置
|
||||
*/
|
||||
void moveToCenter( MogoLatLng latLng, boolean animate );
|
||||
|
||||
/**
|
||||
* 显示我的位置
|
||||
|
||||
@@ -79,9 +79,9 @@ public class MogoMapUIController implements IMogoMapUIController {
|
||||
|
||||
|
||||
@Override
|
||||
public void moveToCenter(MogoLatLng latLng) {
|
||||
public void moveToCenter(MogoLatLng latLng, boolean animate) {
|
||||
if (mDelegate != null) {
|
||||
mDelegate.moveToCenter(latLng);
|
||||
mDelegate.moveToCenter(latLng, animate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,9 @@ public class AppLauncher extends BaseAppLauncher {
|
||||
@Override
|
||||
public void launch( Context context, AppInfo appInfo ) {
|
||||
try {
|
||||
AppServiceHandler.getApis().getAdasControllerApi().closeADAS();
|
||||
if ( LaunchUtils.getLaunchIntentForPackage( context, appInfo.getPackageName() ) != null ) {
|
||||
AppServiceHandler.getApis().getAdasControllerApi().closeADAS();
|
||||
}
|
||||
LaunchUtils.launchByPkg( context, appInfo.getPackageName() );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
|
||||
@@ -35,13 +35,8 @@ public class CardAppLauncher extends BaseAppLauncher {
|
||||
|
||||
@Override
|
||||
public void launch( Context context, AppInfo appInfo ) {
|
||||
if ( sCardApps.containsKey( appInfo.getPackageName() ) ) {
|
||||
mCardManager.switch2( sCardApps.get( appInfo.getPackageName() ) );
|
||||
mAppsPresenter.exit();
|
||||
} else {
|
||||
if ( getNext() != null ) {
|
||||
getNext().launch( context, appInfo );
|
||||
}
|
||||
if ( getNext() != null ) {
|
||||
getNext().launch( context, appInfo );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
package com.mogo.module.apps.applaunch;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.module.apps.AppServiceHandler;
|
||||
import com.mogo.module.apps.R;
|
||||
import com.mogo.module.apps.model.AppInfo;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import kotlin.Unit;
|
||||
|
||||
public class GuideShowLauncher extends BaseAppLauncher {
|
||||
|
||||
@@ -25,19 +18,7 @@ public class GuideShowLauncher extends BaseAppLauncher {
|
||||
|
||||
@Override
|
||||
public void launch(Context context, AppInfo appInfo) {
|
||||
if (appInfo != null && APP_INFO_NAME_GUIDE_SHOW.equals(appInfo.getName())) {
|
||||
if ( mNavi != null && !mNavi.isNaviing()) {
|
||||
AppServiceHandler.getMogoGuideShow().playGuideVideo((Activity) context, (s) -> {
|
||||
Logger.d(TAG, s);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
} else {
|
||||
AIAssist.getInstance(context).speakTTSVoice(context.getString(R.string.module_apps_str_guide_warning));
|
||||
processChain(context,appInfo);
|
||||
}
|
||||
} else {
|
||||
processChain(context, appInfo);
|
||||
}
|
||||
processChain(context, appInfo);
|
||||
}
|
||||
|
||||
private void processChain(Context context, AppInfo appInfo) {
|
||||
|
||||
@@ -20,9 +20,13 @@ public class LaunchUtils {
|
||||
* @param context
|
||||
* @param pkg 包名
|
||||
*/
|
||||
public static void launchByPkg( Context context, String pkg ) throws Exception{
|
||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage( pkg );
|
||||
public static void launchByPkg( Context context, String pkg ) throws Exception {
|
||||
Intent intent = getLaunchIntentForPackage( context, pkg );
|
||||
intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
context.startActivity( intent );
|
||||
}
|
||||
|
||||
public static Intent getLaunchIntentForPackage( Context context, String pkg ) {
|
||||
return context.getPackageManager().getLaunchIntentForPackage( pkg );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class BackToMainHomeManager {
|
||||
|
||||
public static void backToLauncher() {
|
||||
|
||||
if ( mFragmentManager != null ) {
|
||||
if ( !mStatusManager.isSearchUIShow() ) {
|
||||
mFragmentManager.clearAll();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation rootProject.ext.dependencies.androidxappcompat
|
||||
implementation rootProject.ext.dependencies.androidxrecyclerview
|
||||
|
||||
implementation rootProject.ext.dependencies.androidxconstraintlayout
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
api rootProject.ext.dependencies.mogomap
|
||||
api rootProject.ext.dependencies.mogomapapi
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
package com.mogo.module.common.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Build;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.mogo.module.common.R;
|
||||
import com.mogo.module.common.utils.CarSeries;
|
||||
import com.mogo.utils.WindowUtils;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-04-24
|
||||
* <p>
|
||||
* 显示在最上层的对话框
|
||||
*/
|
||||
public class WMDialog implements DialogInterface {
|
||||
|
||||
private WMDialogParams mParams;
|
||||
private WindowManager mWindowManager;
|
||||
private boolean mIsShowing = false;
|
||||
private View mContentView;
|
||||
private WindowManager.LayoutParams mLayoutParams;
|
||||
|
||||
private WMDialog( WMDialogParams params ) {
|
||||
this.mParams = params;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if ( mIsShowing ) {
|
||||
return;
|
||||
}
|
||||
mIsShowing = true;
|
||||
if ( mWindowManager == null ) {
|
||||
mWindowManager = ( WindowManager ) mParams.mContext.getApplicationContext().getSystemService( Context.WINDOW_SERVICE );
|
||||
}
|
||||
if ( mContentView == null ) {
|
||||
mLayoutParams = new WindowManager.LayoutParams();
|
||||
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) {
|
||||
mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
} else {
|
||||
mLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
|
||||
}
|
||||
mLayoutParams.format = PixelFormat.TRANSLUCENT;
|
||||
mLayoutParams.gravity = Gravity.CENTER;
|
||||
mLayoutParams.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
|
||||
|
||||
if ( CarSeries.getSeries() == CarSeries.CAR_SERIES_F80X ) {
|
||||
mLayoutParams.width = 1920;
|
||||
mLayoutParams.height = 1080;
|
||||
} else {
|
||||
mLayoutParams.width = WindowUtils.getScreenWidth( mParams.mContext );
|
||||
mLayoutParams.height = WindowUtils.getScreenHeight( mParams.mContext );
|
||||
}
|
||||
mLayoutParams.dimAmount = 0.5f;
|
||||
mLayoutParams.x = 0;
|
||||
mLayoutParams.y = 0;
|
||||
mContentView = initViews();
|
||||
}
|
||||
mWindowManager.addView( mContentView, mLayoutParams );
|
||||
}
|
||||
|
||||
private View initViews() {
|
||||
View contentView = LayoutInflater.from( mParams.mContext ).inflate( R.layout.module_commons_layout_wm_dialog, null );
|
||||
TextView ok = contentView.findViewById( R.id.module_commons_wm_dialog_button_ok );
|
||||
TextView cancel = contentView.findViewById( R.id.module_commons_wm_dialog_button_cancel );
|
||||
TextView content = contentView.findViewById( R.id.module_commons_wm_dialog_content );
|
||||
|
||||
ok.setText( mParams.mOkButtonText );
|
||||
if ( mParams.mOnOkButtonClickListener != null ) {
|
||||
ok.setOnClickListener( view -> {
|
||||
if ( mParams.mOnOkButtonClickListener != null ) {
|
||||
mParams.mOnOkButtonClickListener.onClick( WMDialog.this, DialogInterface.BUTTON_POSITIVE );
|
||||
}
|
||||
} );
|
||||
}
|
||||
cancel.setText( mParams.mCancelButtonText );
|
||||
if ( mParams.mOnCancelButtonClickListener != null ) {
|
||||
cancel.setOnClickListener( view -> {
|
||||
if ( mParams.mOnCancelButtonClickListener != null ) {
|
||||
mParams.mOnCancelButtonClickListener.onClick( WMDialog.this, DialogInterface.BUTTON_NEGATIVE );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
content.setText( mParams.mContent );
|
||||
return contentView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
if ( !mIsShowing ) {
|
||||
return;
|
||||
}
|
||||
if ( mContentView != null ) {
|
||||
mWindowManager.removeViewImmediate( mContentView );
|
||||
}
|
||||
if ( mParams.mOnDialogDismissListener != null ) {
|
||||
mParams.mOnDialogDismissListener.onDismiss( this );
|
||||
}
|
||||
mIsShowing = false;
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
return mIsShowing;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private Context mContext;
|
||||
private WMDialogParams mParams;
|
||||
|
||||
public Builder( Context context ) {
|
||||
this.mContext = context;
|
||||
mParams = new WMDialogParams();
|
||||
mParams.mContext = context;
|
||||
}
|
||||
|
||||
// public Builder setTitle( CharSequence title ) {
|
||||
// mParams.mTitle = title;
|
||||
// return this;
|
||||
// }
|
||||
//
|
||||
// public Builder setTitle( @StringRes int title ) {
|
||||
// mParams.mTitle = mContext.getString( title );
|
||||
// return this;
|
||||
// }
|
||||
|
||||
public Builder setContent( CharSequence content ) {
|
||||
mParams.mContent = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setContent( @StringRes int content ) {
|
||||
mParams.mContent = mContext.getString( content );
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setOkButton( CharSequence buttonText, OnClickListener listener ) {
|
||||
mParams.mOkButtonText = buttonText;
|
||||
mParams.mOnOkButtonClickListener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setOkButton( @StringRes int buttonText, OnClickListener listener ) {
|
||||
mParams.mOkButtonText = mContext.getText( buttonText );
|
||||
mParams.mOnOkButtonClickListener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCancelButton( CharSequence buttonText, OnClickListener listener ) {
|
||||
mParams.mCancelButtonText = buttonText;
|
||||
mParams.mOnCancelButtonClickListener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCancelButton( @StringRes int buttonText, OnClickListener listener ) {
|
||||
mParams.mCancelButtonText = mContext.getText( buttonText );
|
||||
mParams.mOnCancelButtonClickListener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setOnDialogDismissListener( OnDismissListener onDialogDismissListener ) {
|
||||
mParams.mOnDialogDismissListener = onDialogDismissListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WMDialog build() {
|
||||
WMDialog dialog = new WMDialog( mParams );
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
||||
public static class WMDialogParams {
|
||||
|
||||
// public CharSequence mTitle;
|
||||
public CharSequence mOkButtonText;
|
||||
public CharSequence mCancelButtonText;
|
||||
public CharSequence mContent;
|
||||
public OnClickListener mOnOkButtonClickListener;
|
||||
public OnClickListener mOnCancelButtonClickListener;
|
||||
public OnDismissListener mOnDialogDismissListener;
|
||||
public Context mContext;
|
||||
}
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
package com.yarolegovich.discretescrollview;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Created by yarolegovich on 16.03.2017.
|
||||
*/
|
||||
public enum DSVOrientation {
|
||||
|
||||
HORIZONTAL {
|
||||
@Override
|
||||
Helper createHelper() {
|
||||
return new HorizontalHelper();
|
||||
}
|
||||
},
|
||||
VERTICAL {
|
||||
@Override
|
||||
Helper createHelper() {
|
||||
return new VerticalHelper();
|
||||
}
|
||||
};
|
||||
|
||||
//Package private
|
||||
abstract Helper createHelper();
|
||||
|
||||
interface Helper {
|
||||
|
||||
int getViewEnd(int recyclerWidth, int recyclerHeight);
|
||||
|
||||
int getDistanceToChangeCurrent(int childWidth, int childHeight);
|
||||
|
||||
void setCurrentViewCenter(Point recyclerCenter, int scrolled, Point outPoint);
|
||||
|
||||
void shiftViewCenter(Direction direction, int shiftAmount, Point outCenter);
|
||||
|
||||
int getFlingVelocity(int velocityX, int velocityY);
|
||||
|
||||
int getPendingDx(int pendingScroll);
|
||||
|
||||
int getPendingDy(int pendingScroll);
|
||||
|
||||
void offsetChildren(int amount, RecyclerViewProxy lm);
|
||||
|
||||
float getDistanceFromCenter(Point center, int viewCenterX, int viewCenterY);
|
||||
|
||||
boolean isViewVisible(Point center, int halfWidth, int halfHeight, int endBound,
|
||||
int extraSpace);
|
||||
|
||||
boolean hasNewBecomeVisible(DiscreteScrollLayoutManager lm);
|
||||
|
||||
boolean canScrollVertically();
|
||||
|
||||
boolean canScrollHorizontally();
|
||||
}
|
||||
|
||||
protected static class HorizontalHelper implements Helper {
|
||||
|
||||
@Override
|
||||
public int getViewEnd(int recyclerWidth, int recyclerHeight) {
|
||||
return recyclerWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDistanceToChangeCurrent(int childWidth, int childHeight) {
|
||||
return childWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentViewCenter(Point recyclerCenter, int scrolled, Point outPoint) {
|
||||
int newX = recyclerCenter.x - scrolled;
|
||||
outPoint.set(newX, recyclerCenter.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shiftViewCenter(Direction direction, int shiftAmount, Point outCenter) {
|
||||
int newX = outCenter.x + direction.applyTo(shiftAmount);
|
||||
outCenter.set(newX, outCenter.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewVisible(
|
||||
Point viewCenter, int halfWidth, int halfHeight, int endBound,
|
||||
int extraSpace) {
|
||||
int viewLeft = viewCenter.x - halfWidth;
|
||||
int viewRight = viewCenter.x + halfWidth;
|
||||
return viewLeft < (endBound + extraSpace) && viewRight > -extraSpace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNewBecomeVisible(DiscreteScrollLayoutManager lm) {
|
||||
View firstChild = lm.getFirstChild(), lastChild = lm.getLastChild();
|
||||
int leftBound = -lm.getExtraLayoutSpace();
|
||||
int rightBound = lm.getWidth() + lm.getExtraLayoutSpace();
|
||||
boolean isNewVisibleFromLeft = lm.getDecoratedLeft(firstChild) > leftBound
|
||||
&& lm.getPosition(firstChild) > 0;
|
||||
boolean isNewVisibleFromRight = lm.getDecoratedRight(lastChild) < rightBound
|
||||
&& lm.getPosition(lastChild) < lm.getItemCount() - 1;
|
||||
return isNewVisibleFromLeft || isNewVisibleFromRight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offsetChildren(int amount, RecyclerViewProxy helper) {
|
||||
helper.offsetChildrenHorizontal(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDistanceFromCenter(Point center, int viewCenterX, int viewCenterY) {
|
||||
return viewCenterX - center.x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFlingVelocity(int velocityX, int velocityY) {
|
||||
return velocityX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canScrollHorizontally() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPendingDx(int pendingScroll) {
|
||||
return pendingScroll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPendingDy(int pendingScroll) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected static class VerticalHelper implements Helper {
|
||||
|
||||
@Override
|
||||
public int getViewEnd(int recyclerWidth, int recyclerHeight) {
|
||||
return recyclerHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDistanceToChangeCurrent(int childWidth, int childHeight) {
|
||||
return childHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentViewCenter(Point recyclerCenter, int scrolled, Point outPoint) {
|
||||
int newY = recyclerCenter.y - scrolled;
|
||||
outPoint.set(recyclerCenter.x, newY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shiftViewCenter(Direction direction, int shiftAmount, Point outCenter) {
|
||||
int newY = outCenter.y + direction.applyTo(shiftAmount);
|
||||
outCenter.set(outCenter.x, newY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offsetChildren(int amount, RecyclerViewProxy helper) {
|
||||
helper.offsetChildrenVertical(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDistanceFromCenter(Point center, int viewCenterX, int viewCenterY) {
|
||||
return viewCenterY - center.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewVisible(
|
||||
Point viewCenter, int halfWidth, int halfHeight, int endBound,
|
||||
int extraSpace) {
|
||||
int viewTop = viewCenter.y - halfHeight;
|
||||
int viewBottom = viewCenter.y + halfHeight;
|
||||
return viewTop < (endBound + extraSpace) && viewBottom > -extraSpace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNewBecomeVisible(DiscreteScrollLayoutManager lm) {
|
||||
View firstChild = lm.getFirstChild(), lastChild = lm.getLastChild();
|
||||
int topBound = -lm.getExtraLayoutSpace();
|
||||
int bottomBound = lm.getHeight() + lm.getExtraLayoutSpace();
|
||||
boolean isNewVisibleFromTop = lm.getDecoratedTop(firstChild) > topBound
|
||||
&& lm.getPosition(firstChild) > 0;
|
||||
boolean isNewVisibleFromBottom = lm.getDecoratedBottom(lastChild) < bottomBound
|
||||
&& lm.getPosition(lastChild) < lm.getItemCount() - 1;
|
||||
return isNewVisibleFromTop || isNewVisibleFromBottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFlingVelocity(int velocityX, int velocityY) {
|
||||
return velocityY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canScrollHorizontally() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPendingDx(int pendingScroll) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPendingDy(int pendingScroll) {
|
||||
return pendingScroll;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.yarolegovich.discretescrollview;
|
||||
|
||||
/**
|
||||
* Created by yarolegovich on 16.03.2017.
|
||||
*/
|
||||
enum Direction {
|
||||
|
||||
START {
|
||||
@Override
|
||||
public int applyTo(int delta) {
|
||||
return delta * -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sameAs(int direction) {
|
||||
return direction < 0;
|
||||
}
|
||||
},
|
||||
END {
|
||||
@Override
|
||||
public int applyTo(int delta) {
|
||||
return delta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sameAs(int direction) {
|
||||
return direction > 0;
|
||||
}
|
||||
};
|
||||
|
||||
public abstract int applyTo(int delta);
|
||||
|
||||
public abstract boolean sameAs(int direction);
|
||||
|
||||
public static Direction fromDelta(int delta) {
|
||||
return delta > 0 ? END : START;
|
||||
}
|
||||
}
|
||||
@@ -1,836 +0,0 @@
|
||||
package com.yarolegovich.discretescrollview;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.accessibility.AccessibilityEventCompat;
|
||||
import androidx.core.view.accessibility.AccessibilityRecordCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearSmoothScroller;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.alibaba.idst.nls.internal.utils.L;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.yarolegovich.discretescrollview.transform.DiscreteScrollItemTransformer;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by yarolegovich on 17.02.2017.
|
||||
*/
|
||||
public class DiscreteScrollLayoutManager extends LinearLayoutManager {
|
||||
|
||||
static final int NO_POSITION = -1;
|
||||
|
||||
private static final String EXTRA_POSITION = "extra_position";
|
||||
private static final int DEFAULT_TIME_FOR_ITEM_SETTLE = 300;
|
||||
private static final int DEFAULT_FLING_THRESHOLD = 2100; //Decrease to increase sensitivity.
|
||||
private static final int DEFAULT_TRANSFORM_CLAMP_ITEM_COUNT = 1;
|
||||
|
||||
protected static final float SCROLL_TO_SNAP_TO_ANOTHER_ITEM = 0.6f;
|
||||
|
||||
//This field will take value of all visible view's center points during the fill phase
|
||||
protected Point viewCenterIterator;
|
||||
protected Point recyclerCenter;
|
||||
protected Point currentViewCenter;
|
||||
protected int childHalfWidth, childHalfHeight;
|
||||
protected int extraLayoutSpace;
|
||||
|
||||
//Max possible distance a view can travel during one scroll phase
|
||||
protected int scrollToChangeCurrent;
|
||||
protected int currentScrollState;
|
||||
|
||||
protected int scrolled;
|
||||
protected int pendingScroll;
|
||||
protected int currentPosition;
|
||||
protected int pendingPosition;
|
||||
|
||||
protected SparseArray<View> detachedCache;
|
||||
|
||||
private DSVOrientation.Helper orientationHelper;
|
||||
|
||||
protected boolean isFirstOrEmptyLayout;
|
||||
|
||||
private Context context;
|
||||
|
||||
private int timeForItemSettle;
|
||||
private int offscreenItems;
|
||||
private int transformClampItemCount;
|
||||
|
||||
private boolean dataSetChangeShiftedPosition;
|
||||
|
||||
private int flingThreshold;
|
||||
private boolean shouldSlideOnFling;
|
||||
|
||||
private int viewWidth, viewHeight;
|
||||
|
||||
private float ratio=0.5F;
|
||||
|
||||
private static final String TAG = "DiscreteScrollLayoutMan";
|
||||
@NonNull
|
||||
private final ScrollStateListener scrollStateListener;
|
||||
private DiscreteScrollItemTransformer itemTransformer;
|
||||
|
||||
private RecyclerViewProxy recyclerViewProxy;
|
||||
|
||||
public DiscreteScrollLayoutManager(
|
||||
@NonNull Context c,
|
||||
@NonNull ScrollStateListener scrollStateListener,
|
||||
@NonNull DSVOrientation orientation) {
|
||||
super(c);
|
||||
this.context = c;
|
||||
this.timeForItemSettle = DEFAULT_TIME_FOR_ITEM_SETTLE;
|
||||
this.pendingPosition = NO_POSITION;
|
||||
this.currentPosition = NO_POSITION;
|
||||
this.flingThreshold = DEFAULT_FLING_THRESHOLD;
|
||||
this.shouldSlideOnFling = false;
|
||||
this.recyclerCenter = new Point();
|
||||
this.currentViewCenter = new Point();
|
||||
this.viewCenterIterator = new Point();
|
||||
this.detachedCache = new SparseArray<>();
|
||||
this.scrollStateListener = scrollStateListener;
|
||||
this.orientationHelper = orientation.createHelper();
|
||||
this.recyclerViewProxy = new RecyclerViewProxy(this);
|
||||
this.transformClampItemCount = DEFAULT_TRANSFORM_CLAMP_ITEM_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||
if (state.getItemCount() == 0) {
|
||||
recyclerViewProxy.removeAndRecycleAllViews(recycler);
|
||||
currentPosition = pendingPosition = NO_POSITION;
|
||||
scrolled = pendingScroll = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
ensureValidPosition(state);
|
||||
|
||||
updateRecyclerDimensions(state);
|
||||
|
||||
//onLayoutChildren may be called multiple times and this check is required so that the flag
|
||||
//won't be cleared until onLayoutCompleted
|
||||
if (!isFirstOrEmptyLayout) {
|
||||
isFirstOrEmptyLayout = recyclerViewProxy.getChildCount() == 0;
|
||||
if (isFirstOrEmptyLayout) {
|
||||
initChildDimensions(recycler);
|
||||
}
|
||||
}
|
||||
|
||||
recyclerViewProxy.detachAndScrapAttachedViews(recycler);
|
||||
|
||||
fill(recycler);
|
||||
|
||||
applyItemTransformToChildren();
|
||||
}
|
||||
|
||||
private void ensureValidPosition(RecyclerView.State state) {
|
||||
if (currentPosition == NO_POSITION || currentPosition >= state.getItemCount()) {
|
||||
//currentPosition might have been assigned in onRestoreInstanceState()
|
||||
//which can lead to a crash (position out of bounds) when data set
|
||||
//is not persisted across rotations
|
||||
currentPosition = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void setRatio(float ratio) {
|
||||
this.ratio = ratio;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayoutCompleted(RecyclerView.State state) {
|
||||
if (isFirstOrEmptyLayout) {
|
||||
scrollStateListener.onCurrentViewFirstLayout();
|
||||
isFirstOrEmptyLayout = false;
|
||||
} else if (dataSetChangeShiftedPosition) {
|
||||
scrollStateListener.onDataSetChangeChangedPosition();
|
||||
dataSetChangeShiftedPosition = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void initChildDimensions(RecyclerView.Recycler recycler) {
|
||||
View viewToMeasure = recyclerViewProxy.getMeasuredChildForAdapterPosition(0, recycler);
|
||||
|
||||
int childViewWidth = recyclerViewProxy.getMeasuredWidthWithMargin(viewToMeasure);
|
||||
int childViewHeight = recyclerViewProxy.getMeasuredHeightWithMargin(viewToMeasure);
|
||||
|
||||
childHalfWidth = childViewWidth / 2;
|
||||
childHalfHeight = childViewHeight / 2;
|
||||
|
||||
scrollToChangeCurrent = orientationHelper.getDistanceToChangeCurrent(
|
||||
childViewWidth,
|
||||
childViewHeight);
|
||||
|
||||
extraLayoutSpace = scrollToChangeCurrent * offscreenItems;
|
||||
|
||||
recyclerViewProxy.detachAndScrapView(viewToMeasure, recycler);
|
||||
}
|
||||
|
||||
protected void updateRecyclerDimensions(RecyclerView.State state) {
|
||||
boolean dimensionsChanged = !state.isMeasuring()
|
||||
&& (recyclerViewProxy.getWidth() != viewWidth
|
||||
|| recyclerViewProxy.getHeight() != viewHeight);
|
||||
if (dimensionsChanged) {
|
||||
viewWidth = recyclerViewProxy.getWidth();
|
||||
viewHeight = recyclerViewProxy.getHeight();
|
||||
recyclerViewProxy.removeAllViews();
|
||||
}
|
||||
recyclerCenter.set(
|
||||
(int) (recyclerViewProxy.getWidth() * ratio),
|
||||
recyclerViewProxy.getHeight() / 2);
|
||||
}
|
||||
|
||||
protected void fill(RecyclerView.Recycler recycler) {
|
||||
cacheAndDetachAttachedViews();
|
||||
|
||||
orientationHelper.setCurrentViewCenter(recyclerCenter, scrolled, currentViewCenter);
|
||||
|
||||
final int endBound = orientationHelper.getViewEnd(
|
||||
recyclerViewProxy.getWidth(),
|
||||
recyclerViewProxy.getHeight());
|
||||
|
||||
//Layout current
|
||||
if (isViewVisible(currentViewCenter, endBound)) {
|
||||
layoutView(recycler, currentPosition, currentViewCenter);
|
||||
}
|
||||
|
||||
//Layout items before the current item
|
||||
layoutViews(recycler, Direction.START, endBound);
|
||||
|
||||
//Layout items after the current item
|
||||
layoutViews(recycler, Direction.END, endBound);
|
||||
|
||||
recycleDetachedViewsAndClearCache(recycler);
|
||||
}
|
||||
|
||||
private void layoutViews(RecyclerView.Recycler recycler, Direction direction, int endBound) {
|
||||
final int positionStep = direction.applyTo(1);
|
||||
|
||||
//Predictive layout is required when we are doing smooth fast scroll towards pendingPosition
|
||||
boolean noPredictiveLayoutRequired = pendingPosition == NO_POSITION
|
||||
|| !direction.sameAs(pendingPosition - currentPosition);
|
||||
|
||||
viewCenterIterator.set(currentViewCenter.x, currentViewCenter.y);
|
||||
for (int pos = currentPosition + positionStep; isInBounds(pos); pos += positionStep) {
|
||||
if (pos == pendingPosition) {
|
||||
noPredictiveLayoutRequired = true;
|
||||
}
|
||||
orientationHelper.shiftViewCenter(direction, scrollToChangeCurrent, viewCenterIterator);
|
||||
if (isViewVisible(viewCenterIterator, endBound)) {
|
||||
layoutView(recycler, pos, viewCenterIterator);
|
||||
} else if (noPredictiveLayoutRequired) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void layoutView(RecyclerView.Recycler recycler, int position, Point viewCenter) {
|
||||
if (position < 0) return;
|
||||
View v = detachedCache.get(position);
|
||||
if (v == null) {
|
||||
v = recyclerViewProxy.getMeasuredChildForAdapterPosition(position, recycler);
|
||||
recyclerViewProxy.layoutDecoratedWithMargins(v,
|
||||
viewCenter.x - childHalfWidth, viewCenter.y - childHalfHeight,
|
||||
viewCenter.x + childHalfWidth, viewCenter.y + childHalfHeight);
|
||||
} else {
|
||||
recyclerViewProxy.attachView(v);
|
||||
detachedCache.remove(position);
|
||||
}
|
||||
}
|
||||
|
||||
protected void cacheAndDetachAttachedViews() {
|
||||
detachedCache.clear();
|
||||
for (int i = 0; i < recyclerViewProxy.getChildCount(); i++) {
|
||||
View child = recyclerViewProxy.getChildAt(i);
|
||||
detachedCache.put(recyclerViewProxy.getPosition(child), child);
|
||||
}
|
||||
|
||||
for (int i = 0; i < detachedCache.size(); i++) {
|
||||
recyclerViewProxy.detachView(detachedCache.valueAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
protected void recycleDetachedViewsAndClearCache(RecyclerView.Recycler recycler) {
|
||||
for (int i = 0; i < detachedCache.size(); i++) {
|
||||
View viewToRemove = detachedCache.valueAt(i);
|
||||
recyclerViewProxy.recycleView(viewToRemove, recycler);
|
||||
}
|
||||
detachedCache.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemsAdded(RecyclerView recyclerView, int positionStart, int itemCount) {
|
||||
int newPosition = currentPosition;
|
||||
if (currentPosition == NO_POSITION) {
|
||||
newPosition = 0;
|
||||
} else if (currentPosition >= positionStart) {
|
||||
newPosition = Math.min(currentPosition + itemCount, recyclerViewProxy.getItemCount() - 1);
|
||||
}
|
||||
onNewPosition(newPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount) {
|
||||
int newPosition = currentPosition;
|
||||
if (recyclerViewProxy.getItemCount() == 0) {
|
||||
newPosition = NO_POSITION;
|
||||
} else if (currentPosition >= positionStart) {
|
||||
if (currentPosition < positionStart + itemCount) {
|
||||
//If currentPosition is in the removed items, then the new item became current
|
||||
currentPosition = NO_POSITION;
|
||||
}
|
||||
newPosition = Math.max(0, currentPosition - itemCount);
|
||||
}
|
||||
onNewPosition(newPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemsChanged(RecyclerView recyclerView) {
|
||||
//notifyDataSetChanged() was called. We need to ensure that currentPosition is not out of bounds
|
||||
currentPosition = Math.min(Math.max(0, currentPosition), recyclerViewProxy.getItemCount() - 1);
|
||||
dataSetChangeShiftedPosition = true;
|
||||
}
|
||||
|
||||
private void onNewPosition(int position) {
|
||||
if (currentPosition != position) {
|
||||
currentPosition = position;
|
||||
dataSetChangeShiftedPosition = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||
return scrollBy(dx, recycler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||
return scrollBy(dy, recycler);
|
||||
}
|
||||
|
||||
protected int scrollBy(int amount, RecyclerView.Recycler recycler) {
|
||||
if (recyclerViewProxy.getChildCount() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Direction direction = Direction.fromDelta(amount);
|
||||
int leftToScroll = calculateAllowedScrollIn(direction);
|
||||
if (leftToScroll <= 0) {
|
||||
return 0;
|
||||
}
|
||||
int delta = direction.applyTo(Math.min(leftToScroll, Math.abs(amount)));
|
||||
Logger.d(TAG,"leftToScroll--》"+leftToScroll+"---amount--》"+amount);
|
||||
|
||||
scrolled += delta;
|
||||
if (pendingScroll != 0) {
|
||||
pendingScroll -= delta;
|
||||
}
|
||||
|
||||
orientationHelper.offsetChildren(-delta, recyclerViewProxy);
|
||||
|
||||
if (orientationHelper.hasNewBecomeVisible(this)) {
|
||||
fill(recycler);
|
||||
}
|
||||
|
||||
notifyScroll();
|
||||
|
||||
applyItemTransformToChildren();
|
||||
|
||||
return delta;
|
||||
}
|
||||
|
||||
protected void applyItemTransformToChildren() {
|
||||
if (itemTransformer != null) {
|
||||
int clampAfterDistance = scrollToChangeCurrent * transformClampItemCount;
|
||||
for (int i = 0; i < recyclerViewProxy.getChildCount(); i++) {
|
||||
View child = recyclerViewProxy.getChildAt(i);
|
||||
|
||||
//RecyclerView.ViewHolder childViewHolder = recyclerView.getChildViewHolder(child);
|
||||
float position = getCenterRelativePositionOf(child, clampAfterDistance);
|
||||
itemTransformer.transformItem(child,null, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrollToPosition(int position) {
|
||||
if (currentPosition == position) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentPosition = position;
|
||||
recyclerViewProxy.requestLayout();
|
||||
}
|
||||
|
||||
//@Override
|
||||
//public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
|
||||
// if (currentPosition == position || pendingPosition != NO_POSITION) {
|
||||
// return;
|
||||
// }
|
||||
// checkTargetPosition(state, position);
|
||||
// if (currentPosition == NO_POSITION) {
|
||||
// //Layout not happened yet
|
||||
// currentPosition = position;
|
||||
// } else {
|
||||
// startSmoothPendingScroll(position);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
@Override
|
||||
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
|
||||
LinearSmoothScroller smoothScroller =
|
||||
new LinearSmoothScroller(recyclerView.getContext()) {
|
||||
@Override
|
||||
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
|
||||
// 返回:滑过1px时经历的时间(ms)。
|
||||
return 10f / displayMetrics.densityDpi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) {
|
||||
return boxStart - viewStart;
|
||||
}
|
||||
};
|
||||
|
||||
smoothScroller.setTargetPosition(position);
|
||||
startSmoothScroll(smoothScroller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canScrollHorizontally() {
|
||||
return orientationHelper.canScrollHorizontally();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return orientationHelper.canScrollVertically();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(int state) {
|
||||
if (currentScrollState == RecyclerView.SCROLL_STATE_IDLE && currentScrollState != state) {
|
||||
scrollStateListener.onScrollStart();
|
||||
}
|
||||
|
||||
if (state == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
//Scroll is not finished until current view is centered
|
||||
boolean isScrollEnded = onScrollEnd();
|
||||
if (isScrollEnded) {
|
||||
scrollStateListener.onScrollEnd();
|
||||
} else {
|
||||
//Scroll continues and we don't want to set currentScrollState to STATE_IDLE,
|
||||
//because this will then trigger .scrollStateListener.onScrollStart()
|
||||
return;
|
||||
}
|
||||
} else if (state == RecyclerView.SCROLL_STATE_DRAGGING) {
|
||||
onDragStart();
|
||||
}
|
||||
currentScrollState = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if scroll is ended and we don't need to settle items
|
||||
*/
|
||||
private boolean onScrollEnd() {
|
||||
if (pendingPosition != NO_POSITION) {
|
||||
currentPosition = pendingPosition;
|
||||
pendingPosition = NO_POSITION;
|
||||
scrolled = 0;
|
||||
}
|
||||
|
||||
Direction scrollDirection = Direction.fromDelta(scrolled);
|
||||
if (Math.abs(scrolled) == scrollToChangeCurrent) {
|
||||
currentPosition += scrollDirection.applyTo(1);
|
||||
scrolled = 0;
|
||||
}
|
||||
|
||||
if (isAnotherItemCloserThanCurrent()) {
|
||||
pendingScroll = getHowMuchIsLeftToScroll(scrolled);
|
||||
} else {
|
||||
pendingScroll = -scrolled;
|
||||
}
|
||||
|
||||
if (pendingScroll == 0) {
|
||||
return true;
|
||||
} else {
|
||||
startSmoothPendingScroll();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void onDragStart() {
|
||||
//Here we need to:
|
||||
//1. Stop any pending scroll
|
||||
//2. Set currentPosition to position of the item that is closest to the center
|
||||
boolean isScrollingThroughMultiplePositions = Math.abs(scrolled) > scrollToChangeCurrent;
|
||||
if (isScrollingThroughMultiplePositions) {
|
||||
int scrolledPositions = scrolled / scrollToChangeCurrent;
|
||||
currentPosition += scrolledPositions;
|
||||
scrolled -= scrolledPositions * scrollToChangeCurrent;
|
||||
}
|
||||
if (isAnotherItemCloserThanCurrent()) {
|
||||
Direction direction = Direction.fromDelta(scrolled);
|
||||
currentPosition += direction.applyTo(1);
|
||||
scrolled = -getHowMuchIsLeftToScroll(scrolled);
|
||||
}
|
||||
pendingPosition = NO_POSITION;
|
||||
pendingScroll = 0;
|
||||
}
|
||||
|
||||
public void onFling(int velocityX, int velocityY) {
|
||||
int velocity = orientationHelper.getFlingVelocity(velocityX, velocityY);
|
||||
int throttleValue = shouldSlideOnFling ? Math.abs(velocity / flingThreshold) : 1;
|
||||
int newPosition = currentPosition + Direction.fromDelta(velocity).applyTo(throttleValue);
|
||||
newPosition = checkNewOnFlingPositionIsInBounds(newPosition);
|
||||
boolean isInScrollDirection = velocity * scrolled >= 0;
|
||||
boolean canFling = isInScrollDirection && isInBounds(newPosition);
|
||||
if (canFling) {
|
||||
startSmoothPendingScroll(newPosition);
|
||||
} else {
|
||||
returnToCurrentPosition();
|
||||
}
|
||||
|
||||
Logger.d(TAG,"onFling"+newPosition);
|
||||
}
|
||||
|
||||
public void returnToCurrentPosition() {
|
||||
pendingScroll = -scrolled;
|
||||
if (pendingScroll != 0) {
|
||||
startSmoothPendingScroll();
|
||||
}
|
||||
}
|
||||
|
||||
protected int calculateAllowedScrollIn(Direction direction) {
|
||||
if (pendingScroll != 0) {
|
||||
return Math.abs(pendingScroll);
|
||||
}
|
||||
int allowedScroll;
|
||||
boolean isBoundReached;
|
||||
boolean isScrollDirectionAsBefore = direction.applyTo(scrolled) > 0;
|
||||
if (direction == Direction.START && currentPosition == 0) {
|
||||
//We can scroll to the left when currentPosition == 0 only if we scrolled to the right before
|
||||
isBoundReached = scrolled == 0;
|
||||
allowedScroll = isBoundReached ? 0 : Math.abs(scrolled);
|
||||
} else if (direction == Direction.END && currentPosition == recyclerViewProxy.getItemCount() - 1) {
|
||||
//We can scroll to the right when currentPosition == last only if we scrolled to the left before
|
||||
isBoundReached = scrolled == 0;
|
||||
allowedScroll = isBoundReached ? 0 : Math.abs(scrolled);
|
||||
} else {
|
||||
isBoundReached = false;
|
||||
allowedScroll = isScrollDirectionAsBefore ?
|
||||
scrollToChangeCurrent - Math.abs(scrolled) :
|
||||
scrollToChangeCurrent + Math.abs(scrolled);
|
||||
}
|
||||
scrollStateListener.onIsBoundReachedFlagChange(isBoundReached);
|
||||
return allowedScroll;
|
||||
}
|
||||
|
||||
private void startSmoothPendingScroll() {
|
||||
LinearSmoothScroller scroller = new DiscreteLinearSmoothScroller(context);
|
||||
scroller.setTargetPosition(currentPosition);
|
||||
recyclerViewProxy.startSmoothScroll(scroller);
|
||||
}
|
||||
|
||||
public void startSmoothPendingScroll(int position) {
|
||||
if (currentPosition == position) return;
|
||||
pendingScroll = -scrolled;
|
||||
Direction direction = Direction.fromDelta(position - currentPosition);
|
||||
int distanceToScroll = Math.abs(position - currentPosition) * scrollToChangeCurrent;
|
||||
pendingScroll += direction.applyTo(distanceToScroll);
|
||||
pendingPosition = position;
|
||||
startSmoothPendingScroll();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAutoMeasureEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeVerticalScrollRange(RecyclerView.State state) {
|
||||
return computeScrollRange(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeVerticalScrollOffset(RecyclerView.State state) {
|
||||
return computeScrollOffset(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeVerticalScrollExtent(RecyclerView.State state) {
|
||||
return computeScrollExtent(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeHorizontalScrollRange(RecyclerView.State state) {
|
||||
return computeScrollRange(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeHorizontalScrollOffset(RecyclerView.State state) {
|
||||
return computeScrollOffset(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeHorizontalScrollExtent(RecyclerView.State state) {
|
||||
return computeScrollExtent(state);
|
||||
}
|
||||
|
||||
private int computeScrollOffset(RecyclerView.State state) {
|
||||
int scrollbarSize = computeScrollExtent(state);
|
||||
int offset = (int) ((scrolled / (float) scrollToChangeCurrent) * scrollbarSize);
|
||||
return (currentPosition * scrollbarSize) + offset;
|
||||
}
|
||||
|
||||
private int computeScrollExtent(RecyclerView.State state) {
|
||||
if (getItemCount() == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return (int) (computeScrollRange(state) / (float) getItemCount());
|
||||
}
|
||||
}
|
||||
|
||||
private int computeScrollRange(RecyclerView.State state) {
|
||||
if (getItemCount() == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return scrollToChangeCurrent * (getItemCount() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdapterChanged(RecyclerView.Adapter oldAdapter, RecyclerView.Adapter newAdapter) {
|
||||
pendingPosition = NO_POSITION;
|
||||
scrolled = pendingScroll = 0;
|
||||
if (newAdapter instanceof InitialPositionProvider) {
|
||||
currentPosition = ((InitialPositionProvider) newAdapter).getInitialPosition();
|
||||
} else {
|
||||
currentPosition = 0;
|
||||
}
|
||||
recyclerViewProxy.removeAllViews();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState() {
|
||||
Bundle bundle = new Bundle();
|
||||
if (pendingPosition != NO_POSITION) {
|
||||
currentPosition = pendingPosition;
|
||||
}
|
||||
bundle.putInt(EXTRA_POSITION, currentPosition);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Parcelable state) {
|
||||
Bundle bundle = (Bundle) state;
|
||||
currentPosition = bundle.getInt(EXTRA_POSITION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
|
||||
return new RecyclerView.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
}
|
||||
|
||||
public int getNextPosition() {
|
||||
if (scrolled == 0) {
|
||||
return currentPosition;
|
||||
} else if (pendingPosition != NO_POSITION) {
|
||||
return pendingPosition;
|
||||
} else {
|
||||
return currentPosition + Direction.fromDelta(scrolled).applyTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void setItemTransformer(DiscreteScrollItemTransformer itemTransformer) {
|
||||
this.itemTransformer = itemTransformer;
|
||||
}
|
||||
|
||||
public void setTimeForItemSettle(int timeForItemSettle) {
|
||||
this.timeForItemSettle = timeForItemSettle;
|
||||
}
|
||||
|
||||
public void setOffscreenItems(int offscreenItems) {
|
||||
this.offscreenItems = offscreenItems;
|
||||
extraLayoutSpace = scrollToChangeCurrent * offscreenItems;
|
||||
recyclerViewProxy.requestLayout();
|
||||
}
|
||||
|
||||
public void setTransformClampItemCount(int transformClampItemCount) {
|
||||
this.transformClampItemCount = transformClampItemCount;
|
||||
applyItemTransformToChildren();
|
||||
}
|
||||
|
||||
public void setOrientation(DSVOrientation orientation) {
|
||||
orientationHelper = orientation.createHelper();
|
||||
recyclerViewProxy.removeAllViews();
|
||||
recyclerViewProxy.requestLayout();
|
||||
}
|
||||
|
||||
public void setShouldSlideOnFling(boolean result) {
|
||||
shouldSlideOnFling = result;
|
||||
}
|
||||
|
||||
public void setSlideOnFlingThreshold(int threshold) {
|
||||
flingThreshold = threshold;
|
||||
}
|
||||
|
||||
public int getCurrentPosition() {
|
||||
return currentPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
|
||||
super.onInitializeAccessibilityEvent(event);
|
||||
if (recyclerViewProxy.getChildCount() > 0) {
|
||||
final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
|
||||
record.setFromIndex(getPosition(getFirstChild()));
|
||||
record.setToIndex(getPosition(getLastChild()));
|
||||
}
|
||||
}
|
||||
|
||||
private float getCenterRelativePositionOf(View v, int maxDistance) {
|
||||
float distanceFromCenter = orientationHelper.getDistanceFromCenter(recyclerCenter,
|
||||
getDecoratedLeft(v) + childHalfWidth,
|
||||
getDecoratedTop(v) + childHalfHeight);
|
||||
return Math.min(Math.max(-1f, distanceFromCenter / maxDistance), 1f);
|
||||
}
|
||||
|
||||
private int checkNewOnFlingPositionIsInBounds(int position) {
|
||||
final int itemCount = recyclerViewProxy.getItemCount();
|
||||
//The check is required in case slide through multiple items is turned on
|
||||
if (currentPosition != 0 && position < 0) {
|
||||
//If currentPosition == 0 && position < 0 we forbid scroll to the left,
|
||||
//but if currentPosition != 0 we can slide to the first item
|
||||
return 0;
|
||||
} else if (currentPosition != itemCount - 1 && position >= itemCount) {
|
||||
return itemCount - 1;
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
private int getHowMuchIsLeftToScroll(int dx) {
|
||||
return Direction.fromDelta(dx).applyTo(scrollToChangeCurrent - Math.abs(scrolled));
|
||||
}
|
||||
|
||||
private boolean isAnotherItemCloserThanCurrent() {
|
||||
return Math.abs(scrolled) >= scrollToChangeCurrent * SCROLL_TO_SNAP_TO_ANOTHER_ITEM;
|
||||
}
|
||||
|
||||
public View getFirstChild() {
|
||||
return recyclerViewProxy.getChildAt(0);
|
||||
}
|
||||
|
||||
public View getLastChild() {
|
||||
return recyclerViewProxy.getChildAt(recyclerViewProxy.getChildCount() - 1);
|
||||
}
|
||||
|
||||
public int getExtraLayoutSpace() {
|
||||
return extraLayoutSpace;
|
||||
}
|
||||
|
||||
private void notifyScroll() {
|
||||
float amountToScroll = pendingPosition != NO_POSITION ?
|
||||
Math.abs(scrolled + pendingScroll) :
|
||||
scrollToChangeCurrent;
|
||||
float position = -Math.min(Math.max(-1f, scrolled / amountToScroll), 1f);
|
||||
scrollStateListener.onScroll(position);
|
||||
}
|
||||
|
||||
private boolean isInBounds(int itemPosition) {
|
||||
return itemPosition >= 0 && itemPosition < recyclerViewProxy.getItemCount();
|
||||
}
|
||||
|
||||
private boolean isViewVisible(Point viewCenter, int endBound) {
|
||||
return orientationHelper.isViewVisible(
|
||||
viewCenter, childHalfWidth, childHalfHeight,
|
||||
endBound, extraLayoutSpace);
|
||||
}
|
||||
|
||||
|
||||
public void setPendingScroll(int pendingScroll){
|
||||
this.pendingScroll=pendingScroll;
|
||||
}
|
||||
|
||||
private void checkTargetPosition(RecyclerView.State state, int targetPosition) {
|
||||
if (targetPosition < 0 || targetPosition >= state.getItemCount()) {
|
||||
throw new IllegalArgumentException(String.format(Locale.US,
|
||||
"target position out of bounds: position=%d, itemCount=%d",
|
||||
targetPosition, state.getItemCount()));
|
||||
}
|
||||
}
|
||||
|
||||
protected void setRecyclerViewProxy(RecyclerViewProxy recyclerViewProxy) {
|
||||
this.recyclerViewProxy = recyclerViewProxy;
|
||||
}
|
||||
|
||||
protected void setOrientationHelper(DSVOrientation.Helper orientationHelper) {
|
||||
this.orientationHelper = orientationHelper;
|
||||
}
|
||||
|
||||
private class DiscreteLinearSmoothScroller extends LinearSmoothScroller {
|
||||
|
||||
public DiscreteLinearSmoothScroller(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculateDxToMakeVisible(View view, int snapPreference) {
|
||||
return orientationHelper.getPendingDx(-pendingScroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculateDyToMakeVisible(View view, int snapPreference) {
|
||||
return orientationHelper.getPendingDy(-pendingScroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int calculateTimeForScrolling(int dx) {
|
||||
float dist = Math.min(Math.abs(dx), scrollToChangeCurrent);
|
||||
return (int) (Math.max(0.01f, dist / scrollToChangeCurrent) * timeForItemSettle);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PointF computeScrollVectorForPosition(int targetPosition) {
|
||||
return new PointF(
|
||||
orientationHelper.getPendingDx(pendingScroll),
|
||||
orientationHelper.getPendingDy(pendingScroll));
|
||||
}
|
||||
|
||||
@Override protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
|
||||
return 10f / displayMetrics.densityDpi;
|
||||
}
|
||||
}
|
||||
|
||||
public interface ScrollStateListener {
|
||||
void onIsBoundReachedFlagChange(boolean isBoundReached);
|
||||
|
||||
void onScrollStart();
|
||||
|
||||
void onScrollEnd();
|
||||
|
||||
void onScroll(float currentViewPosition);
|
||||
|
||||
void onCurrentViewFirstLayout();
|
||||
|
||||
void onDataSetChangeChangedPosition();
|
||||
}
|
||||
|
||||
public interface InitialPositionProvider {
|
||||
int getInitialPosition();
|
||||
}
|
||||
}
|
||||
@@ -1,302 +0,0 @@
|
||||
package com.yarolegovich.discretescrollview;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.IntRange;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.mogo.module.common.R;
|
||||
import com.yarolegovich.discretescrollview.transform.DiscreteScrollItemTransformer;
|
||||
import com.yarolegovich.discretescrollview.util.ScrollListenerAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by yarolegovich on 18.02.2017.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class DiscreteScrollView extends RecyclerView {
|
||||
|
||||
public static final int NO_POSITION = DiscreteScrollLayoutManager.NO_POSITION;
|
||||
|
||||
private static final int DEFAULT_ORIENTATION = DSVOrientation.HORIZONTAL.ordinal();
|
||||
|
||||
private DiscreteScrollLayoutManager layoutManager;
|
||||
|
||||
private List<ScrollStateChangeListener> scrollStateChangeListeners;
|
||||
private List<OnItemChangedListener> onItemChangedListeners;
|
||||
|
||||
private boolean isOverScrollEnabled;
|
||||
|
||||
public DiscreteScrollView(Context context) {
|
||||
super(context);
|
||||
init(null);
|
||||
}
|
||||
|
||||
public DiscreteScrollView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(attrs);
|
||||
}
|
||||
|
||||
public DiscreteScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(attrs);
|
||||
}
|
||||
|
||||
private void init(AttributeSet attrs) {
|
||||
scrollStateChangeListeners = new ArrayList<>();
|
||||
onItemChangedListeners = new ArrayList<>();
|
||||
|
||||
int orientation = DEFAULT_ORIENTATION;
|
||||
if (attrs != null) {
|
||||
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.DiscreteScrollView);
|
||||
orientation = ta.getInt(R.styleable.DiscreteScrollView_dsv_orientation, DEFAULT_ORIENTATION);
|
||||
ta.recycle();
|
||||
}
|
||||
|
||||
isOverScrollEnabled = getOverScrollMode() != OVER_SCROLL_NEVER;
|
||||
|
||||
layoutManager = new DiscreteScrollLayoutManager(
|
||||
getContext(), new ScrollStateListener(),
|
||||
DSVOrientation.values()[orientation]);
|
||||
setLayoutManager(layoutManager);
|
||||
}
|
||||
|
||||
public void setRatio(float ratio){
|
||||
layoutManager.setRatio(ratio);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLayoutManager(LayoutManager layout) {
|
||||
if (layout instanceof DiscreteScrollLayoutManager) {
|
||||
super.setLayoutManager(layout);
|
||||
} else {
|
||||
throw new IllegalArgumentException(getContext().getString(R.string.dsv_ex_msg_dont_set_lm));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean fling(int velocityX, int velocityY) {
|
||||
boolean isFling = super.fling(velocityX, velocityY);
|
||||
if (isFling) {
|
||||
layoutManager.onFling(velocityX, velocityY);
|
||||
} else {
|
||||
layoutManager.returnToCurrentPosition();
|
||||
}
|
||||
return isFling;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ViewHolder getViewHolder(int position) {
|
||||
View view = layoutManager.findViewByPosition(position);
|
||||
return view != null ? getChildViewHolder(view) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return adapter position of the current item or -1 if nothing is selected
|
||||
*/
|
||||
public int getCurrentItem() {
|
||||
return layoutManager.getCurrentPosition();
|
||||
}
|
||||
|
||||
public void setItemTransformer(DiscreteScrollItemTransformer transformer) {
|
||||
layoutManager.setItemTransformer(transformer);
|
||||
}
|
||||
|
||||
public void setItemTransitionTimeMillis(@IntRange(from = 10) int millis) {
|
||||
layoutManager.setTimeForItemSettle(millis);
|
||||
}
|
||||
|
||||
public void setSlideOnFling(boolean result){
|
||||
layoutManager.setShouldSlideOnFling(result);
|
||||
}
|
||||
|
||||
public void setSlideOnFlingThreshold(int threshold){
|
||||
layoutManager.setSlideOnFlingThreshold(threshold);
|
||||
}
|
||||
|
||||
public void setOrientation(DSVOrientation orientation) {
|
||||
layoutManager.setOrientation(orientation);
|
||||
}
|
||||
|
||||
public void setOffscreenItems(int items) {
|
||||
layoutManager.setOffscreenItems(items);
|
||||
}
|
||||
|
||||
public void setClampTransformProgressAfter(@IntRange(from = 1) int itemCount) {
|
||||
if (itemCount <= 1) {
|
||||
throw new IllegalArgumentException("must be >= 1");
|
||||
}
|
||||
layoutManager.setTransformClampItemCount(itemCount);
|
||||
}
|
||||
|
||||
public void setOverScrollEnabled(boolean overScrollEnabled) {
|
||||
isOverScrollEnabled = overScrollEnabled;
|
||||
setOverScrollMode(OVER_SCROLL_NEVER);
|
||||
}
|
||||
|
||||
public void addScrollStateChangeListener(@NonNull ScrollStateChangeListener<?> scrollStateChangeListener) {
|
||||
scrollStateChangeListeners.add(scrollStateChangeListener);
|
||||
}
|
||||
|
||||
public void addScrollListener(@NonNull ScrollListener<?> scrollListener) {
|
||||
addScrollStateChangeListener(new ScrollListenerAdapter(scrollListener));
|
||||
}
|
||||
|
||||
public void addOnItemChangedListener(@NonNull OnItemChangedListener<?> onItemChangedListener) {
|
||||
onItemChangedListeners.add(onItemChangedListener);
|
||||
}
|
||||
|
||||
public void removeScrollStateChangeListener(@NonNull ScrollStateChangeListener<?> scrollStateChangeListener) {
|
||||
scrollStateChangeListeners.remove(scrollStateChangeListener);
|
||||
}
|
||||
|
||||
public void removeScrollListener(@NonNull ScrollListener<?> scrollListener) {
|
||||
removeScrollStateChangeListener(new ScrollListenerAdapter<>(scrollListener));
|
||||
}
|
||||
|
||||
public void removeItemChangedListener(@NonNull OnItemChangedListener<?> onItemChangedListener) {
|
||||
onItemChangedListeners.remove(onItemChangedListener);
|
||||
}
|
||||
|
||||
private void notifyScrollStart(ViewHolder holder, int current) {
|
||||
for (ScrollStateChangeListener listener : scrollStateChangeListeners) {
|
||||
listener.onScrollStart(holder, current);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyScrollEnd(ViewHolder holder, int current) {
|
||||
for (ScrollStateChangeListener listener : scrollStateChangeListeners) {
|
||||
listener.onScrollEnd(holder, current);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyScroll(float position,
|
||||
int currentIndex, int newIndex,
|
||||
ViewHolder currentHolder, ViewHolder newHolder) {
|
||||
for (ScrollStateChangeListener listener : scrollStateChangeListeners) {
|
||||
listener.onScroll(position, currentIndex, newIndex,
|
||||
currentHolder,
|
||||
newHolder);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyCurrentItemChanged(ViewHolder holder, int current) {
|
||||
for (OnItemChangedListener listener : onItemChangedListeners) {
|
||||
listener.onCurrentItemChanged(holder, current);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyCurrentItemChanged() {
|
||||
if (onItemChangedListeners.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int current = layoutManager.getCurrentPosition();
|
||||
ViewHolder currentHolder = getViewHolder(current);
|
||||
notifyCurrentItemChanged(currentHolder, current);
|
||||
}
|
||||
|
||||
public void setPendingScroll(int PendingScroll ) {
|
||||
layoutManager.setPendingScroll(PendingScroll);
|
||||
}
|
||||
|
||||
private class ScrollStateListener implements DiscreteScrollLayoutManager.ScrollStateListener {
|
||||
|
||||
@Override
|
||||
public void onIsBoundReachedFlagChange(boolean isBoundReached) {
|
||||
if (isOverScrollEnabled) {
|
||||
setOverScrollMode(isBoundReached ? OVER_SCROLL_ALWAYS : OVER_SCROLL_NEVER);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStart() {
|
||||
if (scrollStateChangeListeners.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int current = layoutManager.getCurrentPosition();
|
||||
ViewHolder holder = getViewHolder(current);
|
||||
if (holder != null) {
|
||||
notifyScrollStart(holder, current);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollEnd() {
|
||||
if (onItemChangedListeners.isEmpty() && scrollStateChangeListeners.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int current = layoutManager.getCurrentPosition();
|
||||
ViewHolder holder = getViewHolder(current);
|
||||
if (holder != null) {
|
||||
notifyScrollEnd(holder, current);
|
||||
notifyCurrentItemChanged(holder, current);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(float currentViewPosition) {
|
||||
if (scrollStateChangeListeners.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int currentIndex = getCurrentItem();
|
||||
int newIndex = layoutManager.getNextPosition();
|
||||
if (currentIndex != newIndex) {
|
||||
notifyScroll(currentViewPosition,
|
||||
currentIndex, newIndex,
|
||||
getViewHolder(currentIndex),
|
||||
getViewHolder(newIndex));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentViewFirstLayout() {
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
notifyCurrentItemChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataSetChangeChangedPosition() {
|
||||
notifyCurrentItemChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public interface ScrollStateChangeListener<T extends ViewHolder> {
|
||||
|
||||
void onScrollStart(@NonNull T currentItemHolder, int adapterPosition);
|
||||
|
||||
void onScrollEnd(@NonNull T currentItemHolder, int adapterPosition);
|
||||
|
||||
void onScroll(float scrollPosition,
|
||||
int currentPosition,
|
||||
int newPosition,
|
||||
@Nullable T currentHolder,
|
||||
@Nullable T newCurrent);
|
||||
}
|
||||
|
||||
public interface ScrollListener<T extends ViewHolder> {
|
||||
|
||||
void onScroll(float scrollPosition,
|
||||
int currentPosition, int newPosition,
|
||||
@Nullable T currentHolder,
|
||||
@Nullable T newCurrent);
|
||||
}
|
||||
|
||||
public interface OnItemChangedListener<T extends ViewHolder> {
|
||||
/*
|
||||
* This method will be also triggered when view appears on the screen for the first time.
|
||||
* If data set is empty, viewHolder will be null and adapterPosition will be NO_POSITION
|
||||
*/
|
||||
void onCurrentItemChanged(@Nullable T viewHolder, int adapterPosition);
|
||||
}
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
package com.yarolegovich.discretescrollview;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.mogo.module.common.R;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by yarolegovich on 28-Apr-17.
|
||||
*/
|
||||
|
||||
public class InfiniteScrollAdapter<T extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<T>
|
||||
implements DiscreteScrollLayoutManager.InitialPositionProvider {
|
||||
|
||||
private static final int CENTER = Integer.MAX_VALUE / 2;
|
||||
private static final int RESET_BOUND = 100;
|
||||
|
||||
public static <T extends RecyclerView.ViewHolder> InfiniteScrollAdapter<T> wrap(
|
||||
@NonNull RecyclerView.Adapter<T> adapter) {
|
||||
return new InfiniteScrollAdapter<>(adapter);
|
||||
}
|
||||
|
||||
private RecyclerView.Adapter<T> wrapped;
|
||||
private DiscreteScrollLayoutManager layoutManager;
|
||||
|
||||
public InfiniteScrollAdapter(@NonNull RecyclerView.Adapter<T> wrapped) {
|
||||
this.wrapped = wrapped;
|
||||
this.wrapped.registerAdapterDataObserver(new DataSetChangeDelegate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
wrapped.onAttachedToRecyclerView(recyclerView);
|
||||
if (recyclerView instanceof DiscreteScrollView) {
|
||||
layoutManager = (DiscreteScrollLayoutManager) recyclerView.getLayoutManager();
|
||||
} else {
|
||||
String msg = recyclerView.getContext().getString(R.string.dsv_ex_msg_adapter_wrong_recycler);
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
wrapped.onDetachedFromRecyclerView(recyclerView);
|
||||
layoutManager = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull T onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return wrapped.onCreateViewHolder(parent, viewType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull T holder, int position) {
|
||||
if (isResetRequired(position)) {
|
||||
int resetPosition = CENTER + mapPositionToReal(layoutManager.getCurrentPosition());
|
||||
setPosition(resetPosition);
|
||||
return;
|
||||
}
|
||||
wrapped.onBindViewHolder(holder, mapPositionToReal(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return wrapped.getItemViewType(mapPositionToReal(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return isInfinite() ? Integer.MAX_VALUE : wrapped.getItemCount();
|
||||
}
|
||||
|
||||
public int getRealItemCount() {
|
||||
return wrapped.getItemCount();
|
||||
}
|
||||
|
||||
public int getRealCurrentPosition() {
|
||||
return getRealPosition(layoutManager.getCurrentPosition());
|
||||
}
|
||||
|
||||
public int getRealPosition(int position) {
|
||||
return mapPositionToReal(position);
|
||||
}
|
||||
|
||||
public int getClosestPosition(int position) {
|
||||
ensureValidPosition(position);
|
||||
int adapterCurrent = layoutManager.getCurrentPosition();
|
||||
int current = mapPositionToReal(adapterCurrent);
|
||||
if (position == current) {
|
||||
return adapterCurrent;
|
||||
}
|
||||
int delta = position - current;
|
||||
int target = adapterCurrent + delta;
|
||||
int wraparoundTarget = adapterCurrent + (position > current ?
|
||||
delta - wrapped.getItemCount() :
|
||||
wrapped.getItemCount() + delta);
|
||||
int distance = Math.abs(adapterCurrent - target);
|
||||
int wraparoundDistance = Math.abs(adapterCurrent - wraparoundTarget);
|
||||
if (distance == wraparoundDistance) {
|
||||
//Scroll to the right feels more natural, so prefer it
|
||||
return target > adapterCurrent ? target : wraparoundTarget;
|
||||
} else {
|
||||
return distance < wraparoundDistance ? target : wraparoundTarget;
|
||||
}
|
||||
}
|
||||
|
||||
private int mapPositionToReal(int position) {
|
||||
if (position < CENTER) {
|
||||
int rem = (CENTER - position) % wrapped.getItemCount();
|
||||
return rem == 0 ? 0 : wrapped.getItemCount() - rem;
|
||||
} else {
|
||||
return (position - CENTER) % wrapped.getItemCount();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isResetRequired(int requestedPosition) {
|
||||
return isInfinite()
|
||||
&& (requestedPosition <= RESET_BOUND
|
||||
|| requestedPosition >= (Integer.MAX_VALUE - RESET_BOUND));
|
||||
}
|
||||
|
||||
private void ensureValidPosition(int position) {
|
||||
if (position >= wrapped.getItemCount()) {
|
||||
throw new IndexOutOfBoundsException(String.format(Locale.US,
|
||||
"requested position is outside adapter's bounds: position=%d, size=%d",
|
||||
position, wrapped.getItemCount()));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInfinite() {
|
||||
return wrapped.getItemCount() > 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInitialPosition() {
|
||||
return isInfinite() ? CENTER : 0;
|
||||
}
|
||||
|
||||
private void setPosition(int position) {
|
||||
layoutManager.scrollToPosition(position);
|
||||
}
|
||||
|
||||
//TODO: handle proper data set change notifications
|
||||
private class DataSetChangeDelegate extends RecyclerView.AdapterDataObserver {
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
setPosition(getInitialPosition());
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeRemoved(int positionStart, int itemCount) {
|
||||
onChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeInserted(int positionStart, int itemCount) {
|
||||
onChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
|
||||
onChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeChanged(int positionStart, int itemCount) {
|
||||
notifyItemRangeChanged(0, getItemCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeChanged(int positionStart, int itemCount, Object payload) {
|
||||
notifyItemRangeChanged(0, getItemCount(), payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
package com.yarolegovich.discretescrollview;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Created by yarolegovich on 10/25/17.
|
||||
*/
|
||||
public class RecyclerViewProxy {
|
||||
|
||||
private RecyclerView.LayoutManager layoutManager;
|
||||
|
||||
public RecyclerViewProxy(@NonNull RecyclerView.LayoutManager layoutManager) {
|
||||
this.layoutManager = layoutManager;
|
||||
}
|
||||
|
||||
public void attachView(View view) {
|
||||
layoutManager.attachView(view);
|
||||
}
|
||||
|
||||
public void detachView(View view) {
|
||||
layoutManager.detachView(view);
|
||||
}
|
||||
|
||||
public void detachAndScrapView(View view, RecyclerView.Recycler recycler) {
|
||||
layoutManager.detachAndScrapView(view, recycler);
|
||||
}
|
||||
|
||||
public void detachAndScrapAttachedViews(RecyclerView.Recycler recycler) {
|
||||
layoutManager.detachAndScrapAttachedViews(recycler);
|
||||
}
|
||||
|
||||
public void recycleView(View view, RecyclerView.Recycler recycler) {
|
||||
recycler.recycleView(view);
|
||||
}
|
||||
|
||||
public void removeAndRecycleAllViews(RecyclerView.Recycler recycler) {
|
||||
layoutManager.removeAndRecycleAllViews(recycler);
|
||||
}
|
||||
|
||||
public int getChildCount() {
|
||||
return layoutManager.getChildCount();
|
||||
}
|
||||
|
||||
public int getItemCount() {
|
||||
return layoutManager.getItemCount();
|
||||
}
|
||||
|
||||
public View getMeasuredChildForAdapterPosition(int position, RecyclerView.Recycler recycler) {
|
||||
View view = recycler.getViewForPosition(position);
|
||||
layoutManager.addView(view);
|
||||
layoutManager.measureChildWithMargins(view, 0, 0);
|
||||
return view;
|
||||
}
|
||||
|
||||
public void layoutDecoratedWithMargins(View v, int left, int top, int right, int bottom) {
|
||||
layoutManager.layoutDecoratedWithMargins(v, left, top, right, bottom);
|
||||
}
|
||||
|
||||
public View getChildAt(int index) {
|
||||
return layoutManager.getChildAt(index);
|
||||
}
|
||||
|
||||
public int getPosition(View view) {
|
||||
return layoutManager.getPosition(view);
|
||||
}
|
||||
|
||||
public int getMeasuredWidthWithMargin(View child) {
|
||||
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) child.getLayoutParams();
|
||||
return layoutManager.getDecoratedMeasuredWidth(child) + lp.leftMargin + lp.rightMargin;
|
||||
}
|
||||
|
||||
public int getMeasuredHeightWithMargin(View child) {
|
||||
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) child.getLayoutParams();
|
||||
return layoutManager.getDecoratedMeasuredHeight(child) + lp.topMargin + lp.bottomMargin;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return layoutManager.getWidth();
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return layoutManager.getHeight();
|
||||
}
|
||||
|
||||
public void offsetChildrenHorizontal(int amount) {
|
||||
layoutManager.offsetChildrenHorizontal(amount);
|
||||
}
|
||||
|
||||
public void offsetChildrenVertical(int amount) {
|
||||
layoutManager.offsetChildrenVertical(amount);
|
||||
}
|
||||
|
||||
public void requestLayout() {
|
||||
layoutManager.requestLayout();
|
||||
}
|
||||
|
||||
public void startSmoothScroll(RecyclerView.SmoothScroller smoothScroller) {
|
||||
layoutManager.startSmoothScroll(smoothScroller);
|
||||
}
|
||||
|
||||
public void removeAllViews() {
|
||||
layoutManager.removeAllViews();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.yarolegovich.discretescrollview.transform;
|
||||
|
||||
import android.view.View;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Created by yarolegovich on 02.03.2017.
|
||||
*/
|
||||
|
||||
public interface DiscreteScrollItemTransformer {
|
||||
void transformItem(View item, RecyclerView.ViewHolder childViewHolder,float position);
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
package com.yarolegovich.discretescrollview.transform;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Created by yarolegovich on 03.03.2017.
|
||||
*/
|
||||
|
||||
public class Pivot {
|
||||
|
||||
public static final int AXIS_X = 0;
|
||||
public static final int AXIS_Y = 1;
|
||||
|
||||
private static final int PIVOT_CENTER = -1;
|
||||
private static final int PIVOT_MAX = -2;
|
||||
|
||||
private int axis;
|
||||
private int pivotPoint;
|
||||
|
||||
public Pivot(@Axis int axis, int pivotPoint) {
|
||||
this.axis = axis;
|
||||
this.pivotPoint = pivotPoint;
|
||||
}
|
||||
|
||||
public void setOn(View view) {
|
||||
if (axis == AXIS_X) {
|
||||
switch (pivotPoint) {
|
||||
case PIVOT_CENTER:
|
||||
view.setPivotX(view.getWidth() * 0.5f);
|
||||
break;
|
||||
case PIVOT_MAX:
|
||||
view.setPivotX(view.getWidth());
|
||||
break;
|
||||
default:
|
||||
view.setPivotX(pivotPoint);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (axis == AXIS_Y) {
|
||||
switch (pivotPoint) {
|
||||
case PIVOT_CENTER:
|
||||
view.setPivotY(view.getHeight() * 0.5f);
|
||||
break;
|
||||
case PIVOT_MAX:
|
||||
view.setPivotY(view.getHeight());
|
||||
break;
|
||||
default:
|
||||
view.setPivotY(pivotPoint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Axis
|
||||
public int getAxis() {
|
||||
return axis;
|
||||
}
|
||||
|
||||
public enum X {
|
||||
LEFT {
|
||||
@Override
|
||||
public Pivot create() {
|
||||
return new Pivot(AXIS_X, 0);
|
||||
}
|
||||
},
|
||||
CENTER {
|
||||
@Override
|
||||
public Pivot create() {
|
||||
return new Pivot(AXIS_X, PIVOT_CENTER);
|
||||
}
|
||||
},
|
||||
RIGHT {
|
||||
@Override
|
||||
public Pivot create() {
|
||||
return new Pivot(AXIS_X, PIVOT_MAX);
|
||||
}
|
||||
};
|
||||
|
||||
public abstract Pivot create();
|
||||
}
|
||||
|
||||
public enum Y {
|
||||
TOP {
|
||||
@Override
|
||||
public Pivot create() {
|
||||
return new Pivot(AXIS_Y, 0);
|
||||
}
|
||||
},
|
||||
CENTER {
|
||||
@Override
|
||||
public Pivot create() {
|
||||
return new Pivot(AXIS_Y, PIVOT_CENTER);
|
||||
}
|
||||
},
|
||||
BOTTOM {
|
||||
@Override
|
||||
public Pivot create() {
|
||||
return new Pivot(AXIS_Y, PIVOT_MAX);
|
||||
}
|
||||
};
|
||||
|
||||
public abstract Pivot create();
|
||||
}
|
||||
|
||||
@IntDef({AXIS_X, AXIS_Y})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Axis{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
package com.yarolegovich.discretescrollview.transform;
|
||||
|
||||
import android.view.View;
|
||||
import androidx.annotation.FloatRange;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Created by yarolegovich on 03.03.2017.
|
||||
*/
|
||||
public class ScaleTransformer implements DiscreteScrollItemTransformer {
|
||||
|
||||
private Pivot pivotX;
|
||||
private Pivot pivotY;
|
||||
private float minScale;
|
||||
private float maxMinDiff;
|
||||
|
||||
public ScaleTransformer() {
|
||||
pivotX = Pivot.X.CENTER.create();
|
||||
pivotY = Pivot.Y.CENTER.create();
|
||||
minScale = 0.8f;
|
||||
maxMinDiff = 0.2f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transformItem(View item, RecyclerView.ViewHolder childViewHolder, float position) {
|
||||
pivotX.setOn(item);
|
||||
pivotY.setOn(item);
|
||||
float closenessToCenter = 1f - Math.abs(position);
|
||||
float scale = minScale + maxMinDiff * closenessToCenter;
|
||||
item.setScaleX(scale);
|
||||
item.setScaleY(scale);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private ScaleTransformer transformer;
|
||||
private float maxScale;
|
||||
|
||||
public Builder() {
|
||||
transformer = new ScaleTransformer();
|
||||
maxScale = 1f;
|
||||
}
|
||||
|
||||
public Builder setMinScale(@FloatRange(from = 0.01) float scale) {
|
||||
transformer.minScale = scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setMaxScale(@FloatRange(from = 0.01) float scale) {
|
||||
maxScale = scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPivotX(Pivot.X pivotX) {
|
||||
return setPivotX(pivotX.create());
|
||||
}
|
||||
|
||||
public Builder setPivotX(Pivot pivot) {
|
||||
assertAxis(pivot, Pivot.AXIS_X);
|
||||
transformer.pivotX = pivot;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPivotY(Pivot.Y pivotY) {
|
||||
return setPivotY(pivotY.create());
|
||||
}
|
||||
|
||||
public Builder setPivotY(Pivot pivot) {
|
||||
assertAxis(pivot, Pivot.AXIS_Y);
|
||||
transformer.pivotY = pivot;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScaleTransformer build() {
|
||||
transformer.maxMinDiff = maxScale - transformer.minScale;
|
||||
return transformer;
|
||||
}
|
||||
|
||||
private void assertAxis(Pivot pivot, @Pivot.Axis int axis) {
|
||||
if (pivot.getAxis() != axis) {
|
||||
throw new IllegalArgumentException("You passed a Pivot for wrong axis.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.yarolegovich.discretescrollview.util;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.yarolegovich.discretescrollview.DiscreteScrollView;
|
||||
|
||||
/**
|
||||
* Created by yarolegovich on 16.03.2017.
|
||||
*/
|
||||
public class ScrollListenerAdapter<T extends RecyclerView.ViewHolder> implements DiscreteScrollView.ScrollStateChangeListener<T> {
|
||||
|
||||
private DiscreteScrollView.ScrollListener<T> adaptee;
|
||||
|
||||
public ScrollListenerAdapter(@NonNull DiscreteScrollView.ScrollListener<T> adaptee) {
|
||||
this.adaptee = adaptee;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStart(@NonNull T currentItemHolder, int adapterPosition) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollEnd(@NonNull T currentItemHolder, int adapterPosition) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(float scrollPosition,
|
||||
int currentIndex, int newIndex,
|
||||
@Nullable T currentHolder, @Nullable T newCurrentHolder) {
|
||||
adaptee.onScroll(scrollPosition, currentIndex, newIndex, currentHolder, newCurrentHolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ScrollListenerAdapter) {
|
||||
return adaptee.equals(((ScrollListenerAdapter) obj).adaptee);
|
||||
} else {
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"
|
||||
>
|
||||
|
||||
<gradient
|
||||
android:angle="180"
|
||||
android:endColor="#3E7FFC"
|
||||
android:startColor="#5CC1FF" />
|
||||
|
||||
<corners
|
||||
android:bottomLeftRadius="@dimen/dp_20"
|
||||
/>
|
||||
</shape>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
|
||||
<gradient
|
||||
android:angle="180"
|
||||
android:endColor="#50526E"
|
||||
android:startColor="#333F4057" />
|
||||
<corners android:bottomRightRadius="@dimen/dp_20"/>
|
||||
|
||||
</shape>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="@dimen/dp_20" />
|
||||
<solid android:color="#3F4057" />
|
||||
</shape>
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="@dimen/dp_790"
|
||||
android:layout_height="@dimen/dp_440"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/module_commons_shape_round_gray">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/module_commons_wm_dialog_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_56"
|
||||
android:layout_marginTop="@dimen/dp_134"
|
||||
android:maxLines="1"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="@dimen/sp_40"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="是否退出导航导航导航导航导航导航导航导航导航导航导航导航导航导航导航导航?" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/module_commons_wm_dialog_button_ok"
|
||||
android:layout_width="@dimen/dp_395"
|
||||
android:layout_height="@dimen/dp_128"
|
||||
android:background="@drawable/moddule_commons_shape_react_blue_grident"
|
||||
android:gravity="center"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="@dimen/dp_40"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
tools:text="确认" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/module_commons_wm_dialog_button_cancel"
|
||||
android:layout_width="@dimen/dp_395"
|
||||
android:layout_height="@dimen/dp_128"
|
||||
android:background="@drawable/module_commons_shape_react_gray_grident"
|
||||
android:gravity="center"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="@dimen/dp_40"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
tools:text="取消" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</FrameLayout>
|
||||
@@ -1,5 +1,6 @@
|
||||
<resources>
|
||||
<string name="app_name">mogo-module-common</string>
|
||||
<string name="dsv_ex_msg_dont_set_lm">You should not set LayoutManager on DiscreteScrollView.class instance. Library uses a special one. Just don\'t call the method.</string>
|
||||
<string name="dsv_ex_msg_adapter_wrong_recycler">InfiniteScrollAdapter is supposed to work only with DiscreteScrollView</string>
|
||||
<string name="module_commons_button_ok">确认</string>
|
||||
<string name="module_commons_button_cancel">取消</string>
|
||||
<string name="module_commons_exit_navi_content">是否退出导航?</string>
|
||||
</resources>
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.module.authorize.authprovider.invoke.AuthorizeConstant;
|
||||
import com.mogo.module.authorize.authprovider.module.IMogoAcquireAuthorizeListener;
|
||||
import com.mogo.module.authorize.authprovider.module.IMogoAuthorizeModuleManager;
|
||||
import com.mogo.module.common.dialog.WMDialog;
|
||||
import com.mogo.module.common.map.MapCenterPointStrategy;
|
||||
import com.mogo.module.common.map.Scene;
|
||||
import com.mogo.module.extensions.ExtensionsModuleConst;
|
||||
@@ -97,7 +98,6 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent
|
||||
private IMogoLocationClient mMogoLocationClient;
|
||||
private IMogoNavi mMogoNavi;
|
||||
private IMogoFragmentManager mMogoFragmentManager;
|
||||
private IMogoAddressManager mMogoAddressManager;
|
||||
private IMogoMarkerManager mMogoMarkerManager;
|
||||
|
||||
private IMogoRegisterCenter mMogoRegisterCenter;
|
||||
@@ -178,7 +178,6 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent
|
||||
|
||||
mEntrancePresenter = new EntrancePresenter( getContext(), this, mIMogoAuthorizeModuleManager );
|
||||
mMogoFragmentManager = mApis.getFragmentManagerApi();
|
||||
mMogoAddressManager = mApis.getAddressManagerApi();
|
||||
|
||||
mStatusManager = mApis.getStatusManagerApi();
|
||||
|
||||
@@ -217,8 +216,16 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent
|
||||
mExitNavi.setOnClickListener( view -> {
|
||||
if ( mMogoNavi != null ) {
|
||||
if ( mIsLock ) {
|
||||
NaviNoticeDialog naviNoticeDialog = new NaviNoticeDialog( getContext() );
|
||||
naviNoticeDialog.show();
|
||||
new WMDialog.Builder( getContext() )
|
||||
.setOkButton( R.string.module_commons_button_ok, ( dlg, which ) -> {
|
||||
mMogoNavi.stopNavi();
|
||||
} )
|
||||
.setCancelButton( R.string.module_commons_button_cancel, ( dlg, which ) -> {
|
||||
dlg.dismiss();
|
||||
} )
|
||||
.setContent( R.string.module_commons_exit_navi_content )
|
||||
.build()
|
||||
.show();
|
||||
} else {
|
||||
MapCenterPointStrategy.setMapCenterPointByScene( mMApUIController, Scene.NAVI );
|
||||
mMApUIController.recoverLockMode();
|
||||
@@ -466,10 +473,10 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent
|
||||
if ( mCurrentUploadFrame == mUploadingFrameRes.length ) {
|
||||
mCurrentUploadFrame = 12;
|
||||
}
|
||||
mUploading.setImageResource( mUploadingFrameRes[mCurrentUploadFrame++%mUploadingFrameRes.length] );
|
||||
mUploading.setImageResource( mUploadingFrameRes[mCurrentUploadFrame++ % mUploadingFrameRes.length] );
|
||||
}
|
||||
mUploadFrameAnimHandler.sendEmptyMessageDelayed( MSG_FRAME_ANIM, TIME_FRAME_INTERVAL_TIME );
|
||||
} else if( msg.what == MSG_STOP_ANIM ){
|
||||
} else if ( msg.what == MSG_STOP_ANIM ) {
|
||||
mStatusManager.setUploadingStatus( TAG, false );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mMogoStatusManager.setMainPageResumeStatus( TAG, true );
|
||||
if ( mCoverUpLayout.getVisibility() == View.VISIBLE ) {
|
||||
if ( mCoverUpLayout.getVisibility() != View.VISIBLE ) {
|
||||
mServiceApis.getAdasControllerApi().showADAS();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public class SchemeIntent implements IMogoStatusChangedListener {
|
||||
if ( mApis.getMapServiceApi().getNavi( mContext ).isNaviing() ) {
|
||||
mApis.getMapServiceApi().getNavi( mContext ).naviTo( new MogoLatLng( dlat, dlon ) );
|
||||
} else {
|
||||
mApis.getAddressManagerApi().calculatePath( new MogoLatLng( dlat, dlon ) );
|
||||
mApis.getSearchManagerApi().calculatePath( new MogoLatLng( dlat, dlon ) );
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
TipToast.shortTip( "目的地异常,不能导航" );
|
||||
|
||||
@@ -28,9 +28,9 @@ import com.mogo.service.intent.IMogoIntentListener;
|
||||
import com.mogo.service.intent.IMogoIntentManager;
|
||||
import com.mogo.service.launcher.IMogoLauncher;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.module.IMogoAddressManager;
|
||||
import com.mogo.service.module.IMogoRegisterCenter;
|
||||
import com.mogo.service.module.IMogoSearchManager;
|
||||
import com.mogo.service.module.IMogoSettingManager;
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||
import com.mogo.service.strategy.IMogoRefreshStrategyController;
|
||||
import com.mogo.utils.ResourcesHelper;
|
||||
@@ -59,7 +59,8 @@ public class MapPresenter extends Presenter< MapView > implements
|
||||
private IMogoStatusManager mStatusManager;
|
||||
private IMogoRegisterCenter mRegisterCenter;
|
||||
private IMogoLauncher mLauncher;
|
||||
private IMogoAddressManager mMogoAddressManager;
|
||||
private IMogoSearchManager mMogoSearchManager;
|
||||
private IMogoSettingManager mSettingManager;
|
||||
private Rect mDisplayOverviewBounds;
|
||||
|
||||
public MapPresenter( MapView view ) {
|
||||
@@ -208,7 +209,7 @@ public class MapPresenter extends Presenter< MapView > implements
|
||||
lon = intent.getDoubleExtra( "LON", 0.0 );
|
||||
|
||||
}
|
||||
mMogoAddressManager.calculatePath( new MogoLatLng( lat, lon ) );
|
||||
mMogoSearchManager.calculatePath( new MogoLatLng( lat, lon ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,7 +288,7 @@ public class MapPresenter extends Presenter< MapView > implements
|
||||
private void onOpenNavi() {
|
||||
mLauncher.backToLauncher( getContext() );
|
||||
if ( !mMogoMapService.getNavi( getContext() ).isNaviing() && !mStatusManager.isSearchUIShow() ) {
|
||||
mMogoAddressManager.goSearch();
|
||||
mSearchManager.showSearch();
|
||||
}
|
||||
AIAssist.getInstance( getContext() ).speakTTSVoice( "已打开" );
|
||||
}
|
||||
@@ -305,7 +306,8 @@ public class MapPresenter extends Presenter< MapView > implements
|
||||
mRegisterCenter = apis.getRegisterCenterApi();
|
||||
mRegisterCenter.registerMogoNaviListener( TAG, this );
|
||||
mLauncher = apis.getLauncherApi();
|
||||
mMogoAddressManager = apis.getAddressManagerApi();
|
||||
mMogoSearchManager = apis.getSearchManagerApi();
|
||||
mSettingManager = apis.getSettingManagerApi();
|
||||
|
||||
IMogoNavi mogoNavi = mMogoMapService.getNavi( getContext() );
|
||||
mogoNavi.setCalculatePathDisplayBounds( new Rect(
|
||||
@@ -418,7 +420,7 @@ public class MapPresenter extends Presenter< MapView > implements
|
||||
break;
|
||||
case VoiceConstants.CMD_MAP_STOP_NAVI_MODE_UN_WAKEUP:
|
||||
case VoiceConstants.CMD_MAP_STOP_NAVI_MODE:
|
||||
mSearchManager.showMain();
|
||||
mLauncher.backToLauncher( getContext() );
|
||||
break;
|
||||
case VoiceConstants.CMD_MAP_NIGHT_MODE_UN_WAKEUP:
|
||||
case VoiceConstants.CMD_MAP_NIGHT_MODE:
|
||||
@@ -443,12 +445,12 @@ public class MapPresenter extends Presenter< MapView > implements
|
||||
break;
|
||||
case VoiceConstants.CMD_MAP_SPEAK_DRAFT_MODE:
|
||||
case VoiceConstants.CMD_MAP_SPEAK_DRAFT_MODE_UN_WAKEUP:
|
||||
mSearchManager.speakDraft();
|
||||
mSettingManager.speakDraft();
|
||||
AIAssist.getInstance( getContext() ).speakTTSVoice( "已切换", null );
|
||||
break;
|
||||
case VoiceConstants.CMD_MAP_SPEAK_DETAIL_MODE:
|
||||
case VoiceConstants.CMD_MAP_SPEAK_DETAIL_MODE_UN_WAKEUP:
|
||||
mSearchManager.speakDetail();
|
||||
mSettingManager.speakDetail();
|
||||
AIAssist.getInstance( getContext() ).speakTTSVoice( "已切换", null );
|
||||
break;
|
||||
case VoiceConstants.CMD_MAP_SPEAK_REMAIN:
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||
|
||||
<application>
|
||||
<activity android:name=".ui.NaviActivity"></activity>
|
||||
<provider
|
||||
android:name=".cp.AddressContentProvider"
|
||||
android:authorities="com.zhidao.auto.personal.provider"
|
||||
|
||||
@@ -47,9 +47,9 @@ public class DataConstants {
|
||||
|
||||
// 泛化语义
|
||||
public static final String STRATEGY_THE_TIME_SHORTEST_PATH = "STRATEGY_THE_TIME_SHORTEST_PATH";
|
||||
public static final String[] WORDS_STRATEGY_THE_TIME_SHORTEST_PATH = {"最快的"};
|
||||
public static final String[] WORDS_STRATEGY_THE_TIME_SHORTEST_PATH = {"最快路线"};
|
||||
public static final String STRATEGY_THE_DISTANCE_SHORTEST_PATH = "STRATEGY_THE_DISTANCE_SHORTEST_PATH";
|
||||
public static final String[] WORDS_STRATEGY_THE_DISTANCE_SHORTED_PATH = {"路程最短的"};
|
||||
public static final String[] WORDS_STRATEGY_THE_DISTANCE_SHORTED_PATH = {"最短路线"};
|
||||
|
||||
// 第x个选个
|
||||
public static final String STRATEGY_THE_FIRST_PATH = "STRATEGY_THE_FIRST_PATH";
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.mogo.module.navi.constants;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.search.geo.IMogoGeoSearch;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.module.gps.simulator.IMogoGpsSimulatorManager;
|
||||
import com.mogo.module.guideshow.provider.IGuideShowProvider;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.analytics.IMogoAnalytics;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
import com.mogo.service.intent.IMogoIntentManager;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.module.IMogoRegisterCenter;
|
||||
import com.mogo.service.module.IMogoSearchManager;
|
||||
import com.mogo.service.module.IMogoSettingManager;
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-05-18
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class SearchApisHolder {
|
||||
|
||||
private static IMogoServiceApis sApis;
|
||||
private static IMogoMapService sMapServiceApis;
|
||||
private static IMogoMapUIController sUiControllerApis;
|
||||
private static IMogoNavi sNaviApis;
|
||||
private static IMogoMarkerManager sMarkerManagerApis;
|
||||
private static IMogoFragmentManager sFragmentManagerApis;
|
||||
private static IMogoAnalytics sAnalyticsApis;
|
||||
private static IMogoLocationClient sLocationClientApis;
|
||||
private static IMogoStatusManager sStatusManager;
|
||||
private static IMogoRegisterCenter sRegisterCenterApis;
|
||||
private static IMogoIntentManager sIntentManager;
|
||||
private static IGuideShowProvider sGuideShowApis;
|
||||
private static IMogoSettingManager sSettingManager;
|
||||
private static IMogoGpsSimulatorManager sGpsSimulatorManager;
|
||||
private static IMogoSearchManager sSearchManager;
|
||||
|
||||
static {
|
||||
sApis = ARouter.getInstance().navigation( IMogoServiceApis.class );
|
||||
sMapServiceApis = sApis.getMapServiceApi();
|
||||
sUiControllerApis = sMapServiceApis.getMapUIController();
|
||||
sNaviApis = sMapServiceApis.getNavi( AbsMogoApplication.getApp() );
|
||||
sMarkerManagerApis = sMapServiceApis.getMarkerManager( AbsMogoApplication.getApp() );
|
||||
sFragmentManagerApis = sApis.getFragmentManagerApi();
|
||||
sAnalyticsApis = sApis.getAnalyticsApi();
|
||||
sLocationClientApis = sMapServiceApis.getSingletonLocationClient( AbsMogoApplication.getApp() );
|
||||
sStatusManager = sApis.getStatusManagerApi();
|
||||
sRegisterCenterApis = sApis.getRegisterCenterApi();
|
||||
sIntentManager = sApis.getIntentManagerApi();
|
||||
sSettingManager = sApis.getSettingManagerApi();
|
||||
sSearchManager = sApis.getSearchManagerApi();
|
||||
sGpsSimulatorManager = ARouter.getInstance().navigation( IMogoGpsSimulatorManager.class);
|
||||
sGuideShowApis = ARouter.getInstance().navigation( IGuideShowProvider.class );
|
||||
}
|
||||
|
||||
public static IMogoServiceApis getApis() {
|
||||
return sApis;
|
||||
}
|
||||
|
||||
public static IMogoMapService getMapServiceApis() {
|
||||
return sMapServiceApis;
|
||||
}
|
||||
|
||||
public static IMogoMapUIController getUiControllerApis() {
|
||||
return sUiControllerApis;
|
||||
}
|
||||
|
||||
public static IMogoNavi getNaviApis() {
|
||||
return sNaviApis;
|
||||
}
|
||||
|
||||
public static IMogoMarkerManager getMarkerManager() {
|
||||
return sMarkerManagerApis;
|
||||
}
|
||||
|
||||
public static IMogoFragmentManager getFragmentManager() {
|
||||
return sFragmentManagerApis;
|
||||
}
|
||||
|
||||
public static IMogoAnalytics getAnalyticsApis() {
|
||||
return sAnalyticsApis;
|
||||
}
|
||||
|
||||
public static IMogoLocationClient getLocationClientApis() {
|
||||
return sLocationClientApis;
|
||||
}
|
||||
|
||||
public static IMogoStatusManager getStatusManager() {
|
||||
return sStatusManager;
|
||||
}
|
||||
|
||||
public static IMogoRegisterCenter getRegisterCenterApis() {
|
||||
return sRegisterCenterApis;
|
||||
}
|
||||
|
||||
public static IMogoIntentManager getIntentManager() {
|
||||
return sIntentManager;
|
||||
}
|
||||
|
||||
public static IGuideShowProvider getGuideShowApis() {
|
||||
return sGuideShowApis;
|
||||
}
|
||||
|
||||
public static IMogoSettingManager getSettingManager() {
|
||||
return sSettingManager;
|
||||
}
|
||||
|
||||
public static IMogoGpsSimulatorManager getGpsSimulatorManager() {
|
||||
return sGpsSimulatorManager;
|
||||
}
|
||||
|
||||
public static IMogoSearchManager getSearchManager() {
|
||||
return sSearchManager;
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package com.mogo.module.navi.constants
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.map.location.IMogoLocationClient
|
||||
import com.mogo.map.marker.IMogoMarkerManager
|
||||
import com.mogo.map.navi.IMogoNavi
|
||||
import com.mogo.map.search.geo.IMogoGeoSearch
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController
|
||||
import com.mogo.module.common.MogoModulePaths
|
||||
import com.mogo.module.gps.simulator.GpsSimulatorConstants
|
||||
import com.mogo.module.gps.simulator.IMogoGpsSimulatorManager
|
||||
import com.mogo.module.guideshow.provider.GuideShowProviderConstant
|
||||
import com.mogo.module.guideshow.provider.IGuideShowProvider
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.analytics.IMogoAnalytics
|
||||
import com.mogo.service.fragmentmanager.FragmentDescriptor
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager
|
||||
import com.mogo.service.intent.IMogoIntentManager
|
||||
import com.mogo.service.launcher.IMogoLauncher
|
||||
import com.mogo.service.map.IMogoMapService
|
||||
import com.mogo.service.module.IMogoRegisterCenter
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager
|
||||
|
||||
/**
|
||||
*@author zyz
|
||||
* 2020-01-08.
|
||||
*/
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
object SearchServiceHolder {
|
||||
// 单例对象,要使用Application Context
|
||||
private lateinit var context: Context
|
||||
|
||||
val fragmentManager: IMogoFragmentManager = ARouter.getInstance().build(MogoServicePaths.PATH_FRAGMENT_MANAGER).navigation() as IMogoFragmentManager
|
||||
val mapService: IMogoMapService = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICES_MAP).navigation() as IMogoMapService
|
||||
val listenerCenter: IMogoRegisterCenter = ARouter.getInstance().build(MogoServicePaths.PATH_REGISTER_CENTER).navigation() as IMogoRegisterCenter
|
||||
val statusManager: IMogoStatusManager = ARouter.getInstance().build(MogoServicePaths.PATH_STATUS_MANAGER).navigation() as IMogoStatusManager
|
||||
val analyticsManager: IMogoAnalytics = ARouter.getInstance().build(MogoServicePaths.PATH_UTILS_ANALYTICS).navigation() as IMogoAnalytics
|
||||
val guideShowProvider: IGuideShowProvider = ARouter.getInstance().build(GuideShowProviderConstant.GUIDE_SHOW_PROVIDER).navigation() as IGuideShowProvider
|
||||
val mogoLauncher: IMogoLauncher = ARouter.getInstance().build(MogoServicePaths.PATH_LAUNCHER_API).navigation() as IMogoLauncher
|
||||
val gpsSimulator = ARouter.getInstance().build(GpsSimulatorConstants.API_PATH).navigation() as IMogoGpsSimulatorManager
|
||||
val intentManager = ARouter.getInstance().build(MogoServicePaths.PATH_INTENT_MANAGER).navigation() as IMogoIntentManager
|
||||
val apis = ARouter.getInstance().navigation(IMogoServiceApis::class.java)
|
||||
var geoSearch: IMogoGeoSearch? = null
|
||||
fun init(context: Context) {
|
||||
this.context = context
|
||||
|
||||
}
|
||||
|
||||
fun push(fragment: Fragment, tag: String) {
|
||||
val builder = FragmentDescriptor.Builder()
|
||||
builder.fragment(fragment)
|
||||
val build = builder.tag(tag).build()
|
||||
fragmentManager.push(build)
|
||||
}
|
||||
|
||||
fun getNavi(): IMogoNavi {
|
||||
return mapService.getNavi(context)
|
||||
}
|
||||
|
||||
fun getLocationClient(): IMogoLocationClient {
|
||||
return mapService.getLocationClient(context)
|
||||
}
|
||||
|
||||
fun getMapUIController(): IMogoMapUIController {
|
||||
return mapService.mapUIController
|
||||
}
|
||||
|
||||
fun getMarkerManger(): IMogoMarkerManager {
|
||||
return mapService.getMarkerManager(context)
|
||||
}
|
||||
|
||||
fun getGeoSearcher(): IMogoGeoSearch {
|
||||
if (geoSearch == null) {
|
||||
geoSearch = mapService.getGeoSearch(context)
|
||||
}
|
||||
return geoSearch!!
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,15 +2,15 @@ package com.mogo.module.navi.manager
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.mogo.map.MogoLatLng
|
||||
import com.mogo.module.common.MogoModulePaths
|
||||
import com.mogo.module.common.map.MapCenterPointStrategy
|
||||
import com.mogo.module.common.map.Scene
|
||||
import com.mogo.module.navi.bean.EntityConvertUtils
|
||||
import com.mogo.module.navi.bean.SearchPoi
|
||||
import com.mogo.module.navi.constants.AMapConstants
|
||||
import com.mogo.module.navi.constants.DataConstants
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder
|
||||
import com.mogo.module.navi.constants.SearchApisHolder
|
||||
import com.mogo.module.navi.cp.AddressHelper
|
||||
import com.mogo.module.navi.dao.SearchPoiDao
|
||||
import com.mogo.module.navi.database.AppDataBase
|
||||
@@ -47,14 +47,6 @@ object AddressManager {
|
||||
return companyAddress != null
|
||||
}
|
||||
|
||||
private fun choosePoint(type: Int){
|
||||
MapCenterPointStrategy.setMapCenterPointByScene(SearchServiceHolder.getMapUIController(), Scene.CHOOSE_POINT)
|
||||
val builder = FragmentDescriptor.Builder()
|
||||
builder.fragment(SettingAddressFragment.newInstance(type))
|
||||
val build = builder.tag(AMapConstants.PATH_FRAGMENT_SETTING_HOME).build()
|
||||
SearchServiceHolder.fragmentManager.push(build)
|
||||
}
|
||||
|
||||
private lateinit var context: Context
|
||||
@SuppressLint("CheckResult")
|
||||
fun init(context: Context) {
|
||||
@@ -64,7 +56,7 @@ object AddressManager {
|
||||
poiDao.companyAddress
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { t1, t2 ->
|
||||
.subscribe { t1, _ ->
|
||||
if (t1.size > 0) {
|
||||
companyAddress = t1[0]
|
||||
}
|
||||
@@ -73,7 +65,7 @@ object AddressManager {
|
||||
poiDao.homeAddress
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { t1, t2 ->
|
||||
.subscribe { t1, _ ->
|
||||
if (t1.size > 0) {
|
||||
homeAddress = t1[0]
|
||||
}
|
||||
@@ -90,7 +82,7 @@ object AddressManager {
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteHome(context: Context) {
|
||||
fun deleteHome() {
|
||||
Observable.create(
|
||||
ObservableOnSubscribe<String> {
|
||||
poiDao.delete(homeAddress)
|
||||
@@ -105,7 +97,7 @@ object AddressManager {
|
||||
|
||||
}
|
||||
|
||||
fun deleteCompany(context: Context) {
|
||||
fun deleteCompany() {
|
||||
Observable.create(
|
||||
ObservableOnSubscribe<String> {
|
||||
poiDao.delete(companyAddress)
|
||||
@@ -122,8 +114,6 @@ object AddressManager {
|
||||
* 回家
|
||||
*/
|
||||
fun goHome() {
|
||||
closeADAS()
|
||||
SearchServiceHolder.statusManager.setSearchUIShow(TAG, true)
|
||||
if (homeAddress == null) {
|
||||
choosePoint(DataConstants.TYPE_HOME_ADDRESS)
|
||||
} else {
|
||||
@@ -131,14 +121,18 @@ object AddressManager {
|
||||
}
|
||||
}
|
||||
|
||||
private fun choosePoint(type: Int) {
|
||||
beforePushFragment()
|
||||
MapCenterPointStrategy.setMapCenterPointByScene(SearchApisHolder.getUiControllerApis(), Scene.CHOOSE_POINT)
|
||||
pushFragment(SettingAddressFragment.newInstance(type), AMapConstants.PATH_FRAGMENT_SETTING_HOME, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* 去公司
|
||||
*/
|
||||
fun goCompany() {
|
||||
closeADAS()
|
||||
SearchServiceHolder.statusManager.setSearchUIShow(TAG, true)
|
||||
if (companyAddress == null) {
|
||||
choosePoint( DataConstants.TYPE_COMPANY_ADDRESS)
|
||||
choosePoint(DataConstants.TYPE_COMPANY_ADDRESS)
|
||||
} else {
|
||||
calculatePath(EntityConvertUtils.poi2MogoTip(companyAddress).point)
|
||||
}
|
||||
@@ -148,14 +142,8 @@ object AddressManager {
|
||||
* 搜索
|
||||
*/
|
||||
fun goSearch() {
|
||||
closeADAS()
|
||||
SearchServiceHolder.statusManager.setSearchUIShow(TAG, true)
|
||||
SearchServiceHolder.fragmentManager.push(
|
||||
FragmentDescriptor.Builder().fragment(SearchFragment())
|
||||
.tag(AMapConstants.PATH_FRAGMENT_SEARCH)
|
||||
.notifyMainModule(true)
|
||||
.build()
|
||||
)
|
||||
beforePushFragment()
|
||||
pushFragment(SearchFragment(), AMapConstants.PATH_FRAGMENT_SEARCH, true)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,34 +151,43 @@ object AddressManager {
|
||||
*/
|
||||
fun calculatePath(destination: MogoLatLng?) {
|
||||
destination?.let {
|
||||
closeADAS()
|
||||
var newInstance = ChoosePathFragment.newInstance(destination)
|
||||
SearchServiceHolder.push(newInstance, AMapConstants.PATH_FRAGMENT_CHOOSE_PATH)
|
||||
beforePushFragment()
|
||||
MapCenterPointStrategy.setMapCenterPointByScene(SearchApisHolder.getUiControllerApis(), Scene.CALCULATE_PATH)
|
||||
pushFragment(ChoosePathFragment.newInstance(destination), AMapConstants.PATH_FRAGMENT_CHOOSE_PATH, true)
|
||||
}
|
||||
}
|
||||
|
||||
fun categorySearch(category: String){
|
||||
closeADAS()
|
||||
val searchFragment = CategorySearchFragment.newInstance(category)
|
||||
SearchServiceHolder.fragmentManager.push(FragmentDescriptor.Builder().fragment(searchFragment)
|
||||
.tag(AMapConstants.PATH_FRAGMENT_SEARCH_CATEGORY)
|
||||
.notifyMainModule(true)
|
||||
.build())
|
||||
fun categorySearch(category: String) {
|
||||
beforePushFragment()
|
||||
pushFragment(CategorySearchFragment.newInstance(category), AMapConstants.PATH_FRAGMENT_SEARCH_CATEGORY, true)
|
||||
}
|
||||
|
||||
fun goSettings(){
|
||||
fun goSettings() {
|
||||
beforePushFragment()
|
||||
pushFragment(NaviSettingFragment(), AMapConstants.PATH_FRAGMENT_NAVI_SETTING, true)
|
||||
}
|
||||
|
||||
private fun beforePushFragment() {
|
||||
closeADAS()
|
||||
val naviSettingFragment = NaviSettingFragment()
|
||||
SearchServiceHolder.fragmentManager.push(FragmentDescriptor.Builder().fragment(naviSettingFragment)
|
||||
.tag(AMapConstants.PATH_FRAGMENT_NAVI_SETTING)
|
||||
.notifyMainModule(true)
|
||||
.build())
|
||||
if (!SearchApisHolder.getStatusManager().isSearchUIShow) {
|
||||
SearchApisHolder.getStatusManager().setSearchUIShow(TAG, true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun pushFragment(fragment: Fragment, tag: String, notifyMain: Boolean) {
|
||||
SearchApisHolder.getFragmentManager().push(
|
||||
FragmentDescriptor.Builder()
|
||||
.fragment(fragment)
|
||||
.tag(tag)
|
||||
.notifyMainModule(notifyMain)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun closeADAS() {
|
||||
try {
|
||||
SearchServiceHolder.apis.adasControllerApi.closeADAS()
|
||||
SearchApisHolder.getApis().adasControllerApi.closeADAS()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
@@ -4,51 +4,56 @@ import android.content.Context;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.module.IMogoAddressManager;
|
||||
import com.mogo.service.module.IMogoSearchManager;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author zyz
|
||||
* 2020-01-12.
|
||||
* <p>
|
||||
* Deprecated, use {@link IMogoSearchManager} instead.
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
@Route( path = MogoServicePaths.PATH_ADDRESS_MANAGER )
|
||||
public class MogoAddressManager implements IMogoAddressManager {
|
||||
|
||||
private static final String TAG = "MogoAddressManager";
|
||||
|
||||
@Override
|
||||
public void goHome() {
|
||||
AddressManager.INSTANCE.goHome();
|
||||
Logger.w( TAG, "Deprecated, use IMogoSearchManager instead." );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goCompany() {
|
||||
AddressManager.INSTANCE.goCompany();
|
||||
Logger.w( TAG, "Deprecated, use IMogoSearchManager instead." );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goSearch() {
|
||||
AddressManager.INSTANCE.goSearch();
|
||||
Logger.w( TAG, "Deprecated, use IMogoSearchManager instead." );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculatePath( MogoLatLng destination ) {
|
||||
AddressManager.INSTANCE.calculatePath( destination );
|
||||
Logger.w( TAG, "Deprecated, use IMogoSearchManager instead." );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void categorySearch( String category ) {
|
||||
AddressManager.INSTANCE.categorySearch( category );
|
||||
Logger.w( TAG, "Deprecated, use IMogoSearchManager instead." );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goSettings() {
|
||||
AddressManager.INSTANCE.goSettings();
|
||||
Logger.w( TAG, "Deprecated, use IMogoSearchManager instead." );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
AddressManager.INSTANCE.init( context );
|
||||
SearchServiceHolder.INSTANCE.init( context );
|
||||
SettingManager.INSTANCE.init( context );
|
||||
Logger.w( TAG, "Deprecated, use IMogoSearchManager instead." );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,55 @@
|
||||
package com.mogo.module.navi.manager;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.map.constants.BroadcastMode;
|
||||
import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.navi.constants.AMapConstants;
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder;
|
||||
import com.mogo.module.navi.ui.search.CategorySearchFragment;
|
||||
import com.mogo.module.navi.ui.search.SearchFragment;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.module.navi.constants.SearchApisHolder;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.fragmentmanager.FragmentDescriptor;
|
||||
import com.mogo.service.module.IMogoSearchManager;
|
||||
|
||||
/**
|
||||
* @author zyz
|
||||
* 2020-01-13.
|
||||
*/
|
||||
@Route(path = MogoServicePaths.PATH_SEARCH_MANAGER)
|
||||
@Route( path = MogoServicePaths.PATH_SEARCH_MANAGER )
|
||||
public class MogoSearchManager implements IMogoSearchManager {
|
||||
@Override public void goHome() {
|
||||
@Override
|
||||
public void goHome() {
|
||||
AddressManager.INSTANCE.goHome();
|
||||
}
|
||||
|
||||
@Override public void goCompany() {
|
||||
@Override
|
||||
public void goCompany() {
|
||||
AddressManager.INSTANCE.goCompany();
|
||||
}
|
||||
|
||||
@Override public void showSearch() {
|
||||
@Override
|
||||
public void showSearch() {
|
||||
if ( SearchApisHolder.getNaviApis().isNaviing() ) {
|
||||
return;
|
||||
}
|
||||
AddressManager.INSTANCE.goSearch();
|
||||
}
|
||||
|
||||
@Override public void showMain() {
|
||||
SearchServiceHolder.INSTANCE.getFragmentManager().clearAll();
|
||||
}
|
||||
|
||||
@Override public void speakDraft() {
|
||||
SearchServiceHolder.INSTANCE.getNavi().setBroadcastMode(BroadcastMode.CONCISE);
|
||||
}
|
||||
|
||||
@Override public void speakDetail() {
|
||||
SearchServiceHolder.INSTANCE.getNavi().setBroadcastMode(BroadcastMode.DETAIL);
|
||||
}
|
||||
|
||||
@Override public void showCategory(String keyword) {
|
||||
@Override
|
||||
public void categorySearch( String keyword ) {
|
||||
AddressManager.INSTANCE.categorySearch( keyword );
|
||||
}
|
||||
|
||||
@Override public void init(Context context) {
|
||||
@Override
|
||||
public void calculatePath( MogoLatLng destination ) {
|
||||
AddressManager.INSTANCE.calculatePath( destination );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goSettings() {
|
||||
AddressManager.INSTANCE.goSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
AddressManager.INSTANCE.init( context );
|
||||
SettingManager.INSTANCE.init( context );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.mogo.module.navi.manager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.module.IMogoSettingManager;
|
||||
@@ -14,23 +14,49 @@ import com.mogo.service.module.IMogoSettingManager;
|
||||
@Route( path = MogoServicePaths.PATH_SETTING_MANAGER )
|
||||
public class MogoSettingManager implements IMogoSettingManager {
|
||||
|
||||
@Override public int getPathPrefer() {
|
||||
@Override
|
||||
public int getPathPrefer() {
|
||||
return SettingManager.INSTANCE.getPathPrefer();
|
||||
}
|
||||
|
||||
@Override public int getVolume() {
|
||||
@Override
|
||||
public int getVolume() {
|
||||
return SettingManager.INSTANCE.getVolume();
|
||||
}
|
||||
|
||||
@Override public int getVoiceStyle() {
|
||||
@Override
|
||||
public int getVoiceStyle() {
|
||||
return SettingManager.INSTANCE.getVoiceStyle();
|
||||
}
|
||||
|
||||
@Override public int getMapType() {
|
||||
@Override
|
||||
public int getMapType() {
|
||||
return SettingManager.INSTANCE.getMapType();
|
||||
}
|
||||
|
||||
@Override public void init(Context context) {
|
||||
SettingManager.INSTANCE.init(context);
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
SettingManager.INSTANCE.init( context );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void speakDraft() {
|
||||
SettingManager.INSTANCE.speakDraft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void speakDetail() {
|
||||
SettingManager.INSTANCE.speakDetail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openAimlessMode() {
|
||||
SettingManager.INSTANCE.openAimlessMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAimlessMode() {
|
||||
SettingManager.INSTANCE.closeAimlessMode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.mogo.module.navi.manager
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.mogo.map.navi.MogoNaviConfig
|
||||
import com.mogo.map.constants.BroadcastMode
|
||||
import com.mogo.module.navi.R
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder
|
||||
import com.mogo.module.navi.constants.SearchApisHolder
|
||||
import com.mogo.service.module.IMogoSettingManager
|
||||
|
||||
/**
|
||||
@@ -187,7 +187,7 @@ object SettingManager : IMogoSettingManager {
|
||||
}
|
||||
|
||||
private fun updateConfig() {
|
||||
SearchServiceHolder.getNavi()
|
||||
SearchApisHolder.getNaviApis()
|
||||
.naviConfig
|
||||
.cost(cost)
|
||||
.avoidSpeed(avoidSpeed)
|
||||
@@ -195,12 +195,31 @@ object SettingManager : IMogoSettingManager {
|
||||
.congestion(congestion)
|
||||
}
|
||||
|
||||
fun setAimlessMode(type: Int){
|
||||
fun setAimlessMode(type: Int) {
|
||||
settings.edit().putInt(KEY_AIMLESS_MODE_TYPE, type).apply()
|
||||
}
|
||||
|
||||
fun getAimlessMode():Int {
|
||||
fun getAimlessMode(): Int {
|
||||
return settings.getInt(KEY_AIMLESS_MODE_TYPE, R.id.aimlessModeClose)
|
||||
}
|
||||
|
||||
override fun speakDraft() {
|
||||
voiceStyle = R.id.rb_navi_draft
|
||||
SearchApisHolder.getNaviApis().setBroadcastMode(BroadcastMode.CONCISE)
|
||||
}
|
||||
|
||||
override fun speakDetail() {
|
||||
voiceStyle = R.id.rb_navi_detail
|
||||
SearchApisHolder.getNaviApis().setBroadcastMode(BroadcastMode.DETAIL)
|
||||
}
|
||||
|
||||
override fun openAimlessMode() {
|
||||
setAimlessMode(R.id.aimlessModeOpen)
|
||||
SearchApisHolder.getNaviApis().setAimlessModeStatus(true)
|
||||
}
|
||||
|
||||
override fun closeAimlessMode() {
|
||||
setAimlessMode(R.id.aimlessModeClose)
|
||||
SearchApisHolder.getNaviApis().setAimlessModeStatus(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.mogo.module.navi.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.module.navi.R
|
||||
import com.mogo.module.navi.ui.base.BaseActivity
|
||||
|
||||
class NaviActivity : BaseActivity() {
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_navi)
|
||||
var fragment = ARouter.getInstance()
|
||||
.build("/navi/search")
|
||||
.navigation() as Fragment
|
||||
supportFragmentManager.beginTransaction().replace(R.id.fl_container,fragment).commitNow()
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,12 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder;
|
||||
|
||||
import com.mogo.utils.NetworkUtils;
|
||||
|
||||
/**
|
||||
|
||||
@@ -101,10 +101,6 @@ public abstract class BaseSearchFragment extends BaseFragment implements SearchV
|
||||
return mSearchType;
|
||||
}
|
||||
|
||||
@Override public void startJumpAnimation() {
|
||||
|
||||
}
|
||||
|
||||
//@Override
|
||||
//public void renderChoicePointResult( RegeocodeAddress address ) {
|
||||
// if ( address == null ) {
|
||||
|
||||
@@ -1,41 +1,17 @@
|
||||
package com.mogo.module.navi.ui.search;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.EditText;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.map.search.geo.MogoPoiItem;
|
||||
import com.mogo.map.search.inputtips.IMogoInputtipsListener;
|
||||
import com.mogo.map.search.inputtips.IMogoInputtipsSearch;
|
||||
import com.mogo.map.search.inputtips.MogoTip;
|
||||
import com.mogo.map.search.inputtips.query.MogoInputtipsQuery;
|
||||
import com.mogo.map.search.poisearch.IMogoPoiSearch;
|
||||
import com.mogo.map.search.poisearch.IMogoPoiSearchListener;
|
||||
import com.mogo.map.search.poisearch.MogoPoiResult;
|
||||
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||
import com.mogo.module.common.TextWatcherAdapter;
|
||||
import com.mogo.module.navi.bean.EntityConvertUtils;
|
||||
import com.mogo.module.navi.bean.SearchPoi;
|
||||
import com.mogo.module.navi.constants.DataConstants;
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder;
|
||||
import com.mogo.module.navi.database.AppDataBase;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleEmitter;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import com.mogo.module.navi.constants.SearchApisHolder;
|
||||
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -43,55 +19,50 @@ import java.util.List;
|
||||
* <p>
|
||||
* 搜搜页逻辑处理
|
||||
*/
|
||||
public class CategoryPresenter extends Presenter<CategoryView> {
|
||||
public class CategoryPresenter extends Presenter< CategoryView > {
|
||||
|
||||
private CompositeDisposable mCompositeDisposable;
|
||||
private IMogoMapService mMapService;
|
||||
|
||||
public CategoryPresenter(CategoryView view) {
|
||||
super(view);
|
||||
public CategoryPresenter( CategoryView view ) {
|
||||
super( view );
|
||||
mCompositeDisposable = new CompositeDisposable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@NonNull LifecycleOwner owner) {
|
||||
super.onCreate(owner);
|
||||
mMapService = (IMogoMapService) ARouter.getInstance()
|
||||
.build(MogoServicePaths.PATH_SERVICES_MAP)
|
||||
.navigation(getContext());
|
||||
public void onCreate( @NonNull LifecycleOwner owner ) {
|
||||
super.onCreate( owner );
|
||||
}
|
||||
|
||||
public void startSearchLocalPoiByInput(String keyword) {
|
||||
MogoPoiSearchQuery mogoInputtipsQuery = new MogoPoiSearchQuery(keyword, keyword);
|
||||
mogoInputtipsQuery.setPageSize(10);
|
||||
mogoInputtipsQuery.setLocation(
|
||||
SearchServiceHolder.INSTANCE.getMapUIController().getWindowCenterLocation());
|
||||
IMogoPoiSearch inputtipsSearch =
|
||||
mMapService.getPoiSearch(getContext(), mogoInputtipsQuery);
|
||||
public void startSearchLocalPoiByInput( String keyword ) {
|
||||
|
||||
inputtipsSearch.setPoiSearchListener(new IMogoPoiSearchListener() {
|
||||
@Override public void onPoiSearched(MogoPoiResult result, int errorCode) {
|
||||
MogoPoiSearchQuery poiSearchQuery = new MogoPoiSearchQuery( keyword, keyword );
|
||||
poiSearchQuery.setPageSize( 10 );
|
||||
poiSearchQuery.setLocation( SearchApisHolder.getUiControllerApis().getWindowCenterLocation() );
|
||||
IMogoPoiSearch poiSearch = SearchApisHolder.getMapServiceApis().getPoiSearch( getContext(), poiSearchQuery );
|
||||
|
||||
poiSearch.setPoiSearchListener( new IMogoPoiSearchListener() {
|
||||
@Override
|
||||
public void onPoiSearched( MogoPoiResult result, int errorCode ) {
|
||||
if ( result != null ) {
|
||||
mView.renderSearchPoiResult(result.getPois());
|
||||
mView.renderSearchPoiResult( result.getPois() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onPoiItemSearched(MogoPoiItem item, int errorCode) {
|
||||
@Override
|
||||
public void onPoiItemSearched( MogoPoiItem item, int errorCode ) {
|
||||
|
||||
}
|
||||
});
|
||||
inputtipsSearch.searchPOIAsyn();
|
||||
} );
|
||||
poiSearch.searchPOIAsyn();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy(@NonNull LifecycleOwner owner) {
|
||||
super.onDestroy(owner);
|
||||
if (mCompositeDisposable != null && !mCompositeDisposable.isDisposed()) {
|
||||
public void onDestroy( @NonNull LifecycleOwner owner ) {
|
||||
super.onDestroy( owner );
|
||||
if ( mCompositeDisposable != null && !mCompositeDisposable.isDisposed() ) {
|
||||
mCompositeDisposable.dispose();
|
||||
mCompositeDisposable = null;
|
||||
}
|
||||
//CameraChangedLiveData.getInstance().removeAllObserver();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Rect
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
@@ -15,26 +14,16 @@ import com.mogo.map.marker.IMogoMarker
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener
|
||||
import com.mogo.map.marker.MogoMarkerOptions
|
||||
import com.mogo.map.search.geo.MogoPoiItem
|
||||
import com.mogo.map.search.inputtips.MogoTip
|
||||
import com.mogo.module.common.MogoModulePaths
|
||||
import com.mogo.module.common.map.MapCenterPointStrategy
|
||||
import com.mogo.module.common.map.Scene
|
||||
import com.mogo.module.navi.R
|
||||
import com.mogo.module.navi.bean.SearchPoi
|
||||
import com.mogo.module.navi.constants.AMapConstants
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder
|
||||
import com.mogo.module.navi.constants.SearchApisHolder
|
||||
import com.mogo.module.navi.manager.AddressManager
|
||||
import com.mogo.module.navi.ui.adapter.SearchCategoryAdapter
|
||||
import com.mogo.module.navi.ui.base.BaseFragment
|
||||
import com.mogo.module.navi.uitls.BitmapUtils
|
||||
import com.mogo.module.navi.uitls.StringUtils
|
||||
import com.mogo.utils.UiThreadHandler
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.cv_search_result
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.et_navi_search
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.iv_navi_back
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.pb_path
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.rv_search_result
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.tv_navi_navi
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.*
|
||||
|
||||
/**
|
||||
* @author zyz
|
||||
@@ -112,7 +101,7 @@ class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBa
|
||||
private fun addMarkers() {
|
||||
addMarkers.clear()
|
||||
var marginBounder = resources.getDimensionPixelSize(R.dimen.dp_60) * 2
|
||||
SearchServiceHolder.getMapUIController().showBounds(TAG,
|
||||
SearchApisHolder.getUiControllerApis().showBounds(TAG,
|
||||
null,
|
||||
locationList,
|
||||
Rect(cv_search_result.width + marginBounder, marginBounder, marginBounder, marginBounder),
|
||||
@@ -120,7 +109,7 @@ class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBa
|
||||
)
|
||||
|
||||
for (options in arrayList) {
|
||||
var addMarker = SearchServiceHolder.getMarkerManger().addMarker(TAG, options)
|
||||
var addMarker = SearchApisHolder.getMarkerManager().addMarker(TAG, options)
|
||||
addMarker.onMarkerClickListener = this
|
||||
addMarkers.add(addMarker)
|
||||
}
|
||||
@@ -180,7 +169,7 @@ class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBa
|
||||
|
||||
|
||||
iv_navi_back.setOnClickListener {
|
||||
SearchServiceHolder.fragmentManager.pop()
|
||||
SearchApisHolder.getFragmentManager().pop()
|
||||
}
|
||||
|
||||
tv_navi_navi.setOnClickListener {
|
||||
@@ -210,8 +199,8 @@ class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBa
|
||||
arrayList.get(mAdapter.lastPosition).icon(getMarkerIcon(mAdapter.lastPosition))
|
||||
arrayList.get(mAdapter.current).icon(getMarkerIcon(mAdapter.current))
|
||||
if (moveToCenter) {
|
||||
SearchServiceHolder.statusManager.setUserInteractionStatus(TAG, true, false)
|
||||
SearchServiceHolder.getMapUIController().moveToCenter(current.position)
|
||||
SearchApisHolder.getStatusManager().setUserInteractionStatus(TAG, true, false)
|
||||
SearchApisHolder.getUiControllerApis().moveToCenter(current.position, true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +225,7 @@ class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBa
|
||||
super.onDestroyView()
|
||||
mSearchPresenter.onDestroy(viewLifecycleOwner)
|
||||
lifecycle.removeObserver(mSearchPresenter)
|
||||
SearchServiceHolder.getMarkerManger().removeMarkers(TAG)
|
||||
SearchApisHolder.getMarkerManager().removeMarkers(TAG)
|
||||
|
||||
unRegisterVoice()
|
||||
}
|
||||
@@ -253,7 +242,7 @@ class CategorySearchFragment : BaseFragment(), CategoryView, IMogoVoiceCmdCallBa
|
||||
|
||||
companion object {
|
||||
fun newInstance(category: String): Fragment {
|
||||
MapCenterPointStrategy.setMapCenterPointByScene(SearchServiceHolder.getMapUIController(), Scene.CATEGORY_SEARCH)
|
||||
MapCenterPointStrategy.setMapCenterPointByScene(SearchApisHolder.getUiControllerApis(), Scene.CATEGORY_SEARCH)
|
||||
var bundle = Bundle()
|
||||
bundle.putString("category", category)
|
||||
var categorySerachFragment = CategorySearchFragment()
|
||||
|
||||
@@ -11,13 +11,10 @@ import com.mogo.commons.voice.IMogoVoiceCmdCallBack
|
||||
import com.mogo.map.MogoLatLng
|
||||
import com.mogo.map.navi.IMogoNaviListener
|
||||
import com.mogo.map.navi.MogoCalculatePath
|
||||
import com.mogo.map.navi.MogoNaviConfig
|
||||
import com.mogo.module.common.map.MapCenterPointStrategy
|
||||
import com.mogo.module.common.map.Scene
|
||||
import com.mogo.module.navi.R
|
||||
import com.mogo.module.navi.constants.AMapConstants
|
||||
import com.mogo.module.navi.constants.DataConstants
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder
|
||||
import com.mogo.module.navi.constants.SearchApisHolder
|
||||
import com.mogo.module.navi.manager.SettingManager
|
||||
import com.mogo.module.navi.ui.adapter.CalculatePathAdapter
|
||||
import com.mogo.module.navi.ui.base.BaseFragment
|
||||
@@ -72,7 +69,7 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
retry()
|
||||
}
|
||||
"cancel" -> {
|
||||
SearchServiceHolder.fragmentManager.clearAll()
|
||||
SearchApisHolder.getFragmentManager().clearAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,7 +81,7 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
}
|
||||
|
||||
override fun onCalculateSuccess() {
|
||||
var calculatedStrategies = SearchServiceHolder.getNavi().calculatedStrategies
|
||||
var calculatedStrategies = SearchApisHolder.getNaviApis().calculatedStrategies
|
||||
if (calculatedStrategies != null && calculatedStrategies.size > 0) {
|
||||
mAdapter.setDatas(calculatedStrategies)
|
||||
mAdapter.selectTag = calculatedStrategies[0].tagId
|
||||
@@ -95,7 +92,9 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
if (calculatedStrategies.isNullOrEmpty()) {
|
||||
return@postDelayed
|
||||
}
|
||||
SearchServiceHolder.getNavi().itemClickInteraction.onItemClicked(calculatedStrategies[0].tagId)
|
||||
if (SearchApisHolder.getNaviApis().itemClickInteraction != null) {
|
||||
SearchApisHolder.getNaviApis().itemClickInteraction.onItemClicked(calculatedStrategies[0].tagId)
|
||||
}
|
||||
|
||||
if (calculatedStrategies.size == 1) {
|
||||
// 一条路线,自动开启导航
|
||||
@@ -157,16 +156,16 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
iv_navi_back.setOnClickListener {
|
||||
SearchServiceHolder.fragmentManager.pop()
|
||||
SearchApisHolder.getFragmentManager().pop()
|
||||
}
|
||||
|
||||
tv_navi_navi.text = getString(R.string.start_navi)
|
||||
|
||||
et_navi_search.setText(getString(R.string.choose_path))
|
||||
et_navi_search.isEnabled = false
|
||||
SearchServiceHolder.getNavi().naviTo(mogoTip)
|
||||
SearchApisHolder.getNaviApis().naviTo(mogoTip)
|
||||
|
||||
SearchServiceHolder.listenerCenter.registerMogoNaviListener(AMapConstants.PATH_FRAGMENT_CHOOSE_PATH, this)
|
||||
SearchApisHolder.getRegisterCenterApis().registerMogoNaviListener(AMapConstants.PATH_FRAGMENT_CHOOSE_PATH, this)
|
||||
|
||||
var arrayList = ArrayList<MogoCalculatePath>()
|
||||
mAdapter = CalculatePathAdapter(activity, arrayList)
|
||||
@@ -181,7 +180,7 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
}
|
||||
}
|
||||
|
||||
SearchServiceHolder.getNavi().setLineClickInteraction {
|
||||
SearchApisHolder.getNaviApis().setLineClickInteraction {
|
||||
mAdapter.selectTag = it
|
||||
}
|
||||
|
||||
@@ -190,7 +189,7 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
selectPath(item)
|
||||
}
|
||||
|
||||
SearchServiceHolder.getMarkerManger().removeMarkers()
|
||||
SearchApisHolder.getMarkerManager().removeMarkers()
|
||||
|
||||
DataConstants.sCmds.entries.filter {
|
||||
it != null && !TextUtils.isEmpty(it.key) && (it.value?.isNotEmpty() ?: false)
|
||||
@@ -198,8 +197,8 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
AIAssist.getInstance(mContext).registerUnWakeupCommand(it.key, it.value, this@ChoosePathFragment)
|
||||
}
|
||||
|
||||
SearchServiceHolder.intentManager.registerIntentListener(AMapConstants.COMMAND_START_NAVI, this)
|
||||
SearchServiceHolder.intentManager.registerIntentListener(AMapConstants.COMMAND_CHOOSE_PATH, this)
|
||||
SearchApisHolder.getIntentManager().registerIntentListener(AMapConstants.COMMAND_START_NAVI, this)
|
||||
SearchApisHolder.getIntentManager().registerIntentListener(AMapConstants.COMMAND_CHOOSE_PATH, this)
|
||||
}
|
||||
|
||||
private fun registerRetryVoice() {
|
||||
@@ -211,7 +210,7 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
}
|
||||
|
||||
private fun retry() {
|
||||
SearchServiceHolder.getNavi().naviTo(mogoTip)
|
||||
SearchApisHolder.getNaviApis().naviTo(mogoTip)
|
||||
pb_path.visibility = View.VISIBLE
|
||||
group_path.visibility = View.GONE
|
||||
}
|
||||
@@ -221,28 +220,30 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
return
|
||||
}
|
||||
|
||||
SearchServiceHolder.getNavi().startNavi(!SettingManager.isMonitor())
|
||||
SearchServiceHolder.getMapUIController().recoverLockMode()
|
||||
SearchApisHolder.getNaviApis().startNavi(!SettingManager.isMonitor())
|
||||
SearchApisHolder.getUiControllerApis().recoverLockMode()
|
||||
|
||||
if (SearchServiceHolder.guideShowProvider.isPlayingVideo()) {
|
||||
SearchServiceHolder.guideShowProvider.closeGuideShowView()
|
||||
if (SearchApisHolder.getGuideShowApis().isPlayingVideo()) {
|
||||
SearchApisHolder.getGuideShowApis().closeGuideShowView()
|
||||
}
|
||||
isStartedNavi = true
|
||||
SearchServiceHolder.fragmentManager.clearAll()
|
||||
SearchApisHolder.getFragmentManager().clearAll()
|
||||
}
|
||||
|
||||
private fun selectPath(item: MogoCalculatePath?) {
|
||||
item?.let {
|
||||
mAdapter.setSelectTag(item.tagId)
|
||||
SearchServiceHolder.getNavi().itemClickInteraction.onItemClicked(item.tagId)
|
||||
if (SearchApisHolder.getNaviApis().itemClickInteraction != null) {
|
||||
SearchApisHolder.getNaviApis().itemClickInteraction.onItemClicked(item.tagId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
SearchServiceHolder.listenerCenter.unregisterMogoNaviListener(AMapConstants.PATH_FRAGMENT_CHOOSE_PATH)
|
||||
SearchApisHolder.getRegisterCenterApis().unregisterMogoNaviListener(AMapConstants.PATH_FRAGMENT_CHOOSE_PATH)
|
||||
if (!isStartedNavi) {
|
||||
SearchServiceHolder.getNavi().clearCalculatePaths()
|
||||
SearchApisHolder.getNaviApis().clearCalculatePaths()
|
||||
}
|
||||
|
||||
DataConstants.sCmds.entries.filter {
|
||||
@@ -251,8 +252,8 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
AIAssist.getInstance(mContext).unregisterUnWakeupCommand(it.key)
|
||||
}
|
||||
|
||||
SearchServiceHolder.intentManager.unregisterIntentListener(AMapConstants.COMMAND_START_NAVI, this)
|
||||
SearchServiceHolder.intentManager.unregisterIntentListener(AMapConstants.COMMAND_CHOOSE_PATH, this)
|
||||
SearchApisHolder.getIntentManager().unregisterIntentListener(AMapConstants.COMMAND_START_NAVI, this)
|
||||
SearchApisHolder.getIntentManager().unregisterIntentListener(AMapConstants.COMMAND_CHOOSE_PATH, this)
|
||||
}
|
||||
|
||||
override fun onIntentReceived(intentStr: String?, intent: Intent?) {
|
||||
@@ -294,7 +295,6 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
val TAG: String = "ChoosePathFragment"
|
||||
|
||||
fun newInstance(searchPoi: MogoLatLng): Fragment {
|
||||
MapCenterPointStrategy.setMapCenterPointByScene(SearchServiceHolder.getMapUIController(), Scene.CALCULATE_PATH)
|
||||
var bundle = Bundle()
|
||||
bundle.putParcelable(AMapConstants.KEY_PARCELABLE, searchPoi)
|
||||
var choosePathFragment = ChoosePathFragment()
|
||||
|
||||
@@ -2,34 +2,29 @@ package com.mogo.module.navi.ui.search;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.health.ServiceHealthStats;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.commons.analytics.AnalyticsUtils;
|
||||
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.commons.voice.IMogoVoiceCmdCallBack;
|
||||
import com.mogo.map.search.inputtips.MogoTip;
|
||||
import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.navi.R;
|
||||
import com.mogo.module.navi.bean.EntityConvertUtils;
|
||||
import com.mogo.module.navi.bean.SearchPoi;
|
||||
import com.mogo.module.navi.constants.AMapConstants;
|
||||
import com.mogo.module.navi.constants.SearchApisHolder;
|
||||
import com.mogo.module.navi.manager.AddressManager;
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder;
|
||||
import com.mogo.module.navi.ui.adapter.HistoryPoiAdapter;
|
||||
import com.mogo.module.navi.ui.adapter.SearchPoiAdapter;
|
||||
import com.mogo.module.navi.ui.base.UiController;
|
||||
import com.mogo.module.navi.ui.setting.NaviSettingFragment;
|
||||
import com.mogo.module.navi.uitls.StringUtils;
|
||||
import com.mogo.service.fragmentmanager.FragmentDescriptor;
|
||||
import com.mogo.service.fragmentmanager.FragmentStackTransactionListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -45,8 +40,8 @@ import java.util.List;
|
||||
* {@link SearchConstants#SEARCH_TYPE_MULTI_HOME}
|
||||
*/
|
||||
public class SearchFragment extends BaseSearchFragment
|
||||
implements SearchView, View.OnClickListener, IMogoVoiceCmdCallBack,
|
||||
FragmentStackTransactionListener {
|
||||
implements SearchView, View.OnClickListener, IMogoVoiceCmdCallBack,
|
||||
FragmentStackTransactionListener {
|
||||
|
||||
public static final String TAG = "search";
|
||||
|
||||
@@ -72,14 +67,15 @@ public class SearchFragment extends BaseSearchFragment
|
||||
private TextView tvEmpty;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof UiController) {
|
||||
public void onAttach( Context context ) {
|
||||
super.onAttach( context );
|
||||
if ( context instanceof UiController ) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@Override
|
||||
public void onCreate( @Nullable Bundle savedInstanceState ) {
|
||||
super.onCreate( savedInstanceState );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,114 +84,117 @@ public class SearchFragment extends BaseSearchFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
SearchServiceHolder.INSTANCE.getMarkerManger().removeMarkers();
|
||||
SearchServiceHolder.INSTANCE.getMapUIController().showMyLocation(false);
|
||||
public void onActivityCreated( @Nullable Bundle savedInstanceState ) {
|
||||
super.onActivityCreated( savedInstanceState );
|
||||
SearchApisHolder.getMarkerManager().removeMarkers();
|
||||
SearchApisHolder.getUiControllerApis().showMyLocation( false );
|
||||
}
|
||||
|
||||
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mSearchResult = view.findViewById(R.id.rv_navi_search);
|
||||
rvHistory = view.findViewById(R.id.rv_navi_history);
|
||||
rlHistory = view.findViewById(R.id.rl_navi_history);
|
||||
@Override
|
||||
public void onViewCreated( @NonNull View view, @Nullable Bundle savedInstanceState ) {
|
||||
super.onViewCreated( view, savedInstanceState );
|
||||
mSearchResult = view.findViewById( R.id.rv_navi_search );
|
||||
rvHistory = view.findViewById( R.id.rv_navi_history );
|
||||
rlHistory = view.findViewById( R.id.rl_navi_history );
|
||||
LinearLayoutManager linearManager =
|
||||
new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
|
||||
new LinearLayoutManager( getActivity(), LinearLayoutManager.VERTICAL, false );
|
||||
|
||||
rvHistory.setLayoutManager(linearManager);
|
||||
rvHistory.setLayoutManager( linearManager );
|
||||
LinearLayoutManager linearLayoutManager =
|
||||
new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
|
||||
mSearchResult.setLayoutManager(linearLayoutManager);
|
||||
new LinearLayoutManager( getActivity(), LinearLayoutManager.VERTICAL, false );
|
||||
mSearchResult.setLayoutManager( linearLayoutManager );
|
||||
|
||||
mPoiAdapter = new SearchPoiAdapter(getActivity(), new ArrayList<>());
|
||||
mSearchResult.setAdapter(mPoiAdapter);
|
||||
mPoiAdapter = new SearchPoiAdapter( getActivity(), new ArrayList<>() );
|
||||
mSearchResult.setAdapter( mPoiAdapter );
|
||||
|
||||
mHistoryAdapter = new HistoryPoiAdapter(getActivity(), new ArrayList<>());
|
||||
rvHistory.setAdapter(mHistoryAdapter);
|
||||
mHistoryAdapter = new HistoryPoiAdapter( getActivity(), new ArrayList<>() );
|
||||
rvHistory.setAdapter( mHistoryAdapter );
|
||||
|
||||
tvEmpty = findViewById(R.id.tv_navi_list_empty);
|
||||
tvEmpty = findViewById( R.id.tv_navi_list_empty );
|
||||
|
||||
findViewById(R.id.iv_navi_back).setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
SearchServiceHolder.INSTANCE.getFragmentManager().pop();
|
||||
findViewById( R.id.iv_navi_back ).setOnClickListener( v -> {
|
||||
SearchApisHolder.getFragmentManager().pop();
|
||||
} );
|
||||
|
||||
mHistoryAdapter.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
SearchApisHolder.getAnalyticsApis().track( "Navigation_History_destination", new HashMap< String, Object >() );
|
||||
SearchPoi item = ( SearchPoi ) v.getTag( R.id.tag_item );
|
||||
goHistory( item );
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
mHistoryAdapter.setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
SearchServiceHolder.INSTANCE.getAnalyticsManager()
|
||||
.track("Navigation_History_destination", new HashMap<String, Object>());
|
||||
SearchPoi item = (SearchPoi) v.getTag(R.id.tag_item);
|
||||
goHistory(item);
|
||||
mPoiAdapter.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
MogoTip tag = ( MogoTip ) v.getTag( R.id.tag_position );
|
||||
goResult( tag );
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
mPoiAdapter.setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
MogoTip tag = (MogoTip) v.getTag(R.id.tag_position);
|
||||
goResult(tag);
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.tv_navi_history_clear).setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
findViewById( R.id.tv_navi_history_clear ).setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
mSearchPresenter.deleteAllCachedPoi();
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
findViewById(R.id.tv_navi_setting).setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
findViewById( R.id.tv_navi_setting ).setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
goSetting();
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
findViewById(R.id.tv_navi_company).setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
findViewById( R.id.tv_navi_company ).setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
AddressManager.INSTANCE.goCompany();
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
findViewById(R.id.tv_navi_home).setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
findViewById( R.id.tv_navi_home ).setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
AddressManager.INSTANCE.goHome();
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
findViewById(R.id.tv_navi_wash).setOnClickListener(this);
|
||||
findViewById(R.id.tv_navi_toilet).setOnClickListener(this);
|
||||
findViewById(R.id.tv_navi_gas).setOnClickListener(this);
|
||||
findViewById(R.id.tv_navi_restaurant).setOnClickListener(this);
|
||||
findViewById(R.id.tv_navi_park).setOnClickListener(this);
|
||||
findViewById( R.id.tv_navi_wash ).setOnClickListener( this );
|
||||
findViewById( R.id.tv_navi_toilet ).setOnClickListener( this );
|
||||
findViewById( R.id.tv_navi_gas ).setOnClickListener( this );
|
||||
findViewById( R.id.tv_navi_restaurant ).setOnClickListener( this );
|
||||
findViewById( R.id.tv_navi_park ).setOnClickListener( this );
|
||||
|
||||
findViewById(R.id.tv_navi_search).setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
SearchServiceHolder.INSTANCE.getAnalyticsManager()
|
||||
.track("Navigation_button_search", new HashMap<String, Object>());
|
||||
|
||||
mSearchPresenter.startSearchPoiByInput(mSearchBox.getText().toString());
|
||||
findViewById( R.id.tv_navi_search ).setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
SearchApisHolder.getAnalyticsApis().track( "Navigation_button_search", new HashMap< String, Object >() );
|
||||
mSearchPresenter.startSearchPoiByInput( mSearchBox.getText().toString() );
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
registerVoidCmd();
|
||||
registerVoidCmd();
|
||||
}
|
||||
|
||||
private void goResult(MogoTip tag) {
|
||||
SearchPoi searchPoi = EntityConvertUtils.tipToPoi(tag);
|
||||
if (tag.getPoint() == null) {
|
||||
goCategory(tag.getName());
|
||||
private void goResult( MogoTip tag ) {
|
||||
SearchPoi searchPoi = EntityConvertUtils.tipToPoi( tag );
|
||||
if ( tag.getPoint() == null ) {
|
||||
goCategory( tag.getName() );
|
||||
} else {
|
||||
mSearchPresenter.insert(searchPoi);
|
||||
mSearchPresenter.insert( searchPoi );
|
||||
AddressManager.INSTANCE.calculatePath( tag.getPoint() );
|
||||
}
|
||||
}
|
||||
|
||||
private void goSetting() {
|
||||
SearchServiceHolder.INSTANCE.getAnalyticsManager().track("Navigation_button_setting", new HashMap<String, Object>());
|
||||
SearchApisHolder.getAnalyticsApis().track( "Navigation_button_setting", new HashMap< String, Object >() );
|
||||
AddressManager.INSTANCE.goSettings();
|
||||
}
|
||||
|
||||
private void goHistory(SearchPoi item) {
|
||||
MogoTip mogoTip = EntityConvertUtils.poi2MogoTip(item);
|
||||
private void goHistory( SearchPoi item ) {
|
||||
MogoTip mogoTip = EntityConvertUtils.poi2MogoTip( item );
|
||||
AddressManager.INSTANCE.calculatePath( mogoTip.getPoint() );
|
||||
}
|
||||
|
||||
@@ -211,99 +210,95 @@ public class SearchFragment extends BaseSearchFragment
|
||||
|
||||
private void registerVoidCmd() {
|
||||
|
||||
AIAssist.getInstance(getContext())
|
||||
.registerUnWakeupCommand(GO_HOME_CMD, new String[] { "回家" }, this);
|
||||
AIAssist.getInstance(getContext())
|
||||
.registerUnWakeupCommand(GO_COMPANY_CMD, new String[] { "去公司" }, this);
|
||||
AIAssist.getInstance(getContext())
|
||||
.registerUnWakeupCommand(GAS_CMD, new String[] { "加油站" }, this);
|
||||
AIAssist.getInstance(getContext())
|
||||
.registerUnWakeupCommand(RESTAURANT_CMD, new String[] { "餐馆" }, this);
|
||||
AIAssist.getInstance(getContext())
|
||||
.registerUnWakeupCommand(TOILET_CMD, new String[] { "卫生间", "厕所" }, this);
|
||||
AIAssist.getInstance(getContext())
|
||||
.registerUnWakeupCommand(PARK_CMD, new String[] { "停车场" }, this);
|
||||
AIAssist.getInstance(getContext())
|
||||
.registerUnWakeupCommand(NAVI_SETTING_CMD, new String[] { "导航设置" }, this);
|
||||
AIAssist.getInstance(getContext())
|
||||
.registerUnWakeupCommand(CLEAN_CMD, new String[] { "清空历史目的地" }, this);
|
||||
AIAssist.getInstance(getContext())
|
||||
.registerUnWakeupCommand(WASH_CMD, new String[] { "洗车" }, this);
|
||||
AIAssist.getInstance( getContext() )
|
||||
.registerUnWakeupCommand( GO_HOME_CMD, new String[]{"回家"}, this );
|
||||
AIAssist.getInstance( getContext() )
|
||||
.registerUnWakeupCommand( GO_COMPANY_CMD, new String[]{"去公司"}, this );
|
||||
AIAssist.getInstance( getContext() )
|
||||
.registerUnWakeupCommand( GAS_CMD, new String[]{"加油站"}, this );
|
||||
AIAssist.getInstance( getContext() )
|
||||
.registerUnWakeupCommand( RESTAURANT_CMD, new String[]{"餐馆"}, this );
|
||||
AIAssist.getInstance( getContext() )
|
||||
.registerUnWakeupCommand( TOILET_CMD, new String[]{"卫生间", "厕所"}, this );
|
||||
AIAssist.getInstance( getContext() )
|
||||
.registerUnWakeupCommand( PARK_CMD, new String[]{"停车场"}, this );
|
||||
AIAssist.getInstance( getContext() )
|
||||
.registerUnWakeupCommand( NAVI_SETTING_CMD, new String[]{"导航设置"}, this );
|
||||
AIAssist.getInstance( getContext() )
|
||||
.registerUnWakeupCommand( CLEAN_CMD, new String[]{"清空历史目的地"}, this );
|
||||
AIAssist.getInstance( getContext() )
|
||||
.registerUnWakeupCommand( WASH_CMD, new String[]{"洗车"}, this );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void renderSearchPoiResult(List<MogoTip> datums, boolean showDelete) {
|
||||
if (datums == null || datums.isEmpty()) {
|
||||
showEmpty(getString(R.string.search_empty));
|
||||
public void renderSearchPoiResult( List< MogoTip > datums, boolean showDelete ) {
|
||||
if ( datums == null || datums.isEmpty() ) {
|
||||
showEmpty( getString( R.string.search_empty ) );
|
||||
return;
|
||||
}
|
||||
showResult();
|
||||
mPoiAdapter.setDatas(datums);
|
||||
mPoiAdapter.setDatas( datums );
|
||||
registerResult();
|
||||
}
|
||||
|
||||
@Override public void showHistory(List<SearchPoi> datums) {
|
||||
@Override
|
||||
public void showHistory( List< SearchPoi > datums ) {
|
||||
|
||||
if (datums == null || datums.isEmpty()) {
|
||||
showEmpty(getString(R.string.history_empty));
|
||||
if ( datums == null || datums.isEmpty() ) {
|
||||
showEmpty( getString( R.string.history_empty ) );
|
||||
return;
|
||||
}
|
||||
showHistory();
|
||||
mHistoryAdapter.setDatas(datums);
|
||||
mHistoryAdapter.setDatas( datums );
|
||||
registerHistory();
|
||||
}
|
||||
|
||||
private void registerHistory() {
|
||||
List<SearchPoi> datums = mHistoryAdapter.getList();
|
||||
for (int i = 0; i < datums.size(); i++) {
|
||||
String s = StringUtils.int2String(i + 1);
|
||||
AIAssist.getInstance(getContext())
|
||||
.registerUnWakeupCommand("history" + i,
|
||||
new String[] { "第" + s + "个", "第" + s + "条" }, this);
|
||||
if (cmds.contains("history" + i)) {
|
||||
List< SearchPoi > datums = mHistoryAdapter.getList();
|
||||
for ( int i = 0; i < datums.size(); i++ ) {
|
||||
String s = StringUtils.int2String( i + 1 );
|
||||
AIAssist.getInstance( getContext() )
|
||||
.registerUnWakeupCommand( "history" + i,
|
||||
new String[]{"第" + s + "个", "第" + s + "条"}, this );
|
||||
if ( cmds.contains( "history" + i ) ) {
|
||||
continue;
|
||||
}
|
||||
cmds.add("history" + i);
|
||||
cmds.add( "history" + i );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void registerResult() {
|
||||
List<MogoTip> datums = mPoiAdapter.getList();
|
||||
for (int i = 0; i < datums.size(); i++) {
|
||||
String s = StringUtils.int2String(i + 1);
|
||||
AIAssist.getInstance(getContext())
|
||||
.registerUnWakeupCommand("history" + i,
|
||||
new String[] { "第" + s + "个", "第" + s + "条" }, this);
|
||||
if (cmds.contains("history" + i)) {
|
||||
List< MogoTip > datums = mPoiAdapter.getList();
|
||||
for ( int i = 0; i < datums.size(); i++ ) {
|
||||
String s = StringUtils.int2String( i + 1 );
|
||||
AIAssist.getInstance( getContext() )
|
||||
.registerUnWakeupCommand( "history" + i,
|
||||
new String[]{"第" + s + "个", "第" + s + "条"}, this );
|
||||
if ( cmds.contains( "history" + i ) ) {
|
||||
continue;
|
||||
}
|
||||
cmds.add("history" + i);
|
||||
cmds.add( "history" + i );
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> cmds = new ArrayList<String>();
|
||||
private List< String > cmds = new ArrayList< String >();
|
||||
|
||||
@Override
|
||||
public int getSearchType() {
|
||||
return mSearchType;
|
||||
}
|
||||
|
||||
@Override public void startJumpAnimation() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出搜索,进行清理
|
||||
*/
|
||||
private void exitSearch() {
|
||||
|
||||
switch (mSearchType) {
|
||||
switch ( mSearchType ) {
|
||||
case SearchConstants.SEARCH_TYPE_COMMON:
|
||||
try {
|
||||
} catch (Exception e) {
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
@@ -313,97 +308,79 @@ public class SearchFragment extends BaseSearchFragment
|
||||
}
|
||||
|
||||
private void showResult() {
|
||||
rlHistory.setVisibility(View.GONE);
|
||||
mSearchResult.setVisibility(View.VISIBLE);
|
||||
tvEmpty.setVisibility(View.GONE);
|
||||
rlHistory.setVisibility( View.GONE );
|
||||
mSearchResult.setVisibility( View.VISIBLE );
|
||||
tvEmpty.setVisibility( View.GONE );
|
||||
}
|
||||
|
||||
private void showHistory() {
|
||||
rlHistory.setVisibility(View.VISIBLE);
|
||||
mSearchResult.setVisibility(View.GONE);
|
||||
tvEmpty.setVisibility(View.GONE);
|
||||
rlHistory.setVisibility( View.VISIBLE );
|
||||
mSearchResult.setVisibility( View.GONE );
|
||||
tvEmpty.setVisibility( View.GONE );
|
||||
}
|
||||
|
||||
private void showEmpty(String str) {
|
||||
rlHistory.setVisibility(View.GONE);
|
||||
tvEmpty.setText(str);
|
||||
mSearchResult.setVisibility(View.GONE);
|
||||
tvEmpty.setVisibility(View.VISIBLE);
|
||||
private void showEmpty( String str ) {
|
||||
rlHistory.setVisibility( View.GONE );
|
||||
tvEmpty.setText( str );
|
||||
mSearchResult.setVisibility( View.GONE );
|
||||
tvEmpty.setVisibility( View.VISIBLE );
|
||||
}
|
||||
|
||||
private boolean isHistory(){
|
||||
return rlHistory.getVisibility()==View.VISIBLE;
|
||||
private boolean isHistory() {
|
||||
return rlHistory.getVisibility() == View.VISIBLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 类别
|
||||
*/
|
||||
@Override public void onClick(View v) {
|
||||
TextView category = (TextView) v;
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
TextView category = ( TextView ) v;
|
||||
String text = category.getText().toString();
|
||||
goCategory(text);
|
||||
goCategory( text );
|
||||
}
|
||||
|
||||
private void goCategory(String text) {
|
||||
private void goCategory( String text ) {
|
||||
AddressManager.INSTANCE.categorySearch( text );
|
||||
}
|
||||
|
||||
@Override public void onResume() {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override public void onPause() {
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
SearchServiceHolder.INSTANCE.getMapUIController().showMyLocation(true);
|
||||
// moveMapToRight();
|
||||
SearchApisHolder.getUiControllerApis().showMyLocation( true );
|
||||
unRegisterVoice();
|
||||
}
|
||||
|
||||
private void unRegisterVoice() {
|
||||
|
||||
//private static final String GO_HOME_CMD="goHome";
|
||||
//private static final String GO_COMPANY_CMD="goCompany";
|
||||
//private static final String GAS_CMD="gas";
|
||||
//private static final String RESTAURANT_CMD="restaurant";
|
||||
//private static final String TOILET_CMD="toilet";
|
||||
//private static final String PARK_CMD="park";
|
||||
//private static final String WASH_CMD="wash";
|
||||
//private static final String NAVI_SETTING_CMD="setting";
|
||||
//private static final String CLEAN_CMD="clean";
|
||||
//private static final String BACK_CMD="back";
|
||||
AIAssist.getInstance(getContext()).unregisterUnWakeupCommand(GO_HOME_CMD);
|
||||
AIAssist.getInstance(getContext()).unregisterUnWakeupCommand(GO_COMPANY_CMD);
|
||||
AIAssist.getInstance(getContext()).unregisterUnWakeupCommand(GAS_CMD);
|
||||
AIAssist.getInstance(getContext()).unregisterUnWakeupCommand(RESTAURANT_CMD);
|
||||
AIAssist.getInstance(getContext()).unregisterUnWakeupCommand(TOILET_CMD);
|
||||
AIAssist.getInstance(getContext()).unregisterUnWakeupCommand(PARK_CMD);
|
||||
AIAssist.getInstance(getContext()).unregisterUnWakeupCommand(WASH_CMD);
|
||||
AIAssist.getInstance(getContext()).unregisterUnWakeupCommand(NAVI_SETTING_CMD);
|
||||
AIAssist.getInstance(getContext()).unregisterUnWakeupCommand(CLEAN_CMD);
|
||||
for (String cmd : cmds) {
|
||||
AIAssist.getInstance(getContext()).unregisterUnWakeupCommand(cmd);
|
||||
AIAssist.getInstance( getContext() ).unregisterUnWakeupCommand( GO_HOME_CMD );
|
||||
AIAssist.getInstance( getContext() ).unregisterUnWakeupCommand( GO_COMPANY_CMD );
|
||||
AIAssist.getInstance( getContext() ).unregisterUnWakeupCommand( GAS_CMD );
|
||||
AIAssist.getInstance( getContext() ).unregisterUnWakeupCommand( RESTAURANT_CMD );
|
||||
AIAssist.getInstance( getContext() ).unregisterUnWakeupCommand( TOILET_CMD );
|
||||
AIAssist.getInstance( getContext() ).unregisterUnWakeupCommand( PARK_CMD );
|
||||
AIAssist.getInstance( getContext() ).unregisterUnWakeupCommand( WASH_CMD );
|
||||
AIAssist.getInstance( getContext() ).unregisterUnWakeupCommand( NAVI_SETTING_CMD );
|
||||
AIAssist.getInstance( getContext() ).unregisterUnWakeupCommand( CLEAN_CMD );
|
||||
for ( String cmd : cmds ) {
|
||||
AIAssist.getInstance( getContext() ).unregisterUnWakeupCommand( cmd );
|
||||
}
|
||||
}
|
||||
|
||||
//@Override public void onPause() {
|
||||
// super.onPause();
|
||||
// unRegisterVoice();
|
||||
//}
|
||||
//
|
||||
//@Override public void onResume() {
|
||||
// super.onResume();
|
||||
// registerVoidCmd();
|
||||
// registerHistory();
|
||||
//}
|
||||
|
||||
@Override public void onHiddenChanged(boolean hidden) {
|
||||
super.onHiddenChanged(hidden);
|
||||
if (hidden) {
|
||||
@Override
|
||||
public void onHiddenChanged( boolean hidden ) {
|
||||
super.onHiddenChanged( hidden );
|
||||
if ( hidden ) {
|
||||
unRegisterVoice();
|
||||
} else {
|
||||
registerVoidCmd();
|
||||
@@ -411,36 +388,37 @@ public class SearchFragment extends BaseSearchFragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onCmdSelected(String cmd) {
|
||||
if (!TextUtils.isEmpty(cmd) && cmd.startsWith("history")) {
|
||||
String index = cmd.substring(7);
|
||||
Integer integer = Integer.valueOf(index);
|
||||
if (isHistory()){
|
||||
if (integer < mHistoryAdapter.getItemCount()) {
|
||||
SearchPoi item = mHistoryAdapter.getItem(integer);
|
||||
goHistory(item);
|
||||
}
|
||||
}else {
|
||||
if (integer < mPoiAdapter.getItemCount()) {
|
||||
MogoTip item = mPoiAdapter.getItem(integer);
|
||||
goResult(item);
|
||||
@Override
|
||||
public void onCmdSelected( String cmd ) {
|
||||
if ( !TextUtils.isEmpty( cmd ) && cmd.startsWith( "history" ) ) {
|
||||
String index = cmd.substring( 7 );
|
||||
Integer integer = Integer.valueOf( index );
|
||||
if ( isHistory() ) {
|
||||
if ( integer < mHistoryAdapter.getItemCount() ) {
|
||||
SearchPoi item = mHistoryAdapter.getItem( integer );
|
||||
goHistory( item );
|
||||
}
|
||||
} else {
|
||||
if ( integer < mPoiAdapter.getItemCount() ) {
|
||||
MogoTip item = mPoiAdapter.getItem( integer );
|
||||
goResult( item );
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
switch (cmd) {
|
||||
switch ( cmd ) {
|
||||
case CLEAN_CMD:
|
||||
mSearchPresenter.deleteAllCachedPoi();
|
||||
AIAssist.getInstance(getContext())
|
||||
.speakQAndACmd(getString(R.string.notice_clean_history),
|
||||
new String[] { "确定","立即清空" }, new String[] { "取消" }, this);
|
||||
AIAssist.getInstance( getContext() )
|
||||
.speakQAndACmd( getString( R.string.notice_clean_history ),
|
||||
new String[]{"确定", "立即清空"}, new String[]{"取消"}, this );
|
||||
break;
|
||||
|
||||
|
||||
case GAS_CMD:
|
||||
|
||||
goCategory(getString(R.string.navi_gas));
|
||||
goCategory( getString( R.string.navi_gas ) );
|
||||
|
||||
break;
|
||||
case GO_COMPANY_CMD:
|
||||
@@ -455,20 +433,20 @@ public class SearchFragment extends BaseSearchFragment
|
||||
break;
|
||||
|
||||
case PARK_CMD:
|
||||
goCategory(getString(R.string.navi_park));
|
||||
goCategory( getString( R.string.navi_park ) );
|
||||
|
||||
break;
|
||||
case RESTAURANT_CMD:
|
||||
goCategory(getString(R.string.navi_restrant));
|
||||
goCategory( getString( R.string.navi_restrant ) );
|
||||
|
||||
break;
|
||||
|
||||
case TOILET_CMD:
|
||||
goCategory(getString(R.string.navi_toilet));
|
||||
goCategory( getString( R.string.navi_toilet ) );
|
||||
break;
|
||||
|
||||
case WASH_CMD:
|
||||
goCategory(getString(R.string.navi_wash));
|
||||
goCategory( getString( R.string.navi_wash ) );
|
||||
|
||||
break;
|
||||
|
||||
@@ -477,26 +455,31 @@ public class SearchFragment extends BaseSearchFragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onCmdAction(String speakText) {
|
||||
@Override
|
||||
public void onCmdAction( String speakText ) {
|
||||
|
||||
mSearchPresenter.hideDialog();
|
||||
mSearchPresenter.deleteAllCachedPoiImpl();
|
||||
}
|
||||
|
||||
@Override public void onCmdCancel(String speakText) {
|
||||
@Override
|
||||
public void onCmdCancel( String speakText ) {
|
||||
|
||||
mSearchPresenter.hideDialog();
|
||||
}
|
||||
|
||||
@Override public void onSpeakEnd(String speakText) {
|
||||
@Override
|
||||
public void onSpeakEnd( String speakText ) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void onSpeakSelectTimeOut(String speakText) {
|
||||
@Override
|
||||
public void onSpeakSelectTimeOut( String speakText ) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void onTransaction(int size) {
|
||||
@Override
|
||||
public void onTransaction( int size ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,36 @@
|
||||
package com.mogo.module.navi.ui.search;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.map.search.geo.MogoPoiItem;
|
||||
import com.mogo.map.search.inputtips.IMogoInputtipsListener;
|
||||
import com.mogo.map.search.inputtips.IMogoInputtipsSearch;
|
||||
import com.mogo.map.search.inputtips.MogoTip;
|
||||
import com.mogo.map.search.inputtips.query.MogoInputtipsQuery;
|
||||
import com.mogo.map.search.poisearch.IMogoPoiSearch;
|
||||
import com.mogo.map.search.poisearch.IMogoPoiSearchListener;
|
||||
import com.mogo.map.search.poisearch.MogoPoiResult;
|
||||
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||
import com.mogo.module.common.TextWatcherAdapter;
|
||||
import com.mogo.module.navi.R;
|
||||
import com.mogo.module.navi.bean.EntityConvertUtils;
|
||||
import com.mogo.module.navi.bean.SearchPoi;
|
||||
import com.mogo.module.navi.constants.DataConstants;
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder;
|
||||
import com.mogo.module.navi.constants.SearchApisHolder;
|
||||
import com.mogo.module.navi.database.AppDataBase;
|
||||
import com.mogo.module.navi.dialog.NoticeDialog;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleEmitter;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
@@ -41,7 +38,6 @@ import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -105,8 +101,7 @@ public class SearchPresenter extends Presenter<SearchView> {
|
||||
MogoInputtipsQuery mogoInputtipsQuery = new MogoInputtipsQuery();
|
||||
mogoInputtipsQuery.setKeyword(keyword);
|
||||
|
||||
MogoLocation lastKnowLocation =
|
||||
SearchServiceHolder.INSTANCE.getLocationClient().getLastKnowLocation();
|
||||
MogoLocation lastKnowLocation = SearchApisHolder.getLocationClientApis().getLastKnowLocation();
|
||||
mogoInputtipsQuery.setCity(lastKnowLocation.getCityName());
|
||||
mogoInputtipsQuery.setCityLimit(true);
|
||||
IMogoInputtipsSearch inputtipsSearch =
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.mogo.module.navi.ui.search;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-08
|
||||
* <p>
|
||||
* 搜索工具类
|
||||
*/
|
||||
public class SearchUtils {
|
||||
|
||||
/**
|
||||
* @param searchType
|
||||
* @return
|
||||
*/
|
||||
public static int checkAndResetSearchType( int searchType ) {
|
||||
switch ( searchType ) {
|
||||
case SearchConstants.SEARCH_TYPE_COMMON:
|
||||
case SearchConstants.SEARCH_TYPE_MULTI_HOME:
|
||||
case SearchConstants.SEARCH_TYPE_MULTI_COMPANY:
|
||||
break;
|
||||
default:
|
||||
searchType = SearchConstants.SEARCH_TYPE_COMMON;
|
||||
break;
|
||||
}
|
||||
return searchType;
|
||||
}
|
||||
|
||||
public static String getSearchTypeActionName( int searchType ) {
|
||||
switch ( searchType ) {
|
||||
case SearchConstants.SEARCH_TYPE_COMMON:
|
||||
return null;
|
||||
case SearchConstants.SEARCH_TYPE_MULTI_HOME:
|
||||
return "设为家";
|
||||
case SearchConstants.SEARCH_TYPE_MULTI_COMPANY:
|
||||
return "设为公司";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.mogo.module.navi.ui.search;
|
||||
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.mogo.commons.mvp.IView;
|
||||
import com.mogo.map.search.inputtips.MogoTip;
|
||||
import com.mogo.module.navi.bean.SearchPoi;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -20,25 +22,11 @@ public interface SearchView extends IView {
|
||||
* @param datums
|
||||
* @param showDelete 是否显示清空历史记录项
|
||||
*/
|
||||
void renderSearchPoiResult(List<MogoTip> datums, boolean showDelete);
|
||||
void renderSearchPoiResult( List< MogoTip > datums, boolean showDelete );
|
||||
|
||||
|
||||
void showHistory(List<SearchPoi> datums);
|
||||
void showHistory( List< SearchPoi > datums );
|
||||
|
||||
int getSearchType();
|
||||
|
||||
|
||||
|
||||
///**
|
||||
// * 显示逆地理位置编码结果
|
||||
// *
|
||||
// * @param address
|
||||
// */
|
||||
//void renderChoicePointResult(RegeocodeAddress address);
|
||||
|
||||
/**
|
||||
* 选点完毕后marker动画
|
||||
*/
|
||||
void startJumpAnimation();
|
||||
|
||||
}
|
||||
|
||||
@@ -4,25 +4,19 @@ import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.CompoundButton
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener
|
||||
import android.widget.CompoundButton.VISIBLE
|
||||
import android.widget.SeekBar
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.commons.voice.AIAssist
|
||||
import com.mogo.map.constants.BroadcastMode
|
||||
import com.mogo.map.uicontroller.EnumMapUI
|
||||
import com.mogo.module.common.MogoModulePaths
|
||||
import com.mogo.module.navi.R
|
||||
import com.mogo.module.navi.bean.SearchPoi
|
||||
import com.mogo.module.navi.constants.DataConstants
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder
|
||||
import com.mogo.module.navi.cp.AddressHelper
|
||||
import com.mogo.module.navi.constants.SearchApisHolder
|
||||
import com.mogo.module.navi.manager.AddressManager
|
||||
import com.mogo.module.navi.manager.SettingManager
|
||||
import com.mogo.module.navi.manager.VolumeManager
|
||||
import com.mogo.module.navi.ui.base.BaseFragment
|
||||
import com.mogo.utils.UiThreadHandler
|
||||
import kotlinx.android.synthetic.main.fragment_navi_setting.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
@@ -66,7 +60,7 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
|
||||
}
|
||||
if (isChecked) {
|
||||
SearchServiceHolder.analyticsManager.track("Navigation_preference", mapOf("type" to type))
|
||||
SearchApisHolder.getAnalyticsApis().track("Navigation_preference", mapOf("type" to type))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -109,7 +103,7 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
|
||||
private fun initEvent() {
|
||||
rl_navi_setting_title.setOnClickListener {
|
||||
SearchServiceHolder.fragmentManager.pop()
|
||||
SearchApisHolder.getFragmentManager().pop()
|
||||
}
|
||||
iv_sound_plus.setOnClickListener {
|
||||
VolumeManager.getInstance(context).incVolume()
|
||||
@@ -134,8 +128,7 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
sb_navi_volume_progress.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
if (fromUser) {
|
||||
VolumeManager.getInstance(context)
|
||||
.setSysVolume(progress)
|
||||
VolumeManager.getInstance(context).setSysVolume(progress)
|
||||
SettingManager.volume = sb_navi_volume_progress.progress
|
||||
|
||||
}
|
||||
@@ -156,39 +149,37 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
SettingManager.mapType = checkedId
|
||||
when (checkedId) {
|
||||
R.id.rb_navi_day -> {
|
||||
SearchServiceHolder.getMapUIController().changeMapMode(EnumMapUI.Type_Light)
|
||||
SearchApisHolder.getUiControllerApis().changeMapMode(EnumMapUI.Type_Light)
|
||||
}
|
||||
R.id.rb_navi_night -> {
|
||||
SearchServiceHolder.getMapUIController().changeMapMode(EnumMapUI.Type_Night)
|
||||
SearchApisHolder.getUiControllerApis().changeMapMode(EnumMapUI.Type_Night)
|
||||
}
|
||||
R.id.rb_navi_auto -> {
|
||||
SearchServiceHolder.getMapUIController().changeMapMode(EnumMapUI.Type_AUTO_LIGHT_Night)
|
||||
SearchApisHolder.getUiControllerApis().changeMapMode(EnumMapUI.Type_AUTO_LIGHT_Night)
|
||||
}
|
||||
}
|
||||
}
|
||||
rg_navi_sound_type.setOnCheckedChangeListener { group, checkedId ->
|
||||
SettingManager.voiceStyle = checkedId
|
||||
SearchServiceHolder.getNavi().setBroadcastMode(
|
||||
if (checkedId == R.id.rb_navi_detail) BroadcastMode.DETAIL else BroadcastMode.CONCISE
|
||||
)
|
||||
|
||||
if (checkedId == R.id.rb_navi_detail) {
|
||||
SearchServiceHolder.analyticsManager.track("Navigation_guide_type", mapOf("type" to 1))
|
||||
} else {
|
||||
SearchServiceHolder.analyticsManager.track("Navigation_guide_type", mapOf("type" to 2))
|
||||
when (checkedId) {
|
||||
R.id.rb_navi_detail -> {
|
||||
SearchApisHolder.getSettingManager().speakDetail()
|
||||
SearchApisHolder.getAnalyticsApis().track("Navigation_guide_type", mapOf("type" to 1))
|
||||
}
|
||||
R.id.rb_navi_draft -> {
|
||||
SearchApisHolder.getSettingManager().speakDraft()
|
||||
SearchApisHolder.getAnalyticsApis().track("Navigation_guide_type", mapOf("type" to 2))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aimlessModeGroup.setOnCheckedChangeListener { group, checkedId ->
|
||||
|
||||
SettingManager.setAimlessMode(checkedId)
|
||||
when (checkedId){
|
||||
when (checkedId) {
|
||||
R.id.aimlessModeClose -> {
|
||||
SearchServiceHolder.getNavi().setAimlessModeStatus(false)
|
||||
SearchApisHolder.getSettingManager().closeAimlessMode()
|
||||
AIAssist.getInstance(mContext).speakTTSVoice("已为您关闭巡航模式")
|
||||
}
|
||||
R.id.aimlessModeOpen -> {
|
||||
SearchServiceHolder.getNavi().setAimlessModeStatus(true)
|
||||
SearchApisHolder.getSettingManager().openAimlessMode()
|
||||
AIAssist.getInstance(mContext).speakTTSVoice("已为您开启巡航模式")
|
||||
}
|
||||
}
|
||||
@@ -196,24 +187,24 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
|
||||
|
||||
tv_navi_clear_home_address.setOnClickListener {
|
||||
AddressManager.deleteHome(context!!)
|
||||
AddressManager.deleteHome()
|
||||
clearHome()
|
||||
}
|
||||
|
||||
tv_navi_clear_company_address.setOnClickListener {
|
||||
AddressManager.deleteCompany(context!!)
|
||||
AddressManager.deleteCompany()
|
||||
clearCompany()
|
||||
}
|
||||
|
||||
tv_navi_company_address.setOnClickListener {
|
||||
if (!AddressManager.hasCompany()) {
|
||||
AddressManager.goCompany()
|
||||
SearchApisHolder.getSearchManager().goCompany()
|
||||
}
|
||||
}
|
||||
|
||||
tv_navi_home_address.setOnClickListener {
|
||||
if (!AddressManager.hasHome()) {
|
||||
AddressManager.goHome()
|
||||
SearchApisHolder.getSearchManager().goHome()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,9 +222,9 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener {
|
||||
SettingManager.setGpsSimulator(isChecked)
|
||||
|
||||
if (isChecked) {
|
||||
SearchServiceHolder.gpsSimulator.open()
|
||||
SearchApisHolder.getGpsSimulatorManager().open()
|
||||
} else {
|
||||
SearchServiceHolder.gpsSimulator.close()
|
||||
SearchApisHolder.getGpsSimulatorManager().close()
|
||||
}
|
||||
}
|
||||
tb_navi.isChecked = SettingManager.isMonitor()
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.mogo.map.MogoLatLng
|
||||
import com.mogo.map.listener.IMogoMapListener
|
||||
import com.mogo.map.marker.IMogoMarker
|
||||
import com.mogo.map.marker.MogoMarkerOptions
|
||||
import com.mogo.map.search.geo.IMogoGeoSearch
|
||||
import com.mogo.map.search.geo.IMogoGeoSearchListener
|
||||
import com.mogo.map.search.geo.MogoGeocodeResult
|
||||
import com.mogo.map.search.geo.MogoRegeocodeResult
|
||||
@@ -20,7 +21,7 @@ import com.mogo.module.navi.bean.EntityConvertUtils
|
||||
import com.mogo.module.navi.bean.SearchPoi
|
||||
import com.mogo.module.navi.constants.AMapConstants
|
||||
import com.mogo.module.navi.constants.DataConstants
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder
|
||||
import com.mogo.module.navi.constants.SearchApisHolder
|
||||
import com.mogo.module.navi.cp.AddressHelper
|
||||
import com.mogo.module.navi.database.AppDataBase
|
||||
import com.mogo.module.navi.manager.AddressManager
|
||||
@@ -37,6 +38,8 @@ import kotlinx.android.synthetic.main.fragment_setting_address.*
|
||||
* 2020-01-07.
|
||||
*/
|
||||
class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
|
||||
|
||||
override fun onRegeocodeSearched(regeocodeResult: MogoRegeocodeResult?) {
|
||||
et_navi_search.setText(regeocodeResult?.regeocodeAddress?.formatAddress)
|
||||
var formatAddress = regeocodeResult?.regeocodeAddress?.formatAddress
|
||||
@@ -58,6 +61,8 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
private var style: Int = DataConstants.TYPE_HOME_ADDRESS
|
||||
var addMarker: IMogoMarker? = null
|
||||
|
||||
private lateinit var mGeoSearch: IMogoGeoSearch
|
||||
|
||||
private var selectPoi: SearchPoi? = null
|
||||
private var mapListener: IMogoMapListener = object : MogoMapListenerAdapter() {
|
||||
override fun onMapChanged(
|
||||
@@ -69,7 +74,7 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
selectPoi = EntityConvertUtils.geoToPoi(latLng?.lat ?: 0.0, latLng?.lng ?: 0.0, style)
|
||||
var mogoRegeocodeQuery = MogoRegeocodeQuery()
|
||||
mogoRegeocodeQuery.point = latLng
|
||||
SearchServiceHolder.getGeoSearcher().getFromLocationAsyn(mogoRegeocodeQuery)
|
||||
mGeoSearch.getFromLocationAsyn(mogoRegeocodeQuery)
|
||||
addMarker?.startJumpAnimation(
|
||||
150f,
|
||||
600,
|
||||
@@ -86,12 +91,13 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
style = arguments?.getInt(AMapConstants.KEY_SET_HOME_COMPONY)
|
||||
?: DataConstants.TYPE_HOME_ADDRESS
|
||||
SearchServiceHolder.listenerCenter.registerMogoMapListener(AMapConstants.PATH_FRAGMENT_SETTING_HOME, mapListener)
|
||||
SearchServiceHolder.getMapUIController().showMyLocation(false)
|
||||
SearchServiceHolder.getGeoSearcher().setGeoSearchListener(this)
|
||||
SearchServiceHolder.getMarkerManger().removeMarkers()
|
||||
style = arguments?.getInt(AMapConstants.KEY_SET_HOME_COMPONY) ?: DataConstants.TYPE_HOME_ADDRESS
|
||||
SearchApisHolder.getRegisterCenterApis().registerMogoMapListener(AMapConstants.PATH_FRAGMENT_SETTING_HOME, mapListener)
|
||||
SearchApisHolder.getUiControllerApis().showMyLocation(false)
|
||||
SearchApisHolder.getMarkerManager().removeMarkers()
|
||||
|
||||
mGeoSearch = SearchApisHolder.getMapServiceApis().getGeoSearch(context)
|
||||
mGeoSearch.setGeoSearchListener(this)
|
||||
}
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
@@ -119,7 +125,7 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
}
|
||||
|
||||
iv_navi_back.setOnClickListener {
|
||||
SearchServiceHolder.fragmentManager.pop()
|
||||
SearchApisHolder.getFragmentManager().pop()
|
||||
}
|
||||
tv_set_as_home.setOnClickListener {
|
||||
if (selectPoi == null) {
|
||||
@@ -127,12 +133,12 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
return@setOnClickListener
|
||||
}
|
||||
insert(selectPoi!!)
|
||||
SearchServiceHolder.fragmentManager.pop()
|
||||
SearchApisHolder.getFragmentManager().pop()
|
||||
}
|
||||
|
||||
et_navi_search.isEnabled = false
|
||||
et_navi_search.setText(getString(string.drag_map_to_choose))
|
||||
var location = SearchServiceHolder.getMapUIController().windowCenterLocation
|
||||
var location = SearchApisHolder.getUiControllerApis().windowCenterLocation
|
||||
|
||||
UiThreadHandler.postDelayed({
|
||||
if (!isAdded) {
|
||||
@@ -145,10 +151,9 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
.owner(TAG)
|
||||
.anchor(0.5f, 1f)
|
||||
.longitude(location?.lng ?: 0.0)
|
||||
addMarker = SearchServiceHolder.getMarkerManger()
|
||||
.addMarker(AMapConstants.PATH_FRAGMENT_SETTING_HOME, options)
|
||||
addMarker = SearchApisHolder.getMarkerManager().addMarker(AMapConstants.PATH_FRAGMENT_SETTING_HOME, options)
|
||||
|
||||
var locationPointInScreen = SearchServiceHolder.getMapUIController().getLocationPointInScreen(location)
|
||||
var locationPointInScreen = SearchApisHolder.getUiControllerApis().getLocationPointInScreen(location)
|
||||
addMarker?.setPositionByPixels(locationPointInScreen)
|
||||
}, 500L)
|
||||
}
|
||||
@@ -169,9 +174,7 @@ class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
SearchServiceHolder.listenerCenter.unregisterMogoMapListener(
|
||||
AMapConstants.PATH_FRAGMENT_SETTING_HOME
|
||||
)
|
||||
SearchApisHolder.getRegisterCenterApis().unregisterMogoMapListener(AMapConstants.PATH_FRAGMENT_SETTING_HOME)
|
||||
addMarker?.destroy()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.NaviActivity"
|
||||
>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fl_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -26,6 +26,7 @@ import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.module.IMogoActionManager;
|
||||
import com.mogo.service.module.IMogoRegisterCenter;
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.carchattingprovider.CallChattingProviderConstant;
|
||||
|
||||
/**
|
||||
@@ -195,11 +196,9 @@ public class MarkerServiceHandler {
|
||||
/**
|
||||
* 对指定类型高亮处理
|
||||
* 建议使用
|
||||
*
|
||||
* @see MapMarkerManager#highlightedMarker(String, boolean)
|
||||
*/
|
||||
@Deprecated
|
||||
public static void highlightedMarker( String typeTag ) {
|
||||
getMapMarkerManager().highlightedMarker( typeTag, false );
|
||||
Logger.w( TAG, "do not invoke this method any more." );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -493,6 +493,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
if ( mStatusManager.isUserInteracted() ) {
|
||||
mLastCustomRefreshCenterLocation = latLng;
|
||||
mLastZoomLevel = zoom;
|
||||
Logger.d( TAG, "user interacted" );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -500,6 +501,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
if ( mStatusManager.isV2XShow() ) {
|
||||
mLastCustomRefreshCenterLocation = latLng;
|
||||
mLastZoomLevel = zoom;
|
||||
Logger.d( TAG, "user v2x show" );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -507,6 +509,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
if ( mStatusManager.isSearchUIShow() ) {
|
||||
mLastCustomRefreshCenterLocation = latLng;
|
||||
mLastZoomLevel = zoom;
|
||||
Logger.d( TAG, "user search Ui show" );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -555,7 +558,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
}
|
||||
float distance = Utils.calculateLineDistance( latLng, mLastCustomRefreshCenterLocation );
|
||||
Logger.d( TAG, "move distance = %s, factor = %s", distance, factor );
|
||||
return distance > factor;
|
||||
return distance > factor / 2;
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "warming. " );
|
||||
return false;
|
||||
@@ -684,8 +687,6 @@ public class MogoServices implements IMogoMapListener,
|
||||
private void onAdasOn() {
|
||||
// ADAS 时,不在自动刷新打点策略
|
||||
stopAutoRefreshStrategy();
|
||||
// 清除所有的打点信息记录
|
||||
MarkerServiceHandler.getMapMarkerManager().alreadySmallMarker.clear();
|
||||
}
|
||||
|
||||
private void onAdasClosed() {
|
||||
|
||||
@@ -9,9 +9,20 @@ import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.search.geo.IMogoGeoSearch;
|
||||
import com.mogo.map.search.geo.IMogoGeoSearchListener;
|
||||
import com.mogo.map.search.geo.MogoGeocodeResult;
|
||||
import com.mogo.map.search.geo.MogoRegeocodeResult;
|
||||
import com.mogo.map.search.geo.query.MogoRegeocodeQuery;
|
||||
import com.mogo.module.common.dialog.WMDialog;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.MogoServiceProvider;
|
||||
import com.mogo.module.service.R;
|
||||
import com.mogo.service.entrance.ButtonIndex;
|
||||
import com.mogo.utils.TipToast;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -71,10 +82,10 @@ public class MockIntentHandler implements IntentHandler {
|
||||
button11.setVisibility( View.VISIBLE );
|
||||
button11.setBackgroundColor( Color.RED );
|
||||
button11.setOnClickListener( view -> {
|
||||
Intent intent1 = new Intent( );
|
||||
Intent intent1 = new Intent();
|
||||
intent1.setAction( Intent.ACTION_VIEW );
|
||||
intent1.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
intent1.setData( Uri.parse("wechathelper://com.zhidao.wechathelper/main/transform?type=navi&lon=116.327007&lat=39.977639&from=os2.0") );
|
||||
intent1.setData( Uri.parse( "wechathelper://com.zhidao.wechathelper/main/transform?type=navi&lon=116.327007&lat=39.977639&from=os2.0" ) );
|
||||
try {
|
||||
view.setOnClickListener( null );
|
||||
view.getContext().startActivity( intent1 );
|
||||
@@ -89,6 +100,37 @@ public class MockIntentHandler implements IntentHandler {
|
||||
float bearing = intent.getFloatExtra( "bearing", 0 );
|
||||
MarkerServiceHandler.getMapUIController().changeBearing( bearing );
|
||||
break;
|
||||
case 9:
|
||||
new WMDialog.Builder( context )
|
||||
.setOkButton( "确认", ( dlg, which ) -> {
|
||||
dlg.dismiss();
|
||||
} )
|
||||
.setCancelButton( "取消", ( dlg, which ) -> {
|
||||
dlg.dismiss();
|
||||
} )
|
||||
.setContent( "内容内容内容内容内容内容内容内容" )
|
||||
.build()
|
||||
.show();
|
||||
break;
|
||||
case 10:
|
||||
IMogoGeoSearch geoSearch = MarkerServiceHandler.getMapService().getGeoSearch( context );
|
||||
geoSearch.setGeoSearchListener( new IMogoGeoSearchListener() {
|
||||
@Override
|
||||
public void onRegeocodeSearched( MogoRegeocodeResult regeocodeResult ) {
|
||||
Logger.d( TAG, GsonUtil.jsonFromObject( regeocodeResult ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGeocodeSearched( MogoGeocodeResult geocodeResult ) {
|
||||
|
||||
}
|
||||
} );
|
||||
MogoRegeocodeQuery query = new MogoRegeocodeQuery();
|
||||
query.setLatlngType( "autonavi" );
|
||||
query.setPoint( new MogoLatLng( intent.getFloatExtra( "lat", 39.917366f ), intent.getFloatExtra( "lon", 116.39962f ) ) );
|
||||
query.setRadius( 1000 );
|
||||
geoSearch.getFromLocationAsyn( query );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
package com.mogo.module.service.marker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.animation.BounceInterpolator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.marker.MogoMarkersHandler;
|
||||
import com.mogo.module.common.ModuleNames;
|
||||
import com.mogo.module.common.entity.MarkerCarPois;
|
||||
import com.mogo.module.common.entity.MarkerCardResult;
|
||||
@@ -30,7 +24,6 @@ import com.mogo.module.service.Utils;
|
||||
import com.mogo.module.service.network.RefreshCallback;
|
||||
import com.mogo.module.service.network.RefreshModel;
|
||||
import com.mogo.module.service.utils.ViewUtils;
|
||||
import com.mogo.service.cardmanager.IMogoCardChangedListener;
|
||||
import com.mogo.service.connection.IMogoOnMessageListener;
|
||||
import com.mogo.service.module.IMogoBizActionDoneListener;
|
||||
import com.mogo.utils.ThreadPoolService;
|
||||
@@ -54,28 +47,18 @@ import java.util.Map;
|
||||
* version: 1.0
|
||||
*/
|
||||
public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
IMogoOnMessageListener< MarkerResponse >, IMogoCardChangedListener,
|
||||
IMogoOnMessageListener< MarkerResponse >,
|
||||
IMogoBizActionDoneListener {
|
||||
private static final String TAG = "MapMarkerManager";
|
||||
// 是否选中在线卡片及气泡,语音搜索触发
|
||||
private boolean mIsAISearchOnlineData = false;
|
||||
|
||||
private Context mContext;
|
||||
// 最后一次选中的气泡
|
||||
private IMogoMarker mLastCheckMarker;
|
||||
private static MapMarkerManager mMarkerManager;
|
||||
|
||||
private String mCurrentModuleName = ServiceConst.CARD_TYPE_BUSINESS_OPERATION;
|
||||
// 记录其它已经缩小的Marker
|
||||
public ArrayList< String > alreadySmallMarker = new ArrayList<>();
|
||||
// 存储所有汽车marker
|
||||
// public ArrayList<IMogoMarker> carMarkers = new ArrayList<>();
|
||||
// 距离用户最近的Marker
|
||||
private IMogoMarker mNearlyMarker = null;
|
||||
// 记录上次请求数据,切换卡片时做数据处理
|
||||
private MarkerCardResult mLastDataResult;
|
||||
|
||||
private boolean mIsMarkerClicked = false;
|
||||
private RefreshModel mRefreshModel;
|
||||
private MogoLatLng mCarLatLng;
|
||||
// 平滑移动事件间隔(单位:秒)
|
||||
@@ -105,7 +88,6 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
|
||||
// 长连接
|
||||
MarkerServiceHandler.getMogoSocketManager().registerOnMessageListener( 401001, this );
|
||||
MarkerServiceHandler.getMogoCardManager().registerCardChangedListener( TAG, this );
|
||||
MarkerServiceHandler.getActionManager().registerBizActionDoneListener( this );
|
||||
}
|
||||
|
||||
@@ -115,30 +97,11 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
Logger.e( TAG, "do not invoke anymore." );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitched( int position, String moduleName ) {
|
||||
Logger.d( TAG, "当前C位卡片:" + moduleName );
|
||||
if ( ( TextUtils.isEmpty( mCurrentModuleName ) || TextUtils.equals( mCurrentModuleName,
|
||||
ServiceConst.CARD_TYPE_BUSINESS_OPERATION ) ) && mIsMarkerClicked ) {
|
||||
mIsMarkerClicked = false;
|
||||
// 在广告位(默认位置)点击marker造成卡片切换的,还是现实全部marker 【需求:os2.0.2-2.5-4】
|
||||
highlightedMarker( moduleName, false );
|
||||
mCurrentModuleName = moduleName;
|
||||
} else {
|
||||
mCurrentModuleName = moduleName;
|
||||
runOnTargetThread( () -> {
|
||||
MarkerServiceHandler.getMarkerManager().removeMarkersExcept( ModuleNames.CARD_TYPE_USER_DATA );
|
||||
drawMarkerByCurrentType( mLastDataResult );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 地图上的Marker点击回调
|
||||
*/
|
||||
@Override
|
||||
public boolean onMarkerClicked( IMogoMarker marker ) {
|
||||
mIsMarkerClicked = true;
|
||||
Logger.d( TAG, "onMarkerClicked 点击了大而全中的Marker:" + marker );
|
||||
try {
|
||||
boolean result = switchMarkerOpenStatus( marker );
|
||||
@@ -173,90 +136,6 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// 对指定类型高亮处理
|
||||
public synchronized void highlightedMarker( final String typeTag ) {
|
||||
highlightedMarker( typeTag, false );
|
||||
}
|
||||
|
||||
public synchronized void highlightedMarker( final String typeTag, final boolean netDataRefresh ) {
|
||||
try {
|
||||
Logger.e( TAG, "上一次选中的卡片类型:mCurrentModuleName==" + mCurrentModuleName );
|
||||
if ( !TextUtils.isEmpty( mCurrentModuleName ) && TextUtils.equals( mCurrentModuleName,
|
||||
typeTag ) && !netDataRefresh ) {
|
||||
return;
|
||||
}
|
||||
// 从已经缩小的记录删除
|
||||
alreadySmallMarker.remove( typeTag );
|
||||
List< IMogoMarker > currentHighLightList =
|
||||
MarkerServiceHandler.getMarkerManager().getMarkers( typeTag );
|
||||
|
||||
if ( currentHighLightList == null || currentHighLightList.size() == 0 ) {
|
||||
alreadySmallMarker.clear();
|
||||
// 放大所有的气泡
|
||||
Map< String, List< IMogoMarker > > lastHighLightList =
|
||||
MarkerServiceHandler.getMarkerManager().getAllMarkers();
|
||||
for ( String markerName : lastHighLightList.keySet() ) {
|
||||
setMarkersBig( lastHighLightList.get( markerName ) );
|
||||
}
|
||||
} else {
|
||||
// 缩小其他的气泡
|
||||
Map< String, List< IMogoMarker > > lastHighLightList =
|
||||
MarkerServiceHandler.getMarkerManager().getAllMarkers();
|
||||
for ( String markerName : lastHighLightList.keySet() ) {
|
||||
if ( !markerName.equals( typeTag ) ) {
|
||||
if ( !alreadySmallMarker.contains( markerName ) ) {
|
||||
alreadySmallMarker.add( markerName );
|
||||
setMarkersSmall( lastHighLightList.get( markerName ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将当前卡片选中的气泡放大
|
||||
setMarkersBig( currentHighLightList );
|
||||
}
|
||||
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void setMarkersBig( List< IMogoMarker > markers ) {
|
||||
if ( markers == null || markers.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
for ( IMogoMarker mogoMarker : markers ) {
|
||||
if ( mogoMarker == null || mogoMarker.isDestroyed() ) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
mogoMarker.startScaleAnimation( 0.6f, 1f, 0.6f, 1f, 1000, new BounceInterpolator() );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setMarkersSmall( List< IMogoMarker > markers ) {
|
||||
if ( markers == null || markers.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
for ( IMogoMarker mogoMarker : markers ) {
|
||||
smallMarker( mogoMarker );
|
||||
}
|
||||
}
|
||||
|
||||
private static void smallMarker( IMogoMarker mogoMarker ) {
|
||||
if ( mogoMarker == null || mogoMarker.isDestroyed() ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
mogoMarker.startScaleAnimation( 1f, 0.6f, 1f, 0.6f, 300, new OvershootInterpolator() );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
|
||||
// 展开气泡
|
||||
private void openMarker( IMogoMarker mogoMarker ) {
|
||||
if ( mogoMarker == null ) {
|
||||
@@ -339,21 +218,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
dispatchDataToBiz();
|
||||
} );
|
||||
|
||||
// 语音触发的在线车辆搜索,采用增量的形式绘制
|
||||
if ( mIsAISearchOnlineData = isOnlineCarDataOnly( mLastDataResult ) ) {
|
||||
MarkerServiceHandler.getMarkerManager().removeMarkers( ServiceConst.CARD_TYPE_USER_DATA );
|
||||
MarkerServiceHandler.getMogoCardManager().switch2( ServiceConst.CARD_TYPE_USER_DATA );
|
||||
} else {
|
||||
mLastCheckMarker = null;
|
||||
// 清空所有地图上绘制的Marker
|
||||
MarkerServiceHandler.getMarkerManager().removeMarkersExcept( ModuleNames.CARD_TYPE_USER_DATA );
|
||||
}
|
||||
|
||||
drawMarkerByCurrentType( mLastDataResult );
|
||||
// 同步新绘制的气泡状态
|
||||
alreadySmallMarker.clear();
|
||||
// highlightedMarker( mCurrentModuleName, true );
|
||||
|
||||
trackData( mLastDataResult );
|
||||
}
|
||||
|
||||
@@ -385,11 +250,6 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
return;
|
||||
}
|
||||
|
||||
if ( TextUtils.isEmpty( mCurrentModuleName ) ) {
|
||||
// 默认大而全
|
||||
mCurrentModuleName = ServiceConst.CARD_TYPE_BUSINESS_OPERATION;
|
||||
}
|
||||
|
||||
drawAllMarker( markerCardResult );
|
||||
}
|
||||
|
||||
@@ -399,14 +259,12 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
* @param markerCardResult
|
||||
*/
|
||||
private void drawAllMarker( MarkerCardResult markerCardResult ) {
|
||||
// List<MarkerOnlineCar> onlineCarList = markerCardResult.getOnlineCar();
|
||||
List< MarkerExploreWay > exploreWayList = markerCardResult.getExploreWay();
|
||||
List< MarkerShareMusic > shareMusicList = markerCardResult.getShareMusic();
|
||||
// List< MarkerShareMusic > shareMusicList = markerCardResult.getShareMusic();
|
||||
List< MarkerNoveltyInfo > noveltyInfoList = markerCardResult.getNoveltyInfo();
|
||||
|
||||
// drawOnlineCarMarkers(onlineCarList, ServiceConst.MAX_AMOUNT_ALL);
|
||||
drawRoadConditionMarker( exploreWayList, ServiceConst.MAX_AMOUNT_ALL );
|
||||
drawShareMusicMarker( shareMusicList, ServiceConst.MAX_AMOUNT_ALL );
|
||||
// drawShareMusicMarker( shareMusicList, ServiceConst.MAX_AMOUNT_ALL );
|
||||
drawNoveltyMarker( noveltyInfoList, ServiceConst.MAX_AMOUNT_ALL );
|
||||
}
|
||||
|
||||
@@ -421,10 +279,9 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
return;
|
||||
}
|
||||
|
||||
double nearlyDistance = Float.MAX_VALUE;
|
||||
int size = getAppropriateSize( maxAmount, onlineCarList );
|
||||
|
||||
Map< String, IMogoMarker > existCarMap = purgeCarsData( onlineCarList );
|
||||
Map< String, IMogoMarker > existCarMap = purgeMarkerData( onlineCarList, ModuleNames.CARD_TYPE_USER_DATA );
|
||||
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
MarkerOnlineCar markerOnlineCar = onlineCarList.get( i );
|
||||
@@ -439,119 +296,13 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
markerShowEntity.setIconUrl( markerOnlineCar.getUserInfo().getUserHead() );
|
||||
}
|
||||
|
||||
if ( markerOnlineCar.getUserInfo() == null || TextUtils.isEmpty( markerOnlineCar.getUserInfo().getSn() ) ) {
|
||||
continue;
|
||||
}
|
||||
IMogoMarker mogoMarker = existCarMap.get( markerOnlineCar.getUserInfo().getSn() );
|
||||
String sn = getCarSnFromEntity( markerOnlineCar );
|
||||
IMogoMarker mogoMarker = existCarMap.get( sn );
|
||||
if ( mogoMarker == null ) {
|
||||
Logger.d( TAG, "car [%s] need be create.", markerOnlineCar.getUserInfo().getSn() );
|
||||
mogoMarker = drawMapMarker( markerShowEntity );
|
||||
}
|
||||
startSmooth( mogoMarker, markerOnlineCar, markerLocation );
|
||||
|
||||
// 计算在线车辆距离当前车辆的距离,每次都与最后一次距离最近的进行比较,保留距离最近的车辆,进行卡片展示
|
||||
try {
|
||||
// 当前车辆的位置
|
||||
MogoLocation currentLocation = MarkerServiceHandler.getMogoLocationClient().getLastKnowLocation();
|
||||
|
||||
// 计算车辆距离指定气泡的距离
|
||||
float calculateDistance =
|
||||
Utils.calculateLineDistance( new MogoLatLng( markerLocation.getLat(),
|
||||
markerLocation.getLon() ),
|
||||
new MogoLatLng( currentLocation.getLatitude(),
|
||||
currentLocation.getLongitude() ) );
|
||||
|
||||
// 进行比较,保留最近的一个数据
|
||||
if ( calculateDistance < nearlyDistance ) {
|
||||
nearlyDistance = calculateDistance;
|
||||
mNearlyMarker = mogoMarker;
|
||||
}
|
||||
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Logger.d( TAG, "距离当前车辆位置最近的距离为:" + nearlyDistance );
|
||||
|
||||
try {
|
||||
// 在ACC on 之后第一次获取到了在线车辆数据,选中最近的一个Marker
|
||||
if ( !mIsAISearchOnlineData ) {
|
||||
return;
|
||||
}
|
||||
if ( mNearlyMarker == null ) {
|
||||
return;
|
||||
}
|
||||
Logger.d( TAG, "语音搜索触发,默认选中最近的在线车辆:" + mNearlyMarker );
|
||||
// 移动地图到指定位置
|
||||
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus( ServiceConst.TYPE, true, false );
|
||||
MarkerServiceHandler.getMapUIController().moveToCenter( mNearlyMarker.getPosition() );
|
||||
onMarkerClicked( mNearlyMarker );
|
||||
MogoMarkersHandler.getInstance().onMarkerClicked( mNearlyMarker );
|
||||
mIsAISearchOnlineData = false;
|
||||
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据新的在线车辆列表,选出已存在的在线车辆,并从视图和内存中移除不存在的在线车辆
|
||||
*
|
||||
* @param newCarsList
|
||||
* @return
|
||||
*/
|
||||
private Map< String, IMogoMarker > purgeCarsData( List< MarkerOnlineCar > newCarsList ) {
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
Map< String, IMogoMarker > existCarsMap = new HashMap<>();
|
||||
List< IMogoMarker > allCarsList = MarkerServiceHandler.getMarkerManager().getMarkers( ModuleNames.CARD_TYPE_USER_DATA );
|
||||
if ( allCarsList == null || allCarsList.isEmpty() ) {
|
||||
return existCarsMap;
|
||||
}
|
||||
if ( newCarsList == null || newCarsList.isEmpty() ) {
|
||||
return existCarsMap;
|
||||
}
|
||||
|
||||
Map< String, IMogoMarker > allCarsMap = new HashMap<>();
|
||||
for ( IMogoMarker marker : allCarsList ) {
|
||||
String sn = getCarSnFromMarker( marker );
|
||||
Logger.d( TAG, "sn = [%s]", sn );
|
||||
allCarsMap.put( sn, marker );
|
||||
}
|
||||
for ( MarkerOnlineCar markerOnlineCar : newCarsList ) {
|
||||
String sn = markerOnlineCar.getUserInfo().getSn();
|
||||
if ( allCarsMap.containsKey( sn ) ) {
|
||||
Logger.d( TAG, " car [%s] is cached.", sn );
|
||||
existCarsMap.put( sn, allCarsMap.get( sn ) );
|
||||
}
|
||||
}
|
||||
for ( String sn : allCarsMap.keySet() ) {
|
||||
if ( !existCarsMap.containsKey( sn ) ) {
|
||||
IMogoMarker dirtyMarker = allCarsMap.get( sn );
|
||||
allCarsList.remove( dirtyMarker );
|
||||
dirtyMarker.destroy();
|
||||
Logger.d( TAG, " car [%s] is destroy.", sn );
|
||||
}
|
||||
}
|
||||
allCarsMap.clear();
|
||||
Logger.i( "timer", "purge data cost " + ( System.currentTimeMillis() - start ) + "ms" );
|
||||
return existCarsMap;
|
||||
}
|
||||
|
||||
private String getCarSnFromMarker( IMogoMarker marker ) {
|
||||
if ( marker == null || marker.getObject() == null || marker.isDestroyed() ) {
|
||||
return null;
|
||||
}
|
||||
if ( !( marker.getObject() instanceof MarkerShowEntity ) ) {
|
||||
return null;
|
||||
}
|
||||
if ( !( ( ( MarkerShowEntity ) marker.getObject() ).getBindObj() instanceof MarkerOnlineCar ) ) {
|
||||
return null;
|
||||
}
|
||||
if ( ( ( MarkerOnlineCar ) ( ( MarkerShowEntity ) marker.getObject() ).getBindObj() ).getUserInfo() == null ) {
|
||||
return null;
|
||||
}
|
||||
return ( ( MarkerOnlineCar ) ( ( MarkerShowEntity ) marker.getObject() ).getBindObj() ).getUserInfo().getSn();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -562,9 +313,11 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
private void drawRoadConditionMarker( List< MarkerExploreWay > exploreWayList, int maxAmount ) {
|
||||
// 将数据同步给探路,避免探路每次 perform 的时候去拉取,造成消耗
|
||||
if ( exploreWayList == null || exploreWayList.isEmpty() ) {
|
||||
MarkerServiceHandler.getMarkerManager().removeMarkers( ModuleNames.CARD_TYPE_ROAD_CONDITION );
|
||||
return;
|
||||
}
|
||||
int size = getAppropriateSize( maxAmount, exploreWayList );
|
||||
Map< String, IMogoMarker > existCarMap = purgeMarkerData( exploreWayList, ModuleNames.CARD_TYPE_ROAD_CONDITION );
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
MarkerExploreWay markerExploreWay = exploreWayList.get( i );
|
||||
if ( !markerExploreWay.getCanLive() ) {
|
||||
@@ -576,21 +329,28 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
markerShowEntity.setMarkerType( markerExploreWay.getType() );
|
||||
markerShowEntity.setTextContent( markerExploreWay.getAddr() );
|
||||
|
||||
drawMapMarker( markerShowEntity );
|
||||
String sn = getCarSnFromEntity( markerExploreWay );
|
||||
IMogoMarker mogoMarker = existCarMap.get( sn );
|
||||
if ( mogoMarker == null ) {
|
||||
drawMapMarker( markerShowEntity );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 共享音乐
|
||||
*
|
||||
* @param shareMusicList
|
||||
*/
|
||||
private void drawShareMusicMarker( List< MarkerShareMusic > shareMusicList, int maxAmount ) {
|
||||
if ( shareMusicList == null ) {
|
||||
if ( shareMusicList == null || shareMusicList.isEmpty() ) {
|
||||
MarkerServiceHandler.getMarkerManager().removeMarkers( ModuleNames.CARD_TYPE_SHARE_MUSIC );
|
||||
return;
|
||||
}
|
||||
int size = getAppropriateSize( maxAmount, shareMusicList );
|
||||
Map< String, IMogoMarker > existCarMap = purgeMarkerData( shareMusicList, ModuleNames.CARD_TYPE_SHARE_MUSIC );
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
MarkerShareMusic markerShareMusic = shareMusicList.get( i );
|
||||
MarkerLocation markerLocation = markerShareMusic.getLocation();
|
||||
@@ -601,7 +361,11 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
markerShowEntity.setTextContent( markerShareMusic.getMediaName() );
|
||||
markerShowEntity.setIconUrl( markerShareMusic.getMediaImg() );
|
||||
|
||||
drawMapMarker( markerShowEntity );
|
||||
String sn = getCarSnFromEntity( markerShareMusic );
|
||||
IMogoMarker mogoMarker = existCarMap.get( sn );
|
||||
if ( mogoMarker == null ) {
|
||||
drawMapMarker( markerShowEntity );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -611,10 +375,12 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
* @param noveltyInfoList
|
||||
*/
|
||||
private void drawNoveltyMarker( List< MarkerNoveltyInfo > noveltyInfoList, int maxAmount ) {
|
||||
if ( noveltyInfoList == null ) {
|
||||
if ( noveltyInfoList == null || noveltyInfoList.isEmpty() ) {
|
||||
MarkerServiceHandler.getMarkerManager().removeMarkers( ModuleNames.CARD_TYPE_NOVELTY );
|
||||
return;
|
||||
}
|
||||
int size = getAppropriateSize( maxAmount, noveltyInfoList );
|
||||
Map< String, IMogoMarker > existCarMap = purgeMarkerData( noveltyInfoList, ModuleNames.CARD_TYPE_NOVELTY );
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
MarkerNoveltyInfo noveltyInfo = noveltyInfoList.get( i );
|
||||
MarkerLocation markerLocation = noveltyInfo.getLocation();
|
||||
@@ -628,10 +394,83 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
} else {
|
||||
markerShowEntity.setTextContent( noveltyInfo.getContentData().getTitle() );
|
||||
}
|
||||
drawMapMarker( markerShowEntity );
|
||||
String sn = getCarSnFromEntity( noveltyInfo );
|
||||
IMogoMarker mogoMarker = existCarMap.get( sn );
|
||||
if ( mogoMarker == null ) {
|
||||
drawMapMarker( markerShowEntity );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* S = (A ∩ B) ∪ B
|
||||
* (A ∩ B)作为旧列表需要保留的部分
|
||||
*
|
||||
* @param newList
|
||||
* @return
|
||||
*/
|
||||
private Map< String, IMogoMarker > purgeMarkerData( List newList, String markerType ) {
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
Map< String, IMogoMarker > existMap = new HashMap<>();
|
||||
List< IMogoMarker > allCarsList = MarkerServiceHandler.getMarkerManager().getMarkers( markerType );
|
||||
if ( allCarsList == null || allCarsList.isEmpty() ) {
|
||||
return existMap;
|
||||
}
|
||||
if ( newList == null || newList.isEmpty() ) {
|
||||
return existMap;
|
||||
}
|
||||
|
||||
Map< String, IMogoMarker > allMap = new HashMap<>();
|
||||
for ( IMogoMarker marker : allCarsList ) {
|
||||
String sn = getCarSnFromMarker( marker );
|
||||
allMap.put( sn, marker );
|
||||
}
|
||||
for ( Object entity : newList ) {
|
||||
String sn = getCarSnFromEntity( entity );
|
||||
if ( allMap.containsKey( sn ) ) {
|
||||
existMap.put( sn, allMap.get( sn ) );
|
||||
}
|
||||
}
|
||||
for ( String sn : allMap.keySet() ) {
|
||||
if ( !existMap.containsKey( sn ) ) {
|
||||
IMogoMarker dirtyMarker = allMap.get( sn );
|
||||
allCarsList.remove( dirtyMarker );
|
||||
dirtyMarker.destroy();
|
||||
}
|
||||
}
|
||||
allMap.clear();
|
||||
Logger.i( "timer", "purge data cost " + ( System.currentTimeMillis() - start ) + "ms" );
|
||||
return existMap;
|
||||
}
|
||||
|
||||
private String getCarSnFromEntity( Object entity ) {
|
||||
try {
|
||||
if ( entity instanceof MarkerOnlineCar ) {
|
||||
return ( ( MarkerOnlineCar ) entity ).getUserInfo().getSn();
|
||||
} else if ( entity instanceof MarkerShareMusic ) {
|
||||
return ( ( MarkerShareMusic ) entity ).getUserInfo().getSn();
|
||||
} else if ( entity instanceof MarkerNoveltyInfo ) {
|
||||
return ( ( MarkerNoveltyInfo ) entity ).getSn();
|
||||
} else if ( entity instanceof MarkerExploreWay ) {
|
||||
return ( ( MarkerExploreWay ) entity ).getUserInfo().getSn();
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getCarSnFromMarker( IMogoMarker marker ) {
|
||||
if ( marker == null || marker.getObject() == null || marker.isDestroyed() ) {
|
||||
return null;
|
||||
}
|
||||
if ( !( marker.getObject() instanceof MarkerShowEntity ) ) {
|
||||
return null;
|
||||
}
|
||||
return getCarSnFromEntity( ( ( MarkerShowEntity ) marker.getObject() ).getBindObj() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxAmount 展示的最大数量
|
||||
* @param list
|
||||
@@ -811,18 +650,14 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
*/
|
||||
public synchronized IMogoMarker drawMapMarker( MarkerShowEntity markerShowEntity ) {
|
||||
try {
|
||||
return drawMapMarker( markerShowEntity, isSmallType() );
|
||||
return drawMapMarkerImpl( markerShowEntity );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSmallType() {
|
||||
return !TextUtils.isEmpty( mCurrentModuleName ) && mLastCheckMarker != null && !mLastCheckMarker.isDestroyed() && TextUtils.equals( mCurrentModuleName, mLastCheckMarker.getOwner() );
|
||||
}
|
||||
|
||||
private IMogoMarker drawMapMarker( MarkerShowEntity markerShowEntity, boolean isSmall ) {
|
||||
private IMogoMarker drawMapMarkerImpl( MarkerShowEntity markerShowEntity ) {
|
||||
if ( markerShowEntity == null || markerShowEntity.getMarkerLocation() == null ) {
|
||||
return null;
|
||||
}
|
||||
@@ -843,12 +678,6 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
marker.setOwner( markerShowEntity.getMarkerType() );
|
||||
markerView.setMarker( marker );
|
||||
marker.setOnMarkerClickListener( this );
|
||||
|
||||
if ( isSmall ) {
|
||||
List< IMogoMarker > markers = new ArrayList<>();
|
||||
markers.add( marker );
|
||||
setMarkersSmall( markers );
|
||||
}
|
||||
markerShowEntity.setMarker( marker );
|
||||
return marker;
|
||||
}
|
||||
@@ -906,9 +735,6 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
}
|
||||
|
||||
List< MarkerOnlineCar > onlineCarList = result.getOnlineCar();
|
||||
if ( !MarkerServiceHandler.getMogoStatusManager().isADASShow() ) {
|
||||
dispatchDataToBis( ServiceConst.CARD_TYPE_USER_DATA, onlineCarList == null ? new ArrayList<>() : onlineCarList );
|
||||
}
|
||||
if ( MarkerServiceHandler.getMogoStatusManager().isSearchUIShow() ) {
|
||||
return;
|
||||
}
|
||||
@@ -933,15 +759,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
if ( MarkerServiceHandler.getMogoStatusManager().isSearchUIShow() ) {
|
||||
return true;
|
||||
}
|
||||
if ( MarkerServiceHandler.getMogoStatusManager().isADASShow() ) {
|
||||
return false;
|
||||
}
|
||||
if ( TextUtils.equals( ServiceConst.CARD_TYPE_USER_DATA, mCurrentModuleName )
|
||||
|| TextUtils.equals( ServiceConst.CARD_TYPE_BUSINESS_OPERATION, mCurrentModuleName )
|
||||
|| TextUtils.equals( ServiceConst.CARD_TYPE_CARS_CHATTING, mCurrentModuleName ) ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void removeCarMarkers() {
|
||||
@@ -1016,7 +834,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
}
|
||||
|
||||
public String getCurrentModuleName() {
|
||||
return mCurrentModuleName;
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -160,9 +160,11 @@ public interface IMogoServiceApis extends IProvider {
|
||||
|
||||
/**
|
||||
* 地址操作
|
||||
* Deprecated, use {@link IMogoSearchManager} instead.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
IMogoAddressManager getAddressManagerApi();
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,7 @@ public interface IMogoMapService extends IProvider {
|
||||
* @param context
|
||||
* @return 定位实例
|
||||
*/
|
||||
@Deprecated
|
||||
IMogoLocationClient getLocationClient( Context context );
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,22 +6,28 @@ import com.mogo.map.MogoLatLng;
|
||||
/**
|
||||
* @author zyz
|
||||
* 2020-01-12.
|
||||
* <p>
|
||||
* Deprecated, use {@link IMogoSearchManager} instead."
|
||||
*/
|
||||
@Deprecated
|
||||
public interface IMogoAddressManager extends IProvider {
|
||||
|
||||
/**
|
||||
* 回家
|
||||
*/
|
||||
@Deprecated
|
||||
void goHome();
|
||||
|
||||
/**
|
||||
* 去公司
|
||||
*/
|
||||
@Deprecated
|
||||
void goCompany();
|
||||
|
||||
/**
|
||||
* 打开搜索
|
||||
*/
|
||||
@Deprecated
|
||||
void goSearch();
|
||||
|
||||
/**
|
||||
@@ -29,12 +35,15 @@ public interface IMogoAddressManager extends IProvider {
|
||||
*
|
||||
* @param destination 目的地
|
||||
*/
|
||||
@Deprecated
|
||||
void calculatePath( MogoLatLng destination );
|
||||
|
||||
/**
|
||||
* 分类搜索
|
||||
*/
|
||||
void categorySearch(String category);
|
||||
@Deprecated
|
||||
void categorySearch( String category );
|
||||
|
||||
@Deprecated
|
||||
void goSettings();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mogo.service.module;
|
||||
|
||||
import com.alibaba.android.arouter.facade.template.IProvider;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
|
||||
/**
|
||||
* @author zyz
|
||||
@@ -8,11 +9,35 @@ import com.alibaba.android.arouter.facade.template.IProvider;
|
||||
*/
|
||||
public interface IMogoSearchManager extends IProvider {
|
||||
|
||||
/**
|
||||
* 回家
|
||||
*/
|
||||
void goHome();
|
||||
|
||||
/**
|
||||
* 去公司
|
||||
*/
|
||||
void goCompany();
|
||||
|
||||
/**
|
||||
* 打开搜索
|
||||
*/
|
||||
void showSearch();
|
||||
void showMain();
|
||||
void speakDraft();
|
||||
void speakDetail();
|
||||
void showCategory(String keyword);
|
||||
|
||||
/**
|
||||
* 规划路线
|
||||
*
|
||||
* @param destination 目的地
|
||||
*/
|
||||
void calculatePath( MogoLatLng destination );
|
||||
|
||||
/**
|
||||
* 分类搜索
|
||||
*/
|
||||
void categorySearch( String keyword );
|
||||
|
||||
/**
|
||||
* 打开导航设置
|
||||
*/
|
||||
void goSettings();
|
||||
}
|
||||
|
||||
@@ -8,8 +8,51 @@ import com.alibaba.android.arouter.facade.template.IProvider;
|
||||
*/
|
||||
public interface IMogoSettingManager extends IProvider {
|
||||
|
||||
/**
|
||||
* 路线偏好
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int getPathPrefer();
|
||||
|
||||
/**
|
||||
* 音量
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int getVolume();
|
||||
|
||||
/**
|
||||
* 获取播报模式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int getVoiceStyle();
|
||||
|
||||
/**
|
||||
* 日夜墨水
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int getMapType();
|
||||
|
||||
/**
|
||||
* 简洁播报
|
||||
*/
|
||||
void speakDraft();
|
||||
|
||||
/**
|
||||
* 详细播报
|
||||
*/
|
||||
void speakDetail();
|
||||
|
||||
/**
|
||||
* 打开巡航模式
|
||||
*/
|
||||
void openAimlessMode();
|
||||
|
||||
/**
|
||||
* 关闭巡航模式
|
||||
*/
|
||||
void closeAimlessMode();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user