// Path: app/src/main/java/com/luciofm/ifican/app/util/Utils.java
// public class Utils {
// 
//     private static final int ANIM_DURATION = 800;
// 
//     private Utils() {
//     }
// 
//     public static void startGif(GifImageView view) {
//         GifDrawable drawable = (GifDrawable) view.getDrawable();
//         if (!drawable.isPlaying()) {
//             drawable.reset();
//             drawable.start();
//         }
//     }
// 
//     public static void stopGif(GifImageView view) {
//         GifDrawable drawable = (GifDrawable) view.getDrawable();
//         if (drawable.isPlaying())
//             drawable.stop();
//     }
// 
//     public static void dispatchTouch(View view) {
//         dispatchTouch(view, 200);
//     }
// 
//     public static void dispatchTouch(final View view, final long duration) {
//         final long downTime = SystemClock.uptimeMillis();
//         final long eventTime = SystemClock.uptimeMillis();
//         final float x = 0.0f;
//         final float y = 0.0f;
//         // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
//         final int metaState = 0;
//         MotionEvent motionEvent = MotionEvent.obtain(downTime,
//                                                      eventTime,
//                                                      MotionEvent.ACTION_DOWN,
//                                                      x,
//                                                      y,
//                                                      metaState);
// 
//         // Dispatch touch event to view
//         view.dispatchTouchEvent(motionEvent);
// 
//         new Handler().postDelayed(new Runnable() {
//             @Override
//             public void run() {
//                 MotionEvent motionEvent = MotionEvent.obtain(downTime + duration,
//                                                              eventTime + duration,
//                                                              MotionEvent.ACTION_UP,
//                                                              x,
//                                                              y,
//                                                              metaState);
//                 view.dispatchTouchEvent(motionEvent);
//             }
//         }, duration);
//     }
// 
//     public static long calcDuration(int position) {
//         int pos = position;
//         if (pos >= 4)
//             pos -= 4;
//         switch (pos) {
//             case 1:
//                 return (long) (ANIM_DURATION + (ANIM_DURATION * 0.2f));
//             case 2:
//                 return (long) (ANIM_DURATION + (ANIM_DURATION * 0.3f));
//             case 3:
//                 return (long) (ANIM_DURATION + (ANIM_DURATION * 0.4f));
//             default:
//                 return ANIM_DURATION;
//         }
//     }
// }


import android.os.Bundle;
import android.app.Fragment;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.luciofm.ifican.app.BaseFragment;
import com.luciofm.ifican.app.R;
import com.luciofm.ifican.app.util.IOUtils;
import com.luciofm.ifican.app.util.Utils;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
package com.luciofm.ifican.app.ui;






/**
 * A simple {@link Fragment} subclass.
 *
 */
public class TouchFeedbackCodeFragment extends BaseFragment {

    @InjectView(R.id.container2)
    View container;
    @InjectView(R.id.text2)
    TextView text2;
    @InjectView(R.id.text3)
    TextView text3;
    @InjectView(R.id.text4)
    TextView text4;

    private int currentStep;

    public TouchFeedbackCodeFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.inject(this, v);

        text4.setText(Html.fromHtml(IOUtils.readFile(getActivity(), "source/touch_anim.xml.html")));
        currentStep = 1;
        return v;
    }

    @Override
    public void onNextPressed() {
        switch (++currentStep) {
            case 2:
                container.setVisibility(View.VISIBLE);
                break;
            case 3:
// Path: app/src/main/java/com/luciofm/ifican/app/util/Utils.java
// public class Utils {
// 
//     private static final int ANIM_DURATION = 800;
// 
//     private Utils() {
//     }
// 
//     public static void startGif(GifImageView view) {
//         GifDrawable drawable = (GifDrawable) view.getDrawable();
//         if (!drawable.isPlaying()) {
//             drawable.reset();
//             drawable.start();
//         }
//     }
// 
//     public static void stopGif(GifImageView view) {
//         GifDrawable drawable = (GifDrawable) view.getDrawable();
//         if (drawable.isPlaying())
//             drawable.stop();
//     }
// 
//     public static void dispatchTouch(View view) {
//         dispatchTouch(view, 200);
//     }
// 
//     public static void dispatchTouch(final View view, final long duration) {
//         final long downTime = SystemClock.uptimeMillis();
//         final long eventTime = SystemClock.uptimeMillis();
//         final float x = 0.0f;
//         final float y = 0.0f;
//         // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
//         final int metaState = 0;
//         MotionEvent motionEvent = MotionEvent.obtain(downTime,
//                                                      eventTime,
//                                                      MotionEvent.ACTION_DOWN,
//                                                      x,
//                                                      y,
//                                                      metaState);
// 
//         // Dispatch touch event to view
//         view.dispatchTouchEvent(motionEvent);
// 
//         new Handler().postDelayed(new Runnable() {
//             @Override
//             public void run() {
//                 MotionEvent motionEvent = MotionEvent.obtain(downTime + duration,
//                                                              eventTime + duration,
//                                                              MotionEvent.ACTION_UP,
//                                                              x,
//                                                              y,
//                                                              metaState);
//                 view.dispatchTouchEvent(motionEvent);
//             }
//         }, duration);
//     }
// 
//     public static long calcDuration(int position) {
//         int pos = position;
//         if (pos >= 4)
//             pos -= 4;
//         switch (pos) {
//             case 1:
//                 return (long) (ANIM_DURATION + (ANIM_DURATION * 0.2f));
//             case 2:
//                 return (long) (ANIM_DURATION + (ANIM_DURATION * 0.3f));
//             case 3:
//                 return (long) (ANIM_DURATION + (ANIM_DURATION * 0.4f));
//             default:
//                 return ANIM_DURATION;
//         }
//     }
// }


// Path: app/src/main/java/com/luciofm/ifican/app/ui/TouchFeedbackCodeFragment.java
import android.os.Bundle;
import android.app.Fragment;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.luciofm.ifican.app.BaseFragment;
import com.luciofm.ifican.app.R;
import com.luciofm.ifican.app.util.IOUtils;
import com.luciofm.ifican.app.util.Utils;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

package com.luciofm.ifican.app.ui;






/**
 * A simple {@link Fragment} subclass.
 *
 */
public class TouchFeedbackCodeFragment extends BaseFragment {

    @InjectView(R.id.container2)
    View container;
    @InjectView(R.id.text2)
    TextView text2;
    @InjectView(R.id.text3)
    TextView text3;
    @InjectView(R.id.text4)
    TextView text4;

    private int currentStep;

    public TouchFeedbackCodeFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.inject(this, v);

        text4.setText(Html.fromHtml(IOUtils.readFile(getActivity(), "source/touch_anim.xml.html")));
        currentStep = 1;
        return v;
    }

    @Override
    public void onNextPressed() {
        switch (++currentStep) {
            case 2:
                container.setVisibility(View.VISIBLE);
                break;
            case 3:
                Utils.dispatchTouch(text2, 300);