make a better attempt at making this a widget

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-07-05 18:04:13 -04:00
parent 4970df45e3
commit 74929d4fe1
17 changed files with 224 additions and 78 deletions

View File

@ -17,6 +17,7 @@
import groovy.xml.MarkupBuilder
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
def twaManifest = [
applicationId: 'website.christine.xesite',
@ -153,6 +154,9 @@ android {
lintOptions {
checkReleaseBuilds false
}
buildFeatures {
viewBinding true
}
}
task generateShorcutsFile {
@ -202,5 +206,6 @@ dependencies {
implementation 'com.google.androidbrowserhelper:locationdelegation:1.0.0'
implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "com.android.support:support-compat:28.0.0"
}

View File

@ -1,48 +1,33 @@
<!--
Copyright 2019 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The "package" attribute is rewritten by the Gradle build with the value of applicationId.
It is still required here, as it is used to derive paths, for instance when referring
to an Activity by ".MyActivity" instead of the full name. If more Activities are added to the
application, the package attribute will need to reflect the correct path in order to use
the abbreviated format. -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="website.christine.xesite">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="Application"
android:name=".Application"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/appName"
android:manageSpaceActivity="com.google.androidbrowserhelper.trusted.ManageDataLauncherActivity"
android:supportsRtl="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<receiver android:name=".NewPostWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/new_post_widget_info" />
</receiver>
<meta-data
android:name="asset_statements"
android:resource="@string/assetStatements" />
<meta-data
android:name="web_manifest_url"
android:value="@string/webManifestUrl" />
<meta-data
android:name="twa_generator"
android:value="@string/generatorApp" />
@ -52,69 +37,56 @@
android:name="android.support.customtabs.trusted.MANAGE_SPACE_URL"
android:value="@string/launchUrl" />
</activity>
<activity
android:name="LauncherActivity"
android:name=".LauncherActivity"
android:alwaysRetainTaskState="true"
android:label="@string/launcherName"
android:screenOrientation="unspecified">
<meta-data
android:name="android.support.customtabs.trusted.DEFAULT_URL"
android:value="@string/launchUrl" />
<meta-data
android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR"
android:resource="@color/colorPrimary" />
<meta-data
android:name="android.support.customtabs.trusted.NAVIGATION_BAR_COLOR"
android:resource="@color/navigationColor" />
<meta-data
android:name="android.support.customtabs.trusted.NAVIGATION_BAR_COLOR_DARK"
android:resource="@color/navigationColorDark" />
<meta-data
android:name="androix.browser.trusted.NAVIGATION_BAR_DIVIDER_COLOR"
android:resource="@color/navigationDividerColor" />
<meta-data
android:name="androix.browser.trusted.NAVIGATION_BAR_DIVIDER_COLOR_DARK"
android:resource="@color/navigationDividerColorDark" />
<meta-data
android:name="android.support.customtabs.trusted.SPLASH_IMAGE_DRAWABLE"
android:resource="@drawable/splash" />
<meta-data
android:name="android.support.customtabs.trusted.SPLASH_SCREEN_BACKGROUND_COLOR"
android:resource="@color/backgroundColor" />
<meta-data
android:name="android.support.customtabs.trusted.SPLASH_SCREEN_FADE_OUT_DURATION"
android:value="@integer/splashScreenFadeOutDuration" />
<meta-data
android:name="android.support.customtabs.trusted.FILE_PROVIDER_AUTHORITY"
android:value="@string/providerAuthority" />
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
<meta-data
android:name="android.support.customtabs.trusted.FALLBACK_STRATEGY"
android:value="@string/fallbackType" />
<meta-data
android:name="android.support.customtabs.trusted.SCREEN_ORIENTATION"
android:value="@string/orientation" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
@ -126,9 +98,7 @@
android:scheme="https" />
</intent-filter>
</activity>
<activity android:name="com.google.androidbrowserhelper.trusted.FocusActivity" />
<activity
android:name="com.google.androidbrowserhelper.trusted.WebViewFallbackActivity"
android:configChanges="orientation|screenSize" />
@ -147,14 +117,14 @@
android:name=".DelegationService"
android:enabled="@bool/enableNotification"
android:exported="@bool/enableNotification">
<intent-filter>
<action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
<activity android:name="com.google.androidbrowserhelper.locationdelegation.PermissionRequestActivity" />
</application>
</manifest>
</manifest>

View File

@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package website.christine.xesite;
package website.christine.xesite
import android.app.Application
public class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
class Application : Application() {
override fun onCreate() {
super.onCreate()
}
}
}

View File

@ -1,14 +0,0 @@
package website.christine.xesite;
import com.google.androidbrowserhelper.locationdelegation.LocationDelegationExtraCommandHandler;
public class DelegationService extends
com.google.androidbrowserhelper.trusted.DelegationService {
@Override
public void onCreate() {
super.onCreate();
registerExtraCommandHandler(new LocationDelegationExtraCommandHandler());
}
}

View File

@ -0,0 +1,11 @@
package website.christine.xesite
import com.google.androidbrowserhelper.locationdelegation.LocationDelegationExtraCommandHandler
import com.google.androidbrowserhelper.trusted.DelegationService
class DelegationService : DelegationService() {
override fun onCreate() {
super.onCreate()
registerExtraCommandHandler(LocationDelegationExtraCommandHandler())
}
}

View File

@ -13,18 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package website.christine.xesite;
package website.christine.xesite
import android.net.Uri;
import android.net.Uri
import com.google.androidbrowserhelper.trusted.LauncherActivity
public class LauncherActivity
extends com.google.androidbrowserhelper.trusted.LauncherActivity {
@Override
protected Uri getLaunchingUrl() {
class LauncherActivity : LauncherActivity() {
override fun getLaunchingUrl(): Uri {
// Get the original launch Url.
Uri uri = super.getLaunchingUrl();
return uri;
return super.getLaunchingUrl()
}
}
}

View File

@ -0,0 +1,46 @@
package website.christine.xesite
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
import android.widget.LinearLayout
import android.widget.RemoteViews
/**
* Implementation of App Widget functionality.
*/
class NewPostWidget : 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
val views = RemoteViews(context.packageName, R.layout.new_post_widget)
}
override fun onDisabled(context: Context) {
// Enter relevant functionality for when the last widget is disabled
}
}
internal fun updateAppWidget(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetId: Int
) {
// Construct the RemoteViews object
val views = RemoteViews(context.packageName, R.layout.new_post_widget)
views.setTextViewText(R.id.article_title, "My Thoughts About Using Android Again as an iPhone User")
views.setTextViewText(R.id.appwidget_text2, "I used to be a hardcore Android user. It was my second major kind of smartphone (the first was Windows Mobile 6.1 on a T-Mobile Dash) and it left me hooked to the concept of smartphones and connected tech in general.")
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views)
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -0,0 +1,76 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor"
android:focusable="auto"
android:padding="@dimen/widget_margin"
android:theme="@style/ThemeOverlay.Xesite_android.AppWidgetContainer">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="92dp"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="92dp"
android:layout_height="75dp"
android:src="@drawable/splash" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="67dp"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:id="@+id/parent_article"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="auto"
android:onClick="clickButton"
android:orientation="vertical">
<TextView
android:id="@+id/article_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="0dp"
android:layout_marginBottom="8dp"
android:background="@color/backgroundColor"
android:contentDescription="@string/appwidget_title"
android:text="@string/appwidget_title"
android:textColor="#3C3836"
android:textSize="24sp"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/appwidget_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="@color/backgroundColor"
android:contentDescription="@string/appwidget_body_preview"
android:text="@string/appwidget_body_preview"
android:textColor="#282828"
android:textSize="16sp"
android:textStyle="italic" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

View File

@ -0,0 +1,7 @@
<resources>
<style name="ThemeOverlay.Xesite_android.AppWidgetContainer" parent="">
<item name="appWidgetBackgroundColor">@color/light_blue_900</item>
<item name="appWidgetTextColor">@color/light_blue_200</item>
</style>
</resources>

View File

@ -0,0 +1,6 @@
<resources>
<declare-styleable name="AppWidgetAttrs">
<attr name="appWidgetBackgroundColor" format="color" />
<attr name="appWidgetTextColor" format="color" />
</declare-styleable>
</resources>

View File

@ -15,4 +15,8 @@
-->
<resources>
<color name="shortcut_background">#F5F5F5</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>

View File

@ -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>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="appwidget_title">EXAMPLE TITLE</string>
<string name="appwidget_body_preview">These are some words that let you see what an article preview would look like.</string>
<string name="add_widget">Add widget</string>
<string name="new_post_channel_name">New Posts</string>
<string name="new_post_channel_desc">Brand new posts on christine.website</string>
</resources>

View File

@ -0,0 +1,7 @@
<resources>
<style name="ThemeOverlay.Xesite_android.AppWidgetContainer" parent="">
<item name="appWidgetBackgroundColor">@color/light_blue_600</item>
<item name="appWidgetTextColor">@color/light_blue_50</item>
</style>
</resources>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialKeyguardLayout="@layout/new_post_widget"
android:initialLayout="@layout/new_post_widget"
android:minWidth="250dp"
android:minHeight="80dp"
android:previewImage="@drawable/example_appwidget_preview"
android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="1800000"
android:widgetCategory="home_screen"></appwidget-provider>

View File

@ -18,12 +18,16 @@
buildscript {
ext {
kotlin_version = '1.5.0'
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files