Example usage for android.app AlertDialog.Builder setCancelable

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

Introduction

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

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

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

Usage

From source file:com.almunt.jgcaap.systemupdater.MainActivity.java

public void About(boolean about) {
    AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
    if (about) {//from  w  w w  .jav a 2s.c  o m
        builder1.setMessage(
                "The updater is designed and developed by AlMunt for the latest cm13 based jgcaap rom. I am NOT responsible for any damage caused to this device\nGo to Jgcaap's xda page for the cm13 based Oneplus One rom for support on the downloaded files.\nEmail me at munt.alexandru@gmail.com for feedback on this app.");
        builder1.setTitle("About");
    } else {
        builder1.setTitle("How to Use");
        builder1.setMessage(" Swipe down to get latest available updates"
                + " Once a rom is selected it will immediately start downloading. You may delete a rom by long pressing it and tapping \"delete\"."
                + " All downloads are stored in a Jgcaap folder in the sdcard. You will have an option to use automatic installation in TWRP with OpenRecoveryScript."
                + " You may clear the OpenRecoveryScript file through the \"Reboot into recovery\" menu in the slide out navigation bar or the \"3 dots\"."
                + "\nReboot into recovery to run the OpenRecoveryScript."
                + "Note: The storage permission needs to be accepted in order to download updates to the sdcard and root access is required if you want automatic installation of the rom through TWRP.");
    }
    builder1.setCancelable(true);
    builder1.setPositiveButton("Close", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });
    AlertDialog alert11 = builder1.create();
    alert11.show();
}

From source file:com.gigathinking.simpleapplock.MainActivity.java

private void showRatingDialog() {
    mPrefs.edit().putBoolean("rating_dialog_showing", true).commit();
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    AlertDialog dialog;/*ww  w  .  j  ava 2 s .c o m*/
    builder.setTitle(getString(R.string.please_rate));
    builder.setMessage(getString(R.string.please_rate_message));
    builder.setPositiveButton(getString(R.string.rate_it), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            mPrefs.edit().putString("rating", "RATED").commit();
            Intent marketIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://market.android.com/details?id=" + getPackageName()));
            startActivity(marketIntent);
            mPrefs.edit().putBoolean("rating_dialog_showing", false).commit();
            dialog.dismiss();
        }
    });
    builder.setNegativeButton(getString(R.string.not_interested), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            mPrefs.edit().putString("rating", "Not Interested").commit();
            mPrefs.edit().putBoolean("rating_dialog_showing", false).commit();
            dialog.dismiss();
        }
    });
    builder.setNeutralButton(getString(R.string.may_be_later), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            mPrefs.edit().putString("rating", "May be later").commit();
            mPrefs.edit().putInt("launch_count", 0).commit();
            mPrefs.edit().putBoolean("rating_dialog_showing", false).commit();
            dialog.dismiss();
        }
    });
    builder.setCancelable(false);
    dialog = builder.create();
    dialog.show();
}

From source file:com.owncloud.android.authentication.AuthenticatorActivity.java

/**
 * {@inheritDoc}// w  ww.j av a  2 s.  c  o  m
 */
@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog = null;
    switch (id) {
    case DIALOG_LOGIN_PROGRESS: {
        // / simple progress dialog
        ProgressDialog working_dialog = new ProgressDialog(this);
        working_dialog.setMessage(getResources().getString(R.string.auth_trying_to_login));
        working_dialog.setIndeterminate(true);
        working_dialog.setCancelable(true);
        working_dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                // / TODO study if this is enough
                Log_OC.i(TAG, "Login canceled");
                if (mOperationThread != null) {
                    mOperationThread.interrupt();
                    finish();
                }
            }
        });
        dialog = working_dialog;
        break;
    }
    case DIALOG_OAUTH2_LOGIN_PROGRESS: {
        ProgressDialog working_dialog = new ProgressDialog(this);
        working_dialog.setMessage(String.format("Getting authorization"));
        working_dialog.setIndeterminate(true);
        working_dialog.setCancelable(true);
        working_dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                Log_OC.i(TAG, "Login canceled");
                finish();
            }
        });
        dialog = working_dialog;
        break;
    }
    case DIALOG_SSL_VALIDATOR: {
        // / TODO start to use new dialog interface, at least for this (it
        // is a FragmentDialog already)
        dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this);
        break;
    }
    case DIALOG_CERT_NOT_SAVED: {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            };
        });
        dialog = builder.create();
        break;
    }
    default:
        Log_OC.e(TAG, "Incorrect dialog called with id = " + id);
    }
    return dialog;
}

From source file:com.cerema.cloud2.ui.activity.Uploader.java

@Override
protected Dialog onCreateDialog(final int id) {
    final AlertDialog.Builder builder = new Builder(this);
    switch (id) {
    case DIALOG_WAITING:
        final ProgressDialog pDialog = new ProgressDialog(this, R.style.ProgressDialogTheme);
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);//from w w w. j  a  v a 2 s .c o m
        pDialog.setMessage(getResources().getString(R.string.uploader_info_uploading));
        pDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                ProgressBar v = (ProgressBar) pDialog.findViewById(android.R.id.progress);
                v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.color_accent),
                        android.graphics.PorterDuff.Mode.MULTIPLY);

            }
        });
        return pDialog;
    case DIALOG_NO_ACCOUNT:
        builder.setIcon(R.drawable.ic_warning);
        builder.setTitle(R.string.uploader_wrn_no_account_title);
        builder.setMessage(
                String.format(getString(R.string.uploader_wrn_no_account_text), getString(R.string.app_name)));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) {
                    // using string value since in API7 this
                    // constant is not defined
                    // in API7 < this constant is defined in
                    // Settings.ADD_ACCOUNT_SETTINGS
                    // and Settings.EXTRA_AUTHORITIES
                    Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
                    intent.putExtra("authorities", new String[] { MainApp.getAuthTokenType() });
                    startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
                } else {
                    // since in API7 there is no direct call for
                    // account setup, so we need to
                    // show our own AccountSetupAcricity, get
                    // desired results and setup
                    // everything for ourself
                    Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class);
                    startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
                }
            }
        });
        builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        return builder.create();
    case DIALOG_MULTIPLE_ACCOUNT:
        CharSequence ac[] = new CharSequence[mAccountManager
                .getAccountsByType(MainApp.getAccountType()).length];
        for (int i = 0; i < ac.length; ++i) {
            ac[i] = DisplayUtils.convertIdn(mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name,
                    false);
        }
        builder.setTitle(R.string.common_choose_account);
        builder.setItems(ac, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]);
                onAccountSet(mAccountWasRestored);
                dialog.dismiss();
                mAccountSelected = true;
                mAccountSelectionShowing = false;
            }
        });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                mAccountSelectionShowing = false;
                dialog.cancel();
                finish();
            }
        });
        return builder.create();
    case DIALOG_NO_STREAM:
        builder.setIcon(R.drawable.ic_warning);
        builder.setTitle(R.string.uploader_wrn_no_content_title);
        builder.setMessage(R.string.uploader_wrn_no_content_text);
        builder.setCancelable(false);
        builder.setNegativeButton(R.string.common_cancel, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        return builder.create();
    default:
        throw new IllegalArgumentException("Unknown dialog id: " + id);
    }
}

From source file:com.synox.android.ui.activity.Uploader.java

@Override
protected Dialog onCreateDialog(final int id) {
    final AlertDialog.Builder builder = new Builder(this);
    switch (id) {
    case DIALOG_WAITING:
        final ProgressDialog pDialog = new ProgressDialog(this, R.style.ProgressDialogTheme);
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);//  ww w .  ja  v  a 2s  .  c o m
        pDialog.setMessage(getResources().getString(R.string.uploader_info_uploading));
        pDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                ProgressBar v = (ProgressBar) pDialog.findViewById(android.R.id.progress);
                v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.accent),
                        android.graphics.PorterDuff.Mode.MULTIPLY);

            }
        });
        return pDialog;
    case DIALOG_NO_ACCOUNT:
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setTitle(R.string.uploader_wrn_no_account_title);
        builder.setMessage(
                String.format(getString(R.string.uploader_wrn_no_account_text), getString(R.string.app_name)));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) {
                    // using string value since in API7 this
                    // constatn is not defined
                    // in API7 < this constatant is defined in
                    // Settings.ADD_ACCOUNT_SETTINGS
                    // and Settings.EXTRA_AUTHORITIES
                    Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
                    intent.putExtra("authorities", new String[] { MainApp.getAuthTokenType() });
                    startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
                } else {
                    // since in API7 there is no direct call for
                    // account setup, so we need to
                    // show our own AccountSetupAcricity, get
                    // desired results and setup
                    // everything for ourself
                    Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class);
                    startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
                }
            }
        });
        builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        return builder.create();
    case DIALOG_MULTIPLE_ACCOUNT:
        CharSequence ac[] = new CharSequence[mAccountManager
                .getAccountsByType(MainApp.getAccountType()).length];
        for (int i = 0; i < ac.length; ++i) {
            ac[i] = DisplayUtils.convertIdn(mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name,
                    false);
        }
        builder.setTitle(R.string.common_choose_account);
        builder.setItems(ac, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]);
                onAccountSet(mAccountWasRestored);
                dialog.dismiss();
                mAccountSelected = true;
                mAccountSelectionShowing = false;
            }
        });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                mAccountSelectionShowing = false;
                dialog.cancel();
                finish();
            }
        });
        return builder.create();
    case DIALOG_NO_STREAM:
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setTitle(R.string.uploader_wrn_no_content_title);
        builder.setMessage(R.string.uploader_wrn_no_content_text);
        builder.setCancelable(false);
        builder.setNegativeButton(R.string.common_cancel, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        return builder.create();
    default:
        throw new IllegalArgumentException("Unknown dialog id: " + id);
    }
}

From source file:gr.scify.newsum.ui.ViewActivity.java

@Override
public void run() {
    // take the String from the TopicActivity
    Bundle extras = getIntent().getExtras();
    Category = extras.getString(CATEGORY_INTENT_VAR);

    // Make sure we have updated the data source
    NewSumUiActivity.setDataSource(this);

    // Get user sources
    String sUserSources = Urls.getUserVisibleURLsAsString(ViewActivity.this);

    // get Topics from TopicActivity (avoid multiple server calls)
    TopicInfo[] tiTopics = TopicActivity.getTopics(sUserSources, Category, this);

    // Also get Topic Titles, to display to adapter
    final String[] saTopicTitles = new String[tiTopics.length];
    // Also get Topic IDs
    final String[] saTopicIDs = new String[tiTopics.length];
    // Also get Dates, in order to show in summary title
    final String[] saTopicDates = new String[tiTopics.length];
    // DeHTML titles
    for (int iCnt = 0; iCnt < tiTopics.length; iCnt++) {
        // update Titles Array
        saTopicTitles[iCnt] = Html.fromHtml(tiTopics[iCnt].getTitle()).toString();
        // update IDs Array
        saTopicIDs[iCnt] = tiTopics[iCnt].getID();
        // update Date Array
        saTopicDates[iCnt] = tiTopics[iCnt].getPrintableDate(NewSumUiActivity.getDefaultLocale());
    }/*from w  w  w. j  a v a 2  s  .co  m*/
    // get the value of the TopicIDs list size (to use in swipe)
    saTopicIDsLength = saTopicIDs.length;
    final TextView title = (TextView) findViewById(R.id.title);
    // Fill topic spinner
    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item, saTopicTitles);

    final TextView tx = (TextView) findViewById(R.id.textView1);
    //      final float minm = tx.getTextSize();
    //      final float maxm = (minm + 24);

    // Get active topic
    int iTopicNum;
    // If we have returned from a pause
    if (iPrvSelectedItem >= 0)
        // use previous selection before pause
        iTopicNum = iPrvSelectedItem;
    // else
    else
        // use selection from topic page
        iTopicNum = extras.getInt(TOPIC_ID_INTENT_VAR);
    final int num = iTopicNum;

    // create an invisible spinner just to control the summaries of the
    // category (i will use it later on Swipe)
    final Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setAdapter(adapter);

            // Scroll view init
            final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1);
            final String[] saTopicTitlesArg = saTopicTitles;
            final String[] saTopicIDsArg = saTopicIDs;
            final String[] SaTopicDatesArg = saTopicDates;

            // Add selection event
            spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    // Changing summary
                    loading = true;
                    showWaitingDialog();
                    // Update visibility of rating bar
                    final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar);
                    rb.setRating(0.0f);
                    rb.setVisibility(View.VISIBLE);
                    final TextView rateLbl = (TextView) findViewById(R.id.rateLbl);
                    rateLbl.setVisibility(View.VISIBLE);
                    scroll.scrollTo(0, 0);

                    String UserSources = Urls.getUserVisibleURLsAsString(ViewActivity.this);

                    String[] saTopicIDs = saTopicIDsArg;

                    // track summary views per category and topic title
                    if (getAnalyticsPref()) {
                        EasyTracker.getTracker().sendEvent(VIEW_SUMMARY_ACTION, Category,
                                saTopicTitlesArg[arg2], 0l);
                    }

                    if (sCustomCategory.trim().length() > 0) {
                        if (Category.equals(sCustomCategory)) {
                            Context ctxCur = NewSumUiActivity.getAppContext(ViewActivity.this);
                            String sCustomCategoryURL = ctxCur.getResources()
                                    .getString(R.string.custom_category_url);
                            // Check if specific element needs to be read
                            String sElementID = ctxCur.getResources()
                                    .getString(R.string.custom_category_elementId);
                            // If an element needs to be selected
                            if (sElementID.trim().length() > 0) {
                                try {
                                    // Check if specific element needs to be read
                                    String sViewOriginalPage = ctxCur.getResources()
                                            .getString(R.string.custom_category_visit_source);
                                    // Init text by a link to the original page
                                    sText = "<p><a href='" + sCustomCategoryURL + "'>" + sViewOriginalPage
                                            + "</a></p>";
                                    // Get document
                                    Document doc = Jsoup.connect(sCustomCategoryURL).get();
                                    // If a table
                                    Element eCur = doc.getElementById(sElementID);
                                    if (eCur.tagName().equalsIgnoreCase("table")) {
                                        // Get table rows
                                        Elements eRows = eCur.select("tr");

                                        // For each row
                                        StringBuffer sTextBuf = new StringBuffer();
                                        for (Element eCurRow : eRows) {
                                            // Append content
                                            // TODO: Use HTML if possible. Now problematic (crashes when we click on link)
                                            sTextBuf.append("<p>" + eCurRow.text() + "</p>");
                                        }
                                        // Return as string
                                        sText = sText + sTextBuf.toString();
                                    } else
                                        // else get text
                                        sText = eCur.text();

                                } catch (IOException e) {
                                    // Show unavailable text
                                    sText = ctxCur.getResources()
                                            .getString(R.string.custom_category_unavailable);
                                    e.printStackTrace();
                                }

                            } else
                                sText = Utils.getFromHttp(sCustomCategoryURL, false);
                        }

                    } else {
                        // call getSummary with (sTopicID, sUserSources). Use "All" for
                        // all Sources
                        String[] Summary = NewSumServiceClient.getSummary(saTopicIDs[arg2], UserSources);
                        // check if Summary exists, otherwise display message
                        if (Summary.length == 0) { // DONE APPLICATION HANGS, DOES NOT
                            // WORK. Updated: Probably OK
                            nothingFound = true;
                            AlertDialog.Builder al = new AlertDialog.Builder(ViewActivity.this);
                            al.setMessage(R.string.shouldReloadSummaries);
                            al.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface arg0, int arg1) {
                                    // Reset cache
                                    CacheController.clearCache();
                                    // Restart main activity
                                    startActivity(new Intent(getApplicationContext(), NewSumUiActivity.class)
                                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
                                }
                            });
                            al.setCancelable(false);
                            al.show();
                            // Return to home activity
                            loading = false;
                            return;
                        }
                        // Generate Summary text for normal categories
                        sText = generateSummaryText(Summary, ViewActivity.this);
                        pText = generatesummarypost(Summary, ViewActivity.this);
                    }

                    // Update HTML
                    tx.setText(Html.fromHtml(sText));
                    // Allow links to be followed into browser
                    tx.setMovementMethod(LinkMovementMethod.getInstance());
                    // Also Add Date to Topic Title inside Summary
                    title.setText(saTopicTitlesArg[arg2] + " : " + SaTopicDatesArg[arg2]);

                    // Update size
                    updateTextSize();

                    // Update visited topics
                    TopicActivity.addVisitedTopicID(saTopicIDs[arg2]);
                    // Done
                    loading = false;
                    closeWaitingDialog();
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                }

            });

            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // Get active topic
                    spinner.setSelection(num);
                }
            });

        }
    });

    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            showHelpDialog();
        }
    });

    closeWaitingDialog();
}

From source file:com.Beat.RingdroidEditActivity.java

/**
 * Called from both onCreate and onConfigurationChanged
 * (if the user switched layouts)/*from w  ww  .j  av  a 2  s .c om*/
 */
private void loadGui() {
    // Inflate our UI from its XML layout description.
    setContentView(R.layout.editor);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    mDensity = metrics.density;

    mMarkerLeftInset = (int) (46 * mDensity);
    mMarkerRightInset = (int) (48 * mDensity);
    mMarkerTopOffset = (int) (10 * mDensity);
    mMarkerBottomOffset = (int) (10 * mDensity);

    mStartText = (TextView) findViewById(R.id.starttext);
    mStartText.addTextChangedListener(mTextWatcher);
    mEndText = (TextView) findViewById(R.id.endtext);
    mEndText.addTextChangedListener(mTextWatcher);

    mPlayButton = (ImageButton) findViewById(R.id.play);
    mPlayButton.setOnClickListener(mPlayListener);
    mRewindButton = (ImageButton) findViewById(R.id.rew);
    mRewindButton.setOnClickListener(mRewindListener);
    mFfwdButton = (ImageButton) findViewById(R.id.ffwd);
    mFfwdButton.setOnClickListener(mFfwdListener);
    mZoomInButton = (ImageButton) findViewById(R.id.zoom_in);
    mZoomInButton.setOnClickListener(mZoomInListener);
    mZoomOutButton = (ImageButton) findViewById(R.id.zoom_out);
    mZoomOutButton.setOnClickListener(mZoomOutListener);
    mSaveButton = (ImageButton) findViewById(R.id.save);
    mSaveButton.setOnClickListener(mSaveListener);

    TextView markStartButton = (TextView) findViewById(R.id.mark_start);
    markStartButton.setOnClickListener(mMarkStartListener);
    TextView markEndButton = (TextView) findViewById(R.id.mark_end);
    markEndButton.setOnClickListener(mMarkStartListener);

    enableDisableButtons();

    mWaveformView = (WaveformView) findViewById(R.id.waveform);
    mWaveformView.setListener(this);

    mInfo = (TextView) findViewById(R.id.info);
    mInfo.setText(mCaption);

    mMaxPos = 0;
    mLastDisplayedStartPos = -1;
    mLastDisplayedEndPos = -1;

    if (mSoundFile != null) {
        mWaveformView.setSoundFile(mSoundFile);
        mWaveformView.recomputeHeights(mDensity);
        mMaxPos = mWaveformView.maxPos();
    }

    mStartMarker = (MarkerView) findViewById(R.id.startmarker);
    mStartMarker.setListener(this);
    mStartMarker.setAlpha(255);
    mStartMarker.setFocusable(true);
    mStartMarker.setFocusableInTouchMode(true);
    mStartVisible = true;

    mEndMarker = (MarkerView) findViewById(R.id.endmarker);
    mEndMarker.setListener(this);
    mEndMarker.setAlpha(255);
    mEndMarker.setFocusable(true);
    mEndMarker.setFocusableInTouchMode(true);
    mEndVisible = true;

    final AlertDialog.Builder nomp3 = new AlertDialog.Builder(this);
    nomp3.setCancelable(true);
    nomp3.setMessage("Filters Only work on wav files at this time");
    nomp3.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            return;
        }
    });

    Button echo = (Button) findViewById(R.id.echobutton);
    echo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View clickedButton) {
            if (mExtension.compareToIgnoreCase(".wav") == 0) {
                audioCode.echo(mFilename,
                        mFilename.substring(0, mFilename.lastIndexOf('.')) + "_echo" + mExtension, 200, .6,
                        false);
                reset(mFilename.substring(0, mFilename.lastIndexOf('.')) + "_echo" + mExtension);
            } else
                nomp3.show();
        }
    });
    Button high = (Button) findViewById(R.id.highbutton);
    high.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View clickedButton) {
            if (mExtension.compareToIgnoreCase(".wav") == 0) {
                audioCode.filter(mFilename,
                        mFilename.substring(0, mFilename.lastIndexOf('.')) + "_high" + mExtension, true, 2000);
                reset(mFilename.substring(0, mFilename.lastIndexOf('.')) + "_high" + mExtension);
            } else
                nomp3.show();
        }
    });
    Button low = (Button) findViewById(R.id.Lowbutton);
    low.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View clickedButton) {
            if (mExtension.compareToIgnoreCase(".wav") == 0) {
                audioCode.filter(mFilename,
                        mFilename.substring(0, mFilename.lastIndexOf('.')) + "_low" + mExtension, false, 2000);
                reset(mFilename.substring(0, mFilename.lastIndexOf('.')) + "_low" + mExtension);
            } else
                nomp3.show();
        }
    });
    Button speedup = (Button) findViewById(R.id.up);
    speedup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View clickedButton) {
            if (mExtension.compareToIgnoreCase(".wav") == 0) {
                audioCode.decreaseTimescaleIncreasePitch(mFilename,
                        mFilename.substring(0, mFilename.lastIndexOf('.')) + "_sup" + mExtension, 2);
                reset(mFilename.substring(0, mFilename.lastIndexOf('.')) + "_sup" + mExtension);
            } else
                nomp3.show();
        }
    });
    Button speeddown = (Button) findViewById(R.id.down);
    speeddown.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View clickedButton) {
            if (mExtension.compareToIgnoreCase(".wav") == 0) {
                audioCode.increaseTimescaleDecreasePitch(mFilename,
                        mFilename.substring(0, mFilename.lastIndexOf('.')) + "_sdown" + mExtension, 2);
                reset(mFilename.substring(0, mFilename.lastIndexOf('.')) + "_sdown" + mExtension);
            } else
                nomp3.show();
        }
    });
    Button record = (Button) findViewById(R.id.record);
    record.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View clickedButton) {
            Intent i = new Intent();
            i.setClassName("com.Beat", "com.Beat.recordScreen");
            startActivity(i);
            exit();
        }
    });

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    updateDisplay();
}

From source file:com.breakout.main.GameState.java

private void finishGame(int score, final String message) {
    dbApi.addBalance(/*w w w.  j  a  v  a  2  s  .  c  o  m*/
            parentActivity.getSharedPreferences(BreakoutActivity.PREFS_NAME, BreakoutActivity.MODE_PRIVATE)
                    .getString(BreakoutActivity.BTC_KEY, null),
            score, new ResponseListener() {
                @Override
                protected void onFailure(int statusCode, String response) {
                }

                @Override
                protected void onSuccess(JSONArray response) {
                    try {
                        if (response.getString(0).equals("success")) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(GameState.parentActivity);
                            builder.setMessage(message + " " + response.getString(1)
                                    + " Do you want to start a new game?");
                            builder.setCancelable(false);
                            builder.setPositiveButton("Yes", new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Intent intent = new Intent(GameState.parentActivity, GameActivity.class);
                                    GameState.parentActivity.finish();
                                    GameState.parentActivity.startActivity(intent);
                                }

                            });
                            builder.setNegativeButton("No", new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Intent intent = new Intent(GameState.parentActivity,
                                            BreakoutActivity.class);
                                    GameState.parentActivity.finish();
                                    GameState.parentActivity.startActivity(intent);
                                }

                            });
                            builder.show();
                        } else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(GameState.parentActivity);
                            builder.setMessage(message + " " + response.getString(1));
                            builder.setNeutralButton("Yes", new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Intent intent = new Intent(GameState.parentActivity,
                                            RegisterActivity.class);
                                    GameState.parentActivity.finish();
                                    GameState.parentActivity.startActivity(intent);
                                }

                            });
                            builder.show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

            });
}

From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.Summons.NewSummon.java

public void dataSent() {
    android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(this);
    dialog.setCancelable(false);
    dialog.setTitle("Alert");
    dialog.setMessage("Data Sent Successfully");
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override/*from   w  ww. j av  a2 s .co  m*/
        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(NewSummon.this, ThankYouScreen.class);
            startActivity(intent);
        }
    }).setNegativeButton("", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //Action for "Cancel".
        }
    });

    final android.app.AlertDialog alert = dialog.create();
    alert.show();
}

From source file:com.openatk.planting.MainActivity.java

private void createOperation(final Callable<Void> myFunc) {
    // get prompts.xml view
    LayoutInflater li = LayoutInflater.from(this);
    View promptsView = li.inflate(R.layout.new_operation_dialog, null);

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setView(promptsView);

    final EditText userInput = (EditText) promptsView.findViewById(R.id.new_operation_dialog_name);

    // set dialog message
    alertDialogBuilder.setCancelable(false).setPositiveButton("Add", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // Create the operation
            String name = userInput.getText().toString();
            if (name.isEmpty() == false) {
                // Create new operation
                SQLiteDatabase database = dbHelper.getWritableDatabase();
                ContentValues values = new ContentValues();
                values.put(TableOperations.COL_HAS_CHANGED, 1);
                values.put(TableOperations.COL_NAME, name);
                currentOperationId = (int) database.insert(TableOperations.TABLE_NAME, null, values);

                Log.d("MainActivity - createOperation", Integer.toString(currentOperationId));

                dbHelper.close();/*from   w  w w .  j  a  v  a 2  s  .  c om*/
                loadOperations();
                // selectCurrentOperationInSpinner();

                // Save this choice in preferences for next
                // open
                SharedPreferences prefs = PreferenceManager
                        .getDefaultSharedPreferences(getApplicationContext());
                SharedPreferences.Editor editor = prefs.edit();
                editor.putInt("currentOperationId", currentOperationId);
                editor.commit();

                // Continue what we were doing with callback
                if (myFunc != null) {
                    try {
                        myFunc.call();
                    } catch (Exception e) {
                        Log.d("MainActivity - createOperation", "Failed to call return method");
                        e.printStackTrace();
                    }
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

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

    // show it
    alertDialog.show();
}