add voice auto tip logic
This commit is contained in:
@@ -18,6 +18,7 @@ import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.analytics.IMogoAnalytics;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -27,8 +28,10 @@ import com.mogo.utils.UiThreadHandler;
|
||||
*/
|
||||
public class ExtensionsFragment extends MvpFragment< ExtensionsView, ExtensionsPresenter > implements ExtensionsView {
|
||||
|
||||
private static final String TAG = "ExtensionsFragment";
|
||||
|
||||
private JSurfaceView mVoiceIcon;
|
||||
private View mVoiceMsg;
|
||||
private TextView mVoiceMsg;
|
||||
|
||||
private TextView mTime;
|
||||
private TextView mDate;
|
||||
@@ -141,4 +144,12 @@ public class ExtensionsFragment extends MvpFragment< ExtensionsView, ExtensionsP
|
||||
mMsgContainer.setVisibility( hasMsg ? View.VISIBLE : View.GONE );
|
||||
mMsgCounter.setText( amount > 99 ? getString( R.string.module_ext_str_dots ) : String.valueOf( amount ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderAITipWords( String word ) {
|
||||
if ( !TextUtils.isEmpty( word ) ) {
|
||||
Logger.d( TAG, "current word: %s", word );
|
||||
mVoiceMsg.setText( word );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
@@ -19,7 +22,16 @@ import com.mogo.service.statusmanager.IMogoMsgCenter;
|
||||
import com.mogo.service.statusmanager.IMogoMsgCenterListener;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
@@ -36,6 +48,31 @@ public class ExtensionsPresenter extends Presenter< ExtensionsView > implements
|
||||
|
||||
private WeatherModel mWeatherModel;
|
||||
|
||||
public static final int MSG_SWITCH_AI_TIP_WORDS = 4000;
|
||||
public static final long INTERVAL_TIME = 8_000L;
|
||||
private String[] mAITipWords;
|
||||
private int mCurrentIndex = 0;
|
||||
private Handler mHandler = new Handler( Looper.getMainLooper() ) {
|
||||
@Override
|
||||
public void handleMessage( Message msg ) {
|
||||
super.handleMessage( msg );
|
||||
if ( msg.what == MSG_SWITCH_AI_TIP_WORDS ) {
|
||||
if ( mView != null ) {
|
||||
if ( mCurrentIndex < mAITipWords.length ) {
|
||||
mView.renderAITipWords( mAITipWords[mCurrentIndex++] );
|
||||
} else {
|
||||
mCurrentIndex = 0;
|
||||
mHasTipWords = generateTipWordsSequence();
|
||||
}
|
||||
}
|
||||
if ( mHasTipWords ) {
|
||||
mHandler.sendEmptyMessageDelayed( MSG_SWITCH_AI_TIP_WORDS, INTERVAL_TIME );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
private boolean mHasTipWords = false;
|
||||
|
||||
/**
|
||||
* 接收时间变化的广播
|
||||
*/
|
||||
@@ -52,10 +89,30 @@ public class ExtensionsPresenter extends Presenter< ExtensionsView > implements
|
||||
|
||||
private IMogoMsgCenter mMsgCenter;
|
||||
|
||||
private boolean generateTipWordsSequence() {
|
||||
if ( mAITipWords != null && mAITipWords.length > 0 ) {
|
||||
Random random = new Random( System.currentTimeMillis() );
|
||||
int loop = mAITipWords.length / 2;
|
||||
int bound = mAITipWords.length;
|
||||
for ( int i = 0; i < loop; i++ ) {
|
||||
int target = random.nextInt( bound );
|
||||
int sweepTarget = random.nextInt( bound );
|
||||
if ( target != sweepTarget ) {
|
||||
String targetStr = mAITipWords[target];
|
||||
mAITipWords[target] = mAITipWords[sweepTarget];
|
||||
mAITipWords[sweepTarget] = targetStr;
|
||||
}
|
||||
}
|
||||
Logger.d( TAG, "next generate sequence: " + mAITipWords );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ExtensionsPresenter( ExtensionsView view ) {
|
||||
super( view );
|
||||
mWeeks = getContext().getResources().getStringArray( R.array.module_ext_str_arr_week );
|
||||
mAITipWords = getContext().getResources().getStringArray( R.array.module_ext_str_arr_ai_tips );
|
||||
mWeatherModel = new WeatherModel( getContext() );
|
||||
}
|
||||
|
||||
@@ -68,6 +125,7 @@ public class ExtensionsPresenter extends Presenter< ExtensionsView > implements
|
||||
refreshTimeAndDate();
|
||||
mMsgCenter = ( IMogoMsgCenter ) ARouter.getInstance().build( MogoServicePaths.PATH_MSG_CENTER ).navigation();
|
||||
mMsgCenter.registerMsgCenterListener( this );
|
||||
mHasTipWords = generateTipWordsSequence();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,6 +173,22 @@ public class ExtensionsPresenter extends Presenter< ExtensionsView > implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume( @NonNull LifecycleOwner owner ) {
|
||||
super.onResume( owner );
|
||||
if ( mHasTipWords ) {
|
||||
mHandler.sendEmptyMessageDelayed( MSG_SWITCH_AI_TIP_WORDS, INTERVAL_TIME );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause( @NonNull LifecycleOwner owner ) {
|
||||
super.onPause( owner );
|
||||
if ( mHasTipWords ) {
|
||||
mHandler.removeMessages( MSG_SWITCH_AI_TIP_WORDS );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy( @NonNull LifecycleOwner owner ) {
|
||||
super.onDestroy( owner );
|
||||
|
||||
@@ -35,4 +35,11 @@ public interface ExtensionsView extends IView {
|
||||
* @param amount 消息数量
|
||||
*/
|
||||
void renderMsgInfo( boolean hasMsg, int amount );
|
||||
|
||||
/**
|
||||
* 更换小智语音提示词
|
||||
*
|
||||
* @param word
|
||||
*/
|
||||
void renderAITipWords( String word );
|
||||
}
|
||||
|
||||
@@ -20,4 +20,26 @@
|
||||
<string name="module_ext_str_exit_navi">退出导航</string>
|
||||
<string name="module_ext_str_continue_navi">继续导航</string>
|
||||
<string name="module_ext_str_exit_path">退出全览</string>
|
||||
|
||||
<string-array name="module_ext_str_arr_ai_tips">
|
||||
<item>你好小智,播放音乐</item>
|
||||
<item>你好小智,我要听音乐</item>
|
||||
<item>你好小智,播放赵磊的歌</item>
|
||||
<item>你好小智,我想听成都</item>
|
||||
<item>你好小智,打开导航</item>
|
||||
<item>你好小智,我要去拉萨</item>
|
||||
<item>你好小智,我要去加油站</item>
|
||||
<item>你好小智,导航去西单商场</item>
|
||||
<item>你好小智,打开行车记录仪</item>
|
||||
<item>你好小智,打开收音机</item>
|
||||
<item>你好小智,调频到97.4</item>
|
||||
<item>你好小智,调频到103.9</item>
|
||||
<item>你好小智,今天天气怎么样</item>
|
||||
<item>你好小智,北京明天天气怎么样</item>
|
||||
<item>你好小智,打开车聊聊</item>
|
||||
<item>你好小智,我想聊天</item>
|
||||
<item>你好小智,中关村堵不堵</item>
|
||||
<item>你好小智,打开探路</item>
|
||||
<item>你好小智,附近路况</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user