package android.csoft.HomeWork4_iwasax;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;

//アクティビティの起動
public class HomeWork4_iwasaxActivity extends Activity 
	implements View.OnClickListener{
	private final static int WC=LinearLayout.LayoutParams.WRAP_CONTENT;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        //レイアウトの生成
        LinearLayout layout = new LinearLayout(this);
        layout.setBackgroundColor(Color.rgb(255, 255, 255));
        layout.setOrientation(LinearLayout.VERTICAL);
        setContentView(layout);
        
        //ボタンの生成
        layout.addView(makeButton("地図の表示；Tokyo","map"));
        
    }

	//ボタンの生成
	private Button makeButton(String text, String tag) {
		Button button = new Button(this);
		button.setText(text);
		button.setTag(tag);
		button.setOnClickListener(this);
		button.setLayoutParams(new LinearLayout.LayoutParams(WC, WC));
		return button;
	}

	//ボタンクリック時に呼ばれる
	public void onClick(View v){
		String tag=(String)v.getTag();
		
		try{
			if(tag.equals("map")){
				Intent intent=new Intent("android.intent.action.VIEW",Uri.parse("geo:0,0?q=Tokyo"));
				startActivity(intent);
			}
		}catch(Exception e){
			showDialog(this,"",e.getMessage());
		}
		
	}

	// ダイアログの表示
	private void showDialog(Context context,String title, String text) {
		AlertDialog.Builder ad=new AlertDialog.Builder(context);
		ad.setTitle(title);
		ad.setMessage(text);
		ad.setPositiveButton("OK", null);
		ad.show();
	}
}