Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

center: Add new methods for center update #4

Open
wants to merge 1 commit into
base: croquette-release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.content.res.Configuration;
import android.icu.text.DateFormat;
import android.os.IBinder;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -332,8 +333,16 @@ public void onMethodCall(@NonNull MethodCall methodCall, @NonNull MethodChannel.
result.success(null);
break;
}
case "getAccentColor": {
result.success(getAccentColor());
case "getLightAccentColor": {
result.success(getLightAccentColor());
break;
}
case "getDarkAccentColor": {
result.success(getDarkAccentColor());
break;
}
case "isCurrentThemeDark": {
result.success(isCurrentThemeDark());
break;
}
default:
Expand Down Expand Up @@ -595,7 +604,20 @@ private void setAutoDelete(boolean enable) {
preferences.edit().putBoolean(Constants.PREF_AUTO_DELETE_UPDATES, enable).apply();
}

private int getAccentColor() {
private Integer getLightAccentColor() {
String colResName = "accent_device_default_light";
Resources res = null;
try {
res = mActivity.getPackageManager().getResourcesForApplication("android");
int resId = res.getIdentifier("android:color/" + colResName, null, null);
return res.getColor(resId);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return 0;
}

private Integer getDarkAccentColor() {
String colResName = "accent_device_default_dark";
Resources res = null;
try {
Expand All @@ -607,4 +629,15 @@ private int getAccentColor() {
}
return 0;
}

private boolean isCurrentThemeDark() {
switch (mActivity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
case Configuration.UI_MODE_NIGHT_YES:
return true;
case Configuration.UI_MODE_NIGHT_NO:
return false;
default:
return false;
}
}
}
10 changes: 8 additions & 2 deletions lib/android_flutter_updater.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,14 @@ class AndroidFlutterUpdater {
static Future<void> startActivity({String pkg, String cls}) async =>
await _channel.invokeMethod('startActivity', {'pkg': pkg, 'cls': cls});

static Future<int> getAccentColor() async =>
await _channel.invokeMethod('getAccentColor');
static Future<int> getLightAccentColor() async =>
await _channel.invokeMethod('getLightAccentColor');

static Future<int> getDarkAccentColor() async =>
await _channel.invokeMethod('getDarkAccentColor');

static Future<bool> isCurrentThemeDark() async =>
await _channel.invokeMethod('isCurrentThemeDark');

static UpdateStatus _strToStatusEnum(String value) =>
UpdateStatus.values.firstWhere((e) =>
Expand Down