Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 package edu.nimbus.glass;
00017
00018 import android.app.PendingIntent;
00019 import android.app.Service;
00020 import android.content.Intent;
00021 import android.os.Binder;
00022 import android.os.IBinder;
00023 import android.widget.RemoteViews;
00024 import android.widget.TextView;
00025
00026 import com.google.android.glass.timeline.LiveCard;
00027 import com.google.android.glass.timeline.TimelineManager;
00028
00029 import de.tavendo.autobahn.WebSocketConnection;
00030 import de.tavendo.autobahn.WebSocketException;
00031
00032
00038 public class ROSMonitorService extends Service {
00039
00040
00042 private static final String LIVE_CARD_ID = "ROS_WARNING";
00044 public final static String HOST_ADDRESS = "ws://10.214.32.10:9090";
00045
00046
00048 private TimelineManager mTimelineManager;
00049 private LiveCard mLiveCard;
00050 private final ROSMonitorBinder mBinder = new ROSMonitorBinder();
00051
00052
00054 private ROSMonitorManager mROSMonitor;
00055 private WebSocketConnection mConnection;
00056
00057
00062 public class ROSMonitorBinder extends Binder {
00063
00064 public void remove_card() {
00065 ROSMonitorService.this.removeLiveCard();
00066 }
00067
00068
00069 }
00070
00071 @Override
00072 public void onCreate(){
00073 if(mConnection==null){
00074 mConnection = new WebSocketConnection();
00075 }
00076
00077 }
00078
00088 @Override
00089 public int onStartCommand(Intent intent, int flags, int startId) {
00090 mTimelineManager = TimelineManager.from(this);
00091
00092
00093
00094 try {
00095 mROSMonitor = new ROSMonitorManager(this, mConnection);
00096 mConnection.connect(HOST_ADDRESS,mROSMonitor );
00097 } catch (WebSocketException e) {
00098 e.printStackTrace();
00099 }
00100
00101
00102 return START_STICKY;
00103 }
00104
00105
00106 @Override
00107 public void onDestroy() {
00108
00109
00110 if (mLiveCard != null && mLiveCard.isPublished()) {
00111 mLiveCard.unpublish();
00112 mLiveCard = null;
00113 }
00114
00115 mConnection.disconnect();
00116 mConnection = null;
00117 super.onDestroy();
00118 }
00119
00120 @Override
00121 public IBinder onBind(Intent intent) {
00122 return mBinder;
00123 }
00124
00130 public void createWarning(String error_message) {
00131
00132 if (mLiveCard == null){
00133 mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_ID);
00134 }
00135
00136 if(mLiveCard.isPublished()){
00137 mLiveCard.unpublish();
00138 }
00139
00140 TextView text = new TextView(this);
00141 text.setText(error_message);
00142 RemoteViews views = new RemoteViews(getBaseContext().getPackageName(), R.layout.warn_card);
00143 views.setTextViewText(R.id.warn_text, error_message );
00144 mLiveCard.setViews(views);
00145
00146
00147 Intent intent = new Intent(this, MenuActivity.class);
00148 mLiveCard.setAction(PendingIntent.getActivity(this, 0, intent, 0));
00149 mLiveCard.publish(LiveCard.PublishMode.REVEAL);
00150 }
00151
00152
00156 public void removeLiveCard(){
00157 if(mLiveCard != null){
00158 mLiveCard.unpublish();
00159 mROSMonitor.setWarning("");
00160 }
00161
00162 }
00163 }
00164