add Smart Location V 0.1 not complete
This commit is contained in:
parent
cdf1813de3
commit
0700dcb625
|
|
@ -90,7 +90,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
SmartLocationAPI smartLocationAPI = new SmartLocationAPI();
|
SmartLocationAPI smartLocationAPI = new SmartLocationAPI(MainActivity.this);
|
||||||
smartLocationAPI.smart(true);
|
smartLocationAPI.smart(true);
|
||||||
if(!smartLocationAPI.isSmart()) {
|
if(!smartLocationAPI.isSmart()) {
|
||||||
smartLocationAPI.customLocation(new CustomLocation());
|
smartLocationAPI.customLocation(new CustomLocation());
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
package com.pureix.easylocator.controller.service;
|
package com.pureix.easylocator.controller.service;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import com.pureix.easylocator.model.bean.CustomLocation;
|
import com.pureix.easylocator.model.bean.CustomLocation;
|
||||||
|
import com.pureix.easylocator.service.SmartLocationBusiness;
|
||||||
import com.pureix.easylocator.service.locatonService.Listener.LocationReceiverListener;
|
import com.pureix.easylocator.service.locatonService.Listener.LocationReceiverListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -11,9 +14,19 @@ public class SmartLocationAPI
|
||||||
{
|
{
|
||||||
private boolean isSmart = true;
|
private boolean isSmart = true;
|
||||||
private LocationReceiverListener locationReceiverListener;
|
private LocationReceiverListener locationReceiverListener;
|
||||||
|
private SmartLocationBusiness smartLocationBusiness;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public SmartLocationAPI(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
|
||||||
|
smartLocationBusiness = new SmartLocationBusiness();
|
||||||
|
smartLocationBusiness.setSmart(isSmart);
|
||||||
|
}
|
||||||
|
|
||||||
public void smart(boolean isSmart) {
|
public void smart(boolean isSmart) {
|
||||||
this.isSmart = isSmart;
|
this.isSmart = isSmart;
|
||||||
|
smartLocationBusiness.setSmart(isSmart);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSmart() {
|
public boolean isSmart() {
|
||||||
|
|
@ -21,10 +34,16 @@ public class SmartLocationAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
public void customLocation(CustomLocation customLocation) {
|
public void customLocation(CustomLocation customLocation) {
|
||||||
|
smartLocationBusiness.setCustomLocation(customLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocationReceiverListener(LocationReceiverListener locationReceiverListener) {
|
public void setLocationReceiverListener(LocationReceiverListener locationReceiverListener)
|
||||||
|
{
|
||||||
|
smartLocationBusiness.start(context);
|
||||||
this.locationReceiverListener = locationReceiverListener;
|
this.locationReceiverListener = locationReceiverListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void pause() {
|
||||||
|
smartLocationBusiness.pause(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,103 @@
|
||||||
package com.pureix.easylocator.service;
|
package com.pureix.easylocator.service;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.android.gms.location.DetectedActivity;
|
||||||
|
import com.pureix.easylocator.controller.service.ActivityRecognitionAPI;
|
||||||
|
import com.pureix.easylocator.model.bean.CustomLocation;
|
||||||
|
import com.pureix.easylocator.service.activityRecognitionService.listener.ActivityRecognitionListener;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by MelDiSooQi on 2/18/2017.
|
* Created by MelDiSooQi on 2/18/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SmartLocationBusiness {
|
public class SmartLocationBusiness {
|
||||||
|
|
||||||
|
private CustomLocation customLocation;
|
||||||
|
private boolean smart;
|
||||||
|
|
||||||
|
public void start(final Context context) {
|
||||||
|
if(smart) {
|
||||||
|
ActivityRecognitionAPI.start(context);
|
||||||
|
|
||||||
|
ActivityRecognitionAPI.setActivitiesRecognitionListener(new ActivityRecognitionListener() {
|
||||||
|
@Override
|
||||||
|
public void updateDetectedActivitiesList(ArrayList<DetectedActivity> updatedActivities) {
|
||||||
|
ArrayList<DetectedActivity> activityArrayList =
|
||||||
|
ActivityRecognitionAPI.getArrayList(updatedActivities);
|
||||||
|
|
||||||
|
DetectedActivity detectedActivity = null;
|
||||||
|
int biggestNumber = -1;
|
||||||
|
for (int i = 0; i < activityArrayList.size(); i++) {
|
||||||
|
DetectedActivity currentActivity = activityArrayList.get(i);
|
||||||
|
int confidence = activityArrayList.get(i).getConfidence();
|
||||||
|
|
||||||
|
if (biggestNumber < confidence) {
|
||||||
|
biggestNumber = confidence;
|
||||||
|
detectedActivity = currentActivity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Toast.makeText(context,
|
||||||
|
ActivityRecognitionAPI.getActivityString(context,
|
||||||
|
detectedActivity.getType()) + " - "
|
||||||
|
+ detectedActivity.getConfidence()
|
||||||
|
+ "%" + "\n", Toast.LENGTH_SHORT).show();
|
||||||
|
decideAction(detectedActivity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
// if not smart use User Custom Location
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void decideAction(DetectedActivity detectedActivity) {
|
||||||
|
int type = detectedActivity.getType();
|
||||||
|
|
||||||
|
if(DetectedActivity.STILL == type){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(DetectedActivity.ON_FOOT == type){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(DetectedActivity.WALKING == type){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(DetectedActivity.RUNNING == type){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(DetectedActivity.ON_BICYCLE == type){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(DetectedActivity.IN_VEHICLE == type){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(DetectedActivity.TILTING == type){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(DetectedActivity.UNKNOWN == type){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomLocation(CustomLocation customLocation) {
|
||||||
|
this.customLocation = customLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSmart(boolean smart) {
|
||||||
|
this.smart = smart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pause(Context context) {
|
||||||
|
ActivityRecognitionAPI.start(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue