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:im.neon.activity.VectorRoomActivity.java

/**
 * Refresh the notifications area.//from  www  .  j a  v  a2  s .com
 */
private void refreshNotificationsArea() {
    // sanity check
    // might happen when the application is logged out
    if ((null == mSession.getDataHandler()) || (null == mRoom) || (null != sRoomPreviewData)) {
        return;
    }

    int iconId = -1;
    int textColor = -1;
    boolean isAreaVisible = false;
    SpannableString text = new SpannableString("");
    boolean hasUnsentEvent = false;

    // remove any listeners
    mNotificationTextView.setOnClickListener(null);
    mNotificationIconImageView.setOnClickListener(null);

    //  no network
    if (!Matrix.getInstance(this).isConnected()) {
        isAreaVisible = true;
        iconId = R.drawable.error;
        textColor = R.color.vector_fuchsia_color;
        text = new SpannableString(getResources().getString(R.string.room_offline_notification));
    } else {
        List<Event> undeliveredEvents = mSession.getDataHandler().getStore()
                .getUndeliverableEvents(mRoom.getRoomId());
        List<Event> unknownDeviceEvents = mSession.getDataHandler().getStore()
                .getUnknownDeviceEvents(mRoom.getRoomId());

        boolean hasUndeliverableEvents = (null != undeliveredEvents) && (undeliveredEvents.size() > 0);
        boolean hasUnknownDeviceEvents = (null != unknownDeviceEvents) && (unknownDeviceEvents.size() > 0);

        if (hasUndeliverableEvents || hasUnknownDeviceEvents) {
            hasUnsentEvent = true;
            isAreaVisible = true;
            iconId = R.drawable.error;

            String cancelAll = getResources().getString(R.string.room_prompt_cancel);
            String resendAll = getResources().getString(R.string.room_prompt_resend);
            String message = getResources()
                    .getString(hasUnknownDeviceEvents ? R.string.room_unknown_devices_messages_notification
                            : R.string.room_unsent_messages_notification, resendAll, cancelAll);

            int cancelAllPos = message.indexOf(cancelAll);
            int resendAllPos = message.indexOf(resendAll);

            text = new SpannableString(message);

            // cancelAllPos should always be > 0 but a GA crash reported here
            if (cancelAllPos >= 0) {
                text.setSpan(new cancelAllClickableSpan(), cancelAllPos, cancelAllPos + cancelAll.length(), 0);
            }

            // resendAllPos should always be > 0 but a GA crash reported here
            if (resendAllPos >= 0) {
                text.setSpan(new resendAllClickableSpan(), resendAllPos, resendAllPos + resendAll.length(), 0);
            }

            mNotificationTextView.setMovementMethod(LinkMovementMethod.getInstance());
            textColor = R.color.vector_fuchsia_color;

        } else if ((null != mIsScrolledToTheBottom) && (!mIsScrolledToTheBottom)) {
            isAreaVisible = true;

            int unreadCount = 0;

            RoomSummary summary = mRoom.getDataHandler().getStore().getSummary(mRoom.getRoomId());

            if (null != summary) {
                unreadCount = mRoom.getDataHandler().getStore().eventsCountAfter(mRoom.getRoomId(),
                        summary.getLatestReadEventId());
            }

            if (unreadCount > 0) {
                iconId = R.drawable.newmessages;
                textColor = R.color.vector_fuchsia_color;

                if (unreadCount == 1) {
                    text = new SpannableString(
                            getResources().getString(R.string.room_new_message_notification));
                } else {
                    text = new SpannableString(
                            getResources().getString(R.string.room_new_messages_notification, unreadCount));
                }
            } else {
                iconId = R.drawable.scrolldown;
                textColor = R.color.vector_text_gray_color;

                if (!TextUtils.isEmpty(mLatestTypingMessage)) {
                    text = new SpannableString(mLatestTypingMessage);
                }
            }

            mNotificationTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mVectorMessageListFragment.scrollToBottom(0);
                }
            });

            mNotificationIconImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mVectorMessageListFragment.scrollToBottom(0);
                }
            });

        } else if (!TextUtils.isEmpty(mLatestTypingMessage)) {
            isAreaVisible = true;

            iconId = R.drawable.vector_typing;
            text = new SpannableString(mLatestTypingMessage);
            textColor = R.color.vector_text_gray_color;
        }
    }

    if (TextUtils.isEmpty(mEventId)) {
        mNotificationsArea.setVisibility(isAreaVisible ? View.VISIBLE : View.INVISIBLE);
    }

    if ((-1 != iconId) && (-1 != textColor)) {
        mNotificationIconImageView.setImageResource(iconId);
        mNotificationTextView.setText(text);
        mNotificationTextView.setTextColor(getResources().getColor(textColor));
    }

    //
    if (null != mResendUnsentMenuItem) {
        mResendUnsentMenuItem.setVisible(hasUnsentEvent);
    }

    if (null != mResendDeleteMenuItem) {
        mResendDeleteMenuItem.setVisible(hasUnsentEvent);
    }

    if (null != mSearchInRoomMenuItem) {
        // the server search does not work on encrypted rooms.
        mSearchInRoomMenuItem.setVisible(!mRoom.isEncrypted());
    }
}

From source file:com.mantz_it.rfanalyzer.MainActivity.java

public void showInfoDialog() {
    AlertDialog dialog = new AlertDialog.Builder(this)
            .setTitle(Html.fromHtml(getString(R.string.info_title, versionName)))
            .setMessage(Html.fromHtml(getString(R.string.info_msg_body)))
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing
                }/*from w  ww.ja v a  2s. co  m*/
            }).create();
    dialog.show();

    // make links clickable:
    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.android.launcher3.Utilities.java

public static void upgradeToPROAlertDialog(Context context) {
    AlertDialog builder = new AlertDialog.Builder(context, R.style.AlertDialogCustom)
            .setTitle(context.getResources().getString(R.string.app_name)).setCancelable(false)
            .setIcon(R.mipmap.ic_launcher_home).setMessage(R.string.license_dialog_message_pro)
            .setPositiveButton(context.getResources().getString(R.string.ok),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                        }/*  www . j ava  2s  .  co m*/
                    })
            .create();
    builder.show();
    ((TextView) builder.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    ((TextView) builder.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_VERTICAL);
    builder.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT);
}

From source file:cgeo.geocaching.CacheDetailActivity.java

static void updateCacheLists(final View view, final Geocache cache, final Resources res) {
    final SpannableStringBuilder builder = new SpannableStringBuilder();
    for (final Integer listId : cache.getLists()) {
        if (builder.length() > 0) {
            builder.append(", ");
        }/*from  ww w .  j a va2s.c  o m*/
        appendClickableList(builder, view, listId);
    }
    builder.insert(0, res.getString(R.string.list_list_headline) + " ");
    final TextView offlineLists = ButterKnife.findById(view, R.id.offline_lists);
    offlineLists.setText(builder);
    offlineLists.setMovementMethod(LinkMovementMethod.getInstance());
}

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

private void showUserSetting(final String initiateUserName, final String initiatePassword,
        final boolean syncChannels) {
    AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);
    builder.setCancelable(false);//from  w  ww .j  av  a2  s.  c  om

    RelativeLayout username_password_setup = (RelativeLayout) getLayoutInflater()
            .inflate(R.layout.username_password_setup, getParentViewGroup(), false);

    final SharedPreferences pref = getSharedPreferences("transportation", Context.MODE_PRIVATE);

    final EditText userName = (EditText) username_password_setup.findViewById(R.id.username_entry);
    final EditText password = (EditText) username_password_setup.findViewById(R.id.password_entry);

    userName.setText(
            pref.getString(SettingConstants.USER_NAME, initiateUserName != null ? initiateUserName : ""));
    password.setText(
            pref.getString(SettingConstants.USER_PASSWORD, initiatePassword != null ? initiatePassword : ""));

    builder.setView(username_password_setup);

    builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            setUserName(userName.getText().toString().trim(), password.getText().toString().trim(),
                    syncChannels);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (syncChannels) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        showChannelSelectionInternal();
                    }
                });
            }
        }
    });

    AlertDialog d = builder.create();

    d.show();

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

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

private void checkTermsAccepted() {
    final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    String terms = pref.getString(SettingConstants.TERMS_ACCEPTED, "");

    if (terms.contains("EPG_FREE")) {
        updateTvData();//from   www  .j a  va2  s  . c o m
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

        builder.setTitle(R.string.terms_of_use_data);
        builder.setMessage(R.string.terms_of_use_text);

        builder.setPositiveButton(R.string.terms_of_use_accept, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Editor edit = pref.edit();

                edit.putString(SettingConstants.TERMS_ACCEPTED, "EPG_FREE");

                edit.commit();

                updateTvData();
            }
        });

        builder.setNegativeButton(android.R.string.cancel, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });

        AlertDialog d = builder.create();

        d.show();

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

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

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

    if (title != null) {
        builder.setTitle(title);//  ww  w  . j  ava2s  .  com
    }
    if (message != null) {
        builder.setMessage(message);
    } else if (view != null) {
        builder.setView(view);
    }

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

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

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

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

    AlertDialog d = builder.create();

    d.show();

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

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

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

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

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

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

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

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

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

                                showPluginInfo();
                            }
                        });

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

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

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

private void searchPlugins(final boolean showChannelUpdateInfo) {
    if (isOnline()) {
        new Thread("SEARCH FOR PLUGINS THREAD") {
            @Override/*  ww  w .  j av a2 s .  c o  m*/
            public void run() {
                updateProgressIcon(true);
                PluginDefinition[] availablePlugins = PluginDefinition.loadAvailablePluginDefinitions();

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

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

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

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

                            boolean wasAdded = false;
                            boolean wasFound = false;

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

                                        String currentVersion = connection.getPluginVersion();

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

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

                StringBuilder pluginsText = new StringBuilder();

                Collections.sort(newPlugins);

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

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

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

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

                    pluginsText.append(news.getDescription());

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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