Fix android scheduling and layouts.
LocationBasedServices/maptology/master This commit looks good

Closes #64 Hide password on login.
Closes #63 Fix scheduling on Android 9.
Remove unused import in statistics bean.
This commit is contained in:
Marcus Handte
2019-08-08 09:20:12 +02:00
parent d577cadf39
commit 5bb2e6fee6
6 changed files with 50 additions and 35 deletions
+13 -2
View File
@@ -27,10 +27,13 @@ android {
applicationId "com.maptology.android.app"
minSdkVersion 14
targetSdkVersion 28
versionCode 5
versionName "1.0.1"
versionCode 6
versionName "${version}"
buildConfigField "long", "BUILD_TIME", System.currentTimeMillis() + "L"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resValue "string", "application_long", "Maptology"
resValue "string", "application_short", "Maptology"
}
signingConfigs {
@@ -50,8 +53,16 @@ android {
// add signing config if key is provided via system property
if (System.properties['android.keystore.password'] != null) signingConfig signingConfigs.release
}
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-dbg"
resValue "string", "application_long", "Maptology (Debug)"
resValue "string", "application_short", "M (Debug)"
}
}
testOptions {
unitTests {
includeAndroidResources = true
@@ -267,7 +267,6 @@ public class LocationService extends Service {
}
@Override
@SuppressLint("InlinedApi")
public void onCreate() {
Log.d(TAG, "Creating location service.");
super.onCreate();
@@ -323,21 +322,19 @@ public class LocationService extends Service {
stopSelf();
return START_NOT_STICKY;
}
if (!isPeriodicExecution(intent)) {
Log.d(TAG, "Scheduling periodic execution.");
scheduleExecution(this, localizationTime);
}
// ensure that localization is only running, if it is not
// running already or has been run only seconds ago
// start localization, if we are not running one already
long now = SystemClock.elapsedRealtime();
if (currentState == LocationState.IDLE) {
if (isDeviceIdle()) {
onDeviceIdle();
} else if (now - localizationTime > LOCALIZATION_TIMEOUT - 1000) {
if (now - localizationTime > LOCALIZATION_TIMEOUT / 2) {
Log.d(TAG, "Starting localization state machine.");
changeState();
} else {
Log.d(TAG, "Ignoring start request while timeout has not expired.");
if (isDeviceIdle()) {
onDeviceIdle();
}
Log.d(TAG, "Scheduling periodic execution.");
scheduleExecution(this, localizationTime);
}
} else {
Log.d(TAG, "Ignoring start request while service is " + currentState + ".");
@@ -617,7 +614,7 @@ public class LocationService extends Service {
// otherwise create idle update
ReleasedLocation update = createLocation();
update.setAvailability(ReleasedLocation.AvailabilityEnum.IDLE);
update.setTimestamp(System.currentTimeMillis());
update.setTimestamp(localizationTime);
update.setAccuracy(previous.getAccuracy());
update.setCoordinate(previous.getCoordinate());
update.setProvider(previous.getProvider());
@@ -940,7 +937,7 @@ public class LocationService extends Service {
}
/**
* Schedules the service for periodic execution.
* Schedules the service for the next execution.
*
* @param context The context used to schedule this.
*/
@@ -950,7 +947,13 @@ public class LocationService extends Service {
long now = SystemClock.elapsedRealtime();
long next = Math.max(0, (lastTime + LOCALIZATION_TIMEOUT) - now);
Log.d(TAG, "Updating alarm to execute in " + next + " ms.");
manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + next, LOCALIZATION_TIMEOUT, pending);
// this is too imprecise on Android 9
//manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + next, LOCALIZATION_TIMEOUT, pending);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + next, pending);
} else {
manager.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + next, 10000, pending);
}
}
/**
@@ -41,6 +41,7 @@ public abstract class AbstractLoginFragment extends AbstractFragment {
private int title;
private int explanation;
private int login;
private boolean passwordVisible = false;
/**
* The listener that listens to changes announced by the async task.
@@ -86,7 +87,6 @@ public abstract class AbstractLoginFragment extends AbstractFragment {
public void onClick(View v) {
String username = usernameText.getText().toString();
String password = passwordText.getText().toString();
username = analyzeInput(username);
password = analyzeInput(password);
if (username == null || password == null) {
@@ -101,17 +101,9 @@ public abstract class AbstractLoginFragment extends AbstractFragment {
});
passwordButton = (ImageButton) view.findViewById(R.id.button_password);
passwordButton.setOnClickListener(new View.OnClickListener() {
private boolean visible = false;
@Override
public void onClick(View v) {
visible = !visible;
if (visible) {
passwordButton.setImageResource(R.drawable.ic_visibility_off_black_24dp);
passwordText.setTransformationMethod(null);
} else {
passwordButton.setImageResource(R.drawable.ic_visibility_black_24dp);
passwordText.setTransformationMethod(new PasswordTransformationMethod());
}
setPasswordVisible(!passwordVisible);
}
});
noLoginButton.setOnClickListener(new View.OnClickListener() {
@@ -175,6 +167,17 @@ public abstract class AbstractLoginFragment extends AbstractFragment {
}
}
private void setPasswordVisible(boolean visible) {
if (visible) {
passwordButton.setImageResource(R.drawable.ic_visibility_off_black_24dp);
passwordText.setTransformationMethod(null);
} else {
passwordButton.setImageResource(R.drawable.ic_visibility_black_24dp);
passwordText.setTransformationMethod(new PasswordTransformationMethod());
}
this.passwordVisible = visible;
}
private void setEnabled(boolean enabled) {
loginButton.setEnabled(enabled);
noLoginButton.setEnabled(enabled);
@@ -182,6 +185,7 @@ public abstract class AbstractLoginFragment extends AbstractFragment {
usernameText.setEnabled(enabled);
passwordText.setEnabled(enabled);
progressBar.setVisibility(enabled?View.GONE:View.VISIBLE);
if (!enabled) setPasswordVisible(false);
}
private String analyzeInput(String input) {
@@ -4,13 +4,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:orientation="vertical"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_width="@dimen/max_view_width"
android:layout_height="match_parent">
<ScrollView android:layout_width="match_parent"
<ScrollView android:layout_width="@dimen/max_view_width"
android:fillViewport="true"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="match_parent"
@@ -50,6 +46,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/space_large"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/input_password"
@@ -69,7 +66,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/space_medium"
android:background="@color/white"
android:background="@android:color/transparent"
android:src="@drawable/ic_visibility_black_24dp" />
</LinearLayout>
@@ -106,7 +103,6 @@
</ScrollView>
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--
<string name="application_long" translatable="false">Maptology</string>
<string name="application_short" translatable="false">Maptology</string>
-->
<string name="maptology_url_default" translatable="false">https://www.maptology.com/api</string>
<string name="maptology_url_share" translatable="false">https://www.maptology.com/app/shares/</string>
@@ -10,7 +10,6 @@ import java.util.List;
import javax.annotation.security.DeclareRoles;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB;
import javax.ejb.Stateful;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;