Create a basic tabbed settings activity

Tabs: Apps, Theme, Launcher
This commit is contained in:
Finn M Glas 2020-05-21 07:35:09 +02:00
parent 75af3f2866
commit abd7a44874
No known key found for this signature in database
GPG key ID: 25037A2E81AB459C
9 changed files with 126 additions and 305 deletions

View file

@ -8,20 +8,27 @@ import android.provider.Settings
import android.view.View import android.view.View
import android.view.WindowManager import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.viewpager.widget.ViewPager
import com.finnmglas.launcher.ui.main.SectionsPagerAdapter
import com.google.android.material.tabs.TabLayout
//TODO Make Settings scrollable as soon as more are added
class SettingsActivity : AppCompatActivity() { class SettingsActivity : AppCompatActivity() {
/** Activity Lifecycle functions */ /** Activity Lifecycle functions */
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN) window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
setContentView(R.layout.activity_settings) val sectionsPagerAdapter = SectionsPagerAdapter(this, supportFragmentManager)
val viewPager: ViewPager = findViewById(R.id.view_pager)
viewPager.adapter = sectionsPagerAdapter
val tabs: TabLayout = findViewById(R.id.tabs)
tabs.setupWithViewPager(viewPager)
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

View file

@ -0,0 +1,19 @@
package com.finnmglas.launcher.ui.main
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
class PageViewModel : ViewModel() {
private val _index = MutableLiveData<Int>()
val text: LiveData<String> = Transformations.map(_index) {
"Tab $it"
}
fun setIndex(index: Int) {
_index.value = index
}
}

View file

@ -0,0 +1,32 @@
package com.finnmglas.launcher.ui.main
import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.finnmglas.launcher.*
private val TAB_TITLES = arrayOf(
R.string.settings_tab_app,
R.string.settings_tab_theme,
R.string.settings_tab_launcher
)
/** Returns the fragment corresponding to the selected tab.*/
class SectionsPagerAdapter(private val context: Context, fm: FragmentManager)
: FragmentPagerAdapter(fm) {
override fun getItem(position: Int): Fragment {
return when (position){
else -> Fragment()
}
}
override fun getPageTitle(position: Int): CharSequence? {
return context.resources.getString(TAB_TITLES[position])
}
override fun getCount(): Int {
return 3
}
}

View file

@ -1,320 +1,56 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/colorPrimaryDark"
tools:context=".SettingsActivity"> tools:context=".SettingsActivity">
<TextView <com.google.android.material.appbar.AppBarLayout
android:id="@+id/heading" android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/settings_title" android:background="@color/colorPrimaryDark"
android:textColor="#cccccc" android:theme="@style/AppTheme.AppBarOverlay">
android:textSize="36sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.100000024" />
<TextView <LinearLayout
android:id="@+id/sub_head_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings_sub_title1"
android:textColor="#999"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias=".1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.189" />
<TableLayout
android:id="@+id/actionschooser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/sub_head_1"
app:layout_constraintVertical_bias="0.120000005">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:text="@string/settings_choose_up"
android:textColor="#ccc"
android:textSize="24sp" />
<Button
android:id="@+id/btn_choose_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha=".8"
android:onClick="chooseUpApp"
android:text="@string/settings_choose_btn" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:text="@string/settings_choose_down"
android:textColor="#ccc"
android:textSize="24sp" />
<Button
android:id="@+id/btn_choose_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha=".8"
android:onClick="chooseDownApp"
android:text="@string/settings_choose_btn" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:text="@string/settings_choose_left"
android:textColor="#ccc"
android:textSize="24sp" />
<Button
android:id="@+id/btn_choose_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha=".8"
android:onClick="chooseLeftApp"
android:text="@string/settings_choose_btn" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:text="@string/settings_choose_right"
android:textColor="#ccc"
android:textSize="24sp" />
<Button
android:id="@+id/btn_choose_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha=".8"
android:onClick="chooseRightApp"
android:text="@string/settings_choose_btn" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_vol_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:text="@string/settings_choose_vol_up"
android:textColor="#ccc"
android:textSize="24sp" />
<Button
android:id="@+id/btn_choose_volume_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha=".8"
android:onClick="chooseVolumeUpApp"
android:text="@string/settings_choose_btn" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_vol_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:text="@string/settings_choose_vol_down"
android:textColor="#ccc"
android:textSize="24sp" />
<Button
android:id="@+id/btn_choose_volume_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha=".8"
android:onClick="chooseVolumeDownApp"
android:text="@string/settings_choose_btn" />
</TableRow>
</TableLayout>
<TextView
android:id="@+id/sub_head_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings_sub_title2"
android:textColor="#999"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="@id/buttons"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/actionschooser"
app:layout_constraintVertical_bias="0.65999997" />
<TableLayout
android:id="@+id/buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/actionschooser"
app:layout_constraintVertical_bias="0.19999999">
<TableRow
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:orientation="horizontal">
<Button <TextView
style="@style/Widget.AppCompat.Button" android:id="@+id/title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:alpha=".3" android:gravity="center"
android:onClick="setLauncher" android:minHeight="?actionBarSize"
android:text="@string/settings_select_launcher" /> android:padding="@dimen/appbar_padding"
android:text="@string/settings_title"
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" />
<Button <com.finnmglas.launcher.FontAwesomeSolid
style="@style/Widget.AppCompat.Button" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_height="wrap_content" android:gravity="center|right"
android:alpha=".3" android:includeFontPadding="true"
android:onClick="resetSettingsClick"
android:text="@string/settings_reset" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
style="@style/Widget.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha=".3"
android:onClick="chooseLaunchApp"
android:text="@string/settings_launch" />
<Button
style="@style/Widget.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha=".3"
android:onClick="chooseUninstallApp"
android:text="@string/settings_uninstall" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="backHome" android:onClick="backHome"
android:text="@string/settings_home" /> android:paddingLeft="16sp"
</TableRow> android:paddingRight="16sp"
android:text="@string/fas_close_window"
android:textColor="#ffffff"
android:textSize="22sp" />
</LinearLayout>
</TableLayout> <com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
<LinearLayout android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.98">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/settings_footer_by" android:background="?attr/colorPrimaryDark" />
android:textColor="#999" </com.google.android.material.appbar.AppBarLayout>
android:textSize="18sp" />
<TextView <androidx.viewpager.widget.ViewPager
android:layout_width="wrap_content" android:id="@+id/view_pager"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:onClick="openFinnWebsite" android:layout_height="match_parent"
android:text=" Finn M Glas" android:background="@color/colorPrimary"
android:textColor="?attr/colorAccent" app:layout_behavior="@string/appbar_scrolling_view_behavior" />
android:textSize="18sp" </androidx.coordinatorlayout.widget.CoordinatorLayout>
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" | "
android:textColor="#999"
android:textSize="18sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="openGithubRepo"
android:text="Open Source"
android:textColor="?attr/colorAccent"
android:textSize="18sp"
tools:ignore="HardcodedText" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View file

@ -0,0 +1,8 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="appbar_padding">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen>
</resources>

View file

@ -4,6 +4,7 @@
<string name="fas_home" translatable="false">&#xf015;</string> <string name="fas_home" translatable="false">&#xf015;</string>
<string name="fas_globe" translatable="false">&#xf0ac;</string> <string name="fas_globe" translatable="false">&#xf0ac;</string>
<string name="fas_settings" translatable="false">&#xf013;</string> <string name="fas_settings" translatable="false">&#xf013;</string>
<string name="fas_close_window" translatable="false">&#xf410;</string>
<string name="fas_star" translatable="false">&#xf005;</string> <string name="fas_star" translatable="false">&#xf005;</string>
<string name="far_star" translatable="false">&#xf005;</string> <string name="far_star" translatable="false">&#xf005;</string>

View file

@ -18,6 +18,10 @@
<string name="settings_sub_title1">Applications</string> <string name="settings_sub_title1">Applications</string>
<string name="settings_sub_title2">Actions</string> <string name="settings_sub_title2">Actions</string>
<string name="settings_tab_app" translatable="false">Apps</string>
<string name="settings_tab_theme" translatable="false">Theme</string>
<string name="settings_tab_launcher" translatable="false">Launcher</string>
<string name="settings_choose_up">Swipe Up</string> <string name="settings_choose_up">Swipe Up</string>
<string name="settings_choose_down">Swipe Down</string> <string name="settings_choose_down">Swipe Down</string>
<string name="settings_choose_left">Swipe Left</string> <string name="settings_choose_left">Swipe Left</string>

View file

@ -9,4 +9,12 @@
<item name="android:windowDisablePreview">true</item> <item name="android:windowDisablePreview">true</item>
</style> </style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources> </resources>