Example usage for android.text.util Linkify addLinks

List of usage examples for android.text.util Linkify addLinks

Introduction

In this page you can find the example usage for android.text.util Linkify addLinks.

Prototype

public static final boolean addLinks(@NonNull TextView text, @LinkifyMask int mask) 

Source Link

Document

Scans the text of the provided TextView and turns all occurrences of the link types indicated in the mask into clickable links.

Usage

From source file:com.razza.apps.iosched.myschedule.MyScheduleActivity.java

private void showAnnouncementDialogIfNeeded(Intent intent) {
    final String title = intent.getStringExtra(EXTRA_DIALOG_TITLE);
    final String message = intent.getStringExtra(EXTRA_DIALOG_MESSAGE);

    if (!mShowedAnnouncementDialog && !TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
        LogUtils.LOGD(TAG, "showAnnouncementDialogIfNeeded, title: " + title);
        LogUtils.LOGD(TAG, "showAnnouncementDialogIfNeeded, message: " + message);
        final String yes = intent.getStringExtra(EXTRA_DIALOG_YES);
        LogUtils.LOGD(TAG, "showAnnouncementDialogIfNeeded, yes: " + yes);
        final String no = intent.getStringExtra(EXTRA_DIALOG_NO);
        LogUtils.LOGD(TAG, "showAnnouncementDialogIfNeeded, no: " + no);
        final String url = intent.getStringExtra(EXTRA_DIALOG_URL);
        LogUtils.LOGD(TAG, "showAnnouncementDialogIfNeeded, url: " + url);
        final SpannableString spannable = new SpannableString(message == null ? "" : message);
        Linkify.addLinks(spannable, Linkify.WEB_URLS);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        if (!TextUtils.isEmpty(title)) {
            builder.setTitle(title);// w w w .j a  va 2  s.  c  o m
        }
        builder.setMessage(spannable);
        if (!TextUtils.isEmpty(no)) {
            builder.setNegativeButton(no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
        }
        if (!TextUtils.isEmpty(yes)) {
            builder.setPositiveButton(yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    startActivity(intent);
                }
            });
        }
        final AlertDialog dialog = builder.create();
        dialog.show();
        final TextView messageView = (TextView) dialog.findViewById(android.R.id.message);
        if (messageView != null) {
            // makes the embedded links in the text clickable, if there are any
            messageView.setMovementMethod(LinkMovementMethod.getInstance());
        }
        mShowedAnnouncementDialog = true;
    }
}

From source file:com.avapira.bobroreader.hanabira.HanabiraParser.java

@SuppressWarnings("ConstantConditions")
private void replaceAll(String begin, String end, SpanObjectFactory factory, int flag) {
    int removedFormatCharsDelta = 0;
    Pattern pattern = Pattern.compile(String.format("(%s)(.+?)(%s)", begin, end), Pattern.MULTILINE | flag);
    String beginRestore = restoreBreaks(begin);
    String endRestore = restoreBreaks(end);
    Matcher matcher = pattern.matcher(builder);
    String inlinedString;/* w w  w. j  a  v  a2 s .  co  m*/

    boolean code = begin.contains("`");
    while (matcher.find()) {
        int start = matcher.start(2);
        int finish = matcher.end(2);

        // don't reformat in code blocks
        if (!code) {
            CodeBlockSpan[] spans = builder.getSpans(start, finish, CodeBlockSpan.class);
            if (spans != null && spans.length != 0) {
                continue;
            }
        }

        // don't reformat double borders while searchin for sinlges
        // e.g.: searching for "*abc*", found "**"
        inlinedString = matcher.group(2);
        if (inlinedString == null || "".equals(inlinedString)) {
            System.out.println(matcher.group());
            continue;
        }

        int lengthPrefix = matcher.group(1).length();
        builder.replace(matcher.start(1) - removedFormatCharsDelta, matcher.end(1) - removedFormatCharsDelta,
                beginRestore);

        builder.replace(matcher.start(3) - lengthPrefix - removedFormatCharsDelta + beginRestore.length(),
                matcher.end(3) - lengthPrefix - removedFormatCharsDelta + beginRestore.length(), endRestore);

        SpannableString rep = new SpannableString(matcher.group(2));
        rep.setSpan(factory.getSpan(), 0, rep.length(), 0);
        if (!code) {
            Linkify.addLinks(rep, Linkify.WEB_URLS);
            // fixme twice used Linkify? try remove and just setSpan to builder
        }
        builder.replace(matcher.start() - removedFormatCharsDelta + beginRestore.length(),
                matcher.start() + rep.length() - removedFormatCharsDelta + endRestore.length(), rep);

        // store deletions
        removedFormatCharsDelta += matcher.group(1).length() - beginRestore.length();
        removedFormatCharsDelta += matcher.group(3).length() - endRestore.length();
    }
}

From source file:de.baumann.hhsmoodle.data_notes.Notes_Fragment.java

public void setNotesList() {

    if (isFABOpen) {
        closeFABMenu();/*from  ww w  . ja v  a  2 s .c  o m*/
    }

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "note_title", "note_content", "note_creation" };
    final Cursor row = db.fetchAllData(getActivity());
    adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes);
            helper_main.switchIcon(getActivity(), note_icon, "note_icon", iv_icon);

            switch (note_attachment) {
            case "":
                iv_attachment.setVisibility(View.GONE);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.ic_attachment);
                break;
            }

            File file = new File(note_attachment);
            if (!file.exists()) {
                iv_attachment.setVisibility(View.GONE);
            }

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red), };

                    ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                            android.R.layout.select_dialog_item, android.R.id.text1, items) {
                        @NonNull
                        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                            //Use super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView) v.findViewById(android.R.id.text1);
                            tv.setTextSize(18);
                            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new AlertDialog.Builder(getActivity())
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            }).setAdapter(adapter, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "3",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "2",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "1",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(getActivity(), lv, note_attachment);
                }
            });
            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_noteBY", "note_title");
    sharedPref.edit().putString("filter_noteBY", "note_title").apply();
    filter.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

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

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final Button attachment;
            final TextView textInput;

            LayoutInflater inflater = getActivity().getLayoutInflater();

            final ViewGroup nullParent = null;
            final View dialogView = inflater.inflate(R.layout.dialog_note_show, nullParent);

            final String attName = note_attachment.substring(note_attachment.lastIndexOf("/") + 1);
            final String att = getString(R.string.app_att) + ": " + attName;

            attachment = (Button) dialogView.findViewById(R.id.button_att);
            if (attName.equals("")) {
                attachment.setVisibility(View.GONE);
            } else {
                attachment.setText(att);
            }

            textInput = (TextView) dialogView.findViewById(R.id.note_text_input);
            if (note_content.isEmpty()) {
                textInput.setVisibility(View.GONE);
            } else {
                textInput.setText(note_content);
                Linkify.addLinks(textInput, Linkify.WEB_URLS);
            }

            attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(getActivity(), textInput, note_attachment);
                }
            });

            final ImageView be = (ImageView) dialogView.findViewById(R.id.imageButtonPri);
            final ImageView attImage = (ImageView) dialogView.findViewById(R.id.attImage);

            File file2 = new File(note_attachment);
            if (!file2.exists()) {
                attachment.setVisibility(View.GONE);
                attImage.setVisibility(View.GONE);
            } else if (note_attachment.contains(".gif") || note_attachment.contains(".bmp")
                    || note_attachment.contains(".tiff") || note_attachment.contains(".png")
                    || note_attachment.contains(".jpg") || note_attachment.contains(".JPG")
                    || note_attachment.contains(".jpeg") || note_attachment.contains(".mpeg")
                    || note_attachment.contains(".mp4") || note_attachment.contains(".3gp")
                    || note_attachment.contains(".3g2") || note_attachment.contains(".avi")
                    || note_attachment.contains(".flv") || note_attachment.contains(".h261")
                    || note_attachment.contains(".h263") || note_attachment.contains(".h264")
                    || note_attachment.contains(".asf") || note_attachment.contains(".wmv")) {
                attImage.setVisibility(View.VISIBLE);

                try {
                    Glide.with(getActivity()).load(note_attachment) // or URI/path
                            .diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(attImage); //imageView to set thumbnail to
                } catch (Exception e) {
                    Log.w("HHS_Moodle", "Error load thumbnail", e);
                    attImage.setVisibility(View.GONE);
                }

                attImage.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        helper_main.openAtt(getActivity(), attImage, note_attachment);
                    }
                });
            }

            switch (note_icon) {
            case "3":
                be.setImageResource(R.drawable.circle_green);
                break;
            case "2":
                be.setImageResource(R.drawable.circle_yellow);
                break;
            case "1":
                be.setImageResource(R.drawable.circle_red);
                break;
            }

            android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(getActivity())
                    .setTitle(note_title).setView(dialogView)
                    .setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setNegativeButton(R.string.note_edit, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            sharedPref.edit().putString("handleTextTitle", note_title)
                                    .putString("handleTextText", note_content)
                                    .putString("handleTextIcon", note_icon).putString("handleTextSeqno", _id)
                                    .putString("handleTextAttachment", note_attachment)
                                    .putString("handleTextCreate", note_creation).apply();
                            helper_main.switchToActivity(getActivity(), Activity_EditNote.class, false);
                        }
                    });
            dialog.show();
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_share),
                    getString(R.string.todo_menu), getString(R.string.count_create),
                    getString(R.string.bookmark_createEvent) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.number_edit_entry))) {
                                Notes_helper.newNote(getActivity(), note_title, note_content, note_icon,
                                        note_attachment, note_creation, _id);
                            }

                            if (options[item].equals(getString(R.string.todo_share))) {
                                File attachment = new File(note_attachment);
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, note_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, note_content);

                                if (attachment.exists()) {
                                    Uri bmpUri = Uri.fromFile(attachment);
                                    sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                                }

                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.todo_menu))) {
                                Todo_helper.newTodo(getActivity(), note_title, note_content,
                                        getActivity().getString(R.string.note_content));
                            }

                            if (options[item].equals(getString(R.string.count_create))) {
                                Count_helper.newCount(getActivity(), note_title, note_content,
                                        getActivity().getString(R.string.note_content), false);
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), note_title, note_content);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setNotesList();
                                            }
                                        });
                                snackbar.show();
                            }
                        }
                    }).show();

            return true;
        }
    });
}

From source file:com.near.chimerarevo.fragments.PostFragment.java

private void addText(String text, boolean isHTML, Typeface tf) {
    TextViewEx txt = new TextViewEx(getActivity());
    boolean justifyText = PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getBoolean("justify_text_pref", false);
    if (isHTML) {
        txt.setText(Html.fromHtml(text), justifyText);
        txt.setLinksClickable(true);/*www  .j  a  v  a 2s. co  m*/
        Linkify.addLinks(txt, Linkify.WEB_URLS);
        txt.setTextIsSelectable(true);
        txt.setMovementMethod(LinkMovementMethod.getInstance());
    } else {
        txt.setText(text, justifyText);
        txt.setTextIsSelectable(true);
    }
    int textSize = PreferenceManager.getDefaultSharedPreferences(getActivity()).getInt("text_size_pref", 16);
    txt.setTextSize(textSize);
    txt.setTypeface(tf);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(15, 10, 15, 0);
    txt.setLayoutParams(params);
    lay.addView(txt);
}

From source file:org.thoughtcrime.securesms.ConversationItem.java

private SpannableString linkifyMessageBody(SpannableString messageBody, boolean shouldLinkifyAllLinks) {
    boolean hasLinks = Linkify.addLinks(messageBody, shouldLinkifyAllLinks ? Linkify.ALL : 0);

    if (hasLinks) {
        URLSpan[] urlSpans = messageBody.getSpans(0, messageBody.length(), URLSpan.class);
        for (URLSpan urlSpan : urlSpans) {
            int start = messageBody.getSpanStart(urlSpan);
            int end = messageBody.getSpanEnd(urlSpan);
            messageBody.setSpan(new LongClickCopySpan(urlSpan.getURL()), start, end,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }//ww w.java  2 s .  c om
    }
    return messageBody;
}

From source file:es.farfuteam.vncpp.controller.ActivityTabs.java

/**
 * @return The new dialog//  www.j  av  a2s .c o m
 * @brief Shows the dialog to indicate about info
 * @details Shows the dialog to indicate about info
 */
private Dialog createAboutDialog() {
    //necesario para poder clicar en los links
    final TextView message = new TextView(this);
    final SpannableString s = new SpannableString(this.getText(R.string.about_message));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    message.setText(s);
    message.setMovementMethod(LinkMovementMethod.getInstance());

    return new AlertDialog.Builder(this).setTitle(R.string.about_title).setView(message)
            .setPositiveButton(R.string.about_ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Auto-generated method stub

                }
            }).show();
}

From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java

/**
<<<<<<< e370c9bc00e8f6b33b1d12a44b4c70a7f063c8b9
 * Parses Spanned text for existing html links and reapplies them after the text has been Linkified
=======/*  ww w .j ava 2s .c o  m*/
 * Parses Spanned text for existing html links and reapplies them.
>>>>>>> Issue #168 bugfix for links not being clickable, adds autoLink feature including web, phone, map and email
 * @see <a href="https://developer.android.com/reference/android/text/util/Linkify.html">Linkify</a>
 *
 * @param spann
 * @param mask bitmask to define which kinds of links will be searched and applied (e.g. <a href="https://developer.android.com/reference/android/text/util/Linkify.html#ALL">Linkify.ALL</a>)
 * @return
 */
public static Spanned linkifySpanned(@NonNull final Spanned spann, final int mask) {
    URLSpan[] existingSpans = spann.getSpans(0, spann.length(), URLSpan.class);
    List<Pair<Integer, Integer>> links = new ArrayList<>();

    for (URLSpan urlSpan : existingSpans) {
        links.add(new Pair<>(spann.getSpanStart(urlSpan), spann.getSpanEnd(urlSpan)));
    }

    Linkify.addLinks((Spannable) spann, mask);

    // add the links back in
    for (int i = 0; i < existingSpans.length; i++) {
        ((Spannable) spann).setSpan(existingSpans[i], links.get(i).first, links.get(i).second,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return spann;
}

From source file:com.opencabinetlabs.destinycommunityhub.ui.MainActivity.java

@Subscribe
public void onPodcastEvent(PlaybackEvent event) {
    if (event.action.equalsIgnoreCase(PodcastService.ACTION_PLAY)
            || event.action.equalsIgnoreCase(PodcastService.ACTION_PAUSE)) {
        currentlyPlayingBundle = event.podcast_info;
        if (currentlyPlayingBundle != null) {
            int progress = currentlyPlayingBundle.getInt(PodcastService.PODCAST_DURATION);
            mSeeker.setMax(progress);/*from w  ww  .  j  a  v  a 2  s . c o  m*/
            mTotalDuration.setText(String.format("%d:%02d", TimeUnit.MILLISECONDS.toMinutes(progress),
                    TimeUnit.MILLISECONDS.toSeconds(progress)
                            - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(progress))));

            String title = currentlyPlayingBundle.getString(PodcastService.PODCAST_TITLE);
            mPodcastTitle.setText(title);
            mExpPodcastTitle.setText(title);
            String artist = currentlyPlayingBundle.getString(PodcastService.PODCAST_ARTIST).trim();
            mPodcastArtist.setText(artist);
            mExpPodcastArtist.setText(artist);
            try {
                Spanned desc = Html
                        .fromHtml((currentlyPlayingBundle.getString(PodcastService.PODCAST_DESCRIPTION)));
                if (desc.toString() != null) {
                    mExpPodcastDescription.setText(desc);
                    Linkify.addLinks(mExpPodcastDescription, Linkify.WEB_URLS);
                }
            } catch (Exception e) {
                Timber.e("error converting text" + e.toString());
                mExpPodcastDescription.setText("");
            }

            mPodcastArtwork.setImageDrawable(
                    getResources().getDrawable(currentlyPlayingBundle.getInt(PodcastService.PODCAST_ARTWORK)));
            mExpPodcastArtwork.setImageDrawable(
                    getResources().getDrawable(currentlyPlayingBundle.getInt(PodcastService.PODCAST_ARTWORK)));

            mPodcastPanel.setVisibility(View.VISIBLE);
        }
        if (event.action.equalsIgnoreCase(PodcastService.ACTION_PLAY)) {
            mPlayPauseButton.setImageResource(R.drawable.ic_action_playback_pause);
        } else if (event.action.equalsIgnoreCase(PodcastService.ACTION_PAUSE)) {
            mPlayPauseButton.setImageResource(R.drawable.ic_action_playback_play);
        }
    } else if (event.action.equalsIgnoreCase(PodcastService.ACTION_STOP)) {
        mPodcastPanel.setVisibility(View.GONE);
    }
}

From source file:com.gmail.taneza.ronald.carbs.main.MainActivity.java

private void showAboutDialog() {
    StringBuilder sb = new StringBuilder();
    sb.append(String.format(Locale.getDefault(), "%s%n", getText(R.string.app_name)));
    sb.append(String.format(Locale.getDefault(), "%s: %s%n%n", getText(R.string.about_version_label),
            getVersion()));/*from ww  w. j a  va2  s .c  o  m*/
    sb.append(String.format(Locale.getDefault(), "%s", getText(R.string.about_info)));

    SpannableString aboutString = new SpannableString(sb.toString());
    Linkify.addLinks(aboutString, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);

    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    TextView aboutBodyView = (TextView) layoutInflater.inflate(R.layout.dialog_about, null);
    aboutBodyView.setText(aboutString);
    aboutBodyView.setMovementMethod(new LinkMovementMethod());

    new AlertDialog.Builder(this).setTitle(R.string.about).setView(aboutBodyView)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // do nothing
                }
            }).show();
}

From source file:org.mariotaku.twidere.fragment.UserFragment.java

@UiThread
public void displayUser(final ParcelableUser user, ParcelableAccount account) {
    final FragmentActivity activity = getActivity();
    if (activity == null)
        return;/*from   ww  w.  j  a  va 2  s .  c  o  m*/
    mUser = user;
    mAccount = account;
    if (user == null || user.key == null) {
        mProfileImageView.setVisibility(View.GONE);
        mProfileTypeView.setVisibility(View.GONE);
        if (activity instanceof ATEActivity) {
            setUiColor(Config.primaryColor(activity, ((ATEActivity) activity).getATEKey()));
        }
        return;
    }
    mProfileImageView.setVisibility(View.VISIBLE);
    final Resources resources = getResources();
    final LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ID_USER);
    lm.destroyLoader(LOADER_ID_FRIENDSHIP);
    mCardContent.setVisibility(View.VISIBLE);
    mHeaderErrorContainer.setVisibility(View.GONE);
    mProgressContainer.setVisibility(View.GONE);
    mUser = user;
    mProfileImageView.setBorderColor(user.color != 0 ? user.color : Color.WHITE);
    mProfileNameContainer.drawEnd(user.account_color);
    mNameView.setText(mBidiFormatter.unicodeWrap(TextUtils.isEmpty(user.nickname) ? user.name
            : getString(R.string.name_with_nickname, user.name, user.nickname)));
    final int typeIconRes = Utils.getUserTypeIconRes(user.is_verified, user.is_protected);
    if (typeIconRes != 0) {
        mProfileTypeView.setImageResource(typeIconRes);
        mProfileTypeView.setVisibility(View.VISIBLE);
    } else {
        mProfileTypeView.setImageDrawable(null);
        mProfileTypeView.setVisibility(View.GONE);
    }
    mScreenNameView.setText(String.format("@%s", user.screen_name));
    final TwidereLinkify linkify = new TwidereLinkify(this);
    if (user.description_unescaped != null) {
        final SpannableStringBuilder text = SpannableStringBuilder.valueOf(user.description_unescaped);
        ParcelableStatusUtils.applySpans(text, user.description_spans);
        linkify.applyAllLinks(text, user.account_key, false, false);
        mDescriptionView.setText(text);
    } else {
        mDescriptionView.setText(user.description_plain);
        Linkify.addLinks(mDescriptionView, Linkify.WEB_URLS);
    }
    mDescriptionContainer.setVisibility(mDescriptionView.length() > 0 ? View.VISIBLE : View.GONE);

    mLocationContainer.setVisibility(TextUtils.isEmpty(user.location) ? View.GONE : View.VISIBLE);
    mLocationView.setText(user.location);
    mURLContainer.setVisibility(
            TextUtils.isEmpty(user.url) && TextUtils.isEmpty(user.url_expanded) ? View.GONE : View.VISIBLE);
    mURLView.setText(TextUtils.isEmpty(user.url_expanded) ? user.url : user.url_expanded);
    final String createdAt = Utils.formatToLongTimeString(activity, user.created_at);
    final float daysSinceCreation = (System.currentTimeMillis() - user.created_at) / 1000 / 60 / 60 / 24;
    final int dailyTweets = Math.round(user.statuses_count / Math.max(1, daysSinceCreation));
    mCreatedAtView.setText(resources.getQuantityString(R.plurals.created_at_with_N_tweets_per_day, dailyTweets,
            createdAt, dailyTweets));
    mListedCount.setText(Utils.getLocalizedNumber(mLocale, user.listed_count));
    final long groupsCount = user.extras != null ? user.extras.groups_count : -1;
    mGroupsCount.setText(Utils.getLocalizedNumber(mLocale, groupsCount));
    mFollowersCount.setText(Utils.getLocalizedNumber(mLocale, user.followers_count));
    mFriendsCount.setText(Utils.getLocalizedNumber(mLocale, user.friends_count));

    mListedContainer.setVisibility(user.listed_count < 0 ? View.GONE : View.VISIBLE);
    mGroupsContainer.setVisibility(groupsCount < 0 ? View.GONE : View.VISIBLE);

    mMediaLoader.displayOriginalProfileImage(mProfileImageView, user);
    if (user.color != 0) {
        setUiColor(user.color);
    } else if (user.link_color != 0) {
        setUiColor(user.link_color);
    } else if (activity instanceof ATEActivity) {
        setUiColor(Config.primaryColor(activity, ((ATEActivity) activity).getATEKey()));
    }
    final int defWidth = resources.getDisplayMetrics().widthPixels;
    final int width = mBannerWidth > 0 ? mBannerWidth : defWidth;
    final String bannerUrl = ParcelableUserUtils.getProfileBannerUrl(user);
    if (ObjectUtils.notEqual(mProfileBannerView.getTag(), bannerUrl)
            || mProfileBannerView.getDrawable() == null) {
        mProfileBannerView.setTag(bannerUrl);
        mMediaLoader.displayProfileBanner(mProfileBannerView, bannerUrl, width);
    }
    final UserRelationship relationship = mRelationship;
    if (relationship == null) {
        getFriendship();
    }
    activity.setTitle(
            UserColorNameManager.decideDisplayName(user.nickname, user.name, user.screen_name, mNameFirst));

    Calendar cal = Calendar.getInstance();
    final int currentMonth = cal.get(Calendar.MONTH), currentDay = cal.get(Calendar.DAY_OF_MONTH);
    cal.setTimeInMillis(user.created_at);
    if (cal.get(Calendar.MONTH) == currentMonth && cal.get(Calendar.DAY_OF_MONTH) == currentDay
            && !mHideBirthdayView) {
        mProfileBirthdayBannerView.setVisibility(View.VISIBLE);
    } else {
        mProfileBirthdayBannerView.setVisibility(View.GONE);
    }
    updateTitleAlpha();
    invalidateOptionsMenu();
    updateSubtitle();
}