WIP: Android 12 Splashscreen #7651
7 changed files with 71 additions and 20 deletions
|
@ -396,6 +396,7 @@ dependencies {
|
|||
// We don't use Kotlin, but some dependencies are actively using it.
|
||||
// See https://stackoverflow.com/a/75719642
|
||||
implementation 'androidx.core:core:1.15.0'
|
||||
implementation 'androidx.core:core-splashscreen:1.0.1'
|
||||
implementation(platform('org.jetbrains.kotlin:kotlin-bom:2.1.10'))
|
||||
implementation 'androidx.annotation:annotation:1.9.1'
|
||||
implementation 'androidx.appcompat:appcompat:1.7.0'
|
||||
|
|
|
@ -7,6 +7,7 @@ import static app.organicmaps.api.Const.EXTRA_PICK_POINT;
|
|||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
|
@ -17,6 +18,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.splashscreen.SplashScreen;
|
||||
|
||||
import app.organicmaps.display.DisplayManager;
|
||||
import app.organicmaps.downloader.DownloaderActivity;
|
||||
|
@ -57,19 +59,27 @@ public class SplashActivity extends AppCompatActivity
|
|||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final Context context = getApplicationContext();
|
||||
final String theme = Config.getCurrentUiTheme(context);
|
||||
if (ThemeUtils.isDefaultTheme(context, theme))
|
||||
setTheme(R.style.MwmTheme_Splash);
|
||||
else if (ThemeUtils.isNightTheme(context, theme))
|
||||
setTheme(R.style.MwmTheme_Night_Splash);
|
||||
|
||||
final int theme = getSplashTheme(context);
|
||||
// use new splashscreen api for >= 31
|
||||
// maybe doesn't work for android auto?
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
getSplashScreen().setSplashScreenTheme(theme);
|
||||
//always keep splash while in SplashActivity
|
||||
splashScreen.setKeepOnScreenCondition(() -> true );
|
||||
}
|
||||
// use old splashscreen method for below 31
|
||||
else
|
||||
throw new IllegalArgumentException("Attempt to apply unsupported theme: " + theme);
|
||||
{
|
||||
setTheme(theme);
|
||||
setContentView(R.layout.activity_splash);
|
||||
}
|
||||
|
||||
UiThread.cancelDelayedTasks(mInitCoreDelayedTask);
|
||||
setContentView(R.layout.activity_splash);
|
||||
|
||||
mPermissionRequest = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(),
|
||||
result -> Config.setLocationRequested());
|
||||
mApiRequest = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
||||
|
@ -214,4 +224,15 @@ public class SplashActivity extends AppCompatActivity
|
|||
|
||||
return manageSpaceActivityName.equals(component.getClassName());
|
||||
}
|
||||
|
||||
private int getSplashTheme(Context context)
|
||||
{
|
||||
final String theme = Config.getCurrentUiTheme(context);
|
||||
if (ThemeUtils.isDefaultTheme(context, theme))
|
||||
return R.style.MwmTheme_Splash;
|
||||
else if (ThemeUtils.isNightTheme(context, theme))
|
||||
return R.style.MwmTheme_Night_Splash;
|
||||
else
|
||||
throw new IllegalArgumentException("Attempt to apply unsupported theme: " + theme);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
<vector android:height="256dp" android:viewportHeight="135.46667"
|
||||
android:viewportWidth="135.46666" android:width="256dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#ffffff"
|
||||
android:pathData="M128.274,22.419C131.432,31.024 114.539,51.944 98.437,57.312 69.309,46.971 68.362,64.338 44.524,80.837 72.704,100.81 102.225,85.258 101.673,65.601c-22.181,13.026 -36.073,14.447 -44.046,14.052 26.838,-5.447 55.807,-22.341 61.877,-29.446 0.006,0.315 0.009,0.631 0.009,0.948 0,33.946 -51.15,84.312 -51.15,84.312 0,0 -26.775,-26.282 -41.581,-53.732 -2.07,-0.029 -14.526,4.612 -19.12,-1.608C2.53,73.18 21.554,49.892 38.052,42.945 67.573,56.681 83.755,21.078 92.99,19.104 65.442,2.368 38.209,9.236 35.131,34.103 50.444,25.183 69.231,20.13 77.914,20.525 53.521,25.635 25.58,44.129 17.212,51.155c0,-28.253 22.901,-51.155 51.15,-51.155 16.706,0 31.541,8.009 40.875,20.398 0.001,-0.001 16.669,-5.557 19.037,2.021zM122.433,24.945c-2.194,-3.061 -9.832,0.514 -9.832,0.514 1.069,1.838 2.028,3.748 2.865,5.722 0.849,2.001 1.575,4.067 2.167,6.189 0,0.001 7.799,-8.24 4.799,-12.424zM13.333,77.239c2.372,3.308 10.627,-0.556 10.627,-0.556 -1.156,-1.986 -2.192,-4.051 -3.098,-6.184 -0.918,-2.162 -1.702,-4.396 -2.342,-6.689 0,0 -8.429,8.907 -5.187,13.43z" android:strokeWidth="1.4541"/>
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="64dp"
|
||||
android:height="64dp"
|
||||
android:viewportHeight="135.47"
|
||||
android:viewportWidth="135.47">
|
||||
<path
|
||||
android:fillColor="#ffffff"
|
||||
android:pathData="M128.274,22.419C131.432,31.024 114.539,51.944 98.437,57.312 69.309,46.971 68.362,64.338 44.524,80.837 72.704,100.81 102.225,85.258 101.673,65.601c-22.181,13.026 -36.073,14.447 -44.046,14.052 26.838,-5.447 55.807,-22.341 61.877,-29.446 0.006,0.315 0.009,0.631 0.009,0.948 0,33.946 -51.15,84.312 -51.15,84.312 0,0 -26.775,-26.282 -41.581,-53.732 -2.07,-0.029 -14.526,4.612 -19.12,-1.608C2.53,73.18 21.554,49.892 38.052,42.945 67.573,56.681 83.755,21.078 92.99,19.104 65.442,2.368 38.209,9.236 35.131,34.103 50.444,25.183 69.231,20.13 77.914,20.525 53.521,25.635 25.58,44.129 17.212,51.155c0,-28.253 22.901,-51.155 51.15,-51.155 16.706,0 31.541,8.009 40.875,20.398 0.001,-0.001 16.669,-5.557 19.037,2.021zM122.433,24.945c-2.194,-3.061 -9.832,0.514 -9.832,0.514 1.069,1.838 2.028,3.748 2.865,5.722 0.849,2.001 1.575,4.067 2.167,6.189 0,0.001 7.799,-8.24 4.799,-12.424zM13.333,77.239c2.372,3.308 10.627,-0.556 10.627,-0.556 -1.156,-1.986 -2.192,-4.051 -3.098,-6.184 -0.918,-2.162 -1.702,-4.396 -2.342,-6.689 0,0 -8.429,8.907 -5.187,13.43z"/>
|
||||
</vector>
|
||||
|
|
5
android/app/src/main/res/drawable/ic_splash_padded.xml
Normal file
5
android/app/src/main/res/drawable/ic_splash_padded.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<inset xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@drawable/ic_splash"
|
||||
android:inset="33dp"/>
|
||||
<!--docs say inset needs to be 1/3 of ic_splash to fit-->
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:opacity="opaque">
|
||||
<item android:drawable="?attr/colorPrimary"/>
|
||||
<item android:drawable="@drawable/ic_splash" android:gravity="center"/>
|
||||
</layer-list>
|
|
@ -1,18 +1,20 @@
|
|||
<?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="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
tools:background="@color/bg_primary"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv__logo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="255dp"
|
||||
android:layout_height="0dp"
|
||||
android:contentDescription="@null"
|
||||
app:srcCompat="@drawable/splash"
|
||||
app:srcCompat="@drawable/ic_splash"
|
||||
android:layout_weight="1000"
|
||||
android:layout_margin="@dimen/margin_double"/>
|
||||
|
||||
|
@ -30,6 +32,7 @@
|
|||
android:layout_marginBottom="@dimen/margin_eighth"
|
||||
android:text="@string/app_name"
|
||||
android:gravity="center_horizontal"
|
||||
tools:textColor="@color/white_primary"
|
||||
android:textAppearance="@style/MwmTextAppearance.Title.Splash" />
|
||||
|
||||
<TextView
|
||||
|
@ -40,6 +43,7 @@
|
|||
android:layout_marginStart="@dimen/margin_double"
|
||||
android:layout_marginEnd="@dimen/margin_double"
|
||||
android:gravity="center_horizontal"
|
||||
tools:textColor="@color/white_primary"
|
||||
android:textAppearance="@style/MwmTextAppearance.Toolbar" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
21
android/app/src/main/res/values-v31/themes.xml
Normal file
21
android/app/src/main/res/values-v31/themes.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="MwmTheme.Splash" parent="Theme.SplashScreen">
|
||||
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash_padded</item>
|
||||
<item name="windowSplashScreenBackground">@color/bg_primary</item>
|
||||
<item name="android:textColorPrimary">@color/white_primary</item>
|
||||
<item name="android:navigationBarColor">@color/bg_primary</item>
|
||||
<item name="android:statusBarColor">@color/bg_primary</item>
|
||||
<item name="postSplashScreenTheme">@style/MwmTheme</item>
|
||||
</style>
|
||||
|
||||
<style name="MwmTheme.Night.Splash" parent="Theme.SplashScreen">
|
||||
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash_padded</item>
|
||||
<item name="windowSplashScreenBackground">@color/bg_primary_night</item>
|
||||
<item name="android:textColorPrimary">@color/white_primary</item>
|
||||
<item name="android:navigationBarColor">@color/bg_primary_night</item>
|
||||
<item name="android:statusBarColor">@color/bg_primary_night</item>
|
||||
<item name="postSplashScreenTheme">@style/MwmTheme</item>
|
||||
</style>
|
||||
</resources>
|
Reference in a new issue