A little refactor before merge to develop
This commit is contained in:
parent
ae5c8d91e2
commit
850d588744
@ -6,6 +6,8 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.location"
|
||||
@ -24,19 +26,6 @@
|
||||
android:theme="@style/AppTheme"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
|
||||
|
||||
<receiver android:name=".utils.BroadcastLocalizationHandler"
|
||||
android:enabled="true"
|
||||
android:exported="false"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="background.location.broadcast">
|
||||
</action>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
||||
|
||||
<activity android:name=".activity.StartupActivity"
|
||||
android:label="@string/title_activity_startup"
|
||||
android:launchMode="singleInstance">
|
||||
@ -61,7 +50,11 @@
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".service.BackgroundLocalizationService"/>
|
||||
android:name=".service.BackgroundLocalizationService"
|
||||
android:exported="false"
|
||||
android:launchMode="singleTop"
|
||||
android:enabled="true"
|
||||
/>
|
||||
|
||||
</application>
|
||||
|
||||
|
@ -343,7 +343,7 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
LdapUser user = new LdapUser("admin@admin",mPassword,"admin",(isTutor)?"Tutor":"Student","string","string",mEmail);
|
||||
LdapUser user = new LdapUser(mEmail,mPassword,"admin",(isTutor)?"Tutor":"Student","string","string",mEmail);
|
||||
|
||||
disposable.add(
|
||||
ldapService
|
||||
|
@ -42,9 +42,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
private MapFragment mapFragment;
|
||||
private NotificationFragment notificationFragment;
|
||||
private ProfileFragment profileFragment;
|
||||
public static IntentFilter backgroundLocalizationService = null;
|
||||
|
||||
private BroadcastReceiver broadcastReceiver = null;
|
||||
|
||||
private static final int REQUEST_PERMISSIONS = 100;
|
||||
private boolean boolean_permission = false;
|
||||
@ -96,7 +93,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
final FloatingActionButton button = findViewById(R.id.logoutButton);
|
||||
button.setOnClickListener(view -> {
|
||||
PrefUtils.cleanUserLocalStorage(getApplicationContext());
|
||||
unRegisterLocalizationService();
|
||||
|
||||
Intent i = getBaseContext().getPackageManager()
|
||||
.getLaunchIntentForPackage(getBaseContext().getPackageName());
|
||||
@ -108,7 +104,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
if (isTutor) {
|
||||
fn_permission();
|
||||
this.broadcastReceiver = new BroadcastLocalizationHandler();
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,17 +127,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
} else {
|
||||
|
||||
if (isTutor) {
|
||||
|
||||
Intent intent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
startForegroundService(intent);
|
||||
} else {
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "Please enable the gps", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@ -157,7 +149,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
case REQUEST_PERMISSIONS: {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
boolean_permission = true;
|
||||
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "Please allow the permission", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
@ -168,37 +159,16 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
backgroundLocalizationService = new IntentFilter(BackgroundLocalizationService.str_receiver);
|
||||
|
||||
if (isTutor)
|
||||
registerReceiver(this.broadcastReceiver, backgroundLocalizationService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (isTutor)
|
||||
unregisterReceiver(this.broadcastReceiver);
|
||||
}
|
||||
|
||||
protected void onDestroy() {
|
||||
unRegisterLocalizationService();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void unRegisterLocalizationService() {
|
||||
if (this.broadcastReceiver != null) {
|
||||
try {
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
|
||||
|
||||
Intent intent = new Intent(this, BackgroundLocalizationService.class);
|
||||
stopService(intent);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.d("Destroy app", "RECIEVER UNREGISTER ERROR");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,16 +44,16 @@ public class BackgroundLocalizationService extends Service {
|
||||
private static final float LOCATION_DISTANCE = 10f;
|
||||
private Handler mHandler = new Handler();
|
||||
private static long notify_interval = 10000;
|
||||
|
||||
double latitude, longitude;
|
||||
boolean isGPSEnable = false;
|
||||
boolean isNetworkEnable = false;
|
||||
|
||||
Location mLastLocation;
|
||||
Intent intent;
|
||||
LocationManager locationManager;
|
||||
Location location;
|
||||
|
||||
double latitude, longitude;
|
||||
|
||||
|
||||
boolean isGPSEnable = false;
|
||||
boolean isNetworkEnable = false;
|
||||
|
||||
private class LocationListener implements android.location.LocationListener {
|
||||
|
||||
@ -66,7 +66,7 @@ public class BackgroundLocalizationService extends Service {
|
||||
public void onLocationChanged(Location location) {
|
||||
Log.e(TAG, "onLocationChanged: " + location);
|
||||
mLastLocation.set(location);
|
||||
sendToBroadcast(mLastLocation);
|
||||
fn_update(mLastLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -88,7 +88,7 @@ public class BackgroundLocalizationService extends Service {
|
||||
LocationListener[] mLocationListeners = new LocationListener[]{
|
||||
new LocationListener(LocationManager.GPS_PROVIDER),
|
||||
new LocationListener(LocationManager.NETWORK_PROVIDER),
|
||||
new LocationListener(LocationManager.PASSIVE_PROVIDER)
|
||||
//new LocationListener(LocationManager.PASSIVE_PROVIDER)
|
||||
};
|
||||
|
||||
@Override
|
||||
@ -114,13 +114,10 @@ public class BackgroundLocalizationService extends Service {
|
||||
else {
|
||||
Notification notification = new NotificationCompat.Builder(this, "NOTIFICATION_CHANNEL")
|
||||
.setContentText("Content").build();
|
||||
|
||||
startForeground(1001, notification);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
initializeLocationManager();
|
||||
|
||||
try {
|
||||
@ -148,12 +145,12 @@ public class BackgroundLocalizationService extends Service {
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Log.d(TAG, "gps provider does not exist " + ex.getMessage());
|
||||
}
|
||||
|
||||
Timer mTimer = new Timer();
|
||||
mTimer.schedule(new TimerTaskToGetLocation(), 5, notify_interval);
|
||||
intent = new Intent(str_receiver);
|
||||
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
private void startMyOwnForeground() {
|
||||
|
||||
@ -252,8 +249,6 @@ public class BackgroundLocalizationService extends Service {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private class TimerTaskToGetLocation extends TimerTask {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -264,21 +259,8 @@ public class BackgroundLocalizationService extends Service {
|
||||
private void fn_update(Location location) {
|
||||
intent.putExtra("latitude", location.getLatitude());
|
||||
intent.putExtra("longitude", location.getLongitude());
|
||||
Log.e(TAG, String.valueOf(location));
|
||||
new Task(location).execute();
|
||||
// sendBroadcast(intent);
|
||||
}
|
||||
|
||||
private void sendToBroadcast(Location location) {
|
||||
Log.e("sendToBroadcast", String.valueOf(location));
|
||||
|
||||
intent.putExtra("latitude",location.getLatitude());
|
||||
intent.putExtra("longitude",location.getLongitude());
|
||||
new Task(location).execute();
|
||||
//sendBroadcast(intent);
|
||||
}
|
||||
|
||||
private void getLocation() {
|
||||
sendToBroadcast(mLastLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -344,9 +326,10 @@ public class BackgroundLocalizationService extends Service {
|
||||
Log.e("CoordinateService onSuccess", String.valueOf(coord));
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("LoginError", "onError: " + e.getMessage());
|
||||
Log.e("CoordinateService onError", e.getMessage());
|
||||
}
|
||||
}));
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user