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.nuvolect.securesuite.data.SqlSyncTest.java

public void pingPongConfirmDiag(final Activity act) {

    m_act = act;/*from   ww w . j a va  2s  .co  m*/

    if (!WebUtil.companionServerAssigned()) {
        Toast.makeText(act, "Configure companion device for test to operate", Toast.LENGTH_LONG).show();
        return;
    }

    String title = "Pyramid comm test with companion device";
    String message = "This is a non-destructive network performance test. "
            + "Payload size is incrementally increased.";

    AlertDialog.Builder builder = new AlertDialog.Builder(act);
    builder.setTitle(title);
    builder.setMessage(Html.fromHtml(message));
    builder.setIcon(CConst.SMALL_ICON);
    builder.setCancelable(true);

    builder.setPositiveButton("Start test", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

            setProgressCallback(m_act, pingPongCallbacks);
            pingPongProgress(act);
            SqlSyncTest.getInstance().init();// Small amount of init on UI thread
            WorkerCommand.quePingTest(m_act);// Heavy lifting on non-UI thread
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

            dialog_alert.cancel();
        }
    });
    dialog_alert = builder.create();
    dialog_alert.show();

    // Activate the HTML
    TextView tv = ((TextView) dialog_alert.findViewById(android.R.id.message));
    tv.setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.gabm.fancyplaces.ui.MainWindow.java

protected void showAbout() {
    // Inflate the about message contents
    View messageView = getLayoutInflater().inflate(R.layout.about_window, null, false);

    TextView content = (TextView) messageView.findViewById(R.id.about_content);
    content.setText(Html.fromHtml(readText(R.raw.about_content)));
    content.setMovementMethod(LinkMovementMethod.getInstance());

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setIcon(R.drawable.ic_launcher);
    builder.setTitle(R.string.app_name);
    builder.setView(messageView);//from w  w w .j av a2  s . co  m
    builder.create();
    builder.show();
}

From source file:com.anandbibek.notifyme.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.def_settings:
        startActivity(new Intent(this, EditFilterActivity.class).putExtra("filter", 9999).setAction("edit"));
        return true;

    case R.id.main_menu_settings:
        startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
        return true;

    case R.id.main_menu_checkaccessibility:
        prefs.setPrevVersion(0);/*w ww. j  av a2 s . c om*/
        ((TemporaryStorage) getApplicationContext()).accessGranted(false);
        finish();
        startActivity(getIntent());
        return true;

    case R.id.main_menu_help:
        new AlertDialog.Builder(this).setMessage(R.string.main_menu_help_message)
                .setTitle(R.string.main_menu_help_title)
                .setPositiveButton(R.string.main_menu_help_ok_button, null).setNegativeButton(
                        R.string.main_menu_help_question_button, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                startActivity(new Intent(Intent.ACTION_VIEW,
                                        Uri.parse("http://forum.xda-developers.com/showthread.php?t=2707698"))
                                                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                            }
                        })
                .show();
        return true;

    case R.id.main_menu_about:
        ViewGroup about = (ViewGroup) ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE))
                .inflate(R.layout.main_menu_about, null);
        ((TextView) about.getChildAt(0)).setMovementMethod(LinkMovementMethod.getInstance());
        new AlertDialog.Builder(this).setView(about).setTitle(R.string.main_menu_about_title)
                .setPositiveButton(R.string.main_menu_about_ok_button, null).show();
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.dwdesign.tweetings.fragment.StatusFragment.java

@SuppressWarnings("deprecation")
public void displayStatus(final ParcelableStatus status) {
    mStatus = null;/*from   ww w .  j a  va2 s  . c  o  m*/
    mImagesPreviewFragment.clear();
    if (status == null || getActivity() == null)
        return;
    mStatus = status;

    final String buffer_authorised = mPreferences.getString(PREFERENCE_KEY_BUFFERAPP_ACCESS_TOKEN, null);

    mMenuBar.inflate(R.menu.menu_status);

    final MenuItem bufferView = mMenuBar.getMenu().findItem(MENU_ADD_TO_BUFFER);
    if (bufferView != null) {
        if (buffer_authorised != null && !buffer_authorised.equals("")) {
            bufferView.setVisible(true);
        } else {
            bufferView.setVisible(false);
        }
    }
    setMenuForStatus(getActivity(), mMenuBar.getMenu(), status);
    mMenuBar.show();

    final boolean is_multiple_account_enabled = getActivatedAccountIds(getActivity()).length > 1;

    updateUserColor();

    mContentScroller
            .setBackgroundResource(is_multiple_account_enabled ? R.drawable.ic_label_account_nopadding : 0);
    if (is_multiple_account_enabled) {
        final Drawable d = mContentScroller.getBackground();
        if (d != null) {
            d.mutate().setColorFilter(getAccountColor(getActivity(), status.account_id),
                    PorterDuff.Mode.MULTIPLY);
            mContentScroller.invalidate();
        }
    }

    mNameView.setText(status.name);
    mScreenNameView.setText("@" + status.screen_name);
    mScreenNameView.setCompoundDrawablesWithIntrinsicBounds(
            getUserTypeIconRes(status.is_verified, status.is_protected), 0, 0, 0);
    mTextView.setText(status.text);

    final TwidereLinkify linkify = new TwidereLinkify(mTextView);
    linkify.setOnLinkClickListener(new OnLinkClickHandler(getActivity(), mAccountId));
    linkify.addAllLinks();
    final boolean is_reply = status.in_reply_to_status_id > 0;
    final String time = formatToLongTimeString(getActivity(), status.status_timestamp);
    final String strTime = "<a href=\"https://twitter.com/" + status.screen_name + "/status/"
            + String.valueOf(status.status_id) + "\">" + time + "</a>";
    final String source_html = status.source;
    if (!isNullOrEmpty(time) && !isNullOrEmpty(source_html)) {
        mTimeAndSourceView.setText(Html.fromHtml(getString(R.string.time_source, strTime, source_html)));
    } else if (isNullOrEmpty(time) && !isNullOrEmpty(source_html)) {
        mTimeAndSourceView.setText(Html.fromHtml(getString(R.string.source, source_html)));
    } else if (!isNullOrEmpty(time) && isNullOrEmpty(source_html)) {
        mTimeAndSourceView.setText(time);
    }
    mTimeAndSourceView.setMovementMethod(LinkMovementMethod.getInstance());
    mInReplyToView.setVisibility(is_reply ? View.VISIBLE : View.GONE);
    mConversationView.setVisibility(is_reply ? View.VISIBLE : View.GONE);
    if (is_reply) {
        mInReplyToView.setText(getString(R.string.in_reply_to, status.in_reply_to_screen_name));

        Display display = getActivity().getWindowManager().getDefaultDisplay();
        int width = display.getWidth(); // deprecated
        int height = display.getHeight(); // deprecated

        int heightOfConversation = (height / 2) - 48 - 44;
        ViewGroup.LayoutParams params = mConversationView.getLayoutParams();
        params.height = heightOfConversation;
        mConversationView.setLayoutParams(params);

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction ft = null;

        ft = fragmentManager.beginTransaction();

        final Fragment fragment = new ConversationFragment();
        final Bundle args = new Bundle();
        args.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId);
        args.putLong(INTENT_KEY_STATUS_ID, status.in_reply_to_status_id);
        fragment.setArguments(args);

        ft.replace(R.id.conversation, fragment, getString(R.string.view_conversation));

        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();

    }
    if (status.play_package != null) {
        mMarketView.setVisibility(View.VISIBLE);
        mPlayInfoTask = new PlayStoreInfoTask();
        mPlayInfoTask.execute();
    } else {
        mMarketView.setVisibility(View.GONE);
    }

    final boolean hires_profile_image = getResources().getBoolean(R.bool.hires_profile_image);
    final String preview_image = hires_profile_image
            ? getBiggerTwitterProfileImage(status.profile_image_url_string)
            : status.profile_image_url_string;
    mLazyImageLoader.displayProfileImage(mProfileImageView, preview_image);
    final List<ImageSpec> images = getImagesInStatus(status.text_html);
    mImagesPreviewContainer.setVisibility(images.size() > 0 ? View.VISIBLE : View.GONE);
    mImagesPreviewFragment.addAll(images);
    mImagesPreviewFragment.update();
    if (mLoadMoreAutomatically == true) {
        mImagesPreviewFragment.show();
    }
    mRetweetedStatusView.setVisibility(status.is_protected ? View.GONE : View.VISIBLE);
    if (status.retweet_id > 0) {
        final boolean display_name = mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_NAME, false);
        final String retweeted_by = display_name ? status.retweeted_by_name : status.retweeted_by_screen_name;
        mRetweetedStatusView.setText(status.retweet_count > 1
                ? getString(R.string.retweeted_by_with_count, retweeted_by, status.retweet_count - 1)
                : getString(R.string.retweeted_by, retweeted_by));
        mRetweetedStatusView.setVisibility(View.VISIBLE);
    } else {
        mRetweetedStatusView.setVisibility(View.GONE);
        mRetweetedStatusView.setText(R.string.users_retweeted_this);
    }
    mLocationView.setVisibility(ParcelableLocation.isValidLocation(status.location) ? View.VISIBLE : View.GONE);

    if (mLoadMoreAutomatically) {
        showFollowInfo(true);
        showLocationInfo(true);
    } else {
        mFollowIndicator.setVisibility(View.GONE);
    }
}

From source file:appteam.nith.hillffair.activities.HomeActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override//w  w  w.j  a  v a2s  .  c  o m
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    switch (id) {
    case R.id.profile:
        startActivity(new Intent(HomeActivity.this, ProfileActivity.class));
        break;
    case R.id.settings:
        startActivity(new Intent(HomeActivity.this, SettingsActivity.class));
        finish();
        break;
    case R.id.aboutus:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(String.format("%1$s", getString(R.string.app_name)));
        builder.setMessage(getResources().getText(R.string.aboutus_text));
        builder.setPositiveButton("OK", null);
        builder.setIcon(R.drawable.ic_action_about);
        AlertDialog welcomeAlert = builder.create();
        welcomeAlert.show();
        break;

    case R.id.report:
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        String uriText = "mailto:" + Uri.encode("appteam.nith@gmail.com") + "?subject="
                + Uri.encode("Reporting A Bug/Feedback") + "&body=" + Uri.encode(
                        "Hello, Appteam \nI want to report a bug/give feedback corresponding to the app Hillfair 2k16.\n.....\n\n-Your name");

        Uri uri = Uri.parse(uriText);
        intent.setData(uri);
        startActivity(Intent.createChooser(intent, "Send Email"));
        break;
    case R.id.license:
        AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
        builder2.setTitle(String.format("%1$s", getString(R.string.open_source_licenses)));
        CharSequence str = getResources().getText(R.string.licenses_text);
        builder2.setMessage(str);
        builder2.setPositiveButton("OK", null);
        AlertDialog welcomeAlert2 = builder2.create();
        welcomeAlert2.show();
        ((TextView) welcomeAlert2.findViewById(android.R.id.message))
                .setMovementMethod(LinkMovementMethod.getInstance());
        break;
    case R.id.notification:
        startActivity(new Intent(HomeActivity.this, NotificationActivity.class));
        break;
    case R.id.logout:
        pref.setUserId(null);
        pref.setRollNo(null);
        pref.setUserName(null);
        startActivity(new Intent(HomeActivity.this, LoginActivity.class));
        finish();
        break;

    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java

public void changeUser(final long account_id, final User user) {
    mFriendship = null;/*  ww  w  . jav  a  2 s  .c  om*/
    mUserId = -1;
    mAccountId = -1;
    if (user == null || user.getId() <= 0 || getActivity() == null
            || !isMyActivatedAccount(getActivity(), account_id))
        return;
    if (mUserInfoTask != null && mUserInfoTask.getStatus() == AsyncTask.Status.RUNNING) {
        mUserInfoTask.cancel(true);
    }
    final boolean is_my_activated_account = isMyActivatedAccount(getActivity(), user.getId());
    mUserInfoTask = null;
    mErrorRetryContainer.setVisibility(View.GONE);
    mAccountId = account_id;
    mUserId = user.getId();
    mScreenName = user.getScreenName();

    updateUserColor();
    final boolean is_multiple_account_enabled = getActivatedAccountIds(getActivity()).length > 1;

    mListView.setBackgroundResource(is_multiple_account_enabled ? R.drawable.ic_label_account_nopadding : 0);
    if (is_multiple_account_enabled) {
        final Drawable d = mListView.getBackground();
        if (d != null) {
            d.mutate().setColorFilter(getAccountColor(getActivity(), account_id), PorterDuff.Mode.MULTIPLY);
            mListView.invalidate();
        }
    }

    mNameView.setText(user.getName());
    mScreenNameView.setText("@" + user.getScreenName());
    mScreenNameView.setCompoundDrawablesWithIntrinsicBounds(
            getUserTypeIconRes(user.isVerified(), user.isProtected()), 0, 0, 0);
    final String description = user.getDescription();
    mDescriptionContainer
            .setVisibility(is_my_activated_account || !isNullOrEmpty(description) ? View.VISIBLE : View.GONE);
    mDescriptionContainer.setOnLongClickListener(this);
    mDescriptionView.setText(description);
    final TwidereLinkify linkify = new TwidereLinkify(mDescriptionView);
    linkify.setOnLinkClickListener(this);
    linkify.addAllLinks();
    mDescriptionView.setMovementMethod(LinkMovementMethod.getInstance());
    final String location = user.getLocation();
    mLocationContainer
            .setVisibility(is_my_activated_account || !isNullOrEmpty(location) ? View.VISIBLE : View.GONE);
    mLocationContainer.setOnLongClickListener(this);
    mLocationView.setText(location);
    final String url = user.getURL() != null ? user.getURL().toString() : null;
    mURLContainer.setVisibility(is_my_activated_account || !isNullOrEmpty(url) ? View.VISIBLE : View.GONE);
    mURLContainer.setOnLongClickListener(this);
    mURLView.setText(url);
    mCreatedAtView.setText(formatToLongTimeString(getActivity(), getTimestampFromDate(user.getCreatedAt())));
    mTweetCount.setText(String.valueOf(user.getStatusesCount()));
    mFollowersCount.setText(String.valueOf(user.getFollowersCount()));
    mFriendsCount.setText(String.valueOf(user.getFriendsCount()));
    // final boolean display_profile_image =
    // mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_PROFILE_IMAGE, true);
    // mProfileImageView.setVisibility(display_profile_image ? View.VISIBLE
    // : View.GONE);
    // if (display_profile_image) {
    final String profile_image_url_string = parseString(user.getProfileImageURL());
    final boolean hires_profile_image = getResources().getBoolean(R.bool.hires_profile_image);
    mLazyImageLoader.displayProfileImage(mProfileImageView,
            hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
                    : profile_image_url_string);
    // }

    String profile_banner_url_string = parseString(user.getProfileBannerImageUrl());
    if (profile_banner_url_string != null) {
        final int def_width = getResources().getDisplayMetrics().widthPixels;
        profile_banner_url_string = profile_banner_url_string + "/" + getBestBannerType(def_width);
    }
    final String banner_url = profile_banner_url_string;
    if (mProfileBackgroundView != null) {
        mProfileBackgroundView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        if (banner_url != null) {
            mLazyImageLoader.displayPreviewImage(mProfileBackgroundView, banner_url);
        } else {
            final Drawable d = getResources().getDrawable(R.drawable.linen);
            mProfileBackgroundView.setImageDrawable(d);
        }
    }

    mUser = user;
    if (isMyAccount(getActivity(), user.getId())) {
        final ContentResolver resolver = getContentResolver();
        final ContentValues values = new ContentValues();
        final URL profile_image_url = user.getProfileImageURL();
        if (profile_image_url != null) {
            values.put(Accounts.PROFILE_IMAGE_URL, profile_image_url.toString());
        }
        values.put(Accounts.USERNAME, user.getScreenName());
        final String where = Accounts.USER_ID + " = " + user.getId() + " AND 1 = 1";
        resolver.update(Accounts.CONTENT_URI, values, where, null);
    }
    mAdapter.add(new UserRecentPhotosAction());
    mAdapter.add(new FavoritesAction());
    mAdapter.add(new UserMentionsAction());
    mAdapter.add(new UserListTypesAction());
    if (user.getId() == mAccountId) {
        mAdapter.add(new MyTweetsRetweetedAction());
        mAdapter.add(new SavedSearchesAction());
        boolean nativeMapSupported = true;
        try {
            Class.forName("com.google.android.maps.MapActivity");
            Class.forName("com.google.android.maps.MapView");
        } catch (final ClassNotFoundException e) {
            nativeMapSupported = false;
        }
        if (nativeMapSupported) {
            mAdapter.add(new UserNearbyAction());
        }
        if (user.isProtected()) {
            mAdapter.add(new IncomingFriendshipsAction());
        }
        mAdapter.add(new UserBlocksAction());
    }
    mAdapter.notifyDataSetChanged();

    if (mRecentPhotosGallery != null) {
        mRecentPhotosGallery.setVisibility(View.GONE);
        mRecentPhotosGallery.setAdapter(new ImageAdapter(this.getActivity()));
        mRecentPhotosGallery.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                ParcelableStatus pStatus = mMediaStatuses.get(position);
                final ImageSpec spec = getAllAvailableImage(pStatus.image_orig_url_string);
                if (spec != null) {
                    openImage(UserProfileFragment.this.getActivity(), Uri.parse(spec.full_image_link),
                            pStatus.is_possibly_sensitive);
                }
            }

        });

        mMediaTimelineTask = new MediaTimelineTask(this.getActivity(), mAccountId, mUser.getScreenName());
        if (mMediaTimelineTask != null) {
            mMediaTimelineTask.execute();
        }
    }

    getFriendship();
    checkPushTracked();
}

From source file:eu.faircode.adblocker.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));
    Util.logExtras(getIntent());//from  ww  w  . j ava2 s  .co m

    if (Build.VERSION.SDK_INT < MIN_SDK) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.android);
        return;
    }

    Util.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    swEnabled = (SwitchCompat) findViewById(R.id.swEnabled);
    running = true;

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabled = prefs.getBoolean("enabled", false);
    boolean initialized = prefs.getBoolean("initialized", false);

    // Upgrade
    Receiver.upgrade(initialized, this);

    if (!getIntent().hasExtra(EXTRA_APPROVE)) {
        if (enabled)
            ServiceSinkhole.start("UI", this);
        else
            ServiceSinkhole.stop("UI", this);
    }

    // Action bar
    final View actionView = getLayoutInflater().inflate(R.layout.actionmain, null, false);
    ivIcon = (ImageView) actionView.findViewById(R.id.ivIcon);
    ivQueue = (ImageView) actionView.findViewById(R.id.ivQueue);

    ivMetered = (ImageView) actionView.findViewById(R.id.ivMetered);

    // Icon
    ivIcon.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            menu_about();
            return true;
        }
    });

    // Title
    getSupportActionBar().setTitle(null);

    // Netguard is busy
    ivQueue.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_queue, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.START, location[0] + ivQueue.getLeft(),
                    Math.round(location[1] + ivQueue.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    // On/off switch
    swEnabled.setChecked(enabled);
    swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Log.i(TAG, "Switch=" + isChecked);
            prefs.edit().putBoolean("enabled", isChecked).apply();

            if (isChecked) {
                try {
                    final Intent prepare = VpnService.prepare(ActivityMain.this);
                    if (prepare == null) {
                        Log.i(TAG, "Prepare done");
                        onActivityResult(REQUEST_VPN, RESULT_OK, null);
                    } else {
                        // Show dialog
                        LayoutInflater inflater = LayoutInflater.from(ActivityMain.this);
                        View view = inflater.inflate(R.layout.vpn, null, false);
                        dialogVpn = new AlertDialog.Builder(ActivityMain.this).setView(view)
                                .setCancelable(false)
                                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (running) {
                                            Log.i(TAG, "Start intent=" + prepare);
                                            try {
                                                startActivityForResult(prepare, REQUEST_VPN);
                                            } catch (Throwable ex) {
                                                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                                                Util.sendCrashReport(ex, ActivityMain.this);
                                                onActivityResult(REQUEST_VPN, RESULT_CANCELED, null);
                                                prefs.edit().putBoolean("enabled", false).apply();
                                            }
                                        }
                                    }
                                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                        dialogVpn = null;
                                    }
                                }).create();
                        dialogVpn.show();
                    }
                } catch (Throwable ex) {
                    // Prepare failed
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    Util.sendCrashReport(ex, ActivityMain.this);
                    prefs.edit().putBoolean("enabled", false).apply();
                }

            } else
                ServiceSinkhole.stop("switch off", ActivityMain.this);
        }
    });
    if (enabled)
        checkDoze();

    // Network is metered
    ivMetered.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_metered, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.START, location[0] + ivMetered.getLeft(),
                    Math.round(location[1] + ivMetered.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(actionView);

    // Disabled warning
    TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
    tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);

    // Application list
    //        RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
    //        rvApplication.setHasFixedSize(true);
    //        rvApplication.setLayoutManager(new LinearLayoutManager(this));
    //        adapter = new AdapterRule(this);
    //        rvApplication.setAdapter(adapter);

    // Swipe to refresh
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    //        swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh);
    //        swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE);
    //        swipeRefresh.setProgressBackgroundColorSchemeColor(tv.data);
    //        swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    //            @Override
    //            public void onRefresh() {
    //                Rule.clearCache(ActivityMain.this);
    //                ServiceSinkhole.reload("pull", ActivityMain.this);
    //                updateApplicationList(null);
    //            }
    //        });

    // Listen for preference changes
    prefs.registerOnSharedPreferenceChangeListener(this);

    // Listen for rule set changes
    IntentFilter ifr = new IntentFilter(ACTION_RULES_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onRulesChanged, ifr);

    // Listen for queue changes
    IntentFilter ifq = new IntentFilter(ACTION_QUEUE_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onQueueChanged, ifq);

    // Listen for added/removed applications
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    registerReceiver(packageChangedReceiver, intentFilter);

    // First use
    if (!initialized) {
        // Create view
        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.first, null, false);
        TextView tvFirst = (TextView) view.findViewById(R.id.tvFirst);
        tvFirst.setMovementMethod(LinkMovementMethod.getInstance());

        // Show dialog
        dialogFirst = new AlertDialog.Builder(this).setView(view).setCancelable(false)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            prefs.edit().putBoolean("initialized", true).apply();
                    }
                }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            finish();
                    }
                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        dialogFirst = null;
                    }
                }).create();
        dialogFirst.show();
    }

    // Fill application list
    updateApplicationList(getIntent().getStringExtra(EXTRA_SEARCH));

    // Update IAB SKUs
    try {
        iab = new IAB(new IAB.Delegate() {
            @Override
            public void onReady(IAB iab) {
                try {
                    iab.updatePurchases();

                    if (!IAB.isPurchased(ActivityPro.SKU_LOG, ActivityMain.this))
                        prefs.edit().putBoolean("log", false).apply();
                    if (!IAB.isPurchased(ActivityPro.SKU_THEME, ActivityMain.this)) {
                        if (!"teal".equals(prefs.getString("theme", "teal")))
                            prefs.edit().putString("theme", "teal").apply();
                    }
                    if (!IAB.isPurchased(ActivityPro.SKU_SPEED, ActivityMain.this))
                        prefs.edit().putBoolean("show_stats", false).apply();
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                } finally {
                    iab.unbind();
                }
            }
        }, this);
        iab.bind();
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    checkExtras(getIntent());
}

From source file:info.schnatterer.nusic.android.activities.MainActivity.java

/**
 * Shows an alert dialog displaying some text. Useful for welcome messages.
 * Calls {@link #registerListenersAndStartLoading()} when the dialog is
 * dismissed./*  ww w  . ja  v  a  2  s.  c  o  m*/
 * 
 * @param text
 *            text to display. If loading from an asset, consider using
 *            {@link TextUtil#loadTextFromAsset(android.content.Context, String)}
 */
@SuppressLint("InflateParams")
// See http://www.doubleencore.com/2013/05/layout-inflation-as-intended/
private void showWelcomeDialog(CharSequence text) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    View layout = getLayoutInflater().inflate(R.layout.simple_textview_layout, null, false);
    TextView textView = (TextView) layout.findViewById(R.id.renderRawHtmlTextView);
    textView.setText(text);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    alertDialogBuilder
            .setTitle(getString(R.string.WelcomeScreenTitle, NusicApplication.getCurrentVersionName()))
            .setIcon(R.drawable.ic_launcher).setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    registerListenersAndStartLoading(true);
                }
            }).setPositiveButton(android.R.string.ok, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    registerListenersAndStartLoading(true);
                }
            }).setView(layout).show();
}

From source file:com.limewoodmedia.nsdroid.activities.WorldAssembly.java

private void doSetup() {
    // General Assembly overview
    generalAssembly.loadCouncil(WACouncil.GENERAL_ASSEMBLY, gaData);

    // Security Council overview
    securityCouncil.loadCouncil(WACouncil.SECURITY_COUNCIL, scData);

    // Happenings
    StringBuilder happText = null;
    for (WAHappening happ : gaData.happenings) {
        if (happText == null) {
            happText = new StringBuilder();
        } else {//from   ww w.  ja va 2s .  co m
            happText.append("<br/><br/>");
        }
        happText.append("<i>" + TagParser.parseTimestamp(this, happ.timestamp) + ":</i> " + happ.text);
    }
    if (happText != null) {
        happenings.setText(Html.fromHtml(happText.toString()));
        happenings.setMovementMethod(LinkMovementMethod.getInstance());
    } else {
        happenings.setVisibility(View.GONE);
    }

    Resources r = getResources();

    // General Assembly
    if (gaData.resolution.name != null) {
        gaTitle.setText(gaData.resolution.name);
        String catText = gaData.resolution.category;
        if (catText.equals("Repeal")) {
            catText += " of GA#" + (Integer.parseInt(gaData.resolution.option) + 1);
        } else {
            catText += "; Strength: " + gaData.resolution.option;
        }
        gaCategory.setText(catText);
        gaProposer.setText(Html.fromHtml(getString(R.string.wa_proposed_by)
                + " <a href=\"com.limewoodMedia.nsdroid.nation://" + gaData.resolution.proposedBy + "\">"
                + TagParser.idToName(gaData.resolution.proposedBy) + "</a>"));
        gaProposer.setMovementMethod(LinkMovementMethod.getInstance());
        gaNation.setText(Html.fromHtml("<b>" + nationData.name + ":</b> " + nationData.generalAssemblyVote));
        gaText.setText(Html.fromHtml(TagParser.parseTags(gaData.resolution.desc.replace("\n", "<br/>"))));
        float total = gaData.resolution.votes.forVotes + gaData.resolution.votes.againstVotes;
        int[] daysHours = Utils.getWADaysHoursLeft(gaData.resolution.voteTrack.forVotes.length);
        int days = daysHours[0];
        int hours = daysHours[1];
        gaBelow.setText(Html
                .fromHtml("<b>" + getString(R.string.wa_votes_for) + ":</b> " + gaData.resolution.votes.forVotes
                        + " (" + format.format(gaData.resolution.votes.forVotes / total) + ")<br/><b>"
                        + getString(R.string.wa_votes_against) + ":</b> " + gaData.resolution.votes.againstVotes
                        + " (" + format.format(gaData.resolution.votes.againstVotes / total) + ")<br/><br/>"
                        + getString(R.string.voting_ends, days, hours,
                                r.getQuantityString(R.plurals.days, days),
                                r.getQuantityString(R.plurals.hours, hours))));

        // Chart
        gaSeries.clear();
        XYSeries forVotes = new XYSeries("For");
        XYSeries againstVotes = new XYSeries("Against");
        int i = 0;
        int forMax = 0;
        for (Integer f : gaData.resolution.voteTrack.forVotes) {
            forVotes.add(i++, f);
            if (f > forMax) {
                forMax = f;
            }
        }
        i = 0;
        int againstMax = 0;
        for (Integer a : gaData.resolution.voteTrack.againstVotes) {
            againstVotes.add(i++, a);
            if (a > againstMax) {
                againstMax = a;
            }
        }
        gaSeries.addSeries(forVotes);
        gaSeries.addSeries(againstVotes);

        gaForRenderer = new XYSeriesRenderer();
        gaAgainstRenderer = new XYSeriesRenderer();
        setUpChartRenderer(gaRenderer, gaForRenderer, gaAgainstRenderer);
        gaRenderer.setYAxisMax(Math.max(forMax, againstMax) * 1.2f);

        LinearLayout layout = (LinearLayout) gaPage.findViewById(R.id.chart);
        gaChart = ChartFactory.getLineChartView(this, gaSeries, gaRenderer);
        layout.addView(gaChart, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                r.getDimensionPixelSize(R.dimen.wa_area_chart_height)));

        gaChart.repaint();
    } else {
        gaTitle.setText(getString(R.string.none));
        gaCategory.setVisibility(View.GONE);
        gaProposer.setVisibility(View.GONE);
        gaText.setVisibility(View.GONE);
        gaBelow.setVisibility(View.GONE);
        gaPage.findViewById(R.id.chart).setVisibility(View.GONE);
    }

    // Security Council
    if (scData.resolution.name != null) {
        scTitle.setText(scData.resolution.name);
        String catText = scData.resolution.category + "; ";
        String[] arr = scData.resolution.option.split(":");
        if (arr[0].equals("N")) {
            catText += getString(R.string.nation) + " <a href=\"com.limewoodMedia.nsdroid.nation://" + arr[1]
                    + "\">" + TagParser.idToName(arr[1]) + "</a>";
        } else if (arr[0].equals("R")) {
            catText += getString(R.string.region) + " <a href=\"com.limewoodMedia.nsdroid.region://" + arr[1]
                    + "\">" + TagParser.idToName(arr[1]) + "</a>";
        } else {
            catText += scData.resolution.option;
        }
        scCategory.setText(Html.fromHtml(catText));
        scCategory.setMovementMethod(LinkMovementMethod.getInstance());
        scProposer.setText(Html.fromHtml(getString(R.string.wa_proposed_by)
                + " <a href=\"com.limewoodMedia.nsdroid.nation://" + scData.resolution.proposedBy + "\">"
                + TagParser.idToName(scData.resolution.proposedBy) + "</a>"));
        scProposer.setMovementMethod(LinkMovementMethod.getInstance());
        scNation.setText(Html.fromHtml("<b>" + nationData.name + ":</b> " + nationData.securityCouncilVote));
        scText.setText(Html.fromHtml(TagParser.parseTags(scData.resolution.desc.replace("\n", "<br/>"))));
        float total = scData.resolution.votes.forVotes + scData.resolution.votes.againstVotes;
        int[] daysHours = Utils.getWADaysHoursLeft(scData.resolution.voteTrack.forVotes.length);
        int days = daysHours[0];
        int hours = daysHours[1];
        scBelow.setText(Html
                .fromHtml("<b>" + getString(R.string.wa_votes_for) + ":</b> " + scData.resolution.votes.forVotes
                        + " (" + format.format(scData.resolution.votes.forVotes / total) + ")<br/><b>"
                        + getString(R.string.wa_votes_against) + ":</b> " + scData.resolution.votes.againstVotes
                        + " (" + format.format(scData.resolution.votes.againstVotes / total) + ")<br/><br/>"
                        + getString(R.string.voting_ends, days, hours,
                                r.getQuantityString(R.plurals.days, days),
                                r.getQuantityString(R.plurals.hours, hours))));

        // Chart
        scSeries.clear();
        XYSeries forVotes = new XYSeries("For");
        XYSeries againstVotes = new XYSeries("Against");
        int i = 0;
        int forMax = 0;
        for (Integer f : scData.resolution.voteTrack.forVotes) {
            forVotes.add(i++, f);
            if (f > forMax) {
                forMax = f;
            }
        }
        i = 0;
        int againstMax = 0;
        for (Integer a : scData.resolution.voteTrack.againstVotes) {
            againstVotes.add(i++, a);
            if (a > againstMax) {
                againstMax = a;
            }
        }
        scSeries.addSeries(forVotes);
        scSeries.addSeries(againstVotes);

        scForRenderer = new XYSeriesRenderer();
        scAgainstRenderer = new XYSeriesRenderer();
        setUpChartRenderer(scRenderer, scForRenderer, scAgainstRenderer);
        scRenderer.setYAxisMax(Math.max(forMax, againstMax) * 1.2f);

        LinearLayout layout = (LinearLayout) scPage.findViewById(R.id.chart);
        scChart = ChartFactory.getLineChartView(this, scSeries, scRenderer);
        layout.addView(scChart, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                r.getDimensionPixelSize(R.dimen.wa_area_chart_height)));

        scChart.repaint();
    } else {
        scTitle.setText(getString(R.string.none));
        scCategory.setVisibility(View.GONE);
        scProposer.setVisibility(View.GONE);
        scText.setVisibility(View.GONE);
        scBelow.setVisibility(View.GONE);
        scPage.findViewById(R.id.chart).setVisibility(View.GONE);
    }

    supportInvalidateOptionsMenu();
}

From source file:com.heath_bar.tvdb.EpisodeDetails.java

/** Update the GUI with the specified rating */
private void setUserRatingTextView(int rating) {

    TextView ratingTextView = (TextView) findViewById(R.id.rating);
    String communityRatingText = myEpisode.getRating() + " / 10";

    String ratingTextA = communityRatingText + "  (";
    String ratingTextB = (rating == 0) ? "rate" : String.valueOf(rating);
    String ratingTextC = ")";

    int start = ratingTextA.length();
    int end = ratingTextA.length() + ratingTextB.length();

    SpannableStringBuilder ssb = new SpannableStringBuilder(ratingTextA + ratingTextB + ratingTextC);

    ssb.setSpan(new NonUnderlinedClickableSpan() {
        @Override/*from w  w  w.  ja  v a2 s . com*/
        public void onClick(View v) {
            showRatingDialog();
        }
    }, start, end, 0);

    ssb.setSpan(new TextAppearanceSpan(getApplicationContext(), R.style.episode_link), start, end, 0); // Set the style of the text
    ratingTextView.setText(ssb, BufferType.SPANNABLE);
    ratingTextView.setMovementMethod(LinkMovementMethod.getInstance());
}