mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Create recycler with other internal actions
Internal activities (settings or the apps list) can be opened through swiping or buttonpresses. Closes #33
This commit is contained in:
parent
2eb5e15334
commit
193df99624
8 changed files with 177 additions and 22 deletions
|
@ -79,7 +79,7 @@ class MainActivity : AppCompatActivity(),
|
|||
showSettingsIcon()
|
||||
|
||||
// As older APIs somehow do not recognize the xml defined onClick
|
||||
activity_main_settings_icon.setOnClickListener() { openSettings() }
|
||||
activity_main_settings_icon.setOnClickListener() { openSettings(this) }
|
||||
|
||||
// Load apps list first - speed up settings that way
|
||||
AsyncTask.execute { viewAdapter = AppsRecyclerAdapter( this, "", "") }
|
||||
|
@ -139,22 +139,17 @@ class MainActivity : AppCompatActivity(),
|
|||
clockTimer.cancel()
|
||||
}
|
||||
|
||||
private fun openSettings(){
|
||||
startActivity(Intent(this, SettingsActivity::class.java))
|
||||
overridePendingTransition(R.anim.bottom_up, android.R.anim.fade_out)
|
||||
}
|
||||
|
||||
/** Touch- and Key-related functions to start activities */
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) { if (settingsIconShown) hideSettingsIcon() }
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) launchApp(volumeUpApp, this)
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) launchApp(volumeDownApp, this)
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) launch(volumeUpApp, this)
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) launch(volumeDownApp, this)
|
||||
return true
|
||||
}
|
||||
|
||||
fun dateViewOnTouch(v: View) { launchApp(calendarApp, this) }
|
||||
fun timeViewOnTouch(v: View) { launchApp(clockApp, this) }
|
||||
fun dateViewOnTouch(v: View) { launch(calendarApp, this) }
|
||||
fun timeViewOnTouch(v: View) { launch(clockApp, this) }
|
||||
|
||||
override fun onFling(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean {
|
||||
|
||||
|
@ -167,21 +162,21 @@ class MainActivity : AppCompatActivity(),
|
|||
val strictness = 4 // how distinguished the swipe has to be to be accepted
|
||||
|
||||
// Only open if the swipe was not from the phones top edge
|
||||
if (diffY < -height / 8 && abs(diffY) > strictness * abs(diffX) && e1.y > 100) launchApp(downApp, this)
|
||||
else if (diffY > height / 8 && abs(diffY) > strictness * abs(diffX)) launchApp(upApp, this)
|
||||
else if (diffX > width / 4 && abs(diffX) > strictness * abs(diffY)) launchApp(leftApp, this)
|
||||
else if (diffX < -width / 4 && abs(diffX) > strictness * abs(diffY)) launchApp(rightApp, this)
|
||||
if (diffY < -height / 8 && abs(diffY) > strictness * abs(diffX) && e1.y > 100) launch(downApp, this)
|
||||
else if (diffY > height / 8 && abs(diffY) > strictness * abs(diffX)) launch(upApp, this)
|
||||
else if (diffX > width / 4 && abs(diffX) > strictness * abs(diffY)) launch(leftApp, this)
|
||||
else if (diffX < -width / 4 && abs(diffX) > strictness * abs(diffY)) launch(rightApp, this)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onLongPress(event: MotionEvent) {
|
||||
if(longClickApp != "") launchApp(longClickApp, this)
|
||||
else openSettings()
|
||||
if(longClickApp != "") launch(longClickApp, this)
|
||||
else openSettings(this)
|
||||
}
|
||||
|
||||
override fun onDoubleTap(event: MotionEvent): Boolean {
|
||||
launchApp(doubleClickApp, this)
|
||||
launch(doubleClickApp, this)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -213,7 +208,7 @@ class MainActivity : AppCompatActivity(),
|
|||
settingsIconShown = false
|
||||
}
|
||||
|
||||
fun settingsIconOnTouch(view: View){ openSettings() }
|
||||
fun settingsIconOnTouch(view: View){ openSettings(this) }
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
return if (mDetector.onTouchEvent(event)) { false } else { super.onTouchEvent(event) }
|
||||
|
|
|
@ -5,7 +5,9 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.finnmglas.launcher.R
|
||||
import com.finnmglas.launcher.choose.other.OtherRecyclerAdapter
|
||||
import com.finnmglas.launcher.extern.dominantColor
|
||||
import com.finnmglas.launcher.extern.getSavedTheme
|
||||
import kotlinx.android.synthetic.main.fragment_choose_other.*
|
||||
|
@ -28,6 +30,17 @@ class ChooseFragmentOther : Fragment() {
|
|||
fragment_choose_other_container.setBackgroundColor(dominantColor)
|
||||
}
|
||||
|
||||
// set up the list / recycler
|
||||
val viewManager = LinearLayoutManager(context)
|
||||
val viewAdapter = OtherRecyclerAdapter(activity!!)
|
||||
|
||||
fragment_choose_other_recycler_view.apply {
|
||||
// improve performance (since content changes don't change the layout size)
|
||||
setHasFixedSize(true)
|
||||
layoutManager = viewManager
|
||||
adapter = viewAdapter
|
||||
}
|
||||
|
||||
super.onStart()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.finnmglas.launcher.choose.other
|
||||
|
||||
class OtherInfo(label: String, data: String) {
|
||||
var label: CharSequence? = label
|
||||
var data: CharSequence? = data
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.finnmglas.launcher.choose.other
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.finnmglas.launcher.R
|
||||
import com.finnmglas.launcher.extern.*
|
||||
import com.finnmglas.launcher.forApp
|
||||
|
||||
/* Will only be used if an app / action is picked */
|
||||
class OtherRecyclerAdapter(val activity: Activity):
|
||||
RecyclerView.Adapter<OtherRecyclerAdapter.ViewHolder>() {
|
||||
|
||||
private val othersList: MutableList<OtherInfo>
|
||||
|
||||
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
|
||||
View.OnClickListener {
|
||||
var textView: TextView = itemView.findViewById(R.id.row_other_name)
|
||||
|
||||
|
||||
override fun onClick(v: View) {
|
||||
val pos = adapterPosition
|
||||
val content = othersList[pos]
|
||||
|
||||
returnChoiceIntent(forApp, content.data.toString())
|
||||
}
|
||||
|
||||
init { itemView.setOnClickListener(this) }
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: ViewHolder, i: Int) {
|
||||
val otherLabel = othersList[i].label.toString()
|
||||
val otherData = othersList[i].data.toString()
|
||||
|
||||
viewHolder.textView.text = otherLabel
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int { return othersList.size }
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val view: View = inflater.inflate(R.layout.recycler_other_row, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
init {
|
||||
othersList = ArrayList()
|
||||
othersList.add(OtherInfo("Settings", "launcher:settings"))
|
||||
othersList.add(OtherInfo("AppsList", "launcher:choose"))
|
||||
}
|
||||
|
||||
/* */
|
||||
private fun returnChoiceIntent(forAction: String, value: String) {
|
||||
val returnIntent = Intent()
|
||||
returnIntent.putExtra("value", value)
|
||||
returnIntent.putExtra("forApp", forApp)
|
||||
activity.setResult(REQUEST_CHOOSE_APP, returnIntent)
|
||||
activity.finish()
|
||||
}
|
||||
}
|
|
@ -17,7 +17,10 @@ import android.view.animation.*
|
|||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.ContextCompat.startActivity
|
||||
import com.finnmglas.launcher.ChooseActivity
|
||||
import com.finnmglas.launcher.R
|
||||
import com.finnmglas.launcher.SettingsActivity
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
|
@ -134,9 +137,19 @@ private fun getIntent(packageName: String, context: Context): Intent? {
|
|||
return intent
|
||||
}
|
||||
|
||||
// select what to launch
|
||||
fun launch(data: String, activity: Activity) {
|
||||
if (data.startsWith("launcher:")) // [type]:[info]
|
||||
when(data.split(":")[1]) {
|
||||
"settings" -> openSettings(activity)
|
||||
"choose" -> openAppsList(activity)
|
||||
}
|
||||
else launchApp(data, activity) // app
|
||||
|
||||
}
|
||||
|
||||
fun launchApp(packageName: String, context: Context) {
|
||||
val intent =
|
||||
getIntent(packageName, context)
|
||||
val intent = getIntent(packageName, context)
|
||||
|
||||
if (intent != null) {
|
||||
context.startActivity(intent)
|
||||
|
@ -203,6 +216,16 @@ fun openAppSettings(pkg :String, context:Context){
|
|||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
fun openSettings(activity: Activity){
|
||||
activity.startActivity(Intent(activity, SettingsActivity::class.java))
|
||||
activity.overridePendingTransition(R.anim.bottom_up, android.R.anim.fade_out)
|
||||
}
|
||||
|
||||
fun openAppsList(activity: Activity){
|
||||
activity.startActivity(Intent(activity, ChooseActivity::class.java))
|
||||
activity.overridePendingTransition(R.anim.bottom_up, android.R.anim.fade_out)
|
||||
}
|
||||
|
||||
fun loadSettings(sharedPref : SharedPreferences){
|
||||
upApp = sharedPref.getString("action_upApp", "").toString()
|
||||
downApp = sharedPref.getString("action_downApp", "").toString()
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.finnmglas.launcher.settings
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
|
|
|
@ -14,6 +14,20 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/fragment_choose_other_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:scrollbars="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</LinearLayout>
|
41
app/src/main/res/layout/recycler_other_row.xml
Normal file
41
app/src/main/res/layout/recycler_other_row.xml
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.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="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/row_other_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="start"
|
||||
android:text=""
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/row_other_button"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/row_other_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_choose_btn"
|
||||
android:textAllCaps="false"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/row_other_icon"
|
||||
android:layout_width="@dimen/app_icon_side"
|
||||
android:layout_height="@dimen/app_icon_side"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@id/row_other_button"
|
||||
app:layout_constraintStart_toStartOf="@+id/row_other_button"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Add table
Reference in a new issue