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.master.metehan.filtereagle.ActivityMain.java

private void menu_about() {
    // Create view
    LayoutInflater inflater = LayoutInflater.from(this);
    View view = inflater.inflate(R.layout.about, null, false);
    TextView tvVersionName = (TextView) view.findViewById(R.id.tvVersionName);
    TextView tvVersionCode = (TextView) view.findViewById(R.id.tvVersionCode);
    Button btnRate = (Button) view.findViewById(R.id.btnRate);
    TextView tvLicense = (TextView) view.findViewById(R.id.tvLicense);

    // Show version
    tvVersionName.setText(Util.getSelfVersionName(this));
    if (!Util.hasValidFingerprint(this))
        tvVersionName.setTextColor(Color.GRAY);
    tvVersionCode.setText(Integer.toString(Util.getSelfVersionCode(this)));

    // Handle license
    tvLicense.setMovementMethod(LinkMovementMethod.getInstance());

    // Handle logcat
    view.setOnClickListener(new View.OnClickListener() {
        private short tap = 0;
        private Toast toast = Toast.makeText(ActivityMain.this, "", Toast.LENGTH_SHORT);

        @Override/*from  w ww  .  j  ava2s . c  o  m*/
        public void onClick(View view) {
            tap++;
            if (tap == 7) {
                tap = 0;
                toast.cancel();

                Intent intent = getIntentLogcat();
                if (intent.resolveActivity(getPackageManager()) != null)
                    startActivityForResult(intent, REQUEST_LOGCAT);

            } else if (tap > 3) {
                toast.setText(Integer.toString(7 - tap));
                toast.show();
            }
        }
    });

    // Handle rate
    btnRate.setVisibility(
            getIntentRate(this).resolveActivity(getPackageManager()) == null ? View.GONE : View.VISIBLE);
    btnRate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(getIntentRate(ActivityMain.this));
        }
    });

    // Show dialog
    dialogAbout = new AlertDialog.Builder(this).setView(view).setCancelable(true)
            .setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    dialogAbout = null;
                }
            }).create();
    dialogAbout.show();
}

From source file:de.frank_durr.ble_v_monitor.MainActivity.java

private void showAboutDialog() {
    View view = getLayoutInflater().inflate(R.layout.dialog_about, null, false);
    TextView textView = (TextView) view.findViewById(R.id.about_message);
    textView.setText(Html.fromHtml(getString(R.string.about_message)));
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setIcon(R.mipmap.ic_launcher);
    builder.setTitle(R.string.app_name);
    builder.setView(view);/*from w w w . j av  a 2  s .  c  o m*/
    builder.create();
    builder.show();
}

From source file:com.if3games.chessonline.DroidFish.java

private final void initUI() {
    leftHanded = leftHandedView();//from ww  w  . j  a  va 2  s.  c om
    if (!isSinglePlayer) {
        setContentView(leftHanded ? R.layout.main_left_handed_gms : R.layout.main_gms);
        for (int id : CLICKABLES) {
            findViewById(id).setOnClickListener(this);
        }
    } else {
        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)
    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);

    player1TitleText = (TextView) findViewById(R.id.player1);
    player2TitleText = (TextView) findViewById(R.id.player2);

    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);

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

    final GestureDetector gd = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
        private float scrollX = 0;
        private float scrollY = 0;

        @Override
        public boolean onDown(MotionEvent e) {
            if (!boardGestures) {
                handleClick(e);
                return true;
            }
            scrollX = 0;
            scrollY = 0;
            return false;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            if (!boardGestures)
                return false;
            cb.cancelLongPress();
            if (invertScrollDirection) {
                distanceX = -distanceX;
                distanceY = -distanceY;
            }
            if ((scrollSensitivity > 0) && (cb.sqSize > 0)) {
                scrollX += distanceX;
                scrollY += distanceY;
                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;
                    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);
                } else {
                    // Next/previous variation
                    int varDelta = 0;
                    while (scrollY > scrollUnit) {
                        varDelta++;
                        scrollY -= scrollUnit;
                    }
                    while (scrollY < -scrollUnit) {
                        varDelta--;
                        scrollY += scrollUnit;
                    }
                    if (varDelta != 0)
                        scrollX = 0;
                    ctrl.changeVariation(varDelta);
                }
            }
            return true;
        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            if (!boardGestures)
                return false;
            cb.cancelLongPress();
            handleClick(e);
            return true;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            if (!boardGestures)
                return false;
            if (e.getAction() == MotionEvent.ACTION_UP)
                handleClick(e);
            return true;
        }

        private final void handleClick(MotionEvent e) {
            if (ctrl.humansTurn() && myTurn) {
                int sq = cb.eventToSquare(e);
                Move m = cb.mousePressed(sq);
                if (m != null) {
                    ctrl.makeHumanMove(m);
                    if (!isSinglePlayer) {
                        if (!invalidMove)
                            broadcastMove(m.to, m.from);
                        else
                            invalidMove = false;
                    }
                }
                setEgtbHints(cb.getSelectedSquare());
            }
        }

        @Override
        public void onLongPress(MotionEvent e) {
            if (!boardGestures)
                return;
            ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(20);
            removeDialog(BOARD_MENU_DIALOG);
            showDialog(BOARD_MENU_DIALOG);
        }
    });
    cb.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            return gd.onTouchEvent(event);
        }
    });
    cb.setOnTrackballListener(new ChessBoard.OnTrackballListener() {
        public void onTrackballEvent(MotionEvent event) {
            if (ctrl.humansTurn()) {
                Move m = cb.handleTrackballEvent(event);
                if (m != null)
                    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) {
            if (isSinglePlayer)
                showDialog(GAME_MODE_DIALOG);
            else
                showDialog(GAME_GMS_MODE_DIALOG);
        }
    });
    undoButton = (ImageButton) findViewById(R.id.undoButton);
    redoButton = (ImageButton) findViewById(R.id.redoButton);

    if (isSinglePlayer) {
        undoButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                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.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ctrl.redoMove();
            }
        });
        redoButton.setOnLongClickListener(new OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                removeDialog(GO_FORWARD_MENU_DIALOG);
                showDialog(GO_FORWARD_MENU_DIALOG);
                return true;
            }
        });
    } else {
        undoButton.setVisibility(View.GONE);
        redoButton.setVisibility(View.GONE);
    }
}

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

private void showEpgDonateInfo() {
    if (!SHOWING_DONATION_INFO && hasEpgDonateChannelsSubscribed()) {
        final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this);

        final String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
        int month = Calendar.getInstance().get(Calendar.MONTH);

        final long now = System.currentTimeMillis();
        long firstDownload = pref.getLong(getString(R.string.EPG_DONATE_FIRST_DATA_DOWNLOAD), now);
        long lastDownload = pref.getLong(getString(R.string.EPG_DONATE_LAST_DATA_DOWNLOAD), now);
        long lastShown = pref.getLong(getString(R.string.EPG_DONATE_LAST_DONATION_INFO_SHOWN),
                (now - (60 * 24 * 60 * 60000L)));

        Calendar monthTest = Calendar.getInstance();
        monthTest.setTimeInMillis(lastShown);
        int shownMonth = monthTest.get(Calendar.MONTH);

        boolean firstTimeoutReached = (firstDownload + (14 * 24 * 60 * 60000L)) < now;
        boolean lastTimoutReached = lastDownload > (now - ((42 * 24 * 60 * 60000L)));
        boolean alreadyShowTimeoutReached = (lastShown + (14 * 24 * 60 * 60000L) < now);
        boolean alreadyShownThisMonth = shownMonth == month;
        boolean dontShowAgainThisYear = year
                .equals(pref.getString(getString(R.string.EPG_DONATE_DONT_SHOW_AGAIN_YEAR), "0"));
        boolean radomShow = Math.random() > 0.33;

        boolean show = firstTimeoutReached && lastTimoutReached && alreadyShowTimeoutReached
                && !alreadyShownThisMonth && !dontShowAgainThisYear && radomShow;

        //Log.d("info21", "firstTimeoutReached (" + ((now - firstDownload)/(24 * 60 * 60000L)) + "): " + firstTimeoutReached + " lastTimoutReached: " + lastTimoutReached + " alreadyShowTimeoutReached: " + alreadyShowTimeoutReached + " alreadyShownThisMonth: " + alreadyShownThisMonth + " dontShowAgainThisYear: " + dontShowAgainThisYear + " randomShow: " + radomShow + " SHOW: " + show);

        if (show) {
            AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

            String info = getString(R.string.epg_donate_info);
            String amount = getString(R.string.epg_donate_amount);
            String percentInfo = getString(R.string.epg_donate_percent_info);

            String amountValue = pref.getString(
                    getString(R.string.EPG_DONATE_CURRENT_DONATION_AMOUNT_PREFIX) + "_" + year,
                    getString(R.string.epg_donate_current_donation_amount_default));
            int percentValue = Integer
                    .parseInt(pref.getString(getString(R.string.EPG_DONATE_CURRENT_DONATION_PERCENT), "-1"));

            amount = amount.replace("{0}", year).replace("{1}", amountValue);

            info = info.replace("{0}", "<h2>" + amount + "</h2>");

            builder.setTitle(R.string.epg_donate_name);
            builder.setCancelable(false);

            View view = getLayoutInflater().inflate(R.layout.dialog_epg_donate_info, getParentViewGroup(),
                    false);/*from w ww . j a va 2  s  .co  m*/

            TextView message = (TextView) view.findViewById(R.id.dialog_epg_donate_message);
            message.setText(Html.fromHtml(info));
            message.setMovementMethod(LinkMovementMethod.getInstance());

            TextView percentInfoView = (TextView) view.findViewById(R.id.dialog_epg_donate_percent_info);
            percentInfoView.setText(Html.fromHtml(percentInfo, null, new NewsTagHandler()));

            SeekBar percent = (SeekBar) view.findViewById(R.id.dialog_epg_donate_percent);
            percent.setEnabled(false);

            if (percentValue >= 0) {
                percent.setProgress(percentValue);
            } else {
                percentInfoView.setVisibility(View.GONE);
                percent.setVisibility(View.GONE);
            }

            final Spinner reason = (Spinner) view.findViewById(R.id.dialog_epg_donate_reason_selection);
            reason.setEnabled(false);

            final CheckBox dontShowAgain = (CheckBox) view.findViewById(R.id.dialog_epg_donate_dont_show_again);
            dontShowAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    reason.setEnabled(isChecked);
                }
            });

            builder.setView(view);
            builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    SHOWING_DONATION_INFO = false;
                    Editor edit = pref.edit();
                    edit.putLong(getString(R.string.EPG_DONATE_LAST_DONATION_INFO_SHOWN), now);

                    if (dontShowAgain.isChecked()) {
                        edit.putString(getString(R.string.EPG_DONATE_DONT_SHOW_AGAIN_YEAR), year);
                    }

                    edit.commit();
                }
            });

            builder.show();
            SHOWING_DONATION_INFO = true;
        }
    }
}

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

private static void showDialog(Context context, int icon, String title, String message, boolean linkify) {
    SpannableString ss = new SpannableString(message);
    if (linkify) {
        Linkify.addLinks(ss, Linkify.ALL);
    }/*from w  w w. j  a  v  a2  s.c o  m*/

    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:gr.scify.newsum.ui.ViewActivity.java

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

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

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

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

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

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

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

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

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

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

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

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

                    String[] saTopicIDs = saTopicIDsArg;

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

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

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

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

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

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

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

                    // Update size
                    updateTextSize();

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

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

            });

            runOnUiThread(new Runnable() {

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

        }
    });

    runOnUiThread(new Runnable() {

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

    closeWaitingDialog();
}

From source file:org.sirimangalo.meditationplus.ActivityMain.java

private void populateOnline(JSONArray onlines) {

    if (onlines.length() == 0) {
        onlineList.setVisibility(View.GONE);
        return;//  w  w w . j ava2 s. co  m
    }

    onlineList.setVisibility(View.VISIBLE);

    ArrayList<JSONObject> onlineArray = new ArrayList<JSONObject>();
    ArrayList<String> onlineNamesArray = new ArrayList<String>();

    // collect into array

    for (int i = 0; i < onlines.length(); i++) {
        try {
            JSONObject a = onlines.getJSONObject(i);
            onlineArray.add(a);
            onlineNamesArray.add(a.getString("username"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    String text = getString(R.string.online) + " ";

    // add spans

    int pos = text.length(); // start after "Online: "

    text += TextUtils.join(", ", onlineNamesArray);
    Spannable span = new SpannableString(text);

    span.setSpan(new StyleSpan(Typeface.BOLD), 0, pos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // bold the "Online: "

    Drawable android = context.getResources().getDrawable(R.drawable.android);
    android.setBounds(0, 0, 48, 32);

    for (JSONObject oneOnA : onlineArray) {
        try {
            final String oneOn = oneOnA.getString("username");

            int end = pos + oneOn.length();

            boolean isMed = false;

            for (int j = 0; j < jsonList.length(); j++) {
                JSONObject user = jsonList.getJSONObject(j);
                String username = user.getString("username");
                if (username.equals(oneOn))
                    isMed = true;
            }

            if (oneOnA.getString("source").equals("android")) {
                ImageSpan image = new ImageSpan(android, ImageSpan.ALIGN_BASELINE);
                span.setSpan(image, pos - 1, pos, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            }

            ClickableSpan clickable = new ClickableSpan() {

                @Override
                public void onClick(View widget) {
                    showProfile(oneOn);
                }

            };
            span.setSpan(clickable, pos, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

            span.setSpan(new UnderlineSpan() {
                public void updateDrawState(TextPaint tp) {
                    tp.setUnderlineText(false);
                }
            }, pos, end, 0);

            span.setSpan(new ForegroundColorSpan(isMed ? 0xFF009900 : 0xFFFF9900), pos, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            pos += oneOn.length() + 2;

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    onlineList.setText(span);
    onlineList.setMovementMethod(LinkMovementMethod.getInstance());

}

From source file:edu.mit.viral.shen.DroidFish.java

private final void initUI() {
    leftHanded = leftHandedView();//from  w  ww  .  j  a va 2 s .  c om
    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)
    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);
    //   server = (TextView)findViewById(R.id.server);
    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);

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

    final GestureDetector gd = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
        private float scrollX = 0;
        private float scrollY = 0;

        @Override
        public boolean onDown(MotionEvent e) {
            if (!boardGestures) {
                handleClick(e);
                return true;
            }
            scrollX = 0;
            scrollY = 0;
            return false;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            if (!boardGestures)
                return false;
            cb.cancelLongPress();
            if (invertScrollDirection) {
                distanceX = -distanceX;
                distanceY = -distanceY;
            }
            if ((scrollSensitivity > 0) && (cb.sqSize > 0)) {
                scrollX += distanceX;
                scrollY += distanceY;
                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;
                    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);
                } else {
                    // Next/previous variation
                    int varDelta = 0;
                    while (scrollY > scrollUnit) {
                        varDelta++;
                        scrollY -= scrollUnit;
                    }
                    while (scrollY < -scrollUnit) {
                        varDelta--;
                        scrollY += scrollUnit;
                    }
                    if (varDelta != 0)
                        scrollX = 0;
                    ctrl.changeVariation(varDelta);
                }
            }
            return true;
        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            if (!boardGestures)
                return false;
            cb.cancelLongPress();
            handleClick(e);
            return true;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            if (!boardGestures)
                return false;
            if (e.getAction() == MotionEvent.ACTION_UP)
                handleClick(e);
            return true;
        }

        private final void handleClick(MotionEvent e) {
            if (ctrl.humansTurn()) {
                int sq = cb.eventToSquare(e);
                Move m = cb.mousePressed(sq);
                if (m != null) {
                    ctrl.makeHumanMove(m);
                    String longfen = TextIO.toFEN(cb.pos);
                    String sentout = utils.getSendMessageJSON(longfen);
                    sendJSON(sentout);
                    // String fen1=longfen.replaceAll("D","1");]
                    // commented out 04/12/15
                    // sendDataone(longfen, 1); 
                }

                setEgtbHints(cb.getSelectedSquare());
            }
        }

        @Override
        public void onLongPress(MotionEvent e) {
            if (!boardGestures)
                return;
            ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(20);
            removeDialog(BOARD_MENU_DIALOG);
            showDialog(BOARD_MENU_DIALOG);
        }
    });
    cb.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            return gd.onTouchEvent(event);
        }
    });
    cb.setOnTrackballListener(new ChessBoard.OnTrackballListener() {
        public void onTrackballEvent(MotionEvent event) {
            if (ctrl.humansTurn()) {
                Move m = cb.handleTrackballEvent(event);
                if (m != null)
                    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);
    }
            });
            */
    undoButton = (ImageButton) findViewById(R.id.undoButton);
    undoButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ctrl.undoMove();
            sendDataone(TextIO.toFEN(cb.pos), 1);

        }
    });
    undoButton.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            removeDialog(GO_BACK_MENU_DIALOG);
            showDialog(GO_BACK_MENU_DIALOG);
            return true;
        }
    });

    commentButton = (ImageButton) findViewById(R.id.commentbutton);
    commentButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this);
            builder.setTitle(R.string.edit_comments);
            View content = View.inflate(DroidFish.this, R.layout.edit_comments, null);
            builder.setView(content);

            DroidChessController.CommentInfo commInfo = ctrl.getComments();

            final TextView preComment, moveView, nag, postComment;
            preComment = (TextView) content.findViewById(R.id.ed_comments_pre);
            moveView = (TextView) content.findViewById(R.id.ed_comments_move);
            nag = (TextView) content.findViewById(R.id.ed_comments_nag);
            postComment = (TextView) content.findViewById(R.id.ed_comments_post);

            preComment.setText(commInfo.preComment);
            postComment.setText(commInfo.postComment);
            moveView.setText(commInfo.move);
            String nagStr = Node.nagStr(commInfo.nag).trim();
            if ((nagStr.length() == 0) && (commInfo.nag > 0))
                nagStr = String.format(Locale.US, "%d", commInfo.nag);
            nag.setText(nagStr);

            builder.setNegativeButton(R.string.cancel, null);
            builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    String pre = preComment.getText().toString().trim();
                    String post = postComment.getText().toString().trim();
                    sendComment(post);
                    int nagVal = Node.strToNag(nag.getText().toString());

                    DroidChessController.CommentInfo commInfo = new DroidChessController.CommentInfo();
                    commInfo.preComment = pre;
                    commInfo.postComment = post;
                    commInfo.nag = nagVal;
                    ctrl.setComments(commInfo);

                }
            });

            builder.show();
        }
    });
    commentButton.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            removeDialog(GO_FORWARD_MENU_DIALOG);
            showDialog(GO_FORWARD_MENU_DIALOG);
            return true;
        }
    });

    redoButton = (ImageButton) findViewById(R.id.redoButton);
    redoButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ctrl.redoMove();
            //startNewGame(2);
        }
    });
    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:com.tsp.clipsy.audio.RingdroidEditActivity.java

private void handleFatalError(final CharSequence errorInternalName, final CharSequence errorString,
        final Exception exception) {
    Log.i("Ringdroid", "handleFatalError");

    SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
    int failureCount = prefs.getInt(PREF_ERROR_COUNT, 0);
    final SharedPreferences.Editor prefsEditor = prefs.edit();
    prefsEditor.putInt(PREF_ERROR_COUNT, failureCount + 1);
    prefsEditor.commit();// w w  w  . jav a 2 s . c o m

    // Check if we already have a pref for whether or not we can
    // contact the server.
    int serverAllowed = prefs.getInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_UNKNOWN);

    if (serverAllowed == SERVER_ALLOWED_NO) {
        Log.i("Ringdroid", "ERR: SERVER_ALLOWED_NO");

        // Just show a simple "write error" message
        showFinalAlert(exception, errorString);
        return;
    }

    if (serverAllowed == SERVER_ALLOWED_YES) {
        Log.i("Ringdroid", "SERVER_ALLOWED_YES");

        new AlertDialog.Builder(RingdroidEditActivity.this).setTitle(R.string.alert_title_failure)
                .setMessage(errorString)
                .setPositiveButton(R.string.alert_ok_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        finish();
                        return;
                    }
                }).setCancelable(false).show();
        return;
    }

    // The number of times the user must have had a failure before
    // we'll ask them.  Defaults to 1, and each time they click "Later"
    // we double and add 1.
    final int allowServerCheckIndex = prefs.getInt(PREF_ERR_SERVER_CHECK, 1);
    if (failureCount < allowServerCheckIndex) {
        Log.i("Ringdroid", "failureCount " + failureCount + " is less than " + allowServerCheckIndex);
        // Just show a simple "write error" message
        showFinalAlert(exception, errorString);
        return;
    }

    final SpannableString message = new SpannableString(
            errorString + ". " + getResources().getText(R.string.error_server_prompt));
    Linkify.addLinks(message, Linkify.ALL);

    AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure)
            .setMessage(message).setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_YES);
                    prefsEditor.commit();
                    finish();
                    return;
                }
            }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    prefsEditor.putInt(PREF_ERR_SERVER_CHECK, 1 + allowServerCheckIndex * 2);
                    Log.i("Ringdroid",
                            "Won't check again until " + (1 + allowServerCheckIndex * 2) + " errors.");
                    prefsEditor.commit();
                    finish();
                }
            }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO);
                    prefsEditor.commit();
                    finish();
                }
            }).setCancelable(false).show();

    // Make links clicky
    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

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 ww  w  .j  a  v  a  2s .  c  o  m
    } 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());
    }
}