package com.sphere.io.glass;

import com.github.barcodeeye.scan.CaptureActivity;
import com.github.barcodeeye.scan.api.CardPresenter;
import com.google.android.glass.media.Sounds;
import com.google.android.glass.widget.CardBuilder;
import com.google.android.glass.widget.CardScrollAdapter;
import com.google.android.glass.widget.CardScrollView;
import com.google.android.glass.widget.Slider;
import com.sphere.io.glass.activities.LoadingActivity;
import com.sphere.io.glass.activities.ProductActivity;
import com.sphere.io.glass.api.SphereApiCaller;
import com.sphere.io.glass.card.CardAdapter;
import com.sphere.io.glass.model.Session;
import com.sphere.io.glass.utils.Constants;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

import de.greenrobot.event.EventBus;

public class SphereMainActivity extends Activity {
    private static final int NAVIGATION_QRCODE = 0;
    private CardScrollView mCardScroller;
    private Slider.Determinate mDeterminate;
    private Slider mSlider;
    private static final int MILLIS_DELAY = 3000;
    private static final int MAX_VALUE = 500;

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        buildView();
        SphereApiCaller.getInstance(this).getSession();
    }

    private void buildView() {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        mCardScroller = new CardScrollView(this);
        mCardScroller.setAdapter(new CardAdapter(createCards()));
        mSlider = Slider.from(mCardScroller);
        setContentView(mCardScroller);
    }

    @Override
    protected void onResume() {
        super.onResume();
        EventBus.getDefault().register(this);
        mCardScroller.activate();
        mDeterminate = mSlider.startDeterminate(MAX_VALUE, 0);
        ObjectAnimator animator = ObjectAnimator.ofFloat(mDeterminate,
                "position", 0, MAX_VALUE);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                startActivity(CaptureActivity.newIntent(SphereMainActivity.this));
                finish();
            }
        });
        animator.setDuration(MILLIS_DELAY).start();
    }

    @Override
    protected void onPause() {
        super.onPause();
        EventBus.getDefault().unregister(this);
    }

    public void onEvent(Session session){
        Log.e("YEYEYEYEYE",session.getToken());
    }

    private List<CardBuilder> createCards() {
        ArrayList<CardBuilder> cards = new ArrayList<CardBuilder>();
        cards.add(NAVIGATION_QRCODE, new CardBuilder(this, CardBuilder.Layout.MENU)
                .setText(R.string.app_title).setIcon(R.drawable.icon_logo));
        return cards;
    }
}

@@ -673,16 +673,74 @@
 nstants;
+%0Aimport com.sphere.io.glass.utils.SpherePreferenceManager;
 %0A%0Aimport
@@ -1529,16 +1529,30 @@
 e Slider
+.Indeterminate
  mSlider
@@ -1648,16 +1648,84 @@
 E = 500;
+%0A    private static String TAG = SphereMainActivity.class.getName();
 %0A%0A    @O
@@ -2122,54 +2122,8 @@
 ));%0A
-        mSlider = Slider.from(mCardScroller);%0A
     
@@ -2329,728 +2329,504 @@
    m
-Determinate
+Slider
  = 
-m
 Slider.
-startDeterminate(MAX_VALUE, 0);%0A        ObjectAnimator animator = ObjectAnimator.ofFloat(mDeterminate,%0A                %22position%22, 0, MAX_VALUE);%0A        animator.addListener(new AnimatorListenerAdapter() %7B%0A            @Override%0A            public void onAnimationEnd(Animator animation) %7B%0A                startActivity(CaptureActivity.newIntent(SphereMainActivity.this));%0A                finish();%0A            %7D%0A        %7D);%0A        animator.setDuration(MILLIS_DELAY).start();%0A    %7D%0A%0A    @Override%0A    protected void onPause() %7B%0A        super.onPause();%0A        EventBus.getDefault().unregister(this);%0A    %7D%0A%0A    public void onEvent(Session session)%7B%0A        Log.e(%22YEYEYEYEYE%22,session.getToken());
+from(mCardScroller).startIndeterminate();%0A    %7D%0A%0A    @Override%0A    protected void onPause() %7B%0A        super.onPause();%0A        EventBus.getDefault().unregister(this);%0A    %7D%0A%0A    public void onEvent(Session session)%7B%0A        SpherePreferenceManager.getInstance(this).setSession(session);%0A        Log.e(TAG, %22SESSION WITH TOKEN %22 + session.getToken() + %22 STORED%22);%0A        mSlider.hide();%0A        startActivity(CaptureActivity.newIntent(SphereMainActivity.this));%0A        finish();%0A
 %0A   

MODIFY sphere activity to handle login properly