How to use AsyncTask with AnyChart

0

I'm trying to make a dashboard by using the AnyChart api to create the graphics, however this error is appearing

  

Skipped 59 frames! The application may be doing a lot of work on its main thread.

I saw in the GOOGLE documentation that there is AsyncTask, I tried to use it the way I saw it in a post, but this error is returned:

  

The WebView method was called on thread 'AsyncTask # 1'. All WebView methods should be called on the same thread.

This is my class for Async:

public class AsyncTaskHelper extends AsyncTask< Void, Void, Void > {

public interface ExecuteAsyncTask { void execute(); }
private ExecuteAsyncTask executeAsyncTask;

public AsyncTaskHelper(ExecuteAsyncTask executeAsyncTask)
{
    this.executeAsyncTask = executeAsyncTask;
}

@Override
protected void onPreExecute()
{
    super.onPreExecute();
}

@Override
protected Void doInBackground(Void... params)
{

    if(executeAsyncTask != null)
        executeAsyncTask.execute();

    return null;
}

@Override
protected void onPostExecute(Void aVoid)
{
    super.onPostExecute(aVoid);
}

}

This is my Fragment:

public class GraphicsFragment extends Fragment {
private AnyChartView bar_doughnut1;
private AnyChartView bar_doughnut2;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_graphics, container, false);
    bar_doughnut1 = (AnyChartView) view.findViewById(R.id.bar_doughnut1);
    bar_doughnut2 = (AnyChartView) view.findViewById(R.id.bar_doughnut2);

    AsyncTaskManeger.ExecuteAsyncTask acao = new AsyncTaskManeger.ExecuteAsyncTask()
    {
        @Override
        public void execute()
        {
            init();
        }
    };

    return view;
}

public void init(){

    Pie pie = AnyChart.pie();

    List<DataEntry> data = new ArrayList<>();
    data.add(new ValueDataEntry("John", 10000));
    data.add(new ValueDataEntry("Jake", 12000));
    data.add(new ValueDataEntry("Peter", 18000));

    pie.innerRadius("60%");
    pie.data(data);
    bar_doughnut1.setChart(pie);
    bar_doughnut2.setChart(pie);

}}

And here's the layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
        <RelativeLayout
            android:id="@+id/relTopGraphics"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/grad"
            android:paddingBottom="20dp">

            <RelativeLayout
                android:id="@+id/imgUser"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:paddingBottom="8dp"
                android:layout_marginStart="25dp"
                android:layout_marginEnd="25dp"
                android:layout_centerVertical="true"
                android:layout_marginTop="25dp">
                <RelativeLayout
                    android:id="@+id/relPhotoClassify"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true"
                    android:layout_marginTop="25dp">

                    <ImageView
                        android:id="@+id/imgClassify"
                        android:layout_width="25dp"
                        android:layout_height="25dp"
                        android:layout_marginTop="10dp"
                        android:layout_centerHorizontal="true"
                        app:srcCompat="@drawable/ic_leaves" />

                    <de.hdodenhof.circleimageview.CircleImageView
                        android:id="@+id/imgPerfil"
                        android:layout_width="60dp"
                        android:layout_height="60dp"
                        android:layout_marginTop="7dp"
                        android:layout_marginBottom="10dp"
                        android:layout_below="@+id/imgClassify"
                        android:background="@drawable/circle"
                        android:padding="3dp"
                        android:src="@drawable/ic_user" />

                </RelativeLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="20dp"
                    android:layout_marginBottom="22dp"
                    android:layout_marginTop="70dp"
                    android:textColor="@color/white"
                    android:textStyle="bold"
                    android:layout_toRightOf="@id/relPhotoClassify"
                    android:text="Cachoeira Paulista"
                    android:textSize="25sp" />



            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="10dp">

                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:padding="6dp"
                    android:layout_alignParentLeft="true"
                    android:id="@+id/imgBack"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/ic_back" />

                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:padding="6dp"
                    android:layout_alignParentRight="true"
                    android:id="@+id/imgOk"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/ic_checked" />

            </RelativeLayout>

            <Button
                android:id="@+id/imgSettings"
                android:layout_width="60dp"
                android:layout_height="30dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentBottom="true"
                android:layout_marginEnd="38dp"

                android:adjustViewBounds="true"
                android:background="@drawable/ic_button_post"
                android:scaleType="centerInside"
                android:text="Fotos" />

        </RelativeLayout>

    <LinearLayout
        android:id="@+id/linlay1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relTopGraphics"
        android:orientation="horizontal"
        android:padding="10dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@color/white"
            android:gravity="center"
            android:paddingTop="5dp"
            android:paddingBottom="5dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:orientation="vertical">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="sans-serif-light"
                    android:text="Publicações"
                    android:id="@+id/seila"
                    android:textColor="@color/grey"
                    android:textStyle="bold"
                    android:textSize="12sp" />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="sans-serif-light"
                    android:text="872"
                    android:textStyle="bold"
                    android:textColor="@color/darkGrey"
                    android:textSize="21sp" />

            </LinearLayout>

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@color/white"
            android:gravity="center"
            android:paddingTop="5dp"
            android:paddingBottom="5dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/tvsolved"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="sans-serif-light"
                    android:text="Resolvidas"
                    android:textStyle="bold"
                    android:textColor="@color/grey"
                    android:textSize="12sp" />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="sans-serif-light"
                    android:text="240"
                    android:textStyle="bold"
                    android:textColor="@color/darkGrey"
                    android:textSize="21sp" />


            </LinearLayout>

        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@color/white"
            android:gravity="center"
            android:paddingTop="5dp"
            android:paddingBottom="5dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:orientation="vertical">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="sans-serif-light"
                    android:text="Publicações"
                    android:id="@+id/tvposts"
                    android:textStyle="bold"
                    android:textColor="@color/grey"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="sans-serif-light"
                    android:text="872"
                    android:textStyle="bold"
                    android:textColor="@color/darkGrey"
                    android:textSize="21sp" />

            </LinearLayout>

        </RelativeLayout>

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/linlay1"
        android:id="@+id/relBarChart"
        android:padding="10dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:text="Publicações"
            android:layout_marginStart="10dp"
            android:id="@+id/tv_bar_chart"
            android:textColor="@color/grey"
            android:textStyle="bold"
            android:textSize="12sp"
            android:layout_marginBottom="10dp"/>



    </RelativeLayout>

    <LinearLayout
        android:id="@+id/linlay2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relBarChart"
        android:orientation="horizontal"
        android:padding="10dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="10dp"
            android:layout_marginEnd="5dp"
            android:background="@color/white">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="sans-serif-light"
                android:text="Publicações"
                android:id="@+id/tv_bar_doughnut1"
                android:textColor="@color/grey"
                android:textStyle="bold"
                android:textSize="12sp"
                android:layout_marginBottom="10dp"/>

            <com.anychart.AnyChartView
                android:id="@+id/bar_doughnut1"
                android:layout_below="@+id/tv_bar_doughnut1"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_centerHorizontal="true"

                />

        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="10dp"
            android:layout_marginEnd="5dp"
            android:layout_marginStart="5dp"
            android:background="@color/white">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="sans-serif-light"
                android:text="Publicações"
                android:id="@+id/tv_bar_doughnut2"
                android:textColor="@color/grey"
                android:textStyle="bold"
                android:textSize="12sp"
                android:layout_marginBottom="10dp"/>

            <com.anychart.AnyChartView
                android:id="@+id/bar_doughnut2"
                android:layout_below="@+id/tv_bar_doughnut2"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_centerHorizontal="true"
                />

        </RelativeLayout>
    </LinearLayout>



    </RelativeLayout>
    </ScrollView>

</RelativeLayout>

NOTE: I left only those two charts to make it easier since running with the two will probably run with all the others.

    
asked by anonymous 01.11.2018 / 21:39

0 answers