mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Refactored android sense agent
This commit is contained in:
parent
2eb18e304a
commit
76f52af4a5
@ -54,6 +54,7 @@ public class RegisterActivity extends Activity {
|
||||
private EditText mHostView;
|
||||
private View mProgressView;
|
||||
private View mLoginFormView;
|
||||
private Button deviceRegisterButton;
|
||||
private Handler mUiHandler = new Handler();
|
||||
|
||||
@Override
|
||||
@ -73,7 +74,7 @@ public class RegisterActivity extends Activity {
|
||||
AvailableSensorsInDevice availableSensorsInDevice = new AvailableSensorsInDevice(getApplicationContext());
|
||||
availableSensorsInDevice.setContent();
|
||||
|
||||
Button deviceRegisterButton = (Button) findViewById(R.id.device_register_button);
|
||||
deviceRegisterButton = (Button) findViewById(R.id.device_register_button);
|
||||
|
||||
|
||||
deviceRegisterButton.setOnClickListener(new OnClickListener() {
|
||||
@ -204,6 +205,7 @@ public class RegisterActivity extends Activity {
|
||||
// and hide the relevant UI components.
|
||||
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
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.
|
||||
*/
|
||||
public class DataPublisherService extends Service {
|
||||
private static final String TAG = DataPublisherService.class.getName();
|
||||
private static String KEY_TAG = "key";
|
||||
private static String TIME_TAG = "time";
|
||||
private static String VALUE_TAG = "value";
|
||||
public static Context context;
|
||||
private final String TAG = DataPublisherService.class.getName();
|
||||
private Context context;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@ -68,9 +65,9 @@ public class DataPublisherService extends Service {
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
context = this;
|
||||
Log.d(TAG, "service started");
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Runnable runnable = new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
try {
|
||||
List<Event> events = new ArrayList<>();
|
||||
//retrieve sensor data.
|
||||
@ -315,10 +312,10 @@ public class DataPublisherService extends Service {
|
||||
} catch (TransportHandlerException e) {
|
||||
Log.e(TAG, "Data Publish Failed", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
Thread dataUploaderThread = new Thread(runnable);
|
||||
dataUploaderThread.start();
|
||||
// }
|
||||
// };
|
||||
// Thread dataUploaderThread = new Thread(runnable);
|
||||
// dataUploaderThread.start();
|
||||
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;
|
||||
|
||||
speed = (float)distance/(float)time;
|
||||
Toast.makeText(mContext, longitude+"\n"+latitude+"\nDistance is: "
|
||||
+distance+"\nSpeed is: "+speed , Toast.LENGTH_SHORT).show();
|
||||
// Toast.makeText(mContext, longitude+"\n"+latitude+"\nDistance is: "
|
||||
// +distance+"\nSpeed is: "+speed , Toast.LENGTH_SHORT).show();
|
||||
|
||||
|
||||
Intent intent = new Intent("speedUpdate");
|
||||
|
||||
@ -73,7 +73,7 @@ public class ActivitySelectSensor extends AppCompatActivity
|
||||
private ListView listView;
|
||||
private SensorManager sensorManager;
|
||||
private ArrayList<Sensor> sensors = new ArrayList<>();
|
||||
private EditText sessionIdText;
|
||||
// private EditText sessionIdText;
|
||||
private RealTimeSensorReader sensorReader = null;
|
||||
private RealTimeSensorChangeReceiver realTimeSensorChangeReceiver = new RealTimeSensorChangeReceiver();
|
||||
private SupportedSensors supportedSensors = SupportedSensors.getInstance();
|
||||
@ -87,21 +87,21 @@ public class ActivitySelectSensor extends AppCompatActivity
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||
sessionIdText = (EditText) findViewById(R.id.sessionId);
|
||||
sessionIdText.setCursorVisible(false);
|
||||
//sessionIdText = (EditText) findViewById(R.id.sessionId);
|
||||
// sessionIdText.setCursorVisible(false);
|
||||
|
||||
listView = (ListView) findViewById(R.id.senseListContainer);
|
||||
verifyBluetooth();
|
||||
//verifyBluetooth();
|
||||
|
||||
registerReceiver(realTimeSensorChangeReceiver, new IntentFilter("sensorDataMap"));
|
||||
|
||||
sessionIdText.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
sessionIdText.setCursorVisible(true);
|
||||
|
||||
}
|
||||
});
|
||||
// sessionIdText.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// sessionIdText.setCursorVisible(true);
|
||||
//
|
||||
// }
|
||||
// });
|
||||
|
||||
//Publish data
|
||||
FloatingActionButton fbtnPublishData = (FloatingActionButton) findViewById(R.id.publish);
|
||||
@ -126,33 +126,33 @@ public class ActivitySelectSensor extends AppCompatActivity
|
||||
}
|
||||
});
|
||||
|
||||
FloatingActionButton fbtnSpeechRecongnizer = (FloatingActionButton) findViewById(R.id.speech);
|
||||
fbtnSpeechRecongnizer.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String sessionId = sessionIdText.getText().toString();
|
||||
if (!sessionId.isEmpty()) {
|
||||
Intent intent = new Intent(getApplicationContext(), WordRecognitionActivity.class);
|
||||
intent.putExtra("sessionId", sessionId);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Toast.makeText(ActivitySelectSensor.this, "Please type a session id value", Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
//FloatingActionButton fbtnSpeechRecongnizer = (FloatingActionButton) findViewById(R.id.speech);
|
||||
// fbtnSpeechRecongnizer.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// String sessionId = sessionIdText.getText().toString();
|
||||
// if (!sessionId.isEmpty()) {
|
||||
// Intent intent = new Intent(getApplicationContext(), WordRecognitionActivity.class);
|
||||
// intent.putExtra("sessionId", sessionId);
|
||||
// startActivity(intent);
|
||||
// } else {
|
||||
// Toast.makeText(ActivitySelectSensor.this, "Please type a session id value", Toast.LENGTH_SHORT)
|
||||
// .show();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
FloatingActionButton fbtnBeaconMonitor = (FloatingActionButton) findViewById(R.id.beacon);
|
||||
fbtnBeaconMonitor.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getApplicationContext(), BeaconMonitoringActivity.class);
|
||||
startActivity(intent);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
// FloatingActionButton fbtnBeaconMonitor = (FloatingActionButton) findViewById(R.id.beacon);
|
||||
// fbtnBeaconMonitor.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// Intent intent = new Intent(getApplicationContext(), BeaconMonitoringActivity.class);
|
||||
// startActivity(intent);
|
||||
//
|
||||
//
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
sharedPreferences = getSharedPreferences(SupportedSensors.SELECTED_SENSORS, 0);
|
||||
@ -313,43 +313,43 @@ public class ActivitySelectSensor extends AppCompatActivity
|
||||
unregisterReceiver(realTimeSensorChangeReceiver);
|
||||
}
|
||||
|
||||
private void verifyBluetooth() {
|
||||
|
||||
try {
|
||||
if (!BeaconManager.getInstanceForApplication(this).checkAvailability()) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Bluetooth not enabled");
|
||||
builder.setMessage("Please enable bluetooth in settings and restart this application.");
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
finish();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
});
|
||||
builder.show();
|
||||
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Bluetooth LE not available");
|
||||
builder.setMessage("Sorry, this device does not support Bluetooth LE.");
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
finish();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
});
|
||||
builder.show();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// private void verifyBluetooth() {
|
||||
//
|
||||
// try {
|
||||
// if (!BeaconManager.getInstanceForApplication(this).checkAvailability()) {
|
||||
// final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
// builder.setTitle("Bluetooth not enabled");
|
||||
// builder.setMessage("Please enable bluetooth in settings and restart this application.");
|
||||
// builder.setPositiveButton(android.R.string.ok, null);
|
||||
// builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void onDismiss(DialogInterface dialog) {
|
||||
// finish();
|
||||
// System.exit(0);
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// builder.show();
|
||||
//
|
||||
// }
|
||||
// } catch (RuntimeException e) {
|
||||
// final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
// builder.setTitle("Bluetooth LE not available");
|
||||
// builder.setMessage("Sorry, this device does not support Bluetooth LE.");
|
||||
// builder.setPositiveButton(android.R.string.ok, null);
|
||||
// builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void onDismiss(DialogInterface dialog) {
|
||||
// finish();
|
||||
// System.exit(0);
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// builder.show();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
@ -57,6 +57,7 @@ public class SenseClientAsyncExecutor extends AsyncTask<String, Void, Map<String
|
||||
private final static String TAG = "SenseService Client";
|
||||
private static final String STATUS = "status";
|
||||
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 Context context;
|
||||
|
||||
@ -117,7 +118,7 @@ public class SenseClientAsyncExecutor extends AsyncTask<String, Void, Map<String
|
||||
new BasicAuthRequestInterceptor(apiApplicationKey.getConsumerKey(), apiApplicationKey.getConsumerSecret()))
|
||||
.contract(new JAXRSContract()).encoder(new JacksonEncoder()).decoder(new JacksonDecoder())
|
||||
.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
|
||||
AndroidSenseManagerService androidSenseManagerService = Feign.builder().client(disableHostnameVerification)
|
||||
|
||||
@ -29,7 +29,7 @@ public interface TokenIssuerService {
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
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
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
|
||||
@ -26,41 +26,65 @@
|
||||
<include layout="@layout/content_activity_select_sensor"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_gravity="bottom|center"
|
||||
android:layout_height="wrap_content" >
|
||||
android:layout_height="100dp"
|
||||
android:layout_margin="20dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/beacon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/beacon"/>
|
||||
<!--<RelativeLayout-->
|
||||
<!--android:layout_width="0dp"-->
|
||||
<!--android:layout_height="match_parent"-->
|
||||
<!--android:layout_weight="0.25"-->
|
||||
<!-->-->
|
||||
<!--<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
|
||||
android:id="@+id/addSensors"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@android:drawable/ic_input_add"/>
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0.5"
|
||||
>
|
||||
<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"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/speech"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/mic"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<!--<RelativeLayout-->
|
||||
<!--android:layout_width="0dp"-->
|
||||
<!--android:layout_height="match_parent"-->
|
||||
<!--android:layout_weight="0.25"-->
|
||||
<!-->-->
|
||||
<!--<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
|
||||
android:id="@+id/publish"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:adjustViewBounds="false"
|
||||
android:src="@drawable/pushtoserver"/>
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0.5"
|
||||
>
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
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>
|
||||
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
@ -11,18 +11,18 @@
|
||||
tools:context="org.wso2.carbon.iot.android.sense.realtimeviewer.ActivitySelectSensor"
|
||||
android:id="@+id/parentContainer">
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:hint="@string/sessionId"
|
||||
android:id="@+id/sessionId"
|
||||
android:inputType="text"
|
||||
android:maxLines="1" android:singleLine="true"/>
|
||||
<!--<EditText-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="wrap_content" android:hint="@string/sessionId"-->
|
||||
<!--android:id="@+id/sessionId"-->
|
||||
<!--android:inputType="text"-->
|
||||
<!--android:maxLines="1" android:singleLine="true"/>-->
|
||||
|
||||
<ListView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/senseListContainer"
|
||||
android:layout_below="@+id/sessionId">
|
||||
>
|
||||
</ListView>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -3,8 +3,8 @@
|
||||
|
||||
<item android:id="@+id/select" android:icon="@android:drawable/ic_menu_agenda"
|
||||
android:title="Sensors" />
|
||||
<item android:id="@+id/speech_recognizer" android:icon="@android:drawable/ic_menu_agenda"
|
||||
android:title="Speech Recognizer" />
|
||||
<!--<item android:id="@+id/speech_recognizer" android:icon="@android:drawable/ic_menu_agenda"-->
|
||||
<!--android:title="Speech Recognizer" />-->
|
||||
<!--<group android:checkableBehavior="single">-->
|
||||
<!-- -->
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ buildscript {
|
||||
maven { url 'https://repo.eclipse.org/content/repositories/paho-releases/' }
|
||||
}
|
||||
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
|
||||
// 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
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
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">
|
||||
<Name>Add Keywords</Name>
|
||||
<Description>Send keywords to the device</Description>
|
||||
<Operation context="/android_sense/device/{deviceId}/words" method="POST">
|
||||
<QueryParameters>
|
||||
<Parameter>keywords</Parameter>
|
||||
</QueryParameters>
|
||||
</Operation>
|
||||
<!--<Operation context="/android_sense/device/{deviceId}/words" method="POST">-->
|
||||
<!--<QueryParameters>-->
|
||||
<!--<Parameter>keywords</Parameter>-->
|
||||
<!--</QueryParameters>-->
|
||||
<!--</Operation>-->
|
||||
</Feature>
|
||||
<Feature code="threshold">
|
||||
<Name>Add Threshold</Name>
|
||||
<Description>Send Threshold to the device</Description>
|
||||
<Operation context="/android_sense/device/{deviceId}/words/threshold" method="POST">
|
||||
<QueryParameters>
|
||||
<Parameter>threshold</Parameter>
|
||||
</QueryParameters>
|
||||
</Operation>
|
||||
<!--<Operation context="/android_sense/device/{deviceId}/words/threshold" method="POST">-->
|
||||
<!--<QueryParameters>-->
|
||||
<!--<Parameter>threshold</Parameter>-->
|
||||
<!--</QueryParameters>-->
|
||||
<!--</Operation>-->
|
||||
</Feature>
|
||||
<Feature code="remove_words">
|
||||
<Name>Remove words</Name>
|
||||
<Description>Remove Threshold from the device</Description>
|
||||
<Operation context="/android_sense/device/{deviceId}/words" method="DELETE">
|
||||
<QueryParameters>
|
||||
<Parameter>words</Parameter>
|
||||
</QueryParameters>
|
||||
</Operation>
|
||||
<!--<Operation context="/android_sense/device/{deviceId}/words" method="DELETE">-->
|
||||
<!--<QueryParameters>-->
|
||||
<!--<Parameter>words</Parameter>-->
|
||||
<!--</QueryParameters>-->
|
||||
<!--</Operation>-->
|
||||
</Feature>
|
||||
</Features>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user