Example usage for android.text.method LinkMovementMethod getInstance

List of usage examples for android.text.method LinkMovementMethod getInstance

Introduction

In this page you can find the example usage for android.text.method LinkMovementMethod getInstance.

Prototype

public static MovementMethod getInstance() 

Source Link

Usage

From source file:com.andfchat.frontend.activities.ChatScreen.java

@Override
public void openAd(Spannable text) {
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View layout = inflater.inflate(R.layout.popup_description, null);

    int height = (int) (this.height * 0.8f);
    int width = (int) (this.width * 0.8f);

    final PopupWindow descriptionPopup = new FListPopupWindow(layout, width, height);
    descriptionPopup.showAtLocation(frame, Gravity.CENTER, 0, 0);

    final TextView descriptionText = (TextView) layout.findViewById(R.id.descriptionText);
    descriptionText.setText(text);//from w  ww  .  j ava2  s  . c  o  m
    // Enable touching/clicking links in text
    descriptionText.setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.pdftron.pdf.utils.Utils.java

public static void showAlertDialogWithLink(Context context, String message, String title) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    builder.setMessage(Html.fromHtml(message)).setCancelable(true).setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {

                @Override//from  w w  w .j a  va 2s .co m
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
    if (title.length() > 0) {
        builder.setTitle(title);
    }
    final AlertDialog d = builder.create();
    d.show();

    // Make the textview clickable. Must be called after show()
    ((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Shows the about screen.//w w w .  j a v a  2s  . c o m
 * 
 * @param activity
 *            the caller activity
 */
public static void showAbout(final FragmentActivity activity) {
    DialogFragment dialog = new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = getBuilder(activity);
            View layout = View.inflate(getContext(), R.layout.about, null);
            String version = "alpha";
            try {
                version = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
            ((TextView) layout.findViewById(R.id.title))
                    .setText(activity.getResources().getString(R.string.title_about_dialog, version));
            ((TextView) layout.findViewById(R.id.build_date)).setText(
                    activity.getResources().getString(R.string.build_date_about, getBuildDate(activity)));
            // make links clickable
            ((TextView) layout.findViewById(R.id.description))
                    .setMovementMethod(LinkMovementMethod.getInstance());
            builder.setView(layout);
            return builder.create();
        }
    };
    dialog.show(activity.getSupportFragmentManager(), "about");
}

From source file:org.tigase.mobile.TigaseMobileMessengerActivity.java

@Override
protected Dialog onCreateDialog(int id, Bundle bundle) {
    switch (id) {
    case NEWS_DIALOG: {

        String str = bundle.getString("news_html");

        Builder bldr = new AlertDialog.Builder(this);
        bldr.setTitle("News");
        bldr.setCancelable(true);/*from  w  ww  . j  a v  a2  s  .  c o  m*/
        bldr.setMessage(Html.fromHtml(str));
        return bldr.create();
    }

    case CONTACT_REMOVE_DIALOG:
        return null;
    case ABOUT_DIALOG: {

        final Dialog dialog = new Dialog(this);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);

        dialog.setContentView(R.layout.about_dialog);
        dialog.setTitle(getString(R.string.aboutButton));

        TextView tos = (TextView) dialog.findViewById(R.id.aboutTermsOfService);
        tos.setText(Html.fromHtml("<a href='" + getResources().getString(R.string.termsOfServiceURL) + "'>"
                + getResources().getString(R.string.termsOfService) + "</a>"));
        tos.setMovementMethod(LinkMovementMethod.getInstance());

        TextView pp = (TextView) dialog.findViewById(R.id.aboutPrivacyPolicy);
        pp.setText(Html.fromHtml("<a href='" + getResources().getString(R.string.privacyPolicyURL) + "'>"
                + getResources().getString(R.string.privacyPolicy) + "</a>"));
        pp.setMovementMethod(LinkMovementMethod.getInstance());

        Button okButton = (Button) dialog.findViewById(R.id.okButton);
        okButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                dialog.cancel();
            }
        });
        return dialog;
    }
    default:
        return null;
    }
}

From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java

@SuppressLint("SetTextI18n")
public void update(Lyrics lyrics, View layout, boolean animation) {
    File musicFile = null;//w w  w  .j  av  a2s .c o  m
    Bitmap cover = null;
    if (PermissionsChecker.hasPermission(getActivity(), "android.permission.READ_EXTERNAL_STORAGE")) {
        musicFile = Id3Reader.getFile(getActivity(), lyrics.getOriginalArtist(), lyrics.getOriginalTrack());
        cover = Id3Reader.getCover(getActivity(), lyrics.getArtist(), lyrics.getTitle());
    }
    setCoverArt(cover, null);
    boolean artCellDownload = Integer.valueOf(
            PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("pref_artworks", "0")) == 0;
    if (cover == null)
        new CoverArtLoader().execute(lyrics, this.getActivity(),
                artCellDownload || OnlineAccessVerifier.isConnectedWifi(getActivity()));
    getActivity().findViewById(R.id.edit_tags_btn).setEnabled(true);
    getActivity().findViewById(R.id.edit_tags_btn)
            .setVisibility(musicFile == null || !musicFile.canWrite() || lyrics.isLRC()
                    || Id3Reader.getLyrics(getActivity(), lyrics.getArtist(), lyrics.getTitle()) == null
                            ? View.GONE
                            : View.VISIBLE);
    TextSwitcher textSwitcher = ((TextSwitcher) layout.findViewById(R.id.switcher));
    LrcView lrcView = (LrcView) layout.findViewById(R.id.lrc_view);
    View v = getActivity().findViewById(R.id.tracks_msg);
    if (v != null)
        ((ViewGroup) v.getParent()).removeView(v);
    TextView artistTV = (TextView) getActivity().findViewById(R.id.artist);
    TextView songTV = (TextView) getActivity().findViewById(R.id.song);
    final TextView id3TV = (TextView) layout.findViewById(R.id.source_tv);
    TextView writerTV = (TextView) layout.findViewById(R.id.writer_tv);
    TextView copyrightTV = (TextView) layout.findViewById(R.id.copyright_tv);
    RelativeLayout bugLayout = (RelativeLayout) layout.findViewById(R.id.error_msg);
    this.mLyrics = lyrics;
    if (SDK_INT >= ICE_CREAM_SANDWICH)
        beamLyrics(lyrics, this.getActivity());
    new PresenceChecker().execute(this, new String[] { lyrics.getArtist(), lyrics.getTitle(),
            lyrics.getOriginalArtist(), lyrics.getOriginalTrack() });

    if (lyrics.getArtist() != null)
        artistTV.setText(lyrics.getArtist());
    else
        artistTV.setText("");
    if (lyrics.getTitle() != null)
        songTV.setText(lyrics.getTitle());
    else
        songTV.setText("");
    if (lyrics.getCopyright() != null) {
        copyrightTV.setText("Copyright: " + lyrics.getCopyright());
        copyrightTV.setVisibility(View.VISIBLE);
    } else {
        copyrightTV.setText("");
        copyrightTV.setVisibility(View.GONE);
    }
    if (lyrics.getWriter() != null) {
        if (lyrics.getWriter().contains(","))
            writerTV.setText("Writers:\n" + lyrics.getWriter());
        else
            writerTV.setText("Writer:" + lyrics.getWriter());
        writerTV.setVisibility(View.VISIBLE);
    } else {
        writerTV.setText("");
        writerTV.setVisibility(View.GONE);
    }
    if (isActiveFragment)
        ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).show();
    EditText newLyrics = (EditText) getActivity().findViewById(R.id.edit_lyrics);
    if (newLyrics != null)
        newLyrics.setText("");

    if (lyrics.getFlag() == Lyrics.POSITIVE_RESULT) {
        if (!lyrics.isLRC()) {
            textSwitcher.setVisibility(View.VISIBLE);
            lrcView.setVisibility(View.GONE);
            if (animation)
                textSwitcher.setText(Html.fromHtml(lyrics.getText()));
            else
                textSwitcher.setCurrentText(Html.fromHtml(lyrics.getText()));
        } else {
            textSwitcher.setVisibility(View.GONE);
            lrcView.setVisibility(View.VISIBLE);
            lrcView.setOriginalLyrics(lyrics);
            lrcView.setSourceLrc(lyrics.getText());
            if (isActiveFragment)
                ((ControllableAppBarLayout) getActivity().findViewById(R.id.appbar)).expandToolbar(true);
            updateLRC();
        }

        bugLayout.setVisibility(View.INVISIBLE);
        id3TV.setMovementMethod(LinkMovementMethod.getInstance());
        if ("Storage".equals(lyrics.getSource())) {
            id3TV.setVisibility(View.VISIBLE);
            SpannableString text = new SpannableString(getString(R.string.from_id3));
            text.setSpan(new UnderlineSpan(), 1, text.length() - 1, 0);
            id3TV.setText(text);
            id3TV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ((MainActivity) getActivity()).id3PopUp(id3TV);
                }
            });
        } else {
            id3TV.setOnClickListener(null);
            id3TV.setVisibility(View.GONE);
        }
        mScrollView.post(new Runnable() {
            @Override
            public void run() {
                mScrollView.scrollTo(0, 0); //only useful when coming from localLyricsFragment
                mScrollView.smoothScrollTo(0, 0);
            }
        });
    } else {
        textSwitcher.setText("");
        textSwitcher.setVisibility(View.INVISIBLE);
        lrcView.setVisibility(View.INVISIBLE);
        bugLayout.setVisibility(View.VISIBLE);
        int message;
        int whyVisibility;
        if (lyrics.getFlag() == Lyrics.ERROR || !OnlineAccessVerifier.check(getActivity())) {
            message = R.string.connection_error;
            whyVisibility = TextView.GONE;
        } else {
            message = R.string.no_results;
            whyVisibility = TextView.VISIBLE;
            updateSearchView(false, lyrics.getTitle(), false);
        }
        TextView whyTextView = ((TextView) bugLayout.findViewById(R.id.bugtext_why));
        ((TextView) bugLayout.findViewById(R.id.bugtext)).setText(message);
        whyTextView.setVisibility(whyVisibility);
        whyTextView.setPaintFlags(whyTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
        id3TV.setVisibility(View.GONE);
    }
    stopRefreshAnimation();
    getActivity().getIntent().setAction("");
    getActivity().invalidateOptionsMenu();
}

From source file:net.phase.wallet.Currency.java

protected void onPrepareDialog(int id, Dialog dialog) {
    switch (id) {
    case DIALOG_URL:
        TextView tv = (TextView) dialog.findViewById(R.id.pasteBinHelpText);
        tv.setMovementMethod(LinkMovementMethod.getInstance());

        break;/*from w  ww.java 2 s . c om*/
    case DIALOG_FILE:
        TextView tvhelp = (TextView) dialog.findViewById(R.id.helpText);
        tvhelp.setMovementMethod(LinkMovementMethod.getInstance());

        Spinner fileSpinner = (Spinner) dialog.findViewById(R.id.fileInput);

        File[] files = Environment.getExternalStorageDirectory().listFiles(fileFilter);

        if (files == null || files.length == 0) {
            toastMessage("No files found on sdcard");
        } else {
            ArrayAdapter<File> adapter = new ArrayAdapter<File>(this, android.R.layout.simple_spinner_item,
                    files);
            fileSpinner.setAdapter(adapter);
        }
        break;
    case DIALOG_PASTE:
        EditText keyText = (EditText) dialog.findViewById(R.id.keysText);

        keyText.setText("");
        break;
    case DIALOG_OPTIONS:
        EditText reqText = (EditText) dialog.findViewById(R.id.reqText);

        reqText.setText(Integer.toString(maxlength));
        Spinner currencySpinner = (Spinner) dialog.findViewById(R.id.currencySpinner);
        Spinner decimalSpinner = (Spinner) dialog.findViewById(R.id.decpointSpinner);

        String current = getActiveCurrency();
        String[] currencies = { current };

        try {
            currencies = Currency.getAvailableCurrencies();
        } catch (IOException e) {
            WalletActivity.toastMessage("Warning: unable to obtain currency information");
        } catch (JSONException e) {
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
                currencies);
        currencySpinner.setAdapter(adapter);
        for (int i = 0; i < currencies.length; i++) {
            if (currencies[i].equals(current)) {
                currencySpinner.setSelection(i);
                break;
            }
        }

        Integer[] decimaloptions = { 0, 1, 2, 3, 4, 5 };

        ArrayAdapter<Integer> adapter2 = new ArrayAdapter<Integer>(this, android.R.layout.simple_spinner_item,
                decimaloptions);
        decimalSpinner.setAdapter(adapter2);
        for (int i = 0; i < decimaloptions.length; i++) {
            if (decimaloptions[i].intValue() == decimalpoints) {
                decimalSpinner.setSelection(i);
                break;
            }
        }

        break;
    }
}

From source file:org.petero.droidfish.DroidFish.java

private final void initUI() {
    leftHanded = leftHandedView();//from  w w  w.  j a v  a2 s  .c  o m
    setContentView(leftHanded ? R.layout.main_left_handed : R.layout.main);
    Util.overrideFonts(findViewById(android.R.id.content));

    // title lines need to be regenerated every time due to layout changes (rotations)
    firstTitleLine = findViewById(R.id.first_title_line);
    secondTitleLine = findViewById(R.id.second_title_line);
    whiteTitleText = (TextView) findViewById(R.id.white_clock);
    whiteTitleText.setSelected(true);
    blackTitleText = (TextView) findViewById(R.id.black_clock);
    blackTitleText.setSelected(true);
    engineTitleText = (TextView) findViewById(R.id.title_text);
    whiteFigText = (TextView) findViewById(R.id.white_pieces);
    whiteFigText.setTypeface(figNotation);
    whiteFigText.setSelected(true);
    whiteFigText.setTextColor(whiteTitleText.getTextColors());
    blackFigText = (TextView) findViewById(R.id.black_pieces);
    blackFigText.setTypeface(figNotation);
    blackFigText.setSelected(true);
    blackFigText.setTextColor(blackTitleText.getTextColors());
    summaryTitleText = (TextView) findViewById(R.id.title_text_summary);

    status = (TextView) findViewById(R.id.status);
    moveListScroll = (ScrollView) findViewById(R.id.scrollView);
    moveList = (TextView) findViewById(R.id.moveList);
    defaultMoveListTypeFace = moveList.getTypeface();
    thinking = (TextView) findViewById(R.id.thinking);
    defaultThinkingListTypeFace = thinking.getTypeface();
    status.setFocusable(false);
    moveListScroll.setFocusable(false);
    moveList.setFocusable(false);
    moveList.setMovementMethod(LinkMovementMethod.getInstance());
    thinking.setFocusable(false);

    firstTitleLine.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            openOptionsMenu();
        }
    });
    secondTitleLine.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            openOptionsMenu();
        }
    });

    cb = (ChessBoardPlay) findViewById(R.id.chessboard);
    cb.setFocusable(true);
    cb.requestFocus();
    cb.setClickable(true);
    cb.setPgnOptions(pgnOptions);

    cb.setOnTouchListener(new OnTouchListener() {
        private boolean pending = false;
        private boolean pendingClick = false;
        private int sq0 = -1;
        private float scrollX = 0;
        private float scrollY = 0;
        private float prevX = 0;
        private float prevY = 0;
        private Handler handler = new Handler();
        private Runnable runnable = new Runnable() {
            public void run() {
                pending = false;
                handler.removeCallbacks(runnable);
                ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(20);
                removeDialog(BOARD_MENU_DIALOG);
                showDialog(BOARD_MENU_DIALOG);
            }
        };

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = MotionEventCompat.getActionMasked(event);
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                handler.postDelayed(runnable, ViewConfiguration.getLongPressTimeout());
                pending = true;
                pendingClick = true;
                sq0 = cb.eventToSquare(event);
                scrollX = 0;
                scrollY = 0;
                prevX = event.getX();
                prevY = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                if (pending) {
                    int sq = cb.eventToSquare(event);
                    if (sq != sq0) {
                        handler.removeCallbacks(runnable);
                        pendingClick = false;
                    }
                    float currX = event.getX();
                    float currY = event.getY();
                    if (onScroll(currX - prevX, currY - prevY)) {
                        handler.removeCallbacks(runnable);
                        pendingClick = false;
                    }
                    prevX = currX;
                    prevY = currY;
                }
                break;
            case MotionEvent.ACTION_UP:
                if (pending) {
                    pending = false;
                    handler.removeCallbacks(runnable);
                    if (!pendingClick)
                        break;
                    int sq = cb.eventToSquare(event);
                    if (sq == sq0) {
                        if (ctrl.humansTurn()) {
                            Move m = cb.mousePressed(sq);
                            if (m != null) {
                                setAutoMode(AutoMode.OFF);
                                ctrl.makeHumanMove(m);
                            }
                            setEgtbHints(cb.getSelectedSquare());
                        }
                    }
                }
                break;
            case MotionEvent.ACTION_CANCEL:
                pending = false;
                handler.removeCallbacks(runnable);
                break;
            }
            return true;
        }

        private boolean onScroll(float distanceX, float distanceY) {
            if (invertScrollDirection) {
                distanceX = -distanceX;
                distanceY = -distanceY;
            }
            if ((scrollSensitivity > 0) && (cb.sqSize > 0)) {
                scrollX += distanceX;
                scrollY += distanceY;
                final float scrollUnit = cb.sqSize * scrollSensitivity;
                if (Math.abs(scrollX) >= Math.abs(scrollY)) {
                    // Undo/redo
                    int nRedo = 0, nUndo = 0;
                    while (scrollX > scrollUnit) {
                        nRedo++;
                        scrollX -= scrollUnit;
                    }
                    while (scrollX < -scrollUnit) {
                        nUndo++;
                        scrollX += scrollUnit;
                    }
                    if (nUndo + nRedo > 0) {
                        scrollY = 0;
                        setAutoMode(AutoMode.OFF);
                    }
                    if (nRedo + nUndo > 1) {
                        boolean analysis = gameMode.analysisMode();
                        boolean human = gameMode.playerWhite() || gameMode.playerBlack();
                        if (analysis || !human)
                            ctrl.setGameMode(new GameMode(GameMode.TWO_PLAYERS));
                    }
                    for (int i = 0; i < nRedo; i++)
                        ctrl.redoMove();
                    for (int i = 0; i < nUndo; i++)
                        ctrl.undoMove();
                    ctrl.setGameMode(gameMode);
                    return nRedo + nUndo > 0;
                } else {
                    // Next/previous variation
                    int varDelta = 0;
                    while (scrollY > scrollUnit) {
                        varDelta++;
                        scrollY -= scrollUnit;
                    }
                    while (scrollY < -scrollUnit) {
                        varDelta--;
                        scrollY += scrollUnit;
                    }
                    if (varDelta != 0) {
                        scrollX = 0;
                        setAutoMode(AutoMode.OFF);
                        ctrl.changeVariation(varDelta);
                    }
                    return varDelta != 0;
                }
            }
            return false;
        }
    });
    cb.setOnTrackballListener(new ChessBoard.OnTrackballListener() {
        public void onTrackballEvent(MotionEvent event) {
            if (ctrl.humansTurn()) {
                Move m = cb.handleTrackballEvent(event);
                if (m != null) {
                    setAutoMode(AutoMode.OFF);
                    ctrl.makeHumanMove(m);
                }
                setEgtbHints(cb.getSelectedSquare());
            }
        }
    });

    moveList.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            removeDialog(MOVELIST_MENU_DIALOG);
            showDialog(MOVELIST_MENU_DIALOG);
            return true;
        }
    });
    thinking.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            if (mShowThinking || gameMode.analysisMode()) {
                if (!pvMoves.isEmpty()) {
                    removeDialog(THINKING_MENU_DIALOG);
                    showDialog(THINKING_MENU_DIALOG);
                }
            }
            return true;
        }
    });

    custom1Button = (ImageButton) findViewById(R.id.custom1Button);
    custom1ButtonActions.setImageButton(custom1Button, this);
    custom2Button = (ImageButton) findViewById(R.id.custom2Button);
    custom2ButtonActions.setImageButton(custom2Button, this);
    custom3Button = (ImageButton) findViewById(R.id.custom3Button);
    custom3ButtonActions.setImageButton(custom3Button, this);

    modeButton = (ImageButton) findViewById(R.id.modeButton);
    modeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(GAME_MODE_DIALOG);
        }
    });
    modeButton.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            openOptionsMenu();
            return true;
        }
    });
    undoButton = (ImageButton) findViewById(R.id.undoButton);
    undoButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setAutoMode(AutoMode.OFF);
            ctrl.undoMove();
        }
    });
    undoButton.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            removeDialog(GO_BACK_MENU_DIALOG);
            showDialog(GO_BACK_MENU_DIALOG);
            return true;
        }
    });
    redoButton = (ImageButton) findViewById(R.id.redoButton);
    redoButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setAutoMode(AutoMode.OFF);
            ctrl.redoMove();
        }
    });
    redoButton.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            removeDialog(GO_FORWARD_MENU_DIALOG);
            showDialog(GO_FORWARD_MENU_DIALOG);
            return true;
        }
    });
}

From source file:github.daneren2005.dsub.util.Util.java

private static void showDialog(Context context, int icon, String title, String message) {
    SpannableString ss = new SpannableString(message);
    Linkify.addLinks(ss, Linkify.ALL);//  w w  w  . j av  a 2 s. c  om

    AlertDialog dialog = new AlertDialog.Builder(context).setIcon(icon).setTitle(title).setMessage(ss)
            .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int i) {
                    dialog.dismiss();
                }
            }).show();

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

From source file:org.tpmkranz.notifyme.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.main_menu_checkaccessibility:
        prefs.setPrevVersion(0);/*w ww. j  a  v  a 2 s . c om*/
        ((TemporaryStorage) getApplicationContext()).accessGranted(false);
        finish();
        startActivity(getIntent());
        return true;
    case R.id.main_menu_popup:
        final View view = ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE))
                .inflate(R.layout.main_menu_popup, null);
        if (android.os.Build.VERSION.SDK_INT >= 11)
            view.findViewById(R.id.main_menu_popup_background).setVisibility(View.GONE);
        ((CheckBox) view.findViewById(R.id.main_menu_popup_background_checkbox))
                .setChecked(prefs.isBackgroundColorInverted());
        view.findViewById(R.id.main_menu_popup_background_caption)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((CheckBox) view.findViewById(R.id.main_menu_popup_background_checkbox)).toggle();
                    }
                });
        ((CheckBox) view.findViewById(R.id.main_menu_popup_orientation_checkbox))
                .setChecked(prefs.isOrientationFixed());
        view.findViewById(R.id.main_menu_popup_orientation_caption)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((CheckBox) view.findViewById(R.id.main_menu_popup_orientation_checkbox)).toggle();
                    }
                });
        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r)).setMax(255);
        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r))
                .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        if (fromUser) {
                            ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_r))
                                    .setText((progress == 0 ? "" : String.valueOf(progress)));
                        }

                        ((ImageView) view.findViewById(R.id.main_menu_popup_color_preview))
                                .setImageDrawable(new ColorDrawable(Color.rgb(progress,
                                        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g))
                                                .getProgress(),
                                        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b))
                                                .getProgress())));
                    }
                });
        ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_r))
                .addTextChangedListener(new TextWatcher() {
                    @Override
                    public void afterTextChanged(Editable s) {
                        try {
                            if (Integer.parseInt(s.toString()) > 255) {
                                s.replace(0, s.length(), "255");
                                return;
                            } else if (Integer.parseInt(s.toString()) < 0) {
                                s.replace(0, s.length(), "0");
                                return;
                            }
                            ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r))
                                    .setProgress(Integer.parseInt(s.toString()));
                        } catch (Exception e) {
                            ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r)).setProgress(0);
                            s.clear();
                        }
                    }

                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                    }
                });
        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g)).setMax(255);
        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g))
                .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        if (fromUser) {
                            ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_g))
                                    .setText((progress == 0 ? "" : String.valueOf(progress)));
                        }
                        ((ImageView) view.findViewById(R.id.main_menu_popup_color_preview))
                                .setImageDrawable(new ColorDrawable(Color.rgb(
                                        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r))
                                                .getProgress(),
                                        progress,
                                        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b))
                                                .getProgress())));
                    }
                });
        ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_g))
                .addTextChangedListener(new TextWatcher() {
                    @Override
                    public void afterTextChanged(Editable s) {
                        try {
                            if (Integer.parseInt(s.toString()) > 255) {
                                s.replace(0, s.length(), "255");
                                return;
                            } else if (Integer.parseInt(s.toString()) < 0) {
                                s.replace(0, s.length(), "0");
                                return;
                            }
                            ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g))
                                    .setProgress(Integer.parseInt(s.toString()));
                        } catch (Exception e) {
                            ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g)).setProgress(0);
                            s.clear();
                        }
                    }

                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                    }
                });
        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b)).setMax(255);
        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b))
                .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        if (fromUser) {
                            ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_b))
                                    .setText((progress == 0 ? "" : String.valueOf(progress)));
                        }
                        ((ImageView) view.findViewById(R.id.main_menu_popup_color_preview))
                                .setImageDrawable(new ColorDrawable(Color.rgb(
                                        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r))
                                                .getProgress(),
                                        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g))
                                                .getProgress(),
                                        progress)));
                    }
                });
        ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_b))
                .addTextChangedListener(new TextWatcher() {
                    @Override
                    public void afterTextChanged(Editable s) {
                        try {
                            if (Integer.parseInt(s.toString()) > 255) {
                                s.replace(0, s.length(), "255");
                                return;
                            } else if (Integer.parseInt(s.toString()) < 0) {
                                s.replace(0, s.length(), "0");
                                return;
                            }
                            ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b))
                                    .setProgress(Integer.parseInt(s.toString()));
                        } catch (Exception e) {
                            ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b)).setProgress(0);
                            s.clear();
                        }
                    }

                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                    }
                });
        ((ImageView) view.findViewById(R.id.main_menu_popup_color_preview))
                .setImageDrawable(new ColorDrawable(Color.rgb(prefs.getSliderBackgroundR(),
                        prefs.getSliderBackgroundG(), prefs.getSliderBackgroundB())));
        ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_r))
                .setText(String.valueOf(prefs.getSliderBackgroundR()));
        ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_g))
                .setText(String.valueOf(prefs.getSliderBackgroundG()));
        ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_b))
                .setText(String.valueOf(prefs.getSliderBackgroundB()));
        ((EditText) view.findViewById(R.id.main_menu_popup_timeout_editor)).setText(
                (prefs.getScreenTimeout() == 0L ? "" : String.valueOf(prefs.getScreenTimeout() / 1000L)));
        ((EditText) view.findViewById(R.id.main_menu_popup_timeout_editor))
                .addTextChangedListener(new TextWatcher() {
                    @Override
                    public void afterTextChanged(Editable s) {
                        if (s.toString().equals(""))
                            return;
                        try {
                            if (Long.parseLong(s.toString()) > 9999L)
                                s.replace(0, s.length(), "9999");
                            else if (Long.parseLong(s.toString()) < 0L)
                                s.replace(0, s.length(), "0");
                        } catch (Exception e) {
                            s.clear();
                        }
                    }

                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                    }
                });
        ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                .setChecked(prefs.isInterfaceSlider());
        ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(0)
                                .setEnabled(((CheckBox) v).isChecked());
                        for (int i = 0; i < 3; i++) {
                            ((ViewGroup) ((ViewGroup) ((ViewGroup) view
                                    .findViewById(R.id.main_menu_popup_color)).getChildAt(1)).getChildAt(i))
                                            .getChildAt(0).setEnabled(((CheckBox) v).isChecked());
                            ((ViewGroup) ((ViewGroup) ((ViewGroup) view
                                    .findViewById(R.id.main_menu_popup_color)).getChildAt(1)).getChildAt(i))
                                            .getChildAt(1).setEnabled(((CheckBox) v).isChecked());
                        }
                        ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(2)
                                .setVisibility((((CheckBox) v).isChecked() ? View.VISIBLE : View.INVISIBLE));
                    }
                });
        ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(0).setEnabled(
                ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)).isChecked());
        for (int i = 0; i < 3; i++) {
            ((ViewGroup) ((ViewGroup) ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(1))
                    .getChildAt(i)).getChildAt(0)
                            .setEnabled(((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                                    .isChecked());
            ((ViewGroup) ((ViewGroup) ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(1))
                    .getChildAt(i)).getChildAt(1)
                            .setEnabled(((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                                    .isChecked());
        }
        ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(2).setVisibility(
                (((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)).isChecked()
                        ? View.VISIBLE
                        : View.INVISIBLE));
        view.findViewById(R.id.main_menu_popup_interface_caption)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)).toggle();
                        ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(0).setEnabled(
                                ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                                        .isChecked());
                        for (int i = 0; i < 3; i++) {
                            ((ViewGroup) ((ViewGroup) ((ViewGroup) view
                                    .findViewById(R.id.main_menu_popup_color)).getChildAt(1)).getChildAt(i))
                                            .getChildAt(0)
                                            .setEnabled(((CheckBox) view
                                                    .findViewById(R.id.main_menu_popup_interface_checkbox))
                                                            .isChecked());
                            ((ViewGroup) ((ViewGroup) ((ViewGroup) view
                                    .findViewById(R.id.main_menu_popup_color)).getChildAt(1)).getChildAt(i))
                                            .getChildAt(1)
                                            .setEnabled(((CheckBox) view
                                                    .findViewById(R.id.main_menu_popup_interface_checkbox))
                                                            .isChecked());
                        }
                        ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(2).setVisibility(
                                (((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                                        .isChecked() ? View.VISIBLE : View.INVISIBLE));
                    }
                });
        new AlertDialog.Builder(this).setView(view)
                .setPositiveButton(R.string.main_menu_popup_save_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        prefs.setBackgroundColorInverted(
                                ((CheckBox) view.findViewById(R.id.main_menu_popup_background_checkbox))
                                        .isChecked());
                        prefs.setInterfaceSlider(
                                ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                                        .isChecked());
                        prefs.setSliderBackground(
                                ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r))
                                        .getProgress(),
                                ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g))
                                        .getProgress(),
                                ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b))
                                        .getProgress());
                        prefs.setScreenTimeout(
                                (((EditText) view.findViewById(R.id.main_menu_popup_timeout_editor)).getText()
                                        .toString().equals("")
                                                ? 0L
                                                : Long.parseLong(((EditText) view
                                                        .findViewById(R.id.main_menu_popup_timeout_editor))
                                                                .getText().toString())
                                                        * 1000L));
                        prefs.setOrientationFixed(
                                ((CheckBox) view.findViewById(R.id.main_menu_popup_orientation_checkbox))
                                        .isChecked());
                    }
                }).setNegativeButton(R.string.main_menu_popup_cancel_button, null).show();
        return true;
    case R.id.main_menu_help:
        new AlertDialog.Builder(this).setMessage(R.string.main_menu_help_message)
                .setTitle(R.string.main_menu_help_title)
                .setPositiveButton(R.string.main_menu_help_ok_button, null).setNegativeButton(
                        R.string.main_menu_help_question_button, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                startActivity(new Intent(Intent.ACTION_VIEW,
                                        Uri.parse("http://forum.xda-developers.com/showthread.php?t=2173226"))
                                                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                            }
                        })
                .show();
        return true;
    case R.id.main_menu_about:
        ViewGroup about = (ViewGroup) ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE))
                .inflate(R.layout.main_menu_about, null);
        ((TextView) about.getChildAt(0)).setMovementMethod(LinkMovementMethod.getInstance());
        new AlertDialog.Builder(this).setView(about).setTitle(R.string.main_menu_about_title)
                .setPositiveButton(R.string.main_menu_about_ok_button, null).show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:net.phase.wallet.Currency.java

protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder;/* w  w w  .  j  av a2 s  .  com*/
    AlertDialog alertDialog;
    builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = null;
    final WalletActivity parentActivity = this;

    switch (id) {
    case DIALOG_URL:
        layout = inflater.inflate(R.layout.urlfetch_dialog, null);

        TextView tv = (TextView) layout.findViewById(R.id.pasteBinHelpText);
        tv.setMovementMethod(LinkMovementMethod.getInstance());

        final EditText hashEditText = (EditText) layout.findViewById(R.id.hashEditText);
        final EditText nameEditText = (EditText) layout.findViewById(R.id.nameEditText);

        builder.setView(layout);
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                String hash = hashEditText.getText().toString();
                String name = nameEditText.getText().toString();

                if (!hash.startsWith("http")) {
                    hash = "http://pastebin.com/raw.php?i=" + hash;
                }

                try {
                    Wallet w = new Wallet(name, new URI(hash), parentActivity);
                    addWallet(w);
                } catch (Exception e) {
                    toastMessage(e.getMessage());
                }
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        break;
    case DIALOG_FILE:
        layout = inflater.inflate(R.layout.file_dialog, null);

        TextView tvhelp = (TextView) layout.findViewById(R.id.helpText);
        tvhelp.setMovementMethod(LinkMovementMethod.getInstance());

        final Spinner fileSpinner = (Spinner) layout.findViewById(R.id.fileInput);
        final EditText nameEditText2 = (EditText) layout.findViewById(R.id.nameEditText);

        builder.setView(layout);
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                File filename = (File) fileSpinner.getSelectedItem();
                String name = nameEditText2.getText().toString();
                boolean alreadyexists = false;

                if (name.length() > 0) {
                    if (wallets != null && wallets.length > 0) {
                        for (Wallet w : wallets) {
                            if (w.name.equals(name)) {
                                alreadyexists = true;
                            }
                        }
                    }

                    if (!alreadyexists) {
                        try {
                            Wallet w = new Wallet(name, filename, parentActivity);
                            addWallet(w);
                        } catch (Exception e) {
                            toastMessage(e.getMessage());
                        }
                    } else {
                        toastMessage("Wallet already exists");
                    }
                } else {
                    toastMessage("Invalid Name");
                }
            }
        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        break;
    case DIALOG_PASTE:
        layout = inflater.inflate(R.layout.paste_dialog, null);

        final EditText keysText = (EditText) layout.findViewById(R.id.keysText);
        final EditText nameEditText3 = (EditText) layout.findViewById(R.id.walletNameText);

        builder.setView(layout);
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                String keys = keysText.getText().toString();
                String name = nameEditText3.getText().toString();
                boolean alreadyexists = false;

                if (name.length() > 0) {
                    if (wallets != null && wallets.length > 0) {
                        for (Wallet w : wallets) {
                            if (w.name.equals(name)) {
                                alreadyexists = true;
                            }
                        }
                    }

                    if (!alreadyexists) {
                        try {
                            Wallet w = new Wallet(name, keys, parentActivity);
                            addWallet(w);
                        } catch (Exception e) {
                            toastMessage(e.getMessage());
                        }
                    } else {
                        toastMessage("Wallet already exists");
                    }
                } else {
                    toastMessage("Invalid Name");
                }
            }
        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        break;
    case DIALOG_OPTIONS:
        layout = inflater.inflate(R.layout.options_dialog, null);

        final Spinner currencySpinner = (Spinner) layout.findViewById(R.id.currencySpinner);
        final EditText reqText = (EditText) layout.findViewById(R.id.reqText);
        final Spinner decpointSpinner = (Spinner) layout.findViewById(R.id.decpointSpinner);

        builder.setView(layout);
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                String currency = (String) currencySpinner.getSelectedItem();
                decimalpoints = ((Integer) decpointSpinner.getSelectedItem()).intValue();
                setActiveCurrency(currency);
                try {
                    maxlength = Integer.parseInt(reqText.getText().toString());
                } catch (RuntimeException e) {
                    toastMessage("Invalid number");
                }
                savePreferences();
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        break;

    }

    alertDialog = builder.create();

    return alertDialog;
}