diff options
-rw-r--r-- | app/build.gradle | 1 | ||||
-rw-r--r-- | app/src/main/AndroidManifest.xml | 1 | ||||
-rw-r--r-- | app/src/main/java/me/texx/Texx/CameraActivity.kt | 54 | ||||
-rw-r--r-- | app/src/main/java/me/texx/Texx/LoginActivity.kt | 1 | ||||
-rw-r--r-- | app/src/main/java/me/texx/Texx/MainActivity.kt | 2 | ||||
-rw-r--r-- | app/src/main/java/me/texx/Texx/RoutingActivity.kt | 12 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_camera.xml | 33 | ||||
-rw-r--r-- | app/src/main/res/xml/network_security_config.xml | 2 |
8 files changed, 98 insertions, 8 deletions
diff --git a/app/build.gradle b/app/build.gradle index 738988b..3fb7432 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,6 +24,7 @@ android { } dependencies { + implementation 'com.otaliastudios:cameraview:1.5.1' implementation 'com.github.mukeshsolanki:easypreferences:1.0.6' implementation 'com.kazakago.cryptore:cryptore:1.3.0' implementation 'com.github.kittinunf.fuel:fuel-android:1.6.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4a05354..b27c25b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -39,6 +39,7 @@ android:name="android.support.PARENT_ACTIVITY" android:value="me.texx.Texx.MainActivity" /> </activity> + <activity android:name=".CameraActivity"></activity> </application> </manifest>
\ No newline at end of file diff --git a/app/src/main/java/me/texx/Texx/CameraActivity.kt b/app/src/main/java/me/texx/Texx/CameraActivity.kt new file mode 100644 index 0000000..df03164 --- /dev/null +++ b/app/src/main/java/me/texx/Texx/CameraActivity.kt @@ -0,0 +1,54 @@ +package me.texx.Texx + +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import android.view.Window +import android.view.WindowManager +import com.otaliastudios.cameraview.CameraListener +import daio.io.dresscode.dressCodeName +import daio.io.dresscode.matchDressCode +import kotlinx.android.synthetic.main.activity_camera.* +import me.texx.Texx.util.ThemeUtil.getThemeName +import org.jetbrains.anko.toast + +class CameraActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + matchDressCode() + super.onCreate(savedInstanceState) + dressCodeName = getThemeName(this) + requestWindowFeature(Window.FEATURE_NO_TITLE) + window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN) + setContentView(R.layout.activity_camera) + + initCameraLayout() + } + + private fun initCameraLayout() { + camera.addCameraListener(object : CameraListener() { + override fun onPictureTaken(jpeg: ByteArray?) { + toast("Photo taken") + } + }) + + photo_button.setOnClickListener { + camera.capturePicture() + } + } + + override fun onResume() { + super.onResume() + camera.start() + } + + override fun onPause() { + super.onPause() + camera.stop() + } + + override fun onDestroy() { + super.onDestroy() + camera.destroy() + } +} diff --git a/app/src/main/java/me/texx/Texx/LoginActivity.kt b/app/src/main/java/me/texx/Texx/LoginActivity.kt index 3674593..baa91ae 100644 --- a/app/src/main/java/me/texx/Texx/LoginActivity.kt +++ b/app/src/main/java/me/texx/Texx/LoginActivity.kt @@ -269,6 +269,7 @@ class LoginActivity : AppCompatActivity(), LoaderCallbacks<Cursor> { .responseJson() result.fold(success = { + // TODO: Fix password incorrect on server down/no internet connection at login val accessToken = result.get().obj().getString("access_token") val userID = result.get().obj().getString("user_id") diff --git a/app/src/main/java/me/texx/Texx/MainActivity.kt b/app/src/main/java/me/texx/Texx/MainActivity.kt index 8473efa..730f6b2 100644 --- a/app/src/main/java/me/texx/Texx/MainActivity.kt +++ b/app/src/main/java/me/texx/Texx/MainActivity.kt @@ -40,7 +40,7 @@ class MainActivity : AppCompatActivity() { longToast("No internet connection!") fab.setOnClickListener { view -> - // TODO: Add camera support + startActivity<CameraActivity>() } } diff --git a/app/src/main/java/me/texx/Texx/RoutingActivity.kt b/app/src/main/java/me/texx/Texx/RoutingActivity.kt index bed9973..3ef5486 100644 --- a/app/src/main/java/me/texx/Texx/RoutingActivity.kt +++ b/app/src/main/java/me/texx/Texx/RoutingActivity.kt @@ -17,7 +17,7 @@ import java.io.IOException * should be started next */ class RoutingActivity : AppCompatActivity() { - private val serverAddress = "192.168.0.104" + private val serverAddress = "192.168.137.1" override fun onCreate(savedInstanceState: Bundle?) { matchDressCode() @@ -49,12 +49,12 @@ class RoutingActivity : AppCompatActivity() { .header("Authorization" to "Bearer $accessToken") .responseJson { _, response, result -> val (_, serverError) = result - when { - response.httpStatusCode == 200 -> startActivity<MainActivity>() - response.httpStatusCode == 401 -> startActivity<LoginActivity>() - !isConnected() -> startActivity<MainActivity>("notConnected" to true) + when { // TODO: Cleaner task solution + response.httpStatusCode == 200 -> startActivity(intentFor<MainActivity>().newTask().clearTask().noAnimation().excludeFromRecents()) + response.httpStatusCode == 401 -> startActivity(intentFor<LoginActivity>().newTask().clearTask().noAnimation().excludeFromRecents()) + !isConnected() -> startActivity(intentFor<MainActivity>("notConnected" to true).newTask().clearTask().noAnimation().excludeFromRecents()) serverError != null -> startActivity(intentFor<MainActivity>("serverDown" to true).newTask().clearTask().noAnimation().excludeFromRecents()) - else -> startActivity<LoginActivity>() + else -> startActivity(intentFor<LoginActivity>().newTask().clearTask().noAnimation().excludeFromRecents()) } } } else { diff --git a/app/src/main/res/layout/activity_camera.xml b/app/src/main/res/layout/activity_camera.xml new file mode 100644 index 0000000..527db7c --- /dev/null +++ b/app/src/main/res/layout/activity_camera.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".CameraActivity"> + + <Button + android:id="@+id/photo_button" + android:layout_width="100dp" + android:layout_height="100dp" + android:layout_marginBottom="48dp" + android:layout_marginEnd="8dp" + android:layout_marginStart="8dp" + android:background="@drawable/focus_marker_outline" + app:layout_constraintBottom_toBottomOf="@+id/camera" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" /> + + <com.otaliastudios.cameraview.CameraView + android:id="@+id/camera" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:keepScreenOn="true" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + </com.otaliastudios.cameraview.CameraView> + +</android.support.constraint.ConstraintLayout>
\ No newline at end of file diff --git a/app/src/main/res/xml/network_security_config.xml b/app/src/main/res/xml/network_security_config.xml index fc31d2f..efe965f 100644 --- a/app/src/main/res/xml/network_security_config.xml +++ b/app/src/main/res/xml/network_security_config.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> - <domain includeSubdomains="true">192.168.0.102</domain> + <domain includeSubdomains="true">192.168.137.1</domain> </domain-config> </network-security-config>
\ No newline at end of file |