Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions mobility-track-android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions mobility-track-android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions mobility-track-android/.idea/vcs.xml

This file was deleted.

19 changes: 15 additions & 4 deletions mobility-track-android/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<afterSyncTasks>
<task>generateDebugAndroidTestSources</task>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
Expand All @@ -28,7 +25,7 @@
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
Expand All @@ -50,13 +47,27 @@
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class Constants {

public static final String SERVER = "192.168.1.3";
public static final String SERVER = "192.168.137.1";
public static final String DATA_POST_URL = "/api/tracker/location/data";
public static final String GET_DEVICE_ID_URL = "/api/tracker/findmac/";
public static final int UPDATE_FREQUENCY = 2000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -28,8 +29,11 @@
import ogr.scorelab.ucsc.mobility_track.net.DataTransferHandler;


public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements View.OnClickListener {


private static final String TAG = MainActivity.class.getSimpleName();
private Button startButton, stopButton;
private TextView txtMac, txtDeviceId;

private String deviceId = null;
Expand All @@ -38,10 +42,26 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
setInit();
setData();
}

txtMac = (TextView) findViewById(R.id.txtMac);
txtDeviceId = (TextView) findViewById(R.id.txtDeviceId);
private void init() {
txtMac = (TextView) findViewById(R.id.mac_address);
txtDeviceId = (TextView) findViewById(R.id.device_id);

startButton=(Button)findViewById(R.id.start_button);
stopButton=(Button)findViewById(R.id.stop_button);
}

private void setInit() {

startButton.setOnClickListener(this);
stopButton.setOnClickListener(this);
}

private void setData() {
getDeviceId();
}

Expand All @@ -50,13 +70,12 @@ private void getDeviceId() {
String deviceMAC = getDeviceMAC();
if (deviceMAC == null) {
txtMac.setText("Device don't have mac address or wi-fi is disabled");
}
else {
} else {
txtMac.setText(deviceMAC);
new GetDeviceConfigs().execute(deviceMAC);
}
} catch (IOException e) {
Log.e("TRACKER", e.getLocalizedMessage());
Log.d(TAG, "getDeviceId() called with: " + e.getLocalizedMessage());
}
}

Expand All @@ -80,7 +99,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
}

if(id == R.id.action_refresh_device_id) {
if (id == R.id.action_refresh_device_id) {
getDeviceId();
return true;
}
Expand All @@ -89,7 +108,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

/* start background service */
public void start(View v) {
public void start() {
if (deviceId == null) {
Toast.makeText(this, R.string.device_unregistered, Toast.LENGTH_LONG).show();
return;
Expand All @@ -106,7 +125,7 @@ public void start(View v) {
}

/* stop background service */
public void stop(View v) {
public void stop() {
Intent intent = new Intent(this, LocationUpdates.class);
stopService(intent);
DataTransferHandler.isThisActive = false;
Expand All @@ -117,13 +136,27 @@ private String getDeviceMAC() throws IOException {
if (wifiManager.getConnectionInfo().getMacAddress() == null) {
return null;
}

String mac = "";
for (String block : wifiManager.getConnectionInfo().getMacAddress().split(":"))
mac += block.toUpperCase();
return mac;
}

@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.start_button:
start();
break;
case R.id.stop_button:
stop();
break;
default:

}
}

/*public boolean isServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
Expand All @@ -141,7 +174,7 @@ private class GetDeviceConfigs extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
try {
URL url = new URL("http",Constants.SERVER,3000,Constants.GET_DEVICE_ID_URL+params[0]);
URL url = new URL("http", Constants.SERVER, 3000, Constants.GET_DEVICE_ID_URL + params[0]);
httpConnection = (HttpURLConnection) url.openConnection();
httpConnection.setDoInput(true);
return inputStreamToString(httpConnection.getInputStream());
Expand All @@ -161,7 +194,7 @@ protected void onPostExecute(String s) {
}
try {
JSONArray jsonArray = new JSONArray(s);
if(jsonArray.length() == 0) {
if (jsonArray.length() == 0) {
txtDeviceId.setText(R.string.device_unregistered);
return;
}
Expand All @@ -176,7 +209,7 @@ protected void onPostExecute(String s) {
}
}

private String inputStreamToString (InputStream in) throws IOException {
private String inputStreamToString(InputStream in) throws IOException {
String ret = "";

BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
Expand Down
48 changes: 19 additions & 29 deletions mobility-track-android/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,49 +1,39 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:id="@+id/button"
android:layout_alignParentLeft="true"
android:onClick="start"
android:layout_alignParentStart="true" />
android:text="@string/start_command"
android:id="@+id/start_button" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
android:onClick="stop"
android:id="@+id/button2"
android:layout_below="@+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
android:text="@string/stop_command"
android:id="@+id/stop_button"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DEVICEMAC"
android:id="@+id/txtMac"
android:layout_marginTop="10dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/button2" />
android:text="@string/device_mac_hint"
android:id="@+id/mac_address"
android:layout_marginTop="10dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DEVICEID"
android:id="@+id/txtDeviceId"
android:text="@string/device_id_hint"
android:id="@+id/device_id"
android:layout_below="@+id/txtMac"
android:layout_marginTop="10dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
android:layout_marginTop="10dp" />
</LinearLayout>
4 changes: 4 additions & 0 deletions mobility-track-android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
<string name="preference_file_key">scorelab.ucsc.mobility_track</string>
<string name="saved_device_id">deviceid</string>
<string name="saved_device_id_default">0</string>
<string name="start_command">Start</string>
<string name="stop_command" >Stop</string>
<string name="device_mac_hint">DEVICE MAC</string>
<string name="device_id_hint">DEVICE ID</string>

</resources>