Example usage for android.app AlertDialog findViewById

List of usage examples for android.app AlertDialog findViewById

Introduction

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

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID or null if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via #show() or #create() ).

Usage

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void showChannelSelection() {
    if (PrefUtils.getStringValue(R.string.PREF_AUTO_CHANNEL_UPDATE_CHANNELS_INSERTED, null) != null
            || PrefUtils.getStringValue(R.string.PREF_AUTO_CHANNEL_UPDATE_CHANNELS_UPDATED, null) != null) {
        showChannelUpdateInfo();//from   w  w  w .  ja v  a 2  s  .com
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

        builder.setTitle(R.string.synchronize_title);
        builder.setMessage(R.string.synchronize_text);
        builder.setCancelable(false);

        builder.setPositiveButton(R.string.synchronize_ok, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                final SharedPreferences pref = getSharedPreferences("transportation", Context.MODE_PRIVATE);

                if (pref.getString(SettingConstants.USER_NAME, "").trim().length() == 0
                        || pref.getString(SettingConstants.USER_PASSWORD, "").trim().length() == 0) {
                    showUserSetting(true);
                } else {
                    syncronizeChannels();
                }
            }
        });
        builder.setNegativeButton(R.string.synchronize_cancel, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        showChannelSelectionInternal();
                    }
                });
            }
        });

        AlertDialog d = builder.create();

        d.show();

        ((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    }
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void showNews() {
    if (!selectingChannels) {
        final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this);

        if (pref.getBoolean(getString(R.string.PREF_NEWS_SHOW),
                getResources().getBoolean(R.bool.pref_news_show_default))) {
            long lastShown = pref.getLong(getString(R.string.NEWS_DATE_LAST_SHOWN), 0);
            long lastKnown = pref.getLong(getString(R.string.NEWS_DATE_LAST_KNOWN), 0);

            final String news = pref.getString(getString(R.string.NEWS_TEXT), "");

            if (lastShown < lastKnown && news.trim().length() > 0) {
                handler.post(new Runnable() {
                    @Override/*from  w ww .j av a  2s . c  o m*/
                    public void run() {
                        final AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

                        builder.setTitle(R.string.title_news);
                        builder.setCancelable(false);
                        builder.setMessage(Html.fromHtml(news, null, new NewsTagHandler()));

                        builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Editor edit = pref.edit();
                                edit.putLong(getString(R.string.NEWS_DATE_LAST_SHOWN),
                                        System.currentTimeMillis());
                                edit.commit();

                                showPluginInfo();
                            }
                        });

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

                        ((TextView) d.findViewById(android.R.id.message))
                                .setMovementMethod(LinkMovementMethod.getInstance());
                    }
                });
            } else {
                showPluginInfo();
            }
        } else {
            showPluginInfo();
        }
    }
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

public void showAlertDialog(String title, String message, View view, String positiveText,
        final Runnable positive, String negativeText, final Runnable negative, boolean link,
        boolean notCancelable) {
    AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);
    builder.setCancelable(!notCancelable);

    if (title != null) {
        builder.setTitle(title);//from  ww w .ja v  a2 s  .c o  m
    }
    if (message != null) {
        builder.setMessage(message);
    } else if (view != null) {
        builder.setView(view);
    }

    if (positive != null) {
        if (positiveText == null) {
            positiveText = getString(android.R.string.ok);
        }

        builder.setPositiveButton(positiveText, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (positive != null) {
                    positive.run();
                }
            }
        });
    }

    if (negative != null) {
        if (negativeText == null) {
            negativeText = getString(android.R.string.cancel);
        }

        builder.setNegativeButton(negativeText, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (negative != null) {
                    negative.run();
                }
            }
        });
    }

    AlertDialog d = builder.create();

    d.show();

    if (link) {
        TextView test = (TextView) d.findViewById(android.R.id.message);

        if (test != null) {
            test.setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
}

From source file:com.max2idea.android.limbo.main.LimboActivity.java

public void promptVNCAllowExternal(final Activity activity) {
    final AlertDialog alertDialog;
    alertDialog = new AlertDialog.Builder(activity).create();
    alertDialog.setTitle("Enable VNC server");

    TextView textView = new TextView(activity);
    textView.setVisibility(View.VISIBLE);
    textView.setId(201012010);/*w  ww  . java 2 s .c o m*/
    textView.setText("VNC Server: " + this.getLocalIpAddress() + ":" + "5901\n"
            + "Warning: VNC is not secure make sure you're on a private network!\n");

    EditText passwdView = new EditText(activity);
    passwdView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    passwdView.setHint("Password");
    passwdView.setEnabled(true);
    passwdView.setVisibility(View.VISIBLE);
    passwdView.setId(11111);
    passwdView.setSingleLine();

    RelativeLayout mLayout = new RelativeLayout(this);
    mLayout.setId(12222);

    RelativeLayout.LayoutParams textViewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    textViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, mLayout.getId());
    mLayout.addView(textView, textViewParams);

    RelativeLayout.LayoutParams passwordViewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

    passwordViewParams.addRule(RelativeLayout.BELOW, textView.getId());
    // passwordViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,
    // mLayout.getId());
    mLayout.addView(passwdView, passwordViewParams);

    alertDialog.setView(mLayout);

    final Handler handler = this.handler;

    alertDialog.setButton("Set", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

            // UIUtils.log("Searching...");
            EditText a = (EditText) alertDialog.findViewById(11111);

            if (a.getText().toString().trim().equals("")) {
                Toast.makeText(getApplicationContext(), "Password cannot be empty!", Toast.LENGTH_SHORT).show();
                vnc_passwd = null;
                vnc_allow_external = 0;
                mVNCAllowExternal.setChecked(false);
                // LimboSettingsManager.setVNCAllowExternal(activity, false);
                return;
            } else {
                sendHandlerMessage(handler, Const.VNC_PASSWORD, "vnc_passwd", "passwd");
                vnc_passwd = a.getText().toString();
                vnc_allow_external = 1;
                // LimboSettingsManager.setVNCAllowExternal(activity, true);
            }

        }
    });
    alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            vnc_passwd = null;
            vnc_allow_external = 0;
            mVNCAllowExternal.setChecked(false);
            // LimboSettingsManager.setVNCAllowExternal(activity, false);
            return;
        }
    });
    alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            mVNCAllowExternal.setChecked(false);
            // LimboSettingsManager.setVNCAllowExternal(activity, false);
            vnc_passwd = null;
            vnc_allow_external = 0;
        }
    });
    alertDialog.show();

}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void searchPlugins(final boolean showChannelUpdateInfo) {
    if (isOnline()) {
        new Thread("SEARCH FOR PLUGINS THREAD") {
            @Override//  www  .  jav a2 s  .  com
            public void run() {
                updateProgressIcon(true);
                PluginDefinition[] availablePlugins = PluginDefinition.loadAvailablePluginDefinitions();

                final ArrayList<PluginDefinition> newPlugins = new ArrayList<PluginDefinition>();
                final PluginServiceConnection[] connections = PluginHandler.getAvailablePlugins();

                for (PluginDefinition def : availablePlugins) {
                    if (Build.VERSION.SDK_INT >= def.getMinApiVersion()) {
                        String packageName = def.getPackageName();
                        String[] services = def.getServices();

                        for (String service : services) {
                            if (service.startsWith(".")) {
                                service = packageName + service;
                            }

                            String[] parts = service.split(":");

                            boolean wasAdded = false;
                            boolean wasFound = false;

                            if (connections != null && connections.length > 0) {
                                for (PluginServiceConnection connection : connections) {
                                    if (connection.getId().equals(parts[0])) {
                                        wasFound = true;

                                        String currentVersion = connection.getPluginVersion();

                                        if (currentVersion != null && !currentVersion.equals(parts[1])) {
                                            newPlugins.add(def);
                                            def.setIsUpdate();
                                            wasAdded = true;
                                            break;
                                        }
                                    }
                                }
                            }

                            if (wasAdded) {
                                break;
                            } else if (!wasFound) {
                                newPlugins.add(def);
                            }
                        }
                    }
                }

                StringBuilder pluginsText = new StringBuilder();

                Collections.sort(newPlugins);

                for (PluginDefinition news : newPlugins) {
                    if (pluginsText.length() > 0) {
                        pluginsText.append("<line>LINE</line>");
                    }

                    pluginsText.append("<h3>");
                    pluginsText.append(news.getName());

                    if (news.isUpdate()) {
                        pluginsText.append(" <i>(Update)</i>");
                    }

                    pluginsText.append("</h3>");

                    pluginsText.append(news.getDescription());

                    pluginsText.append("<p><i>");
                    pluginsText.append(getString(R.string.author)).append(" ");
                    pluginsText.append(news.getAuthor());
                    pluginsText.append(" <right>").append(getString(R.string.version)).append(" ");
                    pluginsText.append(news.getVersion());
                    pluginsText.append("</i></right></p>");

                    if (news.isOnGooglePlay()) {
                        pluginsText.append("<p><a href=\"http://play.google.com/store/apps/details?id=");
                        pluginsText.append(news.getPackageName());
                        pluginsText.append("\">").append(getString(R.string.plugin_open_google_play))
                                .append("</a></p>");
                    }

                    if (news.getDownloadLink() != null && news.getDownloadLink().trim().length() > 0) {
                        pluginsText.append("<p><a href=\"");
                        pluginsText.append(news.getDownloadLink().replace("http://", "plugin://")
                                .replace("https://", "plugins://"));
                        pluginsText.append("\">").append(getString(R.string.plugin_download_manually))
                                .append("</a></p>");
                    }
                }

                String title = getString(R.string.plugin_available_title);

                if (newPlugins.isEmpty()) {
                    title = getString(R.string.plugin_available_not_title);
                    pluginsText.append(getString(R.string.plugin_available_not_message));
                }

                final AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

                builder.setTitle(title);
                builder.setCancelable(false);

                builder.setMessage(
                        getClickableText(Html.fromHtml(pluginsText.toString(), null, new NewsTagHandler())));

                builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (!newPlugins.isEmpty()) {
                            PluginHandler.shutdownPlugins(TvBrowser.this);

                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    PluginHandler.loadPlugins(TvBrowser.this, handler);

                                    if (mPluginPreferencesMenuItem != null) {
                                        mPluginPreferencesMenuItem.setEnabled(PluginHandler.hasPlugins());
                                    }
                                }
                            }, 2000);
                        }

                        if (showChannelUpdateInfo) {
                            showChannelUpdateInfo();
                        }
                    }
                });

                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        AlertDialog d = builder.create();
                        d.show();

                        ((TextView) d.findViewById(android.R.id.message))
                                .setMovementMethod(LinkMovementMethod.getInstance());
                    }
                });

                updateProgressIcon(false);
            }
        }.start();
    }
}

From source file:com.max2idea.android.limbo.main.LimboActivity.java

public void promptImageName(final Activity activity, String hd) {
    final String hd_string = hd;
    final AlertDialog alertDialog;
    alertDialog = new AlertDialog.Builder(activity).create();
    alertDialog.setTitle("Image Name");

    RelativeLayout mLayout = new RelativeLayout(this);
    mLayout.setId(12222);/*from w  w w .  j a v a 2s .co m*/

    EditText imageNameView = new EditText(activity);
    imageNameView.setEnabled(true);
    imageNameView.setVisibility(View.VISIBLE);
    imageNameView.setId(201012010);
    imageNameView.setSingleLine();
    RelativeLayout.LayoutParams searchViewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    mLayout.addView(imageNameView, searchViewParams);

    final Spinner size = new Spinner(this);
    RelativeLayout.LayoutParams setPlusParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    size.setId(201012044);

    String[] arraySpinner = new String[7];
    for (int i = 0; i < arraySpinner.length; i++) {

        if (i < 5) {
            arraySpinner[i] = (i + 1) + " GB";
        }

    }
    arraySpinner[5] = "10 GB";
    arraySpinner[6] = "20 GB";

    ArrayAdapter sizeAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, arraySpinner);
    sizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    size.setAdapter(sizeAdapter);
    setPlusParams.addRule(RelativeLayout.BELOW, imageNameView.getId());
    mLayout.addView(size, setPlusParams);

    // TODO: Not working for now
    // final TextView preallocText = new TextView(this);
    // preallocText.setText("Preallocate? ");
    // preallocText.setTextSize(15);
    // RelativeLayout.LayoutParams preallocTParams = new
    // RelativeLayout.LayoutParams(
    // RelativeLayout.LayoutParams.WRAP_CONTENT,
    // RelativeLayout.LayoutParams.WRAP_CONTENT);
    // preallocTParams.addRule(RelativeLayout.BELOW, size.getId());
    // mLayout.addView(preallocText, preallocTParams);
    // preallocText.setId(64512044);
    //
    // final CheckBox prealloc = new CheckBox(this);
    // RelativeLayout.LayoutParams preallocParams = new
    // RelativeLayout.LayoutParams(
    // RelativeLayout.LayoutParams.WRAP_CONTENT,
    // RelativeLayout.LayoutParams.WRAP_CONTENT);
    // preallocParams.addRule(RelativeLayout.BELOW, size.getId());
    // preallocParams.addRule(RelativeLayout.RIGHT_OF,
    // preallocText.getId());
    // preallocParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,
    // preallocText.getId());
    // mLayout.addView(prealloc, preallocParams);
    // prealloc.setId(64512344);

    alertDialog.setView(mLayout);

    final Handler handler = this.handler;

    // alertDialog.setMessage(body);
    alertDialog.setButton("Create", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            int sizeSel = size.getSelectedItemPosition();
            String templateImage = "hd1g.qcow2";
            if (sizeSel < 5) {
                templateImage = "hd" + (sizeSel + 1) + "g.qcow2";
            } else if (sizeSel == 5) {
                templateImage = "hd10g.qcow2";
            } else if (sizeSel == 6) {
                templateImage = "hd20g.qcow2";
            }

            // UIUtils.log("Searching...");
            EditText a = (EditText) alertDialog.findViewById(201012010);
            progDialog = ProgressDialog.show(activity, "Please Wait", "Creating HD Image...", true);
            // CreateImage createImg = new
            // CreateImage(a.getText().toString(),
            // hd_string, sizeInt, prealloc.isChecked());
            //            CreateImage createImg = new CreateImage(a.getText().toString(),
            //                  hd_string, sizeInt, false);
            //            createImg.execute();

            String image = a.getText().toString();
            if (!image.endsWith(".qcow2")) {
                image += ".qcow2";
            }
            createImg(templateImage, image, hd_string);

        }
    });
    alertDialog.show();

}