package ca.ualberta.CMPUT301W15T06;

import java.io.ByteArrayOutputStream;
import java.text.ParseException;
import java.util.Date;

import android.graphics.Bitmap;
import android.util.Base64;
import android.util.Log;

public class ClaimantReceiptController {

	private Receipt receipt=null;
	
	public ClaimantReceiptController(Receipt r){
		receipt=r;
	}
	
	public void addPhoto(Bitmap bm) throws StatusException, NetWorkException{

		if (!AppSingleton.getInstance().isEditable()){
			throw new StatusException();					
		}
		String encoded =null;
		int quality=100;
		do{
			//http://stackoverflow.com/questions/9224056/android-bitmap-to-base64-string Author: jeet
			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();  
			bm.compress(Bitmap.CompressFormat.JPEG, quality, byteArrayOutputStream);
			byte[] byteArray = byteArrayOutputStream .toByteArray();
			encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
			quality-=10;
		}while(encoded.length()>=65536);
		
		receipt.setPhotoStr(encoded);
		Log.i("size",String.valueOf(encoded.length()));
		Log.i("quality",String.valueOf(quality));
		
	}

	public void deletePhoto() throws StatusException, NetWorkException {
		// TODO Auto-generated method stub
		if (!AppSingleton.getInstance().isEditable()){
			throw new StatusException();					
		}
		receipt.setPhotoStr(null);
	}
	
	
}

@@ -1,360 +1,1897 @@
-package ca.ualberta.CMPUT301W15T06;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.text.ParseException;%0Aimport java.util.Date;%0A%0Aimport android.graphics.Bitmap;%0Aimport android.util.Base64;%0Aimport android.util.Log;%0A%0Apublic class ClaimantReceiptController %7B%0A%0A%09private Receipt receipt=null;%0A%09%0A%09public ClaimantReceiptController(Receipt r)%7B%0A%09%09receipt=r;%0A%09%7D%0A%09
+/*%0AUA CMPUT 301 Project Group: CMPUT301W15T06%0ACopyright %7B2015%7D %7BJingjiao Ni%0A              Tianqi Xiao%0A              Jiafeng Wu%0A              Xinyi Pan %0A              Xinyi Wu%0A              Han Wang%7D%0ALicensed under the Apache License, Version 2.0 (the %22License%22);%0Ayou may not use this file except in compliance with the License.%0AYou may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 %0AUnless required by applicable law or agreed to in writing, software distributed under %0Athe License is distributed on an %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF %0AANY KIND, either express or implied. See the License for the specific language %0Agoverning permissions and limitations under the License.%0A */%0A %0Apackage ca.ualberta.CMPUT301W15T06;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.text.ParseException;%0Aimport java.util.Date;%0A%0Aimport android.graphics.Bitmap;%0Aimport android.util.Base64;%0Aimport android.util.Log;%0A%0A/**%0A * This %3Ccode%3EClaimantReceiptController%3C/code%3E is a controller class%0A * of %3Ccode%3EClaimantReceiptActivity%3C/code%3E and %3Ccode%3EReceipt/code%3E. By calling this class, %0A * user(claimant) can add a new receipt photo or delete an existing %0A * receipt photo to an %3Ccode%3EItem%3C/code%3E.%0A * %0A * @author CMPUT301W15T06%0A * @version 04/07/2015%0A * @see java.io.ByteArrayOutputStream%0A * @see java.text.ParseException%0A * @see java.util.Date%0A * @see android.graphics.Bitmap%0A * @see android.util.Base64%0A * @see android.util.Log%0A */%0Apublic class ClaimantReceiptController %7B%0A%0A%09/**%0A%09 * Set a Receipt object receipt with deault value of null.%0A%09 */%0A%09private Receipt receipt=null;%0A%09%0A%09/**%0A%09 * General constructor.%0A%09 */%0A%09public ClaimantReceiptController(Receipt r)%7B%0A%09%09receipt=r;%0A%09%7D%0A%09%0A%09/**%0A%09 * This method will add a photo receipt.%0A%09 * %0A%09 * @param bm  possible bitmap configurations%0A%09 * @see android.graphics.Bitmap%0A%09 * @throws StatusException%0A%09 * @throws NetWorkException%0A%09 */
 %0A%09pu
@@ -2661,16 +2661,169 @@
 %0A%09%09%0A%09%7D%0A%0A
+%09/**%0A%09 * This method will delete a photo repceipt and set the receipt object as null.%0A%09 * %0A%09 * @throws StatusException%0A%09 * @throws NetWorkException%0A%09 */%0A
 %09public 

Update ClaimantReceiptController.java