update wallpaper ui, update color picker ui, update intents and add custom logger for the widget
This commit is contained in:
@ -6,10 +6,14 @@ import android.app.Activity
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Matrix
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.widget.RelativeLayout
|
||||
@ -267,7 +271,16 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||
|
||||
private fun subscribeUi(viewModel: MainViewModel) {
|
||||
viewModel.showWallpaper.observe(this, Observer {
|
||||
widget_bg.setImageDrawable(if (it) getCurrentWallpaper() else null)
|
||||
val wallpaper = getCurrentWallpaper()
|
||||
widget_bg.setImageDrawable(if (it) wallpaper else null)
|
||||
widget_bg.layoutParams = widget_bg.layoutParams.apply {
|
||||
|
||||
val metrics = DisplayMetrics()
|
||||
windowManager.defaultDisplay.getMetrics(metrics)
|
||||
|
||||
height = metrics.heightPixels
|
||||
width = (wallpaper?.intrinsicWidth ?: 1) * metrics.heightPixels / (wallpaper?.intrinsicWidth ?: 1)
|
||||
}
|
||||
})
|
||||
|
||||
logo.setOnClickListener {
|
||||
|
@ -106,9 +106,7 @@ class ClockSettingsFragment : Fragment() {
|
||||
})
|
||||
|
||||
viewModel.showNextAlarm.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
show_next_alarm_label?.text = if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
}
|
||||
updateNextAlarmWarningUi()
|
||||
})
|
||||
|
||||
viewModel.clockAppName.observe(viewLifecycleOwner, Observer {
|
||||
@ -168,17 +166,20 @@ class ClockSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun updateNextAlarmWarningUi() {
|
||||
show_next_alarm_warning.isVisible = AlarmHelper.isAlarmProbablyWrong(requireContext())
|
||||
with(requireContext().getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
|
||||
val alarm = nextAlarmClock
|
||||
if (alarm != null) {
|
||||
if (AlarmHelper.isAlarmProbablyWrong(requireContext()) && alarm != null && alarm.showIntent != null) {
|
||||
val pm = requireContext().packageManager as PackageManager
|
||||
val appNameOrPackage = try {
|
||||
pm.getApplicationLabel(pm.getApplicationInfo(nextAlarmClock.showIntent.creatorPackage ?: "", 0))
|
||||
pm.getApplicationLabel(pm.getApplicationInfo(alarm.showIntent?.creatorPackage ?: "", 0))
|
||||
} catch (e: Exception) {
|
||||
nextAlarmClock.showIntent.creatorPackage
|
||||
alarm.showIntent?.creatorPackage ?: ""
|
||||
}
|
||||
show_next_alarm_warning.text = getString(R.string.next_alarm_warning).format(appNameOrPackage)
|
||||
} else {
|
||||
maintainScrollPosition {
|
||||
show_next_alarm_label?.text = if (Preferences.showNextAlarm) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ class GeneralSettingsFragment : Fragment() {
|
||||
BottomSheetColorPicker(requireContext(),
|
||||
colors = colors,
|
||||
header = getString(R.string.settings_font_color_title),
|
||||
selected = ColorHelper.getFontColor(),
|
||||
getSelected = ColorHelper::getFontColorRgb,
|
||||
onColorSelected = { color: Int ->
|
||||
val colorString = Integer.toHexString(color)
|
||||
Preferences.textGlobalColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString
|
||||
@ -201,7 +201,7 @@ class GeneralSettingsFragment : Fragment() {
|
||||
BottomSheetColorPicker(requireContext(),
|
||||
colors = colors,
|
||||
header = getString(R.string.settings_background_color_title),
|
||||
selected = ColorHelper.getBackgroundColor(),
|
||||
getSelected = { ColorHelper.getBackgroundColorRgb() },
|
||||
onColorSelected = { color: Int ->
|
||||
val colorString = Integer.toHexString(color)
|
||||
Preferences.backgroundCardColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString
|
||||
|
@ -26,10 +26,7 @@ import com.tommasoberlose.anotherwidget.global.Actions
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.*
|
||||
import com.tommasoberlose.anotherwidget.receivers.NewCalendarEventReceiver
|
||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||
import com.tommasoberlose.anotherwidget.receivers.WeatherReceiver
|
||||
import com.tommasoberlose.anotherwidget.receivers.WidgetClickListenerReceiver
|
||||
import com.tommasoberlose.anotherwidget.receivers.*
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import com.tommasoberlose.anotherwidget.utils.getCapWordString
|
||||
import com.tommasoberlose.anotherwidget.utils.toPixel
|
||||
@ -95,26 +92,46 @@ class MainWidget : AppWidgetProvider() {
|
||||
private fun generateWidgetView(context: Context, appWidgetId: Int, appWidgetManager: AppWidgetManager, w: Int) {
|
||||
var views = RemoteViews(context.packageName, R.layout.the_widget_sans)
|
||||
|
||||
val generatedView = generateWidgetView(context)
|
||||
views.setImageViewBitmap(R.id.bitmap_container, BitmapHelper.getBitmapFromView(generatedView, width = w))
|
||||
|
||||
// Background
|
||||
views.setInt(R.id.widget_shape_background, "setColorFilter", ColorHelper.getBackgroundColorRgb())
|
||||
views.setInt(R.id.widget_shape_background, "setImageAlpha", ColorHelper.getBackgroundAlpha())
|
||||
val refreshIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
appWidgetId,
|
||||
IntentHelper.getWidgetUpdateIntent(context),
|
||||
0
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.widget_shape_background, refreshIntent)
|
||||
try {
|
||||
// Background
|
||||
views.setInt(
|
||||
R.id.widget_shape_background,
|
||||
"setColorFilter",
|
||||
ColorHelper.getBackgroundColorRgb()
|
||||
)
|
||||
views.setInt(
|
||||
R.id.widget_shape_background,
|
||||
"setImageAlpha",
|
||||
ColorHelper.getBackgroundAlpha()
|
||||
)
|
||||
val refreshIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
appWidgetId,
|
||||
IntentHelper.getWidgetUpdateIntent(context),
|
||||
0
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.widget_shape_background, refreshIntent)
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
}
|
||||
|
||||
// Clock
|
||||
views = updateClockView(context, views, appWidgetId)
|
||||
|
||||
// Setup listener
|
||||
views = updateCalendarView(context, generatedView, views, appWidgetId)
|
||||
views = updateWeatherView(context, generatedView, views, appWidgetId)
|
||||
try {
|
||||
val generatedView = generateWidgetView(context)
|
||||
views.setImageViewBitmap(
|
||||
R.id.bitmap_container,
|
||||
BitmapHelper.getBitmapFromView(generatedView, width = w)
|
||||
)
|
||||
views = updateCalendarView(context, generatedView, views, appWidgetId)
|
||||
views = updateWeatherView(context, generatedView, views, appWidgetId)
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
}
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
}
|
||||
@ -267,7 +284,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
FirebaseCrashlytics.getInstance().recordException(ex)
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
}
|
||||
|
||||
return views
|
||||
@ -301,7 +318,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
FirebaseCrashlytics.getInstance().recordException(ex)
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
}
|
||||
return views
|
||||
}
|
||||
@ -358,7 +375,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
FirebaseCrashlytics.getInstance().recordException(ex)
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
}
|
||||
|
||||
return views
|
||||
|
Reference in New Issue
Block a user