Search in sources :

Example 6 with Color

use of android.graphics.Color in project mapbox-plugins-android by mapbox.

the class CircleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_annotation);
    TextView draggableInfoTv = findViewById(R.id.draggable_position_tv);
    mapView = findViewById(R.id.mapView);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
        findViewById(R.id.fabStyles).setOnClickListener(v -> mapboxMap.setStyle(Utils.INSTANCE.getNextStyle()));
        mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(2));
        // create circle manager
        circleManager = new CircleManager(mapView, mapboxMap, style);
        circleManager.addClickListener(circle -> {
            Toast.makeText(CircleActivity.this, String.format("Circle clicked %s", circle.getId()), Toast.LENGTH_SHORT).show();
            return false;
        });
        circleManager.addLongClickListener(circle -> {
            Toast.makeText(CircleActivity.this, String.format("Circle long clicked %s", circle.getId()), Toast.LENGTH_SHORT).show();
            return false;
        });
        // create a fixed circle
        CircleOptions circleOptions = new CircleOptions().withLatLng(new LatLng(6.687337, 0.381457)).withCircleColor(ColorUtils.colorToRgbaString(Color.YELLOW)).withCircleRadius(12f).withDraggable(true);
        circleManager.create(circleOptions);
        // random add circles across the globe
        List<CircleOptions> circleOptionsList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            int color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256));
            circleOptionsList.add(new CircleOptions().withLatLng(createRandomLatLng()).withCircleColor(ColorUtils.colorToRgbaString(color)).withCircleRadius(8f).withDraggable(true));
        }
        circleManager.create(circleOptionsList);
        try {
            circleManager.create(Utils.INSTANCE.loadStringFromAssets(this, "annotations.json"));
        } catch (IOException e) {
            throw new RuntimeException("Unable to parse annotations.json");
        }
        circleManager.addDragListener(new OnCircleDragListener() {

            @Override
            public void onAnnotationDragStarted(Circle annotation) {
                draggableInfoTv.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnnotationDrag(Circle annotation) {
                draggableInfoTv.setText(String.format(Locale.US, "ID: %s\nLatLng:%f, %f", annotation.getId(), annotation.getLatLng().getLatitude(), annotation.getLatLng().getLongitude()));
            }

            @Override
            public void onAnnotationDragFinished(Circle annotation) {
                draggableInfoTv.setVisibility(View.GONE);
            }
        });
    }));
}
Also used : CircleManager(com.mapbox.mapboxsdk.plugins.annotation.CircleManager) Circle(com.mapbox.mapboxsdk.plugins.annotation.Circle) Bundle(android.os.Bundle) ColorUtils(com.mapbox.mapboxsdk.utils.ColorUtils) MapView(com.mapbox.mapboxsdk.maps.MapView) R(com.mapbox.mapboxsdk.plugins.testapp.R) IOException(java.io.IOException) Random(java.util.Random) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Utils(com.mapbox.mapboxsdk.plugins.testapp.Utils) MenuItem(android.view.MenuItem) CircleOptions(com.mapbox.mapboxsdk.plugins.annotation.CircleOptions) ArrayList(java.util.ArrayList) Color(android.graphics.Color) CameraUpdateFactory(com.mapbox.mapboxsdk.camera.CameraUpdateFactory) List(java.util.List) TextView(android.widget.TextView) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) OnCircleDragListener(com.mapbox.mapboxsdk.plugins.annotation.OnCircleDragListener) Locale(java.util.Locale) Toast(android.widget.Toast) Style(com.mapbox.mapboxsdk.maps.Style) Menu(android.view.Menu) View(android.view.View) CircleManager(com.mapbox.mapboxsdk.plugins.annotation.CircleManager) Circle(com.mapbox.mapboxsdk.plugins.annotation.Circle) CircleOptions(com.mapbox.mapboxsdk.plugins.annotation.CircleOptions) OnCircleDragListener(com.mapbox.mapboxsdk.plugins.annotation.OnCircleDragListener) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) IOException(java.io.IOException)

Example 7 with Color

use of android.graphics.Color in project Slide by ccrama.

the class CommentAdapter method setCommentStateHighlighted.

public void setCommentStateHighlighted(final CommentViewHolder holder, final Comment n, final CommentNode baseNode, boolean isReplying, boolean animate) {
    if (currentlySelected != null && currentlySelected != holder) {
        setCommentStateUnhighlighted(currentlySelected, currentBaseNode, true);
    }
    if (mContext instanceof BaseActivity) {
        ((BaseActivity) mContext).setShareUrl("https://reddit.com" + submission.getPermalink() + n.getFullName() + "?context=3");
    }
    // and expand to show all children comments
    if (SettingValues.swap && holder.firstTextView.getVisibility() == View.GONE && !isReplying) {
        hiddenPersons.remove(n.getFullName());
        unhideAll(baseNode, holder.getBindingAdapterPosition() + 1);
        if (toCollapse.contains(n.getFullName()) && SettingValues.collapseComments) {
            setViews(n.getDataNode().get("body_html").asText(), submission.getSubredditName(), holder);
        }
        CommentAdapterHelper.hideChildrenObject(holder.childrenNumber);
        holder.commentOverflow.setVisibility(View.VISIBLE);
        toCollapse.remove(n.getFullName());
    } else {
        currentlySelected = holder;
        currentBaseNode = baseNode;
        int color = Palette.getColor(n.getSubredditName());
        currentSelectedItem = n.getFullName();
        currentNode = baseNode;
        LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
        resetMenu(holder.menuArea, false);
        final View baseView = inflater.inflate(SettingValues.rightHandedCommentMenu ? R.layout.comment_menu_right_handed : R.layout.comment_menu, holder.menuArea);
        if (!isReplying) {
            baseView.setVisibility(View.GONE);
            if (animate) {
                expand(baseView);
            } else {
                baseView.setVisibility(View.VISIBLE);
                final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                baseView.measure(widthSpec, heightSpec);
                View l2 = baseView.findViewById(R.id.replyArea) == null ? baseView.findViewById(R.id.innerSend) : baseView.findViewById(R.id.replyArea);
                final int widthSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                final int heightSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                l2.measure(widthSpec2, heightSpec2);
                ViewGroup.LayoutParams layoutParams = baseView.getLayoutParams();
                layoutParams.height = baseView.getMeasuredHeight() - l2.getMeasuredHeight();
                baseView.setLayoutParams(layoutParams);
            }
        }
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
        params.setMargins(0, 0, 0, 0);
        holder.itemView.setLayoutParams(params);
        View reply = baseView.findViewById(R.id.reply);
        View send = baseView.findViewById(R.id.send);
        final View menu = baseView.findViewById(R.id.menu);
        final View replyArea = baseView.findViewById(R.id.replyArea);
        final View more = baseView.findViewById(R.id.more);
        final ImageView upvote = baseView.findViewById(R.id.upvote);
        final ImageView downvote = baseView.findViewById(R.id.downvote);
        View discard = baseView.findViewById(R.id.discard);
        final EditText replyLine = baseView.findViewById(R.id.replyLine);
        final ImageView mod = baseView.findViewById(R.id.mod);
        final Comment comment = baseNode.getComment();
        if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
            BlendModeUtil.tintImageViewAsModulate(upvote, holder.textColorUp);
            upvote.setContentDescription(mContext.getResources().getString(R.string.btn_upvoted));
        } else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
            BlendModeUtil.tintImageViewAsModulate(downvote, holder.textColorDown);
            downvote.setContentDescription(mContext.getResources().getString(R.string.btn_downvoted));
        } else {
            downvote.clearColorFilter();
            downvote.setContentDescription(mContext.getResources().getString(R.string.btn_downvote));
            upvote.clearColorFilter();
            upvote.setContentDescription(mContext.getResources().getString(R.string.btn_upvote));
        }
        try {
            if (UserSubscriptions.modOf.contains(submission.getSubredditName())) {
                // todo
                mod.setVisibility(View.GONE);
            } else {
                mod.setVisibility(View.GONE);
            }
        } catch (Exception e) {
            Log.d(LogUtil.getTag(), "Error loading mod " + e.toString());
        }
        if (UserSubscriptions.modOf != null && UserSubscriptions.modOf.contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH))) {
            mod.setVisibility(View.VISIBLE);
            final Map<String, Integer> reports = comment.getUserReports();
            final Map<String, String> reports2 = comment.getModeratorReports();
            if (reports.size() + reports2.size() > 0) {
                BlendModeUtil.tintImageViewAsSrcAtop(mod, ContextCompat.getColor(mContext, R.color.md_red_300));
            } else {
                BlendModeUtil.tintImageViewAsSrcAtop(mod, Color.WHITE);
            }
            mod.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    CommentAdapterHelper.showModBottomSheet(CommentAdapter.this, mContext, baseNode, comment, holder, reports, reports2);
                }
            });
        } else {
            mod.setVisibility(View.GONE);
        }
        final ImageView edit = baseView.findViewById(R.id.edit);
        if (Authentication.name != null && Authentication.name.toLowerCase(Locale.ENGLISH).equals(comment.getAuthor().toLowerCase(Locale.ENGLISH)) && Authentication.didOnline) {
            edit.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    CommentAdapterHelper.doCommentEdit(CommentAdapter.this, mContext, fm, baseNode, baseNode.isTopLevel() ? submission.getSelftext() : baseNode.getParent().getComment().getBody(), holder);
                }
            });
        } else {
            edit.setVisibility(View.GONE);
        }
        final ImageView delete = baseView.findViewById(R.id.delete);
        if (Authentication.name != null && Authentication.name.toLowerCase(Locale.ENGLISH).equals(comment.getAuthor().toLowerCase(Locale.ENGLISH)) && Authentication.didOnline) {
            delete.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    CommentAdapterHelper.deleteComment(CommentAdapter.this, mContext, baseNode, holder);
                }
            });
        } else {
            delete.setVisibility(View.GONE);
        }
        if (Authentication.isLoggedIn && !submission.isArchived() && !submission.isLocked() && !(comment.getDataNode().has("locked") && comment.getDataNode().get("locked").asBoolean()) && !deleted.contains(n.getFullName()) && !comment.getAuthor().equals("[deleted]") && Authentication.didOnline) {
            if (isReplying) {
                baseView.setVisibility(View.VISIBLE);
                final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                baseView.measure(widthSpec, heightSpec);
                View l2 = baseView.findViewById(R.id.replyArea) == null ? baseView.findViewById(R.id.innerSend) : baseView.findViewById(R.id.replyArea);
                final int widthSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                final int heightSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                l2.measure(widthSpec2, heightSpec2);
                RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) baseView.getLayoutParams();
                params2.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
                params2.addRule(RelativeLayout.BELOW, R.id.commentOverflow);
                baseView.setLayoutParams(params2);
                replyArea.setVisibility(View.VISIBLE);
                menu.setVisibility(View.GONE);
                currentlyEditing = replyLine;
                currentlyEditing.setOnFocusChangeListener(new View.OnFocusChangeListener() {

                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        if (hasFocus) {
                            mPage.fastScroll.setVisibility(View.GONE);
                            if (mPage.fab != null) {
                                mPage.fab.setVisibility(View.GONE);
                            }
                            mPage.overrideFab = true;
                        } else if (SettingValues.fastscroll) {
                            mPage.fastScroll.setVisibility(View.VISIBLE);
                            if (mPage.fab != null) {
                                mPage.fab.setVisibility(View.VISIBLE);
                            }
                            mPage.overrideFab = false;
                        }
                    }
                });
                final TextView profile = baseView.findViewById(R.id.profile);
                changedProfile = Authentication.name;
                profile.setText("/u/" + changedProfile);
                profile.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final HashMap<String, String> accounts = new HashMap<>();
                        for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
                            if (s.contains(":")) {
                                accounts.put(s.split(":")[0], s.split(":")[1]);
                            } else {
                                accounts.put(s, "");
                            }
                        }
                        final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
                        final int i = keys.indexOf(changedProfile);
                        new AlertDialog.Builder(mContext).setTitle(R.string.sorting_choose).setSingleChoiceItems(keys.toArray(new String[0]), i, (dialog, which) -> {
                            changedProfile = keys.get(which);
                            profile.setText("/u/" + changedProfile);
                        }).setNegativeButton(R.string.btn_cancel, null).show();
                    }
                });
                replyLine.requestFocus();
                KeyboardUtil.toggleKeyboard(mContext, InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                currentlyEditingId = n.getFullName();
                replyLine.setText(backedText);
                replyLine.addTextChangedListener(new SimpleTextWatcher() {

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                        backedText = s.toString();
                    }
                });
                editingPosition = holder.getBindingAdapterPosition();
            }
            reply.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    expandAndSetParams(baseView);
                    // If the base theme is Light or Sepia, tint the Editor actions to be white
                    if (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5) {
                        final ImageView saveDraft = (ImageView) replyArea.findViewById(R.id.savedraft);
                        final ImageView draft = (ImageView) replyArea.findViewById(R.id.draft);
                        final ImageView imagerep = (ImageView) replyArea.findViewById(R.id.imagerep);
                        final ImageView link = (ImageView) replyArea.findViewById(R.id.link);
                        final ImageView bold = (ImageView) replyArea.findViewById(R.id.bold);
                        final ImageView italics = (ImageView) replyArea.findViewById(R.id.italics);
                        final ImageView bulletlist = (ImageView) replyArea.findViewById(R.id.bulletlist);
                        final ImageView numlist = (ImageView) replyArea.findViewById(R.id.numlist);
                        final ImageView draw = (ImageView) replyArea.findViewById(R.id.draw);
                        final ImageView quote = (ImageView) replyArea.findViewById(R.id.quote);
                        final ImageView size = (ImageView) replyArea.findViewById(R.id.size);
                        final ImageView strike = (ImageView) replyArea.findViewById(R.id.strike);
                        final ImageView author = (ImageView) replyArea.findViewById(R.id.author);
                        final ImageView spoiler = (ImageView) replyArea.findViewById(R.id.spoiler);
                        final List<ImageView> imageViewSet = Arrays.asList(saveDraft, draft, imagerep, link, bold, italics, bulletlist, numlist, draw, quote, size, strike, author, spoiler);
                        BlendModeUtil.tintImageViewsAsSrcAtop(imageViewSet, Color.WHITE);
                        BlendModeUtil.tintDrawableAsSrcIn(replyLine.getBackground(), Color.WHITE);
                    }
                    replyArea.setVisibility(View.VISIBLE);
                    menu.setVisibility(View.GONE);
                    currentlyEditing = replyLine;
                    DoEditorActions.doActions(currentlyEditing, replyArea, fm, (Activity) mContext, comment.getBody(), getParents(baseNode));
                    currentlyEditing.setOnFocusChangeListener(new View.OnFocusChangeListener() {

                        @Override
                        public void onFocusChange(View v, boolean hasFocus) {
                            if (hasFocus) {
                                mPage.fastScroll.setVisibility(View.GONE);
                                if (mPage.fab != null)
                                    mPage.fab.setVisibility(View.GONE);
                                mPage.overrideFab = true;
                            } else if (SettingValues.fastscroll) {
                                mPage.fastScroll.setVisibility(View.VISIBLE);
                                if (mPage.fab != null)
                                    mPage.fab.setVisibility(View.VISIBLE);
                                mPage.overrideFab = false;
                            }
                        }
                    });
                    final TextView profile = baseView.findViewById(R.id.profile);
                    changedProfile = Authentication.name;
                    profile.setText("/u/" + changedProfile);
                    profile.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            final HashMap<String, String> accounts = new HashMap<>();
                            for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
                                if (s.contains(":")) {
                                    accounts.put(s.split(":")[0], s.split(":")[1]);
                                } else {
                                    accounts.put(s, "");
                                }
                            }
                            final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
                            final int i = keys.indexOf(changedProfile);
                            new AlertDialog.Builder(mContext).setTitle(R.string.sorting_choose).setSingleChoiceItems(keys.toArray(new String[0]), i, (dialog, which) -> {
                                changedProfile = keys.get(which);
                                profile.setText("/u/" + changedProfile);
                            }).setNegativeButton(R.string.btn_cancel, null).show();
                        }
                    });
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                        replyLine.setOnFocusChangeListener((view, b) -> {
                            if (b) {
                                view.postDelayed(() -> {
                                    if (!view.hasFocus())
                                        view.requestFocus();
                                }, 100);
                            }
                        });
                    }
                    // TODO: Not working when called a second time
                    replyLine.requestFocus();
                    KeyboardUtil.toggleKeyboard(mContext, InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                    currentlyEditingId = n.getFullName();
                    replyLine.addTextChangedListener(new SimpleTextWatcher() {

                        @Override
                        public void onTextChanged(CharSequence s, int start, int before, int count) {
                            backedText = s.toString();
                        }
                    });
                    editingPosition = holder.getBindingAdapterPosition();
                }
            });
            send.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    currentlyEditingId = "";
                    backedText = "";
                    doShowMenu(baseView);
                    if (SettingValues.fastscroll) {
                        mPage.fastScroll.setVisibility(View.VISIBLE);
                        if (mPage.fab != null)
                            mPage.fab.setVisibility(View.VISIBLE);
                        mPage.overrideFab = false;
                    }
                    dataSet.refreshLayout.setRefreshing(true);
                    if (currentlyEditing != null) {
                        String text = currentlyEditing.getText().toString();
                        new ReplyTaskComment(n, baseNode, holder, changedProfile).execute(text);
                        currentlyEditing = null;
                        editingPosition = -1;
                    }
                    // Hide soft keyboard
                    View view = ((Activity) mContext).findViewById(android.R.id.content);
                    if (view != null) {
                        KeyboardUtil.hideKeyboard(mContext, view.getWindowToken(), 0);
                    }
                }
            });
            discard.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    currentlyEditing = null;
                    editingPosition = -1;
                    currentlyEditingId = "";
                    backedText = "";
                    mPage.overrideFab = false;
                    View view = ((Activity) mContext).findViewById(android.R.id.content);
                    if (view != null) {
                        KeyboardUtil.hideKeyboard(mContext, view.getWindowToken(), 0);
                    }
                    doShowMenu(baseView);
                }
            });
        } else {
            if (reply.getVisibility() == View.VISIBLE) {
                reply.setVisibility(View.GONE);
            }
            if ((submission.isArchived() || deleted.contains(n.getFullName()) || comment.getAuthor().equals("[deleted]")) && Authentication.isLoggedIn && Authentication.didOnline && upvote.getVisibility() == View.VISIBLE) {
                upvote.setVisibility(View.GONE);
            }
            if ((submission.isArchived() || deleted.contains(n.getFullName()) || comment.getAuthor().equals("[deleted]")) && Authentication.isLoggedIn && Authentication.didOnline && downvote.getVisibility() == View.VISIBLE) {
                downvote.setVisibility(View.GONE);
            }
        }
        more.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                CommentAdapterHelper.showOverflowBottomSheet(CommentAdapter.this, mContext, holder, baseNode);
            }
        });
        upvote.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                setCommentStateUnhighlighted(holder, comment, baseNode, true);
                if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
                    new Vote(v, mContext).execute(n);
                    ActionStates.setVoteDirection(comment, VoteDirection.NO_VOTE);
                    doScoreText(holder, n, CommentAdapter.this);
                    upvote.clearColorFilter();
                } else {
                    new Vote(true, v, mContext).execute(n);
                    ActionStates.setVoteDirection(comment, VoteDirection.UPVOTE);
                    // reset colour
                    downvote.clearColorFilter();
                    doScoreText(holder, n, CommentAdapter.this);
                    BlendModeUtil.tintImageViewAsModulate(upvote, holder.textColorUp);
                }
            }
        });
        downvote.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                setCommentStateUnhighlighted(holder, comment, baseNode, true);
                if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
                    new Vote(v, mContext).execute(n);
                    ActionStates.setVoteDirection(comment, VoteDirection.NO_VOTE);
                    doScoreText(holder, n, CommentAdapter.this);
                    downvote.clearColorFilter();
                } else {
                    new Vote(false, v, mContext).execute(n);
                    ActionStates.setVoteDirection(comment, VoteDirection.DOWNVOTE);
                    // reset colour
                    upvote.clearColorFilter();
                    doScoreText(holder, n, CommentAdapter.this);
                    BlendModeUtil.tintImageViewAsModulate(downvote, holder.textColorDown);
                }
            }
        });
        menu.setBackgroundColor(color);
        replyArea.setBackgroundColor(color);
        if (!isReplying) {
            menu.setVisibility(View.VISIBLE);
            replyArea.setVisibility(View.GONE);
        }
        holder.itemView.findViewById(R.id.background).setBackgroundColor(Color.argb(50, Color.red(color), Color.green(color), Color.blue(color)));
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) LinearLayout(android.widget.LinearLayout) Arrays(java.util.Arrays) R(me.ccrama.redditslide.R) RobotoTypefaces(com.devspark.robototextview.RobotoTypefaces) AnimatorUtil(me.ccrama.redditslide.util.AnimatorUtil) Uri(android.net.Uri) ImageView(android.widget.ImageView) Animator(android.animation.Animator) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) Locale(java.util.Locale) Handler(android.os.Handler) Looper(android.os.Looper) Map(java.util.Map) View(android.view.View) Drafts(me.ccrama.redditslide.Drafts) PreCachingLayoutManagerComments(me.ccrama.redditslide.Views.PreCachingLayoutManagerComments) RecyclerView(androidx.recyclerview.widget.RecyclerView) DiskCacheUtils(com.nostra13.universalimageloader.utils.DiskCacheUtils) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) PrintWriter(java.io.PrintWriter) AsyncTask(android.os.AsyncTask) KeyboardUtil(me.ccrama.redditslide.util.KeyboardUtil) Authentication(me.ccrama.redditslide.Authentication) CommentPage(me.ccrama.redditslide.Fragments.CommentPage) ApiException(net.dean.jraw.ApiException) DisplayUtil(me.ccrama.redditslide.util.DisplayUtil) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Palette(me.ccrama.redditslide.Visuals.Palette) BlendModeUtil(me.ccrama.redditslide.util.BlendModeUtil) SimpleTextWatcher(me.ccrama.redditslide.util.stubs.SimpleTextWatcher) ViewGroup(android.view.ViewGroup) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) List(java.util.List) TextView(android.widget.TextView) Contribution(net.dean.jraw.models.Contribution) Writer(java.io.Writer) RelativeLayout(android.widget.RelativeLayout) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) CommentOverflow(me.ccrama.redditslide.Views.CommentOverflow) BuildConfig(me.ccrama.redditslide.BuildConfig) SubmissionParser(me.ccrama.redditslide.util.SubmissionParser) Typeface(android.graphics.Typeface) DoEditorActions(me.ccrama.redditslide.Views.DoEditorActions) Context(android.content.Context) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) SettingValues(me.ccrama.redditslide.SettingValues) AlertDialog(androidx.appcompat.app.AlertDialog) HasSeen(me.ccrama.redditslide.HasSeen) FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) Submission(net.dean.jraw.models.Submission) Vote(me.ccrama.redditslide.Vote) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) Constants(me.ccrama.redditslide.Constants) LogUtil(me.ccrama.redditslide.util.LogUtil) InputMethodManager(android.view.inputmethod.InputMethodManager) AccountManager(net.dean.jraw.managers.AccountManager) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UserSubscriptions(me.ccrama.redditslide.UserSubscriptions) SlideRightAlphaAnimator(com.mikepenz.itemanimators.SlideRightAlphaAnimator) Build(android.os.Build) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink) AlphaInAnimator(com.mikepenz.itemanimators.AlphaInAnimator) FragmentManager(androidx.fragment.app.FragmentManager) RedditClient(net.dean.jraw.RedditClient) UserAgent(net.dean.jraw.http.UserAgent) LayoutInflater(android.view.LayoutInflater) StringWriter(java.io.StringWriter) ImageFlairs(me.ccrama.redditslide.ImageFlairs) Reddit(me.ccrama.redditslide.Reddit) VoteDirection(net.dean.jraw.models.VoteDirection) KVStore(com.lusfold.androidkeyvaluestore.KVStore) File(java.io.File) Color(android.graphics.Color) TypedValue(android.util.TypedValue) TreeMap(java.util.TreeMap) Bitmap(android.graphics.Bitmap) ActionStates(me.ccrama.redditslide.ActionStates) CommentNode(net.dean.jraw.models.CommentNode) LastComments(me.ccrama.redditslide.LastComments) Activity(android.app.Activity) Collections(java.util.Collections) EditText(android.widget.EditText) Comment(net.dean.jraw.models.Comment) ValueAnimator(android.animation.ValueAnimator) Resources(android.content.res.Resources) HashMap(java.util.HashMap) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ArrayList(java.util.ArrayList) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) Activity(android.app.Activity) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) List(java.util.List) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) HashSet(java.util.HashSet) EditText(android.widget.EditText) Comment(net.dean.jraw.models.Comment) Vote(me.ccrama.redditslide.Vote) ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ApiException(net.dean.jraw.ApiException) SimpleTextWatcher(me.ccrama.redditslide.util.stubs.SimpleTextWatcher) LayoutInflater(android.view.LayoutInflater) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) RelativeLayout(android.widget.RelativeLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 8 with Color

use of android.graphics.Color in project Taskbar by farmerbb.

the class AppearanceFragment method showColorPicker.

@SuppressLint("SetTextI18n")
private void showColorPicker(ColorPickerType type) {
    int color = -1;
    int dialogTitle = -1;
    switch(type) {
        case BACKGROUND_TINT:
            color = U.getBackgroundTint(getActivity());
            dialogTitle = R.string.tb_pref_title_background_tint;
            break;
        case ACCENT_COLOR:
            color = U.getAccentColor(getActivity());
            dialogTitle = R.string.tb_pref_title_accent_color;
            break;
    }
    alpha = Color.alpha(color);
    red = Color.red(color);
    green = Color.green(color);
    blue = Color.blue(color);
    ScrollView dialogLayout = (ScrollView) View.inflate(getActivity(), R.layout.tb_color_picker_pref, null);
    View colorPreview = dialogLayout.findViewById(R.id.color_preview);
    colorPreview.setBackgroundColor(Color.argb(alpha, red, green, blue));
    TextView hexPreview = dialogLayout.findViewById(R.id.hex_preview);
    hexPreview.setText("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
    final TextView alphaValue = dialogLayout.findViewById(R.id.alpha_value);
    alphaValue.setText("0");
    final SeekBar alphaSeekBar = dialogLayout.findViewById(R.id.alpha_seekbar);
    alphaSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            alpha = progress;
            alphaValue.setText(Integer.toString(alpha));
            colorPreview.setBackgroundColor(Color.argb(alpha, red, green, blue));
            hexPreview.setText("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    alphaSeekBar.setProgress(Color.alpha(color));
    final TextView redValue = dialogLayout.findViewById(R.id.red_value);
    redValue.setText("0");
    final SeekBar redSeekBar = dialogLayout.findViewById(R.id.red_seekbar);
    redSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            red = progress;
            redValue.setText(Integer.toString(red));
            colorPreview.setBackgroundColor(Color.argb(alpha, red, green, blue));
            hexPreview.setText("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    redSeekBar.setProgress(Color.red(color));
    final TextView greenValue = dialogLayout.findViewById(R.id.green_value);
    greenValue.setText("0");
    final SeekBar greenSeekBar = dialogLayout.findViewById(R.id.green_seekbar);
    greenSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            green = progress;
            greenValue.setText(Integer.toString(green));
            colorPreview.setBackgroundColor(Color.argb(alpha, red, green, blue));
            hexPreview.setText("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    greenSeekBar.setProgress(Color.green(color));
    final TextView blueValue = dialogLayout.findViewById(R.id.blue_value);
    blueValue.setText("0");
    final SeekBar blueSeekBar = dialogLayout.findViewById(R.id.blue_seekbar);
    blueSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            blue = progress;
            blueValue.setText(Integer.toString(blue));
            colorPreview.setBackgroundColor(Color.argb(alpha, red, green, blue));
            hexPreview.setText("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    blueSeekBar.setProgress(Color.blue(color));
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(dialogLayout).setTitle(dialogTitle).setPositiveButton(R.string.tb_action_ok, (dialog, which) -> {
        String preferenceId = null;
        switch(type) {
            case BACKGROUND_TINT:
                preferenceId = PREF_BACKGROUND_TINT;
                break;
            case ACCENT_COLOR:
                preferenceId = PREF_ACCENT_COLOR;
                break;
        }
        SharedPreferences pref = U.getSharedPreferences(getActivity());
        pref.edit().putInt(preferenceId, Color.argb(alpha, red, green, blue)).apply();
        findPreference(preferenceId + "_pref").setSummary("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
        U.restartTaskbar(getActivity());
    }).setNegativeButton(R.string.tb_action_cancel, null);
    AlertDialog dialog = builder.create();
    dialog.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) PackageManager(android.content.pm.PackageManager) R(com.farmerbb.taskbar.R) U(com.farmerbb.taskbar.util.U) Intent(android.content.Intent) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Color(android.graphics.Color) ActionBar(androidx.appcompat.app.ActionBar) SeekBar(android.widget.SeekBar) SuppressLint(android.annotation.SuppressLint) ListPreference(android.preference.ListPreference) IconPackActivity(com.farmerbb.taskbar.activity.IconPackActivity) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) ScrollView(android.widget.ScrollView) Preference(android.preference.Preference) View(android.view.View) Activity(android.app.Activity) Constants(com.farmerbb.taskbar.util.Constants) SeekBar(android.widget.SeekBar) SharedPreferences(android.content.SharedPreferences) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) View(android.view.View) SuppressLint(android.annotation.SuppressLint) ScrollView(android.widget.ScrollView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint)

Example 9 with Color

use of android.graphics.Color in project MTweaks-KernelAdiutorMOD by morogoku.

the class BuildpropFragment method load.

@Override
protected void load(List<RecyclerViewItem> items) {
    super.load(items);
    if (mProps == null)
        return;
    String[] titles = mProps.keySet().toArray(new String[mProps.size()]);
    for (int i = 0; i < mProps.size(); i++) {
        final String title = titles[i];
        final String value = mProps.values().toArray(new String[mProps.size()])[i];
        if ((mKeyText != null && !title.contains(mKeyText) || (mValueText != null && !value.contains(mValueText)))) {
            continue;
        }
        int color = ViewUtils.getThemeAccentColor(getActivity());
        String colorCode = "#" + Integer.toHexString(Color.red(color)) + Integer.toHexString(Color.green(color)) + Integer.toHexString(Color.blue(color));
        DescriptionView descriptionView = new DescriptionView();
        if (mKeyText != null && !mKeyText.isEmpty()) {
            descriptionView.setTitle(Utils.htmlFrom(title.replace(mKeyText, "<b><font color=\"" + colorCode + "\">" + mKeyText + "</font></b>")));
        } else {
            descriptionView.setTitle(title);
        }
        if (mValueText != null && !mValueText.isEmpty()) {
            descriptionView.setSummary(Utils.htmlFrom(value.replace(mValueText, "<b><font color=\"" + colorCode + "\">" + mValueText + "</font></b>")));
        } else {
            descriptionView.setSummary(value);
        }
        descriptionView.setOnItemClickListener(item -> {
            mItemOptionsDialog = new Dialog(getActivity()).setItems(getResources().getStringArray(R.array.build_prop_item_options), (dialogInterface, i1) -> {
                switch(i1) {
                    case 0:
                        modify(title, value);
                        break;
                    case 1:
                        delete(title, value);
                        break;
                }
            }).setOnDismissListener(dialogInterface -> mItemOptionsDialog = null);
            mItemOptionsDialog.show();
        });
        items.add(descriptionView);
    }
    Activity activity;
    if (mSearchFragment != null && (activity = getActivity()) != null) {
        activity.runOnUiThread(() -> {
            if (isAdded()) {
                for (int i = 0; i < childFragmentCount(); i++) {
                    Fragment fragment = getChildFragment(i);
                    if (fragment instanceof SearchFragment) {
                        ((SearchFragment) fragment).setCount(items.size());
                    }
                }
            }
        });
    }
}
Also used : RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) RecyclerViewFragment(com.moro.mtweaks.fragments.recyclerview.RecyclerViewFragment) DrawableCompat(androidx.core.graphics.drawable.DrawableCompat) BaseFragment(com.moro.mtweaks.fragments.BaseFragment) Drawable(android.graphics.drawable.Drawable) Editable(android.text.Editable) LinkedHashMap(java.util.LinkedHashMap) Buildprop(com.moro.mtweaks.utils.tools.Buildprop) Dialog(com.moro.mtweaks.views.dialog.Dialog) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) View(android.view.View) ContextCompat(androidx.core.content.ContextCompat) Utils(com.moro.mtweaks.utils.Utils) LayoutInflater(android.view.LayoutInflater) AppCompatEditText(androidx.appcompat.widget.AppCompatEditText) DescriptionView(com.moro.mtweaks.views.recyclerview.DescriptionView) ViewGroup(android.view.ViewGroup) ViewUtils(com.moro.mtweaks.utils.ViewUtils) Color(android.graphics.Color) RootUtils(com.moro.mtweaks.utils.root.RootUtils) R(com.moro.mtweaks.R) List(java.util.List) Nullable(androidx.annotation.Nullable) TextView(android.widget.TextView) Activity(android.app.Activity) TextWatcher(android.text.TextWatcher) Dialog(com.moro.mtweaks.views.dialog.Dialog) DescriptionView(com.moro.mtweaks.views.recyclerview.DescriptionView) Activity(android.app.Activity) RecyclerViewFragment(com.moro.mtweaks.fragments.recyclerview.RecyclerViewFragment) BaseFragment(com.moro.mtweaks.fragments.BaseFragment) Fragment(androidx.fragment.app.Fragment)

Example 10 with Color

use of android.graphics.Color in project qksms by moezbhatti.

the class ThemeManager method setIcon.

public static void setIcon(final QKActivity context) {
    String[] colors = { "Default", "Dark", "Red", "Pink", "Purple", "DeepPurple", "Indigo", "Blue", "LightBlue", "Cyan", "Teal", "Green", "LightGreen", "Lime", "Yellow", "Amber", "Orange", "DeepOrange", "Brown", "Grey", "BlueGrey" };
    RecyclerView recyclerView = new RecyclerView(context);
    recyclerView.setLayoutParams(new LinearLayout.LayoutParams(-1, Units.dpToPx(context, 200)));
    recyclerView.setLayoutManager(new GridLayoutManager(context, 4));
    recyclerView.setAdapter(new IconAdapter(context, (parent, view, position, id) -> {
        PackageManager packageManager = context.getPackageManager();
        // Disable all of the color aliases, except for the alias with the current
        // color.
        String enabledComponent = null;
        for (int i = 0; i < colors.length; i++) {
            String componentClassName = String.format("com.moez.QKSMS.ui.MainActivity-%s", colors[i]);
            // it's all done.
            if (i == position) {
                enabledComponent = componentClassName;
            } else {
                packageManager.setComponentEnabledSetting(new ComponentName(context, componentClassName), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, // won't show up to the user.
                PackageManager.DONT_KILL_APP);
            }
        }
        // Broadcast an intent to a receiver that will:
        // 1) enable the last component; and
        // 2) relaunch QKSMS with the new component name.
        Intent intent = new Intent(IconColorReceiver.ACTION_ICON_COLOR_CHANGED);
        intent.putExtra(IconColorReceiver.EXTRA_COMPONENT_NAME, enabledComponent);
        context.sendBroadcast(intent);
    }));
    new QKDialog().setContext(context).setTitle(R.string.update_icon_title).setMessage(R.string.update_icon_message).setCustomView(recyclerView).setNegativeButton(R.string.cancel, null).show();
}
Also used : ColorPickerPalette(com.moez.QKSMS.ui.view.colorpicker.ColorPickerPalette) GridLayoutManager(android.support.v7.widget.GridLayoutManager) LinearLayout(android.widget.LinearLayout) PackageManager(android.content.pm.PackageManager) QKTextView(com.moez.QKSMS.ui.view.QKTextView) ImageView(android.widget.ImageView) Animator(android.animation.Animator) WidgetProvider(com.moez.QKSMS.ui.widget.WidgetProvider) Drawable(android.graphics.drawable.Drawable) LiveViewManager(com.moez.QKSMS.common.LiveViewManager) View(android.view.View) ArgbEvaluator(android.animation.ArgbEvaluator) Bind(butterknife.Bind) PreferenceManager(android.preference.PreferenceManager) TargetApi(android.annotation.TargetApi) Log(android.util.Log) ContextCompat(android.support.v4.content.ContextCompat) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PorterDuff(android.graphics.PorterDuff) AnalyticsManager(com.moez.QKSMS.common.AnalyticsManager) ColorUtils(com.moez.QKSMS.common.utils.ColorUtils) IconColorReceiver(com.moez.QKSMS.receiver.IconColorReceiver) Units(com.moez.QKSMS.common.utils.Units) SettingsFragment(com.moez.QKSMS.ui.settings.SettingsFragment) EditorInfo(android.view.inputmethod.EditorInfo) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Context(android.content.Context) QKPreference(com.moez.QKSMS.enums.QKPreference) ButterKnife(butterknife.ButterKnife) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) QKActivity(com.moez.QKSMS.ui.base.QKActivity) KeyboardUtils(com.moez.QKSMS.common.utils.KeyboardUtils) R(com.moez.QKSMS.R) SeekBar(android.widget.SeekBar) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) ColorPickerPagerAdapter(com.moez.QKSMS.ui.dialog.ColorPickerPagerAdapter) Build(android.os.Build) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) QKEditText(com.moez.QKSMS.ui.view.QKEditText) CIELChEvaluator(com.moez.QKSMS.common.CIELChEvaluator) Color(android.graphics.Color) ColorInt(android.support.annotation.ColorInt) IconAdapter(com.moez.QKSMS.theme.IconAdapter) RecyclerView(android.support.v7.widget.RecyclerView) DrawableRes(android.support.annotation.DrawableRes) SharedPreferences(android.content.SharedPreferences) ConversationPrefsHelper(com.moez.QKSMS.common.ConversationPrefsHelper) ValueAnimator(android.animation.ValueAnimator) Resources(android.content.res.Resources) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) GridLayoutManager(android.support.v7.widget.GridLayoutManager) PackageManager(android.content.pm.PackageManager) IconAdapter(com.moez.QKSMS.theme.IconAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ComponentName(android.content.ComponentName) Intent(android.content.Intent) LinearLayout(android.widget.LinearLayout)

Aggregations

Color (android.graphics.Color)17 View (android.view.View)16 TextView (android.widget.TextView)14 List (java.util.List)12 Context (android.content.Context)11 Bundle (android.os.Bundle)11 LayoutInflater (android.view.LayoutInflater)11 ArrayList (java.util.ArrayList)10 Toast (android.widget.Toast)9 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)9 Intent (android.content.Intent)8 ViewGroup (android.view.ViewGroup)8 Drawable (android.graphics.drawable.Drawable)7 ImageView (android.widget.ImageView)7 Activity (android.app.Activity)6 Log (android.util.Log)6 SharedPreferences (android.content.SharedPreferences)5 AsyncTask (android.os.AsyncTask)5 MenuItem (android.view.MenuItem)5 Resources (android.content.res.Resources)4