package edu.cs.cs160.storytime;
import org.xmlpull.v1.XmlPullParser;
import android.app.Activity;
import android.content.Intent;
import android.content.res.XmlResourceParser;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class StoryTime extends Activity {
/** Called when the activity is first created. */
public static StoryLibrary library;
public static final int LOAD_LIBRARY = 100;
public static final int LOAD_BOOK = 101;
public static final int LOAD_BOOK_ON_EXIT = 102;
public static final int LOAD_LIBRARY_ON_EXIT = 103;
int numHotspots = -1;
//MediaPlayer mp = MediaPlayer.create(this, R.raw.m);
public void createLibrary() {
library = new StoryLibrary();
//createBooks
StoryBook gnm = new StoryBook("Goodnight Moon","Margaret Wise Brown",R.drawable.gnm_cover,R.drawable.gnm_cover,R.drawable.gnm_cover);
library.addBook(gnm,true);
StoryBook cg = new StoryBook("Curious George","Margret & H. A. Rey",R.drawable.cgcover,R.drawable.george_back,R.drawable.libcover_george);
library.addBook(cg,true);
StoryBook ijf = new StoryBook("I Just Forgot","Mercer Mayer",-1,-1,R.drawable.libcover_iforgot);
library.addBook(ijf,false);
StoryBook gb = new StoryBook("The Going To Bed Book","Sandra Boynton",-1,-1,R.drawable.libcover_goingtobed);
library.addBook(gb,false);
StoryBook ex = new StoryBook("Excuse Me","Karen Katz",-1,-1,R.drawable.libcover_excuse);
library.addBook(ex,false);
StoryPage gnm_p0 = new StoryPage(R.drawable.gnm1);
StoryPage gnm_p1 = new StoryPage(R.drawable.gnm2);
StoryPage gnm_p2 = new StoryPage(R.drawable.gnm3);
StoryPage gnm_p3 = new StoryPage(R.drawable.gnm4);
StoryPage gnm_p4 = new StoryPage(R.drawable.gnm5);
StoryPage gnm_p5 = new StoryPage(R.drawable.gnm6);
StoryPage gnm_p6 = new StoryPage(R.drawable.gnm7);
StoryPage gnm_p7 = new StoryPage(R.drawable.gnm8);
StoryPage gnm_p8 = new StoryPage(R.drawable.gnm9);
StoryPage gnm_p9 = new StoryPage(R.drawable.gnm10);
StoryPage gnm_p10 = new StoryPage(R.drawable.gnm11);
StoryPage gnm_p11 = new StoryPage(R.drawable.gnm12);
StoryPage gnm_p12 = new StoryPage(R.drawable.gnm13);
StoryPage gnm_p13 = new StoryPage(R.drawable.gnm14);
StoryPage gnm_p14 = new StoryPage(R.drawable.gnm15);
StoryPage gnm_p15 = new StoryPage(R.drawable.gnm16);
StoryPage gnm_p16 = new StoryPage(R.drawable.gnm17);
StoryPage gnm_p17 = new StoryPage(R.drawable.gnm18);
StoryPage gnm_p18 = new StoryPage(R.drawable.gnm19);
StoryPage gnm_p19 = new StoryPage(R.drawable.gnm20);
StoryPage gnm_p20 = new StoryPage(R.drawable.gnm21);
StoryPage gnm_p21 = new StoryPage(R.drawable.gnm22);
StoryPage gnm_p22 = new StoryPage(R.drawable.gnm23);
StoryPage gnm_p23 = new StoryPage(R.drawable.gnm24);
StoryPage gnm_p24 = new StoryPage(R.drawable.gnm25);
StoryPage gnm_p25 = new StoryPage(R.drawable.gnm26);
StoryPage gnm_p26 = new StoryPage(R.drawable.gnm27);
StoryPage gnm_p27 = new StoryPage(R.drawable.gnm28);
StoryPage gnm_p28 = new StoryPage(R.drawable.gnm29);
StoryPage gnm_p29 = new StoryPage(R.drawable.gnm30);
StoryPage gnm_p30 = new StoryPage(R.drawable.gnm31);
StoryPage gnm_p31 = new StoryPage(R.drawable.gnm32);
gnm.addPage(gnm_p0);
gnm.addPage(gnm_p1);
gnm.addPage(gnm_p2);
gnm.addPage(gnm_p3);
gnm.addPage(gnm_p4);
StoryHotspot gnm_p4_h1 = new StoryHotspot("cow",.35,.10,.75,.30,Color.BLACK);
gnm_p4.addHotspot(gnm_p4_h1);
StoryHotspot gnm_p4_h2 = new StoryHotspot("moon",.45,.30,.65,.45,Color.BLACK);
gnm_p4.addHotspot(gnm_p4_h2);
StoryResource gnm_res_cow = new StoryResource("Cow",-1,R.string.res_cow);
gnm_p4_h1.addResource(gnm_res_cow);
StoryResource gnm_res_moon = new StoryResource("Moon",-1,R.string.res_moon);
gnm_p4_h2.addResource(gnm_res_moon);
gnm.addPage(gnm_p5);
gnm.addPage(gnm_p6);
gnm.addPage(gnm_p7);
gnm.addPage(gnm_p8);
gnm.addPage(gnm_p9);
gnm.addPage(gnm_p10);
gnm.addPage(gnm_p11);
gnm.addPage(gnm_p12);
gnm.addPage(gnm_p13);
gnm.addPage(gnm_p14);
gnm.addPage(gnm_p15);
gnm.addPage(gnm_p16);
gnm.addPage(gnm_p17);
gnm.addPage(gnm_p18);
gnm.addPage(gnm_p19);
gnm.addPage(gnm_p20);
gnm.addPage(gnm_p21);
gnm.addPage(gnm_p22);
gnm.addPage(gnm_p23);
gnm.addPage(gnm_p24);
gnm.addPage(gnm_p25);
gnm.addPage(gnm_p26);
gnm.addPage(gnm_p27);
gnm.addPage(gnm_p28);
gnm.addPage(gnm_p29);
gnm.addPage(gnm_p30);
gnm.addPage(gnm_p31);
//createPages
StoryPage cg_p0 = new StoryPage(R.drawable.cgpage1);
StoryPage cg_p1 = new StoryPage(R.drawable.cgpage2);
//StoryPage cg_p0 = new StoryPage(R.drawable.temp1);
//StoryPage cg_p1 = new StoryPage(R.drawable.temp2);
cg.addPage(cg_p0);
cg.addPage(cg_p1);
//cg.addPage(new StoryPage(R.drawable.temp1));
//cg.addPage(new StoryPage(R.drawable.temp2));
cg.addPage(new StoryPage(R.drawable.cgpage3));
cg.addPage(new StoryPage(R.drawable.cgpage4));
cg.addPage(new StoryPage(R.drawable.cgpage5));
cg.addPage(new StoryPage(R.drawable.cgpage6));
cg.addPage(new StoryPage(R.drawable.cgpage7));
cg.addPage(new StoryPage(R.drawable.cgpage8));
//cg.addPage(new StoryPage(R.drawable.cgpage1));
//createHotspots
StoryHotspot cg_p1_h1 = new StoryHotspot("curiousgeorge",.35,.45,.65,.85,Color.BLACK);
cg_p1.addHotspot(cg_p1_h1);
StoryHotspot cg_p1_h2 = new StoryHotspot("butterfly",.65,.85,.87,.97,Color.RED);
cg_p1.addHotspot(cg_p1_h2);
numHotspots = cg_p1.getHotspots().size();
//createResources
StoryResource cg_res_curiousgeorge = new StoryResource("CuriousGeorge", -1 ,R.string.res_curiousgeorge);
cg_p1_h1.addResource(cg_res_curiousgeorge);
StoryResource cg_res_monkey = new StoryResource("Monkey",-1,R.string.res_monkey);
cg_p1_h1.addResource(cg_res_monkey);
StoryResource cg_res_brown = new StoryResource("Brown",-1,R.string.res_brown);
cg_p1_h1.addResource(cg_res_brown);
StoryResource cg_res_butterfly = new StoryResource("Butterfly",R.raw.balloon,R.string.res_butterfly);
cg_p1_h2.addResource(cg_res_butterfly);
}
/*
//http://stackoverflow.com/questions/1927406/way-to-parse-xml-org-w3c-document-on-android
private void parseLibraryXML(int XML, StoryLibrary library) {
XmlResourceParser parser = getResources().getXml(R.xml.myfile);
try {
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
String name = null;
switch (eventType){
case XmlPullParser.START_TAG:
name = parser.getName().toLowerCase();
if (name.equals(SOME_TAG)) {
for (int i = 0;i < parser.getAttributeCount();i++) {
String attribute = parser.getAttributeName(i).toLowerCase();
if (attribute.equals("myattribute")) {
String value = parser.getAttributeValue(i);
}
}
}
break;
case XmlPullParser.END_TAG:
name = parser.getName();
break;
}
eventType = parser.next();
}
}
catch (XmlPullParserException e) {
throw new RuntimeException("Cannot parse XML");
}
catch (IOException e) {
throw new RuntimeException("Cannot parse XML");
}
finally {
parser.close();
}
}
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
createLibrary();
//Intent myIntent = new Intent(this, StoryTimeBook.class);
//startActivityForResult(myIntent, LOAD_LIBRARY);
//((TextView) findViewById(R.id.TitleText)).setText("hotspots:"+numHotspots);
ImageView next = (ImageView) findViewById(R.id.TitleBG);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), StoryTimeLibrary.class);
startActivityForResult(myIntent, 0);
}
});
}
/*
public void onActivityResult(int request, int result, Intent i) {
Log.i("activityresult","req:"+request+" res:"+result);
if (result == LOAD_BOOK_ON_EXIT) {
Intent myIntent = new Intent(this.getBaseContext(), StoryTimeBook.class);
startActivityForResult(myIntent, LOAD_BOOK);
} else if (result == LOAD_LIBRARY_ON_EXIT) {
Intent myIntent = new Intent(this, StoryTimeLibrary.class);
startActivityForResult(myIntent, LOAD_LIBRARY);
} else {
finish();
}
}
*/
}
|