Add splash screen to hide black screen in android during launching
This commit is contained in:
parent
c9fc04720c
commit
4a4da3c96c
@ -31,6 +31,7 @@ For similar reasons, and because some features are vastly more complex than othe
|
||||
#### Android
|
||||
* Use the android app bundle, allowing all tracks to be included, by Benau
|
||||
* Use the native progress indicator during game data extraction, by Benau
|
||||
* Add a launch splash screen, by Benau
|
||||
#### iOS
|
||||
* Allow server creation in-game by using only one process for client and server, by Benau
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
android:banner="@drawable/banner"
|
||||
android:hasCode="true"
|
||||
android:isGame="true"
|
||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
||||
android:theme="@style/Theme.STKSplashScreen"
|
||||
android:hardwareAccelerated="true"
|
||||
android:resizeableActivity="true">
|
||||
|
||||
|
@ -497,6 +497,19 @@ mkdir -p "$DIRNAME/res/drawable-xxxhdpi/"
|
||||
rm -rf "$DIRNAME/res/values*"
|
||||
mkdir -p "$DIRNAME/res/values/"
|
||||
|
||||
STYLES_FILE="$DIRNAME/res/values/styles.xml"
|
||||
|
||||
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>" > "$STYLES_FILE"
|
||||
echo "<!--Generated by make.sh-->" >> "$STYLES_FILE"
|
||||
echo "<resources>" >> "$STYLES_FILE"
|
||||
echo " <style name=\"Theme.STKSplashScreen\" parent=\"android:style/Theme.Holo\">" >> "$STYLES_FILE"
|
||||
echo " <item name=\"android:windowBackground\">#A8A8A8</item>" >> "$STYLES_FILE"
|
||||
echo " <item name=\"android:windowFullscreen\">true</item>" >> "$STYLES_FILE"
|
||||
echo " <item name=\"android:windowNoTitle\">true</item>" >> "$STYLES_FILE"
|
||||
echo " <item name=\"android:windowContentOverlay\">@null</item>" >> "$STYLES_FILE"
|
||||
echo " </style>" >> "$STYLES_FILE"
|
||||
echo "</resources>" >> "$STYLES_FILE"
|
||||
|
||||
STRINGS_FILE="$DIRNAME/res/values/strings.xml"
|
||||
|
||||
# Strings used in stk android ui (when extracting game data first time)
|
||||
|
@ -4,6 +4,8 @@ import org.supertuxkart.stk_dbg.STKEditText;
|
||||
import org.libsdl.app.SDLActivity;
|
||||
import org.libsdl.app.SDL;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.ActivityNotFoundException;
|
||||
@ -11,11 +13,18 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.Rect;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Process;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
@ -23,6 +32,7 @@ import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.MarginLayoutParams;
|
||||
@ -32,11 +42,13 @@ import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Set;
|
||||
|
||||
import org.minidns.hla.DnssecResolverApi;
|
||||
@ -48,6 +60,7 @@ public class SuperTuxKartActivity extends SDLActivity
|
||||
{
|
||||
private AlertDialog m_progress_dialog;
|
||||
private ProgressBar m_progress_bar;
|
||||
private ImageView m_splash_screen;
|
||||
private STKEditText m_stk_edittext;
|
||||
private int m_bottom_y;
|
||||
// ------------------------------------------------------------------------
|
||||
@ -164,6 +177,7 @@ public class SuperTuxKartActivity extends SDLActivity
|
||||
super.onCreate(instance);
|
||||
m_progress_dialog = null;
|
||||
m_progress_bar = null;
|
||||
m_splash_screen = null;
|
||||
m_bottom_y = 0;
|
||||
final View root = getWindow().getDecorView().findViewById(
|
||||
android.R.id.content);
|
||||
@ -186,6 +200,56 @@ public class SuperTuxKartActivity extends SDLActivity
|
||||
SDLActivity.moveView(moved_height);
|
||||
}
|
||||
});
|
||||
|
||||
InputStream istr = null;
|
||||
try
|
||||
{
|
||||
LinearLayout ll = new LinearLayout(this);
|
||||
LinearLayout.LayoutParams ll_param = new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
ll.setLayoutParams(ll_param);
|
||||
|
||||
WindowManager wm =
|
||||
(WindowManager)getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics display_metrics = new DisplayMetrics();
|
||||
wm.getDefaultDisplay().getMetrics(display_metrics);
|
||||
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
|
||||
int w = display_metrics.widthPixels;
|
||||
int h = display_metrics.heightPixels;
|
||||
Bitmap scaled = Bitmap.createBitmap(w, h, conf);
|
||||
|
||||
Canvas canvas = new Canvas(scaled);
|
||||
istr = getAssets().open("data/gui/icons/logo.png");
|
||||
Bitmap logo = BitmapFactory.decodeStream(istr);
|
||||
Rect src = new Rect(0, 0, logo.getWidth(), logo.getHeight());
|
||||
// STK logo is a square
|
||||
int target_size = w;
|
||||
if (target_size > h)
|
||||
target_size = h;
|
||||
target_size /= 2;
|
||||
Rect dest = new Rect(w / 2 - target_size / 2,
|
||||
h / 2 - target_size / 2,
|
||||
w / 2 - target_size / 2 + target_size,
|
||||
h / 2 - target_size / 2 + target_size);
|
||||
canvas.drawBitmap(logo, src, dest, null);
|
||||
|
||||
m_splash_screen = new ImageView(this);
|
||||
m_splash_screen.setBackgroundColor(Color.argb(255, 168, 168, 168));
|
||||
m_splash_screen.setImageDrawable(new BitmapDrawable(getResources(),
|
||||
scaled));
|
||||
addContentView(m_splash_screen, ll_param);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (istr != null)
|
||||
istr.close();
|
||||
}
|
||||
catch(Exception e) {}
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
@Override
|
||||
@ -378,4 +442,25 @@ public class SuperTuxKartActivity extends SDLActivity
|
||||
});
|
||||
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
public void hideSplashScreen()
|
||||
{
|
||||
if (m_splash_screen != null)
|
||||
{
|
||||
m_splash_screen.animate().setDuration(200).alpha(0).setListener(
|
||||
new AnimatorListenerAdapter()
|
||||
{
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation)
|
||||
{
|
||||
if (m_splash_screen.getParent() instanceof ViewGroup)
|
||||
{
|
||||
ViewGroup view = (ViewGroup)m_splash_screen.getParent();
|
||||
view.removeView(m_splash_screen);
|
||||
m_splash_screen = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
src/main.cpp
20
src/main.cpp
@ -163,6 +163,7 @@
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <SDL_system.h>
|
||||
#include <jni.h>
|
||||
#endif
|
||||
|
||||
#include <stdexcept>
|
||||
@ -1760,6 +1761,25 @@ void initRest()
|
||||
GUIEngine::init(device, driver, StateManager::get());
|
||||
GUIEngine::renderLoading(true, true, false);
|
||||
|
||||
#ifdef ANDROID
|
||||
JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv();
|
||||
assert(env);
|
||||
jobject activity = (jobject)SDL_AndroidGetActivity();
|
||||
if (activity != NULL)
|
||||
{
|
||||
jclass clazz = env->GetObjectClass(activity);
|
||||
if (clazz != NULL)
|
||||
{
|
||||
jmethodID method_id = env->GetMethodID(clazz, "hideSplashScreen",
|
||||
"()V");
|
||||
if (method_id != NULL)
|
||||
env->CallVoidMethod(activity, method_id);
|
||||
env->DeleteLocalRef(clazz);
|
||||
}
|
||||
env->DeleteLocalRef(activity);
|
||||
}
|
||||
#endif
|
||||
|
||||
stk_config->initMusicFiles();
|
||||
// This only initialises the non-network part of the add-ons manager. The
|
||||
// online section of the add-ons manager will be initialised from a
|
||||
|
Loading…
x
Reference in New Issue
Block a user