opt
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.mogo.service.impl.voice;
|
||||
package com.mogo.service.impl.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -8,11 +8,10 @@ import android.os.Message;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.mogo.service.voice.IMogoVoiceListener;
|
||||
import com.mogo.service.voice.IMogoVoiceManager;
|
||||
import com.mogo.service.intent.IMogoIntentListener;
|
||||
import com.mogo.service.intent.IMogoIntentManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -23,9 +22,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class VoiceManager implements IMogoVoiceManager {
|
||||
public class IntentManager implements IMogoIntentManager {
|
||||
|
||||
private static volatile VoiceManager sInstance;
|
||||
private static volatile IntentManager sInstance;
|
||||
|
||||
public static final int MSG_COMMAND_RECEIVED = 2000;
|
||||
|
||||
@@ -36,9 +35,9 @@ public class VoiceManager implements IMogoVoiceManager {
|
||||
super.handleMessage( msg );
|
||||
if ( msg.what == MSG_COMMAND_RECEIVED ) {
|
||||
MsgObject object = ( ( MsgObject ) msg.obj );
|
||||
List< IMogoVoiceListener > listeners = mListeners.get( object.getCommand() );
|
||||
List< IMogoIntentListener > listeners = mListeners.get( object.getCommand() );
|
||||
if ( listeners != null && !listeners.isEmpty() ) {
|
||||
for ( IMogoVoiceListener listener : listeners ) {
|
||||
for ( IMogoIntentListener listener : listeners ) {
|
||||
listener.onIntentReceived( object.getCommand(), object.getIntent() );
|
||||
}
|
||||
}
|
||||
@@ -46,14 +45,14 @@ public class VoiceManager implements IMogoVoiceManager {
|
||||
}
|
||||
};
|
||||
|
||||
private VoiceManager() {
|
||||
private IntentManager() {
|
||||
}
|
||||
|
||||
public static VoiceManager getInstance() {
|
||||
public static IntentManager getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( VoiceManager.class ) {
|
||||
synchronized ( IntentManager.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new VoiceManager();
|
||||
sInstance = new IntentManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,18 +64,17 @@ public class VoiceManager implements IMogoVoiceManager {
|
||||
}
|
||||
|
||||
|
||||
private Map< String, List< IMogoVoiceListener > > mListeners = new ConcurrentHashMap<>();
|
||||
private Map< String, List< IMogoIntentListener > > mListeners = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public void registerIntentListener( String command, IMogoVoiceListener listener ) {
|
||||
if ( listener == null || command == null ) {
|
||||
public void registerIntentListener( String intent, IMogoIntentListener listener ) {
|
||||
if ( listener == null || intent == null ) {
|
||||
return;
|
||||
}
|
||||
if ( !mListeners.containsKey( command ) ) {
|
||||
mListeners.put( command, new ArrayList<>() );
|
||||
if ( !mListeners.containsKey( intent ) ) {
|
||||
mListeners.put( intent, new ArrayList<>() );
|
||||
}
|
||||
mListeners.get( command ).add( listener );
|
||||
|
||||
mListeners.get( intent ).add( listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.mogo.service.impl.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.intent.IMogoIntentListener;
|
||||
import com.mogo.service.intent.IMogoIntentManager;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-09
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
@Route( path = MogoServicePaths.PATH_INTENT_MANAGER )
|
||||
public class MogoIntentManager implements IMogoIntentManager {
|
||||
|
||||
@Override
|
||||
public void unregisterIntentListener( String command ) {
|
||||
IntentManager.getInstance().unregisterIntentListener( command );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke( String command, Intent intent ) {
|
||||
IntentManager.getInstance().invoke( command, intent );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIntentListener( String intent, IMogoIntentListener listener ) {
|
||||
IntentManager.getInstance().registerIntentListener( intent, listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
IntentManager.getInstance().init( context );
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
package com.mogo.service.impl.voice;
|
||||
package com.mogo.service.impl.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.voice.IMogoVoiceListener;
|
||||
import com.mogo.service.intent.IMogoIntentListener;
|
||||
import com.mogo.service.voice.IMogoVoiceManager;
|
||||
import com.zhidao.auto.platform.voice.VoiceClient;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -20,23 +18,23 @@ import com.zhidao.auto.platform.voice.VoiceClient;
|
||||
@Route( path = MogoServicePaths.PATH_VOICE_MANAGER )
|
||||
public class MogoVoiceManager implements IMogoVoiceManager {
|
||||
|
||||
@Override
|
||||
public void registerIntentListener( String command, IMogoVoiceListener listener ) {
|
||||
VoiceManager.getInstance().registerIntentListener( command, listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterIntentListener( String command ) {
|
||||
VoiceManager.getInstance().unregisterIntentListener( command );
|
||||
IntentManager.getInstance().unregisterIntentListener( command );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke( String command, Intent intent ) {
|
||||
VoiceManager.getInstance().invoke( command, intent );
|
||||
IntentManager.getInstance().invoke( command, intent );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIntentListener( String intent, IMogoIntentListener listener ) {
|
||||
IntentManager.getInstance().registerIntentListener( intent, listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
VoiceManager.getInstance().init( context );
|
||||
IntentManager.getInstance().init( context );
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.service.impl.voice;
|
||||
package com.mogo.service.impl.intent;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
Reference in New Issue
Block a user