package com.apps4glass.glass.euskalexample;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Toast;

import com.apps4glass.glass.euskalexample.R;
import com.google.android.glass.app.Card;
import com.google.android.glass.widget.CardScrollAdapter;
import com.google.android.glass.widget.CardScrollView;

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

public class MainActivity extends Activity {

    private List<Card> cards;
    private CardScrollView cardScrollView;
    private List<ExampleCase> examples;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        cards = new ArrayList<Card>();
        examples = new ArrayList<ExampleCase>();

        populateExamples();

        for (ExampleCase example : examples) cards.add(new Card(this).setText(example.getText()));

        cardScrollView = new CardScrollView(this);
        cardScrollView.setAdapter(new SimpleCardScrollAdapter());
        cardScrollView.activate();

        cardScrollView.setOnItemClickListener( new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int selected, long l) {
                examples.get(selected).onSelected();
            }
        });
        setContentView(cardScrollView);
    }

    private void populateExamples() {

        examples.add(new ExampleCase("Test Toast") {
            @Override
            public void onSelected() {
                Toast.makeText(getBaseContext(), getText(), Toast.LENGTH_SHORT).show();
            }
        });

    }

    private class SimpleCardScrollAdapter extends CardScrollAdapter {

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

        @Override
        public Object getItem(int i) { return cards.get(i); }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) { return cards.get(i).getView(); }

        @Override
        public int getPosition(Object o) { return cards.indexOf(o); }

    }

    private abstract class ExampleCase {
        private String text;

        public ExampleCase(String text) { this.text = text; }

        public String getText() { return text; }

        public abstract void onSelected();
    }
}

@@ -117,17 +117,189 @@
 oid.
-os.Bundle
+graphics.Bitmap;%0Aimport android.graphics.BitmapFactory;%0Aimport android.os.Bundle;%0Aimport android.os.Debug;%0Aimport android.provider.MediaStore;%0Aimport android.speech.RecognizerIntent
 ;%0Aim
@@ -561,16 +561,69 @@
 p.Card;%0A
+import com.google.android.glass.media.CameraManager;%0A
 import c
@@ -728,16 +728,37 @@
 lView;%0A%0A
+import java.io.File;%0A
 import j
@@ -1701,24 +1701,32 @@
 .onSelected(
+selected
 );%0A         
@@ -1938,16 +1938,28 @@
 elected(
+int selected
 ) %7B%0A    
@@ -2065,24 +2065,1931 @@
        %7D);%0A%0A
+        examples.add(new ExampleCase(%22Test Camera%22) %7B%0A%0A            @Override%0A            public void onSelected(int selected) %7B%0A                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);%0A                startActivityForResult(intent, selected);%0A            %7D%0A%0A            @Override%0A            public void onActivityResult(int selected, Intent data) %7B%0A                String path = data.getStringExtra(CameraManager.EXTRA_PICTURE_FILE_PATH);%0A                File imageFile = new File(path);%0A                if (imageFile.exists()) %7B%0A                    Bitmap bmp = BitmapFactory.decodeFile(path);%0A                    cards.get(selected)%0A                            .setImageLayout(Card.ImageLayout.LEFT)%0A                            .addImage(bmp);%0A                %7D%0A            %7D%0A        %7D);%0A%0A        examples.add(new ExampleCase(%22Test Voice%22) %7B%0A            @Override%0A            public void onSelected(int selected) %7B%0A                Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);%0A                startActivityForResult(intent, selected);%0A            %7D%0A%0A            @Override%0A            public void onActivityResult(int selected, Intent data) %7B%0A                List%3CString%3E results = data.getStringArrayListExtra(%0A                        RecognizerIntent.EXTRA_RESULTS);%0A                String spokenText = results.get(0);%0A                Card card = cards.get(selected);%0A                card.setText(card.getText() + %22%5Cn %22 + spokenText);%0A                cardScrollView.getAdapter().notifyDataSetChanged();%0A%0A            %7D%0A        %7D);%0A%0A    %7D%0A%0A    @Override%0A    protected void onActivityResult(int requestCode, int resultCode, Intent data) %7B%0A        System.out.print(%22TEST%22 + requestCode);%0A        if (resultCode == RESULT_OK)%0A            examples.get(requestCode).onActivityResult(requestCode, data);%0A        super.onActivityResult(requestCode, resultCode, data);%0A
     %7D%0A%0A    p
@@ -4650,18 +4650,105 @@
 elected(
-);
+int selected);%0A%0A        public void onActivityResult(int code, Intent data) %7B%0A%0A        %7D%0A
 %0A    %7D%0A%7D

Add camera and voice examples