-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from enpitut2021/funami/home_widget
Funami/home_widget: Androidでウィジェットを押すことでアプリが開く
- Loading branch information
Showing
12 changed files
with
499 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,65 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.chimimoryo_autumn"> | ||
<application | ||
android:label="chimimoryo_autumn" | ||
android:icon="@mipmap/ic_launcher"> | ||
package="com.example.chimimoryo_autumn"> | ||
<application | ||
android:label="chimimoryo_autumn" | ||
android:icon="@mipmap/ic_launcher"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:launchMode="singleTop" | ||
android:theme="@style/LaunchTheme" | ||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" | ||
android:hardwareAccelerated="true" | ||
android:windowSoftInputMode="adjustResize"> | ||
android:name=".MainActivity" | ||
android:launchMode="singleTop" | ||
android:theme="@style/LaunchTheme" | ||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" | ||
android:hardwareAccelerated="true" | ||
android:windowSoftInputMode="adjustResize"> | ||
<!-- Specifies an Android theme to apply to this Activity as soon as | ||
the Android process has started. This theme is visible to the user | ||
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" | ||
/> | ||
<!-- Displays an Android View that continues showing the launch screen | ||
Drawable until Flutter paints its first frame, then this splash | ||
screen fades out. A splash screen is useful to avoid any visual | ||
gap between the end of Android's launch screen and the painting of | ||
Flutter's first frame. --> | ||
<meta-data | ||
android:name="io.flutter.embedding.android.SplashScreenDrawable" | ||
android:resource="@drawable/launch_background" /> | ||
android:name="io.flutter.embedding.android.SplashScreenDrawable" | ||
android:resource="@drawable/launch_background"/> | ||
<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. | ||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> | ||
<meta-data | ||
android:name="flutterEmbedding" | ||
android:value="2" /> | ||
</application> | ||
|
||
<receiver android:name=".HomeWidgetExampleProvider"> | ||
<intent-filter> | ||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/> | ||
</intent-filter> | ||
<meta-data android:name="android.appwidget.provider" | ||
android:resource="@xml/home_widget"/> | ||
</receiver> | ||
|
||
<!-- Used for Background Work --> | ||
<receiver android:name="es.antonborri.home_widget.HomeWidgetBackgroundReceiver" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="es.antonborri.home_widget.action.BACKGROUND"/> | ||
</intent-filter> | ||
</receiver> | ||
<service android:name="es.antonborri.home_widget.HomeWidgetBackgroundService" | ||
android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true"/> | ||
|
||
<!-- Don't delete the meta-data below. | ||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> | ||
<meta-data | ||
android:name="flutterEmbedding" | ||
android:value="2"/> | ||
</application> | ||
<queries> | ||
<intent> | ||
<action android:name="android.intent.action.VIEW" /> | ||
<data android:scheme="https" /> | ||
<action android:name="android.intent.action.VIEW"/> | ||
<data android:scheme="https"/> | ||
</intent> | ||
</queries> | ||
</manifest> |
56 changes: 56 additions & 0 deletions
56
android/app/src/main/kotlin/com/example/chimimoryo_autumn/HomeWidgetExampleProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.example.chimimoryo_autumn | ||
|
||
import android.appwidget.AppWidgetManager | ||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import android.net.Uri | ||
import android.widget.RemoteViews | ||
import es.antonborri.home_widget.HomeWidgetBackgroundIntent | ||
import es.antonborri.home_widget.HomeWidgetLaunchIntent | ||
import es.antonborri.home_widget.HomeWidgetProvider | ||
import com.example.chimimoryo_autumn.* | ||
|
||
class HomeWidgetExampleProvider : HomeWidgetProvider() { | ||
|
||
override fun onUpdate( | ||
context: Context, | ||
appWidgetManager: AppWidgetManager, | ||
appWidgetIds: IntArray, | ||
widgetData: SharedPreferences | ||
) { | ||
appWidgetIds.forEach { widgetId -> | ||
val views = RemoteViews(context.packageName, R.layout.layout).apply { | ||
// Open App on Widget Click | ||
val pendingIntent = HomeWidgetLaunchIntent.getActivity(context, MainActivity::class.java) | ||
setOnClickPendingIntent(R.id.widget_container, pendingIntent) | ||
|
||
// Swap Title Text by calling Dart Code in the Background | ||
setTextViewText( | ||
R.id.widget_title, widgetData.getString("title", null) | ||
?: "魑魅魍魎👊" | ||
) | ||
val backgroundIntent = HomeWidgetBackgroundIntent.getBroadcast( | ||
context, | ||
Uri.parse("homeWidgetExample://titleClicked") | ||
) | ||
// Change widget title | ||
// setOnClickPendingIntent(R.id.widget_title, backgroundIntent) | ||
|
||
val message = widgetData.getString("message", null) | ||
setTextViewText( | ||
R.id.widget_message, message | ||
?: "No Message Set" | ||
) | ||
// Detect App opened via Click inside Flutter | ||
val pendingIntentWithData = HomeWidgetLaunchIntent.getActivity( | ||
context, | ||
MainActivity::class.java, | ||
Uri.parse("homeWidgetExample://message?message=$message") | ||
) | ||
setOnClickPendingIntent(R.id.widget_message, pendingIntentWithData) | ||
} | ||
|
||
appWidgetManager.updateAppWidget(widgetId, views) | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
android/app/src/main/kotlin/com/example/chimimoryo_autumn/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.example.chimimoryo_autumn | ||
|
||
import io.flutter.embedding.android.FlutterActivity | ||
import com.example.chimimoryo_autumn.* | ||
|
||
class MainActivity: FlutterActivity() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<solid android:color="#FFFFFF"/> | ||
<corners android:radius="16dp"/> | ||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_margin="8dp" | ||
android:orientation="vertical" | ||
android:background="@drawable/widget_background" | ||
android:padding="8dp" | ||
android:id="@+id/widget_container"> | ||
|
||
<TextView | ||
android:id="@+id/widget_title" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textSize="36sp" | ||
android:textStyle="bold" | ||
tools:text="Title" /> | ||
|
||
<TextView | ||
android:id="@+id/widget_message" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textSize="18sp" | ||
tools:text="Message" /> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:minWidth="40dp" | ||
android:minHeight="40dp" | ||
android:updatePeriodMillis="86400000" | ||
android:initialLayout="@layout/layout" | ||
android:resizeMode="horizontal|vertical" | ||
android:widgetCategory="home_screen"> | ||
</appwidget-provider> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
buildscript { | ||
ext.kotlin_version = '1.3.50' | ||
ext.kotlin_version = '1.4.0' | ||
repositories { | ||
google() | ||
mavenCentral() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# home_widget | ||
home widgetのための覚書。 | ||
|
||
## android | ||
|
||
- `home_widget_helloworld.dart`は、ホームウィジェットを動かすためのexample code | ||
- ベースとなっているコードは、公式の https://pub.dev/packages/home_widget のものです。 | ||
- ソースは https://github.com/ABausG/home_widget | ||
- 公式のexampleに対してこの`home_widget_helloworld.dart`は、 | ||
chimimoryo内で動くように次の点が異なります | ||
- 関連ファイルへのパス(ウィジェットの動きやスタイルを決めてるkotlinファイルなど) | ||
- nullに対応するための`?`オペレータ等の追加 | ||
- import文やpackage宣言の細かい変更 | ||
- など | ||
|
||
## iOS | ||
TBA |
Oops, something went wrong.