Code Monkey home page Code Monkey logo

slimchart's Introduction

Mansur's GitHub stats

Top Langs

trophy

slimchart's People

Contributors

mancj avatar rayliverified avatar ztrap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slimchart's Issues

Defining textcolor inside RecyclerView Adapter causes Resources$NotFoundException

Hi,

I'm trying to define a SlimChart for each item on a RecyclerView. I need to define the text color of the chart based on a few parameters that relies on each item.

Here is the code inside the RecyclerView Adapter:

@Override
    public void onBindViewHolder(@NonNull SubjectGradeLineHolder holder, int position) {

        float obtainedGrade = mSubjects.get(position).getObtainedGrade();
        float maximumGrade = mSubjects.get(position).getMaximumGrade();
        SlimChart gradeChart = holder.gradeChart;
        int dangerColor = holder.itemView.getResources().getColor(R.color.slimchart_danger_color);
        int warningColor = holder.itemView.getResources().getColor(R.color.slimchart_warning_color);
        int okColor = holder.itemView.getResources().getColor(R.color.slimchart_ok_color);

        obtainedGrade = 75;
        maximumGrade = 100;

        float averageGradePercentage = obtainedGrade / maximumGrade * 100;
        final float[] stats = new float[4];

        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(holder.itemView.getContext());
        Integer dangerGradePercentage = sharedPreferences.getInt("minimumPercentage",60);
        Integer DANGER_WARNING_THRESHOLD = 10;
        Integer warningGradePercentage = dangerGradePercentage + DANGER_WARNING_THRESHOLD;

        holder.subjectName.setText(mSubjects.get(position).getName());

        String gradeText = obtainedGrade + " " +
                holder.itemView.getContext().getResources().getString(R.string.out_of) + " " +
                maximumGrade;

        holder.gradeText.setText(gradeText);

        holder.subjectName.setText(mSubjects.get(position).getName());

        String gradeChartText;
        if(maximumGrade != 0) {
            gradeChartText = String.valueOf(Math.round(averageGradePercentage)) + "%";
        } else {
            gradeChartText = "0%";
        }
        gradeChart.setText(gradeChartText);

        // Create color array for slimChart
        int[] graphColors = new int[4];

        if(averageGradePercentage >= warningGradePercentage) { // If grade is in "safe zone"
            graphColors[0] = okColor;
            graphColors[1] = warningColor;
            graphColors[2] = dangerColor;

            stats[0] = averageGradePercentage;
            stats[1] = warningGradePercentage;
            stats[2] = dangerGradePercentage;

            gradeChart.setTextColor(Color.GREEN);

        } else if (averageGradePercentage >= dangerGradePercentage && averageGradePercentage < warningGradePercentage) {
            graphColors[0] = warningColor;
            graphColors[1] = dangerColor;

            gradeChart.setColors(graphColors);
            stats[0] = averageGradePercentage;
            stats[1] = dangerGradePercentage;
        } else {
            graphColors[0] = dangerColor;
            stats[0] = averageGradePercentage;
        }

        gradeChart.setColors(graphColors);
        gradeChart.setStats(stats);

        //Play animation
        gradeChart.setStartAnimationDuration(2000);
        gradeChart.playStartAnimation();

    }

Here is the stacktrace for the error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: calegari.murilo.agendaescolar, PID: 6486
    android.content.res.Resources$NotFoundException: Resource ID #0xff00ff00
        at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:216)
        at android.content.res.Resources.getColor(Resources.java:964)
        at android.content.Context.getColor(Context.java:588)
        at androidx.core.content.ContextCompat.getColor(ContextCompat.java:514)
        at com.mancj.slimchart.SlimChart.setTextColor(SlimChart.java:251)
        at calegari.murilo.agendaescolar.gradehelper.SubjectGradeLineAdapter$override.onBindViewHolder(SubjectGradeLineAdapter.java:89)
        at calegari.murilo.agendaescolar.gradehelper.SubjectGradeLineAdapter$override.access$dispatch(Unknown Source:124)
        at calegari.murilo.agendaescolar.gradehelper.SubjectGradeLineAdapter.onBindViewHolder(Unknown Source:29)
        at calegari.murilo.agendaescolar.gradehelper.SubjectGradeLineAdapter.onBindViewHolder(SubjectGradeLineAdapter.java:20)
        at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781)
        at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4194)
        at android.view.View.layout(View.java:20836)
        at android.view.ViewGroup.layout(ViewGroup.java:6401)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:20836)
        at android.view.ViewGroup.layout(ViewGroup.java:6401)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:20836)
        at android.view.ViewGroup.layout(ViewGroup.java:6401)
        at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1961)
        at android.view.View.layout(View.java:20836)
        at android.view.ViewGroup.layout(ViewGroup.java:6401)
        at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:148)
        at com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:41)
        at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1633)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:888)
        at android.view.View.layout(View.java:20836)
        at android.view.ViewGroup.layout(ViewGroup.java:6401)
        at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:1231)
        at android.view.View.layout(View.java:20836)
        at android.view.ViewGroup.layout(ViewGroup.java:6401)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:20836)
        at android.view.ViewGroup.layout(ViewGroup.java:6401)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
E/AndroidRuntime:     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
        at android.view.View.layout(View.java:20836)
        at android.view.ViewGroup.layout(ViewGroup.java:6401)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:20836)
        at android.view.ViewGroup.layout(ViewGroup.java:6401)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
        at android.view.View.layout(View.java:20836)
        at android.view.ViewGroup.layout(ViewGroup.java:6401)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at com.android.internal.policy.DecorView.onLayout(DecorView.java:944)
        at android.view.View.layout(View.java:20836)
        at android.view.ViewGroup.layout(ViewGroup.java:6401)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2948)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2635)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1779)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7810)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
        at android.view.Choreographer.doCallbacks(Choreographer.java:723)
        at android.view.Choreographer.doFrame(Choreographer.java:658)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Feature Request: Automatically Sort and Normalize Stat Numbers

Wow, this library is amazing. I love the logo!
There is a slight problem with using this library. The user is required to calculate and normalize values before passing them to the library. Instead the logic should be internalized in the library.

The library uses 100 as the value for a full circle. For the chart to display correctly, the user is required to set their maximum value as 100 and calculate the relationship of the other stat numbers from there. Also, the library does not sort the numbers from highest to lowest so the user is required to sort their stats first. All this logic is common to every project that uses this library so it should be internalized.

I am guessing that you have this logic created so I am creating this issue to bring it to your attention. If not, I can write the logic and make a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.