mirror of
https://github.com/hmalik144/Weather-apps.git
synced 2025-12-10 02:05:20 +00:00
- All committed to main
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:background="@android:color/black"
|
tools:background="@android:color/black"
|
||||||
tools:layout_height="160dp">
|
tools:layout_height="110dp">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -137,14 +137,14 @@
|
|||||||
|
|
||||||
<GridView
|
<GridView
|
||||||
android:id="@+id/widget_listview"
|
android:id="@+id/widget_listview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/central"
|
android:layout_below="@id/central"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
android:numColumns="5"
|
android:numColumns="5"
|
||||||
tools:listitem="@layout/widget_item">
|
tools:listitem="@layout/widget_item"/>
|
||||||
|
|
||||||
</GridView>
|
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
@@ -3,8 +3,9 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/widget_item_layout"
|
android:id="@+id/widget_item_layout"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="82dp"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
android:minHeight="55dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/widget_item_day"
|
android:id="@+id/widget_item_day"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
android:minResizeWidth="350.0dp"
|
android:minResizeWidth="350.0dp"
|
||||||
android:minResizeHeight="110.0dp"
|
android:minResizeHeight="110.0dp"
|
||||||
android:previewImage="@drawable/widget_screenshot"
|
android:previewImage="@drawable/widget_screenshot"
|
||||||
android:updatePeriodMillis="3600000"
|
android:updatePeriodMillis="1800000"
|
||||||
android:resizeMode="vertical"
|
android:resizeMode="vertical"
|
||||||
android:widgetCategory="home_screen">
|
android:widgetCategory="home_screen">
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.PowerManager
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import com.appttude.h_mal.atlas_weather.R
|
import com.appttude.h_mal.atlas_weather.R
|
||||||
@@ -30,13 +31,24 @@ import java.time.format.DateTimeFormatter
|
|||||||
class WidgetJobServiceIntent : BaseWidgetServiceIntentClass() {
|
class WidgetJobServiceIntent : BaseWidgetServiceIntentClass() {
|
||||||
|
|
||||||
override fun onHandleWork(intent: Intent) {
|
override fun onHandleWork(intent: Intent) {
|
||||||
setKodein(this)
|
|
||||||
// We have received work to do. The system or framework is already
|
// We have received work to do. The system or framework is already
|
||||||
// holding a wake lock for us at this point, so we can just go.
|
// holding a wake lock for us at this point, so we can just go.
|
||||||
|
|
||||||
|
val pm = getSystemService(POWER_SERVICE) as PowerManager
|
||||||
|
val isScreenOn = pm.isInteractive
|
||||||
|
|
||||||
|
// If screen is on then update widget or do nothing
|
||||||
|
if (isScreenOn) executeWidgetUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun executeWidgetUpdate(){
|
||||||
|
setKodein(this)
|
||||||
|
|
||||||
val appWidgetManager = AppWidgetManager.getInstance(this)
|
val appWidgetManager = AppWidgetManager.getInstance(this)
|
||||||
val thisAppWidget = ComponentName(packageName, NewAppWidget::class.java.name)
|
val thisAppWidget = ComponentName(packageName, NewAppWidget::class.java.name)
|
||||||
val appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget)
|
val appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget)
|
||||||
|
|
||||||
|
// Check if we have an active connection and permissions granted
|
||||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
|
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||||
!= PackageManager.PERMISSION_GRANTED || !isInternetAvailable(this.applicationContext)) {
|
!= PackageManager.PERMISSION_GRANTED || !isInternetAvailable(this.applicationContext)) {
|
||||||
for (appWidgetId in appWidgetIds) {
|
for (appWidgetId in appWidgetIds) {
|
||||||
|
|||||||
Reference in New Issue
Block a user