Search in sources :

Example 31 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project Reader by TheKeeperOfPie.

the class FragmentProfile method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_profile, container, false);
    layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
    layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
    listener = new ControllerProfile.Listener() {

        @Override
        public void setSortAndTime(Sort sort, Time time) {
            menu.findItem(sort.getMenuId()).setChecked(true);
            menu.findItem(time.getMenuId()).setChecked(true);
            itemSortTime.setTitle(getString(R.string.time_description, menu.findItem(controllerProfile.getTime().getMenuId()).toString()));
        }

        @Override
        public void setPage(Page page) {
            spinnerPage.setSelection(adapterProfilePage.getPages().indexOf(page));
            if (page.getPage().equals(ControllerProfile.PAGE_HIDDEN)) {
                callback.setDrawable(getResources().getDrawable(R.drawable.ic_visibility_white_24dp));
            } else {
                callback.setDrawable(getResources().getDrawable(R.drawable.ic_visibility_off_white_24dp));
            }
        }

        @Override
        public void setIsUser(boolean isUser) {
            // TODO: Fix set page for Profile view
            adapterProfilePage.setIsUser(isUser);
        }

        @Override
        public void loadLink(Comment comment) {
            Log.d(TAG, "Link ID: " + comment.getLinkId());
            Intent intent = new Intent(activity, ActivityMain.class);
            intent.setAction(Intent.ACTION_VIEW);
            intent.putExtra(ActivityMain.REDDIT_PAGE, Reddit.BASE_URL + "/r/" + comment.getSubreddit() + "/comments/" + comment.getLinkId().replace("t3_", ""));
            startActivity(intent);
        }

        @Override
        public RecyclerView.Adapter getAdapter() {
            return adapterProfile;
        }

        @Override
        public void setToolbarTitle(CharSequence title) {
            toolbar.setTitle(title);
        }

        @Override
        public void setRefreshing(boolean refreshing) {
            swipeRefreshProfile.setRefreshing(refreshing);
        }

        @Override
        public void post(Runnable runnable) {
            recyclerProfile.post(runnable);
        }
    };
    int styleColorBackground = AppSettings.THEME_DARK.equals(mListener.getThemeBackground()) ? R.style.MenuDark : R.style.MenuLight;
    ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(new ThemeWrapper(activity, UtilsColor.getThemeForColor(getResources(), themer.getColorPrimary(), mListener)), styleColorBackground);
    toolbar = (Toolbar) activity.getLayoutInflater().cloneInContext(contextThemeWrapper).inflate(R.layout.toolbar, layoutAppBar, false);
    layoutAppBar.addView(toolbar);
    ((AppBarLayout.LayoutParams) toolbar.getLayoutParams()).setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
    if (getFragmentManager().getBackStackEntryCount() <= 1) {
        toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mListener.openDrawer();
            }
        });
    } else {
        toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mListener.onNavigationBackClick();
            }
        });
    }
    toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
    toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
    setUpOptionsMenu();
    adapterProfilePage = new AdapterProfilePage(activity);
    spinnerPage = new AppCompatSpinner(contextThemeWrapper);
    toolbar.addView(spinnerPage);
    ((Toolbar.LayoutParams) spinnerPage.getLayoutParams()).setMarginEnd((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()));
    spinnerPage.setAdapter(adapterProfilePage);
    spinnerPage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            controllerProfile.setPage(adapterProfilePage.getItem(position)).subscribe(getReloadObserver());
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    swipeRefreshProfile = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_profile);
    swipeRefreshProfile.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            controllerProfile.reload().subscribe(getReloadObserver());
        }
    });
    linearLayoutManager = new LinearLayoutManager(activity);
    recyclerProfile = (RecyclerView) view.findViewById(R.id.recycler_profile);
    recyclerProfile.setHasFixedSize(true);
    recyclerProfile.setItemAnimator(null);
    recyclerProfile.setLayoutManager(linearLayoutManager);
    recyclerProfile.addItemDecoration(new ItemDecorationDivider(activity, ItemDecorationDivider.VERTICAL_LIST));
    AdapterListener adapterListener = new AdapterListener() {

        @Override
        public void scrollAndCenter(int position, int height) {
            UtilsAnimation.scrollToPositionWithCentering(position, recyclerProfile, false);
        }

        @Override
        public void hideToolbar() {
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }

        @Override
        public void clearDecoration() {
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }

        @Override
        public void requestMore() {
            controllerProfile.loadMoreLinks().observeOn(AndroidSchedulers.mainThread()).subscribe(new ObserverError<Listing>() {

                @Override
                public void onError(Throwable e) {
                    Toast.makeText(getContext(), getString(R.string.error_loading_links), Toast.LENGTH_SHORT).show();
                }
            });
        }

        @Override
        public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
            recyclerProfile.requestDisallowInterceptTouchEvent(disallow);
            swipeRefreshProfile.requestDisallowInterceptTouchEvent(disallow);
            itemTouchHelper.select(null, CustomItemTouchHelper.ACTION_STATE_IDLE);
        }

        @Override
        public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
            itemTouchHelper.setDisallow(disallow);
        }
    };
    AdapterLink.ViewHolderLink.Listener listenerLink = new AdapterLink.ViewHolderLink.Listener() {

        @Override
        public void onSubmitComment(Link link, String text) {
        }

        @Override
        public void onDownloadImage(Link link) {
        }

        @Override
        public void onDownloadImage(Link link, String title, String fileName, String url) {
        }

        @Override
        public void onLoadUrl(Link link, boolean forceExternal) {
        }

        @Override
        public void onShowFullEditor(Link link) {
        }

        @Override
        public void onVote(Link link, AdapterLink.ViewHolderLink viewHolderLink, Likes vote) {
        }

        @Override
        public void onCopyText(Link link) {
        }

        @Override
        public void onEdit(Link link) {
        }

        @Override
        public void onDelete(Link link) {
        }

        @Override
        public void onReport(Link link) {
        }

        @Override
        public void onSave(Link link) {
        }

        @Override
        public void onShowComments(Link link, AdapterLink.ViewHolderLink viewHolderLink, Source source) {
        }

        @Override
        public void onShowError(String error) {
        }

        @Override
        public void onMarkNsfw(Link link) {
        }
    };
    AdapterCommentList.ViewHolderComment.Listener listenerComments = new AdapterCommentList.ViewHolderComment.Listener() {

        @Override
        public void onToggleComment(Comment comment) {
        }

        @Override
        public void onShowReplyEditor(Comment comment) {
        }

        @Override
        public void onEditComment(Comment comment, String text) {
        }

        @Override
        public void onSendComment(Comment comment, String text) {
        }

        @Override
        public void onMarkRead(Comment comment) {
        }

        @Override
        public void onLoadNestedComments(Comment comment) {
        }

        @Override
        public void onJumpToParent(Comment comment) {
        }

        @Override
        public void onViewProfile(Comment comment) {
        }

        @Override
        public void onCopyText(Comment comment) {
        }

        @Override
        public void onDeleteComment(Comment comment) {
        }

        @Override
        public void onReport(Comment comment) {
        }

        @Override
        public void onVoteComment(Comment comment, AdapterCommentList.ViewHolderComment viewHolderComment, Likes vote) {
        }

        @Override
        public void onSave(Comment comment) {
        }
    };
    if (adapterProfile == null) {
        adapterProfile = new AdapterProfile(getActivity(), controllerProfile, adapterListener, listenerLink, listenerComments, listener);
    }
    recyclerProfile.setAdapter(adapterProfile);
    callback = new CustomItemTouchHelper.SimpleCallback(activity, R.drawable.ic_delete_white_24dp, ItemTouchHelper.START | ItemTouchHelper.END, ItemTouchHelper.START | ItemTouchHelper.END) {

        @Override
        public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            int position = viewHolder.getAdapterPosition();
            if (position == 2 || (position >= 6 && controllerProfile.getViewType(position - 6) == ControllerProfile.VIEW_TYPE_LINK)) {
                return super.getSwipeDirs(recyclerView, viewHolder);
            }
            return 0;
        }

        @Override
        public boolean isLongPressDragEnabled() {
            return false;
        }

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
            Log.d(TAG, "onSwiped: " + viewHolder.getAdapterPosition());
            final int adapterPosition = viewHolder.getAdapterPosition();
            final int position = adapterPosition == 2 ? -1 : adapterPosition - 6;
            final Link link = adapterPosition == 2 ? controllerProfile.remove(-1) : controllerProfile.remove(position);
            mListener.getEventListenerBase().hide(link);
            if (snackbar != null) {
                snackbar.dismiss();
            }
            SpannableString text = new SpannableString(link.isHidden() ? getString(R.string.link_hidden) : getString(R.string.link_shown));
            text.setSpan(new ForegroundColorSpan(themer.getColorFilterPrimary().getColor()), 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            //noinspection ResourceType
            snackbar = Snackbar.make(recyclerProfile, text, UtilsAnimation.SNACKBAR_DURATION).setActionTextColor(themer.getColorFilterPrimary().getColor()).setAction(R.string.undo, new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mListener.getEventListenerBase().hide(link);
                    if (adapterPosition == 2) {
                        controllerProfile.setTopLink(link);
                        adapterProfile.notifyItemChanged(2);
                    } else {
                        controllerProfile.add(position, link);
                    }
                    recyclerProfile.invalidate();
                }
            });
            snackbar.getView().setBackgroundColor(themer.getColorPrimary());
            snackbar.show();
        }
    };
    itemTouchHelper = new CustomItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(recyclerProfile);
    return view;
}
Also used : ItemDecorationDivider(com.winsonchiu.reader.utils.ItemDecorationDivider) AdapterLink(com.winsonchiu.reader.links.AdapterLink) Page(com.winsonchiu.reader.data.Page) SpannableString(android.text.SpannableString) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Sort(com.winsonchiu.reader.data.reddit.Sort) AppBarLayout(android.support.design.widget.AppBarLayout) ForegroundColorSpan(android.text.style.ForegroundColorSpan) AppCompatSpinner(android.support.v7.widget.AppCompatSpinner) SpannableString(android.text.SpannableString) AdapterView(android.widget.AdapterView) AdapterLink(com.winsonchiu.reader.links.AdapterLink) Link(com.winsonchiu.reader.data.reddit.Link) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) Time(com.winsonchiu.reader.data.reddit.Time) Source(com.winsonchiu.reader.comments.Source) ContextThemeWrapper(android.view.ContextThemeWrapper) ThemeWrapper(com.winsonchiu.reader.theme.ThemeWrapper) AdapterCommentList(com.winsonchiu.reader.comments.AdapterCommentList) ActivityMain(com.winsonchiu.reader.ActivityMain) CustomItemTouchHelper(com.winsonchiu.reader.utils.CustomItemTouchHelper) Comment(com.winsonchiu.reader.data.reddit.Comment) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) Intent(android.content.Intent) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ContextThemeWrapper(android.view.ContextThemeWrapper) Listing(com.winsonchiu.reader.data.reddit.Listing) RecyclerView(android.support.v7.widget.RecyclerView) Likes(com.winsonchiu.reader.data.reddit.Likes)

Example 32 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project android_frameworks_base by ParanoidAndroid.

the class ViewPropertyAlphaActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_properties);
    getWindow().getDecorView().postDelayed(new Runnable() {

        @Override
        public void run() {
            startAnim(R.id.button);
            startAnim(R.id.textview);
            startAnim(R.id.spantext);
            startAnim(R.id.edittext);
            startAnim(R.id.selectedtext);
            startAnim(R.id.textviewbackground);
            startAnim(R.id.layout);
            startAnim(R.id.imageview);
            startAnim(myViewAlphaDefault);
            startAnim(myViewAlphaHandled);
            EditText selectedText = (EditText) findViewById(R.id.selectedtext);
            selectedText.setSelection(3, 8);
        }
    }, 2000);
    Button invalidator = (Button) findViewById(R.id.invalidateButton);
    invalidator.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            findViewById(R.id.textview).invalidate();
            findViewById(R.id.spantext).invalidate();
        }
    });
    TextView textView = (TextView) findViewById(R.id.spantext);
    if (textView != null) {
        SpannableStringBuilder text = new SpannableStringBuilder("Now this is a short text message with spans");
        text.setSpan(new BackgroundColorSpan(Color.RED), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new ForegroundColorSpan(Color.BLUE), 4, 9, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new SuggestionSpan(this, new String[] { "longer" }, 3), 11, 16, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new UnderlineSpan(), 17, 20, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new ImageSpan(this, R.drawable.icon), 21, 22, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(text);
    }
    LinearLayout container = (LinearLayout) findViewById(R.id.container);
    myViewAlphaDefault = new MyView(this, false);
    myViewAlphaDefault.setLayoutParams(new LinearLayout.LayoutParams(75, 75));
    container.addView(myViewAlphaDefault);
    myViewAlphaHandled = new MyView(this, true);
    myViewAlphaHandled.setLayoutParams(new LinearLayout.LayoutParams(75, 75));
    container.addView(myViewAlphaHandled);
}
Also used : EditText(android.widget.EditText) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextView(android.widget.TextView) View(android.view.View) UnderlineSpan(android.text.style.UnderlineSpan) Button(android.widget.Button) TextView(android.widget.TextView) SuggestionSpan(android.text.style.SuggestionSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) BackgroundColorSpan(android.text.style.BackgroundColorSpan) LinearLayout(android.widget.LinearLayout) ImageSpan(android.text.style.ImageSpan)

Example 33 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project MPAndroidChart by PhilJay.

the class PieChartItem method generateCenterText.

private SpannableString generateCenterText() {
    SpannableString s = new SpannableString("MPAndroidChart\ncreated by\nPhilipp Jahoda");
    s.setSpan(new RelativeSizeSpan(1.6f), 0, 14, 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.VORDIPLOM_COLORS[0]), 0, 14, 0);
    s.setSpan(new RelativeSizeSpan(.9f), 14, 25, 0);
    s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, 25, 0);
    s.setSpan(new RelativeSizeSpan(1.4f), 25, s.length(), 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 25, s.length(), 0);
    return s;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 34 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project MPAndroidChart by PhilJay.

the class PiePolylineChartActivity method generateCenterSpannableText.

private SpannableString generateCenterSpannableText() {
    SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
    s.setSpan(new RelativeSizeSpan(1.5f), 0, 14, 0);
    s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
    s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
    s.setSpan(new RelativeSizeSpan(.65f), 14, s.length() - 15, 0);
    s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
    return s;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 35 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project MPAndroidChart by PhilJay.

the class RealmDatabaseActivityPie method generateCenterSpannableText.

private SpannableString generateCenterSpannableText() {
    SpannableString s = new SpannableString("Realm.io\nmobile database");
    s.setSpan(new ForegroundColorSpan(Color.rgb(240, 115, 126)), 0, 8, 0);
    s.setSpan(new RelativeSizeSpan(2.2f), 0, 8, 0);
    s.setSpan(new StyleSpan(Typeface.ITALIC), 9, s.length(), 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 9, s.length(), 0);
    s.setSpan(new RelativeSizeSpan(0.85f), 9, s.length(), 0);
    return s;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Aggregations

ForegroundColorSpan (android.text.style.ForegroundColorSpan)157 SpannableStringBuilder (android.text.SpannableStringBuilder)57 SpannableString (android.text.SpannableString)50 StyleSpan (android.text.style.StyleSpan)25 TextView (android.widget.TextView)25 ImageSpan (android.text.style.ImageSpan)23 Spannable (android.text.Spannable)22 RelativeSizeSpan (android.text.style.RelativeSizeSpan)22 View (android.view.View)22 BackgroundColorSpan (android.text.style.BackgroundColorSpan)19 TypefaceSpan (android.text.style.TypefaceSpan)16 StrikethroughSpan (android.text.style.StrikethroughSpan)14 UnderlineSpan (android.text.style.UnderlineSpan)13 Drawable (android.graphics.drawable.Drawable)12 CharacterStyle (android.text.style.CharacterStyle)11 EditText (android.widget.EditText)11 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)8 LinearLayout (android.widget.LinearLayout)8 URLSpan (android.text.style.URLSpan)7