-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d88ee79
commit 4b415d2
Showing
3 changed files
with
96 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
app/android/client/src/main/java/org/stendhalgame/client/SplashUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*************************************************************************** | ||
* Copyright © 2024 - Faiumoni e. V. * | ||
*************************************************************************** | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
package org.stendhalgame.client; | ||
|
||
import android.content.res.Configuration; | ||
import android.widget.ImageView; | ||
|
||
|
||
public class SplashUtil { | ||
|
||
/** Image used as title page background. */ | ||
private final ImageView splash; | ||
|
||
/** Singleton instance. */ | ||
private static SplashUtil instance; | ||
|
||
|
||
/** | ||
* Retrieves singleton instance. | ||
*/ | ||
public static SplashUtil get() { | ||
if (SplashUtil.instance == null) { | ||
SplashUtil.instance = new SplashUtil(); | ||
} | ||
return SplashUtil.instance; | ||
} | ||
|
||
/** | ||
* Hidden singleton constructor. | ||
*/ | ||
private SplashUtil() { | ||
splash = (ImageView) MainActivity.get().findViewById(R.id.splash); | ||
setVisible(false); | ||
} | ||
|
||
/** | ||
* Sets the background splash image. | ||
* | ||
* @param resId | ||
* Resource ID. | ||
* @param bgColor | ||
* Coloring to fill behind splash image. | ||
*/ | ||
private void setImage(final int resId, final int bgColor) { | ||
splash.setBackgroundColor(bgColor); | ||
splash.setImageResource(resId); | ||
} | ||
|
||
/** | ||
* Sets splash image dependent on device orientation. | ||
*/ | ||
public void update() { | ||
if (!isVisible()) { | ||
return; | ||
} | ||
int resId = R.drawable.splash; | ||
if (MainActivity.get().getOrientation() == Configuration.ORIENTATION_PORTRAIT) { | ||
resId = R.drawable.splash_portrait; | ||
} | ||
// light blue background color | ||
setImage(resId, 0xff6c9ed1); | ||
} | ||
|
||
/** | ||
* Shows or hides background splash image. | ||
* | ||
* @param visible | ||
* `true` if image should visible, `false` if not. | ||
*/ | ||
public void setVisible(final boolean visible) { | ||
splash.setVisibility(visible ? ImageView.VISIBLE : ImageView.GONE); | ||
update(); | ||
} | ||
|
||
/** | ||
* Checks if splash is visible. | ||
*/ | ||
public boolean isVisible() { | ||
return ImageView.VISIBLE == splash.getVisibility(); | ||
} | ||
} |