mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Set theme and onClicks in the UIObject interfaces onStart
Also: - Introduce a new temporary bug: The themes do not change anymore, as they will be switched dynamically soon (before I request pull) - Start adding good documentation - Speed up the apps list a little
This commit is contained in:
parent
5d71cf7113
commit
90e1f8893b
15 changed files with 54 additions and 110 deletions
|
@ -12,6 +12,7 @@ import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
|
import android.util.DisplayMetrics
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.animation.*
|
import android.view.animation.*
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
|
@ -27,6 +28,8 @@ import kotlin.math.roundToInt
|
||||||
lateinit var launcherPreferences: SharedPreferences
|
lateinit var launcherPreferences: SharedPreferences
|
||||||
|
|
||||||
/** Variables containing settings */
|
/** Variables containing settings */
|
||||||
|
val displayMetrics = DisplayMetrics()
|
||||||
|
|
||||||
var upApp = ""
|
var upApp = ""
|
||||||
var downApp = ""
|
var downApp = ""
|
||||||
var rightApp = ""
|
var rightApp = ""
|
||||||
|
|
|
@ -6,11 +6,9 @@ import android.net.Uri
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.DisplayMetrics
|
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.GestureDetectorCompat
|
import androidx.core.view.GestureDetectorCompat
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import com.finnmglas.launcher.list.apps.AppsRecyclerAdapter
|
import com.finnmglas.launcher.list.apps.AppsRecyclerAdapter
|
||||||
import com.finnmglas.launcher.tutorial.TutorialActivity
|
import com.finnmglas.launcher.tutorial.TutorialActivity
|
||||||
import kotlinx.android.synthetic.main.home.*
|
import kotlinx.android.synthetic.main.home.*
|
||||||
|
@ -19,20 +17,16 @@ import java.util.*
|
||||||
import kotlin.concurrent.fixedRateTimer
|
import kotlin.concurrent.fixedRateTimer
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
// used for the apps drawer / menu (ChooseActivity)
|
// used in `ListFragmentApps`
|
||||||
lateinit var viewAdapter: RecyclerView.Adapter<*>
|
lateinit var appListViewAdapter: AppsRecyclerAdapter
|
||||||
|
|
||||||
class HomeActivity: UIObject, AppCompatActivity(),
|
class HomeActivity: UIObject, AppCompatActivity(),
|
||||||
GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
|
GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
|
||||||
|
|
||||||
private var currentTheme = "" // keep track of theme changes
|
private var currentTheme = "" // keep track of theme changes
|
||||||
|
|
||||||
/** Variables for this activity */
|
|
||||||
private lateinit var mDetector: GestureDetectorCompat
|
private lateinit var mDetector: GestureDetectorCompat
|
||||||
|
|
||||||
// get device dimensions
|
|
||||||
private val displayMetrics = DisplayMetrics()
|
|
||||||
|
|
||||||
// timers
|
// timers
|
||||||
private var clockTimer = Timer()
|
private var clockTimer = Timer()
|
||||||
private var tooltipTimer = Timer()
|
private var tooltipTimer = Timer()
|
||||||
|
@ -43,48 +37,38 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
// Initialise globals
|
||||||
launcherPreferences = this.getSharedPreferences(
|
launcherPreferences = this.getSharedPreferences(
|
||||||
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
||||||
|
|
||||||
loadSettings()
|
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||||
currentTheme = getSavedTheme(this)
|
|
||||||
|
|
||||||
// TODO: Don't use actual themes, rather create them on the fly
|
loadSettings()
|
||||||
setTheme(
|
|
||||||
when (getSavedTheme(this)) {
|
// Preload list of apps (speed up loading time)
|
||||||
"dark" -> R.style.darkTheme
|
AsyncTask.execute {
|
||||||
"finn" -> R.style.finnmglasTheme
|
appListViewAdapter = AppsRecyclerAdapter(this)
|
||||||
else -> R.style.customTheme
|
}
|
||||||
}
|
|
||||||
)
|
// First time opening the app: show Tutorial
|
||||||
|
if (!launcherPreferences.getBoolean("startedBefore", false))
|
||||||
|
startActivity(Intent(this, TutorialActivity::class.java))
|
||||||
|
|
||||||
|
// Initialise layout
|
||||||
setContentView(R.layout.home)
|
setContentView(R.layout.home)
|
||||||
|
|
||||||
// Load apps list first - speed up settings that way
|
currentTheme = getSavedTheme(this)
|
||||||
AsyncTask.execute { viewAdapter =
|
|
||||||
AppsRecyclerAdapter(this, "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// First Startup
|
|
||||||
if (!launcherPreferences.getBoolean("startedBefore", false)){
|
|
||||||
startActivity(Intent(this, TutorialActivity::class.java))
|
|
||||||
tooltipTimer.cancel()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart(){
|
override fun onStart(){
|
||||||
super<AppCompatActivity>.onStart()
|
super<AppCompatActivity>.onStart()
|
||||||
super<UIObject>.onStart()
|
|
||||||
|
|
||||||
mDetector = GestureDetectorCompat(this, this)
|
mDetector = GestureDetectorCompat(this, this)
|
||||||
mDetector.setOnDoubleTapListener(this)
|
mDetector.setOnDoubleTapListener(this)
|
||||||
|
|
||||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
|
||||||
|
|
||||||
// for if the settings changed
|
// for if the settings changed
|
||||||
loadSettings()
|
loadSettings()
|
||||||
|
super<UIObject>.onStart()
|
||||||
setTheme()
|
|
||||||
setOnClicks()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
@ -124,14 +108,10 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) { if (settingsIconShown) hideSettingsIcon() }
|
if (keyCode == KeyEvent.KEYCODE_BACK) { if (settingsIconShown) hideSettingsIcon() }
|
||||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP)
|
||||||
launch(volumeUpApp, this)
|
launch(volumeUpApp, this,0, 0)
|
||||||
overridePendingTransition(0, 0)
|
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
|
||||||
}
|
launch(volumeDownApp, this,0, 0)
|
||||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
|
||||||
launch(volumeDownApp, this)
|
|
||||||
overridePendingTransition(0, 0)
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,14 @@ interface UIObject {
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTheme()
|
||||||
|
setOnClicks()
|
||||||
|
configure()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setTheme()
|
// Don't use actual themes, rather create them on the fly for faster theme-switching
|
||||||
fun setOnClicks()
|
fun setTheme() { } // colors
|
||||||
fun configure() {}
|
fun setOnClicks() { } // onClicks
|
||||||
|
fun configure() { } // layoutElements
|
||||||
}
|
}
|
|
@ -30,19 +30,8 @@ class ListActivity : AppCompatActivity(), UIObject {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
// TODO: Don't use actual themes, rather create them on the fly
|
// Initialise layout
|
||||||
setTheme(
|
|
||||||
when (getSavedTheme(this)) {
|
|
||||||
"dark" -> R.style.darkTheme
|
|
||||||
"finn" -> R.style.finnmglasTheme
|
|
||||||
else -> R.style.finnmglasTheme
|
|
||||||
}
|
|
||||||
)
|
|
||||||
setContentView(R.layout.list)
|
setContentView(R.layout.list)
|
||||||
|
|
||||||
setTheme()
|
|
||||||
setOnClicks()
|
|
||||||
configure()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart(){
|
override fun onStart(){
|
||||||
|
|
|
@ -2,6 +2,9 @@ package com.finnmglas.launcher.list.apps
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores information used in [AppsRecyclerAdapter] rows.
|
||||||
|
*/
|
||||||
class AppInfo {
|
class AppInfo {
|
||||||
var label: CharSequence? = null
|
var label: CharSequence? = null
|
||||||
var packageName: CharSequence? = null
|
var packageName: CharSequence? = null
|
||||||
|
|
|
@ -16,7 +16,7 @@ import com.finnmglas.launcher.*
|
||||||
import com.finnmglas.launcher.libraries.*
|
import com.finnmglas.launcher.libraries.*
|
||||||
import com.finnmglas.launcher.list.intendedChoosePause
|
import com.finnmglas.launcher.list.intendedChoosePause
|
||||||
|
|
||||||
class AppsRecyclerAdapter(val activity: Activity, val action: String?, val forApp: String?):
|
class AppsRecyclerAdapter(val activity: Activity, val action: String? = "view", val forApp: String? = ""):
|
||||||
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
|
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private val appsList: MutableList<AppInfo>
|
private val appsList: MutableList<AppInfo>
|
||||||
|
|
|
@ -31,9 +31,6 @@ class ListFragmentApps : Fragment(), UIObject {
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super<Fragment>.onStart()
|
super<Fragment>.onStart()
|
||||||
super<UIObject>.onStart()
|
super<UIObject>.onStart()
|
||||||
|
|
||||||
setTheme()
|
|
||||||
configure()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setTheme() {
|
override fun setTheme() {
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package com.finnmglas.launcher.list.other
|
package com.finnmglas.launcher.list.other
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores information used in [OtherRecyclerAdapter] rows.
|
||||||
|
*/
|
||||||
class OtherInfo(label: String, data: String, icon: String) {
|
class OtherInfo(label: String, data: String, icon: String) {
|
||||||
var label: CharSequence? = label
|
var label: CharSequence? = label
|
||||||
var data: CharSequence? = data
|
var data: CharSequence? = data
|
||||||
|
|
|
@ -26,25 +26,15 @@ class SettingsActivity: AppCompatActivity(), UIObject {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
// TODO: Don't use actual themes, rather create them on the fly
|
// Initialise layout
|
||||||
setTheme(
|
|
||||||
when (getSavedTheme(this)) {
|
|
||||||
"dark" -> R.style.darkTheme
|
|
||||||
"finn" -> R.style.finnmglasTheme
|
|
||||||
else -> R.style.customTheme
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
setContentView(R.layout.settings)
|
setContentView(R.layout.settings)
|
||||||
setTheme()
|
|
||||||
setOnClicks()
|
|
||||||
|
|
||||||
|
// set up tabs and swiping in settings
|
||||||
val sectionsPagerAdapter = SettingsSectionsPagerAdapter(this, supportFragmentManager)
|
val sectionsPagerAdapter = SettingsSectionsPagerAdapter(this, supportFragmentManager)
|
||||||
val viewPager: ViewPager = findViewById(R.id.settings_viewpager)
|
val viewPager: ViewPager = findViewById(R.id.settings_viewpager)
|
||||||
viewPager.adapter = sectionsPagerAdapter
|
viewPager.adapter = sectionsPagerAdapter
|
||||||
val tabs: TabLayout = findViewById(R.id.settings_tabs)
|
val tabs: TabLayout = findViewById(R.id.settings_tabs)
|
||||||
tabs.setupWithViewPager(viewPager)
|
tabs.setupWithViewPager(viewPager)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package com.finnmglas.launcher.settings.actions
|
package com.finnmglas.launcher.settings.actions
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores information used in [ActionsRecyclerAdapter] rows.
|
||||||
|
*/
|
||||||
class ActionInfo(actionText: CharSequence, actionName: CharSequence, content: CharSequence) {
|
class ActionInfo(actionText: CharSequence, actionName: CharSequence, content: CharSequence) {
|
||||||
var actionName: CharSequence? = actionName
|
val actionName: CharSequence? = actionName
|
||||||
var actionText: CharSequence? = actionText
|
val actionText: CharSequence? = actionText
|
||||||
var content: CharSequence? = content
|
val content: CharSequence? = content
|
||||||
}
|
}
|
|
@ -29,9 +29,7 @@ class ActionsRecyclerAdapter(val activity: Activity):
|
||||||
var chooseButton: Button = itemView.findViewById(R.id.settings_actions_row_button_choose)
|
var chooseButton: Button = itemView.findViewById(R.id.settings_actions_row_button_choose)
|
||||||
var removeAction: FontAwesome = itemView.findViewById(R.id.settings_actions_row_remove)
|
var removeAction: FontAwesome = itemView.findViewById(R.id.settings_actions_row_remove)
|
||||||
|
|
||||||
override fun onClick(v: View) {
|
override fun onClick(v: View) { }
|
||||||
val pos = adapterPosition
|
|
||||||
}
|
|
||||||
|
|
||||||
init { itemView.setOnClickListener(this) }
|
init { itemView.setOnClickListener(this) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,6 @@ class SettingsFragmentActions : Fragment(), UIObject {
|
||||||
super<Fragment>.onStart()
|
super<Fragment>.onStart()
|
||||||
super<UIObject>.onStart()
|
super<UIObject>.onStart()
|
||||||
|
|
||||||
setTheme()
|
|
||||||
setOnClicks()
|
|
||||||
|
|
||||||
// set up the list / recycler
|
// set up the list / recycler
|
||||||
val actionViewManager = LinearLayoutManager(context)
|
val actionViewManager = LinearLayoutManager(context)
|
||||||
val actionViewAdapter = ActionsRecyclerAdapter( activity!! )
|
val actionViewAdapter = ActionsRecyclerAdapter( activity!! )
|
||||||
|
|
|
@ -33,9 +33,6 @@ class SettingsFragmentMeta : Fragment(), UIObject {
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super<Fragment>.onStart()
|
super<Fragment>.onStart()
|
||||||
super<UIObject>.onStart()
|
super<UIObject>.onStart()
|
||||||
|
|
||||||
setTheme()
|
|
||||||
setOnClicks()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Extra functions */
|
/** Extra functions */
|
||||||
|
|
|
@ -33,9 +33,6 @@ class SettingsFragmentTheme : Fragment(), UIObject {
|
||||||
override fun onStart(){
|
override fun onStart(){
|
||||||
super<Fragment>.onStart()
|
super<Fragment>.onStart()
|
||||||
super<UIObject>.onStart()
|
super<UIObject>.onStart()
|
||||||
|
|
||||||
setTheme()
|
|
||||||
setOnClicks()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
|
|
|
@ -9,41 +9,24 @@ import com.finnmglas.launcher.*
|
||||||
import kotlinx.android.synthetic.main.tutorial.*
|
import kotlinx.android.synthetic.main.tutorial.*
|
||||||
|
|
||||||
|
|
||||||
class TutorialActivity : AppCompatActivity(), UIObject{
|
class TutorialActivity : AppCompatActivity(), UIObject {
|
||||||
|
|
||||||
/** Variables for this activity */
|
|
||||||
|
|
||||||
private var menuNumber = 0
|
private var menuNumber = 0
|
||||||
private var defaultApps = mutableListOf<String>()
|
private var defaultApps = mutableListOf<String>()
|
||||||
private var isFirstTime = false
|
private var isFirstTime = false
|
||||||
|
|
||||||
/** Activity Lifecycle functions */
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
// TODO: Don't use actual themes, rather create them on the fly
|
// Initialise layout
|
||||||
setTheme(
|
|
||||||
when (getSavedTheme(this)) {
|
|
||||||
"dark" -> R.style.darkTheme
|
|
||||||
"finn" -> R.style.finnmglasTheme
|
|
||||||
else -> R.style.finnmglasTheme
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
setContentView(R.layout.tutorial)
|
setContentView(R.layout.tutorial)
|
||||||
setTheme()
|
|
||||||
setOnClicks()
|
|
||||||
|
|
||||||
|
|
||||||
loadMenu(this)
|
loadMenu(this)
|
||||||
|
|
||||||
|
// Check if it is the first time starting the app
|
||||||
isFirstTime = !launcherPreferences.getBoolean("startedBefore", false)
|
isFirstTime = !launcherPreferences.getBoolean("startedBefore", false)
|
||||||
|
|
||||||
if (isFirstTime)
|
if (isFirstTime)
|
||||||
defaultApps = resetSettings(this) // UP, DOWN, RIGHT, LEFT, VOLUME_UP, VOLUME_DOWN
|
defaultApps = resetSettings(this) // UP, DOWN, RIGHT, LEFT, VOLUME_UP, VOLUME_DOWN
|
||||||
else
|
else tutorial_appbar.visibility = View.VISIBLE
|
||||||
tutorial_appbar.visibility = View.VISIBLE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
|
@ -51,7 +34,6 @@ class TutorialActivity : AppCompatActivity(), UIObject{
|
||||||
super<UIObject>.onStart()
|
super<UIObject>.onStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Touch- and Key-related functions to navigate */
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
|
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
|
||||||
menuNumber++
|
menuNumber++
|
||||||
|
|
Loading…
Add table
Reference in a new issue