package com.tonyjhuang.whereyou;

import android.content.res.TypedArray;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.tonyjhuang.whereyou.helpers.ColorPicker;
import com.tonyjhuang.whereyou.helpers.WhereYouActivity;

import java.util.Random;

import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by tony on 5/3/15.
 */
public class AboutActivity extends WhereYouActivity {
    @InjectView(R.id.container)
    LinearLayout container;
    @InjectView(R.id.emoji)
    ImageView emojiView;

    private int currentEmojiResource;
    private TypedArray emojiResources;
    private Random random = new Random();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);

        resetState();
    }

    private int getRandomEmoji() {
        // for some reason, emojiResources.getIndexCount() always returns 0...
        int newEmojiResource = emojiResources.getResourceId(random.nextInt(18), 0);
        if(newEmojiResource == currentEmojiResource)
            return getRandomEmoji();
        else
            return newEmojiResource;
    }

    private void resetState() {
        int[] colors = ColorPicker.getRandomColors(container.getChildCount() + 1);
        for (int i = 0; i < container.getChildCount(); i++) {
            container.getChildAt(i).setBackgroundColor(colors[i]);
        }

        container.setBackgroundColor(colors[container.getChildCount()]);

        emojiResources = getResources().obtainTypedArray(R.array.emojis);
        currentEmojiResource = getRandomEmoji();
        emojiView.setImageResource(currentEmojiResource);
    }

    @OnClick(R.id.j)
    public void onJClicked(View view) {
        Log.d("About", "hey j");
        YoYo.with(Techniques.Pulse)
                .duration(450)
                .playOn(view);
        resetState();
    }

    @Override
    public void finish() {
        emojiResources.recycle();
        super.finish();
        overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_right);
    }
}

@@ -92,16 +92,43 @@
 Bundle;%0A
+import android.os.Handler;%0A
 import a
@@ -144,16 +144,16 @@
 il.Log;%0A
-
 import a
@@ -238,16 +238,48 @@
 rLayout;
+%0Aimport android.widget.TextView;
 %0A%0Aimport
@@ -782,16 +782,60 @@
 ojiView;
+%0A    @InjectView(R.id.j)%0A    TextView jView;
 %0A%0A    pr
@@ -946,16 +946,61 @@
 andom();
+%0A    private Handler handler = new Handler();
 %0A%0A    @O
@@ -1172,32 +1172,286 @@
   resetState();%0A
+        handler.postDelayed(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                YoYo.with(Techniques.Pulse)%0A                        .duration(450)%0A                        .playOn(jView);%0A            %7D%0A        %7D, 3000);%0A
     %7D%0A%0A    priva
@@ -2320,24 +2320,24 @@
 ick(R.id.j)%0A
-
     public v
@@ -2360,24 +2360,74 @@
 iew view) %7B%0A
+        handler.removeCallbacksAndMessages(null);%0A
         Log.

add subtle pulse to J in about