mirror of
https://github.com/apache/cordova-plugin-splashscreen.git
synced 2026-04-14 00:01:34 +08:00
CB-8750 [wp8]: Allow resolution-specific splashscreen images
There are two aspect ratios for Windows Phone devices: 15:9 and 16:9. At the moment, though, there is only one splash screen by default for WP8 Cordova apps. When stretched to fit all possible resolutions, this can sometimes look bad. WP supports resolution-specific splashscreens, so this commit adds the same support to the splashscreen plugin. It uses the same base name for the splashscreen, but adds modifiers such as ".screen-<res>" based on the device. If a screen-specific image is found, it is used. If not, we fall back to the single default image. Fixes https://issues.apache.org/jira/browse/CB-8750 github close #41 github close #42
This commit is contained in:
+52
-7
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -43,7 +43,7 @@ namespace WPCordovaClassLib.Cordova.Commands
|
||||
private Popup popup;
|
||||
|
||||
// Time until we dismiss the splashscreen
|
||||
private int prefDelay = 3000;
|
||||
private int prefDelay = 3000;
|
||||
|
||||
// Whether we hide it by default
|
||||
private bool prefAutoHide = true;
|
||||
@@ -66,8 +66,7 @@ namespace WPCordovaClassLib.Cordova.Commands
|
||||
Stretch = Stretch.Fill
|
||||
};
|
||||
|
||||
Uri imagePath = new Uri(prefImagePath, UriKind.RelativeOrAbsolute);
|
||||
var imageResource = Application.GetResourceStream(imagePath);
|
||||
var imageResource = GetSplashScreenImageResource();
|
||||
if (imageResource != null)
|
||||
{
|
||||
BitmapImage splash_image = new BitmapImage();
|
||||
@@ -76,7 +75,7 @@ namespace WPCordovaClassLib.Cordova.Commands
|
||||
}
|
||||
|
||||
// Instansiate the popup and set the Child property of Popup to SplashScreen
|
||||
popup = new Popup() { IsOpen = false,
|
||||
popup = new Popup() { IsOpen = false,
|
||||
Child = SplashScreen,
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
@@ -133,6 +132,52 @@ namespace WPCordovaClassLib.Cordova.Commands
|
||||
}
|
||||
}
|
||||
|
||||
private StreamResourceInfo GetSplashScreenImageResource()
|
||||
{
|
||||
// Get the base filename for the splash screen images
|
||||
string imageName = System.IO.Path.GetFileNameWithoutExtension(prefImagePath);
|
||||
Uri imageUri = null;
|
||||
StreamResourceInfo imageResource = null;
|
||||
|
||||
// First, try to get a resolution-specific splashscreen
|
||||
try
|
||||
{
|
||||
// Determine the device's resolution
|
||||
switch (ResolutionHelper.CurrentResolution)
|
||||
{
|
||||
case Resolutions.HD:
|
||||
imageUri = new Uri(imageName + ".screen-720p.jpg", UriKind.Relative);
|
||||
break;
|
||||
|
||||
case Resolutions.WVGA:
|
||||
imageUri = new Uri(imageName + ".screen-WVGA.jpg", UriKind.Relative);
|
||||
break;
|
||||
|
||||
case Resolutions.WXGA:
|
||||
default:
|
||||
imageUri = new Uri(imageName + ".screen-WXGA.jpg", UriKind.Relative);
|
||||
break;
|
||||
}
|
||||
|
||||
imageResource = Application.GetResourceStream(imageUri);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// It's OK if we didn't get a resolution-specific image
|
||||
}
|
||||
|
||||
// Fallback to the default image name without decoration
|
||||
if (imageResource == null)
|
||||
{
|
||||
imageUri = new Uri(prefImagePath, UriKind.Relative);
|
||||
imageResource = Application.GetResourceStream(imageUri);
|
||||
}
|
||||
|
||||
if (imageUri != null) Debug.WriteLine("INFO :: SplashScreen: using image {0}", imageUri.OriginalString);
|
||||
|
||||
return imageResource;
|
||||
}
|
||||
|
||||
public void show(string options = null)
|
||||
{
|
||||
Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||
|
||||
Reference in New Issue
Block a user