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:com.mibr.android.intelligentreminder.INeedToo.java

public void unRegisterPhoneWithReason(String reason) {
    File file = null;/*  w w w  . jav a  2 s  .  c  om*/
    Boolean doAlert = false;
    if (isSdPresent()) {
        file = new File("/sdcard/mibr/log2.txt");
        if (file.exists()) {
            file.delete();
            doAlert = true;
        }
    } else {
        file = new File("/data/data/" + getPackageName() + "/files/log2.txt");
        if (file.exists()) {
            file.delete();
            doAlert = true;
        }
    }
    if (doAlert) {
        setTitle(getHeading());
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Your registration has failed.  Reason: " + reason).setCancelable(false)
                .setPositiveButton(R.string.msg_register, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        Intent i4 = new Intent(INeedToo.this, INeedToPay.class);
                        startActivity(i4);
                    }
                }).setNegativeButton(R.string.msg_cancel, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }
                });
        AlertDialog alert = builder.create();
        alert.show();

    }
}

From source file:org.csp.everyaware.offline.Map.java

private void setUpMapIfNeeded(Bundle savedInstanceState) {
    // Do a null check to confirm that we have not already instantiated the map.
    if (mMapView == null) {
        mMapView = (MapView) findViewById(R.id.mapView);
        //MapView object has the same life cycle of activity
        mMapView.onCreate(savedInstanceState);

        //get reference to GoogleMap object from MapView
        mGoogleMap = mMapView.getMap();/* w  ww. j ava2 s  . c  om*/

        if (isGoogleMapsInstalled()) {
            if (mGoogleMap != null) {
                //CameraUpdateFactory e BitmapDescriptorFactory need initialization now
                try {
                    MapsInitializer.initialize(this);
                } catch (GooglePlayServicesNotAvailableException e) {
                    e.printStackTrace();
                }

                setUpMap();
            }
        } else {
            Builder builder = new AlertDialog.Builder(this);
            builder.setMessage(getString(R.string.install_google_maps_string));
            builder.setCancelable(false);
            builder.setPositiveButton(R.string.alert_dialog_ok, getGoogleMapsListener());
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    }
}

From source file:com.mibr.android.intelligentreminder.INeedToo.java

public void TrialIsEndingWarningOrLicensingFailed(String verbiage, Boolean wereDealingWithLicensingHere) {
    final Boolean wdwlh = wereDealingWithLicensingHere;
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(verbiage).setCancelable(false)
            .setNeutralButton(R.string.msg_cus, new DialogInterface.OnClickListener() {
                @Override/*from w ww . jav  a 2  s . c o  m*/
                public void onClick(DialogInterface dialog, int id) {
                    String[] mailto = { "diamondsoftware222@gmail.com", "" };
                    Intent sendIntent = new Intent(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
                    sendIntent.putExtra(Intent.EXTRA_SUBJECT, "".toString());
                    sendIntent.putExtra(Intent.EXTRA_TEXT, "".toString());
                    sendIntent.setType("text/plain");
                    startActivity(Intent.createChooser(sendIntent, "Send EMail..."));
                }
            }).setPositiveButton(R.string.msg_register, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    Intent i4 = new Intent(INeedToo.this, INeedToPay.class);
                    startActivity(i4);
                }
            }).setNegativeButton(R.string.msg_cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (wdwlh) {
                        INeedToo.this.finish();
                    }
                }
            });
    AlertDialog alert = builder.create();
    try {
        alert.show();
    } catch (Exception ee33) {
        int bkhere = 3;
        int bkhere2 = bkhere;
    }
}

From source file:com.mibr.android.intelligentreminder.INeedToo.java

public void showReminderContactsNotAvailable(Activity activity) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setMessage(/*from   w w  w .j  a va2 s. com*/
            "This function requires the Intelligent Reminder add-on for Reminder Contacts.  Do you want to fetch it?")
            .setCancelable(false).setPositiveButton(R.string.msg_yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    if (IS_ANDROID_VERSION) {
                        String uri = "market://details?id=com.mibr.android.remindercontacts";
                        Intent ii3 = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                        startActivity(ii3);
                    } else {
                        Uri uri = Uri.parse(
                                "http://www.amazon.com/gp/mas/dl/android?p=com.mibr.android.remindercontacts");
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        startActivity(intent);
                    }
                }
            }).setNegativeButton(R.string.msg_cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub

                }
            });
    AlertDialog alert = builder.create();
    alert.setOwnerActivity(activity);
    alert.show();
}

From source file:com.ringdroid.RingdroidEditActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case CMD_SAVE:
        if (mSoundFile == null)
            return false;
        if (mSoundFile.getAvgBitrateKbps() <= 32) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage(R.string.rate_low).setCancelable(false)
                    .setPositiveButton(R.string.use_all, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            showDialog(DIALOG_USE_ALL);
                        }/*from  ww  w. j  a  va  2s.  c o m*/
                    }).setNeutralButton(R.string.edit, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            onSave();
                        }
                    }).setNegativeButton(R.string.alertdialog_cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        } else {
            onSave();
        }
        return true;
    case CMD_RESET:
        resetPositions();
        mOffsetGoal = 0;
        updateDisplay();
        return true;
    case CMD_ABOUT:
        onAbout(this);
        return true;
    case CMD_USE_ALL:
        onUseAll();
        return true;
    default:
        return false;
    }
}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

private void sendRegistrationRequest(final String email) {
    final ProgressDialog progressDialog = new ProgressDialog(RegistrationActivity2.this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage(getString(R.string.registration_sending_email, email));
    progressDialog.setCancelable(true);//from   ww  w  .j a va2s  .  c  o  m
    progressDialog.show();
    final SafeRunnable showErrorDialog = new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.UI();
            progressDialog.dismiss();
            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
            builder.setMessage(R.string.error_please_try_again);
            builder.setPositiveButton(R.string.rogerthat, null);
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    };
    final String timestamp = "" + mWiz.getTimestamp();
    final String registrationId = mWiz.getRegistrationId();
    final String deviceId = mWiz.getDeviceId();

    mWorkerHandler.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.REGISTRATION();
            String version = "2";
            String requestSignature = Security.sha256(version + email + " " + timestamp + " " + deviceId + " "
                    + registrationId + " " + CloudConstants.REGISTRATION_EMAIL_SIGNATURE);

            HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_REQUEST_URL);
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
                nameValuePairs.add(new BasicNameValuePair("version", version));
                nameValuePairs.add(new BasicNameValuePair("email", email));
                nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp));
                nameValuePairs.add(new BasicNameValuePair("device_id", deviceId));
                nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId));
                nameValuePairs.add(new BasicNameValuePair("request_signature", requestSignature));
                nameValuePairs.add(new BasicNameValuePair("install_id", mWiz.getInstallationId()));
                nameValuePairs.add(new BasicNameValuePair("request_id", UUID.randomUUID().toString()));
                nameValuePairs.add(new BasicNameValuePair("language", Locale.getDefault().getLanguage()));
                nameValuePairs.add(new BasicNameValuePair("country", Locale.getDefault().getCountry()));
                nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = mHttpClient.execute(httppost);

                int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode == 200) {
                    mUIHandler.post(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            T.UI();
                            mWiz.setEmail(email);
                            mWiz.save();
                            progressDialog.dismiss();
                            mWiz.proceedToNextPage();
                            showNotification();
                        }
                    });
                } else if (statusCode == 502) {

                    final HttpEntity entity = response.getEntity();
                    mUIHandler.post(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            T.UI();
                            progressDialog.dismiss();
                            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);

                            boolean stringSet = false;
                            if (entity != null) {
                                @SuppressWarnings("unchecked")
                                final Map<String, Object> responseMap = (Map<String, Object>) org.json.simple.JSONValue
                                        .parse(new InputStreamReader(entity.getContent()));

                                if (responseMap != null) {
                                    String result = (String) responseMap.get("result");
                                    if (result != null) {
                                        builder.setMessage(result);
                                        stringSet = true;
                                    }
                                }
                            }

                            if (!stringSet) {
                                builder.setMessage(R.string.registration_email_not_valid);
                            }

                            builder.setPositiveButton(R.string.rogerthat, null);
                            AlertDialog dialog = builder.create();
                            dialog.show();
                        }
                    });
                } else {
                    mUIHandler.post(showErrorDialog);
                }

            } catch (ClientProtocolException e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            } catch (IOException e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            }
        }
    });
}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

private void registerWithAccessToken(final String accessToken) {
    final String timestamp = "" + mWiz.getTimestamp();
    final String deviceId = mWiz.getDeviceId();
    final String registrationId = mWiz.getRegistrationId();
    final String installId = mWiz.getInstallationId();
    // Make call to Rogerthat webfarm
    final ProgressDialog progressDialog = new ProgressDialog(RegistrationActivity2.this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog/*from w  w  w .  j  av  a2  s. c o m*/
            .setMessage(getString(R.string.registration_activating_account, getString(R.string.app_name)));
    progressDialog.setCancelable(false);
    progressDialog.show();
    final SafeRunnable showErrorDialog = new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.UI();
            progressDialog.dismiss();
            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
            builder.setMessage(R.string.registration_facebook_error);
            builder.setPositiveButton(R.string.rogerthat, null);
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    };

    mWorkerHandler.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.REGISTRATION();
            String version = "1";
            String signature = Security.sha256(version + " " + installId + " " + timestamp + " " + deviceId
                    + " " + registrationId + " " + accessToken + CloudConstants.REGISTRATION_MAIN_SIGNATURE);

            HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_FACEBOOK_URL);
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(8);
                nameValuePairs.add(new BasicNameValuePair("version", version));
                nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp));
                nameValuePairs.add(new BasicNameValuePair("device_id", deviceId));
                nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId));
                nameValuePairs.add(new BasicNameValuePair("signature", signature));
                nameValuePairs.add(new BasicNameValuePair("install_id", installId));
                nameValuePairs.add(new BasicNameValuePair("access_token", accessToken));
                nameValuePairs.add(new BasicNameValuePair("language", Locale.getDefault().getLanguage()));
                nameValuePairs.add(new BasicNameValuePair("country", Locale.getDefault().getCountry()));
                nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID));
                nameValuePairs.add(
                        new BasicNameValuePair("use_xmpp_kick", CloudConstants.USE_XMPP_KICK_CHANNEL + ""));
                nameValuePairs.add(new BasicNameValuePair("GCM_registration_id", mGCMRegistrationId));

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = mHttpClient.execute(httppost);

                int statusCode = response.getStatusLine().getStatusCode();
                HttpEntity entity = response.getEntity();

                if (entity == null) {
                    mUIHandler.post(showErrorDialog);
                    return;
                }

                @SuppressWarnings("unchecked")
                final Map<String, Object> responseMap = (Map<String, Object>) JSONValue
                        .parse(new InputStreamReader(entity.getContent()));

                if (statusCode != 200 || responseMap == null) {
                    if (statusCode == 500 && responseMap != null) {
                        final String errorMessage = (String) responseMap.get("error");
                        if (errorMessage != null) {
                            mUIHandler.post(new SafeRunnable() {
                                @Override
                                protected void safeRun() throws Exception {
                                    T.UI();
                                    progressDialog.dismiss();
                                    AlertDialog.Builder builder = new AlertDialog.Builder(
                                            RegistrationActivity2.this);
                                    builder.setMessage(errorMessage);
                                    builder.setPositiveButton(R.string.rogerthat, null);
                                    AlertDialog dialog = builder.create();
                                    dialog.show();
                                }
                            });
                            return;
                        }
                    }
                    mUIHandler.post(showErrorDialog);
                    return;
                }
                JSONObject account = (JSONObject) responseMap.get("account");
                final String email = (String) responseMap.get("email");
                mAgeAndGenderSet = (Boolean) responseMap.get("age_and_gender_set");
                final RegistrationInfo info = new RegistrationInfo(email,
                        new Credentials((String) account.get("account"), (String) account.get("password")));
                mUIHandler.post(new SafeRunnable() {
                    @Override
                    protected void safeRun() throws Exception {
                        T.UI();
                        mWiz.setEmail(email);
                        mWiz.save();
                        hideNotification();
                        tryConnect(progressDialog, 1, getString(R.string.registration_establish_connection,
                                email, getString(R.string.app_name)) + " ", info);
                    }
                });

            } catch (Exception e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            }
        }
    });
}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

private void onPinEntered() {

    final String pin = mEnterPinEditText.getText().toString();
    // Validate pin code
    if (!RegexPatterns.PIN.matcher(pin).matches()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
        builder.setMessage(R.string.registration_invalid_pin);
        builder.setPositiveButton(R.string.rogerthat, null);
        AlertDialog dialog = builder.create();
        dialog.show();
        return;/*  ww w  .  j a va2s  .c  o  m*/
    }
    // Make call to Rogerthat webfarm
    final ProgressDialog progressDialog = new ProgressDialog(RegistrationActivity2.this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog
            .setMessage(getString(R.string.registration_activating_account, getString(R.string.app_name)));
    progressDialog.setCancelable(false);
    progressDialog.show();
    final SafeRunnable showErrorDialog = new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.UI();
            progressDialog.dismiss();
            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
            builder.setMessage(R.string.registration_sending_pin_error);
            builder.setPositiveButton(R.string.rogerthat, null);
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    };
    final String email = mWiz.getEmail();
    final String timestamp = "" + mWiz.getTimestamp();
    final String registrationId = mWiz.getRegistrationId();
    final String deviceId = mWiz.getDeviceId();

    mWorkerHandler.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.REGISTRATION();
            String version = "2";
            String pinSignature = Security.sha256(version + " " + email + " " + timestamp + " " + deviceId + " "
                    + registrationId + " " + pin + CloudConstants.REGISTRATION_PIN_SIGNATURE);

            HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_PIN_URL);
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
                nameValuePairs.add(new BasicNameValuePair("version", version));
                nameValuePairs.add(new BasicNameValuePair("email", email));
                nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp));
                nameValuePairs.add(new BasicNameValuePair("device_id", deviceId));
                nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId));
                nameValuePairs.add(new BasicNameValuePair("pin_code", pin));
                nameValuePairs.add(new BasicNameValuePair("pin_signature", pinSignature));
                nameValuePairs.add(new BasicNameValuePair("request_id", UUID.randomUUID().toString()));
                nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID));
                nameValuePairs.add(
                        new BasicNameValuePair("use_xmpp_kick", CloudConstants.USE_XMPP_KICK_CHANNEL + ""));
                nameValuePairs.add(new BasicNameValuePair("GCM_registration_id", mGCMRegistrationId));

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = mHttpClient.execute(httppost);
                int statusCode = response.getStatusLine().getStatusCode();
                HttpEntity entity = response.getEntity();
                if (statusCode != 200 || entity == null) {
                    mUIHandler.post(showErrorDialog);
                    return;
                }
                @SuppressWarnings("unchecked")
                final Map<String, Object> responseMap = (Map<String, Object>) org.json.simple.JSONValue
                        .parse(new InputStreamReader(entity.getContent()));
                if ("success".equals(responseMap.get("result"))) {

                    JSONObject account = (JSONObject) responseMap.get("account");
                    final RegistrationInfo info = new RegistrationInfo(email,
                            new Credentials((String) account.get("account"), (String) account.get("password")));

                    mAgeAndGenderSet = (Boolean) responseMap.get("age_and_gender_set");
                    mUIHandler.post(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            T.UI();
                            hideNotification();
                            tryConnect(progressDialog, 1, getString(R.string.registration_establish_connection,
                                    email, getString(R.string.app_name)) + " ", info);
                        }
                    });
                } else {

                    final long attempts_left = (Long) responseMap.get("attempts_left");
                    mUIHandler.post(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            T.UI();
                            progressDialog.dismiss();
                            if (attempts_left > 0) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(
                                        RegistrationActivity2.this);
                                builder.setMessage(getString(R.string.registration_incorrect_pin, email));
                                builder.setTitle(getString(R.string.registration_incorrect_pin_dialog_title));
                                builder.setPositiveButton(R.string.rogerthat, null);
                                AlertDialog dialog = builder.create();
                                dialog.show();
                                mEnterPinEditText.setText("");
                            } else {
                                hideNotification();
                                new AlertDialog.Builder(RegistrationActivity2.this)
                                        .setMessage(getString(R.string.registration_no_attempts_left))
                                        .setCancelable(true).setPositiveButton(R.string.try_again, null)
                                        .create().show();
                                mWiz.reInit();
                                mWiz.goBackToPrevious();
                                return;
                            }
                        }
                    });

                }
            } catch (Exception e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            }
        }
    });

}

From source file:au.com.wallaceit.reddinator.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = MainActivity.this;
    global = ((GlobalObjects) context.getApplicationContext());
    prefs = PreferenceManager.getDefaultSharedPreferences(context);
    setContentView(R.layout.activity_main);
    // Setup actionbar
    appView = findViewById(R.id.appview);
    actionBar = getActionBar();/*  w ww  . j a  v a2 s  .  com*/
    if (actionBar != null) {
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setCustomView(R.layout.appheader);
    }
    // get actionBar Views
    loader = (ProgressBar) findViewById(R.id.appsrloader);
    errorIcon = (ImageView) findViewById(R.id.apperroricon);
    refreshbutton = (ImageButton) findViewById(R.id.apprefreshbutton);
    configbutton = (ImageButton) findViewById(R.id.appprefsbutton);
    srtext = (TextView) findViewById(R.id.appsubreddittxt);

    // set theme colors
    setThemeColors();

    // setup button onclicks
    refreshbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            listAdapter.reloadReddits();
        }
    });

    View.OnClickListener srclick = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent srintent = new Intent(context, SubredditSelectActivity.class);
            startActivityForResult(srintent, 0);
        }
    };

    View.OnClickListener configclick = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent prefsintent = new Intent(context, PrefsActivity.class);
            prefsintent.putExtra("fromapp", true);
            startActivityForResult(prefsintent, 0);
        }
    };

    srtext.setOnClickListener(srclick);
    configbutton.setOnClickListener(configclick);
    findViewById(R.id.app_logo).setOnClickListener(srclick);

    // Setup list adapter
    listView = (ListView) findViewById(R.id.applistview);
    listAdapter = new ReddinatorListAdapter(global, prefs);
    listView.setAdapter(listAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            openLink(position, 1);
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            final int position = i;
            AlertDialog linkDialog = new AlertDialog.Builder(context).create(); //Read Update
            linkDialog.setTitle("Open in browser");

            linkDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Comments",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            openLink(position, 3);
                        }
                    });

            linkDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "Content",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            openLink(position, 2);
                        }
                    });

            linkDialog.show();
            return true;
        }
    });

    // set the current subreddit
    srtext.setText(prefs.getString("currentfeed-app", "technology"));

    // Trigger reload?
    if (prefs.getBoolean("appreloadpref", false) || listAdapter.getCount() < 2)
        listAdapter.reloadReddits();

}

From source file:com.fabernovel.alertevoirie.ReportDetailsActivity.java

@Override
public void onRequestcompleted(int requestCode, Object result) {
    timeoutHandler.removeCallbacks(timeout);
    if (mPd != null && mPd.isShowing()) {
        // clear pd from memory to avoid progress bar freeze when showed again
        removeDialog(DIALOG_PROGRESS);//from w w w  .  j av a  2 s. co  m
    }
    // //Log.d(Constants.PROJECT_TAG, "Request result " + (String) result);

    if (requestCode == AVService.REQUEST_IMAGE) {
        new AlertDialog.Builder(this).setMessage(R.string.news_photo_added)
                .setPositiveButton(android.R.string.ok, null).show();
        requestAdditionalPhotos();
        return;
    }

    if (requestCode == AVService.REQUEST_JSON && result != null) {
        try {
            JSONObject answer = new JSONArray((String) result).getJSONObject(0);
            boolean isIncident = JsonData.VALUE_REQUEST_NEW_INCIDENT
                    .equals(answer.getString(JsonData.PARAM_REQUEST));
            boolean isOk = (JsonData.VALUE_INCIDENT_SAVED == (answer.getJSONObject(JsonData.PARAM_ANSWER)
                    .getInt(JsonData.PARAM_STATUS)));

            if (isIncident && isOk) {
                /*
                 * FileInputStream fis_close = openFileInput(CAPTURE_CLOSE);
                 * FileInputStream fis_far = openFileInput(CAPTURE_FAR);
                 */

                File img_close = new File(getFilesDir() + "/" + CAPTURE_CLOSE);
                if (!img_close.exists()
                        || ((ImageView) findViewById(R.id.ImageView_close)).getDrawable() == null) {
                    img_close = null;
                }
                File img_far = new File(getFilesDir() + "/" + CAPTURE_ARROW);
                if (!img_far.exists() || ((ImageView) findViewById(R.id.ImageView_far)).getDrawable() == null) {
                    img_far = null;
                }

                // if (!img_far.exists()) {
                // img_far = new File(getFilesDir() + "/" + CAPTURE_FAR);
                // }

                // TODO add a listener which handles commands properly
                AVService.getInstance(this).postImage(null, Utils.getUdid(this), img_comment,
                        answer.getJSONObject(JsonData.PARAM_ANSWER).getString(JsonData.ANSWER_INCIDENT_ID),
                        img_far, img_close, true);
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                AlertDialog alert;
                builder.setMessage(R.string.report_detail_new_report_ok).setCancelable(false)
                        .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                finish();
                            }
                        });
                alert = builder.create();
                alert.show();
            } else {

                // hotfix nico : here we can have valid answer for incident updates !!!
                // handle answer and display popup here instead of when we click on buttons
                int statuscode = answer.getJSONObject(JsonData.PARAM_ANSWER).getInt(JsonData.PARAM_STATUS);

                if (statuscode == 0) {
                    // FIXME end activity when resolve incident ??
                    switch (mCurrentAction) {
                    case ACTION_GET_IMAGES:
                        //Log.d("AlerteVoirie_PM", "images : " + result);
                        JSONArray imgList = answer.getJSONObject(JsonData.PARAM_ANSWER)
                                .getJSONArray(JsonData.PARAM_PHOTOS);
                        ViewGroup photocontainer = (ViewGroup) findViewById(R.id.extra_images_container);
                        photocontainer.removeAllViews();
                        LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
                                LayoutParams.WRAP_CONTENT);
                        for (int i = 0; i < imgList.length() - 2; i++) {
                            JSONObject imgObj = imgList.getJSONObject(i);
                            //Log.d("AlerteVoirie_PM", "received image obj : " + imgObj);
                            View v = getLayoutInflater().inflate(R.layout.extra_photo, null);
                            v.setLayoutParams(params);
                            TextView date = (TextView) v.findViewById(R.id.textView_date);
                            TextView comment = (TextView) v.findViewById(R.id.textView_comment);
                            ImageView icon = (ImageView) v.findViewById(R.id.imageView_icon);

                            // format date
                            String dateString = imgObj.getString(JsonData.PARAM_IMAGES_DATE);
                            date.setText(getFormatedDate(dateString));

                            comment.setText(imgObj.getString(JsonData.PARAM_IMAGES_COMMENT));
                            imgd.download(imgObj.getString(JsonData.PARAM_IMAGES_URL), icon);
                            photocontainer.addView(v);
                        }
                        if (imgList.length() > 2) {
                            findViewById(R.id.TextView_additional_photos_header).setVisibility(View.VISIBLE);
                        } else {
                            findViewById(R.id.TextView_additional_photos_header).setVisibility(View.GONE);
                        }
                        break;
                    case ACTION_CONFIRM_INCIDENT:
                        findViewById(R.id.existing_incidents_confirmed).setEnabled(false);
                        new AlertDialog.Builder(this).setMessage(R.string.news_incidents_confirmed)
                                .setPositiveButton(android.R.string.ok, null).show();
                        break;
                    case ACTION_INVALID_INCIDENT: {
                        AlertDialog dialog = new AlertDialog.Builder(this)
                                .setMessage(R.string.news_incidents_invalidated)
                                .setPositiveButton(android.R.string.ok, null).create();
                        dialog.setOnDismissListener(new OnDismissListener() {
                            @Override
                            public void onDismiss(DialogInterface dialog) {
                                finish();
                            }
                        });
                        dialog.show();
                        break;
                    }
                    case ACTION_SOLVE_INCIDENT: {
                        AlertDialog dialog = new AlertDialog.Builder(this)
                                .setMessage(R.string.news_incidents_resolved)
                                .setPositiveButton(android.R.string.ok, null).create();
                        dialog.setOnDismissListener(new OnDismissListener() {
                            @Override
                            public void onDismiss(DialogInterface dialog) {
                                finish();
                            }
                        });
                        dialog.show();
                        break;
                    }
                    default:
                        // assume it's a generic update request in other cases ...
                        new AlertDialog.Builder(this).setMessage(R.string.report_detail_update_ok)
                                .setPositiveButton(android.R.string.ok, null).show();
                        break;
                    }
                } else {
                    // other things
                    // FIXME show popups instead of toasts !
                    if ((answer.getJSONObject(JsonData.PARAM_ANSWER).getInt(JsonData.PARAM_STATUS)) == 18) {
                        findViewById(R.id.existing_incidents_confirmed).setEnabled(false);
                        Toast.makeText(this, getString(R.string.incident_already_confirmed), Toast.LENGTH_LONG)
                                .show();
                    } else {
                        //Log.d("AlerteVoirie_PM", "erreur ?");
                        Toast.makeText(this, getString(R.string.server_error), Toast.LENGTH_LONG).show();
                    }
                }
            }
        } catch (JSONException e) {
            Log.e(Constants.PROJECT_TAG, "Erreur d'envoi d'image", e);
        } /*
           * catch (FileNotFoundException e) {
           * // TODO Auto-generated catch block
           * Log.e(Constants.PROJECT_TAG,"File not found",e);
           * }
           */

    } else if (requestCode == AVService.REQUEST_ERROR) {
        AVServiceErrorException error = (AVServiceErrorException) result;
        String errorString = null;
        switch (error.errorCode) {
        case 19:
            // already invalidated
            errorString = getString(R.string.error_already_invalidated);
            break;

        default:
            errorString = getString(R.string.server_error);
            break;
        }

        new AlertDialog.Builder(this).setTitle(R.string.error_popup_title).setMessage(errorString)
                .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).show();
    }

}