package de.tud.ess;

import java.util.HashMap;
import java.util.LinkedHashMap;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.android.glass.widget.CardScrollAdapter;
import com.google.android.glass.widget.CardScrollView;
import com.google.glass.widget.RobotoTypefaces;

public class ScrollView extends Activity {

  public class MyScrollAdapter extends CardScrollAdapter {
    
    protected HashMap<Object, String> mMap;

    protected HashMap<Object, String> getMap() {
      if (mMap == null) {
        mMap = new LinkedHashMap<Object, String>();
        mMap.put(0, "Hello");
        mMap.put(1, "World!");
      }
      return mMap;
    }
    
    @Override
    public int findIdPosition(Object key) {
      return (Integer) key;
    }

    @Override
    public int findItemPosition(Object key) {
      return (Integer) key;
    }

    @Override
    public int getCount() {
      return getMap().size();
    }

    @Override
    public Object getItem(int num) {
      return getMap().get(num);
    }

    @Override
    public View getView(int num, View v, ViewGroup parent) {      
      if (v == null) {
        TextView tv = new TextView(getApplicationContext());
        tv.setText(getMap().get(num));
        
        Typeface roboto = RobotoTypefaces.getTypeface(getApplicationContext(), RobotoTypefaces.WEIGHT_THIN);
        tv.setTypeface(roboto);
        tv.setText(getMap().get(num));
        tv.setGravity(Gravity.CENTER);
        tv.setTextSize(50);
        
        v = tv;
      }
      
      return v;
    }
  }

  private CardScrollView mCardScrollView;
  private MyScrollAdapter mAdapter;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    setContentView(R.layout.main);
    mCardScrollView = (CardScrollView) findViewById(R.id.scrollview);
    
    mAdapter = new MyScrollAdapter(); 
    mCardScrollView.setAdapter(mAdapter);
    mCardScrollView.activate();
  }
}

@@ -14,16 +14,133 @@
 d.ess;%0A%0A
+import java.lang.reflect.Field;%0Aimport java.lang.reflect.InvocationTargetException;%0Aimport java.lang.reflect.Method;%0A
 import j
@@ -279,16 +279,68 @@
 Bundle;%0A
+import android.os.Handler;%0Aimport android.util.Log;%0A
 import a
@@ -1952,16 +1952,45 @@
 Adapter;
+%0A  protected Method mAnimate;
 %0A%0A  @Ove
@@ -2322,10 +2322,725 @@
 ();%0A  %7D%0A
+  %0A  @Override%0A  protected void onResume() %7B%0A    super.onResume();%0A    %0A    /* This is an example on how to do an animation to another card.%0A     * API is not published yet, so let's get it via reflection. */    %0A    for(Method m : mCardScrollView.getClass().getDeclaredMethods()) %7B%0A      if (m.getName().equals(%22animateToSelection%22))%0A        mAnimate = m;%0A    %7D%0A    %0A    Handler h = new Handler();%0A    h.postDelayed(new Runnable() %7B%0A      @Override%0A      public void run() %7B%0A        Class params%5B%5D = new Class%5B%5D %7B Integer.class, Integer.class %7D;%0A        try %7B%0A          mAnimate.invoke(mCardScrollView, 1,1);%0A        %7D catch (Exception e) %7B%0A          Log.e(%22meh%22, e.toString());%0A        %7D%0A      %7D%0A    %7D, 300);%0A  %7D%0A
 %7D%0A

change card scroll to include animation example