package wcm.ytwhyc.ratiofixer;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout.LayoutParams;

public class RatioActivity extends Activity {

	private RatioRelativeLayout mRatioLayout;
	
	private RatioFixer mRatioFixer;
	
	public int mVWidth = 0, mVHeight =0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.getActionBar().hide();
		onInitialize();
		
//		int x, y;
//		WindowManager wm = (WindowManager) this
//				.getSystemService(Context.WINDOW_SERVICE);
//		Display display = wm.getDefaultDisplay();

		// if(Build.VERSION.SDK_INT>Build.VERSION_CODES.HONEYCOMB){
		// Point size = new Point();
		// display.getSize(size);
		// x = size.x;
		// y = size.y;
		// }
		// else{
//		x = display.getWidth(); // deprecated
//		y = display.getHeight();
		// }
       if(mVWidth != 0&&mVHeight!= 0)
    	   mRatioLayout = new RatioRelativeLayout(this,mVWidth,mVHeight);
       else
		   mRatioLayout = new RatioRelativeLayout(this);
		mRatioFixer = mRatioLayout.getRatioFixer();
		mRatioLayout.post(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				onLayoutCreated();
			}
		});
		mRatioLayout.setBackgroundColor(Color.WHITE);

		LayoutParams layoutParams = new LayoutParams(
				android.view.ViewGroup.LayoutParams.MATCH_PARENT,
				android.view.ViewGroup.LayoutParams.MATCH_PARENT);
		layoutParams.gravity = Gravity.CENTER;
		setContentView(mRatioLayout, layoutParams);
//		getWindow().getDecorView().findViewById(android.R.id.content)
//				.setBackgroundColor(Color.RED);
	}

/*
 * Initialize function, executes before RatioFixer initialize. Set virtual size or default virtual size here 
 */
	public void onInitialize()
	{
		
	}
	
	
	
	/*
	 * This function will invoke after the layout is drawn
	 */
	public void onLayoutCreated() {

	}
	

	public RatioRelativeLayout getMainLayout() {
		return mRatioLayout;
	}
	
	public void addView(View v,int width,int height,int x,int y)
	{
		mRatioLayout.addView(v,mRatioFixer.getLayoutParam(width, height, x, y));
	}

	public int getRealValue(int v)
	{
		return mRatioFixer.getRealValue(v);
	}
	
	public RatioFixer getRatioFixer()
	{
		return mRatioFixer;
	}
	
//	public void setVirtualSize(int width, int height)
//	{
//		mRatioFixer.setVirtualSize(width, height);
//	}
//	
//	public void setDefaultVirtualSize(int width,int height)
//	{
//		RatioFixer.setDefaultVirtualSize(width, height);
//	}
}

@@ -2465,18 +2465,16 @@
 r;%0A%09%7D%0A%09%0A
-//
 %09public 
@@ -2516,24 +2516,22 @@
 height)%0A
-//
 %09%7B%0A
+%09
 //
-%09
 %09mRatioF
@@ -2570,19 +2570,53 @@
 t);%0A
-//%09%7D%0A//%09%0A//
+%09%09mVWidth = width;%0A%09%09mVHeight = height;%0A%09%7D%0A%09%0A
 %09pub
@@ -2672,15 +2672,11 @@
 ht)%0A
-//
 %09%7B%0A
-//
 %09%09Ra
@@ -2722,15 +2722,13 @@
 eight);%0A
-//
 %09%7D%0A%7D%0A

add set virtual size and set default virtual size function in RatioActivity