opt: cpu
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.mogo.module.extensions;
|
||||
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
@@ -13,8 +12,10 @@ import androidx.annotation.Nullable;
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.mvp.MvpFragment;
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.module.extensions.anim.AnimWrapper;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.analytics.IMogoAnalytics;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -26,8 +27,10 @@ public class ExtensionsFragment extends MvpFragment< ExtensionsView, ExtensionsP
|
||||
|
||||
private static final String TAG = "ExtensionsFragment";
|
||||
|
||||
public static final int MAX_DISPLAY_MSG_AMOUNT = 99;
|
||||
|
||||
private ImageView mVoiceIcon;
|
||||
private AnimationDrawable mAnim;
|
||||
private AnimWrapper mAnim = new AnimWrapper();
|
||||
private TextView mVoiceMsg;
|
||||
|
||||
private TextView mTime;
|
||||
@@ -42,6 +45,7 @@ public class ExtensionsFragment extends MvpFragment< ExtensionsView, ExtensionsP
|
||||
private TextView mMsgCounter;
|
||||
|
||||
private IMogoAnalytics mAnalytics;
|
||||
private IMogoFragmentManager mMogoFragmentManager;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@@ -51,7 +55,7 @@ public class ExtensionsFragment extends MvpFragment< ExtensionsView, ExtensionsP
|
||||
@Override
|
||||
protected void initViews() {
|
||||
mVoiceIcon = findViewById( R.id.module_ext_id_voice );
|
||||
mAnim = ( AnimationDrawable ) mVoiceIcon.getBackground();
|
||||
mAnim.initAnim( mVoiceIcon );
|
||||
mVoiceMsg = findViewById( R.id.module_ext_id_voice_msg );
|
||||
|
||||
mVoiceIcon.setOnClickListener( view -> {
|
||||
@@ -87,22 +91,28 @@ 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() );
|
||||
mMogoFragmentManager = ( IMogoFragmentManager ) ARouter.getInstance().build( MogoServicePaths.PATH_FRAGMENT_MANAGER ).navigation( getContext() );
|
||||
|
||||
mMogoFragmentManager.addMainFragmentStackTransactionListener( size -> {
|
||||
// 主页 fragment 栈变化的时候,改变动画状态
|
||||
if ( size == 0 ) {
|
||||
mAnim.start();
|
||||
} else {
|
||||
mAnim.stop();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if ( mAnim != null ) {
|
||||
mAnim.start();
|
||||
}
|
||||
mAnim.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
if ( mAnim != null ) {
|
||||
mAnim.stop();
|
||||
}
|
||||
mAnim.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,7 +141,7 @@ public class ExtensionsFragment extends MvpFragment< ExtensionsView, ExtensionsP
|
||||
@Override
|
||||
public void renderMsgInfo( boolean hasMsg, int amount ) {
|
||||
mMsgContainer.setVisibility( hasMsg ? View.VISIBLE : View.GONE );
|
||||
mMsgCounter.setText( amount > 99 ? getString( R.string.module_ext_str_dots ) : String.valueOf( amount ) );
|
||||
mMsgCounter.setText( amount > MAX_DISPLAY_MSG_AMOUNT ? getString( R.string.module_ext_str_dots ) : String.valueOf( amount ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.mogo.module.extensions.anim;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-02-26
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public interface Anim {
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.mogo.module.extensions.anim;
|
||||
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.os.Build;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.mogo.module.extensions.R;
|
||||
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 ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.mogo.module.extensions.anim;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-02-26
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class KitkatAnim implements Anim{
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.mogo.module.extensions.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user