Action Bar and Activity Handling in Xamarin - xamarin

I have two questions:
I want to change the Action Bar color. Right now I'm using the default theme for the application. How can I do this?
The next question is: How can I show some specific activities when the application is running for the very first time on device after installation? I don't want to show them again after that.

1)
You can change the color exactly like in an native android app.
http://developer.android.com/training/material/theme.html
Here is a xamarin related tutorial: https://blog.xamarin.com/android-tips-hello-material-design-v7-appcompat/
2) You could use the Settings Plugin and then read a boolean value like
var settings = CrossSettings.Current;
var shownFirstLaunch = settings.GetValueOrDefault<bool>("FirstLaunchShown", false);
if(shownFirstLaunch) {
// show Mainactivity
}
else {
settings.AddOrUpdateValue<bool>("FirstLaunchShown", true);
// show first launch activity
}

Related

Input.Touch not working on OSX

I'm a total beginner in Unity and created a function that simply sets the text of a text element when a touch is detected like this:
// Update is called once per frame
void Update () {
if (didTap ()) {
print ("did tap!");
tapText.text = "TAP!";
}
}
private bool didTap() {
print ("checking didtap");
if (Input.touchCount > 0) {
Touch initialTouch = Input.GetTouch (0);
return initialTouch.phase == TouchPhase.Began;
}
return false;
}
When I run this on an actual device (Android phone) it works perfectly, but when I 'click' in the unity editor when running the game nothing happens. I'm running OSX 10.12.2. Anything I need to configure to have the mouse mimic touch events?
You can duplicate Unity's play mode window onto your mobile device by using the UnityRemote app. This will allow you to interact with your phone's features, while still running Unity on your computer.
UnityRemote requires some setup in Unity along with downloading the app. Consider watching this video: Unity Remote Setup Tutorial
Alternatively, see the answer from Hellium in this question, in conjunction with getting the mouse clicks, to only compile code based on the device used.
There's an odd difference between "touch" input and "mouse" input in Unity. Input.touchCount will always return 0 while you're running in the Editor but Input.GetMouseButtonDown(0) works for both the Editor and the first touch of one or more touches while on a mobile build.
You have two options to solve this issue via code (your other option is the remote ryemoss mentioned):
If you're only ever using one touch, use Input.GetMouseButtonDown(0) and Input.GetMouseButtonUp(0).
Use #if UNITY_IOS, #if UNITY_ANDROID and #if UNITY_EDITOR tags to write separate input readers for your platforms and then have them all call into the same functionality.

How can I detect Windows 10 light/dark mode?

I'm using Windows.UI.ViewManagement.UISettings to get system accent color but it seems this class does not have any method or property for light/dark mode. I failed to find a document for this feature, how can I detect this?
PS: I'm making a JS app which does not have access for Windows.UI.Xaml namespace.
You can create a Windows Runtime Component project in your solution from there you access Windows.UI.Xaml namespace. Add a method to check current ApplicationTheme like that.
public sealed class Test
{
public static string CurrentTheme()
{
var isDark = Application.Current.RequestedTheme == ApplicationTheme.Dark;
if (isDark)
return "Dark";
return "Light";
}
}
Add reference to windows runtime component project in your javascript app project and you can call this method where ever you want to check application theme. Take a look here for walkthrough on createing Windows Runtime Component.
I have found an easier solution, which should work in JavaScript apps as well, without requiring the Windows Runtime Component - the UISettings class:
var uiSettings = new Windows.UI.ViewManagement.UISettings();
var color = uiSettings.getColorValue(
Windows.UI.ViewManagement.UIColorType.background
);
The color you get is either black for dark theme or white for light theme.
The class also has very useful event ColorValuesChanged which you can use to observe theme changes at runtime.
For Windows 10, the value of the AppsUseLightTheme property in the path HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize of the registry specifies wherever Windows is in dark or light mode.
You can read the registry if the theme is enabled for the current user and get the setting from there. Something like this...
private const string RegistryKeyPath = #"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
private const string RegistryValueName = "AppsUseLightTheme";
private static ApplicationTheme GetWindowsTheme()
{
using var key = Registry.CurrentUser.OpenSubKey(RegistryKeyPath);
var registryValueObject = key?.GetValue(RegistryValueName);
if (registryValueObject == null)
{
return ApplicationTheme.Light;
}
var registryValue = (int)registryValueObject;
return registryValue > 0 ? ApplicationTheme.Light : ApplicationTheme.Dark;
}
Full example can be found in this link
https://engy.us/blog/2018/10/20/dark-theme-in-wpf/
Before the Windows Anniversary update you could not do that. The application theme was always the one you set in the App.xaml file:
<Application
...
RequestedTheme="Dark">
</Application>
Now with the new Anniversary Update, you can remove this line from the App.xaml file, which will make the app honor the user's system settings.
The RequestedTheme enumeration has actually three values - Dark, Light and Default. Default is the value that reflects the system settings, Dark and Light force the theme.
If you want to actually detect the current theme in code when App's RequestedTheme is Default, you will probably need to check the some color resource like SystemAltHighColor for its value, because that will give you an idea of what theme is currently set.
ThemeResources have been introduced in 8.1 and their behavior is similar in W10. Therefore you can define suitable resource in ThemeDictionaries responsible for available Themes and then you can check the defined resource when you whant to know which Theme is currently used.
The code will be very similar to the one in this answer.
If you want to get the Value in PowerShell you can use the following code:
(New-Object Windows.UI.ViewManagement.UISettings).GetColorValue("background")

Why does the skin not work to button when using 5.5 plugin?

I am using Kony 5.5 plugin then took build for BBQ10. I declared red colour for the button in the skin. But the colour has not applied to the button means black colour button displayed instead of red colour button in the Q 10 device. I want to change the colour of the button. Please give me solution.
A couple of things to check:
1. make sure that under the Skins for the button widget, there is not a forked setting for BB; you may have changed the "Common" skin, but if there is a declared skin specifically for BB, then it will override your settings.
2. Try adding a new button just to test, specifically set the color to red, and see if that button is displaying properly. This will show if there is an overall issue or just an issue with the button you are trying to configure ( this is more of a sanity check than a technical fix )
Customized skin using colour doesn't work to Blackberry 10 devices.It is a limitation of Kony platform.Please read documents the following link.
Docs
First you have to check whether you choose skin option for button then check its under common. Because you may choose on Windows, iOS or other. Try this:
//Defining the properties for a button with skin: "btnSkin".
var btnBasic = {
id:"button1", isVisible:true, skin:"btnSkin",
focusSkin:"btnFSkin", text:"Click Here"
};
var btnLayout = {
containerWeight:100, padding:[5,5,5,5],
margin:[5,5,5,5], hExpand:true, vExpand:false,
displayText:true
};
var btnPSP={};
//Creating the button.
var button1 = new kony.ui.Button(btnBasic, btnLayout, btnPSP);
//Reading skin of the button.
alert("Button skin ::"+button1.skin);

Wide Tile Windows Phone 7.1 using MangoPollo

I have a Windows Phone 7.1 app and I want to include a wide iconic tile. I found a library called MangoPollo:
http://mangopollo.codeplex.com/
I found this code within:
var tile = ShellTile.ActiveTiles.FirstOrDefault();
if (tile != null)
{
var tileData = new FlipTileData();
tileData.Title = "Start Debugging";
tileData.BackContent = "switch to windows phone, we've got candy";
tileData.BackgroundImage = new Uri("Assets/tileBackground.png", UriKind.Relative);
tileData.BackBackgroundImage = new Uri("Assets/tileBackBackground.png", UriKind.Relative);
tileData.WideBackContent = "switch to windows phone, we've got candy";
tileData.WideBackgroundImage = new Uri("Assets/wideTileBackground.png", UriKind.Relative);
tileData.WideBackBackgroundImage = new Uri("Assets/wideTileBackBackground.png", UriKind.Relative);
tile.Update(tileData);
}
The problem is there isn't any documentation included on Codeplex for the project so I'm not sure where to insert this code (i.e. which function) to change the tile size from normal to wide.
Another way of creating Wide Tile in Windows Phone 7. Tested it and it works.
Check this out.
http://www.supersmithbros.com/index.php/latest-news/93-how-to-create-a-wp8-wide-tile-in-wp7-xna
You may call it where you want and there is no code to change tile at the user screen, because it's not allowed.
If you look in the source code, in the link to MangoPollo which you supplied, the sample code places the tile code in a button click event. So what I would do in your app, is make an option to set up this new tile (settings page, maybe?) and when the user turns this setting on, you would run the code in that event handler.
This way, the code doesn't unnecessarily execute multiple times (as it would if it were in the constructor of a page or in app.xaml.cs).
Hope this helps!
Edit:
Based on your comment then, maybe you can put it in the constructor of your first page. Maybe, then, to prevent the code from executing more than necessary, you could check the existing tile to see if it already has a WideBackgroundImage, and if it doesn't, then set it and call Update() otherwise just continue.

UI Automation FrameWork for iPhone

I am exploring the newly exposed framework UI Automation in iphoneOS 4.0. Has anybody tested their application using this framework. I will appreciate any help.
I am trying to test a sample application that just contains a textfield and a button. I have written a script as
UIALogger.logStart("Starting Test");
var view = UIATarget.localTarget().frontMostApp().mainWindow().elements()[0];
var textfields = view.textFields();
if (textfields.length != 1) {
UIALogger.logFail("Wrong number of text fields");
} else {
UIALogger.logPass("Right number of text fields");
}
textfields[0].setValue("anurag");
view.buttons()[0].tap();
The problem is that the value of textfield is not getting set and no button is tapped. When I run the instruments only the view(with textfield and button) appears and then notting is happening.
There is a message in instruments "Something else has happened".
If your main window contains a button and a text field (in this order in the hierarchy) then your first line of code will return you the UIAButton element, so the next line is incorrect, because you're trying to call textFields() on a button.
The first part should look like this:
var view = UIATarget.localTarget().frontMostApp().mainWindow();
var textfields = view.textFields();
if (textfields.length != 1) {
UIALogger.logFail("Wrong number of text fields");
} else {
UIALogger.logPass("Right number of text fields");
}
And in that case I think there are two ways of testing the tap and text field. Like this:
textfields[0].setValue("anurag");
view.buttons()[0].tap();
or like this:
view.elements()[1].setValue("anurag");
view.elements()[0].tap();
And personally I prefer getting objects by using Accessibility Label instead of index. For more information look for a UIAElement Class Reference and take a look here:
UI Automation Reference Collection
All this stuff is gonna work only if the application is made with that accessibility thing (its own accessibility protocol: by tagging all its UI controls in Interface Builder with names, by setting the Accessability label to a unique value for the view). Or if you work with iPhone standard controls.
If the application doesn't contain anything like that, you won't be able to do much with UI Automation and will see only a 320x480 empty canvas.
You can check this link for some more details.
For example, I work on a OpenGL application that was not built with any accessibility tag and I cannot see anything through UI Automation besides a 320x480 empty form.

Resources