disabling multitouch across the appwide in android xamarin - android

Xamarin forums question link:
https://forums.xamarin.com/discussion/60321/disabling-multitouch-across-the-appwide-in-android-xamarin#latest
Is there a way to disable multi-touch App wide in Xamarin Android.
I currently have a PCL, project. With shared code implemented using Xamarin forms UI.
I just want to prevent users from clicking more than 1 button in Android.
All our buttons are ICommand based and called from the viewModel. They are all async Tasks (we wanted to make them non-blocking and run in the background thread). --> This approach works fine in iOS, just want to disable it App wide in Android.
I tried the following in MainActivity.cs
public override bool OnTouchEvent(MotionEvent e)
{
if(e.PointerCount > 1)
{
return false;
}
else
{
return base.OnTouchEvent(e);
}
}
But it has not made any difference. Any help would be appreciated
public override void OnUserInteraction()
{
base.OnUserInteraction();
}
works but does not give me the number of touch events

Apply an application theme that disables multi-touch (derived from this answer).
Under Resources/Values add a file named Styles.xml with the following code:
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="MyAppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:windowEnableSplitTouch">false</item>
<item name="android:splitMotionEvents">false</item>
</style>
</resources>
android:windowEnableSplitTouch indicates if touches can be split across other windows that also support split touch.
android:splitMotionEvents indicates if a ViewGroup should split MotionEvents to separate child views during touch event dispatch.
Applying these at the application theme level will forced single touch for all views in your application.
And then in your applications manifest apply the style to the android:theme attribute on the application:
Sample manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.companyname.testapp">
<uses-sdk android:minSdkVersion="11" />
<application
android:allowBackup="true"
android:icon="#mipmap/icon"
android:label="#string/app_name"
android:theme="#style/MyAppTheme">
</application>
</manifest>
This will disable multi-touch throughout the application.

Related

Android 12 Splash Screen Icon Not Displaying

I am seeing a weird issue with a new app that I am starting. I am utilizing the new Android 12 splash screen API to create my splash screen and I followed the guide provided by Google to do so. I included core-splashscreen in my project to provide compatibility with older versions of Android OS. When I run the app, I see the splash screen as expected on older OS versions like API 30, but when I run it on API 31, the splash screen icon that I provide is not displayed. The background color that I specify is displayed, but the icon is not there at all. I have tried this with a drawable asset as well as a mipmap and nothing is working. I am stumped as every tutorial I find shows the same steps I have followed and screenshots of their working splash screens, but I am not having any luck.
For context here is my splash screen style definition for v31:
<style name="Theme.Splash" parent="Theme.SplashScreen">
<item name="android:windowSplashScreenBackground">#color/orange_7A</item>
<item name="android:windowSplashScreenAnimatedIcon">#drawable/splash_foreground</item>
<item name="postSplashScreenTheme">#style/Theme.App</item>
</style>
I have an identical style for all other OS versions except I'm using "windowSplashScreenAnimatedIcon" instead of "android:windowSplashScreenAnimatedIcon". I have tried v31 with and without the "android:" in front of the item names and neither work. Here is my MainActivity.kt:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
setContent {
MyVeevaTheme {
Login()
}
}
}
I am also setting the "android:theme" property to my splash style in my AndroidManifest.xml. I know the splash style is being applied because it honors the background color, but it is not showing the icon for some reason even though the icon shows fine for older OS versions. Thanks in advance for any help you can give.
TL;DR kill the app and run from the launcher, icon does not show up when run from Android Studio.
Adding my comment here as an answer for better visibility.
I did figure out how to get it to show. I was following this tutorial to set up a base project to recreate the issue and I noticed the note the author put right near the bottom that mentions that just running the app doesn't show the full splash screen. You have to kill it and open the app from the launcher. Once I did that, I was able to see my splash screen. Annoying, but at least I have a way to test it now. I did go ahead and log a bug report for this as well, but I have a work around for now. Thanks for everyone's answers/comments!
folks as per the document installSplashScreen() should have been called prior to super.onCreate()
When you use the AndroidX SplashScreen Library, like you are doing (Theme.SplashScreen) you need to use the windowSplashScreen* attributes without the android: prefix.
The android: prefix is used to call the platform attributes, but in this case you are using the library and not the platform, so no need for the prefix:
res/values/themes.xml:
<style name="Theme.Splash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#color/orange_7A</item>
<item name="windowSplashScreenAnimatedIcon">#drawable/splash_foreground</item>
<item name="postSplashScreenTheme">#style/Theme.App</item>
</style>
For some reason when the app is launched through android studio it doesn't show the icon. Kill the app and launch app from the menu. Then the icon will appear.
This is true if you are not using Splash API: https://developer.android.com/develop/ui/views/launch/splash-screen/migrate
Icons are also not shown when navigating from the deeplink.
And It looks like its more then only not showing the icon. It also stops calling code for setOnExitAnimation lambda.
installSplashScreen().apply {
setOnAnimationListener { viewProvider ->
viewProvider.iconView
.animate()
.setDuration(500L)
.alpha(0f)
.withEndAnimation {
viewProvider.remove()
someActionCall()
}
.start()
}
If you relied upon this code to be always called it is not.
See mention in issue tracker: https://issuetracker.google.com/issues/207095799
The following instructions helped me, you may try this one. A few things need to keep in mind while working with the new splash screen API.
Keep updated on the latest library version. Follow this link (https://developer.android.com/jetpack/androidx/releases/core).
Put installSplashScreen() before setContentView()
Make a proper theme for the splash screen. You may try the following one.
Put this into your styles.xml or themes.xml folder and use it with your activity as the theme.
<!-- Splash Screen Theme. -->
<style name="Theme.AppSplash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#color/white</item>
<item name="windowSplashScreenAnimatedIcon">#mipmap/ic_launcher_round</item>
<item name="windowSplashScreenAnimationDuration">1000</item>
<item name="postSplashScreenTheme">#style/AppTheme</item>
</style>
Make sure you set the theme to the MainActivity as well. For me that was the cause for the splash screen to now show. So you have to set the theme in both the application and the MainActivity
In addition to the other explanations above, I had the same issue but I realized that in my Manifest file I was setting the Splashscreen theme on my MainActivity which is correct, but my MainActivity was not having the main/launcher intent-filter which tells the android OS that this is the starting activity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
So in your manifest, check that you are actually setting the Splashscreen theme on the Starting activity that is having the main/launcher intent-filter, and leave the Application tag to have your application theme and not the Splashscreen theme, to avoid having your app misbehave on other activities due to the theme because I experienced that too (This is especially for those migrating to the new splash screen).
Thank you, I hope someone finds this helpful
I had the same problem on my phone running Android 12. None of the above suggestions worked, (moving installSpashScreen() above super.onCreate etc...)
What fixed it for me was adding the android:theme attribute in the manifest to the Launching <activity> Tag, Not the <application> Tag, which is contrary to the documentation :
In the manifest, replace the theme of the starting activity to the theme you created in the previous step.
<manifest>
<application android:theme="#style/Theme.App.Starting">
<!-- or -->
<activity android:theme="#style/Theme.App.Starting">
Note, you still have to kill the activity and launch it from the launcher for this to work :(
In my case, the problem with the lack of a splash screen was the installation of the default activity theme:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:name=".App"
android:theme="#style/Theme.Tracker.StartSplashScreen"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
tools:targetApi="tiramisu">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="#style/Theme.Tracker"> <-------
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
When I deleted android:theme="#style/Theme.Tracker" line, it started working.

Android Studio Layout Preview Default Theme

Maybe this is well known option in Android Studio but I couldn't find it and Google has not helped me with this :( Every time I open a layout preview in Android Studio it's applying Material.Light theme to every layout in my project and I need manually apply my own theme to see how it will look like in a real app. Does somebody know how to change default Material.Light theme to be my custom theme when previewing layout with Layout Previewer in Android Studio so I don't need to apply it manually every time?
Thanks in advance.
Click here and change theme to your theme.
If you want a single theme to always open, give
android:theme="#style/YourTheme" in your <application> tag in Manifest file.
From next time onwards, when you create a new xml file, this will be your default theme.
You need to provide default theme on application tag in AndroidManifest.xml file. If you don't provide android:theme="#style/{themeName} there will be added Material.Light default theme.
Please check example of code snippet from my manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage.iqall" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/iqall_main"
android:label="#string/app_name"
android:logo="#drawable/logo"
android:theme="#style/AppTheme" <!--in Preview you will see this as default preview-->
android:name=".IQallApp">
</application>
</manifest>
In all your manifests (in all modules), set
<application android:theme="#Theme/mainTheme">
</application
If you use Splashscreen theme (official way)
in your App module,
<application
android:theme="#style/SplashTheme"
tools:replace="android:theme">
</application>
AND RESTART Android Studio (very important)

Appcelerator Titanium: Open activity without animation

In Titanium Alloy I'm trying to open a controller which is a Window without animation.
What I've done is define a new style inside /platform/android/res/values/activity_no_animation.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.NoAnimation" parent="android:Theme">
<item name="android:windowAnimationStyle">#null</item>
</style>
</resources>
my controller filename is login.js, so in my tiapp.xml I've defined the activity like this (as explained here: http://docs.appcelerator.com/titanium/latest/#!/guide/tiapp.xml_and_timodule.xml_Reference-section-29004921_tiapp.xmlandtimodule.xmlReference-activities)
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<application android:theme="#style/Theme.NoActionBar">
<activity url="login.js" android:theme="#style/Theme.NoAnimation" />
</application>
<!-- Need to specify at least API level 11 for Titanium SDK 3.2.x and prior -->
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19"/>
</manifest>
</android>
but when the app starts, after the splash screen I still see the activity animation. What I would expect is for the activity (window) to just show up.
what am I missing here?
For some strange reasons you cannot override all animations inside Titanium.
I've asked this question over here with no success.
I've tried patching ti mobile source code and making a custom build. As far as I could get was to disable the opening animation. Closing animation was still playing on some devices.
I found this by working backwards from SDK code, but when calling Ti.UI.Window.open() to actually open the window, supply the animated property set to false:
win = Ti.UI.createWindow(/* ... */);
win.open({ animated: false });
I'm not familiar with Alloy, but this should be reasonably easy to translate into Alloy.
This works at least in SDK 5.0.2.

How to "push up" the screen when soft keybord is displayed

I have in my LibGDX android application a table, below some textfields (one row) and a button below (Submit).
My question is, how to "slide" up the table, textfiels and the button when the textfield is focuses (click on it) and the soft keyboard is appearing?
In other words, how to make the soft keyboard not to cover my other objects.
This solution might be related with this question:
How can i find the height of soft-keyboard in a LibGDX application
Many thanks.
I found an workaround for my problem, it's working, but I don't think is too clean.
So, my scenario was:
a container table, containing a ScrollPane (another table), under this scrolling table two TextFields and under them a Submit button
container table set to fill parent (full screen)
the text fields and the button aligned to the bottom of the container table
The problem was that when the OnscreenKeybord was visible, it covered the bottom objects (text fields and button) and a part of the scrolling table.
My solution / workaround is:
keyboard = new OnscreenKeyboard() {
#Override
public void show(boolean visible) {
Gdx.input.setOnscreenKeyboardVisible(visible);
// Hmmmm...
container.invalidate();
if (visible) {
// TODO get OsK height somehow!!!
container.padBottom(310);
} else {
container.padBottom(0);
}
}
};
textFld1.setOnscreenKeyboard(keyboard);
textFld2.setOnscreenKeyboard(keyboard);
and on the InputListener of the Submit button (on touchDown) I have a cleanup function like:
textFld1.setText("");
textFld2.setText("");
stage.unfocus(textFld1);
stage.unfocus(textFld2);
keyboard.show(false);
In this way the container table will be padded up when the soft keyboard is displayed and it will be restored after the submit button is pressed; also the soft keyboard is hidden.
Now, there are two problems with this workaround:
I have not found a way to get the soft keyboard height; as you can see in the sample code I have chosen an arbitrary value for the up padding, so the tings to look good on my emulator
if hard button Back or ESC in emulator is pressed, the soft keyboard will hide, but the up-padding of the table will still be there; I didn't find how to determine if the soft keyboard is visible or not
If anyone finds another solution for my problem, please post it.
Thanks.
i was totally wrestling with this problem too, but i think i found a really nice solution.
Solution in theory:
when the keyboard pops up, it makes the screen resize, thus calling libgdx's resize callback.
Advantages:
no need to have logic having to do with keyboard visibility detection
no need to get height of keyboard
handle everythin in the resize callback of the libgdx's screen class
simple to implement (i think)
Disadvantages
app can no longer be fullscreen; the status bar shows and things
How to do it:
Create a main_layout.xml file, (....YourLibGdxThing\android\res\layout\main_layout.xml) such that has the following XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/main_frame_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
modify your android launcher class (....YourLibGdxThing\android\src\your\name\space\android\AndroidLauncher.java) such that the onCreate looks like this:
public class AndroidLauncher extends AndroidApplication
{
#Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.main_frame_layout);
frameLayout.addView(initializeForView(new YourGame(),config));
}
}
change android:windowFullScreen attribute in the style.xml (....YourLibGdxThing\android\res\values\styles.xml) to false; the XML should look like this in style.xml:
<resources>
<style name="GdxTheme" parent="android:Theme">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowFullscreen">false</item> <!-- IMPORTANT -->
</style>
</resources>
add the attribute android:windowSoftInputMode="adjustResize" to the android manifest, into the activity tag...my AndroidManifest (....YourLibGdxThing\android\AndroidManifest.xml) looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.project.reverse.domain.thing"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="my.project.reverse.domain.thing.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" <!-- IMPORTANT -->
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Thanks! I hope it helps!!!!!!!!!!
Set android:windowSoftInputMode to adjustPan in your <activity> block to get the result you want. See docs: https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

Removing Title Bar in Android 2.3 (Gingerbread) causes problem with SurfaceView

Anyone experiencing a problem with their app in Gingerbread? -- if you use
requestWindowFeature(Window.FEATURE_NO_TITLE);
And you switch to another window, when you come back it changes the dimensions of the surfaceview.
For now, I've put the titlebar back in to work around this issue.
Thanks for any help
Mark
Yes, we too have experienced this after updating to Android 2.3.4. To fix it in our apps we eliminated the requestWindowFeature(Window.FEATURE_NO_TITLE); in our apps and then utilized a styles.xml, saved in the project's values folder with the following:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="#android:style/Theme.Translucent.NoTitleBar.Fullscreen">"
<item name="android:windowBackground">#color/background</item>
</style>
Here a colors.xml will be utilized to set the #color/background, which is also saved in the project's value folder with the following:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<color name ="background">#000000</color>
</resources>
Then in the manifest file we utilized:
<application android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#style/Theme.Transparent"
>
to apply the theme to the application as a whole. Perhaps others will have better suggestions and also maybe a reason for why this occurs in Gingerbread as in Froyo the requestWindowFeature(Window.FEATURE_NO_TITLE); worked well with SurfaceViews.

Categories

Resources