Skip to content

Commit b0f0c34

Browse files
committed
Initial commit
0 parents  commit b0f0c34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1007
-0
lines changed

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/app/build/
13+
/app/release/
14+
/captures
15+
.externalNativeBuild
16+
.cxx
17+
local.properties
18+
*.keystore
19+
*.aab*
20+
*.apk*
21+
.project
22+
.settings

app/build.gradle

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/*
2+
* Copyright 2019 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import groovy.xml.MarkupBuilder
18+
19+
plugins {
20+
id 'com.android.application'
21+
22+
}
23+
24+
def twaManifest = [
25+
applicationId: 'com.bryankok.radically.twa',
26+
hostName: 'radically.bryankok.com', // The domain being opened in the TWA.
27+
launchUrl: '/search?utm_source=android_twa', // The start path for the TWA. Must be relative to the domain.
28+
name: 'Radically CJK Search Engine', // The application name.
29+
launcherName: 'Radically', // The name shown on the Android Launcher.
30+
themeColor: '#FFFFFF', // The color used for the status bar.
31+
navigationColor: '#000000', // The color used for the navigation bar.
32+
navigationColorDark: '#000000', // The color used for the dark navbar.
33+
navigationDividerColor: '#000000', // The navbar divider color.
34+
navigationDividerColorDark: '#000000', // The dark navbar divider color.
35+
backgroundColor: '#016154', // The color used for the splash screen background.
36+
enableNotifications: true, // Set to true to enable notification delegation.
37+
// Every shortcut must include the following fields:
38+
// - name: String that will show up in the shortcut.
39+
// - short_name: Shorter string used if |name| is too long.
40+
// - url: Absolute path of the URL to launch the app with (e.g '/create').
41+
// - icon: Name of the resource in the drawable folder to use as an icon.
42+
shortcuts: [],
43+
// The duration of fade out animation in milliseconds to be played when removing splash screen.
44+
splashScreenFadeOutDuration: 300,
45+
generatorApp: 'bubblewrap-cli', // Application that generated the Android Project
46+
// The fallback strategy for when Trusted Web Activity is not avilable. Possible values are
47+
// 'customtabs' and 'webview'.
48+
fallbackType: 'customtabs',
49+
enableSiteSettingsShortcut: 'true',
50+
orientation: 'default',
51+
]
52+
53+
android {
54+
compileSdkVersion 30
55+
defaultConfig {
56+
applicationId "com.bryankok.radically.twa"
57+
minSdkVersion 19
58+
targetSdkVersion 30
59+
versionCode 2
60+
versionName "2"
61+
62+
// The name for the application
63+
resValue "string", "appName", twaManifest.name
64+
65+
// The name for the application on the Android Launcher
66+
resValue "string", "launcherName", twaManifest.launcherName
67+
68+
// The URL that will be used when launching the TWA from the Android Launcher
69+
def launchUrl = "https://" + twaManifest.hostName + twaManifest.launchUrl
70+
resValue "string", "launchUrl", launchUrl
71+
72+
73+
// The URL the Web Manifest for the Progressive Web App that the TWA points to. This
74+
// is used by Chrome OS to open the Web version of the PWA instead of the TWA, as it
75+
// will probably give a better user experience for non-mobile devices.
76+
resValue "string", "webManifestUrl", 'https://radically.bryankok.com/manifest.json'
77+
78+
79+
80+
81+
// The hostname is used when building the intent-filter, so the TWA is able to
82+
// handle Intents to open https://svgomg.firebaseapp.com.
83+
resValue "string", "hostName", twaManifest.hostName
84+
85+
// This attribute sets the status bar color for the TWA. It can be either set here or in
86+
// `res/values/colors.xml`. Setting in both places is an error and the app will not
87+
// compile. If not set, the status bar color defaults to #FFFFFF - white.
88+
resValue "color", "colorPrimary", twaManifest.themeColor
89+
90+
// This attribute sets the navigation bar color for the TWA. It can be either set here or
91+
// in `res/values/colors.xml`. Setting in both places is an error and the app will not
92+
// compile. If not set, the navigation bar color defaults to #FFFFFF - white.
93+
resValue "color", "navigationColor", twaManifest.navigationColor
94+
95+
// This attribute sets the dark navigation bar color for the TWA. It can be either set here
96+
// or in `res/values/colors.xml`. Setting in both places is an error and the app will not
97+
// compile. If not set, the navigation bar color defaults to #000000 - black.
98+
resValue "color", "navigationColorDark", twaManifest.navigationColorDark
99+
100+
// This attribute sets the navbar divider color for the TWA. It can be either
101+
// set here or in `res/values/colors.xml`. Setting in both places is an error and the app
102+
// will not compile. If not set, the divider color defaults to #00000000 - transparent.
103+
resValue "color", "navigationDividerColor", twaManifest.navigationDividerColor
104+
105+
// This attribute sets the dark navbar divider color for the TWA. It can be either
106+
// set here or in `res/values/colors.xml`. Setting in both places is an error and the
107+
//app will not compile. If not set, the divider color defaults to #000000 - black.
108+
resValue "color", "navigationDividerColorDark", twaManifest.navigationDividerColorDark
109+
110+
// Sets the color for the background used for the splash screen when launching the
111+
// Trusted Web Activity.
112+
resValue "color", "backgroundColor", twaManifest.backgroundColor
113+
114+
// Defines a provider authority fot the Splash Screen
115+
resValue "string", "providerAuthority", twaManifest.applicationId + '.fileprovider'
116+
117+
// The enableNotification resource is used to enable or disable the
118+
// TrustedWebActivityService, by changing the android:enabled and android:exported
119+
// attributes
120+
resValue "bool", "enableNotification", twaManifest.enableNotifications.toString()
121+
122+
twaManifest.shortcuts.eachWithIndex { shortcut, index ->
123+
resValue "string", "shortcut_name_$index", "$shortcut.name"
124+
resValue "string", "shortcut_short_name_$index", "$shortcut.short_name"
125+
}
126+
127+
// The splashScreenFadeOutDuration resource is used to set the duration of fade out animation in milliseconds
128+
// to be played when removing splash screen. The default is 0 (no animation).
129+
resValue "integer", "splashScreenFadeOutDuration", twaManifest.splashScreenFadeOutDuration.toString()
130+
131+
resValue "string", "generatorApp", twaManifest.generatorApp
132+
133+
resValue "string", "fallbackType", twaManifest.fallbackType
134+
135+
resValue "bool", "enableSiteSettingsShortcut", twaManifest.enableSiteSettingsShortcut
136+
resValue "string", "orientation", twaManifest.orientation
137+
}
138+
buildTypes {
139+
release {
140+
minifyEnabled true
141+
}
142+
}
143+
compileOptions {
144+
sourceCompatibility JavaVersion.VERSION_1_8
145+
targetCompatibility JavaVersion.VERSION_1_8
146+
}
147+
lintOptions {
148+
checkReleaseBuilds false
149+
}
150+
}
151+
152+
153+
154+
task generateShorcutsFile {
155+
assert twaManifest.shortcuts.size() < 5, "You can have at most 4 shortcuts."
156+
twaManifest.shortcuts.eachWithIndex { s, i ->
157+
assert s.name != null, 'Missing `name` in shortcut #' + i
158+
assert s.short_name != null, 'Missing `short_name` in shortcut #' + i
159+
assert s.url != null, 'Missing `icon` in shortcut #' + i
160+
assert s.icon != null, 'Missing `url` in shortcut #' + i
161+
}
162+
163+
def shortcutsFile = new File("$projectDir/src/main/res/xml", "shortcuts.xml")
164+
165+
def xmlWriter = new StringWriter()
166+
def xmlMarkup = new MarkupBuilder(new IndentPrinter(xmlWriter, " ", true))
167+
168+
xmlMarkup
169+
.'shortcuts'('xmlns:android': 'http://schemas.android.com/apk/res/android') {
170+
twaManifest.shortcuts.eachWithIndex { s, i ->
171+
'shortcut'(
172+
'android:shortcutId': 'shortcut' + i,
173+
'android:enabled': 'true',
174+
'android:icon': '@drawable/' + s.icon,
175+
'android:shortcutShortLabel': '@string/shortcut_short_name_' + i,
176+
'android:shortcutLongLabel': '@string/shortcut_name_' + i) {
177+
'intent'(
178+
'android:action': 'android.intent.action.MAIN',
179+
'android:targetPackage': twaManifest.applicationId,
180+
'android:targetClass': twaManifest.applicationId + '.LauncherActivity',
181+
'android:data': s.url)
182+
'categories'('android:name': 'android.intent.category.LAUNCHER')
183+
}
184+
}
185+
}
186+
shortcutsFile.text = xmlWriter.toString() + '\n'
187+
}
188+
189+
preBuild.dependsOn(generateShorcutsFile)
190+
191+
repositories {
192+
193+
}
194+
195+
dependencies {
196+
implementation fileTree(include: ['*.jar'], dir: 'libs')
197+
198+
implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.2.1'
199+
200+
}

app/src/main/AndroidManifest.xml

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
<!--
2+
Copyright 2019 Google Inc. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<!-- The "package" attribute is rewritten by the Gradle build with the value of applicationId.
18+
It is still required here, as it is used to derive paths, for instance when referring
19+
to an Activity by ".MyActivity" instead of the full name. If more Activities are added to the
20+
application, the package attribute will need to reflect the correct path in order to use
21+
the abbreviated format. -->
22+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
23+
package="com.bryankok.radically.twa">
24+
25+
26+
27+
28+
29+
<application
30+
android:name="Application"
31+
android:allowBackup="true"
32+
android:icon="@mipmap/ic_launcher"
33+
android:label="@string/appName"
34+
35+
android:manageSpaceActivity="com.google.androidbrowserhelper.trusted.ManageDataLauncherActivity"
36+
37+
android:supportsRtl="true"
38+
android:theme="@android:style/Theme.Translucent.NoTitleBar">
39+
40+
<meta-data
41+
android:name="asset_statements"
42+
android:resource="@string/assetStatements" />
43+
44+
45+
<meta-data
46+
android:name="web_manifest_url"
47+
android:value="@string/webManifestUrl" />
48+
49+
50+
<meta-data
51+
android:name="twa_generator"
52+
android:value="@string/generatorApp" />
53+
54+
55+
<activity android:name="com.google.androidbrowserhelper.trusted.ManageDataLauncherActivity">
56+
<meta-data
57+
android:name="android.support.customtabs.trusted.MANAGE_SPACE_URL"
58+
android:value="@string/launchUrl" />
59+
</activity>
60+
61+
62+
<activity android:name="LauncherActivity"
63+
android:alwaysRetainTaskState="true"
64+
android:label="@string/launcherName">
65+
<meta-data android:name="android.support.customtabs.trusted.DEFAULT_URL"
66+
android:value="@string/launchUrl" />
67+
68+
<meta-data
69+
android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR"
70+
android:resource="@color/colorPrimary" />
71+
72+
<meta-data
73+
android:name="android.support.customtabs.trusted.NAVIGATION_BAR_COLOR"
74+
android:resource="@color/navigationColor" />
75+
76+
<meta-data
77+
android:name="android.support.customtabs.trusted.NAVIGATION_BAR_COLOR_DARK"
78+
android:resource="@color/navigationColorDark" />
79+
80+
<meta-data
81+
android:name="androix.browser.trusted.NAVIGATION_BAR_DIVIDER_COLOR"
82+
android:resource="@color/navigationDividerColor" />
83+
84+
<meta-data
85+
android:name="androix.browser.trusted.NAVIGATION_BAR_DIVIDER_COLOR_DARK"
86+
android:resource="@color/navigationDividerColorDark" />
87+
88+
<meta-data android:name="android.support.customtabs.trusted.SPLASH_IMAGE_DRAWABLE"
89+
android:resource="@drawable/splash"/>
90+
91+
<meta-data android:name="android.support.customtabs.trusted.SPLASH_SCREEN_BACKGROUND_COLOR"
92+
android:resource="@color/backgroundColor"/>
93+
94+
<meta-data android:name="android.support.customtabs.trusted.SPLASH_SCREEN_FADE_OUT_DURATION"
95+
android:value="@integer/splashScreenFadeOutDuration"/>
96+
97+
<meta-data android:name="android.support.customtabs.trusted.FILE_PROVIDER_AUTHORITY"
98+
android:value="@string/providerAuthority"/>
99+
100+
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
101+
102+
<meta-data android:name="android.support.customtabs.trusted.FALLBACK_STRATEGY"
103+
android:value="@string/fallbackType" />
104+
105+
106+
107+
108+
109+
<meta-data android:name="android.support.customtabs.trusted.SCREEN_ORIENTATION"
110+
android:value="@string/orientation"/>
111+
112+
113+
114+
115+
116+
<intent-filter>
117+
<action android:name="android.intent.action.MAIN" />
118+
<category android:name="android.intent.category.LAUNCHER" />
119+
</intent-filter>
120+
121+
<intent-filter android:autoVerify="true">
122+
<action android:name="android.intent.action.VIEW"/>
123+
<category android:name="android.intent.category.DEFAULT" />
124+
<category android:name="android.intent.category.BROWSABLE"/>
125+
<data android:scheme="https"
126+
android:host="@string/hostName"/>
127+
</intent-filter>
128+
129+
130+
</activity>
131+
132+
<activity android:name="com.google.androidbrowserhelper.trusted.FocusActivity" />
133+
134+
<activity android:name="com.google.androidbrowserhelper.trusted.WebViewFallbackActivity"
135+
android:configChanges="orientation|screenSize" />
136+
137+
<provider
138+
android:name="androidx.core.content.FileProvider"
139+
android:authorities="@string/providerAuthority"
140+
android:grantUriPermissions="true"
141+
android:exported="false">
142+
<meta-data
143+
android:name="android.support.FILE_PROVIDER_PATHS"
144+
android:resource="@xml/filepaths" />
145+
</provider>
146+
147+
<service
148+
android:name=".DelegationService"
149+
android:enabled="@bool/enableNotification"
150+
android:exported="@bool/enableNotification">
151+
152+
153+
<meta-data
154+
android:name="android.support.customtabs.trusted.SMALL_ICON"
155+
android:resource="@drawable/ic_notification_icon" />
156+
157+
158+
<intent-filter>
159+
<action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE"/>
160+
<category android:name="android.intent.category.DEFAULT"/>
161+
</intent-filter>
162+
</service>
163+
164+
165+
</application>
166+
</manifest>

0 commit comments

Comments
 (0)