AndroidVoiceMessageService.java
Go to the documentation of this file.
00001 package org.ros.android.androidVoiceMessage;
00002 
00003 import java.net.URI;
00004 import java.net.URISyntaxException;
00005 import java.util.List;
00006 
00007 import org.ros.address.InetAddressFactory;
00008 import org.ros.android.androidVoiceMessage.AndroidVoiceMessageNode;
00009 import org.ros.node.DefaultNodeMainExecutor;
00010 import org.ros.node.NodeConfiguration;
00011 import org.ros.node.NodeMain;
00012 import org.ros.node.NodeMainExecutor;
00013 
00014 import android.app.IntentService;
00015 import android.app.PendingIntent;
00016 import android.content.Context;
00017 import android.content.Intent;
00018 import android.hardware.Sensor;
00019 import android.hardware.SensorManager;
00020 import android.os.Binder;
00021 import android.os.Bundle;
00022 import android.os.IBinder;
00023 import android.speech.SpeechRecognizer;
00024 import android.util.Log;
00025 import android.widget.TextView;
00026 import android.widget.ImageView;
00027 
00028 
00029 public class AndroidVoiceMessageService extends IntentService {
00030 
00031         SensorManager sensorManager;
00032         List<Sensor> sensors;
00033         AndroidVoiceMessageNode androidVoiceMessageNode;
00034         Intent mintent;
00035         NodeMainExecutor nodeMainExecutor;
00036         private String packageName;
00037 
00038         final IBinder binder = new MyBinder();
00039 
00040         public class MyBinder extends Binder {
00041                 AndroidVoiceMessageService getService() {
00042                         return AndroidVoiceMessageService.this;
00043                 }
00044         }
00045 
00046         public AndroidVoiceMessageService() {
00047                 super("AndroidVoiceMessageService");
00048         }
00049 
00050         @Override
00051         public IBinder onBind(Intent intent) {
00052                 mintent = intent;
00053                 sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
00054                 sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
00055                 return binder;
00056         }
00057 
00058         public void setNode(Context context, TextView textView, ImageView imageView, String packageName) {
00059                 showNotification();
00060                 this.packageName = packageName;
00061 
00062                 // We use this bundle
00063                 Bundle b = mintent.getExtras();
00064 
00065                 if (this.androidVoiceMessageNode == null) {
00066                         try {
00067                                 URI masterUri = new URI(b.getString("masterUri"));
00068                                 String hostLocal = InetAddressFactory.newNonLoopback()
00069                                                 .getHostAddress();
00070                                 nodeMainExecutor = DefaultNodeMainExecutor.newDefault();
00071 
00072                                 NodeConfiguration nodeConfiguration = NodeConfiguration
00073                                                 .newPublic(hostLocal, masterUri);
00074                                 nodeConfiguration.setMasterUri(masterUri);
00075                                 nodeConfiguration.setNodeName("android_voice_message");
00076 
00077                                 androidVoiceMessageNode = new AndroidVoiceMessageNode(
00078                                                 sensorManager, context, packageName);
00079                                 
00080                                 setView(textView,imageView);
00081                                 
00082                                 nodeMainExecutor.execute(androidVoiceMessageNode,
00083                                                 nodeConfiguration);
00084                         
00085 
00086                         } catch (URISyntaxException e) {
00087                                 e.printStackTrace();
00088                         }
00089                 }
00090         }
00091 
00092         public void setStart() {
00093                 androidVoiceMessageNode.setFlag(1);
00094         }
00095         
00096         public void setRawModeStart(AndroidVoiceMessageView androidVoiceMessageView) {
00097                 androidVoiceMessageNode.publishRawSound(androidVoiceMessageView);
00098         }
00099         
00100         public void setRawModeStop(){
00101                 androidVoiceMessageNode.stopRawSound();
00102         }
00103         
00104         public void setView(TextView textView,ImageView imageView){
00105                 androidVoiceMessageNode.setView(textView,imageView);
00106         }
00107         
00108         public void setMode(int mode) {
00109                 androidVoiceMessageNode.setMode(mode);
00110         }
00111 
00112         @Override
00113         protected void onHandleIntent(Intent intent) {
00114                 try {
00115                         Thread.sleep(10000);
00116                 } catch (InterruptedException e) {
00117                         e.printStackTrace();
00118                 }
00119 
00120         }
00121 
00122         private void showNotification() {
00123 
00124                 Intent intent = new Intent(this, AndroidVoiceMessage.class);
00125 
00126                 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
00127                                 | Intent.FLAG_ACTIVITY_SINGLE_TOP);
00128 
00129                 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
00130                                 intent, 0);
00131 
00132         }
00133 
00134         @Override
00135         public void onDestroy() {
00136                 nodeMainExecutor.shutdownNodeMain(androidVoiceMessageNode);
00137         }
00138 }


jsk_android_apps
Author(s): Kazuto Murase
autogenerated on Thu Jun 6 2019 18:03:46