Fix some issues in Location And remove some not needed toast and add getActivityString

This commit is contained in:
MOATAZ IBRAHIM ELDESOUKI TAWFEEK MOHAMMED 2017-02-14 22:33:18 +02:00
parent a8f7892e23
commit e3c317990d
6 changed files with 35 additions and 22 deletions

View File

@ -53,19 +53,18 @@ public class MainActivity extends AppCompatActivity {
ArrayList<DetectedActivity> tempList = ActivityRecognitionAPI.getArrayList(updatedActivities); ArrayList<DetectedActivity> tempList = ActivityRecognitionAPI.getArrayList(updatedActivities);
for (int i = 0; i < tempList.size(); i++) { for (int i = 0; i < tempList.size(); i++) {
txt.append(MONITORED_ACTIVITIES[tempList.get(i).getType()-1] +" - " txt.append(ActivityRecognitionAPI.getActivityString(MainActivity.this,
+ tempList.get(i).getConfidence() +" - " tempList.get(i).getType()) +" - "
+ tempList.get(i).getVersionCode()+"\n"); + tempList.get(i).getConfidence()+ "%"+"\n");
} }
Toast.makeText(MainActivity.this, ""+tempList, Toast.LENGTH_SHORT).show(); txt.append("\n");
} }
}); });
InternetAPI.networkListener(new ConnectivityReceiverListener() { InternetAPI.networkListener(new ConnectivityReceiverListener() {
@Override @Override
public void onNetworkConnectionChanged(boolean isConnected, int connectionProvider) { public void onNetworkConnectionChanged(boolean isConnected, int connectionProvider) {
//txt.append(); txt.append("isConnected"+isConnected+" - "+ connectionProvider +"\n\n");
//Toast.makeText(MainActivity.this, ""+isConnected, Toast.LENGTH_SHORT).show();
} }
}); });
@ -73,21 +72,28 @@ public class MainActivity extends AppCompatActivity {
BatteryAPI.batteryListener(new BatteryReceiverListener() { BatteryAPI.batteryListener(new BatteryReceiverListener() {
@Override @Override
public void onBatteryInformationChanged(int level, int scale, int temperature, int voltage, float batteryPct, int status, boolean isCharging, int chargePlug, boolean usbCharge, boolean acCharge) { public void onBatteryInformationChanged(int level, int scale, int temperature, int voltage, float batteryPct, int status, boolean isCharging, int chargePlug, boolean usbCharge, boolean acCharge) {
//Toast.makeText(MainActivity.this, ""+level, Toast.LENGTH_SHORT).show(); txt.append("level is " + level + "/" + scale +
", temp is " + temperature +
", voltage is " + voltage
+ " status :" + status +
" chargePlug :" + chargePlug +
" Battery Pct : " + batteryPct * 100 +"\n\n");
} }
}); });
LocationAPI.setLocationReceiverListener(new LocationReceiverListener() { LocationAPI.setLocationReceiverListener(new LocationReceiverListener() {
@Override @Override
public void getLastKnownLocation(Location location) { public void getLastKnownLocation(Location location) {
Toast.makeText(MainActivity.this, "Broadlocationss getLastKnownLocation "+location.toString()+"", Toast.LENGTH_SHORT).show(); txt.append("getLastKnownLocation "+location+"\n\n");
// Toast.makeText(MainActivity.this, "Broadlocationss getLastKnownLocation "+location.toString()+"", Toast.LENGTH_SHORT).show();
// Log.d("Taag", "Broadlocationss getLastKnownLocation "+location.toString()+""); // Log.d("Taag", "Broadlocationss getLastKnownLocation "+location.toString()+"");
} }
@Override @Override
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
Toast.makeText(MainActivity.this, "Broadlocationss onLocationChanged "+location.toString()+"", Toast.LENGTH_SHORT).show(); txt.append("onLocationChanged "+location+"\n\n");
Log.d("Taag", "Broadlocationss onLocationChanged "+location.toString()+""); // Toast.makeText(MainActivity.this, "Broadlocationss onLocationChanged "+location.toString()+"", Toast.LENGTH_SHORT).show();
// Log.d("Taag", "Broadlocationss onLocationChanged "+location.toString()+"");
} }
}); });

View File

@ -86,4 +86,8 @@ public class ActivityRecognitionAPI
return arrayAdapter; return arrayAdapter;
} }
public static String getActivityString(Context context, int detectedActivityType) {
return Constants.getActivityString(context, detectedActivityType);
}
} }

View File

@ -27,9 +27,10 @@ public class ActivityRecognitionBroadcast extends BroadcastReceiver
ArrayList<DetectedActivity> updatedActivities = ArrayList<DetectedActivity> updatedActivities =
intent.getParcelableArrayListExtra(Constants.ACTIVITY_EXTRA); intent.getParcelableArrayListExtra(Constants.ACTIVITY_EXTRA);
Log.d("mezoTag", "okay here we are hhhhh"); // Log.d("mezoTag", "okay here we are hhhhh");
// Toast.makeText(context, "okay here we are hhhhh", Toast.LENGTH_SHORT).show();
Toast.makeText(context, "okay here we are hhhhh", Toast.LENGTH_SHORT).show();
// mDetectedActivities = new ArrayList<DetectedActivity>(); // mDetectedActivities = new ArrayList<DetectedActivity>();
// //
// // Set the confidence level of each monitored activity to zero. // // Set the confidence level of each monitored activity to zero.

View File

@ -72,14 +72,14 @@ public class BatteryStateReceiver extends BroadcastReceiver
temperature, voltage, batteryPct, status, isCharging, temperature, voltage, batteryPct, status, isCharging,
chargePlug, usbCharge, acCharge); chargePlug, usbCharge, acCharge);
} }
Toast.makeText(context, // Toast.makeText(context,
"level is " + level + "/" + scale + // "level is " + level + "/" + scale +
", temp is " + temperature + // ", temp is " + temperature +
", voltage is " + voltage // ", voltage is " + voltage
+ " status :" + status + // + " status :" + status +
" chargePlug :" + chargePlug + // " chargePlug :" + chargePlug +
" Battery Pct : " + batteryPct * 100, // " Battery Pct : " + batteryPct * 100,
Toast.LENGTH_SHORT).show(); // Toast.LENGTH_SHORT).show();
} }
} }
} }

View File

@ -203,7 +203,7 @@ public class LocationService extends Service implements
sendLocationToBroadcast(location); sendLocationToBroadcast(location);
if(locationReceiverListener !=null) { if(locationReceiverListener !=null) {
locationReceiverListener.getLastKnownLocation(location); locationReceiverListener.getLastKnownLocation(location);
locationReceiverListener.onLocationChanged(location); // locationReceiverListener.onLocationChanged(location);
} }
} catch (Exception e) { } catch (Exception e) {
} }

View File

@ -69,7 +69,9 @@ public class LocationBroadcast extends BroadcastReceiver
if ("LocalStorage".equals(location.getProvider())) { if ("LocalStorage".equals(location.getProvider())) {
locationReceiverListener.getLastKnownLocation(location); locationReceiverListener.getLastKnownLocation(location);
} }
locationReceiverListener.onLocationChanged(location); if (!"LocalStorage".equals(location.getProvider())){
locationReceiverListener.onLocationChanged(location);
}
} }
float kMeter = location.getSpeed() * 3.6f; float kMeter = location.getSpeed() * 3.6f;