package de.markusfisch.android.shadereditor.fragment;

import de.markusfisch.android.shadereditor.activity.AbstractSecondaryActivity;
import de.markusfisch.android.shadereditor.widget.CropImageView;
import de.markusfisch.android.shadereditor.R;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

public class CropImageFragment extends Fragment
{
	public static Bitmap bitmap;
	public static Rect rect;

	private CropImageView imageView;

	public static CropImageFragment newInstance( Bitmap bitmap )
	{
		// since there's no easy way to put a bitmap into
		// a bundle, I'm just using a static member here
		// because simple is always better
		CropImageFragment.bitmap = bitmap;

		return new CropImageFragment();
	}

	public static void recycle()
	{
		if( bitmap == null )
			return;

		bitmap.recycle();
		bitmap = null;
	}

	@Override
	public void onCreate( Bundle state )
	{
		super.onCreate( state );

		setHasOptionsMenu( true );
	}

	@Override
	public View onCreateView(
		LayoutInflater inflater,
		ViewGroup container,
		Bundle state )
	{
		Activity activity;
		View view;

		if( bitmap == null ||
			(activity = getActivity()) == null )
			return null;

		activity.setTitle( R.string.crop_image );

		if( (view = inflater.inflate(
				R.layout.fragment_crop_image,
				container,
				false )) == null ||
			(imageView = (CropImageView)view.findViewById(
				R.id.texture_image )) == null )
		{
			activity.finish();
			return null;
		}

		imageView.setImageBitmap( bitmap );

		return view;
	}

	@Override
	public void onCreateOptionsMenu( Menu menu, MenuInflater inflater )
	{
		inflater.inflate(
			R.menu.fragment_crop_image,
			menu );
	}

	@Override
	public boolean onOptionsItemSelected( MenuItem item )
	{
		switch( item.getItemId() )
		{
			case R.id.cut:
				cutImage();
				return true;
			default:
				return super.onOptionsItemSelected( item );
		}
	}

	private void cutImage()
	{
		rect = imageView.getRectInBound();

		AbstractSecondaryActivity.addFragment(
			getFragmentManager(),
			new TextureDetailsFragment() );
	}
}

@@ -710,17 +710,21 @@
 ageView 
-i
+cropI
 mageView
@@ -1607,17 +1607,21 @@
  %7C%7C%0A%09%09%09(
-i
+cropI
 mageView
@@ -1742,17 +1742,21 @@
 %0A%09%09%7D%0A%0A%09%09
-i
+cropI
 mageView
@@ -2209,17 +2209,21 @@
 %09rect = 
-i
+cropI
 mageView
@@ -2237,16 +2237,17 @@
 tInBound
+s
 ();%0A%0A%09%09A

Use fully qualified symbol name