mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-05-24 19:04:15 +02:00
properly update the gravity of widgets too
This commit is contained in:
parent
576f3a0c91
commit
c575415c51
@ -7,6 +7,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.Color
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import com.simplemobiletools.notes.R.layout.widget
|
||||
import com.simplemobiletools.notes.activities.MainActivity
|
||||
@ -15,6 +16,7 @@ import com.simplemobiletools.notes.extensions.getTextSize
|
||||
|
||||
class MyWidgetProvider : AppWidgetProvider() {
|
||||
lateinit var mDb: DBHelper
|
||||
var textIds = arrayOf(R.id.notes_view_left, R.id.notes_view_center, R.id.notes_view_right)
|
||||
|
||||
companion object {
|
||||
lateinit var mPrefs: SharedPreferences
|
||||
@ -26,18 +28,32 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||
val defaultColor = context.resources.getColor(R.color.dark_grey)
|
||||
val newBgColor = mPrefs.getInt(WIDGET_BG_COLOR, defaultColor)
|
||||
val newTextColor = mPrefs.getInt(WIDGET_TEXT_COLOR, Color.WHITE)
|
||||
mRemoteViews.apply {
|
||||
setInt(R.id.notes_view, "setBackgroundColor", newBgColor)
|
||||
setInt(R.id.notes_view, "setTextColor", newTextColor)
|
||||
setFloat(R.id.notes_view, "setTextSize", context.getTextSize() / context.resources.displayMetrics.density)
|
||||
|
||||
for (id in textIds) {
|
||||
mRemoteViews.apply {
|
||||
setInt(id, "setBackgroundColor", newBgColor)
|
||||
setInt(id, "setTextColor", newTextColor)
|
||||
setFloat(id, "setTextSize", context.getTextSize() / context.resources.displayMetrics.density)
|
||||
setViewVisibility(id, View.GONE)
|
||||
}
|
||||
}
|
||||
|
||||
mRemoteViews.setViewVisibility(getProperTextView(context), View.VISIBLE)
|
||||
|
||||
for (widgetId in appWidgetIds) {
|
||||
updateWidget(appWidgetManager, widgetId, mRemoteViews)
|
||||
}
|
||||
super.onUpdate(context, appWidgetManager, appWidgetIds)
|
||||
}
|
||||
|
||||
private fun getProperTextView(context: Context): Int {
|
||||
return when (Config.newInstance(context).gravity) {
|
||||
GRAVITY_CENTER -> R.id.notes_view_center
|
||||
GRAVITY_RIGHT -> R.id.notes_view_right
|
||||
else -> R.id.notes_view_left
|
||||
}
|
||||
}
|
||||
|
||||
private fun initVariables(context: Context) {
|
||||
mPrefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||
mDb = DBHelper.newInstance(context)
|
||||
@ -54,7 +70,8 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||
private fun updateWidget(widgetManager: AppWidgetManager, widgetId: Int, remoteViews: RemoteViews) {
|
||||
val widgetNoteId = mPrefs.getInt(WIDGET_NOTE_ID, 1)
|
||||
val note = mDb.getNote(widgetNoteId)
|
||||
remoteViews.setTextViewText(R.id.notes_view, note?.value ?: "")
|
||||
for (id in textIds)
|
||||
remoteViews.setTextViewText(id, note?.value ?: "")
|
||||
widgetManager.updateAppWidget(widgetId, remoteViews)
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
settings_gravity.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
config.gravity = settings_gravity.selectedItemPosition
|
||||
updateWidget()
|
||||
}
|
||||
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
|
@ -6,11 +6,30 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notes_view"
|
||||
android:id="@+id/notes_view_left"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@null"
|
||||
android:gravity="start"
|
||||
android:padding="@dimen/activity_margin"/>
|
||||
android:gravity="left"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notes_view_center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@null"
|
||||
android:gravity="center_horizontal"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notes_view_right"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@null"
|
||||
android:gravity="right"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user