/**
 * Copyright (C) 2011 Jeremy Wall <jeremy@marzhillstudios.com>
 * All contents Licensed under the terms of the Apache License 2.0
 * http://www.apache.org/licenses/LICENSE-2.0.html
 */

package com.marzhillstudios.quizme;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.widget.Button;
import android.widget.ListView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.os.Bundle;

import com.marzhillstudios.quizme.adapter.CardListAdapter;
import com.marzhillstudios.quizme.data.CardDatabase;
import com.marzhillstudios.quizme.util.L;

/**
 * 
 * Activity for managing cards. This Activity will be responsible for
 * handling Card Creation/Editing/Deletion and Import/Export.
 * 
 * @author Jeremy Wall <jeremy@marzhillstudios.com>
 */
public class CardManagerActivity extends Activity {
    
    @SuppressWarnings("unused")
    private CardDatabase db;
    private CardListAdapter listAdapter;
    private ListView listView;

    public static final int DIALOG_NEW_CARD = 1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cardmanager);
        db = new CardDatabase(this);
        Button newCardBtn = (Button) findViewById(R.id.NewCardButton);
        listAdapter = new CardListAdapter(this, db);
        listView = (ListView) findViewById(R.id.CardManagerList);
        listView.setAdapter(listAdapter);

        OnClickListener newCardListener = new OnClickListener() {
            public void onClick(View v) {
                showDialog(DIALOG_NEW_CARD);
            }
        };

        newCardBtn.setOnClickListener(newCardListener);
    }

    protected Dialog onCreateDialog(int id) {
        Dialog dialog;
        switch(id) {
            case DIALOG_NEW_CARD:
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                LayoutInflater inflater =
                    (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
                ViewGroup layoutRoot =
                    (ViewGroup) findViewById(R.id.NewCardLayout);
                builder.setView(
                    inflater.inflate(R.layout.new_card_dialog, layoutRoot));
                dialog = builder.create();
                break;
            default:
                dialog = null;
        }
        return dialog;
    }

    public CardListAdapter getListAdapter() {
        return listAdapter;
    }

    public ListView getListView() {
        return listView;
    }

    public CardDatabase getDb() {
        return db;
    }
}

@@ -1976,32 +1976,229 @@
 W_CARD:%0A        
+        dialog = createNewCardDialog();%0A                break;%0A            default:%0A                dialog = null;%0A        %7D%0A        return dialog;%0A    %7D%0A%0A    public Dialog createNewCardDialog() %7B%0A
         AlertDia
@@ -2258,24 +2258,16 @@
         
-    
-    
 LayoutIn
@@ -2284,24 +2284,16 @@
 later =%0A
-        
         
@@ -2364,24 +2364,16 @@
         
- 
-       
 ViewGrou
@@ -2387,24 +2387,16 @@
 tRoot =%0A
-        
         
@@ -2457,237 +2457,1654 @@
     
-        builder.setView(%0A                    inflater.inflate(R.layout.new_card_dialog, layoutRoot));%0A                dialog = builder.create();%0A                break;%0A            default:%0A                dialog = null;%0A        %7D
+builder.setView(inflater.inflate(R.layout.new_card_dialog, layoutRoot));%0A        AlertDialog dialog = builder.create();%0A%0A        Button side1ImageBtn =%0A            (Button) dialog.findViewById(R.id.NewCardSide1ImageBtn);%0A%0A        OnClickListener side1ImageBtnListener = new OnClickListener() %7B%0A            public void onClick(View v) %7B%0A                // TODO(jwall): we need to start an activity to get an image.%0A            %7D%0A        %7D;%0A%0A        side1ImageBtn.setOnClickListener(side1ImageBtnListener);%0A%0A        Button side1TextBtn =%0A            (Button) dialog.findViewById(R.id.NewCardSide1TextBtn);%0A%0A        OnClickListener side1TextBtnListener = new OnClickListener() %7B%0A            public void onClick(View v) %7B%0A                // TODO(jwall): we need to start an activity to write text.%0A            %7D%0A        %7D;%0A%0A        side1TextBtn.setOnClickListener(side1TextBtnListener);%0A%0A        Button side2ImageBtn =%0A            (Button) dialog.findViewById(R.id.NewCardSide2ImageBtn);%0A%0A        OnClickListener side2ImageBtnListener = new OnClickListener() %7B%0A            public void onClick(View v) %7B%0A                // TODO(jwall): we need to start an activity to get an image.%0A            %7D%0A        %7D;%0A%0A        side2ImageBtn.setOnClickListener(side2ImageBtnListener);%0A%0A        Button side2TextBtn =%0A            (Button) dialog.findViewById(R.id.NewCardSide2TextBtn);%0A%0A        OnClickListener side2TextBtnListener = new OnClickListener() %7B%0A            public void onClick(View v) %7B%0A                // TODO(jwall): we need to start an activity to write text.%0A            %7D%0A        %7D;%0A%0A        side2TextBtn.setOnClickListener(side2TextBtnListener);%0A
 %0A   

Add onclick listeners to the four buttons to create the cards.