Flex mobile apps for iPhone 5 screen - iphone-5

I just tested my first Flex mobile app on iPhone 5, but as I was assuming it doesn't fit to the new 4" screen. Does anybody know if this is already possible? (using Flex 4.6 SDK)

This is a little goofy, but it works. First, make sure you've got the latest AIR SDK installed in your Flash Builder eclipse plug in directory. That will make sure that the following trick actually works.
Now, go to your projects main MXML file (if you're building a view based project that will be a ViewNavigatorApplication class instance). In the opening ViewNavigatorApplication tag place a property for splashScreenImage with a value of "#Embed('Default-568h#2x.png')". It should look something like this…
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
firstView="views.myFirstView"
splashScreenImage="#Embed('Default-568h#2x.png')">
Now, make a 640w x 1136h splash screen png and name it "Default-568h#2x.png". Place that image file in the root (probably your "src" directory) of your project. Compile for your iPhone 5 target and voila!
It turns out that AIR looks for that larger splash screen file as an indicator that you're targeting an iPhone 5 screen size. No setting in the app.xml file. No property in code. Just that splashScreenImage file name.
THAT'S obvious, huh?
As far as creating different layouts for different screen sizes Rich Tretola has a great and cheap book, iOS Applications with Flex 4.5, that discusses responsive design using #media queries. His website has an excerpt that might help… but the book is cheap, useful and quick to read.

You can dynamically change the splash screen like this:
<?xml version="1.0" encoding="utf-8"?>
<s:SplashScreenImage xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
override public function getImageClass(aspectRatio:String, dpi:Number, resolution:Number):Class
{
var x:Number = Capabilities.screenResolutionX;
var y:Number = Capabilities.screenResolutionY;
// HTC
if ((x == 480) && (y == 800)) return img_480_800.source;
// iPhone 5
if ((x == 640) && (y == 1136)) return img_1080_1920.source;
// iPhone 4
if ((x == 640) && (y == 960)) return img_640_960.source;
// Samsung galaxy s3
if ((x == 720) && (y == 1280)) return img_720_1280.source;
// Samsung galaxy s4
if ((x == 1080) && (y == 1920)) return img_1080_1920.source;
// Default
return img_1080_1920.source;
}
]]>
</fx:Script>
<s:SplashScreenImageSource id="img_480_800" source="#Embed('Default_480_800.png')"/>
<s:SplashScreenImageSource id="img_640_960" source="#Embed('Default#2x.png')"/>
<s:SplashScreenImageSource id="img_720_1280" source="#Embed('Default_720_1280.png')"/>
<s:SplashScreenImageSource id="img_1080_1920" source="#Embed('Default-568h#2x.png')"/>
</s:SplashScreenImage>
....
splashScreenImage="DynamicSplashScreen"

Related

Can this code be changed to support a preview in the print dialog?

I am not sure if this is an issue that can be resolved with coding or is by design. I am running the latest version of Windows 11 with all updates. And my application is a MFC dialog application built with Visual Studio 2022.
My application uses a CHtmlView control and the user can trigger a Print Preview. This event will trigger the following code:
void CChristianLifeMinistryHtmlView::DoPrintPreview()
{
ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER, nullptr, nullptr);
HWND HWND_PP = nullptr ;
const auto t1 = ::GetTickCount64();
auto t2 = ::GetTickCount64(); // Extra line required for 'while' rearrangement.
while (HWND_PP == nullptr && t2 - t1 <= 6000) // if found or Timeout reached...
{
HWND HWND_FG = ::GetForegroundWindow(); // Get the ForeGroundWindow
if (HWND_FG != nullptr)
{
TCHAR szClassName[256]{} ;
::GetClassName(HWND_FG, &szClassName[0], 256);
if (lstrcmp(&szClassName[0], IE_PPREVIEWCLASS) == 0) // Check for Print Preview Dialog
HWND_PP = HWND_FG ;
}
theApp.PumpMessage();
t2 = ::GetTickCount64();
}
if (HWND_PP != nullptr)
{
RECT workArea{};
::SystemParametersInfo( SPI_GETWORKAREA, 0, &workArea, 0 );
::MoveWindow(HWND_PP, workArea.left, workArea.top,
workArea.right - workArea.left, workArea.bottom - workArea.top, TRUE);
}
}
This code works fine, and I get a good print preview, resized to the display. For example:
Now, if I hit Print from here it displays:
Opting to print to PDF looks the same:
Prior to the recent Windows 11 Updates these latter "print dialogs" looked different with no preview anyway. But since this updated version of the system "print dialog" can cope with a preview, is there no way to get our existing CHtmlView preview displayed there?
This is only a cosmetic thing because I have a standard preview for the user to see anyway (snap 1). But it would be the icing on the cake if that preview could someone be fed into this popup print window.
Is this something we can do by code or is it a "system / by design issue"?

Different wallpaper for each monitor in a multi-monitor setup in Windows 10

There are a number of questions and answers about setting wallpapers programmatically on multi-monitor setups in Windows, but I'm asking specifically for Windows 10 (and maybe Windows 8) because it seems to work differently from all the explanations I found.
Raymond Chen has an article "How do I put a different wallpaper on each monitor?" (https://devblogs.microsoft.com/oldnewthing/?p=25003), also quoted in Monitors position on Windows wallpaper. The core concepts is that Windows places the top-left corner of the provided bitmap at the top-left corner of the primary monitor, and wraps around to fill any desktop space to the left and/or above that. I understand that, I wrote a little program using that knowledge, and it works beautifully in Windows 7.
How it works: I create a bitmap that conceptually covers the whole desktop space, as the user sees it. I draw the contents of each monitor to that bitmap in its appropriate position (the program is written in C++ using VCL, but the principle remains the same in other programming environments):
TRect GetMonitorRect_WallpaperCoords(int MonitorNum)
{
Forms::TMonitor *PrimaryMonitor = Screen->Monitors[0];
Forms::TMonitor *Monitor = Screen->Monitors[MonitorNum];
// Get the rectangle in desktop coordinates
TRect Rect(Monitor->Left, Monitor->Top, Monitor->Left + Monitor->Width, Monitor->Top + Monitor->Height);
// Convert to wallpaper coordinates
Rect.Left += PrimaryMonitor->Left - Screen->DesktopLeft;
Rect.Top += PrimaryMonitor->Top - Screen->DesktopTop;
Rect.Right += PrimaryMonitor->Left - Screen->DesktopLeft;
Rect.Bottom += PrimaryMonitor->Top - Screen->DesktopTop;
return Rect;
}
std::unique_ptr<Graphics::TBitmap> CreateWallpaperBitmap_WallpaperCoords()
{
std::unique_ptr<Graphics::TBitmap> Bmp(new Graphics::TBitmap);
Bmp->PixelFormat = pf24bit;
Bmp->Width = Screen->DesktopWidth;
Bmp->Height = Screen->DesktopHeight;
// Draw background (not that we really need it: it will never be visible)
Bmp->Canvas->Brush->Style = bsSolid;
Bmp->Canvas->Brush->Color = clBlack;
Bmp->Canvas->FillRect(TRect(0, 0, Bmp->Width, Bmp->Height));
for (int MonitorNum = 0; MonitorNum < Screen->MonitorCount; ++MonitorNum)
{
TDrawContext DC(Bmp->Canvas, GetMonitorRect_WallpaperCoords(MonitorNum));
DrawMonitor(DC);
}
return Bmp;
}
(The draw context uses a coordinate translation rect so that the code int DrawMonitor function can draw in a rectangle like (0, 0, 1920, 1080) without having to wonder where in the full bitmap it is drawing, and with a clip rect so that DrawMonitor can not accidentally draw outside of the monitor it's drawing on).
Then I convert that bitmap to an image that will properly wrap around when placed at the top-left corner of the primary monitor (as Raymond Chen describes in his article):
std::unique_ptr<Graphics::TBitmap> ConvertWallpaperToDesktopCoords(std::unique_ptr<Graphics::TBitmap> &Bmp_WallpaperCoords)
{
std::unique_ptr<Graphics::TBitmap> Bmp_DesktopCoords(new Graphics::TBitmap);
Bmp_DesktopCoords->PixelFormat = Bmp_WallpaperCoords->PixelFormat;
Bmp_DesktopCoords->Width = Bmp_WallpaperCoords->Width;
Bmp_DesktopCoords->Height = Bmp_WallpaperCoords->Height;
// Draw Bmp_WallpaperCoords to Bmp_DesktopCoords at four different places to account for all
// possible ways Windows wraps the wallpaper around the left and bottom edges of the desktop
// space
Bmp_DesktopCoords->Canvas->Draw(Screen->DesktopLeft, Screen->DesktopTop, Bmp_WallpaperCoords.get());
Bmp_DesktopCoords->Canvas->Draw(Screen->DesktopLeft + Screen->DesktopWidth, Screen->DesktopTop, Bmp_WallpaperCoords.get());
Bmp_DesktopCoords->Canvas->Draw(Screen->DesktopLeft, Screen->DesktopTop + Screen->DesktopHeight, Bmp_WallpaperCoords.get());
Bmp_DesktopCoords->Canvas->Draw(Screen->DesktopLeft + Screen->DesktopWidth, Screen->DesktopTop + Screen->DesktopHeight, Bmp_WallpaperCoords.get());
return Bmp_DesktopCoords;
}
Then I install that bitmap as a wallpaper by writing the appropriate values in the registry and calling SystemParametersInfo with SPI_SETDESKWALLPAPER:
void InstallWallpaper(const String &Fn)
{
// Install wallpaper:
// There are 3 name/data pairs that have an effect on the desktop wallpaper, all under HKCU\Control Panel\Desktop:
// - Wallpaper (REG_SZ): file path and name of wallpaper
// - WallpaperStyle (REG_SZ):
// . 0: Centered
// . 1: Tiled
// . 2: Stretched
// - TileWallpaper (REG_SZ):
// . 0: Don't tile
// . 1: Tile
// We don't use the Wallpaper value itself; instead we use SystemParametersInfo to set the wallpaper.
// The file name needs to be absolute!
assert(Ioutils::TPath::IsPathRooted(Fn));
std::unique_ptr<TRegistry> Reg(new TRegistry);
Reg->RootKey = HKEY_CURRENT_USER;
if (Reg->OpenKey(L"Control Panel\\Desktop", false))
{
Reg->WriteString(L"WallpaperStyle", L"1");
Reg->WriteString(L"TileWallpaper", L"1");
Reg->CloseKey();
}
SystemParametersInfoW(SPI_SETDESKWALLPAPER, 1, Fn.c_str(), SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
}
But when I test it in Windows 10, it doesn't work properly anymore: Windows 10 puts the wallpaper completely in the wrong place. Seeing as other people have asked questions about multi-monitor wallpapers in the past, I'm hoping there are people with experience of it on Windows 10.
As far as I can see, Windows 10 places the top-left corner of the provided bitmap at the top-left corner of the desktop space (by which I mean the bounding rectangle of all monitors), instead of the top-left corner of the primary monitor. In code, that means: I leave out the ConvertWallpaperToDesktopCoords step, and then it works fine as far as I can see.
But I can't find any documentation on this, so I don't know if this is officially explanation of how Windows 10 does it. Use with care. Also I don't know when this different behavior started: in Windows 10, or maybe earlier in Windows 8.

Density of screen in iOS and Universal WIndows App

Hi I need to know the density of screen in windows 10/8/8.1 and iOS.
I got screen density in Android using DisplayMetrics but I find no such option/property available in UWP and iOS.
So Is there any property through which I can get screen density in UWP and IOS.
UPDATE - June 8th 2018
Xamarin has released Xamarin.Essentials!
Xamarin.Essentials provides developers with cross-platform APIs for their mobile applications.
Android, iOS, and UWP offer unique operating system and platform APIs that developers have access to all in C# leveraging Xamarin. Xamarin.Essentials provides a single cross-platform API that works with any Xamarin.Forms, Android, iOS, or UWP application that can be accessed from shared code no matter how the user interface is created.
https://github.com/xamarin/Essentials
You can now query the device's display information without having to manage all of the individual platform code pieces.
Device Display Information - https://learn.microsoft.com/en-us/xamarin/essentials/device-display
How-To:
Add a reference to Xamarin.Essentials in your class:
using Xamarin.Essentials;
The following information is exposed through the API:
// Get Metrics
var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
// Orientation (Landscape, Portrait, Square, Unknown)
var orientation = mainDisplayInfo.Orientation;
// Rotation (0, 90, 180, 270)
var rotation = mainDisplayInfo.Rotation;
// Width (in pixels)
var width = mainDisplayInfo.Width;
// Height (in pixels)
var height = mainDisplayInfo.Height;
// Screen density
var density = mainDisplayInfo.Density;
Useful Links:
(Github) Xamarin.Essentials - https://github.com/xamarin/Essentials
(Blog) Xamarin.Essentials - https://blog.xamarin.com/xamarin-essentials-cross-platform-apis-mobile-apps/
(Docs) Getting Started with Essentials - https://learn.microsoft.com/en-us/xamarin/essentials/get-started
Original Post (Before Xamarin.Essentials existed)
Below, I'm storing the specific OS's screen details in static vars, located in the Xamarin Forms App class
These all appear to work in my testing.
(copy/pasted from my github page - https://github.com/mattregul/Xamarin_Screensize)
Android (MainActivity.cs) - Jump to Github Page
// Store off the device sizes, so we can access them within Xamarin Forms
// Screen Width = WidthPixels / Density
// Screen Height = HeightPixels / Density
App.DisplayScreenWidth = (double)Resources.DisplayMetrics.WidthPixels / (double)Resources.DisplayMetrics.Density;
App.DisplayScreenHeight = (double)Resources.DisplayMetrics.HeightPixels / (double)Resources.DisplayMetrics.Density;
App.DisplayScaleFactor = (double)Resources.DisplayMetrics.Density;
iOS (AppDelegate.cs) - Jump to Github Page
// Store off the device sizes, so we can access them within Xamarin Forms
App.DisplayScreenWidth = (double)UIScreen.MainScreen.Bounds.Width;
App.DisplayScreenHeight = (double)UIScreen.MainScreen.Bounds.Height;
App.DisplayScaleFactor = (double)UIScreen.MainScreen.Scale;
Note In all Windows examples screensize is the root project namespace
UWP (App.xaml.cs) - Jump to Github Page
// You decided which is best for you...
// Do you want Size of the App's View
// or
// Do you want the Display's resolution
// ######################################
// Size of App's view
screensize.App.DisplayScreenHeight = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds.Height;
screensize.App.DisplayScreenWidth = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds.Width;
// Size of screen's resolution
//screensize.App.DisplayScreenWidth = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().ScreenHeightInRawPixels;
//screensize.App.DisplayScreenHeight = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().ScreenWidthInRawPixels;
// Pixels per View Pixel
// - https://msdn.microsoft.com/en-us/windows/uwp/layout/design-and-ui-intro#effective-pixels-and-scaling
// - https://msdn.microsoft.com/en-us/windows/uwp/layout/screen-sizes-and-breakpoints-for-responsive-design
screensize.App.DisplayScaleFactor = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
Windows Phone 8.1 (App.xaml.cs) - Jump to Github Page
// Size of App's view
screensize.App.DisplayScreenHeight = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds.Height;
screensize.App.DisplayScreenWidth = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds.Width;
// Pixels per View Pixel
// - https://msdn.microsoft.com/en-us/windows/uwp/layout/design-and-ui-intro#effective-pixels-and-scaling
// - https://msdn.microsoft.com/en-us/windows/uwp/layout/screen-sizes-and-breakpoints-for-responsive-design
screensize.App.DisplayScaleFactor = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
Windows 8.1 (App.xaml.cs) - Jump to Github Page
// Size of App's view
screensize.App.DisplayScreenHeight = Window.Current.Bounds.Height;
screensize.App.DisplayScreenWidth = Window.Current.Bounds.Width;
screensize.App.DisplayScaleFactor = 1; // No scaling here? If you find a scaling for Windows 8.1, please let me know :)
Xamarin Forms Page (App.cs) - Jump to Github Page
namespace screensize
{
public class App : Application
{
public static double DisplayScreenWidth = 0f;
public static double DisplayScreenHeight = 0f;
public static double DisplayScaleFactor = 0f;
public App()
{
string ScreenDetails = Device.OS.ToString() + " Device Screen Size:\n" +
$"Width: {DisplayScreenWidth}\n" +
$"Height: {DisplayScreenHeight}\n" +
$"Scale Factor: {DisplayScaleFactor}";
// The root page of your application
var content = new ContentPage
{
Title = "Xamarin_GetDeviceScreensize",
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
HorizontalTextAlignment = TextAlignment.Center,
FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)),
Text = ScreenDetails
}
}
}
};
MainPage = new NavigationPage(content);
}
}
}
This list lists the ios device dpi information. You can also use GBDeviceInfo thrid-party tool to get the screen density for IOS device like this [GBDeviceInfo deviceInfo].displayInfo.pixelsPerInch;
IOS:
iPhones
iPhone 1/3G/3GS 320 x 480 163 ppi
iPhone 4/4S 640 x 940 326 ppi
iPhone 5/5C/5S 640 x 1136 326 ppi
iPhone 6/6S 750 x 1334 326 ppi
iPhone 6 Plus/6S Plus 1080 x 1920 401 ppi
Without downsampling: 1242 x 2208 461 ppi
Except for the 6th generation (= 5th) iPod touch,
all the models are equal to their iPhone counterparts
iPads
iPad 1/2 768 x 1024 132 ppi
iPad 3/4/Air/Air 2 1536 x 2048 264 ppi
iPad Mini 1 768 x 1024 163 ppi
iPad Mini 2/3/4 1536 x 2048 326 ppi
iPad Pro 2737 x 2048 264 ppi
Apple Watches
Apple Watch 38 mm 272 x 340 326 ppi
Apple Watch 42 mm 312 x 390 326 ppi
I found API in the UWP to retrieve the device dpi. Windows.Graphics.Display.DisplayInformation. You can try it.

Find end page in javafx web view while scrolling

I have loaded local html file in JavaFx2. i am scrolling the web view page. I need to get alert message when i reach the end of the page.
How to do that?
Since you're in a webview, you can use javascript to do that, injecting a following code into the loaded page:
setInterval(function() {
var y = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
y -= 12;
var maxY = document.body.scrollHeight - window.innerHeight;
if (y == maxY)
{
alert('bottom');
}
}, 200);
This will check if you scrolled down to the bottom every 200 ms.
Note that the standard javascript alert() is not available in the current JavaFX 2.x (but is planned for version 3.0). You have to handle it yourself like that:
webview.getEngine().setOnAlert(new EventHandler<WebEvent<String>>() {
#Override
public void handle(WebEvent<String> e)
{
System.out.println("Alert: " + e.getData());
}
});
This should print Alert: bottom to standard output when scrolled to the bottom. Not tested. Tested and working.
Note the y -= 12: this is to account for if the horizontal scroll bar is visible. 12 is the standard height of the scroll bar (so you need to modify it if you're styling scroll bars with CSS). Also, if you are not expecting to see horizontal scroll bars, you need to remove that line altogether. For that reason I recommend manually disabling horizontal scroll bars using CSS.
Also, on a related note, for some reason if you're in fullscreen WebView the maxY is going to always be 0. Currently there doesn't seem to be a workaround

How get fonts installed or supportd in mobile using getProperty - java me

Hope you all will be fine. Can any one tell me how can i get the fonts installed or supported in the mobile. And suppose urdu font supported by the mobile then i set a condition like this.
[code]
import java.lang.*;
String value;
String key = "microedition.font"; // not real need value it's just to show what i want
value = System.getProperty( key );
If (value == urdu){
txtArea2.getStyle.setFont(value);
} else {
System.out.println("Urdu not supported);
}
[/code]
is it possible to do something like this.
Thank you.
MIDP 2.x defines 3 faces of font with 3 sizes + 3 styles.
FACE_MONOSPACE
FACE_PROPORTIONAL
FACE_SYSTEM
SIZE_LARGE
SIZE_MEDIUM
SIZE_SMALL
STYLE_BOLD
STYLE_ITALIC
STYLE_UNDERLINED
You can choose font by using these values as like the below code:
Font f = Font.getFont(FACE_SYSTEM | SIZE_MEDIUM | STYLE_ITALIC);
From MIDP 3.0, you can assign font name with installed font or downloaded font. as like:
Font[] f = Font.getAvailableFonts(); // Get available fonts
Font a = Font.getFont("Andale Mono", STYLE_ITALIC, 10); // Get specific font
Unfortunately, there is no development tools for MIDP3 now.

Resources