Skip to content

Commit 592bb51

Browse files
authored
Merge pull request #41 from capacitor-community/merge-android-support
Merge android support
2 parents 3c87bec + 79e416e commit 592bb51

File tree

112 files changed

+2929
-1589
lines changed

Some content is hidden

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

112 files changed

+2929
-1589
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
# - run: npm i
2525
# - run: npm run lint
2626
verify-android:
27-
if: github.ref == 'refs/heads/android-support'
2827
name: Verify Android
2928
runs-on: ubuntu-latest
3029
# needs: lint

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Change Log
22

3+
## [4.1.0](https://github.com/capacitor-community/app-icon/compare/v4.0.0...v4.1.0) (2023-05-28)
4+
5+
### Features
6+
7+
* **android:** Introducing Android support
8+
9+
## [3.1.0-beta.2](https://github.com/capacitor-community/app-icon/compare/v3.1.0-beta.1...v3.1.0-beta.2) (2023-04-10)
10+
11+
### Features
12+
13+
* **android:** add `isSupported` plugin method
14+
315
## [2.0.4](https://github.com/capacitor-community/app-icon/compare/v2.0.3...v2.0.4) (2021-08-31)
416

517
### Minor Changes

README.md

Lines changed: 118 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
## Before Starting
2626

27-
> This plugin only changes the main app icon on the device homescreen. The icon in springboard and in other areas of iOS will not change and continue to show the original.
27+
> This plugin only changes the main app icon on the device homescreen. The icon in springboard and in other areas will not change and continue to show the original. (iOS)
2828
29-
> Changing the app icon is only allowed when the app is in the foreground.
29+
> Changing the app icon is only allowed when the app is in the foreground (iOS).
3030
3131
> Android support is currently in beta. See the [android-support](https://github.com/capacitor-community/app-icon/tree/android-support) branch for more info.
3232
@@ -39,9 +39,57 @@ npx cap sync
3939

4040
## Configuration
4141

42+
The alternate icons need to be included within the app bundle and referenced in the project prior to using this plugin. It is not possible to switch to any icon on the fly without adding it to the project first. Below are the configurations steps for each platform.
43+
44+
## Android Configuration
45+
4246
### Add Alternate Icons
4347

44-
The alternate icons need to be included within the app bundle and referenced in the iOS project `Info.plist` prior to using this plugin. It is not possible to switch to any icon on the fly without adding it to the iOS project first.
48+
Add the alternate icons directly to your android project in `app/src/main/res`.
49+
50+
### Setup ApplicationManifest.xml
51+
52+
Each alternate icon is represented by an [`<activity-alias>`](https://developer.android.com/guide/topics/manifest/activity-alias-element). Add all the alternative icons to the `ApplicationManifest.xml` as child elements under `<application>`. The `name` attribute on `<activity-alias>` must be prefixed with dot `.` See [ApplicationManifest.xml](https://github.com/capacitor-community/app-icon/blob/android-support/example/android/app/src/main/AndroidManifest.xml) for full example.
53+
54+
```xml
55+
<application>
56+
<!-- ... -->
57+
<activity
58+
android:name=".MainActivity"
59+
android:exported="true"
60+
android:launchMode="singleTask"
61+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
62+
android:label="@string/title_activity_main"
63+
android:theme="@style/AppTheme.NoActionBarLaunch">
64+
65+
<intent-filter>
66+
<action android:name="android.intent.action.MAIN" />
67+
<!-- <category android:name="android.intent.category.LAUNCHER" /> -->
68+
</intent-filter>
69+
70+
</activity>
71+
<activity-alias
72+
android:label="Stencil"
73+
android:icon="@drawable/stencil"
74+
android:roundIcon="@drawable/stencil"
75+
android:name=".stencil"
76+
android:enabled="true"
77+
android:exported="true"
78+
android:targetActivity=".MainActivity">
79+
<intent-filter>
80+
<action android:name="android.intent.action.MAIN" />
81+
<category android:name="android.intent.category.LAUNCHER" />
82+
</intent-filter>
83+
</activity-alias>
84+
85+
<!-- additional <activity-alias> -->
86+
87+
<application>
88+
```
89+
90+
## iOS Configuration
91+
92+
### Add Alternate Icons
4593

4694
Add the alternate icons directly to your iOS project or in a subdirectory.
4795

@@ -94,79 +142,120 @@ For iPad specific version of an icon, there is an additional key to add in Info.
94142
```javascript
95143
import { AppIcon } from '@capacitor-community/app-icon';
96144

97-
const changeIcon = async iconName => {
98-
await AppIcon.change({ name: iconName, suppressNotification: true });
99-
};
145+
const changeIcon = async (iconName) => {
146+
await AppIcon.change({name: iconName, suppressNotification: true});
147+
}
148+
149+
const getName = async () => {
150+
const { value } = await AppIcon.getName();
151+
console.log(value);
152+
}
153+
154+
const resetIcon = async () => {
155+
const disable: string[] = ['stencil']; // all added aliaces names
156+
await AppIcon.reset({ suppressNotification: true, disable });
157+
}
100158
```
101159

102160
## API
103161

162+
<docgen-index>
163+
164+
* [`isSupported()`](#issupported)
165+
* [`getName()`](#getname)
166+
* [`change(...)`](#change)
167+
* [`reset(...)`](#reset)
168+
* [Interfaces](#interfaces)
169+
170+
</docgen-index>
171+
172+
<docgen-api>
173+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
174+
104175
### isSupported()
105176

106177
```typescript
107-
isSupported() => Promise<{value: boolean}>
178+
isSupported() => Promise<{ value: boolean; }>
108179
```
109180

110-
Checks to see if using alternate icons is supported on your device.
181+
Checks if changing the app icon is supported. (iOS only)
182+
183+
**Returns:** <code>Promise&lt;{ value: boolean; }&gt;</code>
184+
185+
**Since:** 1.0.0
186+
187+
--------------------
111188

112-
---
113189

114190
### getName()
115191

116192
```typescript
117-
getName(): Promise<{value: string | null}>;
193+
getName() => Promise<{ value: string | null; }>
118194
```
119195

120196
Gets the name of currently set alternate icon. If original icon is set, returns null.
121197

122-
---
198+
**Returns:** <code>Promise&lt;{ value: string | null; }&gt;</code>
199+
200+
**Since:** 1.0.0
201+
202+
--------------------
203+
123204

124205
### change(...)
125206

126207
```typescript
127-
change(options: IconOptions): Promise<void>;
208+
change(options: IconOptions) => Promise<void>
128209
```
129210

130211
Changes app icon to specified alternate.
131212

132213
| Param | Type |
133214
| ------------- | --------------------------------------------------- |
134-
| **`options`** | <code><a href="#IconOptions">IconOptions</a></code> |
215+
| **`options`** | <code><a href="#iconoptions">IconOptions</a></code> |
216+
217+
**Since:** 1.0.0
218+
219+
--------------------
135220

136-
---
137221

138222
### reset(...)
139223

140224
```typescript
141-
reset(options: ResetOptions): Promise<void>;
225+
reset(options: ResetOptions) => Promise<void>
142226
```
143227

144-
Changes app icon to specified alternate.
228+
Reverts app icon to original.
145229

146-
| Param | Type |
147-
| ------------- | ---------------------------------------------------- |
148-
| **`options`** | <code><a href="#IconOptions">ResetOptions</a></code> |
230+
| Param | Type |
231+
| ------------- | ----------------------------------------------------- |
232+
| **`options`** | <code><a href="#resetoptions">ResetOptions</a></code> |
233+
234+
**Since:** 1.0.0
235+
236+
--------------------
149237

150-
---
151238

152239
### Interfaces
153240

241+
154242
#### IconOptions
155243

156-
Represents the options passed to `change`.
244+
| Prop | Type | Description | Since |
245+
| -------------------------- | --------------------- | --------------------------------------------------------------------------------- | ----- |
246+
| **`name`** | <code>string</code> | Name of alternate icon to set | |
247+
| **`disable`** | <code>string[]</code> | Name of icons to disable. This is not used for iOS, but required for Android. | 3.1.0 |
248+
| **`suppressNotification`** | <code>boolean</code> | Flag controlling the in app notification which shows after icon is changed. (iOS) | |
157249

158-
| Prop | Type | Description | Since |
159-
| -------------------------- | -------------------- | --------------------------------------------------------------------------- | ----- |
160-
| **`name`** | <code>string</code> | Name of alternate icon to set. | 1.0.0 |
161-
| **`suppressNotification`** | <code>boolean</code> | Flag controlling the in app notification which shows after icon is changed. | 1.0.0 |
162250

163251
#### ResetOptions
164252

165-
Represents the options passed to `reset`.
253+
| Prop | Type | Description | Since |
254+
| -------------------------- | --------------------- | --------------------------------------------------------------------------------- | ----- |
255+
| **`suppressNotification`** | <code>boolean</code> | Flag controlling the in app notification which shows after icon is changed (iOS). | |
256+
| **`disable`** | <code>string[]</code> | Name of icons to disable. This is not used for iOS, but required for Android. | 3.1.1 |
166257

167-
| Prop | Type | Description | Since |
168-
| -------------------------- | -------------------- | --------------------------------------------------------------------------- | ----- |
169-
| **`suppressNotification`** | <code>boolean</code> | Flag controlling the in app notification which shows after icon is changed. | 1.0.0 |
258+
</docgen-api>
170259

171260
## Contributors ✨
172261

android/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

android/build.gradle

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
ext {
2+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
4+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
5+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
6+
}
7+
8+
buildscript {
9+
repositories {
10+
google()
11+
mavenCentral()
12+
}
13+
dependencies {
14+
classpath 'com.android.tools.build:gradle:8.0.0'
15+
}
16+
}
17+
18+
apply plugin: 'com.android.library'
19+
20+
android {
21+
namespace "com.mycompany.plugins.example"
22+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
23+
defaultConfig {
24+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
25+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
26+
versionCode 1
27+
versionName "1.0"
28+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29+
}
30+
buildTypes {
31+
release {
32+
minifyEnabled false
33+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34+
}
35+
}
36+
lintOptions {
37+
abortOnError false
38+
}
39+
compileOptions {
40+
sourceCompatibility JavaVersion.VERSION_17
41+
targetCompatibility JavaVersion.VERSION_17
42+
}
43+
}
44+
45+
repositories {
46+
google()
47+
mavenCentral()
48+
}
49+
50+
51+
dependencies {
52+
implementation fileTree(dir: 'libs', include: ['*.jar'])
53+
implementation project(':capacitor-android')
54+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55+
testImplementation "junit:junit:$junitVersion"
56+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58+
}

android/gradle.properties

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Project-wide Gradle settings.
2+
3+
# IDE (e.g. Android Studio) users:
4+
# Gradle settings configured through the IDE *will override*
5+
# any settings specified in this file.
6+
7+
# For more details on how to configure your build environment visit
8+
# http://www.gradle.org/docs/current/userguide/build_environment.html
9+
10+
# Specifies the JVM arguments used for the daemon process.
11+
# The setting is particularly useful for tweaking memory settings.
12+
org.gradle.jvmargs=-Xmx1536m
13+
14+
# When configured, Gradle will run in incubating parallel mode.
15+
# This option should only be used with decoupled projects. More details, visit
16+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17+
# org.gradle.parallel=true
18+
19+
# AndroidX package structure to make it clearer which packages are bundled with the
20+
# Android operating system, and which are packaged with your app's APK
21+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
22+
android.useAndroidX=true
23+
60.2 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip
4+
networkTimeout=10000
5+
zipStoreBase=GRADLE_USER_HOME
6+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)