зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1366674 - Add Splash Screen. r=maliu
MozReview-Commit-ID: EjRS6w8IOX3 --HG-- extra : rebase_source : 03f8a099667c58c55d18771eb1f80555a099c972
This commit is contained in:
Родитель
8d3b2301c6
Коммит
81076e055d
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 44 KiB |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 68 KiB |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 128 KiB |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 202 KiB |
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.mozilla.gecko.widget.SplashScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/splash_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#ffffff"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:src="@drawable/firefox_logo"/>
|
||||
|
||||
</org.mozilla.gecko.widget.SplashScreen>
|
|
@ -165,6 +165,7 @@ import android.widget.ListView;
|
|||
import android.widget.ViewFlipper;
|
||||
import org.mozilla.gecko.switchboard.AsyncConfigLoader;
|
||||
import org.mozilla.gecko.switchboard.SwitchBoard;
|
||||
import org.mozilla.gecko.widget.SplashScreen;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -242,6 +243,9 @@ public class BrowserApp extends GeckoApp
|
|||
private FirstrunAnimationContainer mFirstrunAnimationContainer;
|
||||
private HomeScreen mHomeScreen;
|
||||
private TabsPanel mTabsPanel;
|
||||
|
||||
private boolean showSplashScreen = false;
|
||||
private SplashScreen splashScreen;
|
||||
/**
|
||||
* Container for the home screen implementation. This will be populated with any valid
|
||||
* home screen implementation (currently that is just the HomePager, but that will be extended
|
||||
|
@ -613,6 +617,7 @@ public class BrowserApp extends GeckoApp
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
final Context appContext = getApplicationContext();
|
||||
|
||||
showSplashScreen = true;
|
||||
GeckoLoader.loadMozGlue(appContext);
|
||||
if (!HardwareUtils.isSupportedSystem() || !GeckoLoader.neonCompatible()) {
|
||||
// This build does not support the Android version of the device; Exit early.
|
||||
|
@ -2772,7 +2777,23 @@ public class BrowserApp extends GeckoApp
|
|||
if (mDynamicToolbar.isEnabled()) {
|
||||
mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
|
||||
}
|
||||
showSplashScreen = false;
|
||||
} else {
|
||||
// The tab going to load is not about page. It's a web page.
|
||||
// If showSplashScreen is true, it means the app is first launched. We want to show the SlashScreen
|
||||
// But if GeckoThread.isRunning, the will be 0 sec for web rendering.
|
||||
// In that case, we don't want to show the SlashScreen/
|
||||
if (showSplashScreen && !GeckoThread.isRunning()) {
|
||||
|
||||
final ViewGroup main = (ViewGroup) findViewById(R.id.main_layout);
|
||||
final View splashLayout = LayoutInflater.from(this).inflate(R.layout.splash_screen, main);
|
||||
splashScreen = (SplashScreen) splashLayout.findViewById(R.id.splash_root);
|
||||
|
||||
showSplashScreen = false;
|
||||
} else if (splashScreen != null) {
|
||||
// Below line will be run when LOCATION_CHANGE. Which means the page load is almost completed.
|
||||
splashScreen.hide();
|
||||
}
|
||||
hideHomePager();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
package org.mozilla.gecko.widget;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
public class SplashScreen extends RelativeLayout {
|
||||
|
||||
private static long MIN_DISPLAY_TIME = 500;
|
||||
private static long MAX_DISPLAY_TIME = 2000;
|
||||
|
||||
private boolean hasReachedThreshold = false;
|
||||
private boolean shouldHideAsap = false;
|
||||
|
||||
public SplashScreen(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public SplashScreen(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public SplashScreen(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
// check if the splash screen could hide now.
|
||||
public void hide() {
|
||||
if (getVisibility() == GONE) {
|
||||
return;
|
||||
}
|
||||
if (hasReachedThreshold) {
|
||||
vanish();
|
||||
} else {
|
||||
// if the threshold not reached, mark
|
||||
shouldHideAsap = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
// Splash Screen will at least wait for this long before disappear.
|
||||
atLeast(MIN_DISPLAY_TIME);
|
||||
}
|
||||
|
||||
// the minimum time the splash screen will stay on the screen
|
||||
private void atLeast(long millis) {
|
||||
postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// Now the threshold is reached. If you want to hide the splash screen asap, do it now.
|
||||
if (shouldHideAsap) {
|
||||
vanish();
|
||||
} else {
|
||||
// after the display threshold is met, hasReachedThreshold is set to true.
|
||||
// So others who want to hide the splash screen could use hide() to hide it afterward.
|
||||
hasReachedThreshold = true;
|
||||
// Now the splash screen will continue to wait till MAX_DISPLAY_TIME is reached.
|
||||
atMost(MAX_DISPLAY_TIME - MIN_DISPLAY_TIME);
|
||||
}
|
||||
}
|
||||
}, millis);
|
||||
}
|
||||
|
||||
// the maximum time the splash screen will stay on the screen
|
||||
private void atMost(long millis) {
|
||||
postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
vanish();
|
||||
}
|
||||
}, millis);
|
||||
}
|
||||
|
||||
// tell the splash screen to fade out.
|
||||
// Don't bother if it's already animating or gone.
|
||||
private void vanish() {
|
||||
if (getVisibility() == GONE || getAlpha() < 1) {
|
||||
return;
|
||||
}
|
||||
SplashScreen.this.animate().alpha(0.0f)
|
||||
.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
super.onAnimationEnd(animation);
|
||||
SplashScreen.this.setVisibility(GONE);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
|
@ -995,6 +995,7 @@ gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [
|
|||
'widget/TabThumbnailWrapper.java',
|
||||
'widget/ThumbnailView.java',
|
||||
'widget/TouchDelegateWithReset.java',
|
||||
'widget/SplashScreen.java',
|
||||
]]
|
||||
# The following sources are checked in to version control but
|
||||
# generated by a script (java/org/mozilla/gecko/widget/themed/generate_themed_views.py).
|
||||
|
|
Загрузка…
Ссылка в новой задаче