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:cm.aptoide.pt.MainActivity.java

public void showAbout() {
    View aboutView = LayoutInflater.from(this).inflate(R.layout.dialog_about, null);
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this).setView(aboutView);
    final AlertDialog aboutDialog = dialogBuilder.create();
    aboutDialog.setIcon(android.R.drawable.ic_menu_help);
    aboutDialog.setTitle(getString(R.string.about));
    aboutDialog.setCancelable(true);/*w w w .  j a  v  a 2  s. c  o  m*/

    WindowManager.LayoutParams params = aboutDialog.getWindow().getAttributes();
    params.width = WindowManager.LayoutParams.MATCH_PARENT;
    aboutDialog.getWindow().setAttributes(params);

    aboutDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.btn_chlog),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Uri uri = Uri.parse(getString(R.string.change_log_url));
                    startActivity(new Intent(Intent.ACTION_VIEW, uri));
                }
            });

    aboutDialog.show();
}

From source file:cm.aptoide.pt.MainActivity.java

private void requestUpdateSelf() {
    View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null);
    Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
    final AlertDialog updateSelfDialog = dialogBuilder.create();
    updateSelfDialog.setTitle(getText(R.string.update_self_title));
    updateSelfDialog.setIcon(R.drawable.icon_brand_aptoide);
    TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
    message.setText(getString(R.string.update_self_msg, ApplicationAptoide.MARKETNAME));
    updateSelfDialog.setCancelable(false);
    updateSelfDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes),
            new Dialog.OnClickListener() {
                @Override/*from  w  ww  .  ja v  a 2 s  . c  o  m*/
                public void onClick(DialogInterface arg0, int arg1) {
                    new DownloadSelfUpdate().execute();
                }
            });
    updateSelfDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no),
            new Dialog.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int arg1) {
                    dialog.dismiss();
                }
            });
    updateSelfDialog.show();

}

From source file:cm.aptoide.pt.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    AptoideThemePicker.setAptoideTheme(this);
    super.onCreate(savedInstanceState);

    serviceDownloadManagerIntent = new Intent(this, ServiceDownloadManager.class);
    startService(serviceDownloadManagerIntent);
    mContext = this;

    File sdcard_file = new File(SDCARD);
    if (!sdcard_file.exists() || !sdcard_file.canWrite()) {
        View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null);
        Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
        final AlertDialog noSDDialog = dialogBuilder.create();
        noSDDialog.setTitle(getText(R.string.remote_in_noSD_title));
        noSDDialog.setIcon(android.R.drawable.ic_dialog_alert);
        TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
        message.setText(getText(R.string.remote_in_noSD));
        noSDDialog.setCancelable(false);
        noSDDialog.setButton(Dialog.BUTTON_NEUTRAL, getString(android.R.string.ok),
                new Dialog.OnClickListener() {
                    @Override//from   w w  w.  j av  a2  s. c o  m
                    public void onClick(DialogInterface arg0, int arg1) {
                        finish();
                    }
                });
        noSDDialog.show();
    } else {
        StatFs stat = new StatFs(sdcard_file.getPath());
        long blockSize = stat.getBlockSize();
        long totalBlocks = stat.getBlockCount();
        long availableBlocks = stat.getAvailableBlocks();

        long total = (blockSize * totalBlocks) / 1024 / 1024;
        long avail = (blockSize * availableBlocks) / 1024 / 1024;
        Log.d("Aptoide", "* * * * * * * * * *");
        Log.d("Aptoide", "Total: " + total + " Mb");
        Log.d("Aptoide", "Available: " + avail + " Mb");

        if (avail < 10) {
            Log.d("Aptoide", "No space left on SDCARD...");
            Log.d("Aptoide", "* * * * * * * * * *");
            View simpleView = LayoutInflater.from(this).inflate(R.layout.dialog_simple_layout, null);
            Builder dialogBuilder = new AlertDialog.Builder(this).setView(simpleView);
            final AlertDialog noSpaceDialog = dialogBuilder.create();
            noSpaceDialog.setIcon(android.R.drawable.ic_dialog_alert);
            TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
            message.setText(getText(R.string.remote_in_noSDspace));
            noSpaceDialog.setButton(Dialog.BUTTON_NEUTRAL, getText(android.R.string.ok),
                    new Dialog.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            finish();
                        }
                    });
            noSpaceDialog.show();
        } else {

            SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mContext);
            editor = PreferenceManager.getDefaultSharedPreferences(mContext).edit();

            if (!sPref.contains("matureChkBox")) {

                editor.putBoolean("matureChkBox", ApplicationAptoide.MATURECONTENTSWITCHVALUE);
                SharedPreferences sPrefOld = getSharedPreferences("aptoide_prefs", MODE_PRIVATE);
                if (sPrefOld.getString("app_rating", "none").equals("Mature")) {
                    editor.putBoolean("matureChkBox", false);
                }

            }

            if (!sPref.contains("version")) {

                ApplicationAptoide.setRestartLauncher(true);
                try {
                    editor.putInt("version",
                            getPackageManager().getPackageInfo(getPackageName(), 0).versionCode);
                } catch (NameNotFoundException e) {
                    e.printStackTrace();
                }

            }

            if (sPref.getString("myId", null) == null) {
                String rand_id = UUID.randomUUID().toString();
                editor.putString("myId", rand_id);
            }

            if (sPref.getInt("scW", 0) == 0 || sPref.getInt("scH", 0) == 0) {
                DisplayMetrics dm = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(dm);
                editor.putInt("scW", dm.widthPixels);
                editor.putInt("scH", dm.heightPixels);
            }
            editor.commit();
            File file = new File(LOCAL_PATH + "/apks");
            if (!file.exists()) {
                file.mkdirs();
            }

            new Thread(new Runnable() {

                @Override
                public void run() {

                    // Note the L that tells the compiler to interpret the
                    // number as a Long
                    final long MAXFILEAGE = 2678400000L; // 1 month in
                    // milliseconds

                    // Get file handle to the directory. In this case the
                    // application files dir
                    File dir = new File(LOCAL_PATH + "/apks");

                    // Optain list of files in the directory.
                    // listFiles() returns a list of File objects to each
                    // file found.
                    File[] files = dir.listFiles();

                    // Loop through all files
                    for (File f : files) {

                        // Get the last modified date. Miliseconds since
                        // 1970
                        long lastmodified = f.lastModified();

                        // Do stuff here to deal with the file..
                        // For instance delete files older than 1 month
                        if (lastmodified + MAXFILEAGE < System.currentTimeMillis()) {
                            f.delete();
                        }
                    }
                }
            }).start();
            db = Database.getInstance();

            Intent i = new Intent(mContext, MainService.class);
            startService(i);
            bindService(i, conn, Context.BIND_AUTO_CREATE);
            order = Order.values()[PreferenceManager.getDefaultSharedPreferences(mContext).getInt("order_list",
                    0)];

            registerReceiver(updatesReceiver, new IntentFilter("update"));
            registerReceiver(statusReceiver, new IntentFilter("status"));
            registerReceiver(loginReceiver, new IntentFilter("login"));
            registerReceiver(storePasswordReceiver, new IntentFilter("401"));
            registerReceiver(redrawInstalledReceiver, new IntentFilter("pt.caixamagica.aptoide.REDRAW"));
            if (!ApplicationAptoide.MULTIPLESTORES) {
                registerReceiver(parseFailedReceiver, new IntentFilter("PARSE_FAILED"));
            }

            registerReceiver(newRepoReceiver, new IntentFilter("pt.caixamagica.aptoide.NEWREPO"));
            registered = true;

            categoriesStrings = new HashMap<String, Integer>();

            //            categoriesStrings.put("Applications", R.string.applications);

            boolean serversFileIsEmpty = true;

            if (sPref.getBoolean("firstrun", true)) {
                // Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
                // shortcutIntent.setClassName("cm.aptoide.pt",
                // "cm.aptoide.pt.Start");
                // final Intent intent = new Intent();
                // intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
                // shortcutIntent);
                //
                // intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                // getString(R.string.app_name));
                // Parcelable iconResource =
                // Intent.ShortcutIconResource.fromContext(this,
                // R.drawable.ic_launcher);
                //
                // intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                // iconResource);
                // intent.putExtra("duplicate", false);
                // intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
                // sendBroadcast(intent);

                if (new File(LOCAL_PATH + "/servers.xml").exists()
                        && ApplicationAptoide.DEFAULTSTORENAME == null) {
                    try {

                        SAXParserFactory spf = SAXParserFactory.newInstance();
                        SAXParser sp = spf.newSAXParser();

                        MyappHandler handler = new MyappHandler();

                        sp.parse(new File(LOCAL_PATH + "/servers.xml"), handler);
                        ArrayList<String> server = handler.getServers();
                        if (server.isEmpty()) {
                            serversFileIsEmpty = true;
                        } else {
                            getIntent().putExtra("newrepo", server);
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
                editor.putBoolean("firstrun", false);
                editor.putBoolean("orderByCategory", true);
                editor.commit();
            }

            if (getIntent().hasExtra("newrepo")) {
                ArrayList<String> repos = (ArrayList<String>) getIntent().getSerializableExtra("newrepo");
                for (final String uri2 : repos) {
                    View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout,
                            null);
                    Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
                    final AlertDialog addNewRepoDialog = dialogBuilder.create();
                    addNewRepoDialog.setTitle(getString(R.string.add_store));
                    addNewRepoDialog.setIcon(android.R.drawable.ic_menu_add);

                    TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
                    message.setText((getString(R.string.newrepo_alrt) + uri2 + " ?"));

                    addNewRepoDialog.setCancelable(false);
                    addNewRepoDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes),
                            new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    dialogAddStore(uri2, null, null);
                                }
                            });
                    addNewRepoDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no),
                            new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int arg1) {
                                    dialog.cancel();
                                }
                            });
                    addNewRepoDialog.show();
                }
            } else if (db.getStores(false).getCount() == 0 && ApplicationAptoide.DEFAULTSTORENAME == null
                    && serversFileIsEmpty) {
                View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null);
                Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
                final AlertDialog addAppsRepoDialog = dialogBuilder.create();
                addAppsRepoDialog.setTitle(getString(R.string.add_store));
                addAppsRepoDialog.setIcon(android.R.drawable.ic_menu_add);
                TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
                message.setText(getString(R.string.myrepo_alrt) + "\n" + "http://apps.store.aptoide.com/");
                addAppsRepoDialog.setCancelable(false);
                addAppsRepoDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes),
                        new Dialog.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface arg0, int arg1) {
                                dialogAddStore("http://apps.store.aptoide.com", null, null);
                            }
                        });
                addAppsRepoDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no),
                        new Dialog.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int arg1) {
                                dialog.cancel();
                            }
                        });
                addAppsRepoDialog.show();
            }

            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        getUpdateParameters();
                        if (getPackageManager().getPackageInfo(getPackageName(), 0).versionCode < Integer
                                .parseInt(updateParams.get("versionCode"))) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    requestUpdateSelf();
                                }
                            });
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();

        }

        featuredView = LayoutInflater.from(mContext).inflate(R.layout.page_featured, null);
        availableView = LayoutInflater.from(mContext).inflate(R.layout.page_available, null);
        updateView = LayoutInflater.from(mContext).inflate(R.layout.page_updates, null);
        banner = (LinearLayout) availableView.findViewById(R.id.banner);
        breadcrumbs = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.breadcrumb_container, null);
        installedView = new ListView(mContext);
        updatesListView = (ListView) updateView.findViewById(R.id.updates_list);

        availableListView = (ListView) availableView.findViewById(R.id.available_list);
        joinStores = (CheckBox) availableView.findViewById(R.id.join_stores);

        availableAdapter = new AvailableListAdapter(mContext, null,
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        installedAdapter = new InstalledAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER,
                db);
        updatesAdapter = new UpdatesAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

        pb = (TextView) availableView.findViewById(R.id.loading_pb);
        addStoreButton = availableView.findViewById(R.id.add_store);

        bannerStoreAvatar = (ImageView) banner.findViewById(R.id.banner_store_avatar);
        bannerStoreName = (TextView) banner.findViewById(R.id.banner_store_name);
        bannerStoreDescription = (AutoScaleTextView) banner.findViewById(R.id.banner_store_description);
    }
}

From source file:cm.aptoide.pt.MainActivity.java

private void displayOptionsDialog() {

    final SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(this);
    final Editor editor = sPref.edit();

    View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_order_popup, null);
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(view);
    final AlertDialog orderDialog = dialogBuilder.create();
    orderDialog.setIcon(android.R.drawable.ic_menu_sort_by_size);
    orderDialog.setTitle(getString(R.string.menu_display_options));
    orderDialog.setCancelable(true);/*  ww w . j  ava2  s.  c  o m*/

    final RadioButton ord_rct = (RadioButton) view.findViewById(R.id.org_rct);
    final RadioButton ord_abc = (RadioButton) view.findViewById(R.id.org_abc);
    final RadioButton ord_rat = (RadioButton) view.findViewById(R.id.org_rat);
    final RadioButton ord_dwn = (RadioButton) view.findViewById(R.id.org_dwn);
    final RadioButton ord_price = (RadioButton) view.findViewById(R.id.org_price);
    final RadioButton btn1 = (RadioButton) view.findViewById(R.id.shw_ct);
    final RadioButton btn2 = (RadioButton) view.findViewById(R.id.shw_all);

    final ToggleButton adult = (ToggleButton) view.findViewById(R.id.adultcontent_toggle);

    orderDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
        boolean pop_change = false;
        private boolean pop_change_category = false;

        public void onClick(DialogInterface dialog, int which) {
            if (ord_rct.isChecked()) {
                pop_change = true;
                order = Order.DATE;
            } else if (ord_abc.isChecked()) {
                pop_change = true;
                order = Order.NAME;
            } else if (ord_rat.isChecked()) {
                pop_change = true;
                order = Order.RATING;
            } else if (ord_dwn.isChecked()) {
                pop_change = true;
                order = Order.DOWNLOADS;
            } else if (ord_price.isChecked()) {
                pop_change = true;
                order = Order.PRICE;
            }

            if (btn1.isChecked()) {
                pop_change = true;
                pop_change_category = true;
                editor.putBoolean("orderByCategory", true);
            } else if (btn2.isChecked()) {
                pop_change = true;
                pop_change_category = true;
                editor.putBoolean("orderByCategory", false);
            }
            if (adult.isChecked()) {
                pop_change = true;
                editor.putBoolean("matureChkBox", false);
            } else {
                editor.putBoolean("matureChkBox", true);
            }
            if (pop_change) {
                editor.putInt("order_list", order.ordinal());
                editor.commit();
                if (pop_change_category) {

                    if (!depth.equals(ListDepth.CATEGORY1) && !depth.equals(ListDepth.STORES)) {
                        if (depth.equals(ListDepth.APPLICATIONS)) {
                            removeLastBreadCrumb();
                        }
                        removeLastBreadCrumb();
                        depth = ListDepth.CATEGORY1;
                    }

                }
                redrawAll();
                refreshAvailableList(true);
            }
        }
    });

    if (sPref.getBoolean("orderByCategory", false)) {
        btn1.setChecked(true);
    } else {
        btn2.setChecked(true);
    }
    if (!ApplicationAptoide.MATURECONTENTSWITCH) {
        adult.setVisibility(View.GONE);
        view.findViewById(R.id.dialog_adult_content_label).setVisibility(View.GONE);
    }
    adult.setChecked(!sPref.getBoolean("matureChkBox", false));
    // adult.setOnCheckedChangeListener(adultCheckedListener);
    switch (order) {
    case DATE:
        ord_rct.setChecked(true);
        break;
    case DOWNLOADS:
        ord_dwn.setChecked(true);
        break;
    case NAME:
        ord_abc.setChecked(true);
        break;
    case RATING:
        ord_rat.setChecked(true);
        break;
    case PRICE:
        ord_price.setChecked(true);
        break;

    default:
        break;
    }

    orderDialog.show();

}

From source file:com.cognizant.trumobi.PersonaLauncher.java

/**
 * ADW: Put the launcher in desktop edit mode We could be able to add,
 * remove and reorder screens//from  w  ww. j  ava2  s  . c  om
 */
private void startDesktopEdit() {
    if (!mIsEditMode) {
        mIsEditMode = true;
        final PersonaWorkspace personaWorkspace = mWorkspace;
        if (personaWorkspace == null)
            return;
        personaWorkspace.enableChildrenCache(0, personaWorkspace.getChildCount());
        hideDesktop(true);
        personaWorkspace.lock();
        // Load a gallery view
        final PersonaScreensAdapter screens = new PersonaScreensAdapter(this,
                personaWorkspace.getChildAt(0).getWidth(), personaWorkspace.getChildAt(0).getHeight());
        for (int i = 0; i < personaWorkspace.getChildCount(); i++) {
            screens.addScreen((PersonaCellLayout) personaWorkspace.getChildAt(i));
        }
        mScreensEditor = mInflater.inflate(R.layout.pr_screens_editor, null);
        final Gallery gal = (Gallery) mScreensEditor.findViewById(R.id.gallery_screens);
        gal.setCallbackDuringFling(false);
        gal.setClickable(false);
        gal.setAdapter(screens);
        // Setup delete button event
        View deleteButton = mScreensEditor.findViewById(R.id.delete_screen);
        deleteButton.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                final int screenToDelete = gal.getSelectedItemPosition();
                if (personaWorkspace.getChildCount() > 1) {
                    AlertDialog alertDialog = new AlertDialog.Builder(PersonaLauncher.this).create();
                    alertDialog.setTitle(getResources().getString(R.string.title_dialog_xml));
                    alertDialog.setMessage(getResources().getString(R.string.message_delete_desktop_screen));
                    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
                            getResources().getString(android.R.string.ok),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    personaWorkspace.removeScreen(screenToDelete);
                                    screens.removeScreen(screenToDelete);
                                }
                            });
                    alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                            getResources().getString(android.R.string.cancel),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                }
                            });
                    alertDialog.show();
                } else {
                    Toast t = Toast.makeText(PersonaLauncher.this,
                            R.string.message_cannot_delete_desktop_screen, Toast.LENGTH_LONG);
                    t.show();
                }

            }
        });
        // Setup add buttons events
        View addLeftButton = mScreensEditor.findViewById(R.id.add_left);
        addLeftButton.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                if (screens.getCount() < MAX_SCREENS) {
                    final int screenToAddLeft = gal.getSelectedItemPosition();
                    PersonaCellLayout newScreen = personaWorkspace.addScreen(screenToAddLeft);
                    screens.addScreen(newScreen, screenToAddLeft);
                } else {
                    Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_add_desktop_screen,
                            Toast.LENGTH_LONG);
                    t.show();
                }
            }
        });
        View addRightButton = mScreensEditor.findViewById(R.id.add_right);
        addRightButton.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                if (screens.getCount() < MAX_SCREENS) {
                    final int screenToAddRight = gal.getSelectedItemPosition();
                    PersonaCellLayout newScreen = personaWorkspace.addScreen(screenToAddRight + 1);
                    screens.addScreen(newScreen, screenToAddRight + 1);
                } else {
                    Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_add_desktop_screen,
                            Toast.LENGTH_LONG);
                    t.show();
                }
            }
        });

        final View swapLeftButton = mScreensEditor.findViewById(R.id.swap_left);
        swapLeftButton.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                int currentScreen = gal.getSelectedItemPosition();
                if (currentScreen > 0) {
                    personaWorkspace.swapScreens(currentScreen - 1, currentScreen);
                    screens.swapScreens(currentScreen - 1, currentScreen);
                } else {
                    Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_swap_desktop_screen,
                            Toast.LENGTH_LONG);
                    t.show();
                }
            }
        });
        final View swapRightButton = mScreensEditor.findViewById(R.id.swap_right);
        swapRightButton.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                int currentScreen = gal.getSelectedItemPosition();
                if (currentScreen < gal.getCount() - 1) {
                    personaWorkspace.swapScreens(currentScreen, currentScreen + 1);
                    screens.swapScreens(currentScreen, currentScreen + 1);
                } else {
                    Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_swap_desktop_screen,
                            Toast.LENGTH_LONG);
                    t.show();
                }
            }
        });
        final View setDefaultButton = mScreensEditor.findViewById(R.id.set_default);
        setDefaultButton.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                int currentScreen = gal.getSelectedItemPosition();
                if (currentScreen < mWorkspace.getChildCount()) {
                    mWorkspace.setDefaultScreen(currentScreen);
                    PersonaAlmostNexusSettingsHelper.setDefaultScreen(PersonaLauncher.this, currentScreen);
                    Toast t = Toast.makeText(PersonaLauncher.this, R.string.pref_title_default_screen,
                            Toast.LENGTH_LONG);
                    t.show();
                }
            }
        });
        gal.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (position <= 0) {
                    swapLeftButton.setVisibility(View.GONE);
                } else {
                    swapLeftButton.setVisibility(View.VISIBLE);
                }
                if (position < parent.getCount() - 1) {
                    swapRightButton.setVisibility(View.VISIBLE);
                } else {
                    swapRightButton.setVisibility(View.GONE);
                }
            }

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

        });
        mDragLayer.addView(mScreensEditor);
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@SuppressWarnings("unused")
void addSearch() {
    final PersonaWidget info = PersonaWidget.makeSearch();
    final PersonaCellLayout.CellInfo cellInfo = mAddItemCellInfo;

    final int[] xy = mCellCoordinates;
    final int spanX = info.spanX;
    final int spanY = info.spanY;

    AlertDialog.Builder builder;/*from   ww  w . j  a  v  a2s . c om*/
    AlertDialog alertDialog;

    final View dlg_layout = View.inflate(PersonaLauncher.this, R.layout.pr_widget_span_setup, null);
    final PersonaNumberPicker ncols = (PersonaNumberPicker) dlg_layout.findViewById(R.id.widget_columns_span);
    ncols.setRange(1, mWorkspace.currentDesktopColumns());
    ncols.setCurrent(spanX);
    final PersonaNumberPicker nrows = (PersonaNumberPicker) dlg_layout.findViewById(R.id.widget_rows_span);
    nrows.setRange(1, mWorkspace.currentDesktopRows());
    nrows.setCurrent(spanY);
    builder = new AlertDialog.Builder(PersonaLauncher.this);
    builder.setView(dlg_layout);
    alertDialog = builder.create();
    alertDialog.setTitle(getResources().getString(R.string.widget_config_dialog_title));
    alertDialog.setMessage(getResources().getString(R.string.widget_config_dialog_summary));
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    int spanX = ncols.getCurrent();
                    int spanY = nrows.getCurrent();
                    // realAddSearch(info,cellInfo,xy,spanX,spanY);
                }
            });
    alertDialog.show();
}