forked from sduduzog/slim-launcher
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support long-press for settings and hiding quick buttons (#44)
* Open settings with long-press * Support customizing quick buttons Co-authored-by: jkuester <[email protected]>
- Loading branch information
Showing
11 changed files
with
268 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/com/sduduzog/slimlauncher/ui/dialogs/ChooseQuickButtonDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.sduduzog.slimlauncher.ui.dialogs | ||
|
||
import android.app.AlertDialog | ||
import android.app.Dialog | ||
import android.content.Context | ||
import android.content.DialogInterface | ||
import android.content.SharedPreferences | ||
import android.os.Bundle | ||
import androidx.core.content.edit | ||
import androidx.fragment.app.DialogFragment | ||
import com.sduduzog.slimlauncher.R | ||
|
||
class ChooseQuickButtonDialog(private var settingsKey: Int, private var defaultIconId: Int) : DialogFragment() { | ||
private lateinit var settings: SharedPreferences | ||
private var onDismissListener: DialogInterface.OnDismissListener? = null | ||
private val iconIdsByIndex = mapOf(0 to defaultIconId, 1 to R.drawable.ic_empty) | ||
private val indexesByIconId = iconIdsByIndex.entries.associate { it.value to it.key } | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
val builder = AlertDialog.Builder(requireContext()) | ||
settings = requireContext().getSharedPreferences(getString(R.string.prefs_settings), Context.MODE_PRIVATE) | ||
|
||
val currentIconId = settings.getInt(getString(settingsKey), defaultIconId) | ||
|
||
builder.setTitle(R.string.options_fragment_customize_quick_buttons) | ||
|
||
builder.setSingleChoiceItems(R.array.quick_button_array, indexesByIconId[currentIconId]!!) { dialogInterface, i -> | ||
dialogInterface.dismiss() | ||
settings.edit { | ||
putInt(getString(settingsKey), iconIdsByIndex[i]!!) | ||
} | ||
|
||
} | ||
return builder.create() | ||
} | ||
|
||
fun setOnDismissListener(onDismissListener: DialogInterface.OnDismissListener?) { | ||
this.onDismissListener = onDismissListener | ||
} | ||
|
||
override fun onDismiss(dialog: DialogInterface) { | ||
super.onDismiss(dialog) | ||
onDismissListener?.onDismiss(dialog) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/src/main/java/com/sduduzog/slimlauncher/ui/options/CustomizeQuickButtonsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.sduduzog.slimlauncher.ui.options | ||
|
||
import android.content.Context | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.sduduzog.slimlauncher.R | ||
import com.sduduzog.slimlauncher.ui.dialogs.ChooseQuickButtonDialog | ||
import com.sduduzog.slimlauncher.utils.BaseFragment | ||
import kotlinx.android.synthetic.main.customize_quick_buttons_fragment.* | ||
|
||
class CustomizeQuickButtonsFragment : BaseFragment() { | ||
override fun getFragmentView(): ViewGroup = customize_quick_buttons_fragment | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return inflater.inflate(R.layout.customize_quick_buttons_fragment, container, false) | ||
} | ||
|
||
override fun onActivityCreated(savedInstanceState: Bundle?) { | ||
super.onActivityCreated(savedInstanceState) | ||
|
||
customize_quick_buttons_fragment_left.setOnClickListener { | ||
val chooseTimeFormatDialog = ChooseQuickButtonDialog(R.string.prefs_settings_key_quick_button_left_icon_id, R.drawable.ic_call) | ||
chooseTimeFormatDialog.setOnDismissListener(DialogInterface.OnDismissListener { | ||
setQuickButtonIcons() | ||
}) | ||
chooseTimeFormatDialog.showNow(childFragmentManager, "QUICK_BUTTON_CHOOSER") | ||
} | ||
customize_quick_buttons_fragment_center.setOnClickListener { | ||
val chooseTimeFormatDialog = ChooseQuickButtonDialog(R.string.prefs_settings_key_quick_button_center_icon_id, R.drawable.ic_cog) | ||
chooseTimeFormatDialog.setOnDismissListener(DialogInterface.OnDismissListener { | ||
setQuickButtonIcons() | ||
}) | ||
chooseTimeFormatDialog.showNow(childFragmentManager, "QUICK_BUTTON_CHOOSER") | ||
} | ||
customize_quick_buttons_fragment_right.setOnClickListener { | ||
val chooseTimeFormatDialog = ChooseQuickButtonDialog(R.string.prefs_settings_key_quick_button_right_icon_id, R.drawable.ic_photo_camera) | ||
chooseTimeFormatDialog.setOnDismissListener(DialogInterface.OnDismissListener { | ||
setQuickButtonIcons() | ||
}) | ||
chooseTimeFormatDialog.showNow(childFragmentManager, "QUICK_BUTTON_CHOOSER") | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
setQuickButtonIcons() | ||
} | ||
|
||
private fun setQuickButtonIcons() { | ||
customize_quick_buttons_fragment_left.setImageResource(getIcon(R.string.prefs_settings_key_quick_button_left_icon_id, R.drawable.ic_call)) | ||
customize_quick_buttons_fragment_center.setImageResource(getIcon(R.string.prefs_settings_key_quick_button_center_icon_id, R.drawable.ic_cog)) | ||
customize_quick_buttons_fragment_right.setImageResource(getIcon(R.string.prefs_settings_key_quick_button_right_icon_id, R.drawable.ic_photo_camera)) | ||
} | ||
|
||
private fun getIcon(buttonPrefKey: Int, defaultIconId: Int): Int { | ||
return context?.getSharedPreferences(getString(R.string.prefs_settings), Context.MODE_PRIVATE) | ||
?.getInt(getString(buttonPrefKey), defaultIconId) ?: defaultIconId | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path android:fillColor="#00000000" | ||
android:pathData="M0,0 L0,0 L0,0 z" /> | ||
</vector> |
62 changes: 62 additions & 0 deletions
62
app/src/main/res/layout/customize_quick_buttons_fragment.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?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:id="@+id/customize_quick_buttons_fragment" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ui.options.CustomizeQuickButtonsFragment"> | ||
|
||
<TextView | ||
android:id="@+id/customize_quick_buttons_fragment_header" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="@dimen/_16sdp" | ||
android:layout_marginTop="@dimen/_8sdp" | ||
android:text="@string/options_fragment_customize_quick_buttons" | ||
android:textAppearance="@style/TextAppearance.AppCompat" | ||
android:textSize="@dimen/_25ssp" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<ImageView | ||
android:id="@+id/customize_quick_buttons_fragment_left" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="@dimen/_8sdp" | ||
android:layout_marginBottom="@dimen/_8sdp" | ||
android:padding="@dimen/_8sdp" | ||
android:background="@layout/imageview_border" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:srcCompat="@drawable/ic_call" | ||
tools:ignore="ContentDescription" /> | ||
|
||
<ImageView | ||
android:id="@+id/customize_quick_buttons_fragment_center" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="@dimen/_8sdp" | ||
android:alpha="1" | ||
android:padding="@dimen/_8sdp" | ||
android:background="@layout/imageview_border" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toStartOf="@+id/customize_quick_buttons_fragment_right" | ||
app:layout_constraintStart_toEndOf="@+id/customize_quick_buttons_fragment_left" | ||
app:srcCompat="@drawable/ic_cog" | ||
tools:ignore="ContentDescription" /> | ||
|
||
<ImageView | ||
android:id="@+id/customize_quick_buttons_fragment_right" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="@dimen/_8sdp" | ||
android:layout_marginBottom="@dimen/_8sdp" | ||
android:padding="@dimen/_8sdp" | ||
android:background="@layout/imageview_border" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:srcCompat="@drawable/ic_photo_camera" | ||
tools:ignore="ContentDescription" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="wrap_content"> | ||
<stroke | ||
android:width="3dp" | ||
android:color="?attr/colorAccent" /> | ||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters