优化卡片滑动性能:探路视频播放、C位事件逻辑;定制化app列表;修改小智动画策略;其他优化;

This commit is contained in:
wangcongtao
2020-02-12 17:57:53 +08:00
parent c6a258e9c6
commit 62614236b2
17 changed files with 563 additions and 163 deletions

View File

@@ -4,8 +4,13 @@ import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import com.mogo.module.apps.model.AppEnum;
import com.mogo.module.apps.model.AppEnumHelper;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author congtaowang
@@ -18,6 +23,7 @@ public class AppFilterImpl implements AppFilter {
private final Context mContext;
private List< String > mFilterPackages;
public AppFilterImpl( Context context ) {
mContext = context;
final String[] values = context.getResources().getStringArray( R.array.module_apps_array_filter_packages );
@@ -37,6 +43,9 @@ public class AppFilterImpl implements AppFilter {
if ( noLaunchIntent( packageInfo ) ) {
return true;
}
if ( !AppEnumHelper.isCustomizedApp( packageInfo.packageName ) ) {
return true;
}
return false;
}

View File

@@ -56,7 +56,11 @@ public class AppsAdapter extends BaseAdapter {
holder = ( ( AppViewHolder ) convertView.getTag() );
}
AppInfo appInfo = getItem( position );
holder.mIcon.setImageDrawable( appInfo.getIcon() );
if ( appInfo.getIconResId() <= 0 ) {
holder.mIcon.setImageDrawable( appInfo.getIcon() );
} else {
holder.mIcon.setImageResource( appInfo.getIconResId() );
}
holder.mName.setText( appInfo.getName() );
return holder.mItemView;
}

View File

@@ -15,6 +15,7 @@ import com.mogo.service.analytics.IMogoAnalytics;
import com.mogo.service.cardmanager.IMogoCardManager;
import com.mogo.utils.ThreadPoolService;
import com.mogo.utils.UiThreadHandler;
import com.mogo.utils.logger.Logger;
import java.util.HashMap;
import java.util.Map;
@@ -58,6 +59,8 @@ public class AppsPresenter extends Presenter< AppsView > {
private void renderAppsList() {
ThreadPoolService.execute( () -> {
AppsModel.getInstance( getContext() ).load( appInfoList -> {
Logger.d( TAG, "apps: %s", appInfoList );
UiThreadHandler.post( () -> {
if ( mView != null ) {
mView.renderApps( appInfoList );

View File

@@ -0,0 +1,90 @@
package com.mogo.module.apps.model;
/**
* @author congtaowang
* @since 2020-02-12
* <p>
* 定制化的 app 列表
* <p>
* <p>
* 自研类QQ音乐、车聊聊、探路、新鲜事、福利、蘑菇小队、行车记录仪、懒人听书、一键清理、系统升级
* 第三方:车机微信助手、爱奇艺、喜马拉雅
* 基础类均衡器、方控学习、蓝牙、FM、车载设置、AUX
*/
public enum AppEnum {
//"QQ音乐",
QQMusic( "com.pvetec.musics", 0 ),
//"车聊聊",
Im( "com.zhidao.imdemo", 0 ),
//"探路",
RoadCondition( "com.zhidao.roadcondition", 0 ),
RoadConditionSlit( "com.zhidao.roadcondition.split", 0 ),
//"福利",
Welfare( "com.zhidaohulian.welfare.car", 0 ),
//"蘑菇小队",
Fleet( "com.zhidao.fleet", 0 ),
//"行车记录仪",
CarCorder( "com.zhidao.carcorder", 0 ),
//"懒人听书",
Lrts( "com.zhidao.lrts", 0 ),
//"一键清理",
CleanMaster( "com.zhidao.cleanmaster", 0 ),
//"系统升级",
Fota( "com.abupdate.fota_demo_iot", 0 ),
//"微信车机助手",
WecahtHelper( "com.zhidao.wechathelper", 0 ),
//"爱奇艺HD",
Qiyi( "com.qiyi.video.pad", 0 ),
//"喜马拉雅",
Ximalaya( "com.ximalaya.ting.android.car", 0 ),
//"均衡器",
Equlizer( "com.zhidao.equalizer", 0 ),
//"方控学习",
SteerProduct( "com.zd.steerproduct", 0 ),
//"蓝牙音乐",
BTMusic( "com.nwd.bt.music", 0 ),
//"车载设置",
CarSettings( "com.zhidao.settings", 0 ),
//"AUX",
AUX( "com.nwd.auxin", 0 ),
//FM
FM( " com.nwd.radio", 0 ),
// 新鲜事
FreshThins( "com.zhidao.fresh.things", 0 ),
;
private String mPkg;
private int mIconResId;
AppEnum( String pkg, int iconResId ) {
this.mPkg = pkg;
this.mIconResId = iconResId;
}
public String getPkg() {
return mPkg;
}
public int getIconResId() {
return mIconResId;
}
}

View File

@@ -0,0 +1,34 @@
package com.mogo.module.apps.model;
import java.util.HashMap;
import java.util.Map;
/**
* @author congtaowang
* @since 2020-02-12
* <p>
* 定制化的app
*/
public class AppEnumHelper {
private static Map< String, AppEnum > sCustomizedApps = new HashMap<>();
static {
AppEnum[] customizedApps = AppEnum.values();
for ( AppEnum customizedApp : customizedApps ) {
sCustomizedApps.put( customizedApp.getPkg(), customizedApp );
}
}
public static boolean isCustomizedApp( String pkg ) {
return sCustomizedApps.containsKey( pkg );
}
public static int getCustomizedAppIconResId( String pkg ) {
AppEnum appEnum = sCustomizedApps.get( pkg );
if ( appEnum != null ) {
return appEnum.getIconResId();
}
return 0;
}
}

View File

@@ -15,13 +15,19 @@ public class AppInfo {
private final String mVersionName;
private final int mVersionCode;
private final Drawable mIcon;
private final int mIconResId;
public AppInfo( String name, String mPackageName, String mVersionName, int versionCode, Drawable icon ) {
this.mName = name;
public AppInfo( String mName, String mPackageName, String mVersionName, int mVersionCode, Drawable mIcon, int mIconResId ) {
this.mName = mName;
this.mPackageName = mPackageName;
this.mVersionName = mVersionName;
this.mVersionCode = versionCode;
this.mIcon = icon;
this.mVersionCode = mVersionCode;
this.mIcon = mIcon;
this.mIconResId = mIconResId;
}
public int getIconResId() {
return mIconResId;
}
public String getName() {

View File

@@ -79,7 +79,7 @@ public class AppsModel {
String versionName = packageInfo.versionName;
int versionCode = packageInfo.versionCode;
Drawable appIcon = packageInfo.applicationInfo.loadIcon( packageManager );
AppInfo appInfo = new AppInfo( appName, packageName, versionName, versionCode, appIcon );
AppInfo appInfo = new AppInfo( appName, packageName, versionName, versionCode, appIcon, AppEnumHelper.getCustomizedAppIconResId( packageName ) );
mPagedApps.get( page ).add( appInfo );
}
if ( callback != null ) {
@@ -106,7 +106,7 @@ public class AppsModel {
String versionName = packageInfo.versionName;
int versionCode = packageInfo.versionCode;
Drawable appIcon = packageInfo.applicationInfo.loadIcon( packageManager );
AppInfo appInfo = new AppInfo( appName, packageName, versionName, versionCode, appIcon );
AppInfo appInfo = new AppInfo( appName, packageName, versionName, versionCode, appIcon, AppEnumHelper.getCustomizedAppIconResId( packageName ) );
int pageIndex = getPageIndex( packageName, true );
if ( !mPagedApps.containsKey( pageIndex ) ) {
mPagedApps.put( pageIndex, new ArrayList<>() );

View File

@@ -1,17 +0,0 @@
package com.mogo.module.apps.model;
/**
* @author congtaowang
* @since 2020-02-09
* <p>
* 描述
*/
public class CardAppInfo extends AppInfo {
private String mCardType;
public CardAppInfo( AppInfo app, String cardType ) {
super( app.getName(), app.getPackageName(), app.getVersionName(), app.getVersionCode(), app.getIcon() );
this.mCardType = cardType;
}
}

View File

@@ -1,5 +1,6 @@
package com.mogo.module.extensions;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
@@ -30,7 +31,8 @@ public class ExtensionsFragment extends MvpFragment< ExtensionsView, ExtensionsP
private static final String TAG = "ExtensionsFragment";
private JSurfaceView mVoiceIcon;
private ImageView mVoiceIcon;
private AnimationDrawable mAnim;
private TextView mVoiceMsg;
private TextView mTime;
@@ -55,6 +57,7 @@ public class ExtensionsFragment extends MvpFragment< ExtensionsView, ExtensionsP
@Override
protected void initViews() {
mVoiceIcon = findViewById( R.id.module_ext_id_voice );
mAnim = ( AnimationDrawable ) mVoiceIcon.getBackground();
mVoiceMsg = findViewById( R.id.module_ext_id_voice_msg );
mVoiceIcon.setOnClickListener( view -> {
@@ -79,7 +82,7 @@ public class ExtensionsFragment extends MvpFragment< ExtensionsView, ExtensionsP
} );
mMsgCounter = findViewById( R.id.module_ext_id_msg_counter );
mVoiceIcon.setFrames( AnimRes.sRes );
// mVoiceIcon.setFrames( AnimRes.sRes );
mMogoFragmentManager = ( IMogoFragmentManager ) ARouter.getInstance().build( MogoServicePaths.PATH_FRAGMENT_MANAGER ).navigation( getContext() );
mMogoFragmentManager.addMainFragmentStackTransactionListener( size -> {
@@ -101,19 +104,22 @@ public class ExtensionsFragment extends MvpFragment< ExtensionsView, ExtensionsP
public void onActivityCreated( @Nullable Bundle savedInstanceState ) {
super.onActivityCreated( savedInstanceState );
mAnalytics = ( IMogoAnalytics ) ARouter.getInstance().build( MogoServicePaths.PATH_UTILS_ANALYTICS ).navigation( getContext() );
mVoiceIcon.startAnim();
}
@Override
public void onResume() {
super.onResume();
mVoiceIcon.startAnim();
if ( mAnim != null ) {
mAnim.start();
}
}
@Override
public void onStop() {
super.onStop();
mVoiceIcon.stop();
if ( mAnim != null ) {
mAnim.stop();
}
}
@Override

View File

@@ -82,6 +82,7 @@ public class JSurfaceView extends SurfaceView implements Runnable, SurfaceHolder
}
bRunning = true;
mThread = new Thread( this );
mThread.setName( TAG + "thread" );
mThread.start();
}

View File

@@ -0,0 +1,207 @@
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/mogo_tts_icon_00000"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00001"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00002"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00003"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00004"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00005"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00006"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00007"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00008"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00009"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00010"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00011"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00012"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00013"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00014"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00015"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00016"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00017"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00018"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00019"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00020"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00021"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00022"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00023"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00024"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00025"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00026"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00027"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00028"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00029"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00030"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00031"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00032"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00033"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00034"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00035"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00036"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00037"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00038"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00039"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00040"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00041"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00042"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00043"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00044"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00045"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00046"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00047"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00048"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00049"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00050"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00051"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00052"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00053"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00054"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00055"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00056"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00057"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00058"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00059"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00060"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00061"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00062"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00063"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00064"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00065"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00066"
android:duration="100" />
<item
android:drawable="@drawable/mogo_tts_icon_00067"
android:duration="100" />
</animation-list>

View File

@@ -8,13 +8,17 @@
android:paddingLeft="@dimen/module_ext_paddingLeft"
android:paddingRight="@dimen/module_ext_paddingRight">
<com.mogo.module.extensions.anim.JSurfaceView
<ImageView
android:id="@+id/module_ext_id_voice"
android:layout_width="@dimen/module_ext_voice_icon_width"
android:layout_height="@dimen/module_ext_voice_icon_height"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
android:layout_width="@dimen/module_ext_voice_icon_width"
android:layout_height="@dimen/module_ext_voice_icon_height"
android:background="@drawable/module_ext_frame_anim_voice"/>
<!-- <com.mogo.module.extensions.anim.JSurfaceView-->
<!-- />-->
<TextView
android:id="@+id/module_ext_id_voice_msg"

View File

@@ -307,7 +307,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
private void startLocation() {
mLocationClient = mMogoMapService.getSingletonLocationClient( getApplicationContext() );
mLocationClient.addLocationListener( this );
mLocationClient.start();
mLocationClient.start(10_000L);
}
private void loadContainerModules() {

View File

@@ -1,13 +1,10 @@
package com.mogo.module.main.cards;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
@@ -29,9 +26,11 @@ import com.mogo.module.extensions.ExtensionsModuleConst;
import com.mogo.module.main.MainActivity;
import com.mogo.module.main.assist.MapBroadCastHelper;
import com.mogo.module.main.registercenter.MogoRegisterCenterHandler;
import com.mogo.module.service.receiver.MogoReceiver;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.analytics.IMogoAnalytics;
import com.mogo.service.map.IMogoMapService;
import com.mogo.service.intent.IMogoIntentListener;
import com.mogo.service.intent.IMogoIntentManager;
import com.mogo.service.module.IMogoModuleLifecycle;
import com.mogo.service.module.IMogoModuleProvider;
import com.mogo.service.module.ModuleType;
@@ -58,24 +57,26 @@ import java.util.Map;
public class MogoModulesManager implements MogoModulesHandler,
IMogoMapListener,
IMogoNaviListener,
IMogoLocationListener {
IMogoLocationListener,
IMogoIntentListener {
private static final String TAG = "MogoModulesManager";
private MainActivity mActivity;
private Map< MogoModule, IMogoModuleProvider > mModuleProviders = new HashMap<>();
// 空间换效率
private Map< String, IMogoModuleProvider > mModuleNameProviders = new HashMap<>();
private IMogoAnalytics mTrackManager;
private IMogoMapService mapService;
private String mEnableModuleName = null;
private Runnable mMapLoadedCallback;
private BroadcastReceiver mReceiver;
public static final String KEY_SORTED_CARD_MODULES = "sortedCards";
private List< String > mSortedCards = new ArrayList<>();
private IMogoIntentManager mMogoIntentManager;
public MogoModulesManager( MainActivity activity ) {
if ( activity == null ) {
throw new NullPointerException( "activity can't be null." );
@@ -85,9 +86,9 @@ public class MogoModulesManager implements MogoModulesHandler,
.build( MogoServicePaths.PATH_UTILS_ANALYTICS )
.navigation();
mapService = ( IMogoMapService ) ARouter.getInstance().build(
MogoServicePaths.PATH_SERVICES_MAP
).navigation();
mMogoIntentManager = ( IMogoIntentManager ) ARouter.getInstance()
.build( MogoServicePaths.PATH_INTENT_MANAGER )
.navigation();
registerReceiver();
}
@@ -108,6 +109,7 @@ public class MogoModulesManager implements MogoModulesHandler,
IMogoModuleProvider provider = load( module.getPath() );
if ( provider != null ) {
mModuleProviders.put( module, provider );
mModuleNameProviders.put( module.getName(), provider );
}
}
}
@@ -236,50 +238,34 @@ public class MogoModulesManager implements MogoModulesHandler,
// 仅操作上一个模块和当前模块
Iterator< IMogoModuleProvider > iterator = mModuleProviders.values().iterator();
int counter = 0;
while ( iterator.hasNext() ) {
IMogoModuleProvider provider = iterator.next();
if ( provider == null ) {
continue;
}
if ( provider.getType() != ModuleType.TYPE_CARD_FRAGMENT ) {
continue;
}
if ( TextUtils.equals( mEnableModuleName, provider.getModuleName() ) ) {
final IMogoModuleLifecycle lifecycle =
MogoRegisterCenterHandler.getInstance().getLifecycleListener( mEnableModuleName );
if ( lifecycle != null ) {
try {
final long start = System.currentTimeMillis();
lifecycle.onDisable();
Logger.i( TAG,
"set %s module disable event cost " + ( System.currentTimeMillis()
- start ) + "ms", mEnableModuleName );
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );
}
// 上一个卡片设置为 disable
IMogoModuleProvider prev = mModuleNameProviders.get( mEnableModuleName );
if ( prev != null ) {
final IMogoModuleLifecycle lifecycle = MogoRegisterCenterHandler.getInstance().getLifecycleListener( mEnableModuleName );
if ( lifecycle != null ) {
try {
final long start = System.currentTimeMillis();
lifecycle.onDisable();
Logger.i( TAG, "set %s module disable event cost " + ( System.currentTimeMillis() - start ) + "ms", mEnableModuleName );
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );
}
counter++;
continue;
}
if ( TextUtils.equals( module, provider.getModuleName() ) ) {
final IMogoModuleLifecycle lifecycle =
MogoRegisterCenterHandler.getInstance().getLifecycleListener( module );
if ( lifecycle != null ) {
try {
final long start = System.currentTimeMillis();
lifecycle.onPerform();
Logger.i( TAG,
"set %s module perform event cost " + ( System.currentTimeMillis()
- start ) + "ms", module );
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );
}
}
// 当前卡片设置为 perform
IMogoModuleProvider current = mModuleNameProviders.get( module );
if ( current != null ) {
final IMogoModuleLifecycle lifecycle = MogoRegisterCenterHandler.getInstance().getLifecycleListener( module );
if ( lifecycle != null ) {
try {
final long start = System.currentTimeMillis();
lifecycle.onPerform();
Logger.i( TAG, "set %s module perform event cost " + ( System.currentTimeMillis() - start ) + "ms", module );
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );
}
counter++;
continue;
}
if ( counter == 2 ) {
break;
}
}
@@ -287,7 +273,7 @@ public class MogoModulesManager implements MogoModulesHandler,
mSortedCards.remove( mEnableModuleName );
mSortedCards.add( 0, mEnableModuleName );
SharedPrefsMgr.getInstance( getContext() ).putString( KEY_SORTED_CARD_MODULES, GsonUtil.jsonFromObject( mSortedCards ) );
Log.i(TAG, "enable & disable card cost " + (System.currentTimeMillis() - start1) + "ms");
Log.i( TAG, "enable & disable card cost " + ( System.currentTimeMillis() - start1 ) + "ms" );
}
@Override
@@ -300,8 +286,7 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onTouch( MotionEvent motionEvent ) {
Iterator< IMogoMapListener > iterator =
MogoRegisterCenterHandler.getInstance().getMapListeners();
Iterator< IMogoMapListener > iterator = MogoRegisterCenterHandler.getInstance().getMapListeners();
if ( iterator == null ) {
return;
}
@@ -319,8 +304,7 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onPOIClick( MogoPoi poi ) {
Iterator< IMogoMapListener > iterator =
MogoRegisterCenterHandler.getInstance().getMapListeners();
Iterator< IMogoMapListener > iterator = MogoRegisterCenterHandler.getInstance().getMapListeners();
if ( iterator == null ) {
return;
}
@@ -338,8 +322,7 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onMapClick( MogoLatLng latLng ) {
Iterator< IMogoMapListener > iterator =
MogoRegisterCenterHandler.getInstance().getMapListeners();
Iterator< IMogoMapListener > iterator = MogoRegisterCenterHandler.getInstance().getMapListeners();
if ( iterator == null ) {
return;
}
@@ -357,8 +340,7 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onLockMap( boolean isLock ) {
Iterator< IMogoMapListener > iterator =
MogoRegisterCenterHandler.getInstance().getMapListeners();
Iterator< IMogoMapListener > iterator = MogoRegisterCenterHandler.getInstance().getMapListeners();
if ( iterator == null ) {
return;
}
@@ -376,8 +358,7 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onMapModeChanged( EnumMapUI ui ) {
Iterator< IMogoMapListener > iterator =
MogoRegisterCenterHandler.getInstance().getMapListeners();
Iterator< IMogoMapListener > iterator = MogoRegisterCenterHandler.getInstance().getMapListeners();
if ( iterator == null ) {
return;
}
@@ -395,8 +376,9 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onMapChanged( MogoLatLng location, float zoom, float tilt, float bearing ) {
Iterator< IMogoMapListener > iterator =
MogoRegisterCenterHandler.getInstance().getMapListeners();
final long start = System.currentTimeMillis();
Iterator< IMogoMapListener > iterator = MogoRegisterCenterHandler.getInstance().getMapListeners();
if ( iterator == null ) {
return;
}
@@ -410,12 +392,12 @@ public class MogoModulesManager implements MogoModulesHandler,
}
}
}
Log.i( TAG, "onMapChanged event cost " + ( System.currentTimeMillis() - start ) + "ms" );
}
@Override
public void onInitNaviFailure() {
Iterator< IMogoNaviListener > iterator =
MogoRegisterCenterHandler.getInstance().getNaviListeners();
Iterator< IMogoNaviListener > iterator = MogoRegisterCenterHandler.getInstance().getNaviListeners();
if ( iterator == null ) {
return;
}
@@ -433,8 +415,7 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onInitNaviSuccess() {
Iterator< IMogoNaviListener > iterator =
MogoRegisterCenterHandler.getInstance().getNaviListeners();
Iterator< IMogoNaviListener > iterator = MogoRegisterCenterHandler.getInstance().getNaviListeners();
if ( iterator == null ) {
return;
}
@@ -453,8 +434,7 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onNaviInfoUpdate( MogoNaviInfo naviinfo ) {
MapBroadCastHelper.getInstance( getApplicationContext() ).notifyXiaozhi( naviinfo );
Iterator< IMogoNaviListener > iterator =
MogoRegisterCenterHandler.getInstance().getNaviListeners();
Iterator< IMogoNaviListener > iterator = MogoRegisterCenterHandler.getInstance().getNaviListeners();
if ( iterator == null ) {
return;
@@ -473,8 +453,7 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onStartNavi() {
Iterator< IMogoNaviListener > iterator =
MogoRegisterCenterHandler.getInstance().getNaviListeners();
Iterator< IMogoNaviListener > iterator = MogoRegisterCenterHandler.getInstance().getNaviListeners();
mTrackManager.track( "Navigation_begin", new HashMap<>() );
MapBroadCastHelper.getInstance( getApplicationContext() ).startNavi();
@@ -497,8 +476,7 @@ public class MogoModulesManager implements MogoModulesHandler,
public void onStopNavi() {
mTrackManager.track( "Navigation_end", new HashMap<>() );
MapBroadCastHelper.getInstance( getApplicationContext() ).stopNavi();
Iterator< IMogoNaviListener > iterator =
MogoRegisterCenterHandler.getInstance().getNaviListeners();
Iterator< IMogoNaviListener > iterator = MogoRegisterCenterHandler.getInstance().getNaviListeners();
if ( iterator == null ) {
return;
}
@@ -516,8 +494,7 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onCalculateSuccess() {
Iterator< IMogoNaviListener > iterator =
MogoRegisterCenterHandler.getInstance().getNaviListeners();
Iterator< IMogoNaviListener > iterator = MogoRegisterCenterHandler.getInstance().getNaviListeners();
if ( iterator == null ) {
return;
}
@@ -535,8 +512,7 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onoCalculateFailed() {
Iterator< IMogoNaviListener > iterator =
MogoRegisterCenterHandler.getInstance().getNaviListeners();
Iterator< IMogoNaviListener > iterator = MogoRegisterCenterHandler.getInstance().getNaviListeners();
if ( iterator == null ) {
return;
}
@@ -554,8 +530,7 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onUpdateTraffic( MogoTraffic traffic ) {
Iterator< IMogoNaviListener > iterator =
MogoRegisterCenterHandler.getInstance().getNaviListeners();
Iterator< IMogoNaviListener > iterator = MogoRegisterCenterHandler.getInstance().getNaviListeners();
if ( iterator == null ) {
return;
}
@@ -573,8 +548,8 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public void onLocationChanged( MogoLocation location ) {
Iterator< IMogoLocationListener > iterator =
MogoRegisterCenterHandler.getInstance().getLocationListeners();
final long start = System.currentTimeMillis();
Iterator< IMogoLocationListener > iterator = MogoRegisterCenterHandler.getInstance().getLocationListeners();
if ( iterator == null ) {
return;
}
@@ -588,40 +563,51 @@ public class MogoModulesManager implements MogoModulesHandler,
}
}
}
Log.i( TAG, "onLocationChanged event cost " + ( System.currentTimeMillis() - start ) + "ms" );
}
public void registerReceiver() {
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive( Context context, Intent intent ) {
final String action = intent.getAction();
if ( TextUtils.equals( action, Intent.ACTION_POWER_CONNECTED ) ) {
Iterator< IMogoModuleLifecycle > iterator =
MogoRegisterCenterHandler.getInstance().getLifecycleListeners();
if ( iterator.hasNext() ) {
iterator.next().accOn();
}
} else if ( TextUtils.equals( action, Intent.ACTION_POWER_DISCONNECTED ) ) {
mMogoIntentManager.registerIntentListener( Intent.ACTION_POWER_CONNECTED, this );
mMogoIntentManager.registerIntentListener( Intent.ACTION_POWER_DISCONNECTED, this );
mMogoIntentManager.registerIntentListener( MogoReceiver.ACTION_NWD_ACC, this );
}
@Override
public void onIntentReceived( String intentStr, Intent intent ) {
Iterator< IMogoModuleLifecycle > iterator = MogoRegisterCenterHandler.getInstance().getLifecycleListeners();
if ( Intent.ACTION_POWER_CONNECTED.equals( intentStr ) ) {
while ( iterator.hasNext() ) {
IMogoModuleLifecycle lifecycle = iterator.next();
if ( lifecycle != null ) {
lifecycle.accOn();
}
}
};
IntentFilter inputFilter = new IntentFilter();
inputFilter.addAction( Intent.ACTION_POWER_CONNECTED );
inputFilter.addAction( Intent.ACTION_POWER_DISCONNECTED );
getApplicationContext().registerReceiver( mReceiver, inputFilter );
} else if ( Intent.ACTION_POWER_DISCONNECTED.equals( intentStr ) ) {
} else if ( MogoReceiver.ACTION_NWD_ACC.equals( intentStr ) ) {
int state = intent.getByteExtra( MogoReceiver.PARAM_ACC_STATUS, ( byte ) 0 );
if ( state == 1 ) {
while ( iterator.hasNext() ) {
IMogoModuleLifecycle lifecycle = iterator.next();
if ( lifecycle != null ) {
lifecycle.accOn();
}
}
}
}
if ( iterator.hasNext() ) {
iterator.next().accOn();
}
}
@Override
public void destroy() {
if ( mReceiver != null ) {
try {
getApplicationContext().unregisterReceiver( mReceiver );
} catch ( Exception e ) {
e.printStackTrace();
}
if ( mMogoIntentManager != null ) {
mMogoIntentManager.unregisterIntentListener( Intent.ACTION_POWER_CONNECTED );
mMogoIntentManager.unregisterIntentListener( Intent.ACTION_POWER_DISCONNECTED );
mMogoIntentManager.unregisterIntentListener( MogoReceiver.ACTION_NWD_ACC );
}
mReceiver = null;
mActivity = null;
if ( mModuleProviders != null ) {
mModuleProviders.clear();
@@ -633,8 +619,7 @@ public class MogoModulesManager implements MogoModulesHandler,
@Override
public boolean onMarkerClicked( IMogoMarker marker ) {
IMogoMarkerClickListener listener =
MogoRegisterCenterHandler.getInstance().getMarkerListener( marker.getOwner() );
IMogoMarkerClickListener listener = MogoRegisterCenterHandler.getInstance().getMarkerListener( marker.getOwner() );
if ( listener != null ) {
try {
return listener.onMarkerClicked( marker );

View File

@@ -49,6 +49,7 @@ import com.mogo.service.statusmanager.IMogoStatusManager;
import com.mogo.service.statusmanager.StatusDescriptor;
import com.mogo.utils.logger.Logger;
import java.util.Iterator;
import java.util.List;
/**
@@ -125,8 +126,8 @@ public class MogoServiceProvider implements IMogoModuleProvider,
mRefreshRemainingTime -= ServiceConst.DECREASE_INTERVAL;
if ( mRefreshRemainingTime == 0 ) {
Logger.d( TAG, "move to center and refresh data." );
mStatusManager.setUserInteractionStatus(ServiceConst.TYPE, true, false );
mUiController.moveToCenter(mLastAutoRefreshLocation);
mStatusManager.setUserInteractionStatus( ServiceConst.TYPE, true, false );
mUiController.moveToCenter( mLastAutoRefreshLocation );
notifyRefreshData( mLastAutoRefreshLocation, getQueryRadius(), mAutoRefreshCallback );
} else {
mHandler.sendEmptyMessageDelayed( msg.what, ServiceConst.DECREASE_INTERVAL );
@@ -495,8 +496,8 @@ public class MogoServiceProvider implements IMogoModuleProvider,
}
Logger.d( TAG, mAutoRefreshCallback == callback ? "触发自动刷新" : "触发手动刷新" );
int amount = mLastZoomLevel >= 10 ? 5 : 10;
mRefreshModel.refreshData( latLng, radius, mLastZoomLevel >= 10 ? 5 : 10, callback );
Logger.i( TAG, "刷新半径 = %d, 点 = %s, amount = %d", radius, latLng, amount );
mRefreshModel.refreshData( latLng, radius, amount, callback );
Logger.i( TAG, "刷新半径 = %d, 点 = %s, zoomLevel = %f, amount = %d", radius, latLng, mLastZoomLevel, amount );
}
@Override
@@ -523,9 +524,9 @@ public class MogoServiceProvider implements IMogoModuleProvider,
@Override
public void onStatusChanged( StatusDescriptor descriptor, boolean isTrue ) {
Logger.d(TAG, "状态发生改变---descriptor---" + descriptor + "----isTrue---" + isTrue);
Logger.d( TAG, "状态发生改变---descriptor---" + descriptor + "----isTrue---" + isTrue );
switch ( descriptor ) {
case USER_INTERACTED:
case USER_INTERACTED:
if ( isTrue && !mRefreshRemainingTimeStatus ) {
mRefreshRemainingTimeStatus = true;
mRefreshRemainingTime += mAutoRefreshStrategy.getInterruptInterval();
@@ -556,17 +557,17 @@ public class MogoServiceProvider implements IMogoModuleProvider,
mAutoRefreshCallback.onSuccess();
}
}
} catch (Exception e) {
} catch ( Exception e ) {
e.printStackTrace();
}
break;
}
}
public void refreshStrategy(){
public void refreshStrategy() {
Logger.d( TAG, "move to center and refresh data." );
mStatusManager.setUserInteractionStatus(ServiceConst.TYPE, true, false );
mUiController.moveToCenter(mLastAutoRefreshLocation);
mStatusManager.setUserInteractionStatus( ServiceConst.TYPE, true, false );
mUiController.moveToCenter( mLastAutoRefreshLocation );
notifyRefreshData( mLastAutoRefreshLocation, getQueryRadius(), mAutoRefreshCallback );
}

View File

@@ -4,6 +4,9 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
@@ -72,14 +75,12 @@ import com.mogo.module.tanlu.model.event.MarkerInfo;
import com.mogo.module.tanlu.model.event.PushTypeInfo;
import com.mogo.module.tanlu.model.event.SharedialogEvent;
import com.mogo.module.tanlu.util.Utils;
import com.mogo.module.tanlu.video.FullMediaActivity;
import com.mogo.module.tanlu.video.SimpleCoverVideoPlayer;
import com.mogo.module.tanlu.view.AutoZoomInImageView;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.analytics.IMogoAnalytics;
import com.mogo.service.cardmanager.IMogoCardManager;
import com.mogo.service.datamanager.IMogoDataChangedListener;
import com.mogo.service.datamanager.IMogoDataManager;
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
import com.mogo.service.imageloader.IMogoImageLoaderListener;
import com.mogo.service.imageloader.IMogoImageloader;
@@ -168,7 +169,12 @@ public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
private String mKeywords;
private boolean isCurrentPage;
private Handler mMsgHandler = new Handler( Looper.getMainLooper() ){
@Override
public void handleMessage( Message msg ) {
super.handleMessage( msg );
}
};
@Override
protected int getLayoutId() {
return R.layout.tanlu_item_main_media_recycler;
@@ -772,9 +778,8 @@ public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
mNextTv.setVisibility(View.VISIBLE);
}
//展示第一个数据
MarkerExploreWay markerExploreWay = markerExploreWayList.get(0);
handleMarkerExploreWay(markerExploreWay);
//延时展示第一个数据
mMsgHandler.postDelayed( mDelayRunnable, 1_000L );
} else {
mEmptyLayout.setVisibility(View.VISIBLE);
mRootLayout.setVisibility(View.GONE);
@@ -782,6 +787,31 @@ public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
}
}
private MarkerExploreWay mLastPlayEntity = null;
// 播放第一个数据需要延时,避免滑动卡顿
private Runnable mDelayRunnable = new Runnable() {
@Override
public void run() {
if ( isCurrentPage && !isRemoving() && !isDetached() ) {
try {
final MarkerExploreWay markerExploreWay = markerExploreWayList.get(0);
if ( mLastPlayEntity == markerExploreWay ) {
if ( markerExploreWay.getFileType() == 1 ) {
// 视频的话重新播放
simpleCoverVideoPlayer.getGSYVideoManager().start();
}
} else {
mLastPlayEntity = markerExploreWay;
handleMarkerExploreWay(markerExploreWay);
}
} catch( Exception e ){
e.printStackTrace();
}
}
}
};
@Override
public void onDataSetChanged( Object data ) {
Logger.d( TAG, "receive data changed." );
@@ -811,6 +841,28 @@ public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
public void onDisable() {
Logger.d(TAG, "tanlu卡片 无效 ----->");
isCurrentPage = false;
mMsgHandler.removeCallbacks( mDelayRunnable );
if ( mLastPlayEntity != null ) {
if ( mLastPlayEntity.getFileType() == 1 ) {
try {
if ( simpleCoverVideoPlayer.getVisibility() == View.VISIBLE ) {
// 卡片滑动过去之后停止播放
simpleCoverVideoPlayer.getGSYVideoManager().pause();
}
} catch ( Exception e ) {
e.printStackTrace();
}
} else {
try {
if ( autoZoomInImageView.getVisibility() == View.VISIBLE ) {
autoZoomInImageView.stopCurrentAnimator();
}
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
AIAssist.getInstance(getActivity()).unregisterUnWakeupCommand(TanluConstants.PLAY_VIDEO);
}

View File

@@ -94,13 +94,15 @@ public class AutoZoomInImageView extends MogoImageView {
setImageMatrix(mMatrix);
}
private ValueAnimator mCurrentAnimator;
private void startZoomInByScaleDelta(final float scaleDelta, long duration) {
final float oriScaleX = mValues[0];
final float oriScaleY = mValues[4];
ValueAnimator va = ValueAnimator.ofFloat(0, scaleDelta);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
mCurrentAnimator = ValueAnimator.ofFloat(0, scaleDelta);
mCurrentAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
@@ -113,7 +115,7 @@ public class AutoZoomInImageView extends MogoImageView {
setImageMatrix(mMatrix);
}
});
va.addListener(new Animator.AnimatorListener() {
mCurrentAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
if (mOnZoomListener != null) mOnZoomListener.onStart(AutoZoomInImageView.this);
@@ -122,18 +124,31 @@ public class AutoZoomInImageView extends MogoImageView {
@Override
public void onAnimationEnd(Animator animation) {
if (mOnZoomListener != null) mOnZoomListener.onEnd(AutoZoomInImageView.this);
mCurrentAnimator = null;
}
@Override
public void onAnimationCancel(Animator animation) {
mCurrentAnimator = null;
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
va.setDuration(duration);
va.start();
mCurrentAnimator.setDuration(duration);
mCurrentAnimator.start();
}
/**
* 停止动画
*/
public void stopCurrentAnimator(){
if ( mCurrentAnimator != null ) {
if ( mCurrentAnimator.isRunning() ) {
mCurrentAnimator.cancel();
}
}
}
/**