5

I am alerting the user after some action and showing alert dialog but when accessibility is on it is not reading full alert dailog header and body. It is reading only header. I found this issue in samsung galaxy s5. Please help me solving this issue.

public class TransactionDialog extends DialogFragment {

private int _state = -1;
private final String TITLE = "TITLE";
private final String MESSAGE = "MESSAGE";
private final String POS_TEXT = "POS_TEXT";     
private final String STATE = "STATE";
private int _title = 0;
private int _message = 0;
private int _positiveText = 0;  
private NoticeDialogListener mListener;
Logger logger = Logger.getNewLogger("com.ui.TransactionDialog");
boolean actionPerformed = false;    
AlertDialog dialog = null;

public TransactionDialog() {

}

public void setListener(NoticeDialogListener listener) {
    this.mListener = listener;
}

public TransactionDialog(int title, int message, int positiveText, int state) {
    this._title = title;
    this._message = message;
    this._positiveText = positiveText;
    this._state = state;
}

public int getState() {
    return _state;
}

@Override
public void onSaveInstanceState(Bundle outState) {
    // TODO Auto-generated method stub
    super.onSaveInstanceState(outState);
    outState.putInt(TITLE, this._title);
    outState.putInt(MESSAGE, this._message);
    outState.putInt(POS_TEXT, this._positiveText);  
    outState.putInt(STATE, this._state);
}

@Override
public void onResume() {
    super.onResume();
    logger.debug("TITLE:" + this._title);
    logger.debug("_message:" + this._message);
    logger.debug("_positiveText:" + this._positiveText);        
    logger.debug("_state:" + this._state);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    logger.debug("Created");
}

@Override
public void onDismiss(DialogInterface dialog) {
    // TODO Auto-generated method stub
    super.onDismiss(dialog);
    mListener.onDialogDismissed();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    logger.debug("ON CREATE");

    if (savedInstanceState != null) {
        this._title = savedInstanceState.getInt(TITLE);
        this._message = savedInstanceState.getInt(MESSAGE);
        this._positiveText = savedInstanceState.getInt(POS_TEXT);   
        this._state = savedInstanceState.getInt(STATE);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());       
    builder.setTitle(getResources().getString(this._title))
            .setMessage(getResources().getString(_message))             
            .setPositiveButton(getResources().getString(_positiveText), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {   
                    if(actionPerformed) 
                        return;
                    actionPerformed = true;
                    mListener.onDialogPositiveClick(TransactionDialog.this);                                
                }
            });     



    dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);        
    dialog.show();

    dialog.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                mListener.onDialogPositiveClick(TransactionDialog.this);        
            }
            return false;
        }
    });

    return dialog;
}



@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    // Verify that the host activity implements the callback interface
    try {
        // Instantiate the NoticeDialogListener so we can send events to the
        // host
        mListener = (NoticeDialogListener) activity;
    } catch (ClassCastException e) {
        // The activity doesn't implement the interface, throw exception
        throw new ClassCastException(activity.toString()
                + " must implement NoticeDialogListener");
    }

}

public interface NoticeDialogListener {
    public void onDialogPositiveClick(DialogFragment dialog);

    public void onDialogDismissed();
}}

Here i am using the txndialog class for creating the alert dialog.

private TransactionDialog transactionDialog;
    transactionDialog = (TransactionDialog) newTransactionFrgment;
            transactionDialog.setListener(this);
 transactionDialog = new TransactionDialog(R.string.transaction_complete_header, R.string.transaction_complete_message,
                    R.string.transaction_complete_positive_button, STATE_SET_TRANSACION);
            transactionDialog.show(getFragmentManager(), TRANSACTION_DIALOG_TAG);
Rahul Hawge
  • 154
  • 4
  • 15
Nikhil PV
  • 1,014
  • 2
  • 16
  • 29
  • 1
    Post some of your code. Is it running fine in other devices? – Reaz Murshed May 02 '16 at 11:39
  • 1
    what you tried so far? post your code – Sathish Kumar J May 02 '16 at 11:39
  • `it is not reading full alert dailog header and body`. Do you mean complete dialog isn't shown, i.e some part is missing? Please elaborate and preferably update your question with a screenshot. – Sufian May 02 '16 at 11:57
  • Alert dialog is shown properly, but when accessibility is on it is not reading alert dialog body, it is reading only header of alert dialog. My issue is how to set content description for an alert dialog. – Nikhil PV May 02 '16 at 12:05
  • @Nikhil what do you mean by "reading"? Please add a screenshot for it. – Sufian May 03 '16 at 15:54
  • @Sufian that means, TalkBack is able to read only title not the dialog message – Rahul Hawge May 04 '16 at 09:48
  • Check out [this](http://stackoverflow.com/questions/25169273/accessibility-dialog-dialogfragment-reads-text-instead-of-content-description) and [this](http://stackoverflow.com/questions/16668296/set-contentdescription-for-a-custom-dialog) question. Have you tried testing with a different `message`? – Sufian May 04 '16 at 12:37
  • @RahulHawge and OP, if support library's `DialogFragment` is being extended, I think it might be causing this issue. Try using a different support library version and don't forget to clean-build, especially because the code seems to be written in Eclipse. If you succeed, please post an answer saying what steps you followed. Good luck! :) – Sufian May 05 '16 at 09:48
  • 1
    @Sufian I have found out that this issue is with lollipop device because the talkback(accessibility) is working fine with os version 4.3. – Rahul Hawge May 09 '16 at 06:47
  • @RahulHawge if it hasn't been fixed in later version (e.g Marshmallow) then it would be better if you open an issue at [Android issue tracker](https://code.google.com/p/android/issues/list). In you issue details, provide a sample code (preferably zipped project) and OS version on which this occurs. – Sufian May 09 '16 at 06:57

0 Answers0