Example usage for android.app AlertDialog.Builder show

List of usage examples for android.app AlertDialog.Builder show

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder show.

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:br.com.GUI.perfil.SelecionarTipoDeLogin.java

@SuppressWarnings("deprecation")
public void loginComFacebook() {
    clearFbData();//from w  w w . j ava 2 s.  c  o  m
    //Log.i("clicou", "logarComFacebook");
    Log.i("issessionvalid", " " + String.valueOf(facebook.isSessionValid()));

    if (facebook.isSessionValid()) {
        getProfileInformation();

        AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
        alertDialog.setTitle("Carregando");
        alertDialog.setMessage("Carregando informaes... Por favor, Espere alguns momentos...");
        alertDialog.setIcon(R.drawable.profile);
        alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        // Showing Alert Message
        alertDialog.show();
    } else {
        String access_token = mPrefs.getString("access_token", null);
        long expires = mPrefs.getLong("access_expires", 0);

        if (access_token != null) {
            facebook.setAccessToken(access_token);
        }

        if (expires != 0) {
            facebook.setAccessExpires(expires);
        }

        if (!facebook.isSessionValid()) {
            facebook.authorize(this, new String[] { "publish_stream" }, new DialogListener() {
                //"name","email","gender","username"
                @Override
                public void onCancel() {
                    // Function to handle cancel event
                }

                @Override
                public void onComplete(Bundle values) {
                    // Function to handle complete event
                    // Edit Preferences and update facebook acess_token
                    SharedPreferences.Editor editor = mPrefs.edit();
                    editor.putString("access_token", facebook.getAccessToken());
                    editor.putLong("access_expires", facebook.getAccessExpires());
                    editor.commit();
                    //Log.i("entrei aki ", "entrei no on complete");

                    getProfileInformation();

                }

                @Override
                public void onError(DialogError error) {
                    // Function to handle error

                }

                @Override
                public void onFacebookError(FacebookError fberror) {
                    // Function to handle Facebook errors

                }

            });
        }
    }

}

From source file:au.org.ala.fielddata.mobile.MobileFieldDataDashboard.java

private void showConnectionError() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.initialisationErrorTitle);
    builder.setMessage(String.format(getResources().getString(R.string.initialisationError),
            preferences.getFieldDataServerUrl()));
    builder.setNegativeButton(R.string.close, new Dialog.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();/*from  w w w.  j  ava  2s. c  o m*/
        }
    });
    builder.show();
    return;
}

From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    if (id == R.id.action_view_as_grid) {
        Intent i = new Intent(POIMapActivity.this, POIGridActivity.class);

        i.putExtra("playOn", mActionPlay);

        i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        // finish();
        overridePendingTransition(0, 0);

        startActivityForResult(i, 1);//w  w w .  j  av  a2s. c  om
        overridePendingTransition(0, 0);

    } else if (id == R.id.action_directions) {

        if (mActionDirections == 1) { // cancel directions action
            item.setIcon(R.drawable.ic_action_directions);
            mActionDirections = 0;
            tvMapDirectionsInfo.setVisibility(View.INVISIBLE);
            if (mRoute != null) {
                mRoute.remove();
            }
        } else if (mActionDirections == 0) { // set directions action on

            item.setIcon(R.drawable.ic_action_directions_pressed);
            mActionDirections = 1;

            gmm.handleMapWarningMessages(POIMapActivity.this, tvMapMessage);
            if (gmm.myLocationEnabled && gmm.internetEnabled) {
                Toast.makeText(POIMapActivity.this,
                        POIMapActivity.this.getResources().getString(R.string.tap_route_destination),
                        Toast.LENGTH_SHORT).show();

            } else {
                tvMapMessage.setBackgroundColor(
                        POIMapActivity.this.getResources().getColor(R.color.red_transparent));

                item.setIcon(R.drawable.ic_action_directions);
                mActionDirections = 0;
                tvMapDirectionsInfo.setVisibility(View.INVISIBLE);

            }
        } else { // mActionDirections == 3
            item.setIcon(R.drawable.ic_action_directions);
            mActionDirections = 0;
            tvMapDirectionsInfo.setVisibility(View.INVISIBLE);
            if (mRoute != null) {
                mRoute.remove();
            }
        }

    } else if (id == R.id.action_play) {

        if (mActionPlay) { // cancel play mode
            gmm.addAllMarkers(POIMapActivity.this);
            item.setIcon(R.drawable.ic_action_play);
            mActionPlay = false;

            miDirections.setIcon(R.drawable.ic_action_directions);
            mActionDirections = 0;
            tvMapDirectionsInfo.setVisibility(View.INVISIBLE);
            if (mRoute != null) {
                mRoute.remove();
            }
        } else {
            gmm.addPlayMarkers(POIMapActivity.this);
            item.setIcon(R.drawable.ic_action_pause_red);
            if (gmm.activePOIMarker != null) {
                drawUserDestRoute(gmm.activePOIMarker.getPosition());
            }
            mActionPlay = true;

        }

    } else if (id == R.id.action_google_map_type) {
        // get google map type names
        String[] googleMapTypeNames = getResources().getStringArray(R.array.google_map_type_names);

        // creating and Building the Dialog
        AlertDialog.Builder builderMapType = new AlertDialog.Builder(this);
        builderMapType.setTitle(getResources().getString(R.string.action_google_map_type));
        builderMapType.setSingleChoiceItems(googleMapTypeNames, selectedMapType,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {

                        if (item != selectedMapType) {
                            switchGoogleMapType(item);
                            // save selected type in settings
                            SharedPreferences preferences = PreferenceManager
                                    .getDefaultSharedPreferences(POIMapActivity.this);
                            SharedPreferences.Editor editor = preferences.edit();
                            editor.putString("googleMapType", String.valueOf(item));
                            editor.commit();
                        }
                        mapTypeDialog.dismiss();
                    }
                });
        mapTypeDialog = builderMapType.create();
        mapTypeDialog.show();

    } else if (id == R.id.action_legal_notices) {

        String licenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext());
        AlertDialog.Builder licenseDialog = new AlertDialog.Builder(POIMapActivity.this);
        licenseDialog.setTitle(getString(R.string.action_legal_notices));
        licenseDialog.setMessage(licenseInfo);
        licenseDialog.show();

    } else if (id == R.id.action_scan_qr_code) {

        handleQRcodeScanRequest();

    } else if (id == R.id.action_about) {
        String about = getString(R.string.about_application);
        AlertDialog alertDialog;
        alertDialog = new AlertDialog.Builder(POIMapActivity.this).create();

        alertDialog.setTitle(getString(R.string.action_about));
        alertDialog.setMessage(Html.fromHtml(about));

        alertDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        alertDialog.show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.cloudtask1.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*from w ww.  j  av  a 2  s.  c  o m*/
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                finish();
            }
        });
    }
}

From source file:com.kuaichumen.whistle.admin.CaptureActivity.java

private void displayFrameworkBugMessageAndExit() {
    // camera error
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(com.kuaichumen.whistle.R.string.app_name));
    builder.setMessage("???");
    builder.setPositiveButton("", new DialogInterface.OnClickListener() {

        @Override//from w  ww  .j ava  2  s .c  om
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }

    });
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            finish();
        }
    });
    builder.show();
}

From source file:com.photon.phresco.nativeapp.eshop.activity.PhrescoActivity.java

/**
 * Show the error message dialog box with OK button
 *
 * @param errorMessage/*from w  ww .j  a  va  2  s  .  c om*/
 */
private void showErrorDialog(String errorMessage) {
    try {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(errorMessage).setTitle(R.string.app_name).setCancelable(false)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        finish();
                        // System.runFinalizersOnExit(true);
                        android.os.Process.killProcess(android.os.Process.myPid());
                    }
                });
        @SuppressWarnings("unused")
        AlertDialog alert = builder.show();
    } catch (Exception ex) {
        PhrescoLogger.info(TAG + "showErrorDialog: " + ex.toString());
        PhrescoLogger.warning(ex);
    }
}

From source file:li.klass.fhem.adapter.devices.genericui.AvailableTargetStatesDialogUtil.java

public static <D extends FhemDevice<D>> void showSwitchOptionsMenu(final Context context, final D device,
        final TargetStateSelectedCallback callback) {
    AlertDialog.Builder contextMenu = new AlertDialog.Builder(context);
    contextMenu.setTitle(context.getResources().getString(R.string.switchDevice));
    final List<String> setOptions = device.getSetList().getSortedKeys();
    final String[] eventMapOptions = device.getAvailableTargetStatesEventMapTexts();

    DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
        @Override/* w  w w .  j a  va 2 s .c o  m*/
        public void onClick(DialogInterface dialog, int position) {
            final String option = setOptions.get(position);

            if (handleSelectedOption(context, device, option, callback))
                return;

            dialog.dismiss();
        }
    };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.list_item_with_arrow,
            eventMapOptions) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = View.inflate(context, R.layout.list_item_with_arrow, null);
            }
            TextView textView = (TextView) convertView.findViewById(R.id.text);
            ImageView imageView = (ImageView) convertView.findViewById(R.id.image);

            textView.setText(getItem(position));

            String setOption = setOptions.get(position);
            SetList setList = device.getSetList();
            final SetListValue setListValue = setList.get(setOption);

            imageView.setVisibility(setListValue instanceof SetListGroupValue ? VISIBLE : GONE);

            return convertView;
        }
    };
    contextMenu.setAdapter(adapter, clickListener);

    contextMenu.show();
}

From source file:nz.ac.wintec.soit.af5.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*w ww.  j a v a  2s  .c o  m*/
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //  startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                finish();
            }
        });
    }
}

From source file:net.evecom.android.log.DailyLogLookActivity.java

/**
 * /*from  w w w.jav  a 2  s. co  m*/
 * 
 * @param errorMsg
 */
private void DialogToast(String errorMsg) {
    AlertDialog.Builder builder1 = new AlertDialog.Builder(DailyLogLookActivity.this);
    builder1.setTitle("");
    builder1.setIcon(R.drawable.qq_dialog_default_icon);// 
    builder1.setMessage("" + errorMsg);
    builder1.setPositiveButton("", new DialogInterface.OnClickListener() {
        // @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    builder1.show();
}

From source file:com.cleverzone.zhizhi.capture.CaptureActivity.java

private void displayFrameworkBugMessageAndExit() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.app_name));
    builder.setMessage(getString(R.string.msg_camera_framework_bug));
    builder.setPositiveButton(R.string.button_ok, new FinishListener(this));
    builder.setOnCancelListener(new FinishListener(this));
    builder.show();
}