/*******************************************************************************
 * Copyright (c) 2009 Ferenc Hechler - ferenc_hechler@users.sourceforge.net
 * 
 * This file is part of AndroMaze
 *
 * AndroMaze is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation;
 * either version 2 of the License, or (at your option) any later version.
 * 
 * AndroMaze is distributed
 * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with the AndroMaze;
 * if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *  
 *******************************************************************************/
package de.hechler.andmaz;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

/**
 * This class provides a basic demonstration of how to write an Android
 * activity. Inside of its window, it places a single view: an EditText that
 * displays and edits some internal text.
 */
public class AndroMazeHelpActivity extends Activity {

	Button btBack;
	Button btReleaseNotes;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

		// create view from xml
        setContentView(R.layout.help);

        // find buttons in view
        btBack = ((Button) findViewById(R.id.btBack));
        btReleaseNotes = ((Button) findViewById(R.id.btReleaseNotes));
        
        // set actions for buttons
        btBack.setOnClickListener(ExitListener);
        btReleaseNotes.setOnClickListener(ReleaseNotesListener);
    }

       
    OnClickListener ExitListener = new OnClickListener() {
        public void onClick(View v) {
            finish();
        }
    };
    
    OnClickListener ReleaseNotesListener = new OnClickListener() {
        public void onClick(View v) {
            showDialog(AndroMazeActivity.SPLASH_SCREEN);
        }
    };
    
    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case AndroMazeActivity.SPLASH_SCREEN:
	        LayoutInflater factory = LayoutInflater.from(this);
	        final View splashView = factory.inflate(R.layout.splash_screen, null);
			final TextView tvReleaseNotes = (TextView)splashView.findViewById(R.id.release_text);
			String release_notes = Helper.readRawResource(this, "release_notes");
			if (release_notes != null) {
				release_notes = release_notes.replaceAll("\\r\\n", "\n");
				tvReleaseNotes.setText(release_notes);
			}
	        return new AlertDialog.Builder(this)
	            .setIcon(R.drawable.icon)
	            .setTitle("New in Release "+AndroMazeActivity.VERSION)
	            .setView(splashView)
	            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
	                public void onClick(DialogInterface dialog, int whichButton) {
	                	SimplePersistence persist = new SimplePersistence(AndroMazeHelpActivity.this, "AndroMaze");
	                	persist.putString("version", AndroMazeActivity.VERSION);
	                	persist.commit();
	                }
	            })
	            .create();
        }
	    return null;
    }
    

	
}