-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paintroid 434: Zoom window settings dialog
- Loading branch information
Showing
13 changed files
with
251 additions
and
82 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
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
82 changes: 82 additions & 0 deletions
82
Paintroid/src/main/java/org/catrobat/paintroid/dialog/ZoomWindowSettingsDialog.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,82 @@ | ||
package org.catrobat.paintroid.dialog | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.content.SharedPreferences | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.View | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.appcompat.widget.SwitchCompat | ||
import com.google.android.material.slider.Slider | ||
import org.catrobat.paintroid.R | ||
import org.catrobat.paintroid.UserPreferences | ||
import org.catrobat.paintroid.tools.helper.AdvancedSettingsAlgorithms | ||
import org.catrobat.paintroid.tools.implementation.DefaultToolPaint | ||
|
||
class ZoomWindowSettingsDialog( | ||
private val sharedPreferences: UserPreferences | ||
) : MainActivityDialogFragment() { | ||
|
||
private val initialEnabledValue = sharedPreferences.preferenceZoomWindowEnabled | ||
private val initialPercentageValue = sharedPreferences.preferenceZoomWindowZoomPercentage | ||
|
||
private var enabled = sharedPreferences.preferenceZoomWindowEnabled | ||
private var percentage = sharedPreferences.preferenceZoomWindowZoomPercentage | ||
|
||
@SuppressLint("SetTextI18n") | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
val enabledSwitch = view.findViewById<SwitchCompat>(R.id.pocketpaint_zoom_window_enabled) | ||
val slider = view.findViewById<Slider>(R.id.pocketpaint_zoom_window_slider) | ||
val sliderTextView = view.findViewById<TextView>(R.id.pocketpaint_zoom_window_slider_progress) | ||
|
||
enabledSwitch.isChecked = initialEnabledValue | ||
sliderTextView.text = "$initialPercentageValue%" | ||
slider.value = initialPercentageValue.toFloat() | ||
|
||
enabledSwitch.setOnCheckedChangeListener { _, isChecked -> | ||
enabled = isChecked | ||
} | ||
|
||
slider.addOnChangeListener { _, value, _ -> | ||
var percentageValue = value.toInt().toString() | ||
sliderTextView.text = "$percentageValue%" | ||
|
||
percentage = value.toInt() | ||
} | ||
|
||
slider.setLabelFormatter { value: Float -> | ||
value.toInt().toString() + '%' | ||
} | ||
} | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
val inflater = requireActivity().layoutInflater | ||
val layout = inflater.inflate(R.layout.dialog_pocketpaint_zoomwindow_settings, null) | ||
onViewCreated(layout, savedInstanceState) | ||
|
||
return AlertDialog.Builder(requireContext(), R.style.PocketPaintAlertDialog) | ||
.setTitle(R.string.menu_zoom_settings) | ||
.setView(layout) | ||
.setPositiveButton(R.string.pocketpaint_ok) { _, _ -> | ||
sharedPreferences.preferenceZoomWindowEnabled = enabled | ||
sharedPreferences.preferenceZoomWindowZoomPercentage = percentage | ||
dismiss() | ||
} | ||
.setNegativeButton(R.string.cancel_button_text) { _, _ -> | ||
sharedPreferences.preferenceZoomWindowEnabled = initialEnabledValue | ||
sharedPreferences.preferenceZoomWindowZoomPercentage = initialPercentageValue | ||
dismiss() | ||
} | ||
.create() | ||
} | ||
|
||
override fun onCancel(dialog: DialogInterface) { | ||
sharedPreferences.preferenceZoomWindowEnabled = initialEnabledValue | ||
sharedPreferences.preferenceZoomWindowZoomPercentage = initialPercentageValue | ||
super.onCancel(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
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
Oops, something went wrong.