Refactored android sense agent

revert-dabc3590
Milan Perera 8 years ago
parent 2eb18e304a
commit 76f52af4a5

@ -54,6 +54,7 @@ public class RegisterActivity extends Activity {
private EditText mHostView; private EditText mHostView;
private View mProgressView; private View mProgressView;
private View mLoginFormView; private View mLoginFormView;
private Button deviceRegisterButton;
private Handler mUiHandler = new Handler(); private Handler mUiHandler = new Handler();
@Override @Override
@ -73,7 +74,7 @@ public class RegisterActivity extends Activity {
AvailableSensorsInDevice availableSensorsInDevice = new AvailableSensorsInDevice(getApplicationContext()); AvailableSensorsInDevice availableSensorsInDevice = new AvailableSensorsInDevice(getApplicationContext());
availableSensorsInDevice.setContent(); availableSensorsInDevice.setContent();
Button deviceRegisterButton = (Button) findViewById(R.id.device_register_button); deviceRegisterButton = (Button) findViewById(R.id.device_register_button);
deviceRegisterButton.setOnClickListener(new OnClickListener() { deviceRegisterButton.setOnClickListener(new OnClickListener() {
@ -204,6 +205,7 @@ public class RegisterActivity extends Activity {
// and hide the relevant UI components. // and hide the relevant UI components.
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
deviceRegisterButton.setVisibility(show? View.VISIBLE : View.GONE);
} }
} }

@ -52,11 +52,8 @@ import java.util.List;
* This is an android service which publishes the data to the server. * This is an android service which publishes the data to the server.
*/ */
public class DataPublisherService extends Service { public class DataPublisherService extends Service {
private static final String TAG = DataPublisherService.class.getName(); private final String TAG = DataPublisherService.class.getName();
private static String KEY_TAG = "key"; private Context context;
private static String TIME_TAG = "time";
private static String VALUE_TAG = "value";
public static Context context;
@Nullable @Nullable
@Override @Override
@ -68,9 +65,9 @@ public class DataPublisherService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
context = this; context = this;
Log.d(TAG, "service started"); Log.d(TAG, "service started");
Runnable runnable = new Runnable() { // Runnable runnable = new Runnable() {
@Override // @Override
public void run() { // public void run() {
try { try {
List<Event> events = new ArrayList<>(); List<Event> events = new ArrayList<>();
//retrieve sensor data. //retrieve sensor data.
@ -315,10 +312,10 @@ public class DataPublisherService extends Service {
} catch (TransportHandlerException e) { } catch (TransportHandlerException e) {
Log.e(TAG, "Data Publish Failed", e); Log.e(TAG, "Data Publish Failed", e);
} }
} // }
}; // };
Thread dataUploaderThread = new Thread(runnable); // Thread dataUploaderThread = new Thread(runnable);
dataUploaderThread.start(); // dataUploaderThread.start();
return Service.START_NOT_STICKY; return Service.START_NOT_STICKY;
} }
} }

@ -183,8 +183,8 @@ public class LocationDataReader extends DataReader implements LocationListener {
double distance =CalculationByDistance(latitude, longitude, lat_old, lon_old)/1000; double distance =CalculationByDistance(latitude, longitude, lat_old, lon_old)/1000;
speed = (float)distance/(float)time; speed = (float)distance/(float)time;
Toast.makeText(mContext, longitude+"\n"+latitude+"\nDistance is: " // Toast.makeText(mContext, longitude+"\n"+latitude+"\nDistance is: "
+distance+"\nSpeed is: "+speed , Toast.LENGTH_SHORT).show(); // +distance+"\nSpeed is: "+speed , Toast.LENGTH_SHORT).show();
Intent intent = new Intent("speedUpdate"); Intent intent = new Intent("speedUpdate");

@ -73,7 +73,7 @@ public class ActivitySelectSensor extends AppCompatActivity
private ListView listView; private ListView listView;
private SensorManager sensorManager; private SensorManager sensorManager;
private ArrayList<Sensor> sensors = new ArrayList<>(); private ArrayList<Sensor> sensors = new ArrayList<>();
private EditText sessionIdText; // private EditText sessionIdText;
private RealTimeSensorReader sensorReader = null; private RealTimeSensorReader sensorReader = null;
private RealTimeSensorChangeReceiver realTimeSensorChangeReceiver = new RealTimeSensorChangeReceiver(); private RealTimeSensorChangeReceiver realTimeSensorChangeReceiver = new RealTimeSensorChangeReceiver();
private SupportedSensors supportedSensors = SupportedSensors.getInstance(); private SupportedSensors supportedSensors = SupportedSensors.getInstance();
@ -87,21 +87,21 @@ public class ActivitySelectSensor extends AppCompatActivity
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sessionIdText = (EditText) findViewById(R.id.sessionId); //sessionIdText = (EditText) findViewById(R.id.sessionId);
sessionIdText.setCursorVisible(false); // sessionIdText.setCursorVisible(false);
listView = (ListView) findViewById(R.id.senseListContainer); listView = (ListView) findViewById(R.id.senseListContainer);
verifyBluetooth(); //verifyBluetooth();
registerReceiver(realTimeSensorChangeReceiver, new IntentFilter("sensorDataMap")); registerReceiver(realTimeSensorChangeReceiver, new IntentFilter("sensorDataMap"));
sessionIdText.setOnClickListener(new View.OnClickListener() { // sessionIdText.setOnClickListener(new View.OnClickListener() {
@Override // @Override
public void onClick(View v) { // public void onClick(View v) {
sessionIdText.setCursorVisible(true); // sessionIdText.setCursorVisible(true);
//
} // }
}); // });
//Publish data //Publish data
FloatingActionButton fbtnPublishData = (FloatingActionButton) findViewById(R.id.publish); FloatingActionButton fbtnPublishData = (FloatingActionButton) findViewById(R.id.publish);
@ -126,33 +126,33 @@ public class ActivitySelectSensor extends AppCompatActivity
} }
}); });
FloatingActionButton fbtnSpeechRecongnizer = (FloatingActionButton) findViewById(R.id.speech); //FloatingActionButton fbtnSpeechRecongnizer = (FloatingActionButton) findViewById(R.id.speech);
fbtnSpeechRecongnizer.setOnClickListener(new View.OnClickListener() { // fbtnSpeechRecongnizer.setOnClickListener(new View.OnClickListener() {
@Override // @Override
public void onClick(View v) { // public void onClick(View v) {
String sessionId = sessionIdText.getText().toString(); // String sessionId = sessionIdText.getText().toString();
if (!sessionId.isEmpty()) { // if (!sessionId.isEmpty()) {
Intent intent = new Intent(getApplicationContext(), WordRecognitionActivity.class); // Intent intent = new Intent(getApplicationContext(), WordRecognitionActivity.class);
intent.putExtra("sessionId", sessionId); // intent.putExtra("sessionId", sessionId);
startActivity(intent); // startActivity(intent);
} else { // } else {
Toast.makeText(ActivitySelectSensor.this, "Please type a session id value", Toast.LENGTH_SHORT) // Toast.makeText(ActivitySelectSensor.this, "Please type a session id value", Toast.LENGTH_SHORT)
.show(); // .show();
} // }
//
} // }
}); // });
FloatingActionButton fbtnBeaconMonitor = (FloatingActionButton) findViewById(R.id.beacon); // FloatingActionButton fbtnBeaconMonitor = (FloatingActionButton) findViewById(R.id.beacon);
fbtnBeaconMonitor.setOnClickListener(new View.OnClickListener() { // fbtnBeaconMonitor.setOnClickListener(new View.OnClickListener() {
@Override // @Override
public void onClick(View v) { // public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), BeaconMonitoringActivity.class); // Intent intent = new Intent(getApplicationContext(), BeaconMonitoringActivity.class);
startActivity(intent); // startActivity(intent);
//
//
} // }
}); // });
sharedPreferences = getSharedPreferences(SupportedSensors.SELECTED_SENSORS, 0); sharedPreferences = getSharedPreferences(SupportedSensors.SELECTED_SENSORS, 0);
@ -313,43 +313,43 @@ public class ActivitySelectSensor extends AppCompatActivity
unregisterReceiver(realTimeSensorChangeReceiver); unregisterReceiver(realTimeSensorChangeReceiver);
} }
private void verifyBluetooth() { // private void verifyBluetooth() {
//
try { // try {
if (!BeaconManager.getInstanceForApplication(this).checkAvailability()) { // if (!BeaconManager.getInstanceForApplication(this).checkAvailability()) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this); // final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Bluetooth not enabled"); // builder.setTitle("Bluetooth not enabled");
builder.setMessage("Please enable bluetooth in settings and restart this application."); // builder.setMessage("Please enable bluetooth in settings and restart this application.");
builder.setPositiveButton(android.R.string.ok, null); // builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(new DialogInterface.OnDismissListener() { // builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
//
@Override // @Override
public void onDismiss(DialogInterface dialog) { // public void onDismiss(DialogInterface dialog) {
finish(); // finish();
System.exit(0); // System.exit(0);
} // }
//
}); // });
builder.show(); // builder.show();
//
} // }
} catch (RuntimeException e) { // } catch (RuntimeException e) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this); // final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Bluetooth LE not available"); // builder.setTitle("Bluetooth LE not available");
builder.setMessage("Sorry, this device does not support Bluetooth LE."); // builder.setMessage("Sorry, this device does not support Bluetooth LE.");
builder.setPositiveButton(android.R.string.ok, null); // builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(new DialogInterface.OnDismissListener() { // builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
//
@Override // @Override
public void onDismiss(DialogInterface dialog) { // public void onDismiss(DialogInterface dialog) {
finish(); // finish();
System.exit(0); // System.exit(0);
} // }
//
}); // });
builder.show(); // builder.show();
//
} // }
//
} // }
} }

@ -57,6 +57,7 @@ public class SenseClientAsyncExecutor extends AsyncTask<String, Void, Map<String
private final static String TAG = "SenseService Client"; private final static String TAG = "SenseService Client";
private static final String STATUS = "status"; private static final String STATUS = "status";
private final String PASSWORD_GRANT_TYPE = "password"; private final String PASSWORD_GRANT_TYPE = "password";
private final String SCOPE = "perm:android-sense:enroll";
private final static String DEVICE_NAME = Build.MANUFACTURER + " " + Build.MODEL; private final static String DEVICE_NAME = Build.MANUFACTURER + " " + Build.MODEL;
private Context context; private Context context;
@ -117,7 +118,7 @@ public class SenseClientAsyncExecutor extends AsyncTask<String, Void, Map<String
new BasicAuthRequestInterceptor(apiApplicationKey.getConsumerKey(), apiApplicationKey.getConsumerSecret())) new BasicAuthRequestInterceptor(apiApplicationKey.getConsumerKey(), apiApplicationKey.getConsumerSecret()))
.contract(new JAXRSContract()).encoder(new JacksonEncoder()).decoder(new JacksonDecoder()) .contract(new JAXRSContract()).encoder(new JacksonEncoder()).decoder(new JacksonDecoder())
.target(TokenIssuerService.class, endpoint); .target(TokenIssuerService.class, endpoint);
accessTokenInfo = tokenIssuerService.getToken(PASSWORD_GRANT_TYPE, username, password, "device_" + deviceId); accessTokenInfo = tokenIssuerService.getToken(PASSWORD_GRANT_TYPE, username, password, "device_" + deviceId, SCOPE);
//DeviceRegister //DeviceRegister
AndroidSenseManagerService androidSenseManagerService = Feign.builder().client(disableHostnameVerification) AndroidSenseManagerService androidSenseManagerService = Feign.builder().client(disableHostnameVerification)

@ -29,7 +29,7 @@ public interface TokenIssuerService {
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
AccessTokenInfo getToken(@QueryParam("grant_type") String grant, @QueryParam("username") String username, AccessTokenInfo getToken(@QueryParam("grant_type") String grant, @QueryParam("username") String username,
@QueryParam("password") String password, @QueryParam("deviceId") String deviceId); @QueryParam("password") String password, @QueryParam("deviceId") String deviceId, @QueryParam("scope") String scope);
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)

@ -26,41 +26,65 @@
<include layout="@layout/content_activity_select_sensor"/> <include layout="@layout/content_activity_select_sensor"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="fill_parent"
android:layout_gravity="bottom|center" android:layout_gravity="bottom|center"
android:layout_height="wrap_content" > android:layout_height="100dp"
android:layout_margin="20dp"
<android.support.design.widget.FloatingActionButton android:orientation="horizontal">
android:id="@+id/beacon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/beacon"/>
<android.support.design.widget.FloatingActionButton <!--<RelativeLayout-->
android:id="@+id/addSensors" <!--android:layout_width="0dp"-->
android:layout_width="wrap_content" <!--android:layout_height="match_parent"-->
android:layout_height="wrap_content" <!--android:layout_weight="0.25"-->
android:layout_margin="@dimen/fab_margin" <!--&gt;-->
android:src="@android:drawable/ic_input_add"/> <!--<android.support.design.widget.FloatingActionButton-->
<!--android:id="@+id/beacon"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_margin="15dp"-->
<!--android:src="@drawable/beacon"/>-->
<!--</RelativeLayout>-->
<android.support.design.widget.FloatingActionButton <RelativeLayout
android:id="@+id/speech" android:layout_width="0dp"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_height="wrap_content" android:layout_weight="0.5"
android:layout_margin="@dimen/fab_margin" >
android:src="@drawable/mic"/> <android.support.design.widget.FloatingActionButton
android:id="@+id/addSensors"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:layout_centerInParent="true"
android:src="@android:drawable/ic_input_add"/>
</RelativeLayout>
<!--<RelativeLayout-->
<!--android:layout_width="0dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_weight="0.25"-->
<!--&gt;-->
<!--<android.support.design.widget.FloatingActionButton-->
<!--android:id="@+id/speech"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_margin="15dp"-->
<!--android:src="@drawable/mic"/>-->
<!--</RelativeLayout>-->
<android.support.design.widget.FloatingActionButton <RelativeLayout
android:id="@+id/publish" android:layout_width="0dp"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_height="wrap_content" android:layout_weight="0.5"
android:layout_margin="@dimen/fab_margin" >
android:adjustViewBounds="false" <android.support.design.widget.FloatingActionButton
android:src="@drawable/pushtoserver"/> android:id="@+id/publish"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:layout_centerInParent="true"
android:src="@drawable/pushtoserver"/>
</RelativeLayout>
</LinearLayout> </LinearLayout>
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>

@ -11,18 +11,18 @@
tools:context="org.wso2.carbon.iot.android.sense.realtimeviewer.ActivitySelectSensor" tools:context="org.wso2.carbon.iot.android.sense.realtimeviewer.ActivitySelectSensor"
android:id="@+id/parentContainer"> android:id="@+id/parentContainer">
<EditText <!--<EditText-->
android:layout_width="match_parent" <!--android:layout_width="match_parent"-->
android:layout_height="wrap_content" android:hint="@string/sessionId" <!--android:layout_height="wrap_content" android:hint="@string/sessionId"-->
android:id="@+id/sessionId" <!--android:id="@+id/sessionId"-->
android:inputType="text" <!--android:inputType="text"-->
android:maxLines="1" android:singleLine="true"/> <!--android:maxLines="1" android:singleLine="true"/>-->
<ListView <ListView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/senseListContainer" android:id="@+id/senseListContainer"
android:layout_below="@+id/sessionId"> >
</ListView> </ListView>
</RelativeLayout> </RelativeLayout>

@ -3,8 +3,8 @@
<item android:id="@+id/select" android:icon="@android:drawable/ic_menu_agenda" <item android:id="@+id/select" android:icon="@android:drawable/ic_menu_agenda"
android:title="Sensors" /> android:title="Sensors" />
<item android:id="@+id/speech_recognizer" android:icon="@android:drawable/ic_menu_agenda" <!--<item android:id="@+id/speech_recognizer" android:icon="@android:drawable/ic_menu_agenda"-->
android:title="Speech Recognizer" /> <!--android:title="Speech Recognizer" />-->
<!--<group android:checkableBehavior="single">--> <!--<group android:checkableBehavior="single">-->
<!-- --> <!-- -->

@ -6,7 +6,7 @@ buildscript {
maven { url 'https://repo.eclipse.org/content/repositories/paho-releases/' } maven { url 'https://repo.eclipse.org/content/repositories/paho-releases/' }
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.android.tools.build:gradle:2.2.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

@ -1,6 +1,6 @@
#Wed May 11 14:40:10 IST 2016 #Mon Jan 09 12:13:26 IST 2017
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

@ -22,29 +22,29 @@
<Feature code="keywords"> <Feature code="keywords">
<Name>Add Keywords</Name> <Name>Add Keywords</Name>
<Description>Send keywords to the device</Description> <Description>Send keywords to the device</Description>
<Operation context="/android_sense/device/{deviceId}/words" method="POST"> <!--<Operation context="/android_sense/device/{deviceId}/words" method="POST">-->
<QueryParameters> <!--<QueryParameters>-->
<Parameter>keywords</Parameter> <!--<Parameter>keywords</Parameter>-->
</QueryParameters> <!--</QueryParameters>-->
</Operation> <!--</Operation>-->
</Feature> </Feature>
<Feature code="threshold"> <Feature code="threshold">
<Name>Add Threshold</Name> <Name>Add Threshold</Name>
<Description>Send Threshold to the device</Description> <Description>Send Threshold to the device</Description>
<Operation context="/android_sense/device/{deviceId}/words/threshold" method="POST"> <!--<Operation context="/android_sense/device/{deviceId}/words/threshold" method="POST">-->
<QueryParameters> <!--<QueryParameters>-->
<Parameter>threshold</Parameter> <!--<Parameter>threshold</Parameter>-->
</QueryParameters> <!--</QueryParameters>-->
</Operation> <!--</Operation>-->
</Feature> </Feature>
<Feature code="remove_words"> <Feature code="remove_words">
<Name>Remove words</Name> <Name>Remove words</Name>
<Description>Remove Threshold from the device</Description> <Description>Remove Threshold from the device</Description>
<Operation context="/android_sense/device/{deviceId}/words" method="DELETE"> <!--<Operation context="/android_sense/device/{deviceId}/words" method="DELETE">-->
<QueryParameters> <!--<QueryParameters>-->
<Parameter>words</Parameter> <!--<Parameter>words</Parameter>-->
</QueryParameters> <!--</QueryParameters>-->
</Operation> <!--</Operation>-->
</Feature> </Feature>
</Features> </Features>

Loading…
Cancel
Save