// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/util/TextViewUtils.java
// public class TextViewUtils {
//     private static final String TAG = TextViewUtils.class.getSimpleName();
//     private static TextViewUtils instance;
// 
//     static {
//         instance = new TextViewUtils();
//     }
// 
//     public static TextViewUtils getInstance() {
//         return instance;
//     }
// 
//     public Thread printIncrement(TextView textView, long endNumber, long millis) {
//         return printIncrement(textView, 0, endNumber, millis);
//     }
// 
//     public Thread printIncrement(TextView textView, long startNumber, long endNumber, long millis) {
//         return printIncrement(textView, "%d", startNumber, endNumber, millis);
//     }
// 
//     public Thread printIncrement(TextView textView, String format, long endNumber, long millis) {
//         return printIncrement(textView, Locale.getDefault(), format, endNumber, millis);
// 
//     }
// 
//     public Thread printIncrement(TextView textView, String format, long startNumber, long endNumber, long millis) {
//         return printIncrement(textView, Locale.getDefault(), format, startNumber, endNumber, millis);
// 
//     }
// 
//     public Thread printIncrement(TextView textView, Locale locale, String format, long endNumber, long millis) {
//         return printIncrement(textView, locale, format, 0, endNumber, millis);
// 
//     }
// 
//     public Thread printIncrement(final TextView textView, final Locale locale, final String format, final long startNumber, final long endNumber, final long millis) {
//         final Thread thread = printIncrementPostDelayed(textView, locale, format, startNumber, endNumber, millis);
//         textView.post(new Runnable() {
//             @Override
//             public void run() {
//                 thread.start();
//             }
//         });
// 
//         return thread;
// 
//     }
// 
// 
//     private Thread printIncrementPostDelayed(final TextView textView, final Locale locale,
//                                              final String format, final long startNumber,
//                                              final long endNumber, final long millis) {
// 
//         return new Thread() {
//             @Override
//             public void run() {
//                 try {
//                     long start;
//                     long end;
// 
//                     if (startNumber > endNumber) {
//                         start = endNumber;
//                         end = startNumber;
//                     } else {
//                         start = startNumber;
//                         end = endNumber;
//                     }
//                     long counter = start;
//                     double delayDuration = (double) millis / (double) (end - start);
//                     long increment;
//                     if (delayDuration < 1) {
//                         increment = (long) Math.ceil(1f / delayDuration);
//                         delayDuration *= increment;
//                     } else
//                         increment = 1;
// 
//                     displayText(textView, locale, format,
//                             startNumber < endNumber ? counter : startNumber - (counter - start));
//                     while (counter < end) {
//                         sleep((long) delayDuration);
//                         counter += increment;
//                         counter = counter > end ? end : counter;
//                         displayText(textView, locale, format,
//                                 startNumber < endNumber ? counter : startNumber - (counter - start));
//                     }
//                 } catch (InterruptedException e) {
//                     e.printStackTrace();
//                 }
//             }
//         };
// 
// 
//     }
// 
//     private void displayText(final TextView textView, Locale locale, String format, long counter) {
// 
//         final String displayText = getString(locale, format, counter);
//         textView.post(new Runnable() {
//             @Override
//             public void run() {
//                 textView.setText(displayText);
//             }
//         });
//     }
// 
//     private String getString(Locale locale, String format, long counter) {
//         return String.format(
//                 locale, format, counter
//         );
//     }
// 
// 
// }


import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.app.infideap.stylishwidget.util.TextViewUtils;
package com.app.infideap.mystylishexample;




/**
 * A simple {@link Fragment} subclass.
 * Use the {@link WidgetFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class WidgetFragment extends Fragment {

    private TextView incrementTextView;
    private TextView decrementTextView;
    private Thread incrementThread;
    private Thread decrementTread;

    public WidgetFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @return A new instance of fragment WidgetFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static WidgetFragment newInstance() {
        return new WidgetFragment();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.layout_widget, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        incrementTextView = (TextView) view.findViewById(R.id.textView_increment);
        decrementTextView = (TextView) view.findViewById(R.id.textView_decrement);

        startCounter();

    }

    private void startCounter() {

        if (incrementThread != null) {
            incrementThread.interrupt();
        }
        if (decrementTread != null) {
            decrementTread.interrupt();
        }

// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/util/TextViewUtils.java
// public class TextViewUtils {
//     private static final String TAG = TextViewUtils.class.getSimpleName();
//     private static TextViewUtils instance;
// 
//     static {
//         instance = new TextViewUtils();
//     }
// 
//     public static TextViewUtils getInstance() {
//         return instance;
//     }
// 
//     public Thread printIncrement(TextView textView, long endNumber, long millis) {
//         return printIncrement(textView, 0, endNumber, millis);
//     }
// 
//     public Thread printIncrement(TextView textView, long startNumber, long endNumber, long millis) {
//         return printIncrement(textView, "%d", startNumber, endNumber, millis);
//     }
// 
//     public Thread printIncrement(TextView textView, String format, long endNumber, long millis) {
//         return printIncrement(textView, Locale.getDefault(), format, endNumber, millis);
// 
//     }
// 
//     public Thread printIncrement(TextView textView, String format, long startNumber, long endNumber, long millis) {
//         return printIncrement(textView, Locale.getDefault(), format, startNumber, endNumber, millis);
// 
//     }
// 
//     public Thread printIncrement(TextView textView, Locale locale, String format, long endNumber, long millis) {
//         return printIncrement(textView, locale, format, 0, endNumber, millis);
// 
//     }
// 
//     public Thread printIncrement(final TextView textView, final Locale locale, final String format, final long startNumber, final long endNumber, final long millis) {
//         final Thread thread = printIncrementPostDelayed(textView, locale, format, startNumber, endNumber, millis);
//         textView.post(new Runnable() {
//             @Override
//             public void run() {
//                 thread.start();
//             }
//         });
// 
//         return thread;
// 
//     }
// 
// 
//     private Thread printIncrementPostDelayed(final TextView textView, final Locale locale,
//                                              final String format, final long startNumber,
//                                              final long endNumber, final long millis) {
// 
//         return new Thread() {
//             @Override
//             public void run() {
//                 try {
//                     long start;
//                     long end;
// 
//                     if (startNumber > endNumber) {
//                         start = endNumber;
//                         end = startNumber;
//                     } else {
//                         start = startNumber;
//                         end = endNumber;
//                     }
//                     long counter = start;
//                     double delayDuration = (double) millis / (double) (end - start);
//                     long increment;
//                     if (delayDuration < 1) {
//                         increment = (long) Math.ceil(1f / delayDuration);
//                         delayDuration *= increment;
//                     } else
//                         increment = 1;
// 
//                     displayText(textView, locale, format,
//                             startNumber < endNumber ? counter : startNumber - (counter - start));
//                     while (counter < end) {
//                         sleep((long) delayDuration);
//                         counter += increment;
//                         counter = counter > end ? end : counter;
//                         displayText(textView, locale, format,
//                                 startNumber < endNumber ? counter : startNumber - (counter - start));
//                     }
//                 } catch (InterruptedException e) {
//                     e.printStackTrace();
//                 }
//             }
//         };
// 
// 
//     }
// 
//     private void displayText(final TextView textView, Locale locale, String format, long counter) {
// 
//         final String displayText = getString(locale, format, counter);
//         textView.post(new Runnable() {
//             @Override
//             public void run() {
//                 textView.setText(displayText);
//             }
//         });
//     }
// 
//     private String getString(Locale locale, String format, long counter) {
//         return String.format(
//                 locale, format, counter
//         );
//     }
// 
// 
// }


// Path: app/src/main/java/com/app/infideap/mystylishexample/WidgetFragment.java
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.app.infideap.stylishwidget.util.TextViewUtils;

package com.app.infideap.mystylishexample;




/**
 * A simple {@link Fragment} subclass.
 * Use the {@link WidgetFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class WidgetFragment extends Fragment {

    private TextView incrementTextView;
    private TextView decrementTextView;
    private Thread incrementThread;
    private Thread decrementTread;

    public WidgetFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @return A new instance of fragment WidgetFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static WidgetFragment newInstance() {
        return new WidgetFragment();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.layout_widget, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        incrementTextView = (TextView) view.findViewById(R.id.textView_increment);
        decrementTextView = (TextView) view.findViewById(R.id.textView_decrement);

        startCounter();

    }

    private void startCounter() {

        if (incrementThread != null) {
            incrementThread.interrupt();
        }
        if (decrementTread != null) {
            decrementTread.interrupt();
        }

        TextViewUtils utils = TextViewUtils.getInstance();