Skip to content

Commit

Permalink
Implement the settings app
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimjio committed Aug 11, 2022
1 parent f343086 commit 24ea670
Show file tree
Hide file tree
Showing 61 changed files with 3,110 additions and 55 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.3.0

- Improved dict management
- Added uiLoadingShowOrientationGuide option
- Improved force landscape mode behavior
- Disable NativeBridge hooking in Riru module
- New: Add Settings App

## 2.2.0

- Add Force landscape mode
Expand Down
23 changes: 15 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ plugins {

android {
namespace 'com.kimjio.umamusumelocalify.settings'
compileSdk 32
compileSdk 33

defaultConfig {
applicationId "com.kimjio.umamusumelocalify.settings"
minSdk 23
targetSdk 32
targetSdk 33
versionCode 1
versionName "1.0"
versionName "1.0.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -22,16 +22,23 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
dataBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.0'
implementation 'androidx.appcompat:appcompat:1.6.0-beta01'
implementation 'com.google.android.material:material:1.7.0-alpha03'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.preference:preference:1.2.0'
implementation 'com.google.code.gson:gson:2.9.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
27 changes: 26 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission-sdk-23 android:maxSdkVersion="29" android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission-sdk-23 android:maxSdkVersion="29" android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission-sdk-23 android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

<queries>
<package android:name="jp.co.cygames.umamusume" />
<package android:name="com.kakaogames.umamusume" />
<!-- TODO Package by region -->
</queries>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.UmamusumeLocalifyAndroid" />
android:theme="@style/Theme.UmamusumeLocalifyAndroid">
<activity
android:name=".activity.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="@string/manage_translate"
android:name=".activity.ManageTranslateActivity"
android:exported="false" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.kimjio.umamusumelocalify.settings;

public final class ColorUtils {
public static int argb(float alpha, int red, int green, int blue) {
return ((int) (alpha * 255.0f + 0.5f) << 24) |
(red << 16) |
(green << 8) |
blue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.kimjio.umamusumelocalify.settings;

import java.util.List;

public final class Constants {
public static final String PREF_NAME = "pref_settings";

public static final List<String> targetPackageNames = List.of(
"jp.co.cygames.umamusume",
"com.kakaogames.umamusume"
// TODO Package by region
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.kimjio.umamusumelocalify.settings.activity;

import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.ColorInt;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.kimjio.umamusumelocalify.settings.ColorUtils;
import com.kimjio.umamusumelocalify.settings.R;

import java.lang.reflect.ParameterizedType;
import java.util.Objects;
import java.util.function.Consumer;


public abstract class BaseActivity<VB extends ViewDataBinding> extends AppCompatActivity {
protected VB binding;

@ColorInt
protected int backgroundColor;

private final Consumer<Boolean> crossWindowBlurEnabledListener = enabled -> {
getWindow().setBackgroundDrawable(
enabled ? new ColorDrawable(backgroundColor) : new ColorDrawable(backgroundColor & (0xFF << 24)));
};

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, getLayoutRes());
binding.setLifecycleOwner(this);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
getWindow().setDecorFitsSystemWindows(false);
} else {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}

Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER | WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

backgroundColor = ((ColorDrawable) getWindow().getDecorView().getBackground()).getColor();

if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
backgroundColor = ColorUtils.argb(0.5f, Color.red(backgroundColor), Color.green(backgroundColor), Color.blue(backgroundColor));
} else {
backgroundColor = ColorUtils.argb(0.7f, Color.red(backgroundColor), Color.green(backgroundColor), Color.blue(backgroundColor));
}

getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));

float density = getResources().getDisplayMetrics().density;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
window.getAttributes().setBlurBehindRadius((int) (density * 20.0f));
window.getDecorView().addOnAttachStateChangeListener(
new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
getWindowManager().addCrossWindowBlurEnabledListener(
crossWindowBlurEnabledListener);
}

@Override
public void onViewDetachedFromWindow(View v) {
getWindowManager().removeCrossWindowBlurEnabledListener(
crossWindowBlurEnabledListener);
}
});
}
}

@NonNull
public ActionBar requireSupportActionBar() {
ActionBar actionBar = getSupportActionBar();
if (actionBar == null)
throw new IllegalArgumentException("ActionBar does not set for this Activity");
return actionBar;
}

@LayoutRes
private int getLayoutRes() {
String[] split = ((Class<?>) ((ParameterizedType) Objects.requireNonNull(getClass().getGenericSuperclass())).getActualTypeArguments()[0])
.getSimpleName().replace("Binding", "").split("(?<=.)(?=\\p{Upper})");
StringBuilder name = new StringBuilder();

for (int i = 0; i < split.length; i++) {
name.append(split[i].toLowerCase());
if (i != split.length - 1)
name.append("_");
}

try {
return R.layout.class.getField(name.toString()).getInt(R.layout.class);
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}

return 0;
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
boolean result = false;
if (item.getItemId() == android.R.id.home) {
finish();
result = true;
}
return result || super.onOptionsItemSelected(item);
}
}
Loading

0 comments on commit 24ea670

Please sign in to comment.