mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-02-11 08:50:43 +01:00
couple widget corrections
This commit is contained in:
parent
ff7d406c15
commit
7f6cbbb461
@ -2,7 +2,6 @@ package com.simplemobiletools.notes.activities
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.appwidget.AppWidgetManager
|
import android.appwidget.AppWidgetManager
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@ -10,12 +9,10 @@ import android.support.v7.app.AppCompatActivity
|
|||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
import com.simplemobiletools.notes.*
|
import com.simplemobiletools.notes.R
|
||||||
import com.simplemobiletools.notes.extensions.getTextSize
|
import com.simplemobiletools.notes.extensions.getTextSize
|
||||||
|
import com.simplemobiletools.notes.helpers.Config
|
||||||
import com.simplemobiletools.notes.helpers.MyWidgetProvider
|
import com.simplemobiletools.notes.helpers.MyWidgetProvider
|
||||||
import com.simplemobiletools.notes.helpers.PREFS_KEY
|
|
||||||
import com.simplemobiletools.notes.helpers.WIDGET_BG_COLOR
|
|
||||||
import com.simplemobiletools.notes.helpers.WIDGET_TEXT_COLOR
|
|
||||||
import kotlinx.android.synthetic.main.widget_config.*
|
import kotlinx.android.synthetic.main.widget_config.*
|
||||||
import yuku.ambilwarna.AmbilWarnaDialog
|
import yuku.ambilwarna.AmbilWarnaDialog
|
||||||
|
|
||||||
@ -50,8 +47,8 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initVariables() {
|
private fun initVariables() {
|
||||||
val prefs = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
val config = Config.newInstance(this)
|
||||||
mBgColor = prefs.getInt(WIDGET_BG_COLOR, 1)
|
mBgColor = config.widgetBgColor
|
||||||
if (mBgColor == 1) {
|
if (mBgColor == 1) {
|
||||||
mBgColor = Color.BLACK
|
mBgColor = Color.BLACK
|
||||||
mBgAlpha = .2f
|
mBgAlpha = .2f
|
||||||
@ -66,7 +63,7 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
updateBackgroundColor()
|
updateBackgroundColor()
|
||||||
|
|
||||||
mTextColor = prefs.getInt(WIDGET_TEXT_COLOR, resources.getColor(R.color.color_primary))
|
mTextColor = config.widgetTextColor
|
||||||
updateTextColor()
|
updateTextColor()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,8 +83,9 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun storeWidgetBackground() {
|
private fun storeWidgetBackground() {
|
||||||
getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE).apply {
|
Config.newInstance(this).apply {
|
||||||
edit().putInt(WIDGET_BG_COLOR, mBgColor).putInt(WIDGET_TEXT_COLOR, mTextColor).apply()
|
widgetBgColor = mBgColor
|
||||||
|
widgetTextColor = mTextColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +110,7 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun pickBackgroundColor() {
|
fun pickBackgroundColor() {
|
||||||
val dialog = AmbilWarnaDialog(this, mBgColorWithoutTransparency, object : AmbilWarnaDialog.OnAmbilWarnaListener {
|
AmbilWarnaDialog(this, mBgColorWithoutTransparency, object : AmbilWarnaDialog.OnAmbilWarnaListener {
|
||||||
override fun onCancel(dialog: AmbilWarnaDialog) {
|
override fun onCancel(dialog: AmbilWarnaDialog) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,13 +118,11 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||||||
mBgColorWithoutTransparency = color
|
mBgColorWithoutTransparency = color
|
||||||
updateBackgroundColor()
|
updateBackgroundColor()
|
||||||
}
|
}
|
||||||
})
|
}).show()
|
||||||
|
|
||||||
dialog.show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pickTextColor() {
|
fun pickTextColor() {
|
||||||
val dialog = AmbilWarnaDialog(this, mTextColor, object : AmbilWarnaDialog.OnAmbilWarnaListener {
|
AmbilWarnaDialog(this, mTextColor, object : AmbilWarnaDialog.OnAmbilWarnaListener {
|
||||||
override fun onCancel(dialog: AmbilWarnaDialog) {
|
override fun onCancel(dialog: AmbilWarnaDialog) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,9 +130,7 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||||||
mTextColor = color
|
mTextColor = color
|
||||||
updateTextColor()
|
updateTextColor()
|
||||||
}
|
}
|
||||||
})
|
}).show()
|
||||||
|
|
||||||
dialog.show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val bgSeekbarChangeListener = object : SeekBar.OnSeekBarChangeListener {
|
private val bgSeekbarChangeListener = object : SeekBar.OnSeekBarChangeListener {
|
||||||
|
@ -3,13 +3,10 @@ package com.simplemobiletools.notes.helpers
|
|||||||
val NOTE_ID = "note_id"
|
val NOTE_ID = "note_id"
|
||||||
|
|
||||||
// shared preferences
|
// shared preferences
|
||||||
val PREFS_KEY = "Notes"
|
|
||||||
val CURRENT_NOTE_ID = "current_note_id"
|
val CURRENT_NOTE_ID = "current_note_id"
|
||||||
val WIDGET_NOTE_ID = "widget_note_id"
|
val WIDGET_NOTE_ID = "widget_note_id"
|
||||||
val FONT_SIZE = "font_size"
|
val FONT_SIZE = "font_size"
|
||||||
val GRAVITY = "gravity"
|
val GRAVITY = "gravity"
|
||||||
val WIDGET_BG_COLOR = "widget_bg_color"
|
|
||||||
val WIDGET_TEXT_COLOR = "widget_text_color"
|
|
||||||
|
|
||||||
// gravity
|
// gravity
|
||||||
val GRAVITY_LEFT = 0
|
val GRAVITY_LEFT = 0
|
||||||
|
@ -5,14 +5,11 @@ import android.appwidget.AppWidgetManager
|
|||||||
import android.appwidget.AppWidgetProvider
|
import android.appwidget.AppWidgetProvider
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.graphics.Color
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import com.simplemobiletools.notes.R
|
import com.simplemobiletools.notes.R
|
||||||
import com.simplemobiletools.notes.R.layout.widget
|
import com.simplemobiletools.notes.R.layout.widget
|
||||||
import com.simplemobiletools.notes.activities.MainActivity
|
import com.simplemobiletools.notes.activities.MainActivity
|
||||||
import com.simplemobiletools.notes.helpers.DBHelper
|
|
||||||
import com.simplemobiletools.notes.extensions.getTextSize
|
import com.simplemobiletools.notes.extensions.getTextSize
|
||||||
|
|
||||||
class MyWidgetProvider : AppWidgetProvider() {
|
class MyWidgetProvider : AppWidgetProvider() {
|
||||||
@ -20,20 +17,19 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||||||
var textIds = arrayOf(R.id.notes_view_left, R.id.notes_view_center, R.id.notes_view_right)
|
var textIds = arrayOf(R.id.notes_view_left, R.id.notes_view_center, R.id.notes_view_right)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
lateinit var mPrefs: SharedPreferences
|
|
||||||
lateinit var mRemoteViews: RemoteViews
|
lateinit var mRemoteViews: RemoteViews
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||||
initVariables(context)
|
initVariables(context)
|
||||||
val defaultColor = Color.BLACK
|
val config = Config.newInstance(context)
|
||||||
val newBgColor = mPrefs.getInt(WIDGET_BG_COLOR, defaultColor)
|
val widgetBgColor = config.widgetBgColor
|
||||||
val newTextColor = mPrefs.getInt(WIDGET_TEXT_COLOR, Color.WHITE)
|
val widgetTextColor = config.widgetTextColor
|
||||||
|
|
||||||
for (id in textIds) {
|
for (id in textIds) {
|
||||||
mRemoteViews.apply {
|
mRemoteViews.apply {
|
||||||
setInt(id, "setBackgroundColor", newBgColor)
|
setInt(id, "setBackgroundColor", widgetBgColor)
|
||||||
setInt(id, "setTextColor", newTextColor)
|
setInt(id, "setTextColor", widgetTextColor)
|
||||||
setFloat(id, "setTextSize", context.getTextSize() / context.resources.displayMetrics.density)
|
setFloat(id, "setTextSize", context.getTextSize() / context.resources.displayMetrics.density)
|
||||||
setViewVisibility(id, View.GONE)
|
setViewVisibility(id, View.GONE)
|
||||||
}
|
}
|
||||||
@ -42,7 +38,7 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||||||
mRemoteViews.setViewVisibility(getProperTextView(context), View.VISIBLE)
|
mRemoteViews.setViewVisibility(getProperTextView(context), View.VISIBLE)
|
||||||
|
|
||||||
for (widgetId in appWidgetIds) {
|
for (widgetId in appWidgetIds) {
|
||||||
updateWidget(appWidgetManager, widgetId, mRemoteViews)
|
updateWidget(appWidgetManager, widgetId, mRemoteViews, context)
|
||||||
}
|
}
|
||||||
super.onUpdate(context, appWidgetManager, appWidgetIds)
|
super.onUpdate(context, appWidgetManager, appWidgetIds)
|
||||||
}
|
}
|
||||||
@ -56,7 +52,6 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initVariables(context: Context) {
|
private fun initVariables(context: Context) {
|
||||||
mPrefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
|
||||||
mDb = DBHelper.newInstance(context)
|
mDb = DBHelper.newInstance(context)
|
||||||
mRemoteViews = RemoteViews(context.packageName, widget)
|
mRemoteViews = RemoteViews(context.packageName, widget)
|
||||||
setupAppOpenIntent(R.id.notes_holder, context)
|
setupAppOpenIntent(R.id.notes_holder, context)
|
||||||
@ -68,9 +63,8 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||||||
mRemoteViews.setOnClickPendingIntent(id, pendingIntent)
|
mRemoteViews.setOnClickPendingIntent(id, pendingIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateWidget(widgetManager: AppWidgetManager, widgetId: Int, remoteViews: RemoteViews) {
|
private fun updateWidget(widgetManager: AppWidgetManager, widgetId: Int, remoteViews: RemoteViews, context: Context) {
|
||||||
val widgetNoteId = mPrefs.getInt(WIDGET_NOTE_ID, 1)
|
val note = mDb.getNote(Config.newInstance(context).widgetNoteId)
|
||||||
val note = mDb.getNote(widgetNoteId)
|
|
||||||
for (id in textIds)
|
for (id in textIds)
|
||||||
remoteViews.setTextViewText(id, note?.value ?: "")
|
remoteViews.setTextViewText(id, note?.value ?: "")
|
||||||
widgetManager.updateAppWidget(widgetId, remoteViews)
|
widgetManager.updateAppWidget(widgetId, remoteViews)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user