package com.mobile.constellations.ui;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mobile.constellations.R;
import com.mobile.constellations.data.Contans;
import com.mobile.constellations.data.Home;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.LoadedFrom;
import com.nostra13.universalimageloader.core.display.BitmapDisplayer;
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
import com.zdp.aseo.content.AseoZdpAseo;

/**
 * 星座详情页
 * 
 * @author Linda
 * 
 */
public class ConDescActivity extends Activity implements
		OnClickListener {

	private ImageLoader imageLoader = ImageLoader.getInstance();
	private DisplayImageOptions options;
	public static String CONDESC_SERIAL = "condescSerial";
	private Home myData;

	public static void intentConDescActivity(Context context, Home myData) {
		Intent intent = new Intent(context, ConDescActivity.class);
		Bundle bundle = new Bundle();
		bundle.putSerializable(CONDESC_SERIAL, myData);
		intent.putExtras(bundle);
		context.startActivity(intent);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		super.onCreate(savedInstanceState);
		initOptions();
		myData = (Home) getIntent().getSerializableExtra(CONDESC_SERIAL);
		setContentView(R.layout.activity_con_desc);
		resetTitlebar(myData);
		ImageView image = (ImageView) findViewById(R.id.imageView1);
		TextView title = (TextView) findViewById(R.id.title);
		TextView date = (TextView) findViewById(R.id.date);
		TextView desc = (TextView) findViewById(R.id.desc);
		AseoZdpAseo.initType(this, AseoZdpAseo.SCREEN_TYPE);
		TextView character = (TextView) findViewById(R.id.character);
		TextView character1 = (TextView) findViewById(R.id.character1);
		TextView character2 = (TextView) findViewById(R.id.character2);
		TextView character3 = (TextView) findViewById(R.id.character3);
		TextView character4 = (TextView) findViewById(R.id.character4);
		TextView character5 = (TextView) findViewById(R.id.character5);
		TextView character6 = (TextView) findViewById(R.id.character6);
		TextView character7 = (TextView) findViewById(R.id.character7);
		TextView character8 = (TextView) findViewById(R.id.character8);
		TextView character9 = (TextView) findViewById(R.id.character9);
		TextView character10 = (TextView) findViewById(R.id.character10);
		TextView character11 = (TextView) findViewById(R.id.character11);
		TextView character12 = (TextView) findViewById(R.id.character12);
		TextView character13 = (TextView) findViewById(R.id.character13);
		TextView character14 = (TextView) findViewById(R.id.character14);
		TextView more = (TextView) findViewById(R.id.more);
		more.setText("+更多"+myData.title+"资料");
		imageLoader.displayImage(myData.image, image, options, null);
		title.setText(myData.title + "简介");
		date.setText(myData.date);
		desc.setText(myData.desc);
		character.setText(myData.title + "特性");
		character1.setText(myData.character1);
		character2.setText(myData.character2);
		character3.setText(myData.character3);
		character4.setText(myData.character4);
		character5.setText(myData.character5);
		character6.setText(myData.character6);
		character7.setText(myData.character7);
		character8.setText(myData.character8);
		character9.setText(myData.character9);
		character10.setText(myData.character10);
		character11.setText(myData.character11);
		character12.setText(myData.character12);
		character13.setText(myData.character13);
		character14.setText(myData.character14);
		showAd();
		more.setOnClickListener(this);
	}

	private void showAd(){

	}
	
	private void resetTitlebar(Home myData) {
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
				R.layout.view_comm_titlebar);
		TextView title = (TextView) findViewById(R.id.titlebar_title);
		LinearLayout back = (LinearLayout) findViewById(R.id.titlebar_left_layout);
		title.setText(myData.title);
		back.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	private void initOptions() {
		options = new DisplayImageOptions.Builder()
				.showImageOnLoading(R.drawable.ic_stub)
				.showImageForEmptyUri(R.drawable.ic_empty)
				.showImageOnFail(R.drawable.ic_error).cacheInMemory(true)
				.cacheOnDisc(true).considerExifParams(true)
				.displayer(new SimpleBitmapDisplayer()).build();
	}

	private final class SimpleBitmapDisplayer implements BitmapDisplayer {
		@Override
		public void display(Bitmap bitmap, ImageAware imageAware,
				LoadedFrom loadedFrom) {
			imageAware.setImageBitmap(bitmap);
		}
	}

	private String consUrl() {
		if ("白羊座".equals(myData.title)) {
			return Contans.PATH_BAIYANG;
		} else if ("金牛座".equals(myData.title)) {
			return Contans.PATH_JINNIU;
		} else if ("双子座".equals(myData.title)) {
			return Contans.PATH_SHUANGZI;
		} else if ("巨蟹座".equals(myData.title)) {
			return Contans.PATH_JUXIE;
		} else if ("狮子座".equals(myData.title)) {
			return Contans.PATH_SHIZI;
		} else if ("处女座".equals(myData.title)) {
			return Contans.PATH_CHUNV;
		} else if ("天秤座".equals(myData.title)) {
			return Contans.PATH_TIANCHENG;
		} else if ("天蝎座".equals(myData.title)) {
			return Contans.PATH_TIANXIE;
		} else if ("射手座".equals(myData.title)) {
			return Contans.PATH_SHESHOU;
		} else if ("摩羯座".equals(myData.title)) {
			return Contans.PATH_MOJIE;
		} else if ("水瓶座".equals(myData.title)) {
			return Contans.PATH_SHUIPING;
		} else if ("双鱼座".equals(myData.title)) {
			return Contans.PATH_SHUANGYU;
		}
		return "";
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.more:
			CommConsDescActivity.intentCommConsDescActivity(this, consUrl());
			break;

		default:
			break;
		}
	}

}
