Example usage for android.content DialogInterface cancel

List of usage examples for android.content DialogInterface cancel

Introduction

In this page you can find the example usage for android.content DialogInterface cancel.

Prototype

void cancel();

Source Link

Document

Cancels the dialog, invoking the OnCancelListener .

Usage

From source file:com.duy.pascal.ui.editor.BaseEditorActivity.java

@Override
public void doRemoveFile(@NonNull final File file) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(getString(R.string.remove_file_msg) + " " + file.getName());
    builder.setTitle(R.string.delete_file);
    builder.setIcon(R.drawable.ic_delete_forever_white_24dp);
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override/*  w  ww. ja  va2s.com*/
        public void onClick(DialogInterface dialog, int which) {
            int position = mPagerAdapter.getPositionForTag(file.getPath());
            boolean success = FileUtils.deleteRecursive(file);
            if (success) {
                if (position >= 0) {
                    removePage(position);
                }
                Toast.makeText(getApplicationContext(), R.string.deleted, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), R.string.failed, Toast.LENGTH_SHORT).show();
            }

            //reload file
            FileExplorerView controller = (FileExplorerView) getSupportFragmentManager()
                    .findFragmentByTag("fragment_file_view");
            if (controller != null) {
                controller.refresh();
            } else {
                DLog.d(TAG, "onClick: Fragment file is null");
            }
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    builder.create().show();
}

From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java

protected void prolong(final String a) {
    long age = System.currentTimeMillis() - refreshtime;
    if (refreshing || age > MAX_CACHE_AGE) {
        Toast.makeText(getActivity(), R.string.account_no_concurrent, Toast.LENGTH_LONG).show();
        if (!refreshing) {
            refresh();//from www  . j av a2 s . c om
        }
        return;
    }

    MultiStepResultHelper<String> msrhProlong = new MultiStepResultHelper<>(getActivity(), a,
            R.string.doing_prolong);
    msrhProlong.setCallback(new Callback<String>() {
        @Override
        public void onSuccess(MultiStepResult result) {
            if (getActivity() == null) {
                return;
            }
            invalidateData();

            if (result.getMessage() != null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setMessage(result.getMessage()).setCancelable(false).setNegativeButton(R.string.close,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                AlertDialog alert = builder.create();
                alert.show();
            }
        }

        @Override
        public void onError(MultiStepResult result) {
            if (getActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setMessage(result.getMessage()).setCancelable(true)
                    .setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface d, int id) {
                            d.cancel();
                        }
                    }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface d) {
                            if (d != null) {
                                d.cancel();
                            }
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        }

        @Override
        public void onUnhandledResult(MultiStepResult result) {
        }

        @Override
        public void onUserCancel() {
        }

        @Override
        public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection,
                String argument) {
            return new ProlongTask(helper, useraction, selection, argument);
        }
    });
    msrhProlong.start();
}

From source file:com.balakrish.gpstracker.WaypointsListActivity.java

/**
 * Delete waypoint by id with confirmation dialog
 * /*from   w ww .ja  v  a2  s.co m*/
 * @param wpid
 */
private void deleteWaypoint(long wpid) {

    final long waypointId = wpid;

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(R.string.are_you_sure).setCancelable(true)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {

                    // delete waypoint from db

                    Waypoints.delete(app.getDatabase(), waypointId);

                    // cursor.requery();
                    updateWaypointsArray();

                    waypointsArrayAdapter.setItems(waypoints);
                    waypointsArrayAdapter.notifyDataSetChanged();

                    Toast.makeText(WaypointsListActivity.this, R.string.waypoint_deleted, Toast.LENGTH_SHORT)
                            .show();
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });

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

}

From source file:com.amazonaws.cognito.sync.demo.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    Log.i(TAG, "onCreate");

    /**/*from  w w  w  .j  a v a  2 s  .  co m*/
     * Initialize Facebook SDK
     */
    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();

    //Twitter
    if (mOauthConsumer == null) {
        mOauthProvider = new DefaultOAuthProvider("https://api.twitter.com/oauth/request_token",
                "https://api.twitter.com/oauth/access_token", "https://api.twitter.com/oauth/authorize");
        mOauthConsumer = new DefaultOAuthConsumer(getString(R.string.twitter_consumer_key),
                getString(R.string.twitter_consumer_secret));
    }
    retrieveTwitterCredentials(getIntent());

    //If access token is already here, set fb session
    final AccessToken fbAccessToken = AccessToken.getCurrentAccessToken();
    if (fbAccessToken != null) {
        setFacebookSession(fbAccessToken);
        btnLoginFacebook.setVisibility(View.GONE);
    }

    /**
     * Initializes the sync client. This must be call before you can use it.
     */
    CognitoSyncClientManager.init(this);

    btnLoginFacebook = (Button) findViewById(R.id.btnLoginFacebook);
    btnLoginFacebook.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // start Facebook Login
            LoginManager.getInstance().logInWithReadPermissions(MainActivity.this,
                    Arrays.asList("public_profile"));
            LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    btnLoginFacebook.setVisibility(View.GONE);
                    new GetFbName(loginResult).execute();
                    setFacebookSession(loginResult.getAccessToken());
                }

                @Override
                public void onCancel() {
                    Toast.makeText(MainActivity.this, "Facebook login cancelled", Toast.LENGTH_LONG).show();
                }

                @Override
                public void onError(FacebookException error) {
                    Toast.makeText(MainActivity.this, "Error in Facebook login " + error.getMessage(),
                            Toast.LENGTH_LONG).show();
                }
            });
        }
    });
    btnLoginFacebook.setEnabled(getString(R.string.facebook_app_id) != "facebook_app_id");

    try {
        mAuthManager = new AmazonAuthorizationManager(this, Bundle.EMPTY);
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "Login with Amazon isn't configured correctly. " + "Thus it's disabled in this demo.");
    }
    btnLoginLWA = (Button) findViewById(R.id.btnLoginLWA);
    btnLoginLWA.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mAuthManager.authorize(APP_SCOPES, Bundle.EMPTY, new AuthorizeListener());
        }
    });
    btnLoginLWA.setEnabled(mAuthManager != null);

    Button btnWipedata = (Button) findViewById(R.id.btnWipedata);
    btnWipedata.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(MainActivity.this).setTitle("Wipe data?")
                    .setMessage("This will log off your current session and wipe all user data. "
                            + "Any data not synchronized will be lost.")
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // clear login status
                            if (fbAccessToken != null) {
                                LoginManager.getInstance().logOut();
                            }
                            btnLoginFacebook.setVisibility(View.VISIBLE);
                            if (mAuthManager != null) {
                                mAuthManager.clearAuthorizationState(null);
                            }
                            btnLoginLWA.setVisibility(View.VISIBLE);
                            // wipe data
                            CognitoSyncClientManager.getInstance().wipeData();

                            // Wipe shared preferences
                            AmazonSharedPreferencesWrapper
                                    .wipe(PreferenceManager.getDefaultSharedPreferences(MainActivity.this));
                        }

                    }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    }).show();
        }
    });

    findViewById(R.id.btnListDatasets).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, ListDatasetsActivity.class);
            startActivity(intent);
        }
    });

    btnLoginDevAuth = (Button) findViewById(R.id.btnLoginDevAuth);
    if ((CognitoSyncClientManager.credentialsProvider
            .getIdentityProvider()) instanceof DeveloperAuthenticationProvider) {
        btnLoginDevAuth.setEnabled(true);
        Log.w(TAG, "Developer authentication feature configured correctly. ");
    } else {
        btnLoginDevAuth.setEnabled(false);
        Log.w(TAG, "Developer authentication feature configured incorrectly. "
                + "Thus it's disabled in this demo.");
    }
    btnLoginDevAuth.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // username and password dialog
            final Dialog login = new Dialog(MainActivity.this);
            login.setContentView(R.layout.login_dialog);
            login.setTitle("Sample developer login");
            final TextView txtUsername = (TextView) login.findViewById(R.id.txtUsername);
            txtUsername.setHint("Username");
            final TextView txtPassword = (TextView) login.findViewById(R.id.txtPassword);
            txtPassword.setHint("Password");
            Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
            Button btnCancel = (Button) login.findViewById(R.id.btnCancel);

            btnCancel.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    login.dismiss();
                }
            });

            btnLogin.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Validate the username and password
                    if (txtUsername.getText().toString().isEmpty()
                            || txtPassword.getText().toString().isEmpty()) {
                        new AlertDialog.Builder(MainActivity.this).setTitle("Login error")
                                .setMessage("Username or password cannot be empty!!").show();
                    } else {
                        // Clear the existing credentials
                        CognitoSyncClientManager.credentialsProvider.clearCredentials();
                        // Initiate user authentication against the
                        // developer backend in this case the sample Cognito
                        // developer authentication application.
                        ((DeveloperAuthenticationProvider) CognitoSyncClientManager.credentialsProvider
                                .getIdentityProvider()).login(txtUsername.getText().toString(),
                                        txtPassword.getText().toString(), MainActivity.this);
                    }
                    login.dismiss();
                }
            });
            login.show();
        }
    });

    /**
     * Button that leaves the app and launches the Twitter site to get an authorization.
     * If the user grants permissions to our app, it will be redirected to us again through
     * a callback.
     */
    Button btnLoginTwitter = (Button) findViewById(R.id.btnLoginTwitter);
    btnLoginTwitter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        String callbackUrl = "callback://" + getString(R.string.twitter_callback_url);
                        String authUrl = mOauthProvider.retrieveRequestToken(mOauthConsumer, callbackUrl);
                        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));
                        startActivity(intent);
                    } catch (Exception e) {
                        Log.w("oauth fail", e);
                    }
                }
            }).start();
        }
    });
    btnLoginTwitter.setEnabled(getString(R.string.twitter_consumer_secret) != "twitter_consumer_secret");

}

From source file:com.shafiq.myfeedle.core.MyfeedleCreatePost.java

@Override
public void onClick(View v) {
    if (v == mSend) {
        if (!mAccountsService.isEmpty()) {
            final ProgressDialog loadingDialog = new ProgressDialog(this);
            final AsyncTask<Void, String, Void> asyncTask = new AsyncTask<Void, String, Void>() {
                @Override//from w w w .ja v  a  2s . c om
                protected Void doInBackground(Void... arg0) {
                    Iterator<Map.Entry<Long, Integer>> entrySet = mAccountsService.entrySet().iterator();
                    while (entrySet.hasNext()) {
                        Map.Entry<Long, Integer> entry = entrySet.next();
                        final long accountId = entry.getKey();
                        final int service = entry.getValue();
                        final String placeId = mAccountsLocation.get(accountId);
                        // post or comment!
                        Cursor account = getContentResolver().query(
                                Accounts.getContentUri(MyfeedleCreatePost.this),
                                new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET },
                                Accounts._ID + "=?", new String[] { Long.toString(accountId) }, null);
                        if (account.moveToFirst()) {
                            final String serviceName = Myfeedle.getServiceName(getResources(), service);
                            publishProgress(serviceName);
                            String message;
                            MyfeedleOAuth myfeedleOAuth;
                            HttpPost httpPost;
                            String response = null;
                            switch (service) {
                            case TWITTER:
                                myfeedleOAuth = new MyfeedleOAuth(TWITTER_KEY, TWITTER_SECRET,
                                        mMyfeedleCrypto.Decrypt(
                                                account.getString(account.getColumnIndex(Accounts.TOKEN))),
                                        mMyfeedleCrypto.Decrypt(
                                                account.getString(account.getColumnIndex(Accounts.SECRET))));
                                // limit tweets to 140, breaking up the message if necessary
                                message = mMessage.getText().toString();
                                while (message.length() > 0) {
                                    final String send;
                                    if (message.length() > 140) {
                                        // need to break on a word
                                        int end = 0;
                                        int nextSpace = 0;
                                        for (int i = 0, i2 = message.length(); i < i2; i++) {
                                            end = nextSpace;
                                            if (message.substring(i, i + 1).equals(" ")) {
                                                nextSpace = i;
                                            }
                                        }
                                        // in case there are no spaces, just break on 140
                                        if (end == 0) {
                                            end = 140;
                                        }
                                        send = message.substring(0, end);
                                        message = message.substring(end + 1);
                                    } else {
                                        send = message;
                                        message = "";
                                    }
                                    httpPost = new HttpPost(String.format(TWITTER_UPDATE, TWITTER_BASE_URL));
                                    // resolve Error 417 Expectation by Twitter
                                    httpPost.getParams().setBooleanParameter("http.protocol.expect-continue",
                                            false);
                                    List<NameValuePair> params = new ArrayList<NameValuePair>();
                                    params.add(new BasicNameValuePair(Sstatus, send));
                                    if (placeId != null) {
                                        params.add(new BasicNameValuePair("place_id", placeId));
                                        params.add(new BasicNameValuePair("lat", mLat));
                                        params.add(new BasicNameValuePair("long", mLong));
                                    }
                                    try {
                                        httpPost.setEntity(new UrlEncodedFormEntity(params));
                                        response = MyfeedleHttpClient.httpResponse(mHttpClient,
                                                myfeedleOAuth.getSignedRequest(httpPost));
                                    } catch (UnsupportedEncodingException e) {
                                        Log.e(TAG, e.toString());
                                    }
                                    publishProgress(serviceName,
                                            getString(response != null ? R.string.success : R.string.failure));
                                }
                                break;
                            case FACEBOOK:
                                // handle tags
                                StringBuilder tags = null;
                                if (mAccountsTags.containsKey(accountId)) {
                                    String[] accountTags = mAccountsTags.get(accountId);
                                    if ((accountTags != null) && (accountTags.length > 0)) {
                                        tags = new StringBuilder();
                                        tags.append("[");
                                        String tag_format;
                                        if (mPhotoPath != null)
                                            tag_format = "{\"tag_uid\":\"%s\",\"x\":0,\"y\":0}";
                                        else
                                            tag_format = "%s";
                                        for (int i = 0, l = accountTags.length; i < l; i++) {
                                            if (i > 0)
                                                tags.append(",");
                                            tags.append(String.format(tag_format, accountTags[i]));
                                        }
                                        tags.append("]");
                                    }
                                }
                                if (mPhotoPath != null) {
                                    // upload photo
                                    // uploading a photo takes a long time, have the service handle it
                                    Intent i = Myfeedle.getPackageIntent(
                                            MyfeedleCreatePost.this.getApplicationContext(),
                                            PhotoUploadService.class);
                                    i.setAction(Myfeedle.ACTION_UPLOAD);
                                    i.putExtra(Accounts.TOKEN,
                                            account.getString(account.getColumnIndex(Accounts.TOKEN)));
                                    i.putExtra(Widgets.INSTANT_UPLOAD, mPhotoPath);
                                    i.putExtra(Statuses.MESSAGE, mMessage.getText().toString());
                                    i.putExtra(Splace, placeId);
                                    if (tags != null)
                                        i.putExtra(Stags, tags.toString());
                                    startService(i);
                                    publishProgress(serviceName + " photo");
                                } else {
                                    // regular post
                                    httpPost = new HttpPost(String.format(FACEBOOK_POST, FACEBOOK_BASE_URL,
                                            Saccess_token, mMyfeedleCrypto.Decrypt(account
                                                    .getString(account.getColumnIndex(Accounts.TOKEN)))));
                                    List<NameValuePair> params = new ArrayList<NameValuePair>();
                                    params.add(new BasicNameValuePair(Smessage, mMessage.getText().toString()));
                                    if (placeId != null)
                                        params.add(new BasicNameValuePair(Splace, placeId));
                                    if (tags != null)
                                        params.add(new BasicNameValuePair(Stags, tags.toString()));
                                    try {
                                        httpPost.setEntity(new UrlEncodedFormEntity(params));
                                        response = MyfeedleHttpClient.httpResponse(mHttpClient, httpPost);
                                    } catch (UnsupportedEncodingException e) {
                                        Log.e(TAG, e.toString());
                                    }
                                    publishProgress(serviceName,
                                            getString(response != null ? R.string.success : R.string.failure));
                                }
                                break;
                            case MYSPACE:
                                myfeedleOAuth = new MyfeedleOAuth(MYSPACE_KEY, MYSPACE_SECRET,
                                        mMyfeedleCrypto.Decrypt(
                                                account.getString(account.getColumnIndex(Accounts.TOKEN))),
                                        mMyfeedleCrypto.Decrypt(
                                                account.getString(account.getColumnIndex(Accounts.SECRET))));
                                try {
                                    HttpPut httpPut = new HttpPut(
                                            String.format(MYSPACE_URL_STATUSMOOD, MYSPACE_BASE_URL));
                                    httpPut.setEntity(new StringEntity(String.format(MYSPACE_STATUSMOOD_BODY,
                                            mMessage.getText().toString())));
                                    response = MyfeedleHttpClient.httpResponse(mHttpClient,
                                            myfeedleOAuth.getSignedRequest(httpPut));
                                } catch (IOException e) {
                                    Log.e(TAG, e.toString());
                                }
                                // warn users about myspace permissions
                                if (response != null) {
                                    publishProgress(serviceName, getString(R.string.success));
                                } else {
                                    publishProgress(serviceName, getString(R.string.failure) + " "
                                            + getString(R.string.myspace_permissions_message));
                                }
                                break;
                            case FOURSQUARE:
                                try {
                                    message = URLEncoder.encode(mMessage.getText().toString(), "UTF-8");
                                    if (placeId != null) {
                                        if (message != null) {
                                            httpPost = new HttpPost(String.format(FOURSQUARE_CHECKIN,
                                                    FOURSQUARE_BASE_URL, placeId, message, mLat, mLong,
                                                    mMyfeedleCrypto.Decrypt(account.getString(
                                                            account.getColumnIndex(Accounts.TOKEN)))));
                                        } else {
                                            httpPost = new HttpPost(String.format(FOURSQUARE_CHECKIN_NO_SHOUT,
                                                    FOURSQUARE_BASE_URL, placeId, mLat, mLong,
                                                    mMyfeedleCrypto.Decrypt(account.getString(
                                                            account.getColumnIndex(Accounts.TOKEN)))));
                                        }
                                    } else {
                                        httpPost = new HttpPost(String.format(FOURSQUARE_CHECKIN_NO_VENUE,
                                                FOURSQUARE_BASE_URL, message, mMyfeedleCrypto.Decrypt(account
                                                        .getString(account.getColumnIndex(Accounts.TOKEN)))));
                                    }
                                    response = MyfeedleHttpClient.httpResponse(mHttpClient, httpPost);
                                } catch (UnsupportedEncodingException e) {
                                    Log.e(TAG, e.toString());
                                }
                                publishProgress(serviceName,
                                        getString(response != null ? R.string.success : R.string.failure));
                                break;
                            case LINKEDIN:
                                myfeedleOAuth = new MyfeedleOAuth(LINKEDIN_KEY, LINKEDIN_SECRET,
                                        mMyfeedleCrypto.Decrypt(
                                                account.getString(account.getColumnIndex(Accounts.TOKEN))),
                                        mMyfeedleCrypto.Decrypt(
                                                account.getString(account.getColumnIndex(Accounts.SECRET))));
                                try {
                                    httpPost = new HttpPost(String.format(LINKEDIN_POST, LINKEDIN_BASE_URL));
                                    httpPost.setEntity(new StringEntity(String.format(LINKEDIN_POST_BODY, "",
                                            mMessage.getText().toString())));
                                    httpPost.addHeader(new BasicHeader("Content-Type", "application/xml"));
                                    response = MyfeedleHttpClient.httpResponse(mHttpClient,
                                            myfeedleOAuth.getSignedRequest(httpPost));
                                } catch (IOException e) {
                                    Log.e(TAG, e.toString());
                                }
                                publishProgress(serviceName,
                                        getString(response != null ? R.string.success : R.string.failure));
                                break;
                            case IDENTICA:
                                myfeedleOAuth = new MyfeedleOAuth(IDENTICA_KEY, IDENTICA_SECRET,
                                        mMyfeedleCrypto.Decrypt(
                                                account.getString(account.getColumnIndex(Accounts.TOKEN))),
                                        mMyfeedleCrypto.Decrypt(
                                                account.getString(account.getColumnIndex(Accounts.SECRET))));
                                // limit tweets to 140, breaking up the message if necessary
                                message = mMessage.getText().toString();
                                while (message.length() > 0) {
                                    final String send;
                                    if (message.length() > 140) {
                                        // need to break on a word
                                        int end = 0;
                                        int nextSpace = 0;
                                        for (int i = 0, i2 = message.length(); i < i2; i++) {
                                            end = nextSpace;
                                            if (message.substring(i, i + 1).equals(" ")) {
                                                nextSpace = i;
                                            }
                                        }
                                        // in case there are no spaces, just break on 140
                                        if (end == 0) {
                                            end = 140;
                                        }
                                        send = message.substring(0, end);
                                        message = message.substring(end + 1);
                                    } else {
                                        send = message;
                                        message = "";
                                    }
                                    httpPost = new HttpPost(String.format(IDENTICA_UPDATE, IDENTICA_BASE_URL));
                                    // resolve Error 417 Expectation by Twitter
                                    httpPost.getParams().setBooleanParameter("http.protocol.expect-continue",
                                            false);
                                    List<NameValuePair> params = new ArrayList<NameValuePair>();
                                    params.add(new BasicNameValuePair(Sstatus, send));
                                    if (placeId != null) {
                                        params.add(new BasicNameValuePair("place_id", placeId));
                                        params.add(new BasicNameValuePair("lat", mLat));
                                        params.add(new BasicNameValuePair("long", mLong));
                                    }
                                    try {
                                        httpPost.setEntity(new UrlEncodedFormEntity(params));
                                        response = MyfeedleHttpClient.httpResponse(mHttpClient,
                                                myfeedleOAuth.getSignedRequest(httpPost));
                                    } catch (UnsupportedEncodingException e) {
                                        Log.e(TAG, e.toString());
                                    }
                                    publishProgress(serviceName,
                                            getString(response != null ? R.string.success : R.string.failure));
                                }
                                break;
                            case CHATTER:
                                // need to get an updated access_token
                                response = MyfeedleHttpClient.httpResponse(mHttpClient, new HttpPost(
                                        String.format(CHATTER_URL_ACCESS, CHATTER_KEY, mMyfeedleCrypto.Decrypt(
                                                account.getString(account.getColumnIndex(Accounts.TOKEN))))));
                                if (response != null) {
                                    try {
                                        JSONObject jobj = new JSONObject(response);
                                        if (jobj.has("instance_url") && jobj.has(Saccess_token)) {
                                            httpPost = new HttpPost(String.format(CHATTER_URL_POST,
                                                    jobj.getString("instance_url"),
                                                    Uri.encode(mMessage.getText().toString())));
                                            httpPost.setHeader("Authorization",
                                                    "OAuth " + jobj.getString(Saccess_token));
                                            response = MyfeedleHttpClient.httpResponse(mHttpClient, httpPost);
                                        }
                                    } catch (JSONException e) {
                                        Log.e(TAG, serviceName + ":" + e.toString());
                                        Log.e(TAG, response);
                                    }
                                }
                                publishProgress(serviceName,
                                        getString(response != null ? R.string.success : R.string.failure));
                                break;
                            }
                        }
                        account.close();
                    }
                    return null;
                }

                @Override
                protected void onProgressUpdate(String... params) {
                    if (params.length == 1) {
                        loadingDialog.setMessage(String.format(getString(R.string.sending), params[0]));
                    } else {
                        (Toast.makeText(MyfeedleCreatePost.this, params[0] + " " + params[1],
                                Toast.LENGTH_LONG)).show();
                    }
                }

                @Override
                protected void onPostExecute(Void result) {
                    if (loadingDialog.isShowing())
                        loadingDialog.dismiss();
                    finish();
                }

            };
            loadingDialog.setMessage(getString(R.string.loading));
            loadingDialog.setCancelable(true);
            loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    if (!asyncTask.isCancelled())
                        asyncTask.cancel(true);
                }
            });
            loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
            loadingDialog.show();
            asyncTask.execute();
        } else
            (Toast.makeText(MyfeedleCreatePost.this, "no accounts selected", Toast.LENGTH_LONG)).show();
    }
}

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

private void showWidgetThemeDialog() {

    // set themes list
    LinkedHashMap<String, String> themeList = global.mThemeManager.getThemeList(ThemeManager.LISTMODE_ALL);
    themeList.put("app_select", "Use App theme");
    final String[] keys = themeList.keySet().toArray(new String[themeList.keySet().size()]);
    String curTheme = mSharedPreferences.getString("widgettheme-" + mAppWidgetId, "app_select");
    int curIndex = 0;
    for (int i = 0; i < keys.length; i++) {
        if (keys[i].equals(curTheme)) {
            curIndex = i;//from w w w. ja v  a  2 s  .c o  m
            break;
        }
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Select Widget Theme")
            .setSingleChoiceItems(themeList.values().toArray(new String[themeList.values().size()]), curIndex,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            needsThemeUpdate = true;
                            SharedPreferences.Editor editor = mSharedPreferences.edit();
                            editor.putString("widgettheme-" + mAppWidgetId, keys[i]);
                            System.out.println(keys[i]);
                            editor.apply();
                            dialogInterface.cancel();
                        }
                    })
            .setPositiveButton("Close", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            }).show();
}

From source file:com.balakrish.gpstracker.WaypointsListActivity.java

/**
  * /*ww  w.  j  a  va  2  s  .  c o m*/
  */
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    // Handle item selection
    switch (item.getItemId()) {

    case R.id.deleteWaypointsMenuItem:

        // clear all waypoints with confirmation dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.are_you_sure).setCancelable(true)
                .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                        Waypoints.deleteAll(app.getDatabase());

                        updateWaypointsArray();// cursor.requery();

                        waypointsArrayAdapter.setItems(waypoints);
                        waypointsArrayAdapter.notifyDataSetChanged();

                        Toast.makeText(WaypointsListActivity.this, R.string.all_waypoints_deleted,
                                Toast.LENGTH_SHORT).show();

                    }

                }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();

        alert.show();

        return true;

    // import waypoints from external file
    case R.id.importMenuItem:

        // this.importFromTextFile();

        this.importFromXMLFile();

        return true;

    case R.id.exportMenuItem:

        exportWaypoints();

        return true;

    case R.id.showMapMenuItem:

        // startActivity(new Intent(this, WaypointsMapActivity.class));

        Intent i = new Intent(this, MyMapActivity.class);

        // using Bundle to pass track id into new activity
        Bundle b = new Bundle();
        b.putInt("mode", Constants.SHOW_ALL_WAYPOINTS);

        i.putExtras(b);
        startActivity(i);

        return true;

    default:

        return super.onOptionsItemSelected(item);

    }

}

From source file:com.fbbackup.MyFriendFragmentActivity.java

/**
 * gback//from  w w  w.  j ava 2s  . co  m
 */
@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();

    // pGfragmnet stackOq0AN?efragment
    if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
        controlPanelHandler.sendEmptyMessage(SHOW_CONTROL_PANEL);
    } else if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
        // MainActivity.exitHandler.sendEmptyMessage(0);

        AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(MyFriendFragmentActivity.this);

        // Setting Dialog Title
        alertDialog2.setTitle(getString(R.string.exit_app_tittle));

        // Setting Dialog Message
        alertDialog2.setMessage(getString(R.string.exit_app_text));

        // Setting Icon to Dialog
        // alertDialog2.setIcon(R.drawable.delete);

        // Setting Positive "Yes" Btn
        alertDialog2.setPositiveButton("YES", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // Write your code here to execute after dialog
                exit();
                System.exit(0);
            }
        });
        // Setting Negative "NO" Btn
        alertDialog2.setNegativeButton("NO", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // Write your code here to execute after dialog

                Fragment newFragment = new MyFriendFragment();

                Bundle args = new Bundle();
                args.putStringArray("friendPic", friendsPicture);
                args.putStringArray("friendName", friendsName);
                args.putStringArray("friendID", friendsID);
                args.putString("token", token);

                newFragment.setArguments(args);

                FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                ft.replace(R.id.rl_user_photo, newFragment, "first");

                ft.addToBackStack(null);

                ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

                ft.commit();

                dialog.cancel();
            }
        });

        // Showing Alert Dialog
        alertDialog2.show();

    }
    Log.w("dow", "getSupportFragmentManager().getBackStackEntryCount():"
            + getSupportFragmentManager().getBackStackEntryCount());
    // press back popup alertdialog ask finish this app

}

From source file:com.VVTeam.ManHood.Fragment.HistogramFragment.java

private void showClosestNeedMesurementMessage() {

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());

    // set title/*from  w w w .  j a  v a2  s. co  m*/
    alertDialogBuilder.setTitle("Measurement needed to see the Area around you");

    // set dialog message
    alertDialogBuilder.setMessage("To see the close by, you need to get yourself measured").setCancelable(false)
            .setPositiveButton("How-To", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                    ((MainActivity) getActivity()).openGuideActivity();

                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // if this button is clicked, just close
                    // the dialog box and do nothing
                    dialog.cancel();
                }
            });

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();
}

From source file:com.VVTeam.ManHood.Fragment.HistogramFragment.java

private void showMesurementMessage() {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());

    // set title//ww w.j  av  a  2 s .  c  o m
    alertDialogBuilder.setTitle("Mapping the world, Hood by Hood");

    // set dialog message
    alertDialogBuilder.setMessage("Start with yourself first").setCancelable(false)
            .setPositiveButton("How-To", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                    ((MainActivity) getActivity()).openGuideActivity();

                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // if this button is clicked, just close
                    // the dialog box and do nothing
                    dialog.cancel();
                }
            });

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();

}