Splash Screen's Appearance Mode

This commit is contained in:
kongchanlina 2026-04-02 03:04:34 +07:00
parent 92c795c60f
commit e373dbdbaa
11 changed files with 179 additions and 53 deletions

View file

@ -17,21 +17,22 @@
https://support.google.com/googleplay/android-developer/answer/9214102#
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" /> -->
<application
android:name=".MyApp"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:theme="@style/AppTheme"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:resizeableActivity="false"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme"
android:supportsRtl="true">
android:supportsRtl="true"
>
<receiver android:name=".NetworkStateReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<!-- see the events from this app in sentry.keyman.com dashboard -->
<meta-data
android:name="io.sentry.dsn" android:value="https://2f067e5571a74974b9e210ca76ca9607@o1005580.ingest.sentry.io/5983520" />
@ -42,19 +43,19 @@
<meta-data
android:name="io.sentry.auto-init" android:value="false" />
<service
android:name="com.keyman.android.SystemKeyboard"
android:exported="true"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize"
android:permission="android.permission.BIND_INPUT_METHOD">
<intent-filter>
<action android:name="android.view.InputMethod" />
</intent-filter>
<!-- <service-->
<!-- android:name="com.keyman.android.SystemKeyboard"-->
<!-- android:exported="true"-->
<!-- android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize"-->
<!-- android:permission="android.permission.BIND_INPUT_METHOD">-->
<!-- <intent-filter>-->
<!-- <action android:name="android.view.InputMethod" />-->
<!-- </intent-filter>-->
<meta-data
android:name="android.view.im"
android:resource="@xml/method" />
</service>
<!-- <meta-data-->
<!-- android:name="android.view.im"-->
<!-- android:resource="@xml/method" />-->
<!-- </service>-->
<service
android:name="com.keyman.android.DownloadIntentService"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize"
@ -65,7 +66,14 @@
android:exported="true"
android:label="@string/app_name"
android:resizeableActivity="false"
android:theme="@style/AppTheme.BrandedLaunch">
android:theme="@style/Theme.App.Starting">
<!-- <activity-->
<!-- android:name=".SplashScreenActivity"-->
<!-- android:exported="true"-->
<!-- android:label="@string/app_name"-->
<!-- android:resizeableActivity="false"-->
<!-- android:theme="@style/AppTheme_BrandedLunch"-->
<!-- >-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View file

@ -66,6 +66,7 @@ import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.widget.SwitchCompat;
import androidx.appcompat.app.AlertDialog;
@ -88,6 +89,8 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.drawerlayout.widget.DrawerLayout;
@ -153,11 +156,19 @@ public class MainActivity extends BaseActivity implements OnKeyboardEventListene
DownloadResultReceiver resultReceiver;
private static ProgressDialog progressDialog;
private static final String PREFS_NAME = "settings";
private static final String KEY_THEME_MODE = "theme_mode";
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
// setTheme(R.style.AppTheme);
SharedPreferences theme_prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
int savedMode = theme_prefs.getInt(KEY_THEME_MODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
AppCompatDelegate.setDefaultNightMode(savedMode);
getDelegate().applyDayNight();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
checkSendCrashReport();
@ -245,6 +256,7 @@ public class MainActivity extends BaseActivity implements OnKeyboardEventListene
if (imManager != null) {
imManager.showInputMethodPicker();
}
} else if (id == R.id.nav_installed_languages) {
drawerLayout.closeDrawers();
Intent intent = new Intent(context, LanguagesSettingsActivity.class);
@ -268,6 +280,9 @@ public class MainActivity extends BaseActivity implements OnKeyboardEventListene
} else if (id == R.id.nav_about) {
drawerLayout.closeDrawers();
startActivity(new Intent(context, InfoActivity.class));
}else if (id == R.id.nav_palette){
drawerLayout.closeDrawers();
openThemeDialog();
}
return true;
}
@ -313,6 +328,40 @@ public class MainActivity extends BaseActivity implements OnKeyboardEventListene
checkGetStarted();
}
private void openThemeDialog() {
String[] options = {"Dark Mode", "Light Mode", "System Default"};
SharedPreferences themePrefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
int currentMode = themePrefs.getInt(KEY_THEME_MODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
int checkedItem;
if (currentMode == AppCompatDelegate.MODE_NIGHT_YES) checkedItem = 0;
else if (currentMode == AppCompatDelegate.MODE_NIGHT_NO) checkedItem = 1;
else checkedItem = 2;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose Theme");
builder.setSingleChoiceItems(options, checkedItem, (dialog, which) -> {
int modeToApply;
switch (which) {
case 0: modeToApply = AppCompatDelegate.MODE_NIGHT_YES; break;
case 1: modeToApply = AppCompatDelegate.MODE_NIGHT_NO; break;
default: modeToApply = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; break;
}
// Save the choice
themePrefs.edit().putInt(KEY_THEME_MODE, modeToApply).apply();
// Apply immediately
AppCompatDelegate.setDefaultNightMode(modeToApply);
getDelegate().applyDayNight(); // ensures current activity updates
dialog.dismiss();
});
builder.setNegativeButton("Cancel", (dialog, which) -> dialog.dismiss());
builder.show();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent returnIntent) {
@ -561,6 +610,7 @@ public class MainActivity extends BaseActivity implements OnKeyboardEventListene
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Android Gradle 8.0 no longer declares resources final, so can't use switch statement here

View file

@ -0,0 +1,15 @@
package com.tavultesoft.kmapro;
import android.app.Application;
import android.content.SharedPreferences;
import androidx.appcompat.app.AppCompatDelegate;
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
SharedPreferences prefs = getSharedPreferences("settings", MODE_PRIVATE);
int mode = prefs.getInt("theme_mode", AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
AppCompatDelegate.setDefaultNightMode(mode);
}
}

View file

@ -1,25 +1,37 @@
package com.tavultesoft.kmapro;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import com.keyman.engine.util.KMLog;
import java.util.Calendar;
public class SplashScreenActivity extends Activity {
public class SplashScreenActivity extends AppCompatActivity {
private final static String TAG = "Splash";
// For now, disable this Activity so app is not delayed showing version/copyright text
private static int SPLASH_TIME_OUT = 0; // msec
private static int SPLASH_TIME_OUT = 100; // msec
@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences prefs = getSharedPreferences("settings", MODE_PRIVATE);
int savedMode = prefs.getInt("theme_mode", AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
if (savedMode == AppCompatDelegate.MODE_NIGHT_YES) {
setTheme(R.style.AppTheme_BrandedLaunchDark);
} else {
setTheme(R.style.AppTheme_BrandedLaunchLight);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
@ -41,6 +53,8 @@ public class SplashScreenActivity extends Activity {
String date = String.format("%s%s", copyright.getText(), year);
//copyright.setText(date);
AppCompatDelegate.setDefaultNightMode(savedMode);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M480,880Q398,880 325,848.5Q252,817 197.5,762.5Q143,708 111.5,635Q80,562 80,480Q80,397 112.5,324Q145,251 200.5,197Q256,143 330,111.5Q404,80 488,80Q568,80 639,107.5Q710,135 763.5,183.5Q817,232 848.5,298.5Q880,365 880,442Q880,557 810,618.5Q740,680 640,680L566,680Q557,680 553.5,685Q550,690 550,696Q550,708 565,730.5Q580,753 580,782Q580,832 552.5,856Q525,880 480,880ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480ZM303,503Q320,486 320,460Q320,434 303,417Q286,400 260,400Q234,400 217,417Q200,434 200,460Q200,486 217,503Q234,520 260,520Q286,520 303,503ZM423,343Q440,326 440,300Q440,274 423,257Q406,240 380,240Q354,240 337,257Q320,274 320,300Q320,326 337,343Q354,360 380,360Q406,360 423,343ZM623,343Q640,326 640,300Q640,274 623,257Q606,240 580,240Q554,240 537,257Q520,274 520,300Q520,326 537,343Q554,360 580,360Q606,360 623,343ZM743,503Q760,486 760,460Q760,434 743,417Q726,400 700,400Q674,400 657,417Q640,434 640,460Q640,486 657,503Q674,520 700,520Q726,520 743,503ZM480,800Q489,800 494.5,795Q500,790 500,782Q500,768 485,749Q470,730 470,692Q470,650 499,625Q528,600 570,600L640,600Q706,600 753,561.5Q800,523 800,442Q800,321 707.5,240.5Q615,160 488,160Q352,160 256,253Q160,346 160,480Q160,613 253.5,706.5Q347,800 480,800Z"/>
</vector>

View file

@ -1,19 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:layout_marginBottom="@dimen/activity_splash_bottom"
android:gravity="bottom"
android:orientation="vertical">
<!-- Overlay text fields below logos -->
<TextView
android:id="@+id/splash_version"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/splash_blank"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/activity_splash_textsize" />
<TextView
@ -21,7 +20,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/splash_blank"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/activity_splash_textsize" />
</LinearLayout>
</LinearLayout>

View file

@ -12,7 +12,7 @@
<ImageView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:src="@drawable/keyman_logo"
android:src="@drawable/keyman_logo_mode"
/>
</LinearLayout>

View file

@ -38,7 +38,7 @@
<item android:id="@+id/action_share"
app:showAsAction="always"
android:title="@string/action_share"
android:icon="@drawable/ic_light_action_share" />
android:icon="@drawable/ic_action_share_mode" />
<item
android:id="@+id/action_text_size"

View file

@ -66,6 +66,10 @@
android:icon="@drawable/ic_info_outline"
android:title="Send Crash Report"
app:actionLayout="@layout/nav_switch_item" />
<item
android:id="@+id/nav_palette"
android:icon="@drawable/ic_palette"
android:title="Appearance Mode" />
<item
android:id="@+id/nav_settings"

View file

@ -10,16 +10,21 @@
<item name="colorPrimary">@android:color/black</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@android:color/black</item>
<item name="android:statusBarColor">@android:color/black</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
<!-- <item name="android:windowBackground">@color/toolbarColor</item>-->
<item name="android:windowBackground">#131313</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">@android:color/black</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="actionOverflowMenuStyle">@style/AppTheme.PopupMenu</item>
<!--
@ -29,9 +34,7 @@
-->
</style>
<style name="AppTheme.Dialog"
parent="Theme.AppCompat.DayNight.Dialog">
<style name="AppTheme.Dialog" parent="Theme.AppCompat.DayNight.Dialog">
<!-- Example overrides -->
<item name="colorPrimary">#424242</item>
<item name="colorPrimaryDark">#424242</item>
@ -40,17 +43,23 @@
<item name="android:windowBackground">#424242</item>
</style>
<style name="AppTheme.BrandedLaunch" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/branded_logo_dark_mode</item>
</style>
<!-- <style name="AppTheme.Toolbar" parent="Base.Widget.AppCompat.Toolbar">-->
<!-- <item name="android:colorPrimary">@android:color/white</item>-->
<!-- <item name="android:background">@android:color/white</item>-->
<!-- <item name="android:textColorPrimary">@android:color/black</item>-->
<!-- <item name="android:textColorSecondary">@android:color/black</item>-->
<!-- <style name="AppTheme.BrandedLaunch" parent="Theme.AppCompat.NoActionBar">-->
<!-- <item name="android:windowBackground">@drawable/branded_logo_dark_mode</item>-->
<!-- </style>-->
<!-- <style name="Theme.App.Starting" parent="Theme.SplashScreen">-->
<!-- <item name="windowSplashScreenBackground">@android:color/black</item>-->
<!-- <item name="windowSplashScreenAnimatedIcon">@drawable/branded_logo_dark_mode</item>-->
<!-- <item name="postSplashScreenTheme">@style/AppTheme</item>-->
<!-- </style>-->
<style name="AppTheme.Toolbar" parent="Base.Widget.AppCompat.Toolbar">
<item name="android:colorPrimary">@android:color/white</item>
<item name="android:background">@android:color/white</item>
<item name="android:textColorPrimary">@android:color/black</item>
<item name="android:textColorSecondary">@android:color/black</item>
</style>
<style name="AppTheme.ToolbarBackArrow" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlNormal">@color/iconColor</item>
</style>

View file

@ -12,8 +12,6 @@
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/complementary_5</item>
<item name="android:statusBarColor">@android:color/white</item>
<item name="android:textColor">@android:color/black</item>
<item name="android:textColorHint">@color/neutral_3</item>
<item name="android:textColorPrimary">@android:color/black</item>
@ -22,29 +20,48 @@
<item name="popupMenuStyle">@style/AppTheme.PopupMenu</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
<!-- <item name="android:windowBackground">@color/toolbarColor</item>-->
<item name="android:windowBackground">@android:color/white</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">@android:color/white</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<style name="AppTheme.Dialog" parent="AppTheme.Light.Dialog" />
<style name="AppTheme.BrandedLaunch" parent="Theme.AppCompat.NoActionBar">
<!-- <style name="AppTheme.BrandedLaunch" parent="Theme.AppCompat.NoActionBar">-->
<!-- <item name="android:windowBackground">@drawable/branded_logo</item>-->
<!-- </style>-->
<!-- <style name="AppTheme.BrandedLaunch" parent="Theme.SplashScreen">-->
<!-- <item name="android:windowBackground">@drawable/branded_logo</item>-->
<!-- </style>-->
<style name="Theme.App.Starting" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@android:color/white</item>
</style>
<style name="AppTheme.BrandedLaunchDark" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/branded_logo_dark_mode</item>
</style>
<style name="AppTheme.BrandedLaunchLight" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/branded_logo</item>
</style>
<!-- <style name="AppTheme.Toolbar" parent="Base.Widget.AppCompat.Toolbar">-->
<!-- <item name="android:colorPrimary">@android:color/white</item>-->
<!-- <item name="android:background">@android:color/white</item>-->
<!-- <item name="android:textColorPrimary">@android:color/black</item>-->
<!-- <item name="android:textColorSecondary">@android:color/black</item>-->
<!-- </style>-->
<style name="AppTheme.Toolbar" parent="Base.Widget.AppCompat.Toolbar">
<item name="android:colorPrimary">@android:color/white</item>
<item name="android:background">@android:color/white</item>
<item name="android:textColorPrimary">@android:color/black</item>
<item name="android:textColorSecondary">@android:color/black</item>
</style>
<style name="AppTheme.PopupMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<item name="android:popupBackground">@color/menuBgColor</item>