Merge branch '98-fix-geofence' into 'master'

Resolve "Fix geofence"

Closes #98

See merge request marcel.schwarz/2020ss-qbc-geofence-timetracking!75
This commit is contained in:
Tobias Wieck 2020-05-27 22:22:54 +00:00
commit 2a1eb3feef
11 changed files with 113 additions and 43 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -40,7 +40,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.2.0-alpha06'
implementation 'com.google.android.material:material:1.1.0'
implementation "com.google.android.gms:play-services-location:17.0.0"
implementation 'androidx.preference:preference:1.1.1'
testImplementation 'junit:junit:4.13'

View File

@ -19,6 +19,7 @@ import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import kotlinx.android.synthetic.main.activity_login.*
/**
* A simple [Fragment] subclass.
@ -70,8 +71,8 @@ class Login : AppCompatActivity() {
}
private fun login() {
val name = findViewById<TextView>(R.id.setting_input_username).text.toString()
val pswd = findViewById<TextView>(R.id.input_password).text.toString()
val name = input_username.text.toString()
val pswd = input_password.text.toString()
val call = service.login(ValuesUserLogin(name, pswd))
call.enqueue(object : Callback<Void> {

View File

@ -1,17 +1,19 @@
package de.hft.geotracker.activities
import android.Manifest.permission.ACCESS_FINE_LOCATION
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.Looper
import android.widget.ArrayAdapter
import android.widget.Spinner
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.location.Geofence
import com.google.android.gms.location.GeofencingClient
import com.google.android.gms.location.GeofencingRequest
import com.google.android.gms.location.LocationServices
import androidx.core.app.ActivityCompat
import androidx.core.app.ActivityCompat.requestPermissions
import com.google.android.gms.location.*
import de.hft.geotracker.GeofenceBroadcastReceiver
import de.hft.geotracker.R
import de.hft.geotracker.retrofit.AuthenticationInterceptor
@ -34,12 +36,29 @@ class MainActivity : AppCompatActivity() {
lateinit var actionButton: TextView
var running = false
lateinit var service: GeofenceService
lateinit var locationRequest: LocationRequest
lateinit var fusedLocationClient: FusedLocationProviderClient
lateinit var locationCallback: LocationCallback
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
//Get location data and permissions
createLocationRequest()
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED
) {
requestPermissions(this, arrayOf(ACCESS_FINE_LOCATION), 1000)
}
locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
locationResult ?: return
}
}
//React on geofence state
this.getSharedPreferences("LOCATION", Context.MODE_PRIVATE)
?.edit()
?.putBoolean("ENABLED", false)
@ -124,6 +143,7 @@ class MainActivity : AppCompatActivity() {
true
}
R.id.logout -> {
deleteFile("JWToken")
startActivity(Intent(this, Login::class.java))
println("Logout pressed")
true
@ -172,6 +192,26 @@ class MainActivity : AppCompatActivity() {
PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
override fun onResume() {
super.onResume()
startLocationUpdates()
}
private fun startLocationUpdates() {
fusedLocationClient.requestLocationUpdates(
locationRequest,
locationCallback,
Looper.getMainLooper()
)
}
private fun createLocationRequest() {
locationRequest = LocationRequest.create().apply {
interval = 10000
fastestInterval = 5000
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
}
}
override fun onBackPressed() {
}

View File

@ -8,8 +8,6 @@
android:background="@color/background_grey"
tools:context=".activities.MainActivity">
<!-- TODO: Update blank fragment layout -->
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
@ -84,6 +82,7 @@
android:textOff="@string/stop"
android:textOn="@string/btn_start_text"
android:textStyle="bold"
app:cornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

View File

@ -22,70 +22,92 @@
app:title="@string/app_name" />
</com.google.android.material.appbar.AppBarLayout>
<EditText
android:id="@+id/setting_input_username"
style="@style/input_field"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_username_layout"
style="@style/LoginTextInputLayoutStyle"
android:layout_width="240dp"
android:layout_height="42dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:colorControlNormal="@color/logo_blue"
android:ems="10"
android:hint="@string/username"
android:inputType="textPersonName"
android:textAlignment="center"
android:textColor="@color/logo_white"
app:layout_constraintBottom_toTopOf="@+id/input_password"
android:textColorHint="@color/logo_white"
app:boxBackgroundColor="@color/common_google_signin_btn_text_dark_disabled"
app:boxBackgroundMode="outline"
app:layout_constraintBottom_toTopOf="@+id/input_password_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.49"
app:layout_constraintVertical_chainStyle="packed" />
app:layout_constraintVertical_chainStyle="packed">
<EditText
android:id="@+id/input_password"
style="@style/input_field"
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/input_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:textAppearance="@style/text_style"
android:textColor="@color/logo_white"
android:textColorHint="@color/logo_white" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_password_layout"
style="@style/LoginTextInputLayoutStyle"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="32dp"
android:ems="10"
android:hint="@string/password"
android:inputType="textPassword"
android:textAlignment="center"
android:textColorHint="@color/logo_white"
app:boxBackgroundColor="@color/common_google_signin_btn_text_dark_disabled"
app:boxBackgroundMode="outline"
app:layout_constraintBottom_toTopOf="@+id/button_create_account"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/setting_input_username"
app:layout_constraintVertical_bias="0.13" />
app:layout_constraintTop_toBottomOf="@+id/input_username_layout"
app:layout_constraintVertical_bias="0.13">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:textAppearance="@style/text_style"
android:textColor="@color/logo_white"
android:textColorHint="@color/logo_white" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/button_create_account"
style="@style/Widget.AppCompat.Button"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_height="55dp"
android:layout_marginTop="32dp"
android:layout_marginBottom="16dp"
android:background="@drawable/outlined_button_filled"
android:backgroundTint="@color/colorAccent"
android:text="@string/login"
android:textAppearance="@style/text_style"
android:textStyle="bold"
app:cornerRadius="8dp"
app:layout_constraintBottom_toTopOf="@+id/button_register"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/input_password" />
app:layout_constraintTop_toBottomOf="@+id/input_password_layout" />
<Button
android:id="@+id/button_register"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:background="@drawable/outlined_button"
android:layout_height="55dp"
android:backgroundTint="@color/colorPrimaryDark"
android:text="@string/register"
android:textAppearance="@style/text_style"
android:textStyle="bold"
app:cornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"

View File

@ -35,10 +35,10 @@
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="@+id/button_create_account"
app:layout_constraintEnd_toEndOf="@+id/input_email_register"
app:layout_constraintTop_toBottomOf="@+id/input_password" />
app:layout_constraintTop_toBottomOf="@+id/input_password_layout" />
<EditText
android:id="@+id/input_password"
android:id="@+id/input_password_layout"
style="@style/input_field"
android:layout_width="240dp"
android:layout_height="wrap_content"
@ -78,24 +78,26 @@
android:colorControlNormal="@color/logo_blue"
android:ems="10"
android:foregroundTint="@color/colorAccent"
android:hint="@string/username"
android:hint="@string/choose_username"
android:inputType="textPersonName"
android:textAlignment="center"
android:textColor="@color/logo_white"
app:layout_constraintBottom_toTopOf="@+id/input_password"
app:layout_constraintBottom_toTopOf="@+id/input_password_layout"
app:layout_constraintEnd_toEndOf="@+id/input_email_register"
app:layout_constraintTop_toBottomOf="@+id/input_email_register" />
<Button
android:id="@+id/button_create_account"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin16"
android:layout_marginBottom="175dp"
android:background="@drawable/outlined_button_filled"
android:backgroundTint="@color/logo_blue"
android:text="@string/create_account"
android:textAppearance="@style/text_style"
android:textStyle="bold"
app:cornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/input_email_register"
app:layout_constraintTop_toBottomOf="@+id/input_password2" />

View File

@ -68,7 +68,7 @@
android:background="@color/colorAccent" />
<EditText
android:id="@+id/setting_input_username"
android:id="@+id/input_username_layout"
style="@style/input_field"
android:layout_width="match_parent"
android:layout_height="42dp"

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<color name="colorPrimary">#272727</color>
<color name="colorPrimaryDark">#272727</color>
<color name="colorAccent">#0096ff</color>
<color name="background_grey">#131313</color>
<color name="logo_blue">#0096ff</color>
<color name="logo_white">#EBE7D9</color>
<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">@color/logo_white</color>
</resources>

View File

@ -9,7 +9,8 @@
<string name="pause">PAUSE</string>
<string name="stop">STOP</string>
<string name="username_email">Your Username or E-Mail</string>
<string name="username">Choose a Username</string>
<string name="username">Username</string>
<string name="choose_username">Choose a Username</string>
<string name="email">E-Mail</string>
<string name="password">Password</string>
<string name="login">Login</string>

View File

@ -20,5 +20,10 @@
<item name="android:fontFamily">@font/montserrat</item>
<item name="android:textSize">18sp</item>
</style>
<style name="LoginTextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">@color/logo_blue</item>
<item name="boxStrokeWidth">2dp</item>
<item name="hintTextColor">@color/logo_white</item>
</style>
</resources>