Example usage for android.app AlertDialog show

List of usage examples for android.app AlertDialog show

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:edu.cwru.apo.Home.java

public void onRestRequestComplete(Methods method, JSONObject result) {
    if (method == Methods.phone) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    SharedPreferences.Editor editor = getSharedPreferences(APO.PREF_FILE_NAME, MODE_PRIVATE)
                            .edit();//from  ww w.  j a  v a  2 s . com
                    editor.putLong("updateTime", result.getLong("updateTime"));
                    editor.commit();
                    int numbros = result.getInt("numBros");
                    JSONArray caseID = result.getJSONArray("caseID");
                    JSONArray first = result.getJSONArray("first");
                    JSONArray last = result.getJSONArray("last");
                    JSONArray phone = result.getJSONArray("phone");
                    JSONArray family = result.getJSONArray("family");
                    ContentValues values;
                    for (int i = 0; i < numbros; i++) {
                        values = new ContentValues();
                        values.put("_id", caseID.getString(i));
                        values.put("first", first.getString(i));
                        values.put("last", last.getString(i));
                        values.put("phone", phone.getString(i));
                        values.put("family", family.getString(i));
                        database.replace("phoneDB", null, values);
                    }
                } else if (requestStatus.compareTo("timestamp invalid") == 0) {
                    Toast msg = Toast.makeText(this, "Invalid timestamp.  Please try again.",
                            Toast.LENGTH_LONG);
                    msg.show();
                } else if (requestStatus.compareTo("HMAC invalid") == 0) {
                    Auth.loggedIn = false;
                    Toast msg = Toast.makeText(this,
                            "You have been logged out by the server.  Please log in again.", Toast.LENGTH_LONG);
                    msg.show();
                    finish();
                } else {
                    Toast msg = Toast.makeText(this, "Invalid requestStatus", Toast.LENGTH_LONG);
                    msg.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } else if (method == Methods.checkAppVersion) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    String appVersion = result.getString("version");
                    String appDate = result.getString("date");
                    final String appUrl = result.getString("url");
                    PackageInfo pinfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
                    ;
                    if (appVersion.compareTo(pinfo.versionName) != 0) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(this);
                        builder.setTitle("Upgrade");
                        builder.setMessage("Update available, ready to upgrade?");
                        builder.setIcon(R.drawable.icon);
                        builder.setCancelable(false);
                        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Intent promptInstall = new Intent("android.intent.action.VIEW",
                                        Uri.parse("https://apo.case.edu:8090/app/" + appUrl));
                                startActivity(promptInstall);
                            }
                        });
                        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else {
                        Toast msg = Toast.makeText(this, "No updates found", Toast.LENGTH_LONG);
                        msg.show();
                    }
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NameNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

From source file:no.ntnu.idi.socialhitchhiking.myAccount.MyAccountPreferences.java

/**
 * Called when the button "Set Facebook privacy" is clicked. Opens an AlertDialog where the user selects a privacy setting.
 * @param view//from w w  w.j a  v  a  2 s.  co m
 */
public void btnFacebookClicked(View view) {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Set Privacy");
    builder.setSingleChoiceItems(R.array.privacy_setting, selectedPrivacy,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    selectedPrivacy = item;
                }
            });
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            switch (selectedPrivacy) {
            case 0:
                privacyPreference = Visibility.FRIENDS;
                facebookPrivacy = "Friends";
                break;
            case 1:
                privacyPreference = Visibility.FRIENDS_OF_FRIENDS;
                facebookPrivacy = "Friends of friends";
                break;
            case 2:
                privacyPreference = Visibility.PUBLIC;
                facebookPrivacy = "Public";
                break;
            default:
                break;
            }
            // Setting button text
            btnFacebook.setText(Html.fromHtml("<b align = left><big>" + "Set Facebook privacy" + "</big></b>"
                    + "<br />" + facebookPrivacy + "<br />"));

            // Writing data to SharedPreferences
            getApp().getSettings().setFacebookPrivacy(privacyPreference);
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();

}

From source file:com.toppatch.mv.ui.activities.MainActivity.java

private void checkConditions() {
    //sendToWelcomePage();
    if (isConnectingToInternet()) {
        if (AdminHelper.isUserLoggedIn(this)) {
            if (AdminHelper.isAdminActive(this)) {
                if (AdminHelper.isSamsungESDKEnabled(this))
                    if (AdminHelper.isGCMRegistered(this)) {
                        Log.i("see", "gcmif");
                        sendToWelcomePage();
                    } else {
                        Log.i("see", "gcmelse");
                        sendToGCMPage();
                    }//from  ww  w  .  j a v  a  2 s  . co m
                else {
                    Log.i("see", "register");
                    Boolean canRegiser = Registration.register(this);
                    if (!canRegiser)
                        sendToLoginPage();
                }

            } else {
                sendToLoginPage();
            }
        } else {
            sendToLoginPage();
        }
    } else {
        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle("Ohh No!!");
        alertDialog.setMessage("No Internet Connection...Exiting..");
        alertDialog.show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                finish();
            }
        }, 2000);
    }
}

From source file:com.example.prasadnr.traquad.TraQuad.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tra_quad);
    ConnectivityManager connManager = (ConnectivityManager) getSystemService(TraQuad.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    Builder alert = new AlertDialog.Builder(TraQuad.this);

    WifiManager managerWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    Method[] wmMethods = managerWifi.getClass().getDeclaredMethods();
    for (Method method : wmMethods) {
        if (method.getName().equals("isWifiApEnabled")) {

            try {
                isWifiAPenabled = (boolean) method.invoke(managerWifi);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();//from   ww w. j a  v  a  2  s  . c o  m
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    }

    final ProgressDialog pDialog;
    MediaController mediaController = new MediaController(this);

    pDialog = new ProgressDialog(TraQuad.this);
    pDialog.setTitle("TraQuad app (Connecting...)");
    pDialog.setMessage("Buffering...Please wait...");
    pDialog.setCancelable(true);

    if (!isWifiAPenabled) {

        alert.setTitle("WiFi Hotspot Settings");
        alert.setMessage("Can you please connect WiFi-hotspot?");
        alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                irritation = true;
                startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
                pDialog.show();
            }
        });
        alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //Dismiss AlertDialog
                pDialog.show();
                Toast.makeText(getApplicationContext(), "Please connect your WiFi!", Toast.LENGTH_LONG).show();
            }
        });
        alert.setCancelable(false);
        AlertDialog alertDialog = alert.create();
        alertDialog.show();
    }

    WebView webView = (WebView) findViewById(R.id.webView);

    if (irritation == true | isWifiAPenabled) {
        pDialog.show();
    }

    mediaController.setAnchorView(webView);
    mediaController.setVisibility(View.GONE);

    extra = getIntent().getStringExtra("VideosId");
    webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);

    final GlobalClass globalVariable = (GlobalClass) getApplicationContext();
    final String IPaddressNew = globalVariable.getIP();
    final String httpString = "http://";
    final String commandPort = String.valueOf(1500);
    final String streamPort = String.valueOf(8080);
    final String IPaddressStream = httpString + IPaddressNew + ":" + streamPort;
    final String IPaddressCommand = httpString + IPaddressNew + ":" + commandPort;
    TextView sendCharacter = (TextView) findViewById(R.id.sendCharacter);

    try {
        webView.loadUrl(IPaddressStream);
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), IPaddressNew + ":Error!", Toast.LENGTH_LONG).show();
    }

    webView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            pDialog.dismiss();
        }
    });

    final Button switchact = (Button) findViewById(R.id.btn2);
    switchact.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent act1 = new Intent(view.getContext(), Joypad.class);
            startActivity(act1);

        }
    });

    final Button hometraquad = (Button) findViewById(R.id.button5);

    hometraquad.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            Intent acthometraquad = new Intent(TraQuad.this, MainActivity.class);
            startActivity(acthometraquad);
        }
    });

}

From source file:com.wellsandwhistles.android.redditsp.reddit.prepared.RedditPreparedPost.java

public static void showActionMenu(final AppCompatActivity activity, final RedditPreparedPost post) {

    final EnumSet<Action> itemPref = PrefsUtility.pref_menus_post_context_items(activity,
            PreferenceManager.getDefaultSharedPreferences(activity));

    if (itemPref.isEmpty())
        return;//ww w .jav  a  2 s  . co m

    final RedditAccount user = RedditAccountManager.getInstance(activity).getDefaultAccount();

    final ArrayList<RPVMenuItem> menu = new ArrayList<>();

    if (!RedditAccountManager.getInstance(activity).getDefaultAccount().isAnonymous()) {

        if (itemPref.contains(Action.UPVOTE)) {
            if (!post.isUpvoted()) {
                menu.add(new RPVMenuItem(activity, R.string.action_upvote, Action.UPVOTE));
            } else {
                menu.add(new RPVMenuItem(activity, R.string.action_upvote_remove, Action.UNVOTE));
            }
        }

        if (itemPref.contains(Action.DOWNVOTE)) {
            if (!post.isDownvoted()) {
                menu.add(new RPVMenuItem(activity, R.string.action_downvote, Action.DOWNVOTE));
            } else {
                menu.add(new RPVMenuItem(activity, R.string.action_downvote_remove, Action.UNVOTE));
            }
        }

        if (itemPref.contains(Action.SAVE)) {
            if (!post.isSaved()) {
                menu.add(new RPVMenuItem(activity, R.string.action_save, Action.SAVE));
            } else {
                menu.add(new RPVMenuItem(activity, R.string.action_unsave, Action.UNSAVE));
            }
        }

        if (itemPref.contains(Action.HIDE)) {
            if (!post.isHidden()) {
                menu.add(new RPVMenuItem(activity, R.string.action_hide, Action.HIDE));
            } else {
                menu.add(new RPVMenuItem(activity, R.string.action_unhide, Action.UNHIDE));
            }
        }

        if (itemPref.contains(Action.EDIT) && post.isSelf()
                && user.username.equalsIgnoreCase(post.src.getAuthor())) {
            menu.add(new RPVMenuItem(activity, R.string.action_edit, Action.EDIT));
        }

        if (itemPref.contains(Action.DELETE) && user.username.equalsIgnoreCase(post.src.getAuthor())) {
            menu.add(new RPVMenuItem(activity, R.string.action_delete, Action.DELETE));
        }

        if (itemPref.contains(Action.REPORT))
            menu.add(new RPVMenuItem(activity, R.string.action_report, Action.REPORT));
    }

    if (itemPref.contains(Action.EXTERNAL))
        menu.add(new RPVMenuItem(activity, R.string.action_external, Action.EXTERNAL));
    if (itemPref.contains(Action.SELFTEXT_LINKS) && post.src.getRawSelfText() != null
            && post.src.getRawSelfText().length() > 1)
        menu.add(new RPVMenuItem(activity, R.string.action_selftext_links, Action.SELFTEXT_LINKS));
    if (itemPref.contains(Action.SAVE_IMAGE) && post.mIsProbablyAnImage)
        menu.add(new RPVMenuItem(activity, R.string.action_save_image, Action.SAVE_IMAGE));
    if (itemPref.contains(Action.GOTO_SUBREDDIT))
        menu.add(new RPVMenuItem(activity, R.string.action_gotosubreddit, Action.GOTO_SUBREDDIT));
    if (post.showSubreddit) {
        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());

            if (itemPref.contains(Action.BLOCK) && post.showSubreddit) {
                final List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(activity,
                        PreferenceManager.getDefaultSharedPreferences(activity));

                if (blockedSubreddits.contains(subredditCanonicalName)) {
                    menu.add(new RPVMenuItem(activity, R.string.action_unblock_subreddit, Action.UNBLOCK));
                } else {
                    menu.add(new RPVMenuItem(activity, R.string.action_block_subreddit, Action.BLOCK));
                }
            }

            if (itemPref.contains(Action.PIN) && post.showSubreddit) {
                List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(activity,
                        PreferenceManager.getDefaultSharedPreferences(activity));
                if (pinnedSubreddits.contains(subredditCanonicalName)) {
                    menu.add(new RPVMenuItem(activity, R.string.action_unpin_subreddit, Action.UNPIN));
                } else {
                    menu.add(new RPVMenuItem(activity, R.string.action_pin_subreddit, Action.PIN));
                }
            }

            if (!RedditAccountManager.getInstance(activity).getDefaultAccount().isAnonymous()) {
                if (itemPref.contains(Action.SUBSCRIBE)) {
                    if (RedditSubredditSubscriptionManager
                            .getSingleton(activity,
                                    RedditAccountManager.getInstance(activity).getDefaultAccount())
                            .getSubscriptionState(
                                    subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.SUBSCRIBED) {
                        menu.add(new RPVMenuItem(activity, R.string.action_unsubscribe_subreddit,
                                Action.UNSUBSCRIBE));
                    } else {
                        menu.add(new RPVMenuItem(activity, R.string.action_subscribe_subreddit,
                                Action.SUBSCRIBE));
                    }
                }
            }

        } catch (RedditSubreddit.InvalidSubredditNameException ex) {
            throw new RuntimeException(ex);
        }
    }

    if (itemPref.contains(Action.SHARE))
        menu.add(new RPVMenuItem(activity, R.string.action_share, Action.SHARE));
    if (itemPref.contains(Action.SHARE_COMMENTS))
        menu.add(new RPVMenuItem(activity, R.string.action_share_comments, Action.SHARE_COMMENTS));
    if (itemPref.contains(Action.SHARE_IMAGE) && post.mIsProbablyAnImage)
        menu.add(new RPVMenuItem(activity, R.string.action_share_image, Action.SHARE_IMAGE));
    if (itemPref.contains(Action.COPY))
        menu.add(new RPVMenuItem(activity, R.string.action_copy, Action.COPY));
    if (itemPref.contains(Action.USER_PROFILE))
        menu.add(new RPVMenuItem(activity, R.string.action_user_profile, Action.USER_PROFILE));
    if (itemPref.contains(Action.PROPERTIES))
        menu.add(new RPVMenuItem(activity, R.string.action_properties, Action.PROPERTIES));

    final String[] menuText = new String[menu.size()];

    for (int i = 0; i < menuText.length; i++) {
        menuText[i] = menu.get(i).title;
    }

    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    builder.setItems(menuText, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            onActionMenuItemSelected(post, activity, menu.get(which).action);
        }
    });

    //builder.setNeutralButton(R.string.dialog_cancel, null);

    final AlertDialog alert = builder.create();
    alert.setCanceledOnTouchOutside(true);
    alert.show();
}

From source file:edu.asu.bsse.vtanders.finalproject.MainActivity.java

License:asdf

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_config) {
        AlertDialog.Builder connInfoDialogBuilder = new AlertDialog.Builder(this);
        connInfoDialogBuilder.setTitle("Server Information");
        final View view = getLayoutInflater().inflate(R.layout.server_config, null);
        connInfoDialogBuilder.setView(view);
        final AlertDialog connInfoDialog = connInfoDialogBuilder.create();
        connInfoDialog.show();
        Button apply = (Button) view.findViewById(R.id.apply_settings_button);
        apply.setOnClickListener(new View.OnClickListener() {
            @Override//  w  ww.j ava 2  s  .  c  om
            public void onClick(View v) {
                EditText hostET = (EditText) view.findViewById(R.id.host_content);
                String host = hostET.getText().toString();

                EditText portET = (EditText) view.findViewById(R.id.port_content);
                int port = Integer.valueOf(portET.getText().toString());

                EditText nickET = (EditText) view.findViewById(R.id.nickname_content);
                String nick = nickET.getText().toString();

                Log.d("ASDF", host + " " + port + " " + nick);

                new SetupConnectionTask(host, port, nick).execute();
                connInfoDialog.dismiss();
            }
        });

        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.mercandalli.android.apps.files.user.community.UserFragment.java

public void updateAdapter() {
    if (mRecyclerView != null && isAdded()) {
        mCircularProgressBar.setVisibility(View.GONE);

        if (mUserModels.size() == 0) {
            mMessageTextView.setText(getString(R.string.no_user));
            mMessageTextView.setVisibility(View.VISIBLE);
        } else {/*from  www. j a v a2s .  c  o  m*/
            mMessageTextView.setVisibility(View.GONE);
        }

        final AdapterModelUser adapterModelUser = new AdapterModelUser(mUserModels, new IModelUserListener() {
            @Override
            public void execute(final UserModel userModel) {
                final AlertDialog.Builder menuAlert = new AlertDialog.Builder(getContext());
                String[] menuList = { getString(R.string.talk) };
                if (Config.isUserAdmin()) {
                    menuList = new String[] { getString(R.string.talk), getString(R.string.delete) };
                }
                menuAlert.setTitle(getString(R.string.action));
                menuAlert.setItems(menuList, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {
                        switch (item) {
                        case 0:
                            DialogUtils.prompt(getContext(), "Send Message", "Write your message", "Send",
                                    new DialogUtils.OnDialogUtilsStringListener() {
                                        @Override
                                        public void onDialogUtilsStringCalledBack(String text) {
                                            String url = Constants.URL_DOMAIN + Config.ROUTE_USER_CONVERSATION
                                                    + "/" + userModel.getId();
                                            List<StringPair> parameters = new ArrayList<>();
                                            parameters.add(new StringPair("message", "" + text));

                                            new TaskPost(getActivity(), url, new IPostExecuteListener() {
                                                @Override
                                                public void onPostExecute(JSONObject json, String body) {

                                                }
                                            }, parameters).execute();
                                        }
                                    }, getString(android.R.string.cancel), null);
                            break;
                        case 1:
                            DialogUtils.alert(getContext(), "Delete " + userModel.username + "?",
                                    "This process cannot be undone.", getString(R.string.delete),
                                    new DialogUtils.OnDialogUtilsListener() {
                                        @Override
                                        public void onDialogUtilsCalledBack() {
                                            if (Config.isUserAdmin()) {
                                                userModel.delete(getActivity(), new IPostExecuteListener() {
                                                    @Override
                                                    public void onPostExecute(JSONObject json, String body) {
                                                        UserFragment.this.refreshList();
                                                    }
                                                });
                                            } else {
                                                Toast.makeText(getActivity(), "Not permitted.",
                                                        Toast.LENGTH_SHORT).show();
                                            }
                                        }
                                    }, getString(android.R.string.cancel), null);
                            break;
                        }
                    }
                });
                AlertDialog menuDrop = menuAlert.create();
                menuDrop.show();
            }
        });
        mRecyclerView.setAdapter(adapterModelUser);

        if ((mRootView.findViewById(R.id.circle)).getVisibility() == View.GONE) {
            (mRootView.findViewById(R.id.circle)).setVisibility(View.VISIBLE);
            Animation animOpen = AnimationUtils.loadAnimation(getContext(), R.anim.circle_button_bottom_open);
            (mRootView.findViewById(R.id.circle)).startAnimation(animOpen);
        }

        (mRootView.findViewById(R.id.circle)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Fab UserFragment
                Toast.makeText(getActivity(), getString(R.string.not_implemented), Toast.LENGTH_SHORT).show();
            }
        });

        adapterModelUser.setOnItemClickListener(new AdapterModelUser.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {

            }
        });

        mSwipeRefreshLayout.setRefreshing(false);
    }
}

From source file:com.starwood.anglerslong.LicenseActivity.java

/*****************************************************************************************************
 * Handles the onClick of the button/image
 *****************************************************************************************************
 * @param v Holds the clicked view//from w w  w. j av a2s  .c  o  m
 *****************************************************************************************************/
private void clickedItem(View v) {
    for (int i = 0; i < imageViewIdArray.length; i++) {
        if (v.getId() == imageViewIdArray[i]) {
            currentItemID = i;
            break;
        }
    }

    //*******************************************************************************************************
    // Only goes here if they clicked the DELETE button in the actionbar menu.
    //*******************************************************************************************************
    if (isDeletable) {
        AlertDialog.Builder builder = new AlertDialog.Builder(LicenseActivity.this);
        builder.setMessage("Are you sure you want to delete this item from the list?").setTitle("Delete")
                .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        try {
                            delete(currentItemID);
                            onBackPressed();
                            Toast.makeText(getApplicationContext(), "Your item has been deleted!",
                                    Toast.LENGTH_SHORT).show();
                        } catch (IOException | JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                    }
                });

        AlertDialog alert = builder.create();
        alert.show();
        isDeletable = false;
    }
    //*******************************************************************************************************
    // Go here if you just want to click the item, see info that's stored, and possibly add to it.
    //*******************************************************************************************************
    else {
        isEdit = true;
        Intent intent = new Intent();
        intent.setClass(getApplicationContext(), LicenseAddActivity.class);
        intent.putExtra("title", "License");
        intent.putExtra("isPopulated", isLicensePopulated);
        intent.putExtra("isArrayEmpty", isArrayEmpty);
        intent.putExtra("isEdit", isEdit);
        intent.putExtra("currentItemID", currentItemID);
        intent.putExtra("isLicense", true);
        startActivity(intent);
    }
}

From source file:fr.mdk.kisspush.KISSPush.java

protected void openAdd() {
    final Activity act = this;
    // get prompts.xml view
    LayoutInflater layoutInflater = getLayoutInflater();
    View promptView = layoutInflater.inflate(R.layout.prompts, null);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(act);
    // set prompts.xml to be the layout file of the alertdialog
    // builder/*from  w w w .j av  a  2s . com*/
    alertDialogBuilder.setView(promptView);
    final EditText input = (EditText) promptView.findViewById(R.id.userInput);
    // setup a dialog window
    alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // get user input and set it to
            // result
            if (input.getText().toString().length() > 0) {
                kiss_push_cli.add_alias(input.getText().toString(), new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
                        getAliases();
                    }
                });
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    // create an alert dialog
    AlertDialog alertD = alertDialogBuilder.create();
    alertD.show();

}

From source file:com.linkedin.android.eventsapp.EventFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final String eventNameArg = getArguments().getString(EXTRA_EVENT_NAME);
    final long eventDateArg = getArguments().getLong(EXTRA_EVENT_DATE);
    final String eventLocationArg = getArguments().getString(EXTRA_EVENT_LOCATION);
    int pictureIdArg = getArguments().getInt(EXTRA_PICTURE_ID);
    boolean isAttendingArg = getArguments().getBoolean(EXTRA_EVENT_ATTENDING);
    Person[] attendeesArg = (Person[]) getArguments().getParcelableArray(EXTRA_EVENT_ATTENDEES);

    SimpleDateFormat dateFormat = new SimpleDateFormat("E dd MMM yyyy 'at' hh:00 a");
    final String dateString = dateFormat.format(new Date(eventDateArg));

    View v = inflater.inflate(R.layout.layout_event_fragment, container, false);

    boolean accessTokenValid = LISessionManager.getInstance(getActivity()).getSession().isValid();
    if (!accessTokenValid) {
        ViewStub linkedinLogin = (ViewStub) v.findViewById(R.id.connectWithLinkedInStub);
        linkedinLogin.inflate();//from w ww . ja  v  a  2 s.c om

        Button loginButton = (Button) v.findViewById(R.id.connectWithLinkedInButton);
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "clicked login button");
                LISessionManager.getInstance(getActivity()).init(getActivity(), Constants.scope,
                        new AuthListener() {
                            @Override
                            public void onAuthSuccess() {
                                Intent intent = new Intent(getActivity(), MainActivity.class);
                                startActivity(intent);
                                getActivity().finish();
                            }

                            @Override
                            public void onAuthError(LIAuthError error) {

                            }
                        }, false);
            }
        });
    }

    TextView eventNameView = (TextView) v.findViewById(R.id.eventName);
    eventNameView.setText(eventNameArg);

    TextView eventLocationAndDateView = (TextView) v.findViewById(R.id.eventLocationAndDate);
    eventLocationAndDateView.setText(eventLocationArg + "   " + dateString);

    TextView eventAttendeeCount = (TextView) v.findViewById(R.id.attendeeCount);
    eventAttendeeCount.setText("Other Attendees (" + attendeesArg.length + ")");

    ImageView eventImageView = (ImageView) v.findViewById(R.id.eventImage);
    eventImageView.setImageResource(pictureIdArg);

    final Button attendButton = (Button) v.findViewById(R.id.attendButton);
    final Button declineButton = (Button) v.findViewById(R.id.declineButton);

    if (isAttendingArg) {
        attendButton.setText("Attending");
        attendButton.setEnabled(false);

        declineButton.setText("Decline");
        declineButton.setEnabled(true);
    }

    attendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((Button) v).setText("Attending");
            v.setEnabled(false);
            declineButton.setText("Decline");
            declineButton.setEnabled(true);
            if (LISessionManager.getInstance(getActivity()).getSession().isValid()) {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                alertDialogBuilder.setTitle("Share on LinkedIn?");
                alertDialogBuilder.setCancelable(true)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                JSONObject shareObject = new JSONObject();
                                try {
                                    JSONObject visibilityCode = new JSONObject();
                                    visibilityCode.put("code", "anyone");
                                    shareObject.put("visibility", visibilityCode);
                                    shareObject.put("comment", "I am attending " + eventNameArg + " in "
                                            + eventLocationArg + " on " + dateString);
                                } catch (JSONException e) {

                                }
                                APIHelper.getInstance(getActivity()).postRequest(getActivity(),
                                        Constants.shareBaseUrl, shareObject, new ApiListener() {
                                            @Override
                                            public void onApiSuccess(ApiResponse apiResponse) {
                                                Toast.makeText(getActivity(), "Your share was successful!",
                                                        Toast.LENGTH_LONG);
                                            }

                                            @Override
                                            public void onApiError(LIApiError apiError) {
                                                Log.e(TAG, apiError.toString());
                                                Toast.makeText(getActivity(),
                                                        "Your share was unsuccessful. Try again later!",
                                                        Toast.LENGTH_LONG);
                                            }
                                        });
                            }
                        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            }
        }
    });

    declineButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((Button) v).setText("Declined");
            v.setEnabled(false);
            attendButton.setText("Attend");
            attendButton.setEnabled(true);
        }
    });

    ListView attendeesListView = (ListView) v.findViewById(R.id.attendeesList);
    AttendeeAdapter adapter = new AttendeeAdapter(getActivity(), R.layout.attendee_list_item, attendeesArg,
            accessTokenValid);
    attendeesListView.setAdapter(adapter);
    attendeesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ArrayAdapter adapter = (ArrayAdapter) parent.getAdapter();
            Person person = (Person) adapter.getItem(position);

            Intent intent = new Intent(getActivity(), ProfileActivity.class);
            Bundle extras = new Bundle();
            extras.putParcelable("person", person);
            intent.putExtras(extras);
            startActivity(intent);
        }
    });
    return v;
}