package io.akessler.elixircounter;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

/**
 * Created by Andy on 9/14/2017.
 */
public class OverlayService extends Service {

    WindowManager windowManager;

    Button[] buttons;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

        buttons = new Button[11];
        for(int i = 0; i < buttons.length; i++) {
            int counterValue = i != 0 ? -i : 1; // FIXME There might be a cleaner way...
            buttons[i] = new CounterButton(this, counterValue);
            WindowManager.LayoutParams buttonParams = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, // FIXME Acts up on certain API versions
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                    PixelFormat.TRANSLUCENT
            );
            buttonParams.gravity = Gravity.LEFT | Gravity.TOP;
            // FIXME Change these values to be dynamic, based on dimensions of screen
            buttonParams.x = 25;
            buttonParams.y = (buttons.length - i) * 150;
            windowManager.addView(buttons[i], buttonParams);
        }

        ElixirStore.createInstance(this, windowManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        for(int i=0; i<buttons.length; i++) {
            Button b = buttons[i];
            if(buttons[i] != null) {
                windowManager.removeView(b);
                b = null;
            }
        }
    }
}
@@ -157,16 +157,50 @@
 Format;%0A
+import android.os.CountDownTimer;%0A
 import a
@@ -534,16 +534,95 @@
 ttons;%0A%0A
+    CountDownTimer regularElixirTimer;%0A%0A    CountDownTimer doubleElixirTimer;%0A%0A
     @Nul
@@ -1965,85 +1965,925 @@
 r);%0A
-    %7D%0A%0A    @Override%0A    public void onDestroy() %7B%0A        super.onDestroy();
+%0A        doubleElixirTimer = new CountDownTimer(120000, 1400) %7B%0A            public void onTick(long millisUntilFinished) %7B%0A                ElixirStore.add(1);%0A            %7D%0A%0A            public void onFinish() %7B%0A                System.out.println(%222x elixir time complete.%22);%0A            %7D%0A        %7D;%0A%0A        regularElixirTimer = new CountDownTimer(120000, 2800) %7B%0A            public void onTick(long millisUntilFinished) %7B%0A                ElixirStore.add(1);%0A            %7D%0A%0A            public void onFinish() %7B%0A                System.out.println(%221x elixir time complete.%22);%0A                ElixirStore.add(1);%0A                doubleElixirTimer.start();%0A            %7D%0A        %7D;%0A%0A        regularElixirTimer.start();%0A    %7D%0A%0A    @Override%0A    public void onDestroy() %7B%0A        super.onDestroy();%0A        regularElixirTimer.cancel();%0A        doubleElixirTimer.cancel();%0A        // FIXME Remove TextView from ElixirStore
 %0A   

Add CountDownTimer for 1x and 2x elixir periods