From 65a497c585fd23d080ca084a80e97afb07aa0825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Thu, 3 Oct 2019 22:32:33 +0200 Subject: [PATCH] Add Stub Settings to Android --- android/app/build.gradle | 1 + android/app/src/main/AndroidManifest.xml | 3 ++ .../com/metallic/chiaki/main/MainActivity.kt | 26 ++++++++++++++++ .../chiaki/settings/SettingsActivity.kt | 31 +++++++++++++++++++ .../chiaki/settings/SettingsFragment.kt | 30 ++++++++++++++++++ .../main/res/drawable/ic_settings_48dp.xml | 4 +++ .../app/src/main/res/layout/activity_main.xml | 1 + .../src/main/res/layout/activity_settings.xml | 14 +++++++++ android/app/src/main/res/menu/main.xml | 9 ++++++ android/app/src/main/res/values/strings.xml | 1 + android/app/src/main/res/xml/preferences.xml | 11 +++++++ 11 files changed, 131 insertions(+) create mode 100644 android/app/src/main/java/com/metallic/chiaki/settings/SettingsActivity.kt create mode 100644 android/app/src/main/java/com/metallic/chiaki/settings/SettingsFragment.kt create mode 100644 android/app/src/main/res/drawable/ic_settings_48dp.xml create mode 100644 android/app/src/main/res/layout/activity_settings.xml create mode 100644 android/app/src/main/res/menu/main.xml create mode 100644 android/app/src/main/res/xml/preferences.xml diff --git a/android/app/build.gradle b/android/app/build.gradle index c195467..0f970ac 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -55,6 +55,7 @@ dependencies { implementation 'androidx.core:core-ktx:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.recyclerview:recyclerview:1.0.0' + implementation 'androidx.preference:preference:1.1.0' implementation 'com.google.android.material:material:1.1.0-alpha10' implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0' diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index bca0080..977e511 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -26,6 +26,9 @@ android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:screenOrientation="userLandscape"/> + + diff --git a/android/app/src/main/java/com/metallic/chiaki/main/MainActivity.kt b/android/app/src/main/java/com/metallic/chiaki/main/MainActivity.kt index 309cb51..34edd87 100644 --- a/android/app/src/main/java/com/metallic/chiaki/main/MainActivity.kt +++ b/android/app/src/main/java/com/metallic/chiaki/main/MainActivity.kt @@ -21,6 +21,8 @@ import android.app.ActivityOptions import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.view.Menu +import android.view.MenuItem import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProviders import androidx.recyclerview.widget.LinearLayoutManager @@ -28,6 +30,7 @@ import com.metallic.chiaki.R import com.metallic.chiaki.TestStartActivity import com.metallic.chiaki.common.getDatabase import com.metallic.chiaki.common.ext.viewModelFactory +import com.metallic.chiaki.settings.SettingsActivity import io.reactivex.disposables.CompositeDisposable import kotlinx.android.synthetic.main.activity_main.* @@ -40,6 +43,10 @@ class MainActivity : AppCompatActivity() super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + title = "" + setSupportActionBar(toolbar) + + addButton.setOnClickListener { Intent(this, TestStartActivity::class.java).also { it.putExtra(TestStartActivity.EXTRA_REVEAL_X, addButton.x + addButton.width * 0.5f) @@ -63,4 +70,23 @@ class MainActivity : AppCompatActivity() super.onDestroy() disposable.dispose() } + + override fun onCreateOptionsMenu(menu: Menu?): Boolean + { + menuInflater.inflate(R.menu.main, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean = when(item.itemId) + { + R.id.action_settings -> + { + Intent(this, SettingsActivity::class.java).also { + startActivity(it) + } + true + } + + else -> super.onOptionsItemSelected(item) + } } diff --git a/android/app/src/main/java/com/metallic/chiaki/settings/SettingsActivity.kt b/android/app/src/main/java/com/metallic/chiaki/settings/SettingsActivity.kt new file mode 100644 index 0000000..45919bd --- /dev/null +++ b/android/app/src/main/java/com/metallic/chiaki/settings/SettingsActivity.kt @@ -0,0 +1,31 @@ +/* + * This file is part of Chiaki. + * + * Chiaki is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chiaki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chiaki. If not, see . + */ + +package com.metallic.chiaki.settings + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import com.metallic.chiaki.R + +class SettingsActivity: AppCompatActivity() +{ + override fun onCreate(savedInstanceState: Bundle?) + { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_settings) + } +} \ No newline at end of file diff --git a/android/app/src/main/java/com/metallic/chiaki/settings/SettingsFragment.kt b/android/app/src/main/java/com/metallic/chiaki/settings/SettingsFragment.kt new file mode 100644 index 0000000..9dcee63 --- /dev/null +++ b/android/app/src/main/java/com/metallic/chiaki/settings/SettingsFragment.kt @@ -0,0 +1,30 @@ +/* + * This file is part of Chiaki. + * + * Chiaki is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chiaki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chiaki. If not, see . + */ + +package com.metallic.chiaki.settings + +import android.os.Bundle +import androidx.preference.PreferenceFragmentCompat +import com.metallic.chiaki.R + +class SettingsFragment: PreferenceFragmentCompat() +{ + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) + { + setPreferencesFromResource(R.xml.preferences, rootKey) + } +} \ No newline at end of file diff --git a/android/app/src/main/res/drawable/ic_settings_48dp.xml b/android/app/src/main/res/drawable/ic_settings_48dp.xml new file mode 100644 index 0000000..826bf4c --- /dev/null +++ b/android/app/src/main/res/drawable/ic_settings_48dp.xml @@ -0,0 +1,4 @@ + + + diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml index 3f3a61a..7cfcfbd 100644 --- a/android/app/src/main/res/layout/activity_main.xml +++ b/android/app/src/main/res/layout/activity_main.xml @@ -26,6 +26,7 @@ android:layout_height="wrap_content" android:layout_width="match_parent"> + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/menu/main.xml b/android/app/src/main/res/menu/main.xml new file mode 100644 index 0000000..25755cc --- /dev/null +++ b/android/app/src/main/res/menu/main.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index ff94885..268bfd0 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -8,4 +8,5 @@ Reconnect Quit Connect + Settings diff --git a/android/app/src/main/res/xml/preferences.xml b/android/app/src/main/res/xml/preferences.xml new file mode 100644 index 0000000..19e2975 --- /dev/null +++ b/android/app/src/main/res/xml/preferences.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file