-
Notifications
You must be signed in to change notification settings - Fork 786
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 #197 from maotoumao/dev
publish v0.3.0
- Loading branch information
Showing
79 changed files
with
1,481 additions
and
508 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
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
173 changes: 173 additions & 0 deletions
173
android/app/src/main/java/fun/upup/musicfree/appIconUtil/AppIconUtilModule.java
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,173 @@ | ||
// 参考:https://blog.stackademic.com/change-the-app-icon-at-runtime-for-react-native-by-creating-a-nativemodule-5bfb285bd69b | ||
package fun.upup.musicfree.appIconUtil; | ||
|
||
import android.Manifest; | ||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.app.Activity; | ||
import android.app.Application; | ||
import android.content.ComponentName; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
|
||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
|
||
public class AppIconUtilModule extends ReactContextBaseJavaModule implements Application.ActivityLifecycleCallbacks { | ||
private static ReactApplicationContext reactContext; | ||
|
||
private final String packageName; | ||
|
||
public static final String MAIN_ACTVITY_BASE_NAME = ".MainActivity"; | ||
|
||
private String componentClass = ""; | ||
|
||
private final Set<String> classesToKill = new HashSet<>(); | ||
|
||
public AppIconUtilModule(ReactApplicationContext context, String packageName) { | ||
super(context); | ||
reactContext = context; | ||
this.packageName = packageName; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String getName() { | ||
return "AppIconUtil"; | ||
} | ||
|
||
@ReactMethod | ||
public void getIcon(Promise promise) { | ||
final Activity activity = getCurrentActivity(); | ||
if (activity == null) { | ||
promise.reject("ACTIVITY_NOT_FOUND", "Activity was not found"); | ||
return; | ||
} | ||
|
||
final String activityName = activity.getComponentName().getClassName(); | ||
|
||
if (activityName.endsWith(MAIN_ACTVITY_BASE_NAME)) { | ||
promise.resolve("Default"); | ||
return; | ||
} | ||
String[] activityNameSplit = activityName.split("MainActivity"); | ||
if (activityNameSplit.length != 2) { | ||
promise.reject("ANDROID:UNEXPECTED_COMPONENT_CLASS:", this.componentClass); | ||
return; | ||
} | ||
promise.resolve(activityNameSplit[1]); | ||
} | ||
|
||
@ReactMethod | ||
public void changeIcon(String iconName, Promise promise) { | ||
|
||
final Activity activity = getCurrentActivity(); | ||
|
||
if (activity == null) { | ||
promise.reject("ACTIVITY_NOT_FOUND", "The activity is null. Check if the app is running properly."); | ||
return; | ||
} | ||
if (iconName.isEmpty()) { | ||
promise.reject("EMPTY_ICON_STRING", "Icon name is missing i.e. changeIcon('YOUR_ICON_NAME_HERE')"); | ||
return; | ||
} | ||
if (this.componentClass.isEmpty()) { | ||
this.componentClass = activity.getComponentName().getClassName(); // i.e. MyActivity | ||
} | ||
|
||
final String activeClass = this.packageName + MAIN_ACTVITY_BASE_NAME + iconName; | ||
|
||
if (this.componentClass.equals(activeClass)) { | ||
promise.reject("ICON_ALREADY_USED", "This icons is the current active icon. " + this.componentClass); | ||
return; | ||
} | ||
|
||
try { | ||
activity.getPackageManager().setComponentEnabledSetting( | ||
new ComponentName(this.packageName, activeClass), | ||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, | ||
PackageManager.DONT_KILL_APP | ||
); | ||
promise.resolve(iconName); | ||
} catch (Exception e) { | ||
promise.reject("ICON_INVALID", e.getLocalizedMessage()); | ||
return; | ||
} | ||
|
||
this.classesToKill.add(this.componentClass); | ||
this.componentClass = activeClass; | ||
activity.getApplication().registerActivityLifecycleCallbacks(this); | ||
// The completeIconChange() is what makes the current active class disabled. | ||
// Move it to onActivityPaused or onActivityStopped etc to change the icon only when the app closes or goes to background | ||
completeIconChange(); | ||
} | ||
|
||
private void completeIconChange() { | ||
final Activity activity = getCurrentActivity(); | ||
if (activity == null) return; | ||
|
||
// Works for minSdkVersion = 23 | ||
for (String className : classesToKill) { | ||
activity.getPackageManager().setComponentEnabledSetting( | ||
new ComponentName(this.packageName, className), | ||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, | ||
PackageManager.DONT_KILL_APP | ||
); | ||
} | ||
/* | ||
// Works for minSdkVersion = 24 and above | ||
classesToKill.forEach((cls) -> activity.getPackageManager().setComponentEnabledSetting( | ||
new ComponentName(this.packageName, cls), | ||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, | ||
PackageManager.DONT_KILL_APP | ||
)); | ||
*/ | ||
classesToKill.clear(); | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityStarted(@NonNull Activity activity) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityResumed(@NonNull Activity activity) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityPaused(@NonNull Activity activity) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityStopped(@NonNull Activity activity) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityDestroyed(@NonNull Activity activity) { | ||
|
||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
android/app/src/main/java/fun/upup/musicfree/appIconUtil/AppIconUtilPackage.java
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,35 @@ | ||
package fun.upup.musicfree.appIconUtil; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class AppIconUtilPackage implements ReactPackage { | ||
|
||
private final String packageName; | ||
|
||
public AppIconUtilPackage(String packageName) { | ||
this.packageName = packageName; | ||
} | ||
|
||
@Override | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public List<NativeModule> createNativeModules( | ||
ReactApplicationContext reactContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
|
||
modules.add(new AppIconUtilModule(reactContext, this.packageName)); | ||
|
||
return modules; | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions
83
android/app/src/main/res/drawable-v24/musicfree_logo_1_foreground.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,83 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:width="108dp" | ||
android:height="108dp" | ||
android:viewportWidth="815.8" | ||
android:viewportHeight="692.07"> | ||
<group android:scaleX="0.53" | ||
android:scaleY="0.44961646" | ||
android:translateX="191.713" | ||
android:translateY="190.45197"> | ||
<path | ||
android:pathData="M397.87,346.03m-336.11,0a336.11,336.11 0,1 1,672.22 0a336.11,336.11 0,1 1,-672.22 0" | ||
android:strokeWidth="19.84" | ||
android:fillColor="#00000000"> | ||
<aapt:attr name="android:strokeColor"> | ||
<gradient | ||
android:startX="51.84" | ||
android:startY="346.03" | ||
android:endX="743.9" | ||
android:endY="346.03" | ||
android:type="linear"> | ||
<item android:offset="0.03" android:color="#FF00A5E7"/> | ||
<item android:offset="0.44" android:color="#FFFFFFFF"/> | ||
<item android:offset="0.46" android:color="#FFF6E3EE"/> | ||
<item android:offset="0.51" android:color="#FFE9BCD5"/> | ||
<item android:offset="0.55" android:color="#FFDE9AC1"/> | ||
<item android:offset="0.6" android:color="#FFD67FB0"/> | ||
<item android:offset="0.65" android:color="#FFCF6AA3"/> | ||
<item android:offset="0.71" android:color="#FFCA5B9A"/> | ||
<item android:offset="0.77" android:color="#FFC75294"/> | ||
<item android:offset="0.88" android:color="#FFC75093"/> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path | ||
android:pathData="M413.35,628.39c-19.26,0 -28.83,-34.2 -31.03,-110.9v-0.18s0,-0.18 0,-0.18c0.07,-1.56 6.04,-135.23 8.16,-180.05 -3.79,6.93 -8.99,19.36 -14.92,41.51 -9.49,35.49 -26.79,67.93 -50.01,93.81 -25.12,28 -79.22,45 -96.3,45 -0.6,0 -1.14,-0.02 -1.65,-0.06l-0.25,-9.87c0.15,-0.02 16.86,-2.32 36.48,-15.46 18.09,-12.12 42.48,-36.25 55.93,-82.4l1.13,-3.87c3.51,-12.07 7.15,-24.55 11.2,-36.73 9.24,-27.79 23.34,-68.03 38.03,-101.93 24.87,-57.38 37.58,-64.74 45.88,-64.74 2.32,0 5.76,0.72 8.97,4.14 7.74,8.25 17.09,33.67 9.02,158.52 -0.03,0.36 -2.35,33.74 -3.25,68.3 -1.26,48.38 1.09,65.75 2.79,71.93 5.48,-5.55 16.89,-21.55 27.66,-64.62 0.19,-0.75 4.73,-18.98 12.4,-37.53 11.11,-26.85 22.61,-39.9 35.16,-39.9 13.4,0 25.13,15.21 35.86,46.5l0.09,0.26 0.06,0.27c0.34,1.49 8.63,36.66 39.12,36.66 17.36,0 38.77,-11.06 63.64,-32.89l0.4,-0.35 0.47,-0.26c0.63,-0.35 15.66,-8.48 42.38,-8.48s68.95,8.22 122.05,47.4l-5.29,8.37c-0.53,-0.28 -53.64,-28.39 -106.74,-28.39 -25.76,0 -47.36,6.58 -64.21,19.57 -3.45,4.09 -27.82,31.43 -62.26,31.43 -23.41,0 -45.67,-12.58 -66.26,-37.43 -5.13,15.97 -16.7,50.86 -30.52,85.41 -34.84,87.06 -53.33,97.14 -64.21,97.14h0Z"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient | ||
android:startX="163.92" | ||
android:startY="415.36" | ||
android:endX="962.42" | ||
android:endY="415.36" | ||
android:type="linear"> | ||
<item android:offset="0" android:color="#FF3675BB"/> | ||
<item android:offset="0.03" android:color="#FF3368A4"/> | ||
<item android:offset="0.09" android:color="#FF2F527B"/> | ||
<item android:offset="0.16" android:color="#FF2B3F58"/> | ||
<item android:offset="0.22" android:color="#FF28303E"/> | ||
<item android:offset="0.29" android:color="#FF26262B"/> | ||
<item android:offset="0.35" android:color="#FF25201F"/> | ||
<item android:offset="0.42" android:color="#FF251E1C"/> | ||
<item android:offset="0.95" android:color="#FFC55194"/> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path | ||
android:pathData="M416.02,207.3c13.43,0 20.62,40.17 13.04,157.38 0,0 -9.91,141.41 3.08,147.84 0,0 17.81,-6.43 33.88,-70.71 0,0 18.21,-73.68 42.75,-73.68 9.65,0 20.28,11.39 31.17,43.15 0,0 9.01,40.55 43.97,40.55 16.18,0 37.93,-8.69 66.92,-34.12 0,0 14.23,-7.86 39.98,-7.86 27.59,0 68.4,9.03 119.11,46.43 0,0 -54.04,-28.97 -109.08,-28.98 -23.81,0 -47.79,5.42 -67.68,20.94 0,0 -24.31,30.06 -58.79,30.06 -20.18,0 -43.84,-10.29 -68.16,-42.92 0,0 -57.67,188.04 -92.84,188.04 -13.6,0 -23.84,-28.11 -26.08,-106.08 0,0 8.03,-179.98 8.84,-193.64 0,0 -0.01,0 -0.03,0 -0.67,0 -11.2,0.85 -25.3,53.59 -9.08,33.95 -25.44,65.62 -48.91,91.78 -24.34,27.12 -77.28,43.35 -92.6,43.35 -0.46,0 -0.89,-0.01 -1.28,-0.04 0,0 69.55,-8.73 96.56,-101.39 3.94,-13.52 7.82,-27.05 12.27,-40.42 17.64,-53.03 56.97,-163.27 79.21,-163.27m0,-9.92c-9.17,0 -17.7,6.99 -27.65,22.66 -6.78,10.68 -14.45,25.84 -22.78,45.07 -14.77,34.07 -28.92,74.46 -38.19,102.34 -4.08,12.27 -7.73,24.8 -11.25,36.92l-1.12,3.86c-10.4,35.67 -28.39,62.37 -53.48,79.36 -18.71,12.67 -34.68,14.95 -34.83,14.97l0.54,19.73c0.63,0.05 1.31,0.07 2.02,0.07 10.03,0 28.79,-4.92 46.68,-12.24 16.18,-6.62 38.56,-17.97 53.31,-34.4 23.74,-26.46 41.42,-59.61 51.11,-95.85 1.31,-4.88 2.57,-9.27 3.78,-13.21 -2.56,55.8 -6.55,145.02 -6.78,150.26l-0.02,0.36v0.36c1.11,38.31 4.09,65.98 9.13,84.59 2.57,9.48 5.66,16.54 9.46,21.57 5.96,7.9 12.76,9.56 17.42,9.56 12.29,0 23.98,-10.57 37.9,-34.28 9.41,-16.02 19.81,-38.22 30.92,-65.98 11.82,-29.53 21.99,-59.32 27.94,-77.42 19.97,21.61 41.52,32.55 64.24,32.55 35.5,0 60.81,-27.13 65.69,-32.77 15.91,-12.1 36.35,-18.23 60.78,-18.23 51.81,0 103.89,27.53 104.41,27.8l10.57,-16.73c-23.86,-17.61 -47.71,-30.6 -70.86,-38.63 -18.63,-6.46 -36.84,-9.74 -54.14,-9.74 -27.98,0 -44.11,8.73 -44.78,9.1l-0.94,0.52 -0.81,0.71c-23.61,20.71 -44.48,31.65 -60.37,31.65 -26.69,0 -34.21,-32.45 -34.28,-32.78l-0.12,-0.54 -0.18,-0.52c-7.34,-21.4 -19.52,-49.85 -40.55,-49.85 -14.78,0 -27.78,14.05 -39.75,42.97 -7.82,18.89 -12.45,37.47 -12.64,38.25 -7.09,28.36 -14.38,44.49 -19.8,53.47 -1.01,-10.43 -1.73,-29.02 -0.8,-62.01 0.94,-33.52 3.15,-65.21 3.17,-65.52v-0.03s0,-0.03 0,-0.03c8.11,-125.36 -1.27,-152.55 -10.35,-162.24 -4.42,-4.72 -9.28,-5.7 -12.59,-5.7h0Z" | ||
android:fillColor="#fff"/> | ||
<path | ||
android:pathData="M83.99,654.7c-51.3,0 -72.77,-41.38 -73.66,-43.14l-0.17,-0.33 -0.12,-0.35c-15.66,-47.61 5.3,-93.65 60.6,-133.14 35.14,-25.1 73.02,-39.85 84.21,-43.92l16.04,-346.29 7.59,48.46c1.12,7.15 10.82,20.46 50.64,43.2 28.19,16.1 62.62,31.88 87.76,43.4 11.05,5.06 20.59,9.43 27.28,12.76 9.17,4.56 13.9,7.17 12.85,12.01 -0.29,1.32 -1.51,4.41 -6.57,4.41 -7.27,0 -33.84,-6.31 -97.48,-23.33 1.51,1.15 2.81,2.28 3.85,3.4 37.84,40.45 41.22,92.38 41.35,94.57l2.35,41.17 -12.05,-39.43c-9.17,-30 -29.24,-54.24 -59.65,-72.03 -15.41,-9.01 -29.73,-14 -37.53,-16.32l4.37,197.81c5.71,53.2 -7.29,109.56 -19.22,147.5 -12.67,40.29 -48.58,68.24 -89.37,69.56 -1.03,0.03 -2.05,0.05 -3.06,0.05h0Z"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient | ||
android:startX="5" | ||
android:startY="371.11" | ||
android:endX="357.15" | ||
android:endY="371.11" | ||
android:type="linear"> | ||
<item android:offset="0" android:color="#FF00A5E7"/> | ||
<item android:offset="0.14" android:color="#FF409CE8"/> | ||
<item android:offset="0.29" android:color="#FF6391E5"/> | ||
<item android:offset="0.43" android:color="#FF8085DD"/> | ||
<item android:offset="0.57" android:color="#FF9979D0"/> | ||
<item android:offset="0.71" android:color="#FFAD6BBF"/> | ||
<item android:offset="0.86" android:color="#FFBD5DAB"/> | ||
<item android:offset="1" android:color="#FFC75093"/> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path | ||
android:pathData="M173.58,136.75c6.52,41.65 198.74,110.05 176.86,110.05 -8.14,0 -45.95,-9.49 -134.03,-33.35 -1.52,-0.41 -2.39,-0.6 -2.73,-0.6 -2.78,0 30.67,12.93 39.51,22.38 37.05,39.6 40.02,91.46 40.02,91.46 -23.09,-75.55 -107.03,-93.39 -107.03,-93.39l4.52,204.62c5.71,52.68 -7.38,108.74 -19,145.69 -11.8,37.53 -45.48,64.82 -84.8,66.09 -0.98,0.03 -1.95,0.05 -2.91,0.05 -48.84,0 -69.23,-40.42 -69.23,-40.42 -36.47,-110.89 144.9,-171.95 144.9,-171.95l13.92,-300.63m-5.37,-98.46l-4.54,98 -13.62,294.01c-14.22,5.37 -49.44,19.93 -82.29,43.39 -57.25,40.88 -78.83,88.86 -62.43,138.73l0.23,0.71 0.33,0.66c0.24,0.48 6.08,11.89 18.51,23.11 16.51,14.89 37.11,22.76 59.57,22.76 1.07,0 2.15,-0.02 3.23,-0.05 42.89,-1.39 80.65,-30.74 93.94,-73.03 12.05,-38.34 25.19,-95.31 19.44,-149.3l-4.21,-190.63c7.87,2.73 18.72,7.17 30.18,13.9 29.15,17.13 48.38,40.36 57.14,69.04l24.1,78.87 -4.7,-82.33c-0.12,-2.1 -3.13,-48.43 -34.75,-88.45 59.44,15.75 75.59,19.05 82.07,19.05 9.14,0 11.12,-6.92 11.42,-8.31 0.39,-1.77 0.82,-6.34 -3.54,-10.36 -0.9,-0.83 -1.99,-1.63 -3.43,-2.54 -1.97,-1.23 -4.67,-2.7 -8.51,-4.61 -6.76,-3.37 -16.34,-7.75 -27.42,-12.83 -25.05,-11.48 -59.36,-27.2 -87.36,-43.19 -42.79,-24.44 -47.71,-36.54 -48.2,-39.66l-15.17,-96.92h0Z" | ||
android:fillColor="#fff"/> | ||
</group> | ||
</vector> |
Oops, something went wrong.