How to hide toast message from TalkBack for some reason - android

For accessibility demo purpose, I’m creating android example app.
By the way, during creating bad example accessibility, I have a question about toast issue. By default, every time toast is showing, TalkBack read the toast and it is very good.
But sometimes I want to hide toast from TalkBack so that TalkBack won’t read the toast message. Of course TalkBack must read all toast messages in order to give same information with none screen reader users. But sometimes in some apps, too many toast messages are appeared on screen and even the same message is stayed on screen.
So in that case TalkBack says too much and even TalkBack won’t read the toast, blind users can read the message that toasted through swiping.
Also the toast message is not alert text. So in some cases, I think hiding toast from TalkBack is needed.
But I don’t know how to do this. I set one view in java and added toast message. And then I set importantForAccessibility to NO, but it doesn’t work.
My code is below.
Lastly, I referred as the stack that customizing TalkBack toast.
Thank you.
imgClick2 = (ImageView)findViewById(R.id.imageView2);
imgClick2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast toast = new Toast(MainActivity.this);
TextView messageView = new TextView(MainActivity.this);
messageView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
messageView.setText("visible text");
toast.setView(messageView);
toast.show();
}
});

Related

Android 13: FLAG_SECURE toast message is not showing

Our app does not allow screen capture, so below code is used:
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
}
Whenever user tried to capture, some toast message from OS will show up like this: "Unable to capture screen, DRM protected image."
But the things is, starting from Android 13, toast message doesn't show up. It just showing black blocked captured image at the left bottom corner.
Is there any way to display the user friendly message or toast?
It is totally OS dependent thing. Nothing developer can do.
Not suitable for my case, but there's useful link using ContentObserver.
https://proandroiddev.com/detect-screenshots-in-android-7bc4343ddce1

Image icon within Toast maketext message

I am beginning learning some android mobile development and have created a notepad app through some tutorials and am now wanting to customise it a little.
I currently have a Toast maketext message that displays when a user saves a new note. The code is as follows:
if(Utilities.saveNote(this, new Note(mNoteCreationTime, title, content)))
Toast.makeText(this, "Swag Note has been saved", Toast.LENGTH_SHORT).show();
What I am wanting to do is add a small icon at both ends of this toast message.
Is there a relatively simple way of achieving this?
Toasts cannot have icons. You can create a custom Toast with ImageViews in it (example). However, there might be an unicode symbol that suits your purpose: in that case, you can just paste it.
Edit:
To make the linked example work, you'd just have to add a View for the image with id "toast_image", which will be invoked this way:
ImageView image = (ImageView) layout.findViewById(R.id.toast_image);
Show Toast as you do it now:
Toast.makeText(this, "Swag Note has been saved", Toast.LENGTH_SHORT).show();
Show MyToast from linked example:
MyToast.show(this, "Swag Note has been saved", false);

android- How to prevent enter key/click coming from barcode scanner

Hello I have an application which I got entries by barcode scanner. I use Zebra TC56 as testing device.
I need to show a warning message to the user and that is why I have a custom dialog box.
Dialog box is being showed when user gets an error. Picture of my dialog box can be seen here :
Below red part is a button and when button is clicked , dialog box will be closed and user will turn the latest screen.
Everything works fine but there is somethin I dont want. When user scans a barcode(enters data) button is trigered and dialog box is closed.
I want dialog box to be closed only by clicking the button(TAMAM) from the screen. But when I scan anything, dialog box is closed.
Here is the code of the dialog box class :
public class ViewDialog {
public void showDialog(Activity activity, String msg){
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.customdialog);
TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
text.setText(msg);
Button dialogButton = (Button) dialog.findViewById(R.id.btn_dialog);
dialogButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
I tried to get focus to somewhere except the button(TAMAM) but it didnt help. If someone knows how to dismiss enter key from the barcode scanner, I really need some help and will be appreciated. (I already set the device to send Enter key because I need in other screens)
Few ways to do this that I can think of.
Firstly, I presume you are using DataWedge to automatically append the enter key to scanned data, you could dynamically switch to a profile which did not send the enter key but was identical in every other way using the SWITCH_PROFILE API: http://techdocs.zebra.com/datawedge/6-3/guide/api/switchtoprofile/. This is presuming that you still need to be able to scan when the dialog is visible, if you wish to disable scanning entirely you could use the SCANNER_INPUT_PLUGIN API: http://techdocs.zebra.com/datawedge/6-3/guide/api/scannerinputplugin/.
Secondly, you could use the EMDK profile API to change the parameters of the KeyStroke output plugin (http://techdocs.zebra.com/emdk-for-android/6-3/mx/data-capture/keystroke/#keystrokeoutput) then apply that newly modified profile. I've never tried that myself but it should work - check out the following sample for the principles behind that: http://techdocs.zebra.com/emdk-for-android/6-3/samples/data-capture/
Thirdly, you could use the Java SDK for the scanner which gives you more control over how the scanner behaves (http://techdocs.zebra.com/emdk-for-android/6-3/api/)

Mono Droid Modal Popup

I am wondering how I go about (if it is possible) creating a modal popup in a mono for droid application.
Scenario: The application talks to the customers hosted web server (so this location will be different customer to customer). To use the app the user must specify the connection string of their web server. So when the application starts and it hits the main activity, the first task I do is check if there is a connection string set in the devices application settings. If not I want to throw up a simple modal popup that allows the user to specify a connection to their server.
I dont really want to start a normal activity because the user will be able to click the back button and just go back to the main menu and the app is than in an invalid state because it doesnt know what server to talk to.
Any ideas on how I go about this?
Or should I be structuring the activity chain so that the connection string is entered on the first activity so that if they click back it actually goes out of the app?
Im a little confused.
Thanks in advance
This is possible with AlertDialog. It can create dialogs for simple input with lists, checkboxes, yes/no buttons and custom views.
There is a sample in the Xamarin Sample Repository for different type of dialogs and in the bottom you can find one where a custom view with a username and password field has been added.
So first define your custom view you want to put in the AlertDialog. alert_dialog_connection_entry.xml and is a Layout:
Somewhere in your activity add the code:
var connection_string_view = LayoutInflater.Inflate(Resource.Layout.alert_dialog_connection_entry, null);
var builder = new AlertDialog.Builder(this);
builder.SetTitle("Connection String");
builder.SetView(connection_string_view);
builder.SetPositiveButton("OK", OkClicked);
builder.SetNegativeButton("Cancel", CancelClicked);
builder.Create();
builder.Show();
Add some handlers for the buttons:
private void CancelClicked(object sender, DialogClickEventArgs dialogClickEventArgs)
{
//Todo
}
private void OkClicked(object sender, DialogClickEventArgs dialogClickEventArgs)
{
var dialog = sender as AlertDialog;
if (null != dialog)
{
var connectionEdit = dialog.FindViewById(Resource.Id.connectionstring_edit) as EditText;
if (null != connectionEdit)
Console.WriteLine("Connection String: {0}", connectionEdit.Text);
}
}
That should be it. You should be able to put any kind of custom view in the dialog.
If you just want to display a modal popup for letting users put their connection string, you could try this.
First, you need to have a simple layout for how the dialog is presented. In this case, a TextView displaying something like "Connection string:" and an EditText to let the user put connection string is probably enough to go.
Then, you can put this code somewhere in your MainActivity, like after checking application settings or something similar.
var builder = new AlertDialog.Builder(this);
var view = LayoutInflater.Inflate(Resource.Layout.ModalDialog, null);
builder.SetView(view);
string connectionString = view.FindViewById<EditText>(Resource.Id.ConnectionString).Text;
AlertDialog alert = builder.Create();
alert.SetCancelable(false); //This prevents the dialog from being dismissed by either hit back button or hit out side of the dialog
alert.SetButton("OK", (s,e)=> ToDo(connectionString)); //Now you have the connection string, to do whatever you want.
alert.Show();
As you said, the alternative could be allowing user specify the connection string in the first screen. This is a good approach too. I assume you know how to do it, so I didn't post code here.

Suppressing toast from package in Android

I'm developing an Android app and I'm trying to show some information with a Toast.
I used Toasts in other projects and everything works, but in this app, when the Toast should appear, it doesn't do it and Logcat shows the next message:
Suppressing toast from package com.xxxxxxx by user request.
I'm creating the toast with the next code:
Context context = xxxxxxx.this;
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
I tried to set the context with getApplicationContext() and getBaseContext() too, but doesn't work.
Anyone knows how to solve this problem?
Thank you very much.
Go to the App-Info Screen of your application ( long click on the app and drag it to the top in Android 4.0) and make sure the "Show notification" checkbox is selected. Otherwise your Toasts will be suppressed.

Categories

Resources