mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Camera and phone gestures can now be toggled on or off
This commit is contained in:
parent
5dbb033993
commit
8eec1d9a9b
4 changed files with 133 additions and 2 deletions
|
|
@ -75,6 +75,9 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
|
||||
private lateinit var dateText: TextClock
|
||||
|
||||
private var cameraSwipeEnabled = true
|
||||
private var contactsSwipeEnabled = true
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -143,6 +146,8 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
setShortCutAlignment()
|
||||
setSearchAlignment()
|
||||
|
||||
setGestures()
|
||||
|
||||
adapter?.notifyDataSetChanged()
|
||||
|
||||
}
|
||||
|
|
@ -177,12 +182,12 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
}
|
||||
|
||||
// Detect swipe left
|
||||
else if (deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold){
|
||||
else if (cameraSwipeEnabled && deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold){
|
||||
startActivity(cameraIntent)
|
||||
}
|
||||
|
||||
// Detect swipe right
|
||||
else if (deltaX > -swipeThreshold && abs(velocityX) > swipeVelocityThreshold) {
|
||||
else if (contactsSwipeEnabled && deltaX > -swipeThreshold && abs(velocityX) > swipeVelocityThreshold) {
|
||||
startActivity(phoneIntent)
|
||||
}
|
||||
}
|
||||
|
|
@ -722,6 +727,15 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
|||
}
|
||||
}
|
||||
|
||||
private fun setGestures() {
|
||||
val cameraGesture = sharedPreferenceManager.getCameraEnabled(this@MainActivity)
|
||||
val contactsGesture = sharedPreferenceManager.getContactsEnabled(this@MainActivity)
|
||||
|
||||
cameraSwipeEnabled = cameraGesture
|
||||
|
||||
contactsSwipeEnabled = contactsGesture
|
||||
}
|
||||
|
||||
fun isJobActive(): Boolean {
|
||||
return if (job != null) {
|
||||
job!!.isActive
|
||||
|
|
|
|||
|
|
@ -122,5 +122,18 @@ class SettingsActivity : AppCompatActivity() {
|
|||
override fun onNothingSelected(parent: AdapterView<*>) {
|
||||
}
|
||||
}
|
||||
|
||||
binding.camera.isChecked = sharedPreferenceManager.getCameraEnabled(this@SettingsActivity)
|
||||
|
||||
binding.camera.setOnCheckedChangeListener { _, isChecked ->
|
||||
sharedPreferenceManager.setCameraEnabled(this@SettingsActivity, isChecked)
|
||||
}
|
||||
|
||||
binding.contacts.isChecked = sharedPreferenceManager.getContactsEnabled(this@SettingsActivity)
|
||||
|
||||
binding.contacts.setOnCheckedChangeListener { _, isChecked ->
|
||||
sharedPreferenceManager.setContactsEnabled(this@SettingsActivity, isChecked)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -189,4 +189,30 @@ class SharedPreferenceManager {
|
|||
val key = "search_size"
|
||||
return sharedPreferences.getInt(key, 2)
|
||||
}
|
||||
|
||||
fun setCameraEnabled(cont: Context, isEnabled: Boolean) {
|
||||
val editor = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE).edit()
|
||||
val key = "camera_enabled"
|
||||
editor.putBoolean(key, isEnabled)
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
fun getCameraEnabled(cont: Context) : Boolean {
|
||||
val sharedPreferences = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE)
|
||||
val key = "camera_enabled"
|
||||
return sharedPreferences.getBoolean(key, true)
|
||||
}
|
||||
|
||||
fun setContactsEnabled(cont: Context, isEnabled: Boolean) {
|
||||
val editor = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE).edit()
|
||||
val key = "contacts_enabled"
|
||||
editor.putBoolean(key, isEnabled)
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
fun getContactsEnabled(cont: Context) : Boolean {
|
||||
val sharedPreferences = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE)
|
||||
val key = "contacts_enabled"
|
||||
return sharedPreferences.getBoolean(key, true)
|
||||
}
|
||||
}
|
||||
|
|
@ -371,4 +371,82 @@
|
|||
app:layout_constraintTop_toBottomOf="@+id/search_size_label"
|
||||
tools:layout_editor_absoluteX="46dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/camera_label"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:gravity="start"
|
||||
android:paddingLeft="20dp"
|
||||
android:paddingTop="20dp"
|
||||
android:paddingRight="20dp"
|
||||
android:paddingBottom="20dp"
|
||||
android:text="Camera Swipe Left"
|
||||
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
|
||||
android:textColor="#F3F3F3"
|
||||
android:textSize="20sp"
|
||||
android:visibility="visible"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/search_size_label" />
|
||||
|
||||
<Switch
|
||||
android:id="@+id/camera"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/camera_label"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.08"
|
||||
app:layout_constraintStart_toEndOf="@+id/camera_label"
|
||||
app:layout_constraintTop_toBottomOf="@+id/search_size_label" />
|
||||
|
||||
<View
|
||||
android:id="@+id/divider10"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
app:layout_constraintTop_toBottomOf="@+id/camera_label"
|
||||
tools:layout_editor_absoluteX="0dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contacts_label"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:gravity="start"
|
||||
android:paddingLeft="20dp"
|
||||
android:paddingTop="20dp"
|
||||
android:paddingRight="20dp"
|
||||
android:paddingBottom="20dp"
|
||||
android:text="Phone Swipe Right"
|
||||
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
|
||||
android:textColor="#F3F3F3"
|
||||
android:textSize="20sp"
|
||||
android:visibility="visible"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/camera_label" />
|
||||
|
||||
<Switch
|
||||
android:id="@+id/contacts"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/contacts_label"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.08"
|
||||
app:layout_constraintStart_toEndOf="@+id/camera_label"
|
||||
app:layout_constraintTop_toBottomOf="@+id/camera_label" />
|
||||
|
||||
<View
|
||||
android:id="@+id/divider11"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
app:layout_constraintTop_toBottomOf="@+id/contacts_label"
|
||||
tools:layout_editor_absoluteX="0dp" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue