-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First step towards support for #12 on Android
- Loading branch information
Showing
17 changed files
with
234 additions
and
19 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,26 +1,48 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="dev.jhale.binaryclock"> | ||
package="dev.jhale.binaryclock"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:name=".MainApplication" | ||
android:label="@string/app_name" | ||
android:icon="@mipmap/ic_launcher" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:allowBackup="false" | ||
android:theme="@style/BootTheme"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:name=".MainApplication" | ||
android:allowBackup="false" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" | ||
android:launchMode="singleTask" | ||
android:windowSoftInputMode="adjustResize" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:theme="@style/BootTheme"> | ||
<receiver | ||
android:name="com.binaryclock.BinaryClockWidget" | ||
android:exported="false"> | ||
<intent-filter> | ||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> | ||
</intent-filter> | ||
|
||
<meta-data | ||
android:name="android.appwidget.provider" | ||
android:resource="@xml/binary_clock_widget_info" /> | ||
</receiver> | ||
|
||
<activity | ||
android:name="com.binaryclock.BinaryClockWidgetConfigureActivity" | ||
android:exported="false"> | ||
<intent-filter> | ||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".MainActivity" | ||
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" | ||
android:exported="true" | ||
android:label="@string/app_name" | ||
android:launchMode="singleTask" | ||
android:windowSoftInputMode="adjustResize"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> | ||
|
||
</manifest> |
37 changes: 37 additions & 0 deletions
37
android/app/src/main/java/dev/jhale/binaryclock/BinaryClockWidget.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,37 @@ | ||
package com.binaryclock | ||
|
||
import android.appwidget.AppWidgetManager | ||
import android.appwidget.AppWidgetProvider | ||
import android.content.Context | ||
import android.widget.RemoteViews | ||
import dev.jhale.binaryclock.R | ||
|
||
/** | ||
* Implementation of App Widget functionality. | ||
*/ | ||
class BinaryClockWidget : AppWidgetProvider() { | ||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { | ||
// There may be multiple widgets active, so update all of them | ||
for (appWidgetId in appWidgetIds) { | ||
updateAppWidget(context, appWidgetManager, appWidgetId) | ||
} | ||
} | ||
|
||
override fun onEnabled(context: Context) { | ||
// Enter relevant functionality for when the first widget is created | ||
} | ||
|
||
override fun onDisabled(context: Context) { | ||
// Enter relevant functionality for when the last widget is disabled | ||
} | ||
} | ||
|
||
internal fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int) { | ||
val widgetText = context.getString(R.string.appwidget_text) | ||
// Construct the RemoteViews object | ||
val views = RemoteViews(context.packageName, R.layout.binary_clock_widget) | ||
views.setTextViewText(R.id.appwidget_text, widgetText) | ||
|
||
// Instruct the widget manager to update the widget | ||
appWidgetManager.updateAppWidget(appWidgetId, views) | ||
} |
Binary file added
BIN
+3.44 KB
android/app/src/main/res/drawable-nodpi/example_appwidget_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions
10
android/app/src/main/res/drawable-v21/app_widget_background.xml
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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- | ||
Background for widgets to make the rounded corners based on the | ||
appWidgetRadius attribute value | ||
--> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
|
||
<corners android:radius="?attr/appWidgetRadius" /> | ||
<solid android:color="?android:attr/colorBackground" /> | ||
</shape> |
10 changes: 10 additions & 0 deletions
10
android/app/src/main/res/drawable-v21/app_widget_inner_view_background.xml
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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- | ||
Background for views inside widgets to make the rounded corners based on the | ||
appWidgetInnerRadius attribute value | ||
--> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
|
||
<corners android:radius="?attr/appWidgetInnerRadius" /> | ||
<solid android:color="?android:attr/colorAccent" /> | ||
</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,19 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
style="@style/Widget.BinaryClock.AppWidget.Container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:theme="@style/BootTheme.AppWidgetContainer"> | ||
|
||
<TextView | ||
android:id="@+id/appwidget_text" | ||
style="@style/Widget.BinaryClock.AppWidget.InnerView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerHorizontal="true" | ||
android:layout_centerVertical="true" | ||
android:layout_margin="8dp" | ||
android:contentDescription="@string/appwidget_text" | ||
android:text="@string/appwidget_text" | ||
android:textSize="24sp" | ||
android:textStyle="bold|italic" /> | ||
</RelativeLayout> |
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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<!-- | ||
Having themes.xml for night-v31 because of the priority order of the resource qualifiers. | ||
--> | ||
<style name="BootTheme.AppWidgetContainerParent" parent="@android:style/Theme.DeviceDefault.DayNight"> | ||
<item name="appWidgetRadius">@android:dimen/system_app_widget_background_radius</item> | ||
<item name="appWidgetInnerRadius">@android:dimen/system_app_widget_inner_radius</item> | ||
</style> | ||
</resources> |
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,14 @@ | ||
<resources> | ||
|
||
<style name="Widget.BinaryClock.AppWidget.Container" parent="android:Widget"> | ||
<item name="android:id">@android:id/background</item> | ||
<item name="android:padding">?attr/appWidgetPadding</item> | ||
<item name="android:background">@drawable/app_widget_background</item> | ||
</style> | ||
|
||
<style name="Widget.BinaryClock.AppWidget.InnerView" parent="android:Widget"> | ||
<item name="android:padding">?attr/appWidgetPadding</item> | ||
<item name="android:background">@drawable/app_widget_inner_view_background</item> | ||
<item name="android:textColor">?android:attr/textColorPrimary</item> | ||
</style> | ||
</resources> |
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,16 @@ | ||
<resources> | ||
|
||
<style name="Widget.BinaryClock.AppWidget.Container" parent="android:Widget"> | ||
<item name="android:id">@android:id/background</item> | ||
<item name="android:padding">?attr/appWidgetPadding</item> | ||
<item name="android:background">@drawable/app_widget_background</item> | ||
<item name="android:clipToOutline">true</item> | ||
</style> | ||
|
||
<style name="Widget.BinaryClock.AppWidget.InnerView" parent="android:Widget"> | ||
<item name="android:padding">?attr/appWidgetPadding</item> | ||
<item name="android:background">@drawable/app_widget_inner_view_background</item> | ||
<item name="android:textColor">?android:attr/textColorPrimary</item> | ||
<item name="android:clipToOutline">true</item> | ||
</style> | ||
</resources> |
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<!-- | ||
Having themes.xml for v31 variant because @android:dimen/system_app_widget_background_radius | ||
and @android:dimen/system_app_widget_internal_padding requires API level 31 | ||
--> | ||
<style name="BootTheme.AppWidgetContainerParent" parent="@android:style/Theme.DeviceDefault.DayNight"> | ||
<item name="appWidgetRadius">@android:dimen/system_app_widget_background_radius</item> | ||
<item name="appWidgetInnerRadius">@android:dimen/system_app_widget_inner_radius</item> | ||
</style> | ||
</resources> |
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,7 @@ | ||
<resources> | ||
<declare-styleable name="AppWidgetAttrs"> | ||
<attr name="appWidgetPadding" format="dimension" /> | ||
<attr name="appWidgetInnerRadius" format="dimension" /> | ||
<attr name="appWidgetRadius" format="dimension" /> | ||
</declare-styleable> | ||
</resources> |
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,3 +1,7 @@ | ||
<resources> | ||
<color name="bootsplash_background">#000000</color> | ||
<color name="light_blue_50">#FFE1F5FE</color> | ||
<color name="light_blue_200">#FF81D4FA</color> | ||
<color name="light_blue_600">#FF039BE5</color> | ||
<color name="light_blue_900">#FF01579B</color> | ||
</resources> |
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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<!-- | ||
Refer to App Widget Documentation for margin information | ||
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout | ||
--> | ||
<dimen name="widget_margin">0dp</dimen> | ||
|
||
</resources> |
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,3 +1,7 @@ | ||
<resources> | ||
<string name="app_name">BinaryClock</string> | ||
<string name="appwidget_text">EXAMPLE</string> | ||
<string name="configure">Configure</string> | ||
<string name="add_widget">Add widget</string> | ||
<string name="app_widget_description">This is an app widget description</string> | ||
</resources> |
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
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 @@ | ||
<resources> | ||
|
||
<style name="BootTheme.AppWidgetContainerParent" parent="@android:style/Theme.DeviceDefault"> | ||
<!-- Radius of the outer bound of widgets to make the rounded corners --> | ||
<item name="appWidgetRadius">16dp</item> | ||
<!-- | ||
Radius of the inner view's bound of widgets to make the rounded corners. | ||
It needs to be 8dp or less than the value of appWidgetRadius | ||
--> | ||
<item name="appWidgetInnerRadius">8dp</item> | ||
</style> | ||
|
||
<style name="BootTheme.AppWidgetContainer" parent="BootTheme.AppWidgetContainerParent"> | ||
<!-- Apply padding to avoid the content of the widget colliding with the rounded corners --> | ||
<item name="appWidgetPadding">16dp</item> | ||
</style> | ||
</resources> |
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,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:description="@string/app_widget_description" | ||
android:initialKeyguardLayout="@layout/binary_clock_widget" | ||
android:initialLayout="@layout/binary_clock_widget" | ||
android:minWidth="40dp" | ||
android:minHeight="40dp" | ||
android:previewImage="@drawable/example_appwidget_preview" | ||
android:previewLayout="@layout/binary_clock_widget" | ||
android:resizeMode="horizontal|vertical" | ||
android:targetCellWidth="1" | ||
android:targetCellHeight="1" | ||
android:updatePeriodMillis="86400000" | ||
android:widgetCategory="home_screen|keyguard" /> |