Example usage for android.app Dialog setCanceledOnTouchOutside

List of usage examples for android.app Dialog setCanceledOnTouchOutside

Introduction

In this page you can find the example usage for android.app Dialog setCanceledOnTouchOutside.

Prototype

public void setCanceledOnTouchOutside(boolean cancel) 

Source Link

Document

Sets whether this dialog is canceled when touched outside the window's bounds.

Usage

From source file:org.catrobat.catroid.ui.dialogs.CustomIconContextMenu.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final String menuTitle = getArguments().getString(BUNDLE_ARGUMENTS_MENU_TITLE);

    Dialog dialog = new AlertDialog.Builder(getActivity()).setTitle(menuTitle)
            .setIcon(R.drawable.ic_dialog_menu_generic)
            .setAdapter(menuAdapter, new DialogInterface.OnClickListener() {
                @Override/*from ww  w . j  a  v  a 2 s  .com*/
                public void onClick(DialogInterface dialoginterface, int position) {
                    CustomContextMenuItem item = (CustomContextMenuItem) menuAdapter.getItem(position);

                    if (clickListener != null) {
                        clickListener.onClick(item.contextMenuItemId);
                    }
                }
            }).setInverseBackgroundForced(true).create();

    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            dismiss();
        }
    });

    return dialog;
}

From source file:org.catrobat.catroid.ui.dialogs.MultiLineTextDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_text_multiline_dialog, null);
    input = (EditText) dialogView.findViewById(R.id.dialog_text_EditMultiLineText);

    if (getHint() != null) {
        input.setHint(getHint());/* ww w  .  j a va  2 s .co m*/
    }

    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                getDialog().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    initialize();

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle())
            .setNegativeButton(R.string.cancel_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();

    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            if (getDialog() == null) {
                dismiss();
            } else {
                Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
                buttonPositive.setEnabled(getPositiveButtonEnabled());

                setPositiveButtonClickCustomListener();

                InputMethodManager inputManager = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);

                initTextChangedListener();
            }
        }
    });

    return dialog;
}

From source file:com.eng.arab.translator.androidtranslator.activity.NumberViewActivity.java

public void displayDialog(String vid) {
    if (getResources().getIdentifier(vid, "raw", getPackageName()) == 0) {
        /* TEST if RAW file doesn't exist then do nothing*/
    } else {/*from  w w  w . j av a  2 s . c o m*/
        final Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
        dialog.setContentView(R.layout.number_video_view);
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(true);

        mVideoView = (VideoView) dialog.findViewById(R.id.videoView);
        mVideoView.setZOrderMediaOverlay(true);
        String path = "android.resource://" + getPackageName() + "/" + //R.raw.alif;
                getResources().getIdentifier(vid, "raw", getPackageName());

        FrameLayout fl = (FrameLayout) dialog.findViewById(R.id.VideoFrameLayout);
        ImageButton imageButtonClose = (ImageButton) fl.findViewById(R.id.imageButtonClose);
        imageButtonClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //dialog.dismiss();
                if (v.getId() == R.id.imageButtonClose) {
                    dialog.dismiss();
                }
            }
            // Perform button logic
        });

        // Set the media controller buttons
        if (mediaController == null) {
            mediaController = new MediaController(NumberViewActivity.this);

            // Set the videoView that acts as the anchor for the MediaController.
            mediaController.setAnchorView(mVideoView);

            // Set MediaController for VideoView
            mVideoView.setMediaController(mediaController);
        }

        mVideoView.setVideoURI(Uri.parse(path));
        mVideoView.requestFocus();

        // When the video file ready for playback.
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            public void onPrepared(MediaPlayer mediaPlayer) {
                mVideoView.seekTo(position);
                if (position == 0) {
                    mVideoView.start();
                }
                // When video Screen change size.
                mediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
                    @Override
                    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {

                        // Re-Set the videoView that acts as the anchor for the MediaController
                        mediaController.setAnchorView(mVideoView);
                    }
                });
            }
        });
        dialog.show();
    }
}

From source file:org.tigase.mobile.chat.ChatHistoryFragment.java

private void showMessageDetails(final long id) {
    Cursor cc = null;/*from w w w . ja  v  a  2  s.c  o m*/
    final java.text.DateFormat df = DateFormat.getDateFormat(getActivity());
    final java.text.DateFormat tf = DateFormat.getTimeFormat(getActivity());

    try {
        cc = getChatEntry(id);

        Dialog alertDialog = new Dialog(getActivity());
        alertDialog.setContentView(R.layout.chat_item_details_dialog);
        alertDialog.setCancelable(true);
        alertDialog.setCanceledOnTouchOutside(true);
        alertDialog.setTitle("Message details");

        TextView msgDetSender = (TextView) alertDialog.findViewById(R.id.msgDetSender);
        msgDetSender.setText(cc.getString(cc.getColumnIndex(ChatTableMetaData.FIELD_JID)));

        Date timestamp = new Date(cc.getLong(cc.getColumnIndex(ChatTableMetaData.FIELD_TIMESTAMP)));
        TextView msgDetReceived = (TextView) alertDialog.findViewById(R.id.msgDetReceived);
        msgDetReceived.setText(df.format(timestamp) + " " + tf.format(timestamp));

        final int state = cc.getInt(cc.getColumnIndex(ChatTableMetaData.FIELD_STATE));
        TextView msgDetState = (TextView) alertDialog.findViewById(R.id.msgDetState);
        switch (state) {
        case ChatTableMetaData.STATE_INCOMING:
            msgDetState.setText("Received");
            break;
        case ChatTableMetaData.STATE_OUT_SENT:
            msgDetState.setText("Sent");
            break;
        case ChatTableMetaData.STATE_OUT_NOT_SENT:
            msgDetState.setText("Not sent");
            break;
        default:
            msgDetState.setText("?");
            break;
        }

        alertDialog.show();
    } finally {
        if (cc != null && !cc.isClosed())
            cc.close();
    }
}

From source file:com.sastra.app.timetable.TimetableActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case 0:/*from w  w  w. jav  a 2  s.  co m*/
        startActivityForResult(intent, 0);
        break;
    case 1:
        action = "insert";
        data.open();
        ArrayList<HashMap<String, Object>> arrayS = data.selectSubjects2();
        data.close();
        arraySubjects = new String[arrayS.size()];
        colo = new String[arrayS.size()];

        Iterator<HashMap<String, Object>> it = arrayS.iterator();
        int i = 0;
        while (it.hasNext()) {
            HashMap<String, Object> hm = it.next();
            arraySubjects[i] = hm.get("SName").toString();
            colo[i] = hm.get("SColor").toString();
            Log.d("AB", "This is inside the onOptionsItemSelected Function :485");
            Log.d("AB", arraySubjects[i]);
            Log.d("AB", colo[i]);
            i++;
        }

        newSpinnerAdapter ma = new newSpinnerAdapter(TimetableActivity.this, R.id.text1, arraySubjects);
        SName.setAdapter(ma);

        //mySpinnerAdapter msa = new mySpinnerAdapter(this,arrayS,R.layout.timetable_spinner_layout,from2, to2,colo );
        //msa.setDropDownViewResource(R.layout.timetable_spinner_layout);
        //  SName.setAdapter(msa);

        addDialog.setTitle("Add Class");
        addDialog.show();

        //                  data.open();
        //                  results2 = data.selectSubjects2();
        //                  data.close();
        //                  colorVet2 = new String[results2.size()];
        //                  for(int i=0;i<results2.size();i++) {
        //                     HashMap<String, Object> color = new HashMap<String, Object>();
        //                     
        //                     color = results2.get(i);
        //                     colorVet2[i] = (String) color.get("SColor");
        //                  }
        //                   

        // Sarrayadapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, arraySubjects);
        //Sarrayadapter = new ArrayAdapter<String>(this,R.layout.timetable_spinner_layout, arraySubjects);
        //Sarrayadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        break;
    case 2:
        alert.show();
        break;
    case 3:

        Dialog d = new Dialog(this);
        d.setCanceledOnTouchOutside(true);
        d.setTitle("ABOUT");
        TextView tv2 = new TextView(this);
        tv2.setText(
                "This application was developed by R.R.Arun Balaji,a student of SASTRA University.Special Thanks to J.Sivaguru from SASTRA.\n\nLICENSE INFORMATION : \nSASTRA TimeTable\nThis program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for more details.This program makes use of the following libary ViewPageIndicator licensed under Apache License 2.0 and modifies the StudentTimeTable application made by Mazzarelli Alessio and Hopstank,distributed under GNU GPL v3.");
        ScrollView sv = new ScrollView(this);
        sv.addView(tv2);
        LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        d.addContentView(sv, lp);
        d.setTitle("About");
        d.show();
        break;
    case 4:
        Dialog d2 = new Dialog(this);
        d2.setTitle("HELP");
        d2.setCanceledOnTouchOutside(true);
        TextView tv = new TextView(this);
        tv.setText(
                "This application can be used to store your timetable.\nFirst,click on Manage Subjects Icon(Wrench Icon) inorder to add all your subjects.Click on Add Subjects on top and enter the details of your subject.The fields that appear are optional and not manditory.\n\nOnce you have added all the subjects,go back to the main screen and click on Add Classes icon(Plus Icon) to add the different classes to your timetable.The fields that appear are again optional and all of them need not be filled.You can long press on any particular subject to edit or delete them.You can delete all the informations using Delete All(Garbage Icon) option.");
        ScrollView sav = new ScrollView(this);
        sav.addView(tv);
        LayoutParams lap = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        d2.addContentView(sav, lap);
        d2.show();
        break;

    }
    return false;
}

From source file:hku.fyp14017.blencode.ui.dialogs.DeleteLookDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final int selectedPosition = getArguments().getInt(BUNDLE_ARGUMENTS_SELECTED_POSITION);

    Dialog dialog = new CustomAlertDialogBuilder(getActivity())
            .setTitle(hku.fyp14017.blencode.R.string.delete_look_dialog)
            .setNegativeButton(hku.fyp14017.blencode.R.string.cancel_button, new OnClickListener() {
                @Override//from   w ww  .ja  va  2s .  c om
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(hku.fyp14017.blencode.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    handleDeleteLook(selectedPosition);
                }
            }).create();

    dialog.setCanceledOnTouchOutside(true);

    return dialog;
}

From source file:hku.fyp14017.blencode.ui.dialogs.DeleteSoundDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final int selectedPosition = getArguments().getInt(BUNDLE_ARGUMENTS_SELECTED_POSITION);

    Dialog dialog = new CustomAlertDialogBuilder(getActivity())
            .setTitle(hku.fyp14017.blencode.R.string.delete_sound_dialog)
            .setNegativeButton(hku.fyp14017.blencode.R.string.cancel_button, new OnClickListener() {
                @Override/*from   www. j av a2  s .  c o m*/
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(hku.fyp14017.blencode.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    handleDeleteSound(selectedPosition);
                }
            }).create();

    dialog.setCanceledOnTouchOutside(true);

    return dialog;
}

From source file:hku.fyp14017.blencode.ui.dialogs.MultiLineTextDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity())
            .inflate(hku.fyp14017.blencode.R.layout.dialog_text_multiline_dialog, null);
    input = (EditText) dialogView.findViewById(hku.fyp14017.blencode.R.id.dialog_text_EditMultiLineText);

    if (getHint() != null) {
        input.setHint(getHint());/*from w  w  w  .j  a  v a 2s . co m*/
    }

    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                getDialog().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    initialize();

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle())
            .setNegativeButton(hku.fyp14017.blencode.R.string.cancel_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(hku.fyp14017.blencode.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();

    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
            buttonPositive.setEnabled(getPositiveButtonEnabled());

            setPositiveButtonClickCustomListener();

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);

            initTextChangedListener();
        }
    });

    return dialog;
}

From source file:com.haibison.android.anhuu.utils.ui.bookmark.BookmarkFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (BuildConfig.DEBUG)
        Log.d(CLASSNAME, "onCreateDialog()");

    Dialog dialog = new Dialog(getActivity(),
            UI.resolveAttribute(getActivity(), R.attr.anhuu_f5be488d_theme_dialog));
    dialog.setCanceledOnTouchOutside(true);
    dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
    dialog.setTitle(R.string.anhuu_f5be488d_title_bookmark_manager);
    dialog.setContentView(initContentView(dialog.getLayoutInflater(), null));
    dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.anhuu_f5be488d_bookmarks_dark);

    return dialog;
}