Example usage for android.app AlertDialog setButton

List of usage examples for android.app AlertDialog setButton

Introduction

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

Prototype

public void setButton(int whichButton, CharSequence text, OnClickListener listener) 

Source Link

Document

Set a listener to be invoked when the positive button of the dialog is pressed.

Usage

From source file:edu.rutgers.winlab.crowdpp.ui.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity_layout);

    // Create the adapter that will return a fragment for each of the three primary sections of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical parent.
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from   w ww.j ava2s.  c  om
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    SharedPreferences settings = this.getSharedPreferences("config", Context.MODE_PRIVATE);
    ;
    SharedPreferences.Editor editor = settings.edit();

    // load the default parameters into SharedPreferences for the first time launch 
    int ct = settings.getInt("count", 0);
    if (ct == 0) {
        editor.putString("start", "9");
        editor.putString("end", "21");
        editor.putString("interval", "15");
        editor.putString("duration", "5");
        editor.putString("location", "On");
        editor.putString("upload", "On");
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        editor.putString("IMEI", tm.getDeviceId());
        editor.putString("brand", Build.BRAND);
        editor.putString("model", Build.MODEL);
        String phone_type = Build.BRAND + "_" + Build.MODEL;

        // motoX
        if (phone_type.equals("motorola_XT1058")) {
            editor.putString("mfcc_dist_same_semi", "13");
            editor.putString("mfcc_dist_diff_semi", "18");
            editor.putString("mfcc_dist_same_un", "13");
            editor.putString("mfcc_dist_diff_un", "18");
        }
        // nexus 4
        else if (phone_type.equals("google_Nexus 4")) {
            editor.putString("mfcc_dist_same_semi", "17");
            editor.putString("mfcc_dist_diff_semi", "22");
            editor.putString("mfcc_dist_same_un", "17");
            editor.putString("mfcc_dist_diff_un", "22");
        }
        // s2
        else if (phone_type.equals("samsung_SAMSUNG-SGH-I727")) {
            editor.putString("mfcc_dist_same_semi", "18");
            editor.putString("mfcc_dist_diff_semi", "25");
            editor.putString("mfcc_dist_same_un", "18");
            editor.putString("mfcc_dist_diff_un", "25");
        }
        // s3 
        else if (phone_type.equals("samsung_SAMSUNG-SGH-I747")) {
            editor.putString("mfcc_dist_same_semi", "16");
            editor.putString("mfcc_dist_diff_semi", "21");
            editor.putString("mfcc_dist_same_un", "16");
            editor.putString("mfcc_dist_diff_un", "21");
        }
        // s4
        else if (phone_type.equals("samsung_SAMSUNG-SGH-I337")) {
            editor.putString("mfcc_dist_same_semi", "14");
            editor.putString("mfcc_dist_diff_semi", "24");
            editor.putString("mfcc_dist_same_un", "14");
            editor.putString("mfcc_dist_diff_un", "24");
        }
        // other devices
        else {
            editor.putString("mfcc_dist_same_semi", "15.6");
            editor.putString("mfcc_dist_diff_semi", "21.6");
            editor.putString("mfcc_dist_same_un", "15.6");
            editor.putString("mfcc_dist_diff_un", "21.6");
            Toast.makeText(this, "Your device is not recognized and the result might not be accurate...",
                    Toast.LENGTH_SHORT).show();
        }
        Log.i("Crowd++", "First time launched");

        AlertDialog dialog = new AlertDialog.Builder(this).create();
        dialog.setTitle("Welcome to Crowd++");
        dialog.setMessage(Constants.hello_msg);
        dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Close", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        dialog.show();
        dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextSize(20);
    }

    editor.putInt("count", ++ct);
    editor.commit();
    Log.i("Launched Count", Integer.toString(ct));
    mConst = new Constants(this);
    if (!Constants.calibration())
        Toast.makeText(this, "You haven't calibrated the system.", Toast.LENGTH_SHORT).show();
}

From source file:in.fabinpaul.sixthsense.SixthSenseActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case REQUEST_CAMERA_PERMISSION: {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);

        } else {/*from  w  w  w.  java2  s  .  com*/

            AlertDialog ad = new AlertDialog.Builder(this).create();
            ad.setCancelable(false); // This blocks the 'BACK' button
            ad.setMessage(
                    "It seems that you device does not support camera (or it is locked). Application will be closed.");
            ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    finish();
                }
            });
            ad.show();
        }
        return;
    }

    // other 'case' lines to check for other
    // permissions this app might request
    }
}

From source file:org.fdroid.fdroid.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_login:
        if (mService != null) {
            com.skubit.Utils.startAuthorization(this, mService);
        } else {/* w  w  w  .  j  a v  a 2  s  .c  o m*/
            if (!com.skubit.Utils.isIabInstalled(getPackageManager())) {
                startActivityForResult(com.skubit.Utils.getIabIntent(), com.skubit.Utils.PLAY_CODE);
            }
        }
        return true;
    case R.id.action_update_repo:
        updateRepos();
        return true;

    case R.id.action_manage_repos:
        Intent i = new Intent(this, ManageReposActivity.class);
        startActivityForResult(i, REQUEST_MANAGEREPOS);
        return true;

    case R.id.action_settings:
        Intent prefs = new Intent(getBaseContext(), PreferencesActivity.class);
        startActivityForResult(prefs, REQUEST_PREFS);
        return true;

    case R.id.action_swap:
        startActivity(new Intent(this, SwapActivity.class));
        return true;

    case R.id.action_search:
        onSearchRequested();
        return true;

    case R.id.action_bluetooth_apk:
        /*
         * If Bluetooth has not been enabled/turned on, then enabling
         * device discoverability will automatically enable Bluetooth
         */
        Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 121);
        startActivityForResult(discoverBt, REQUEST_ENABLE_BLUETOOTH);
        // if this is successful, the Bluetooth transfer is started
        return true;

    case R.id.action_about:
        View view = null;
        if (Build.VERSION.SDK_INT >= 11) {
            LayoutInflater li = LayoutInflater.from(this);
            view = li.inflate(R.layout.about, null);
        } else {
            view = View.inflate(new ContextThemeWrapper(this, R.style.AboutDialogLight), R.layout.about, null);
        }

        // Fill in the version...
        try {
            PackageInfo pi = getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), 0);
            ((TextView) view.findViewById(R.id.version)).setText(pi.versionName);
        } catch (Exception e) {
        }

        AlertDialog.Builder p = null;
        if (Build.VERSION.SDK_INT >= 11) {
            p = new AlertDialog.Builder(this).setView(view);
        } else {
            p = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AboutDialogLight)).setView(view);
        }
        final AlertDialog alrt = p.create();
        alrt.setIcon(R.drawable.ic_launcher_market);
        alrt.setTitle(getString(R.string.about_title));
        alrt.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.about_website),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Uri uri = Uri.parse("https://f-droid.org");
                        startActivity(new Intent(Intent.ACTION_VIEW, uri));
                    }
                });
        alrt.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                });
        alrt.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.wahtod.wififixer.ui.MainActivity.java

public void showServiceAlert() {
    final Context c;
    c = this;/*from w w  w  . j a  v a  2 s.c  om*/
    AlertDialog alert = new AlertDialog.Builder(c).create();
    alert.setTitle(getString(R.string.note));
    alert.setIcon(R.drawable.icon);
    alert.setMessage(getString(R.string.servicealert_message));
    alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok_button),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    PrefUtil.writeBoolean(c, PrefConstants.SERVICEWARNED, true);
                }
            });
    alert.show();
}

From source file:com.jwork.dhammapada.MainActivity.java

public void displayChangeLog() {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle("Changelog");

    WebView wv = new WebView(this);
    wv.loadData(getString(R.string.changelog_dialog_text), "text/html", "utf-8");
    wv.setScrollContainer(true);//from   w w w .  ja  v  a2s  .  c  om
    dialog.setView(wv);

    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Configuration.getInstance(MainActivity.this)
                            .setCurrentVersion(CrashHandler.getVersionCode(MainActivity.this));
                    dialog.dismiss();
                }
            });
    dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Rate It", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Configuration.getInstance(MainActivity.this)
                    .setCurrentVersion(CrashHandler.getVersionCode(MainActivity.this));
            dialog.dismiss();
            Uri uri = Uri.parse("market://details?id=" + MainActivity.this.getPackageName());
            Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
            try {
                MainActivity.this.startActivity(myAppLinkToMarket);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(MainActivity.this, "Failed to find Market application", Toast.LENGTH_LONG)
                        .show();
            }
        }
    });
    dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Donate", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Configuration.getInstance(MainActivity.this)
                    .setCurrentVersion(CrashHandler.getVersionCode(MainActivity.this));
            dialog.dismiss();
            openDonate();
        }
    });
    dialog.show();
}

From source file:id.ridon.keude.Keude.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case R.id.action_update_repo:
        updateRepos();//from   w ww . j a v a2s. c  o m
        return true;

    case R.id.action_manage_repos:
        Intent i = new Intent(this, ManageReposActivity.class);
        startActivityForResult(i, REQUEST_MANAGEREPOS);
        return true;

    case R.id.action_settings:
        Intent prefs = new Intent(getBaseContext(), PreferencesActivity.class);
        startActivityForResult(prefs, REQUEST_PREFS);
        return true;

    case R.id.action_swap:
        startActivity(new Intent(this, SwapActivity.class));
        return true;

    case R.id.action_search:
        onSearchRequested();
        return true;

    case R.id.action_bluetooth_apk:
        /*
         * If Bluetooth has not been enabled/turned on, then enabling
         * device discoverability will automatically enable Bluetooth
         */
        Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 121);
        startActivityForResult(discoverBt, REQUEST_ENABLE_BLUETOOTH);
        // if this is successful, the Bluetooth transfer is started
        return true;

    case R.id.action_about:
        View view = null;
        if (Build.VERSION.SDK_INT >= 11) {
            LayoutInflater li = LayoutInflater.from(this);
            view = li.inflate(R.layout.about, null);
        } else {
            view = View.inflate(new ContextThemeWrapper(this, R.style.AboutDialogLight), R.layout.about, null);
        }

        // Fill in the version...
        try {
            PackageInfo pi = getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), 0);
            ((TextView) view.findViewById(R.id.version)).setText(pi.versionName);
        } catch (Exception e) {
        }

        Builder p = null;
        if (Build.VERSION.SDK_INT >= 11) {
            p = new AlertDialog.Builder(this).setView(view);
        } else {
            p = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AboutDialogLight)).setView(view);
        }
        final AlertDialog alrt = p.create();
        alrt.setIcon(R.drawable.ic_launcher);
        alrt.setTitle(getString(R.string.about_title));
        alrt.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.about_website),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Uri uri = Uri.parse("https://f-droid.org");
                        startActivity(new Intent(Intent.ACTION_VIEW, uri));
                    }
                });
        alrt.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                });
        alrt.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.acrylicgoat.devchat.MainActivity.java

private void displayPopup() {
    //retrieve yesterday's data
    String yData = getYesterday(currentOwner);
    if (yData.equals("")) {
        yData = getString(R.string.no_yesterday);
    }/*  w ww  .  j  a v a2s .c o  m*/
    //display in popup
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Last Chat");
    alertDialog.setMessage(yData);
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Done", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            //do nothing

        }
    });
    alertDialog.show();
}

From source file:org.wahtod.wififixer.ui.MainActivity.java

private void phoneTutNag() {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle(getString(R.string.phone_ui_tutorial));
    dialog.setMessage(getString(R.string.phone_tutorial_q));
    dialog.setIcon(R.drawable.icon);//from   w ww .  j a va 2s. c om
    dialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok_button),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    runTutorial();
                }
            });

    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.later_button),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    PrefUtil.writeBoolean(self.get(), PrefConstants.TUTORIAL, true);
                }
            });
    dialog.show();
}

From source file:com.acrylicgoat.scrumnotes.MainActivity.java

private void displayPopup() {
    //retrieve yesterday's data
    String yData = getYesterday(currentOwner);
    if (yData.equals("")) {
        yData = getString(R.string.no_yesterday);
    }//  www.  jav a 2 s .  c o  m
    //display in popup
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Yesterday");
    alertDialog.setMessage(yData);
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Done", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            //do nothing

        }
    });
    alertDialog.show();
}

From source file:com.aikidonord.fragments.FragmentDate.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_date, null /*container, false*/);

    View rlLoading = view.findViewById(R.id.loadingPanel);
    //View listView = view.getListView();

    if (VerifConnexion.isOnline(this.getActivity())) {
        rlLoading.setVisibility(View.VISIBLE);

        // on va fair l'impasse l dessus vu que je ne suis pas bien sr
        // de la manire dont il faut oprer tant que la vue n'a pas t renvoye.
        //listView.setVisibility(View.GONE);
        this.lancementAsync();
    } else {/*ww w . j av a2s .c  o  m*/

        AlertDialog alertDialog = new AlertDialog.Builder(this.getActivity()).create();
        alertDialog.setTitle(getResources().getString(R.string.app_name));
        alertDialog.setMessage(getResources().getString(R.string.no_network));
        alertDialog.setIcon(R.drawable.ic_launcher);
        alertDialog.setCancelable(false);
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getResources().getString(R.string.close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, close
                        // current activity
                        FragmentDate.this.getActivity().finish();
                    }
                });
        alertDialog.show();
    }

    return view;
}