This commit is contained in:
wangcongtao
2020-05-20 09:46:45 +08:00
parent f5a1925532
commit a5b3ce5831
198 changed files with 703 additions and 769 deletions

View File

@@ -1,6 +1,8 @@
package com.mogo.module.apps;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -8,7 +10,9 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.commons.voice.AIAssist;
import com.mogo.module.apps.adapter.AppIndicatorAdapter;
import com.mogo.module.apps.anim.AnimWrapper;
import com.mogo.module.apps.applaunch.AppLauncher;
import com.mogo.module.apps.applaunch.BaseAppLauncher;
import com.mogo.module.apps.applaunch.InternalFunctionLauncher;
@@ -30,6 +34,10 @@ public class AppNavigatorFragment extends MvpFragment< AppNavigatorView, AppNavi
private RecyclerView mNavigatorAppsList;
private AppIndicatorAdapter mAppIndicatorAdapter;
private ImageView mAIAssist;
private View mAIAssistContainer;
private AnimWrapper mAnim = new AnimWrapper();
private BaseAppLauncher mLauncher;
@Override
@@ -39,10 +47,7 @@ public class AppNavigatorFragment extends MvpFragment< AppNavigatorView, AppNavi
@Override
protected void initViews() {
// mApps.setOnClickListener( view -> {
// openAppsPanel();
// trackNavigatorClickEvent( 4 );
// } );
mLauncher = new InternalFunctionLauncher( getActivity() );
mLauncher.setNext( new AppLauncher() );
@@ -53,6 +58,48 @@ public class AppNavigatorFragment extends MvpFragment< AppNavigatorView, AppNavi
mLauncher.launch( getContext(), data );
} );
mNavigatorAppsList.setAdapter( mAppIndicatorAdapter );
mAIAssistContainer = findViewById( R.id.module_apps_id_ai_assist_container );
mAIAssist = findViewById( R.id.module_apps_id_ai_assist );
mAnim.initAnim( mAIAssist );
mAIAssist.setOnClickListener( view -> {
AIAssist.startAssistant( getContext() );
AppServiceHandler.getApis().getAnalyticsApi().track( "Launcher_xiaozhi_Click", null );
} );
mAIAssistContainer.setOnClickListener( view -> {
mAIAssist.performClick();
} );
AppServiceHandler.getApis().getFragmentManagerApi().addMainFragmentStackTransactionListener( size -> {
// 主页 fragment 栈变化的时候,改变动画状态
if ( size == 0 ) {
mAnim.start();
} else {
mAnim.stop();
}
} );
}
@Override
public void hideNavigationEntrance() {
mAppIndicatorAdapter.setDatas( NavigatorApps.getAppsWithoutNavigation() );
}
@Override
public void showNavigationEntrance() {
mAppIndicatorAdapter.setDatas( NavigatorApps.getApps() );
}
@Override
public void onResume() {
super.onResume();
mAnim.start();
}
@Override
public void onPause() {
super.onPause();
mAnim.stop();
}
@NonNull

View File

@@ -9,6 +9,7 @@ import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.commons.mvp.Presenter;
import com.mogo.commons.voice.AIAssist;
import com.mogo.commons.voice.IMogoVoiceCmdCallBack;
import com.mogo.map.navi.IMogoNaviListener2;
import com.mogo.module.apps.model.AppsModel;
import com.mogo.module.apps.utils.LaunchUtils;
import com.mogo.service.MogoServicePaths;
@@ -26,7 +27,9 @@ import org.json.JSONObject;
* <p>
* 描述
*/
public class AppNavigatorPresenter extends Presenter< AppNavigatorView > implements IMogoIntentListener, IMogoVoiceCmdCallBack {
public class AppNavigatorPresenter extends Presenter< AppNavigatorView > implements IMogoIntentListener,
IMogoVoiceCmdCallBack,
IMogoNaviListener2 {
private static final String TAG = "AppNavigatorPresenter";
@@ -42,6 +45,7 @@ public class AppNavigatorPresenter extends Presenter< AppNavigatorView > impleme
super.onCreate( owner );
mIntentManager = AppServiceHandler.getApis().getIntentManagerApi();
mMogoStatusManager = AppServiceHandler.getApis().getStatusManagerApi();
AppServiceHandler.getApis().getRegisterCenterApi().registerMogoNaviListener( TAG, this );
// 预加载应用列表,空间换时间
AppsModel.getInstance( getContext() ).load( null );
}
@@ -106,26 +110,6 @@ public class AppNavigatorPresenter extends Presenter< AppNavigatorView > impleme
}
}
@Override
public void onCmdAction( String speakText ) {
}
@Override
public void onCmdCancel( String speakText ) {
}
@Override
public void onSpeakEnd( String speakText ) {
}
@Override
public void onSpeakSelectTimeOut( String speakText ) {
}
@Override
public void onDestroy( @NonNull LifecycleOwner owner ) {
if ( mIntentManager != null ) {
@@ -133,4 +117,14 @@ public class AppNavigatorPresenter extends Presenter< AppNavigatorView > impleme
}
super.onDestroy( owner );
}
@Override
public void onStartNavi() {
mView.hideNavigationEntrance();
}
@Override
public void onStopNavi() {
mView.showNavigationEntrance();
}
}

View File

@@ -15,4 +15,8 @@ public interface AppNavigatorView extends IView {
* 打开全部应用
*/
void openAppsPanel();
void hideNavigationEntrance();
void showNavigationEntrance();
}

View File

@@ -0,0 +1,14 @@
package com.mogo.module.apps.anim;
/**
* @author congtaowang
* @since 2020-02-26
* <p>
* 描述
*/
public interface Anim {
void start();
void stop();
}

View File

@@ -0,0 +1,84 @@
package com.mogo.module.apps.anim;
import com.mogo.module.apps.R;
/**
* @author congtaowang
* @since 2020-01-09
* <p>
* 描述
*/
public class AnimRes {
public static final int sRes[] = {
R.drawable.mogo_tts_icon_00000,
R.drawable.mogo_tts_icon_00001,
R.drawable.mogo_tts_icon_00002,
R.drawable.mogo_tts_icon_00003,
R.drawable.mogo_tts_icon_00004,
R.drawable.mogo_tts_icon_00005,
R.drawable.mogo_tts_icon_00006,
R.drawable.mogo_tts_icon_00007,
R.drawable.mogo_tts_icon_00008,
R.drawable.mogo_tts_icon_00009,
R.drawable.mogo_tts_icon_00010,
R.drawable.mogo_tts_icon_00011,
R.drawable.mogo_tts_icon_00012,
R.drawable.mogo_tts_icon_00013,
R.drawable.mogo_tts_icon_00014,
R.drawable.mogo_tts_icon_00015,
R.drawable.mogo_tts_icon_00016,
R.drawable.mogo_tts_icon_00017,
R.drawable.mogo_tts_icon_00018,
R.drawable.mogo_tts_icon_00019,
R.drawable.mogo_tts_icon_00020,
R.drawable.mogo_tts_icon_00021,
R.drawable.mogo_tts_icon_00022,
R.drawable.mogo_tts_icon_00023,
R.drawable.mogo_tts_icon_00024,
R.drawable.mogo_tts_icon_00025,
R.drawable.mogo_tts_icon_00026,
R.drawable.mogo_tts_icon_00027,
R.drawable.mogo_tts_icon_00028,
R.drawable.mogo_tts_icon_00029,
R.drawable.mogo_tts_icon_00030,
R.drawable.mogo_tts_icon_00031,
R.drawable.mogo_tts_icon_00032,
R.drawable.mogo_tts_icon_00033,
R.drawable.mogo_tts_icon_00034,
R.drawable.mogo_tts_icon_00035,
R.drawable.mogo_tts_icon_00036,
R.drawable.mogo_tts_icon_00037,
R.drawable.mogo_tts_icon_00038,
R.drawable.mogo_tts_icon_00039,
R.drawable.mogo_tts_icon_00040,
R.drawable.mogo_tts_icon_00041,
R.drawable.mogo_tts_icon_00042,
R.drawable.mogo_tts_icon_00043,
R.drawable.mogo_tts_icon_00044,
R.drawable.mogo_tts_icon_00045,
R.drawable.mogo_tts_icon_00046,
R.drawable.mogo_tts_icon_00047,
R.drawable.mogo_tts_icon_00048,
R.drawable.mogo_tts_icon_00049,
R.drawable.mogo_tts_icon_00050,
R.drawable.mogo_tts_icon_00051,
R.drawable.mogo_tts_icon_00052,
R.drawable.mogo_tts_icon_00053,
R.drawable.mogo_tts_icon_00054,
R.drawable.mogo_tts_icon_00055,
R.drawable.mogo_tts_icon_00056,
R.drawable.mogo_tts_icon_00057,
R.drawable.mogo_tts_icon_00058,
R.drawable.mogo_tts_icon_00059,
R.drawable.mogo_tts_icon_00060,
R.drawable.mogo_tts_icon_00061,
R.drawable.mogo_tts_icon_00062,
R.drawable.mogo_tts_icon_00063,
R.drawable.mogo_tts_icon_00064,
R.drawable.mogo_tts_icon_00065,
R.drawable.mogo_tts_icon_00066,
R.drawable.mogo_tts_icon_00067
};
}

View File

@@ -0,0 +1,68 @@
package com.mogo.module.apps.anim;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;
import com.mogo.module.apps.R;
import com.mogo.module.common.utils.CarSeries;
import com.mogo.utils.ThreadPoolService;
import com.mogo.utils.UiThreadHandler;
import com.mogo.utils.logger.Logger;
/**
* @author congtaowang
* @since 2020-02-26
* <p>
* 描述
*/
public class AnimWrapper implements Anim {
private static final String TAG = "AnimWrapper";
private ImageView mTarget;
private Anim mDelegate;
private boolean mIsStarted = false;
public AnimWrapper() {
}
public void initAnim( ImageView target ) {
mTarget = target;
if ( CarSeries.getSeries() == CarSeries.CAR_SERIES_F80X ) {
ThreadPoolService.execute( () -> {
final AnimationDrawable drawable = new AnimationDrawable();
for ( int i = 0; i < AnimRes.sRes.length; i++ ) {
drawable.addFrame( target.getResources().getDrawable( AnimRes.sRes[i] ), 100 );
}
UiThreadHandler.post( () -> {
target.setBackground( drawable );
mDelegate = new OthersAnim( drawable );
start();
} );
} );
} else {
mTarget.setImageResource( R.drawable.mogo_tts_icon_00000 );
}
}
@Override
public synchronized void start() {
if ( mDelegate != null && !mIsStarted ) {
mIsStarted = true;
mDelegate.start();
Logger.d( TAG, "开启小智动画" );
}
}
@Override
public void stop() {
if ( mDelegate != null ) {
mIsStarted = false;
mDelegate.stop();
Logger.d( TAG, "停止小智动画" );
}
}
public void release() {
mDelegate = null;
}
}

View File

@@ -0,0 +1,183 @@
package com.mogo.module.apps.anim;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import com.mogo.utils.logger.Logger;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
public class JSurfaceView extends SurfaceView implements Runnable, SurfaceHolder.Callback {
private static final String TAG = "JSurfaceView";
private SurfaceHolder mHolder;
/**
* 动画是否执行中
*/
private boolean bRunning = false;
/**
* 当前执行的第几帧
*/
private int mCurrentPos;
/**
* 动画集合
*/
private int[] mFrames;
private Thread mThread;
// 使用 BitmapFactory.Option.inBitmap 属性复用 bitmap 对象
private Bitmap mContainerBitmap = null;
// mContainerBitmap 是否生效
private boolean mContainerBitmapStatus = true;
// mContainerBitmapStatus 为 false 时,使用该缓存方案
private Map< Integer, WeakReference< Bitmap > > mBitmapRefMap = new HashMap<>();
public JSurfaceView( Context context ) {
super( context );
init();
}
public JSurfaceView( Context context, AttributeSet attrs ) {
super( context, attrs );
init();
}
public JSurfaceView( Context context, AttributeSet attrs, int defStyleAttr ) {
super( context, attrs, defStyleAttr );
init();
}
private void init() {
mHolder = getHolder();
mHolder.addCallback( this );
setZOrderOnTop( true );
mHolder.setFormat( PixelFormat.TRANSLUCENT );
}
public void setFrames( int[] frames ) {
mFrames = frames;
}
public void startAnim() {
if ( bRunning ) {
return;
}
bRunning = true;
mThread = new Thread( this );
mThread.setName( TAG + "thread" );
mThread.start();
}
public void stop() {
bRunning = false;
try {
mThread.interrupt();
mThread = null;
} catch ( Exception e ) {
e.printStackTrace();
}
}
@Override
public void run() {
while ( bRunning ) {
drawBitmap();
mCurrentPos++;
try {
Thread.sleep( 100 );
} catch ( InterruptedException e ) {
e.printStackTrace();
}
}
}
private void drawBitmap() {
//获取画布并锁定
Canvas canvas = mHolder.lockCanvas();
if ( canvas == null ) {
return;
}
//绘制透明色
canvas.drawColor( Color.TRANSPARENT, PorterDuff.Mode.CLEAR );
int factPosition = mCurrentPos % mFrames.length;
if ( mContainerBitmapStatus ) {
if ( mContainerBitmap == null ) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
mContainerBitmap = BitmapFactory.decodeResource( getResources(), mFrames[factPosition], options );
} else {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
options.inBitmap = mContainerBitmap;
try {
BitmapFactory.decodeResource( getResources(), mFrames[factPosition], options );
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );
mContainerBitmapStatus = false;
mContainerBitmap = null;
}
}
}
if ( !mContainerBitmapStatus ) {
WeakReference< Bitmap > ref = mBitmapRefMap.get( factPosition );
if ( ref != null && ref.get() != null && !ref.get().isRecycled() ) {
mContainerBitmap = ref.get();
} else {
mContainerBitmap = BitmapFactory.decodeResource( getResources(), mFrames[factPosition] );
mBitmapRefMap.put( factPosition, new WeakReference<>( mContainerBitmap ) );
}
}
if ( mContainerBitmap == null || mContainerBitmap.isRecycled() ) {
return;
}
Paint paint = new Paint();
Rect mSrcRect = new Rect( 0,
0,
mContainerBitmap.getWidth(),
mContainerBitmap.getHeight() ); // 图片绘制
Rect mDestRect = new Rect( 0,
0,
getWidth(),
getHeight() );// 图片绘制位置
canvas.drawBitmap( mContainerBitmap, mSrcRect, mDestRect, paint );
//解锁画布并展示bitmap到surface
mHolder.unlockCanvasAndPost( canvas );
}
@Override
public void surfaceCreated( SurfaceHolder holder ) {
}
@Override
public void surfaceChanged( SurfaceHolder holder, int format, int width, int height ) {
}
@Override
public void surfaceDestroyed( SurfaceHolder holder ) {
}
}

View File

@@ -0,0 +1,20 @@
package com.mogo.module.apps.anim;
/**
* @author congtaowang
* @since 2020-02-26
* <p>
* 描述
*/
public class KitkatAnim implements Anim{
@Override
public void start() {
}
@Override
public void stop() {
}
}

View File

@@ -0,0 +1,32 @@
package com.mogo.module.apps.anim;
import android.graphics.drawable.AnimationDrawable;
/**
* @author congtaowang
* @since 2020-02-26
* <p>
* 描述
*/
public class OthersAnim implements Anim{
private AnimationDrawable mDrawable;
public OthersAnim( AnimationDrawable drawable ) {
this.mDrawable = drawable;
}
@Override
public void start() {
if ( mDrawable != null ) {
mDrawable.start();
}
}
@Override
public void stop() {
if ( mDrawable != null ) {
mDrawable.stop();
}
}
}

View File

@@ -13,15 +13,25 @@ import java.util.List;
*/
public class NavigatorApps {
private static List< AppInfo > sApps = new ArrayList<>();
private static AppInfo app = new AppInfo( "导航", "com.mogo.launcher.navi.search", "", 0, null, R.drawable.module_apps_ic_navigator_navi );
private static AppInfo app2 = new AppInfo( "音乐", "com.pvetec.musics", "", 0, null, R.drawable.module_apps_ic_navigator_media );
private static AppInfo app3 = new AppInfo( "个人中心", "com.zhidao.auto.personal", "", 0, null, R.drawable.module_apps_ic_navigator_personcenter );
private static AppInfo app4 = new AppInfo( "全部应用", "com.mogo.launcher.applist", "", 0, null, R.drawable.module_apps_ic_navigator_applist );
public static List< AppInfo > getApps() {
if ( sApps.isEmpty() ) {
sApps.add( new AppInfo( "导航", "com.mogo.launcher.navi.search", "", 0, null, R.drawable.module_apps_ic_apps ) );
sApps.add( new AppInfo( "音乐", "com.pvetec.musics", "", 0, null, R.drawable.module_apps_ic_apps ) );
sApps.add( new AppInfo( "个人中心", "com.zhidao.auto.personal", "", 0, null, R.drawable.module_apps_ic_apps ) );
sApps.add( new AppInfo( "全部应用", "com.mogo.launcher.applist", "", 0, null, R.drawable.module_apps_ic_apps ) );
}
List< AppInfo > sApps = new ArrayList<>();
sApps.add( app );
sApps.add( app2 );
sApps.add( app3 );
sApps.add( app4 );
return sApps;
}
public static List< AppInfo > getAppsWithoutNavigation() {
List< AppInfo > sApps = new ArrayList<>();
sApps.add( app2 );
sApps.add( app3 );
sApps.add( app4 );
return sApps;
}
}