Example usage for android.app Dialog setCancelable

List of usage examples for android.app Dialog setCancelable

Introduction

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

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:nz.co.android.cowseye2.activity.RecordLocationActivity.java

protected void setupManagers(Bundle savedInstanceState) {
    int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
    if (result != ConnectionResult.SUCCESS) {
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(result, this, 69);
        dialog.setCancelable(false);
        dialog.show();/*from   w  w w. j  a  v  a2 s .c o m*/
    }
    // setUpMapIfNeeded(savedInstanceState);
}

From source file:com.android2ee.tileprovider.activity.MainActivity.java

/**
 * Check if the device has the google play service available
 * @return//  w  w  w  . jav a  2s . c  o  m
 */
public boolean checkGooglePlayServicesAvailability() {
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                PLAY_SERVICES_RESOLUTION_REQUEST);
        dialog.setCancelable(false);
        dialog.show();
    }
    return resultCode == ConnectionResult.SUCCESS;
}

From source file:com.yammy.meter.MainActivity.java

private void showAlert() {
    final Dialog myDialog = new Dialog(this);
    myDialog.setContentView(R.layout.isvo_dialog_low_oil);
    myDialog.setCancelable(true);
    myDialog.setTitle("Peringatan!");
    Button batal = (Button) myDialog.findViewById(R.id.dialog_low_oil_cancel);
    Button cari = (Button) myDialog.findViewById(R.id.dialog_low_oil_cari);
    myDialog.show();//from  w  w w .j  a va2 s. co  m
    cari.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(MainActivity.this, MainCari.class);
            startActivity(i);
        }
    });
    batal.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            myDialog.cancel();
        }
    });
}

From source file:com.procleus.brime.ui.LabelsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    ((MainActivity) getActivity()).setActionBarTitle("Labels");
    ((MainActivity) getActivity()).showFloatingActionButton(true);
    final View v = inflater.inflate(R.layout.labels_gragment, container, false);
    final NotesDbHelperOld tn = new NotesDbHelperOld(getActivity());

    labelsRetrieved = new ArrayList<String>();
    labelsRetrieved = tn.retrieveLabel();

    listView = (ListView) v.findViewById(R.id.listLabel);
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(),
            android.R.layout.simple_list_item_1, labelsRetrieved);
    listView.setAdapter(arrayAdapter);/*from   w w w . ja v  a  2 s.  c  om*/
    ImageButton addLabelBtn = (ImageButton) v.findViewById(R.id.addLabelBtn);

    addLabelBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            addLabelFunc(v, tn);
        }
    });

    /*/WORK OF LONG ITEM CLICK LISTENER*/

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(final AdapterView<?> parent, View view, final int position, long id) {

            final Dialog dialog = new Dialog(getContext());
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.setCancelable(false);
            dialog.setContentView(R.layout.dialog_label);
            dialog.show();

            final Button negative = (Button) dialog.findViewById(R.id.btn_no_label);
            final Button positive = (Button) dialog.findViewById(R.id.btn_yes_label);

            negative.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    dialog.dismiss();

                }
            });

            positive.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Log.i("brinjal", "Yes");

                    tn.deleteTextNote(String.valueOf(parent.getItemAtPosition(position)));
                    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(),
                            android.R.layout.simple_list_item_1, labelsRetrieved);
                    listView.setAdapter(arrayAdapter);
                    dialog.dismiss();

                }

            });

            return true;

        }
    });

    return v;
}

From source file:com.procleus.brime.ui.LabelsFragment.java

@Override
public void onResume() {
    super.onResume();
    NotesDbHelperOld tn = new NotesDbHelperOld(getContext());
    labelsRetrieved = tn.retrieveLabel();
    listView = (ListView) getView().findViewById(R.id.listLabel);
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(),
            android.R.layout.simple_list_item_1, labelsRetrieved);
    listView.setAdapter(arrayAdapter);/*w ww.jav a 2s.  c o m*/

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(final AdapterView<?> parent, View view, final int position, long id) {

            final Dialog dialog = new Dialog(getContext());
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.setCancelable(false);
            dialog.setContentView(R.layout.dialog_label);
            dialog.show();

            final Button negative = (Button) dialog.findViewById(R.id.btn_no_label);
            final Button positive = (Button) dialog.findViewById(R.id.btn_yes_label);

            /*/This is Database Spinner Retreival*/
            /* Spinner getting Data from dataBase*/

            negative.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    dialog.dismiss();

                }
            });

            positive.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Log.i("brinjalResume", "Yes");

                    NotesDbHelperOld tn = new NotesDbHelperOld(getActivity());
                    tn.deleteTextNote(String.valueOf(parent.getItemAtPosition(position)));
                    labelsRetrieved = tn.retrieveLabel();
                    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(),
                            android.R.layout.simple_list_item_1, labelsRetrieved);
                    listView.setAdapter(arrayAdapter);
                    dialog.dismiss();
                }

            });

            return true;

        }
    });

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Toast.makeText(getActivity(),
                    "Inside in label" + ":" + String.valueOf(parent.getItemAtPosition(position)),
                    Toast.LENGTH_SHORT).show();
            Intent i = new Intent(getActivity(), LabelOpenActivity.class);
            i.putExtra("label", String.valueOf(parent.getItemAtPosition(position)));
            startActivity(i);

        }
    });

}

From source file:transapps.gpxfitness.ui.MainActivity.java

public void profileAlertDialog() {
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.profile_dialog);
    dialog.setTitle("Please Enter Profile:");
    dialog.setCancelable(false);

    Button ok_button = (Button) dialog.findViewById(R.id.button);
    ok_button.setText("Ok");
    final EditText username = (EditText) dialog.findViewById(R.id.username);
    final EditText height_ft = (EditText) dialog.findViewById(R.id.height_ft);
    final EditText height_in = (EditText) dialog.findViewById(R.id.height_in);
    final EditText weight_lbs = (EditText) dialog.findViewById(R.id.weight_lbs);
    final EditText age_yrs = (EditText) dialog.findViewById(R.id.age_yrs);
    final RadioButton male = (RadioButton) dialog.findViewById(R.id.male);
    final EditText[] et = { username, height_ft, height_in, weight_lbs, age_yrs };
    ok_button.setOnClickListener(new OnClickListener() {
        @Override/*from  w w  w  . j ava2 s  .co  m*/
        public void onClick(View v) {
            String user_string = username.getText().toString();
            String height_ft_string = height_ft.getText().toString();
            String height_in_string = height_in.getText().toString();
            String weight_lbs_string = weight_lbs.getText().toString();
            String age_yrs_string = age_yrs.getText().toString();
            boolean are_any_empty = false;
            for (EditText e : et) {
                String str = e.getText().toString();
                if (str == null || str.length() == 0)
                    are_any_empty = true;
            }
            if (!are_any_empty) {
                int height = Integer.parseInt(height_ft_string) * 12 + Integer.parseInt(height_in_string);
                String sex;
                if (male.isChecked())
                    sex = "male";
                else
                    sex = "female";
                ProfileAccessor.createNewProfile(user_string, height, Integer.parseInt(weight_lbs_string), sex,
                        Integer.parseInt(age_yrs_string));
                dialog.dismiss();
            }
        }
    });

    dialog.show();
}

From source file:de.hero.vertretungsplan.PrefsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    ListPreference listPref = (ListPreference) findPreference("prefs_benachrichtigungsintervall");
    listPref.setSummary(//from   w ww.  j ava2 s  . c  o  m
            getSummaryInterval(mySharedPreferences.getString("prefs_benachrichtigungsintervall", "1")));
    listPref.setOnPreferenceChangeListener(new ListPreference.OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            preference.setSummary(getSummaryInterval(newValue.toString()));

            MainActivity.setNewAlarm(getBaseContext(), true, newValue.toString());
            return true;
        }

    });

    Preference klasse = findPreference("prefs_klasse");
    klasse.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            showDialog(R.string.dialog_klasse);
            return true;
        }
    });

    CheckBoxPreference ckBxPref = (CheckBoxPreference) findPreference("prefs_benachrichtigungen");
    ckBxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals("prefs_benachrichtigungen")) {
                MainActivity.setNewAlarm(getBaseContext(), !((CheckBoxPreference) preference).isChecked(),
                        mySharedPreferences);
            }
            return true;
        }
    });

    CheckBoxPreference ckBxPrefAppUpdate = (CheckBoxPreference) findPreference("prefs_check_for_app_updates");
    ckBxPrefAppUpdate.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals("prefs_check_for_app_updates")) {
                Intent i = new Intent(getBaseContext(), CheckForAppUpdate.class);
                i.putExtra("setTimer", !((CheckBoxPreference) preference).isChecked());
                if (!((CheckBoxPreference) preference).isChecked()) {
                    i.putExtra("checkNow", true);
                }
                getBaseContext().startService(i);
            }
            return true;
        }
    });

    Preference ueber = findPreference("ueber");
    ueber.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            Dialog ueberDialog = new Dialog(PrefsActivity.this);

            ueberDialog.setContentView(R.layout.ueber_dialog_layout);
            ueberDialog.setTitle(getString(R.string.ueber));
            ueberDialog.setCancelable(true);
            ueberDialog.setCanceledOnTouchOutside(true);

            TextView dialogText = (TextView) ueberDialog.findViewById(R.id.text_in_dialog);
            dialogText.setTextColor(Color.BLACK);
            dialogText.setAutoLinkMask(Linkify.ALL);

            dialogText.setText(String.format(getString(R.string.ueberTextFormated),
                    getString(R.string.version_nr), getString(R.string.emailAdresseEntwickler),
                    getString(R.string.webAdresseAppDownload), getString(R.string.GNU_GPLwebadresse)));
            ueberDialog.show();
            return true;
        }
    });

    CheckBoxPreference ckBxPrefDebugging = (CheckBoxPreference) findPreference("prefs_debug");
    ckBxPrefDebugging.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals("prefs_debug")) {
                Log.d("PrefsActivity", "new");
                if (!((CheckBoxPreference) preference).isChecked()) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(preference.getContext());

                    builder.setMessage(getString(R.string.debugText)).setTitle(getString(R.string.debugTitel));

                    AlertDialog dialog = builder.create();
                    dialog.show();
                }
            }
            return true;
        }
    });
}

From source file:ca.frozen.curlingtv.activities.ScannerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // get the controls
    View view = inflater.inflate(R.layout.fragment_scanner, container, false);
    message = (TextView) view.findViewById(R.id.scanner_message);
    status = (TextView) view.findViewById(R.id.scanner_status);
    progress = (ProgressBar) view.findViewById(R.id.scanner_progress);
    cancelButton = (Button) view.findViewById(R.id.scanner_cancel);

    // configure the dialog
    Dialog dialog = getDialog();
    if (dialog != null) {
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override/* ww  w. ja  v  a 2  s  . c  o  m*/
            public boolean onKey(android.content.DialogInterface dialog, int keyCode,
                    android.view.KeyEvent event) {
                if ((keyCode == android.view.KeyEvent.KEYCODE_BACK)) {
                    cancel();
                }
                return false;
            }
        });
    }

    // handle the cancel button
    cancelButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            cancel();
            dismiss();
        }
    });

    // create the dismiss handler and runnable
    dismissHandler = new Handler();
    dismissRunner = new Runnable() {
        @Override
        public void run() {
            dismiss();
        }
    };

    // configure the view if we've already done the scan
    if (savedInstanceState != null) {
        DeviceScanner scanner = (scannerWeakRef != null) ? scannerWeakRef.get() : null;
        if (scanner != null) {
            boolean complete = scanner.isComplete();
            scanner.setStatus(complete);
            if (complete) {
                cancelButton.setText(App.getStr(R.string.done));
            }
        }
    }

    return view;
}

From source file:transapps.gpxfitness.ui.MainActivity.java

public void editProfileAlertDialog() {
    if (!ProfileAccessor.isProfileSet()) {
        profileAlertDialog();/*from   w  w w.  j av a2 s  .c  om*/
        return;
    }
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.profile_dialog);
    dialog.setTitle("Edit Profile:");
    dialog.setCancelable(true);

    Button ok_button = (Button) dialog.findViewById(R.id.button);
    ok_button.setText("Ok");
    final EditText username = (EditText) dialog.findViewById(R.id.username);
    username.setText(ProfileAccessor.getUsername());
    final EditText height_ft = (EditText) dialog.findViewById(R.id.height_ft);
    height_ft.setText("" + (int) ProfileAccessor.getHeight() / 12);
    final EditText height_in = (EditText) dialog.findViewById(R.id.height_in);
    height_in.setText("" + (int) ProfileAccessor.getHeight() % 12);
    final EditText weight_lbs = (EditText) dialog.findViewById(R.id.weight_lbs);
    weight_lbs.setText(ProfileAccessor.getWeight() + "");
    final EditText age_yrs = (EditText) dialog.findViewById(R.id.age_yrs);
    age_yrs.setText(ProfileAccessor.getAge() + "");
    final RadioButton male = (RadioButton) dialog.findViewById(R.id.male);
    final RadioButton female = (RadioButton) dialog.findViewById(R.id.female);
    if (ProfileAccessor.getSex().equals("male")) {
        male.setChecked(true);
        female.setChecked(false);
    } else {
        male.setChecked(false);
        female.setChecked(true);
    }
    final EditText[] et = { username, height_ft, height_in, weight_lbs, age_yrs };
    ok_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            String user_string = username.getText().toString();
            String height_ft_string = height_ft.getText().toString();
            String height_in_string = height_in.getText().toString();
            Log.d("TEXT", height_in_string);
            String weight_lbs_string = weight_lbs.getText().toString();
            String age_yrs_string = age_yrs.getText().toString();
            boolean are_any_empty = false;
            for (EditText e : et) {
                String str = e.getText().toString();
                if (str == null || str.length() == 0)
                    are_any_empty = true;
            }
            if (!are_any_empty) {
                int height = Integer.parseInt(height_ft_string) * 12 + Integer.parseInt(height_in_string);
                String sex;
                if (male.isChecked())
                    sex = "male";
                else
                    sex = "female";
                //ProfileAccessor.createNewProfile(user_string, height, Integer.parseInt(weight_lbs_string), sex, Integer.parseInt(age_yrs_string));
                ProfileAccessor.changeUsername(user_string);
                //actionBar.setTitle(getString(R.string.app_name) + ": " + ProfileAccessor.getUsername());
                ProfileAccessor.changeHeight(height);
                ProfileAccessor.changeWeight(Double.parseDouble(weight_lbs_string));
                ProfileAccessor.changeSex(sex);
                ProfileAccessor.changeAge(Integer.parseInt(age_yrs_string));
                dialog.dismiss();
            }
        }
    });

    dialog.show();
}

From source file:com.cerema.cloud2.ui.dialog.ChangelogDialog.java

/**
 * {@inheritDoc}/*from w  ww.  j a  v  a2s  .  co  m*/
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    /// load the custom view to insert in the dialog, between title and 
    WebView webview = new WebView(getActivity());
    webview.loadUrl(
            "file:///android_res/raw/" + getResources().getResourceEntryName(R.raw.changelog) + ".html");

    /// build the dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    Dialog dialog = builder.setView(webview).setIcon(DisplayUtils.getSeasonalIconId())
            //.setTitle(R.string.whats_new)
            .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();

    dialog.setCancelable(getArguments().getBoolean(ARG_CANCELABLE));
    return dialog;
}