How to disable the android wear back swipe? - wear-os

I am creating a Android Wear app that has an touch area. The user is suppose to be able to move it's finger in all directions over the screen (Think touchpad on your laptop). However the back swipe makes this a bit problematic. Any help with getting around this issue would be a great help.
How to disable the android wear back swipe?
/Jakob

There is an attribute in window style to disable this behavior:
<style name="AppTheme" parent="#android:style/Theme.DeviceDefault.Light">
<item name="android:windowSwipeToDismiss">false</item>
</style>
Once you disable it you have to provide other way of exiting your app.
There is a DismissOverlayView class (listed here https://developer.android.com/training/wearables/apps/layouts.html#UiLibrary) that you should use instead.
Basically it provides an overlay that will show a red button with cross after a long press. Clicking the red button will exit your app.
Here is a video from Google I/O 2014 with some bookmarked moments:
https://www.youtube.com/watch?v=sha_w3_5c2c#t=1390 <- disabling android:windowSwipeToDismiss
https://www.youtube.com/watch?v=sha_w3_5c2c#t=1505 <- Java code for DismissOverlayView
You can also check another video called:
Fullscreen apps for Android Wear:
https://www.youtube.com/watch?v=naf_WbtFAlY

You can try to write AndroidManifest.xml theme
android:theme="#style/Theme.Wearable.Modal inside activity tag
<activity
android:name="com.smart.remote.wear.MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.Wearable.Modal">

If you want the whole app to override Swipe, place the theme property under your Manifest's <application> tag. If you want it to apply only to a certain activity, then place the property under that activity's <activity> tag.
So:
create or update styles.xml in the res/values folder with the android:windowSwipeToDismiss property, such as:
...
false
If you want to override swipe in the whole app, Update your Manifest as such:
<application
...
android:theme="#style/AppTheme">
If you want to override swipe in a specific activity, Update your Manifest as such:
<activity
...
android:theme="#style/AppTheme">
</activity>
where ... represents all your other settings you already have. Remember you will need to give alternative ways out of the activity and/or app depending on which level you overrode

Related

How to make Sure Keyboard is not placed over an Entry when it is focused in Xamarin?

I have an Entry which is placed in a ContentView, and this ContentView is placed in a Grid. When this Entry is Focused, the Keyboard is placed over the ContentView preventing the user from seeing the Entry.
I would like to know if there is a way to determine if a View is Visible and if not make sure it is (prevent the Keyboard from being placed over it).
Any thoughts on how I could do this.
I would need this to work on iOS specifically, Android and Windows seem not to have this issue in my use-case.
On Android platform, the official document provides Soft Keyboard Input Mode. Refer to https://learn.microsoft.com/en-us/xamarin/xamarin-forms/platform/android/soft-keyboard-input-mode for details.
On IOS platform, you can query KeyboardOverlap installation in IOS's nuget, and then add KeyboardOverlapRenderer.Init (); in AppDelegate to achieve the effect in IOS.

Xamarin Forms - physical keyboard dims page when no input control is present

My actual application is using a bluetooth scanner in HID mode and capturing the input on the DispatchKeyEvent of the MainActivity. It works great except that the screens dims to some dark opaque color where it looks like everything is disabled and you have to navigate back to a page with an input control and tap on it to get the screen to go back to normal.
It's not as noticeable in the stock template but in my actual application (Screen shots at bottom) the dimming is very noticeable; it's a blue-gray opaque overlay that really stands out. I have no idea why it's like that. I'd almost just be happy if my actual app dimmed like the default forms sample.
Steps:
Make a Xamarin Forms app from one of the templates.
Change nothing.
Run simulator.
Press a button on your keyboard.
Result:
The screen dims and the soft keyboard does not popup.
Next Steps:
Add an Entry control. < Entry/> will do.
Click on it and the screen brightens back up.
Delete < Entry/>
Press a key on your keyboard and the soft keyboard pops up and the screen doesn't dim again.
What I want:
To know where the dim/overlay color/opacity is set so I can change it.
To not allow the soft keyboard to try and popup at all unless there's an entry field that has focus.
Here's screenshots from the default forms app:
Not Dim:
Dimmed after pressing the keyboard:
My actual test device is a Samsung Galaxy XCover Pro running Android 10.0. I'm working on porting a native Xamarin Android app to Forms so we can run it on iOS as well. I never had this issue with my android app and I'm not sure how to track down what's happening.
Here's a before pic. I've got an Entry field focused.
After scanning a barcode with my bluetooth scanner this happens:
There is NOT any overlay/modal boxview defined in the XAML. The overlay is nothing that I added. Though I seem to have done something to influence the color; I don't see anything in my styles.xml files that would change the color from the default light gray (as shown in the sample Xamrin Forms template).
I can reproduce this with a scanner on the "Welcome to Xamaring Forms!" as well, the screenshots don't really show the change in overlay color; its much more subtle; I really would like to know why in my app the overlay is so much more obvious.
I'm still annoyed it happens at all. But just in case anyone else using a
hardware keyboard as input (or a BT scanner connected as a HID) and you thought you'd be fancy and override one of the default styles and use a pretty green accent color like this: (though stupidOverlayColor has been changed to pink just to make sure I found the issue) - don't do it.
<!-- Base theme applied regardless of API level -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlHighlight">#color/stupidOverlayColor</item>
</style>
The moral of the story is that "colorControlHighlight" is evil and not to be overridden and used with hardware keyboards, unless you want your app to think the entire screen should get the highlight color after you scan a barcode like this:

Disable Swipe to dismiss on ONLY ONE activity

I have a fragment activity and I want to disable the swipe to dismiss feature on this, and only this, activity.
Is it possible?
I got it.
on my manifest in the activity I want to disable the swipe to dismiss I've added this:
<activity android:label="#string/app_name" android:name=".ACTIVITYNAME"
android:theme="#style/Theme.Wearable.Modal"/>

Issue while setting WindowSoftInputMode to AdjustPan

I’m working on Xamarin forms project. I’ve many Entry fields in my application, one of them is in popup and the popup opens in the centre of the device screen. Also few entry fields are in scroll view. The issue is only with the Android Application. For iOS it’s working perfectly.
When I click on Entry field in side the popup, the soft key board is opened and the UI of my popup gets disturbed. So, I decided to set
WindowSoftInputMode = SoftInput.AdjustPan to my main Activity. This solves my UI issue of the popups but now when I click on other entry fields,my ![scroll view stops scrolling] (few entry fields are in side scrollview).I tried by using AdjustResize and rest of other soft inputs, but of no use.
Any ideas on how to get rid of this ?
On Android Xamarin.Forms Application is working on a single Android Activity, so WindowSoftInputMode is set globally. You could do a dependency injection service. On iOS it would do nothing and on Android it would set WindowSoftInputMode to your desired value. Then use it to set WindowSoftInputMode before and after showing your Popup.
In Xamarin.Forms Forms.Context is the Activity.
var window = ((Activity)Forms.Context).Window;
window.SetSoftInputMode(SoftInput.AdjustPan);
In case of
Xamarin Android
you can access window directly from mainActivity Like so:
Window.SetSoftInputMode(Android.Views.SoftInput.AdjustPan);
or in AndroidManifest.xml
<activity android:name=".myActivity"
android:label="#string/app_name"
android:screenOrientation="sensorPortrait"
android:windowSoftInputMode="adjustPan"/>

icon invisible in menu

In my Android application I create such menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/rymcium"
android:title="rymcium"
android:icon="#android:drawable/ic_delete"
/>
</menu>
When I run it on old Android version (on emulated Android 1.6), icon is visible. When I run it on new Android version (on real or emulated Android 4), the icon is invisible. Is it normal? Can I do something to make it visible?
It was because my activity used theme android:Theme.Light (it was default when I created my project in eclipse). When I changed theme for android:style/Holo.ButtonBar, icons are visible.

Resources