Update the bitmap factory and the location request. Fixed #53
This commit is contained in:
@ -10,15 +10,14 @@ object Preferences : KotprefModel() {
|
||||
var darkThemePreference by intPref(default = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) MODE_NIGHT_FOLLOW_SYSTEM else MODE_NIGHT_AUTO_BATTERY)
|
||||
|
||||
var showEvents by booleanPref(key = "PREF_SHOW_EVENTS", default = false)
|
||||
var showWeather by booleanPref(key = "PREF_SHOW_WEATHER")
|
||||
var weatherIcon by stringPref(key = "PREF_WEATHER_ICON")
|
||||
var weatherTemp by floatPref(key = "PREF_WEATHER_TEMP")
|
||||
var showWeather by booleanPref(key = "PREF_SHOW_WEATHER", default = false)
|
||||
var weatherIcon by stringPref(key = "PREF_WEATHER_ICON", default = "")
|
||||
var weatherTemp by floatPref(key = "PREF_WEATHER_TEMP", default = 0f)
|
||||
var weatherTempUnit by stringPref(key = "PREF_WEATHER_TEMP_UNIT", default = "F")
|
||||
var weatherRealTempUnit by stringPref(key = "PREF_WEATHER_REAL_TEMP_UNIT", default = "F")
|
||||
var calendarAllDay by booleanPref(key = "PREF_CALENDAR_ALL_DAY", default = false)
|
||||
var calendarAllDay by booleanPref(key = "PREF_CALENDAR_ALL_DAY", default = true)
|
||||
var calendarFilter by stringPref(key = "PREF_CALENDAR_FILTER", default = "")
|
||||
|
||||
var eventId by intPref(key = "PREF_EVENT_ID", default = -1)
|
||||
var nextEventId by longPref(key = "PREF_NEXT_EVENT_ID", default = -1)
|
||||
var nextEventName by stringPref(key = "PREF_NEXT_EVENT_NAME")
|
||||
var nextEventStartDate by longPref(key = "PREF_NEXT_EVENT_START_DATE")
|
||||
@ -29,7 +28,6 @@ object Preferences : KotprefModel() {
|
||||
var customLocationLat by stringPref(key = "PREF_CUSTOM_LOCATION_LAT", default = "")
|
||||
var customLocationLon by stringPref(key = "PREF_CUSTOM_LOCATION_LON", default = "")
|
||||
var customLocationAdd by stringPref(key = "PREF_CUSTOM_LOCATION_ADD", default = "")
|
||||
var hourFormat by stringPref(key = "PREF_HOUR_FORMAT", default = "12")
|
||||
var dateFormat by stringPref(default = "")
|
||||
var weatherRefreshPeriod by intPref(key = "PREF_WEATHER_REFRESH_PERIOD", default = 1)
|
||||
var showUntil by intPref(key = "PREF_SHOW_UNTIL", default = 1)
|
||||
@ -41,7 +39,6 @@ object Preferences : KotprefModel() {
|
||||
var eventAppName by stringPref(key = "PREF_EVENT_APP_NAME", default = "")
|
||||
var eventAppPackage by stringPref(key = "PREF_EVENT_APP_PACKAGE", default = "")
|
||||
var openEventDetails by booleanPref(default = true)
|
||||
var showEventLocation by stringPref(key = "PREF_SHOW_EVENT_LOCATION", default = "")
|
||||
var textGlobalColor by stringPref(key = "PREF_TEXT_COLOR", default = "#FFFFFF")
|
||||
var textMainSize by floatPref(key = "PREF_TEXT_MAIN_SIZE", default = 26f)
|
||||
var textSecondSize by floatPref(key = "PREF_TEXT_SECOND_SIZE", default = 18f)
|
||||
@ -52,18 +49,14 @@ object Preferences : KotprefModel() {
|
||||
var clockAppPackage by stringPref(key = "PREF_CLOCK_APP_PACKAGE", default = "")
|
||||
var showNextAlarm by booleanPref(default = false)
|
||||
var textShadow by intPref(key = "PREF_TEXT_SHADOW", default = 1)
|
||||
var showDiffTime by booleanPref(key = "PREF_SHOW_DIFF_TIME")
|
||||
var showDeclinedEvents by booleanPref(key = "PREF_SHOW_DECLINED_EVENTS", default = true)
|
||||
var openWeatherApiKey by stringPref(key = "PREF_OPEN_WEATHER_API_KEY", default = "")
|
||||
var darkSkyApiKey by stringPref(key = "PREF_DARK_SKY_API_KEY", default = "")
|
||||
var wuApiKey by stringPref(key = "PREF_WU_API_KEY", default = "")
|
||||
var secondRowInformation by intPref(key = "PREF_SECOND_ROW_INFORMATION", default = 1)
|
||||
var showDiffTime by booleanPref(key = "PREF_SHOW_DIFF_TIME", default = true)
|
||||
var showDeclinedEvents by booleanPref(key = "PREF_SHOW_DECLINED_EVENTS", default = false)
|
||||
var secondRowInformation by intPref(key = "PREF_SECOND_ROW_INFORMATION", default = 0)
|
||||
var customFont by intPref(key = "PREF_CUSTOM_FONT", default = Constants.CUSTOM_FONT_PRODUCT_SANS)
|
||||
var customFontFile by stringPref(key = "PREF_CUSTOM_FONT_FILE")
|
||||
var showNextEvent by booleanPref(key = "PREF_SHOW_NEXT_EVENT", default = true)
|
||||
var showGpsInformation by booleanPref(key = "PREF_SHOW_GPS_NOTIFICATION", default = true)
|
||||
|
||||
var showWallpaper by booleanPref(default = false)
|
||||
var showWallpaper by booleanPref(default = true)
|
||||
var showBigClockWarning by booleanPref(default = true)
|
||||
var showWeatherWarning by booleanPref(default = true)
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import android.util.Log
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import androidx.core.view.drawToBitmap
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import java.lang.Exception
|
||||
|
||||
@ -19,10 +20,11 @@ object BitmapHelper {
|
||||
view.measure(measuredWidth, measuredHeight)
|
||||
|
||||
return try {
|
||||
Log.d("ciao", "bitmap ${view.measuredWidth}, ${view.measuredHeight} - draw = ${draw}")
|
||||
val btm = Bitmap.createBitmap(
|
||||
view.measuredWidth,
|
||||
view.measuredHeight,
|
||||
Bitmap.Config.ARGB_8888
|
||||
if (draw) Bitmap.Config.ARGB_8888 else Bitmap.Config.ALPHA_8
|
||||
)
|
||||
if (draw) {
|
||||
//Bind a canvas to it
|
||||
@ -35,7 +37,7 @@ object BitmapHelper {
|
||||
btm
|
||||
} catch (ex: Exception) {
|
||||
FirebaseCrashlytics.getInstance().recordException(ex)
|
||||
Bitmap.createBitmap(5, 5, Bitmap.Config.ARGB_8888)
|
||||
Bitmap.createBitmap(5, 5, Bitmap.Config.ALPHA_8)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ object WeatherHelper {
|
||||
val networkApi = WeatherNetworkApi(context)
|
||||
if (Preferences.customLocationAdd != "") {
|
||||
networkApi.updateWeather()
|
||||
} else if (context.checkGrantedPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
} else if (context.checkGrantedPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)) {
|
||||
LocationServices.getFusedLocationProviderClient(context).lastLocation.addOnCompleteListener { task ->
|
||||
if (task.isSuccessful) {
|
||||
val location = task.result
|
||||
|
@ -12,7 +12,6 @@ class NewCalendarEventReceiver : BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
val eventRepository = EventRepository(context)
|
||||
Log.d("ciao", "nuovo evento")
|
||||
when (intent.action) {
|
||||
Intent.ACTION_PROVIDER_CHANGED,
|
||||
Intent.ACTION_TIME_CHANGED -> {
|
||||
|
@ -21,6 +21,9 @@ class UpdatesReceiver : BroadcastReceiver() {
|
||||
when (intent.action) {
|
||||
Intent.ACTION_BOOT_COMPLETED,
|
||||
Intent.ACTION_MY_PACKAGE_REPLACED,
|
||||
Intent.ACTION_TIME_CHANGED,
|
||||
Intent.ACTION_TIMEZONE_CHANGED,
|
||||
Intent.ACTION_LOCALE_CHANGED,
|
||||
Actions.ACTION_CALENDAR_UPDATE -> CalendarHelper.updateEventList(context)
|
||||
|
||||
"com.sec.android.widgetapp.APPWIDGET_RESIZE",
|
||||
|
@ -17,6 +17,8 @@ class WeatherReceiver : BroadcastReceiver() {
|
||||
when (intent.action) {
|
||||
Intent.ACTION_BOOT_COMPLETED,
|
||||
Intent.ACTION_MY_PACKAGE_REPLACED,
|
||||
Intent.ACTION_TIMEZONE_CHANGED,
|
||||
Intent.ACTION_LOCALE_CHANGED,
|
||||
Intent.ACTION_TIME_CHANGED -> setUpdates(context)
|
||||
|
||||
Actions.ACTION_WEATHER_UPDATE -> WeatherHelper.updateWeather(context)
|
||||
|
@ -125,7 +125,7 @@ class CustomLocationActivity : AppCompatActivity() {
|
||||
private fun requirePermission() {
|
||||
Dexter.withContext(this)
|
||||
.withPermissions(
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
Manifest.permission.ACCESS_BACKGROUND_LOCATION
|
||||
).withListener(object: MultiplePermissionsListener {
|
||||
override fun onPermissionsChecked(report: MultiplePermissionsReport?) {
|
||||
report?.let {
|
||||
|
@ -34,10 +34,7 @@ import com.tommasoberlose.anotherwidget.utils.getCurrentWallpaper
|
||||
import com.tommasoberlose.anotherwidget.utils.toPixel
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.the_widget_sans.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
@ -91,12 +88,13 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||
|
||||
private fun updateUI() {
|
||||
preview.setCardBackgroundColor(getColor(if (ColorHelper.getFontColor().isColorDark()) android.R.color.white else R.color.colorAccent))
|
||||
val generatedView = MainWidget.generateWidgetView(this@MainActivity)
|
||||
generatedView.measure(0, 0)
|
||||
preview.measure(0, 0)
|
||||
|
||||
uiJob?.cancel()
|
||||
uiJob = lifecycleScope.launch(Dispatchers.IO) {
|
||||
delay(200)
|
||||
val generatedView = MainWidget.generateWidgetView(this@MainActivity)
|
||||
generatedView.measure(0, 0)
|
||||
preview.measure(0, 0)
|
||||
val bitmap = BitmapHelper.getBitmapFromView(generatedView, if (preview.width > 0) preview.width else generatedView.measuredWidth, generatedView.measuredHeight)
|
||||
withContext(Dispatchers.Main) {
|
||||
// Clock
|
||||
|
@ -5,6 +5,7 @@ import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -70,6 +71,7 @@ class AdvancedSettingsFragment : Fragment() {
|
||||
setupListener()
|
||||
|
||||
app_version.text = "v%s".format(BuildConfig.VERSION_NAME)
|
||||
requirePermission()
|
||||
}
|
||||
|
||||
private fun subscribeUi(
|
||||
@ -117,7 +119,7 @@ class AdvancedSettingsFragment : Fragment() {
|
||||
action_show_wallpaper.setOnClickListener {
|
||||
maintainScrollPosition {
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_title_show_wallpaper))
|
||||
.setSelectedValue(Preferences.showWallpaper)
|
||||
.setSelectedValue(Preferences.showWallpaper && activity?.checkGrantedPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == true)
|
||||
.addItem(
|
||||
getString(R.string.settings_visible),
|
||||
true
|
||||
@ -174,6 +176,7 @@ class AdvancedSettingsFragment : Fragment() {
|
||||
).withListener(object: MultiplePermissionsListener {
|
||||
override fun onPermissionsChecked(report: MultiplePermissionsReport?) {
|
||||
report?.let {
|
||||
Preferences.showWallpaper = false
|
||||
Preferences.showWallpaper = report.areAllPermissionsGranted()
|
||||
}
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ class CalendarSettingsFragment : Fragment() {
|
||||
binding.isCalendarEnabled = it
|
||||
|
||||
if (it) {
|
||||
requirePermission()
|
||||
CalendarHelper.setEventUpdatesAndroidN(requireContext())
|
||||
} else {
|
||||
CalendarHelper.removeEventUpdatesAndroidN(requireContext())
|
||||
|
@ -115,6 +115,7 @@ class WeatherSettingsFragment : Fragment() {
|
||||
temp_unit.text =
|
||||
if (it == "F") getString(R.string.fahrenheit) else getString(R.string.celsius)
|
||||
}
|
||||
checkLocationPermission()
|
||||
})
|
||||
|
||||
viewModel.weatherRefreshPeriod.observe(viewLifecycleOwner, Observer {
|
||||
@ -133,7 +134,7 @@ class WeatherSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun checkLocationPermission() {
|
||||
if (activity?.checkGrantedPermission(Manifest.permission.ACCESS_FINE_LOCATION) == true) {
|
||||
if (activity?.checkGrantedPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION) == true) {
|
||||
location_permission_alert_icon.isVisible = false
|
||||
WeatherReceiver.setUpdates(requireContext())
|
||||
} else if (Preferences.showWeather && Preferences.customLocationAdd == "") {
|
||||
@ -231,7 +232,7 @@ class WeatherSettingsFragment : Fragment() {
|
||||
private fun requirePermission() {
|
||||
Dexter.withContext(requireContext())
|
||||
.withPermissions(
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
Manifest.permission.ACCESS_BACKGROUND_LOCATION
|
||||
).withListener(object: MultiplePermissionsListener {
|
||||
override fun onPermissionsChecked(report: MultiplePermissionsReport?) {
|
||||
report?.let {
|
||||
|
Reference in New Issue
Block a user