diff --git a/enabler/res/drawable/bluetooth_white.png b/enabler/res/drawable/bluetooth_white.png new file mode 100644 index 000000000..9f8d1feea Binary files /dev/null and b/enabler/res/drawable/bluetooth_white.png differ diff --git a/enabler/res/drawable/network_white.png b/enabler/res/drawable/network_white.png new file mode 100644 index 000000000..e214daa20 Binary files /dev/null and b/enabler/res/drawable/network_white.png differ diff --git a/enabler/res/drawable/play_from_file_white.png b/enabler/res/drawable/play_from_file_white.png new file mode 100644 index 000000000..298014e96 Binary files /dev/null and b/enabler/res/drawable/play_from_file_white.png differ diff --git a/enabler/res/drawable/questionmark_white.png b/enabler/res/drawable/questionmark_white.png new file mode 100644 index 000000000..ca05b0ad7 Binary files /dev/null and b/enabler/res/drawable/questionmark_white.png differ diff --git a/enabler/res/drawable/usb_white.png b/enabler/res/drawable/usb_white.png new file mode 100644 index 000000000..18b8bcb47 Binary files /dev/null and b/enabler/res/drawable/usb_white.png differ diff --git a/enabler/res/drawable/warning.png b/enabler/res/drawable/warning.png new file mode 100644 index 000000000..e838460d9 Binary files /dev/null and b/enabler/res/drawable/warning.png differ diff --git a/enabler/res/layout-land/main.xml b/enabler/res/layout-land/main.xml index 9d58d442f..a4c57fc45 100644 --- a/enabler/res/layout-land/main.xml +++ b/enabler/res/layout-land/main.xml @@ -6,20 +6,64 @@ android:paddingRight="5sp" android:orientation="vertical"> + + + + + - - - - - + android:text="@string/status_label"/> + + + + + + + + + + + + + @@ -31,29 +75,4 @@ style="@style/ItemData"/> - - - - - - - - - - - diff --git a/enabler/res/layout/main.xml b/enabler/res/layout/main.xml index b59bab304..499a951de 100644 --- a/enabler/res/layout/main.xml +++ b/enabler/res/layout/main.xml @@ -6,20 +6,64 @@ android:paddingRight="5sp" android:orientation="vertical"> + + + + + - - - - - + android:text="@string/status_label"/> + + + + + + + + + + + + + @@ -29,24 +73,5 @@ - - - - - - - - - - + diff --git a/enabler/res/values/strings.xml b/enabler/res/values/strings.xml index d1f067fba..38872381e 100644 --- a/enabler/res/values/strings.xml +++ b/enabler/res/values/strings.xml @@ -2,9 +2,15 @@ OpenXC Enabler Status - Vehicle Service: + Active Connections: Recording Status: Messages Received: + Unknown + File + Bluetooth + USB + Network + None Settings Recording @@ -44,4 +50,6 @@ Version Version Number application_version + VehicleService not running. + Warning diff --git a/enabler/res/values/styles.xml b/enabler/res/values/styles.xml index b6df4033c..68d1a1cc1 100644 --- a/enabler/res/values/styles.xml +++ b/enabler/res/values/styles.xml @@ -36,6 +36,18 @@ right + + + + + + + + diff --git a/enabler/src/com/openxc/enabler/OpenXcEnablerActivity.java b/enabler/src/com/openxc/enabler/OpenXcEnablerActivity.java index 71da8b382..2ac52e08f 100644 --- a/enabler/src/com/openxc/enabler/OpenXcEnablerActivity.java +++ b/enabler/src/com/openxc/enabler/OpenXcEnablerActivity.java @@ -14,7 +14,7 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; -import android.widget.ListView; +import android.view.View; import android.widget.TextView; import com.openxc.VehicleManager; @@ -42,10 +42,14 @@ public class OpenXcEnablerActivity extends Activity { private static String TAG = "OpenXcEnablerActivity"; - private TextView mVehicleManagerStatusView; + private View mServiceNotRunningWarningView; private TextView mMessageCountView; - private ListView mSourceListView; - private ListView mSinkListView; + private View mUnknownConnIV; + private View mBluetoothConnIV; + private View mUsbConnIV; + private View mNetworkConnIV; + private View mFileConnIV; + private View mNoneConnView; private TimerTask mUpdateMessageCountTask; private TimerTask mUpdatePipelineStatusTask; private Timer mTimer; @@ -63,7 +67,7 @@ public void run() { mVehicleManager.waitUntilBound(); OpenXcEnablerActivity.this.runOnUiThread(new Runnable() { public void run() { - mVehicleManagerStatusView.setText("Running"); + mServiceNotRunningWarningView.setVisibility(View.GONE); } }); } @@ -73,7 +77,8 @@ public void run() { OpenXcEnablerActivity.this, mMessageCountView); mUpdatePipelineStatusTask = new PipelineStatusUpdateTask( mVehicleManager, OpenXcEnablerActivity.this, - mSourceListView, mSinkListView); + mUnknownConnIV, mFileConnIV, mNetworkConnIV, + mBluetoothConnIV, mUsbConnIV, mNoneConnView); mTimer = new Timer(); mTimer.schedule(mUpdateMessageCountTask, 100, 1000); mTimer.schedule(mUpdatePipelineStatusTask, 100, 1000); @@ -84,7 +89,7 @@ public void onServiceDisconnected(ComponentName className) { mVehicleManager = null; OpenXcEnablerActivity.this.runOnUiThread(new Runnable() { public void run() { - mVehicleManagerStatusView.setText("Not running"); + mServiceNotRunningWarningView.setVisibility(View.VISIBLE); } }); } @@ -99,15 +104,18 @@ public void onCreate(Bundle savedInstanceState) { startService(new Intent(this, VehicleManager.class)); startService(new Intent(this, PreferenceManagerService.class)); - mVehicleManagerStatusView = (TextView) findViewById( - R.id.vehicle_service_status); + mServiceNotRunningWarningView = findViewById(R.id.service_not_running_bar); mMessageCountView = (TextView) findViewById(R.id.message_count); - mSourceListView = (ListView) findViewById(R.id.source_list); - mSinkListView = (ListView) findViewById(R.id.sink_list); + mBluetoothConnIV = findViewById(R.id.connection_bluetooth); + mUsbConnIV = findViewById(R.id.connection_usb); + mFileConnIV = findViewById(R.id.connection_file); + mNetworkConnIV = findViewById(R.id.connection_network); + mUnknownConnIV = findViewById(R.id.connection_unknown); + mNoneConnView = findViewById(R.id.connection_none); OpenXcEnablerActivity.this.runOnUiThread(new Runnable() { public void run() { - mVehicleManagerStatusView.setText("Not running"); + mServiceNotRunningWarningView.setVisibility(View.VISIBLE); } }); } diff --git a/enabler/src/com/openxc/enabler/PipelineStatusUpdateTask.java b/enabler/src/com/openxc/enabler/PipelineStatusUpdateTask.java index de79e974d..f3d28ce74 100644 --- a/enabler/src/com/openxc/enabler/PipelineStatusUpdateTask.java +++ b/enabler/src/com/openxc/enabler/PipelineStatusUpdateTask.java @@ -1,55 +1,94 @@ package com.openxc.enabler; +import java.util.List; import java.util.TimerTask; import android.app.Activity; import com.openxc.VehicleManager; -import android.widget.ListView; -import android.widget.ArrayAdapter; +import com.openxc.interfaces.InterfaceType; + +import android.view.View; public class PipelineStatusUpdateTask extends TimerTask { - private VehicleManager mVehicleManager; + private VehicleManager mVehicleManager; private Activity mActivity; - private ListView mSourceListView; - private ListView mSinkListView; - private ArrayAdapter mSourceListAdapter; - private ArrayAdapter mSinkListAdapter; + private View mUnknownConnView; + private View mNetworkConnView; + private View mBluetoothConnView; + private View mUsbConnView; + private View mFileConnView; + private View mNoneConnView; public PipelineStatusUpdateTask(VehicleManager vehicleService, - Activity activity, ListView sourceListView, ListView sinkListView) { + Activity activity, View unknownConnIV, View fileConnIV, + View networkConnIV, View bluetoothConnIV, View usbConnIV, + View noneConnView) { mVehicleManager = vehicleService; mActivity = activity; - mSourceListView = sourceListView; - mSinkListView = sinkListView; - - mSourceListAdapter = new ArrayAdapter(mActivity, - android.R.layout.simple_list_item_1); - mSourceListView.setAdapter(mSourceListAdapter); + mUnknownConnView = unknownConnIV; + mFileConnView = fileConnIV; + mNetworkConnView = networkConnIV; + mBluetoothConnView = bluetoothConnIV; + mUsbConnView = usbConnIV; + mNoneConnView = noneConnView; + } - mSinkListAdapter = new ArrayAdapter(mActivity, - android.R.layout.simple_list_item_1); - mSinkListView.setAdapter(mSinkListAdapter); + private void setIconVisibility(InterfaceType interfaceType, final View icon, + List activeInterfaceTypes){ + // If active and not visible => make visible + if(activeInterfaceTypes.contains(interfaceType) + && icon.getVisibility() != View.VISIBLE){ + mActivity.runOnUiThread(new Runnable(){ + @Override + public void run() { + icon.setVisibility(View.VISIBLE); + } + }); + } + + // If not active and not gone => make gone + if(!activeInterfaceTypes.contains(interfaceType) + && (icon.getVisibility() != View.GONE)){ + mActivity.runOnUiThread(new Runnable(){ + @Override + public void run() { + icon.setVisibility(View.GONE); + } + }); + } } + + public void run() { - public void run() { - mActivity.runOnUiThread(new Runnable() { - public void run() { - mSourceListAdapter.clear(); - // ArrayAdapter has a nice addAll method, but it's only - // supported in API 11 and greater (i.e. not 2.3). - for(String summary : mVehicleManager.getSourceSummaries()) { - mSourceListAdapter.add(summary); - } - mSourceListAdapter.notifyDataSetChanged(); - - mSinkListAdapter.clear(); - // See about RE: addAll - for(String summary : mVehicleManager.getSinkSummaries()) { - mSinkListAdapter.add(summary); - } - mSinkListAdapter.notifyDataSetChanged(); - } - }); + List activeInterfaceTypes = mVehicleManager.getActiveSourceTypes(); + + if(activeInterfaceTypes.isEmpty()){ + mActivity.runOnUiThread(new Runnable(){ + @Override + public void run() { + mNoneConnView.setVisibility(View.VISIBLE); + + mBluetoothConnView.setVisibility(View.GONE); + mFileConnView.setVisibility(View.GONE); + mNetworkConnView.setVisibility(View.GONE); + mUsbConnView.setVisibility(View.GONE); + mUnknownConnView.setVisibility(View.GONE); + } + }); + } else { + mActivity.runOnUiThread(new Runnable(){ + @Override + public void run() { + mNoneConnView.setVisibility(View.GONE); + } + }); + + setIconVisibility(InterfaceType.BLUETOOTH, mBluetoothConnView, activeInterfaceTypes); + setIconVisibility(InterfaceType.FILE, mFileConnView, activeInterfaceTypes); + setIconVisibility(InterfaceType.NETWORK, mNetworkConnView, activeInterfaceTypes); + setIconVisibility(InterfaceType.USB, mUsbConnView, activeInterfaceTypes); + setIconVisibility(InterfaceType.UNKNOWN, mUnknownConnView, activeInterfaceTypes); + } } } diff --git a/openxc/src/com/openxc/VehicleManager.java b/openxc/src/com/openxc/VehicleManager.java index 36b89c135..994c24597 100644 --- a/openxc/src/com/openxc/VehicleManager.java +++ b/openxc/src/com/openxc/VehicleManager.java @@ -19,6 +19,7 @@ import android.widget.Toast; import com.google.common.base.Objects; +import com.openxc.interfaces.InterfaceType; import com.openxc.interfaces.VehicleInterface; import com.openxc.interfaces.VehicleInterfaceManagerUtils; import com.openxc.measurements.BaseMeasurement; @@ -474,6 +475,44 @@ public List getSinkSummaries() { } return sinks; } + + /** + * Returns a list of all active interface types + * + * @return A list of the InterfaceTypes actively connected. + */ + public List getActiveSourceTypes(){ + ArrayList sources = new ArrayList(); + for(VehicleDataSource source : mSources) { + + Log.d(TAG, "VehicleDataSource: " + source.toString()); + + if(source.isConnected()){ + Log.d(TAG, "Connected VehicleDataSource: " + source.toString()); + + sources.add(InterfaceType.interfaceTypeFromClass(source)); + } + } + + for(VehicleDataSource source : mPipeline.getSources()) { + if(source.isConnected()){ + sources.add(InterfaceType.interfaceTypeFromClass(source)); + } + } + + if(mRemoteService != null) { + try { + //sources.addAll(mRemoteService.getActiveSourceTypes()); + for(String sourceTypeString:mRemoteService.getActiveSourceTypeStrings()){ + sources.add(InterfaceType.interfaceTypeFromString(sourceTypeString)); + } + } catch(RemoteException e) { + Log.w(TAG, "Unable to retreive remote source summaries", e); + } + + } + return sources; + } /** * Read the number of messages received by the vehicle service. diff --git a/openxc/src/com/openxc/interfaces/InterfaceType.java b/openxc/src/com/openxc/interfaces/InterfaceType.java new file mode 100644 index 000000000..6185527a6 --- /dev/null +++ b/openxc/src/com/openxc/interfaces/InterfaceType.java @@ -0,0 +1,61 @@ +package com.openxc.interfaces; + +import com.openxc.interfaces.bluetooth.BluetoothVehicleInterface; +import com.openxc.interfaces.network.NetworkVehicleInterface; +import com.openxc.interfaces.usb.UsbVehicleInterface; +import com.openxc.sources.VehicleDataSource; +import com.openxc.sources.trace.TraceVehicleDataSource; + +public enum InterfaceType { + BLUETOOTH("BLUETOOTH"), + FILE("FILE"), + NETWORK("NETWORK"), + USB("USB"), + UNKNOWN("UNKNOWN"); + + private String stringValue; + private InterfaceType(String toString){ + stringValue = toString; + } + + public static InterfaceType interfaceTypeFromClass( + VehicleDataSource source){ + + if(source == null){ + return UNKNOWN; + } else if(source instanceof BluetoothVehicleInterface){ + return BLUETOOTH; + } else if(source instanceof TraceVehicleDataSource){ + return FILE; + } else if(source instanceof NetworkVehicleInterface){ + return NETWORK; + } else if(source instanceof UsbVehicleInterface){ + return USB; + } else { + return UNKNOWN; + } + } + + public static InterfaceType interfaceTypeFromString( + String vInterfaceString){ + + if(vInterfaceString == null){ + return UNKNOWN; + } else if(vInterfaceString.equalsIgnoreCase("BLUETOOTH")){ + return BLUETOOTH; + } else if(vInterfaceString.equalsIgnoreCase("FILE")){ + return FILE; + } else if(vInterfaceString.equalsIgnoreCase("NETWORK")){ + return NETWORK; + } else if(vInterfaceString.equalsIgnoreCase("USB")){ + return USB; + } else { + return UNKNOWN; + } + } + + @Override + public String toString(){ + return stringValue; + } +} diff --git a/openxc/src/com/openxc/remote/VehicleService.java b/openxc/src/com/openxc/remote/VehicleService.java index b3d1ab661..a339cedf9 100644 --- a/openxc/src/com/openxc/remote/VehicleService.java +++ b/openxc/src/com/openxc/remote/VehicleService.java @@ -13,6 +13,7 @@ import com.openxc.DataPipeline; import com.openxc.R; +import com.openxc.interfaces.InterfaceType; import com.openxc.interfaces.VehicleInterface; import com.openxc.interfaces.VehicleInterfaceException; import com.openxc.interfaces.VehicleInterfaceFactory; @@ -189,6 +190,16 @@ public List getSourceSummaries() { } return sources; } + + public List getActiveSourceTypeStrings() { + ArrayList sources = new ArrayList(); + for(VehicleDataSource source : mPipeline.getSources()) { + if(source.isConnected()){ + sources.add(InterfaceType.interfaceTypeFromClass(source).toString()); + } + } + return sources; + } public List getSinkSummaries() { ArrayList sinks = new ArrayList(); diff --git a/openxc/src/com/openxc/remote/VehicleServiceInterface.aidl b/openxc/src/com/openxc/remote/VehicleServiceInterface.aidl index cf3cdb494..7c1e3972a 100644 --- a/openxc/src/com/openxc/remote/VehicleServiceInterface.aidl +++ b/openxc/src/com/openxc/remote/VehicleServiceInterface.aidl @@ -68,4 +68,5 @@ interface VehicleServiceInterface { List getSourceSummaries(); List getSinkSummaries(); + List getActiveSourceTypeStrings(); } diff --git a/openxc/src/com/openxc/sources/trace/TraceVehicleDataSource.java b/openxc/src/com/openxc/sources/trace/TraceVehicleDataSource.java index 3e768d4d7..bc54f7d11 100644 --- a/openxc/src/com/openxc/sources/trace/TraceVehicleDataSource.java +++ b/openxc/src/com/openxc/sources/trace/TraceVehicleDataSource.java @@ -126,7 +126,11 @@ public TraceVehicleDataSource(Context context, URI filename, boolean loop) @Override public boolean isConnected() { - return mRunning && super.isConnected(); + // TODO BaseVehicleDataSource.isConnected() always returns false do + // not us its result until this is fixed + //return mRunning && super.isConnected(); + + return mRunning; } /**