Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ android {
namespace = "com.pranshulgg.weather_master_app"
compileSdk = flutter.compileSdkVersion
ndkVersion = "27.0.12077973"


compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
isCoreLibraryDesugaringEnabled = true

}

kotlinOptions {
Expand All @@ -37,7 +37,7 @@ android {
applicationId = "com.pranshulgg.weather_master_app"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = 23
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
Expand Down
84 changes: 58 additions & 26 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
Expand All @@ -31,12 +31,11 @@
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
Expand All @@ -47,17 +46,19 @@

<!-- WIDGETS -->

<receiver
android:name="dev.fluttercommunity.plus.homewidget.HomeWidgetBackgroundReceiver"
android:exported="true"
>
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
</receiver>
<receiver
android:name="dev.fluttercommunity.plus.homewidget.HomeWidgetBackgroundReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
</receiver>


<receiver android:name=".WeatherWidgetProvider" android:exported="true" android:label="Current horizontal pill">
<receiver
android:name=".WeatherWidgetProvider"
android:exported="true"
android:label="Current horizontal pill">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -67,7 +68,10 @@
android:resource="@xml/weather_widget_info" />
</receiver>

<receiver android:name=".WeatherWidgetCastProvider" android:exported="true" android:label="Current + hourly + daily">
<receiver
android:name=".WeatherWidgetCastProvider"
android:exported="true"
android:label="Current + hourly + daily">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -77,7 +81,10 @@
android:resource="@xml/weather_widget_info_cast" />
</receiver>

<receiver android:name=".PillWidgetProvider" android:exported="true" android:label="Current pill">
<receiver
android:name=".PillWidgetProvider"
android:exported="true"
android:label="Current pill">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -87,7 +94,10 @@
android:resource="@xml/pill_widget_info" />
</receiver>

<receiver android:name=".ClockHourlyWidgetProvider" android:exported="true" android:label="Clock + hourly + current">
<receiver
android:name=".ClockHourlyWidgetProvider"
android:exported="true"
android:label="Clock + hourly + current">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -97,7 +107,10 @@
android:resource="@xml/clock_hourly_info" />
</receiver>

<receiver android:name=".DateCurrentWidgetProvider" android:exported="true" android:label="Date + Current">
<receiver
android:name=".DateCurrentWidgetProvider"
android:exported="true"
android:label="Date + Current">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -107,11 +120,14 @@
android:resource="@xml/date_temp_widget_info" />
</receiver>

<activity android:name=".clockDateWidgetConfigActivity"
<activity
android:name=".clockDateWidgetConfigActivity"
android:theme="@style/Theme.widgetsThemeConfigs"
android:exported="true">
</activity>
<receiver android:name=".clockDateWidgetProvider" android:exported="true" android:label="Glance">
android:exported="true"></activity>
<receiver
android:name=".clockDateWidgetProvider"
android:exported="true"
android:label="Glance">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -130,8 +146,24 @@

<!-- WIDGETS END -->

<!-- SCREEN SAVERS -->
<service
android:name=".WeatherDreamService"
android:exported="true"
android:icon="@drawable/shape_set_2"
android:label="Weather"
android:permission="android.permission.BIND_DREAM_SERVICE">

<intent-filter>
<action android:name="android.service.dreams.DreamService" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<meta-data
android:name="android.service.dream"
android:resource="@xml/weather_dream" />
</service>
<!-- SCREEN SAVERS END -->
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
Expand All @@ -140,8 +172,8 @@
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
<action android:name="android.intent.action.PROCESS_TEXT" />
<data android:mimeType="text/plain" />
</intent>
</queries>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.pranshulgg.weather_master_app

import android.service.dreams.DreamService
import android.view.ViewGroup
import io.flutter.FlutterInjector
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterView
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.dart.DartExecutor.DartEntrypoint
import io.flutter.plugins.GeneratedPluginRegistrant


class WeatherDreamService : DreamService() {
private var flutterEngine: FlutterEngine? = null
private var flutterView: FlutterView? = null

override fun onAttachedToWindow() {
super.onAttachedToWindow()

// Allow click to propagate to the FlutterView
isInteractive = true

// Make the window fullscreen
isFullscreen = true

// TODO: figure out if this is required or not
isScreenBright = true

// It doesn't seem work with applicationContext, use this instead:
val engine = flutterEngine ?: FlutterEngine(this, null).also {
it.dartExecutor.executeDartEntrypoint(
DartEntrypoint(
dartEntrypointFunctionName = "onDreamServiceStarted"
)
)
flutterEngine = it
}


//setContentView(R.layout.flutter_view)
//flutterView = findViewById<FlutterView>(R.id.flutter_view).also {
// it.attachToFlutterEngine(engine)
//}

flutterView = FlutterView(this).also {
it.id = FlutterActivity.FLUTTER_VIEW_ID
it.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
it.isFocusable = true
it.isFocusableInTouchMode = true

setContentView(it)

it.attachToFlutterEngine(engine)
it.requestFocus()
}
}

override fun onDreamingStarted() {
super.onDreamingStarted()
flutterEngine?.lifecycleChannel?.appIsResumed()
}

override fun onDreamingStopped() {
super.onDreamingStopped()
flutterEngine?.lifecycleChannel?.appIsInactive()
flutterEngine?.lifecycleChannel?.appIsPaused()
}

override fun onDetachedFromWindow() {
flutterView?.let {
it.detachFromFlutterEngine()
flutterView = null
}
super.onDetachedFromWindow()
}
}

fun DartEntrypoint(
pathToBundle: String? = null,
dartEntrypointLibrary: String? = null,
dartEntrypointFunctionName: String = "main"
): DartEntrypoint {
val pathToBundle = pathToBundle ?: FlutterInjector.instance().flutterLoader().let {
if (!it.initialized()) {
throw AssertionError(
"DartEntrypoints can only be created once a FlutterEngine is created."
)
}
it.findAppBundlePath()
}
return dartEntrypointLibrary?.let {
DartEntrypoint(
pathToBundle,
it,
dartEntrypointFunctionName
)
} ?: DartEntrypoint(pathToBundle, dartEntrypointFunctionName)
}
6 changes: 6 additions & 0 deletions android/app/src/main/res/layout/flutter_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<io.flutter.embedding.android.FlutterView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/flutter_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
4 changes: 4 additions & 0 deletions android/app/src/main/res/xml/weather_dream.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<dream xmlns:android="http://schemas.android.com/apk/res/android"
android:previewImage="@mipmap/ic_launcher"
android:showClockAndComplications="false"
android:settingsActivity="com.pranshulgg.weather_master_app.MainActivity" />
32 changes: 32 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,38 @@ void main() async {
);
}

@pragma('vm:entry-point')
void onDreamServiceStarted() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MaterialApp(
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
home: Builder(builder: (context) {
return Scaffold(
body: Center(
child: FilledButton(
onPressed: () => showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text("Headline"),
content: Text("Supporting text"),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text("Cancel")),
TextButton(
onPressed: () => Navigator.pop(context),
child: Text("OK"))
],
),
),
child: Text("Hello world!")),
),
);
}),
));
}

class MyApp extends StatelessWidget {
final String? cacheKey;
final String? cityName;
Expand Down
Loading