On my Blog Magical Android i discussed Low Image Quality Tweaking so i wont repeat that, lets just get our hands grimmy and improve on ODK picture Quality on Low Android Firmware.

  1. And the following to package:org.odk.collect.android.widgets

package org.odk.collect.android.widgets;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.graphics.Bitmap.CompressFormat;
import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.james.mime4j.parser.Event;
import org.odk.collect.android.R;
import org.odk.collect.android.utilities.FileUtils;

// Need the following import to get access to the app resources, since this
// class is in a sub-package.

// ———————————————————————-

public class CamaraView extends Activity implements SurfaceHolder.Callback,
        OnClickListener {
    static final int FOTO_MODE = 0;
    private static final String TAG = “CameraTest”;
    private static  int scaleFactor = 1;
    private  int imageQuality=60;
    Camera mCamera;
    boolean mPreviewRunning = false;
    private Context mContext = this;
     Button mCapture;
     RadioGroup mRadioGroup;
     RadioButton radio_low;
     RadioButton radio_normal ;

     RadioButton radio_high ;
     RadioButton radio_super ;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        Log.e(TAG, “onCreate”);
       

        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.surface_camera);
        radio_low = (RadioButton) findViewById(R.id.radio_low);
        radio_normal = (RadioButton) findViewById(R.id.radio_normal);
        radio_high = (RadioButton) findViewById(R.id.radio_high);
        radio_super = (RadioButton) findViewById(R.id.radio_super);
          radio_low.setOnClickListener(radio_listener);
          radio_normal.setOnClickListener(radio_listener);
         
        radio_high.setOnClickListener(radio_listener);
        radio_super.setOnClickListener(radio_listener);
       
        mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);
        mCapture= (Button) findViewById(R.id.button_camera_capture);
        mCapture.setOnClickListener(this);
        //mSurfaceView.setOnClickListener(this);
        mRadioGroup=(RadioGroup) findViewById(R.id.RadioImageC);
       
        mSurfaceHolder = mSurfaceView.getHolder();
        mSurfaceHolder.addCallback(this);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    private OnClickListener radio_listener = new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            RadioButton rb = (RadioButton) v;
            if(rb.getText().equals(“Low”))
            {
                 imageQuality=  60;
            }
            if(rb.getText().equals(“Normal”))
            {
                imageQuality=70;
            }
            if(rb.getText().equals(“High Detail”))
            {
                imageQuality=80;
            }
            if(rb.getText().equals(“Super High Detail”))
            {
                imageQuality=100;
            }
           
         
        }
    };
    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
    }
//      @Override
//        public boolean onCreateOptionsMenu(Menu menu) {
//
//            // Inflate our menu which can gather user input for switching camera
//            MenuInflater inflater = getMenuInflater();
//            inflater.inflate(R.menu.camera_menu, menu);
//            return true;
//        }

    Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
        public void onPictureTaken(byte[] imageData, Camera c) {

            if (imageData != null) {

               

                StoreByteImage(mContext, imageData, imageQuality,
                        “ImageName”);
                setResult(1);
                mCamera.startPreview();

           
               
                finish();

            }
        }
    };

    protected void onResume() {
        Log.e(TAG, “onResume”);
        super.onResume();
    }

    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }
    protected void onStop() {
        Log.e(TAG, “onStop”);
        super.onStop();
    }

    public void surfaceCreated(SurfaceHolder holder) {
        Log.e(TAG, “surfaceCreated”);
        mCamera = Camera.open();

    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        Log.e(TAG, “surfaceChanged”);

        // XXX stopPreview() will crash if preview is not running
        if (mPreviewRunning) {
            mCamera.stopPreview();
        }

        Camera.Parameters p = mCamera.getParameters();
        p.setPictureFormat(PixelFormat.JPEG);
     

        p.setPreviewSize(w, h);
        mCamera.setParameters(p);
        try {
            mCamera.setPreviewDisplay(holder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        mCamera.startPreview();
        mPreviewRunning = true;
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        Log.e(TAG, “surfaceDestroyed”);
        mCamera.stopPreview();
        mPreviewRunning = false;
        mCamera.release();
    }

    private SurfaceView mSurfaceView;
    private SurfaceHolder mSurfaceHolder;
Boolean focused=false;
     AutoFocusCallback myAutoFocusCallback = new AutoFocusCallback(){

          @Override
          public void onAutoFocus(boolean arg0, Camera arg1) {
           // TODO Auto-generated method stub
           mCapture.setEnabled(true);
           focused=true;
          }};
    public void onClick(View arg0) {
        mCapture.setEnabled(false);
    mCamera.autoFocus(myAutoFocusCallback);       
   mCamera.takePicture(null, mPictureCallback, mPictureCallback);
       
       
    }
   
    public static boolean StoreByteImage(Context mContext, byte[] imageData,
            int quality, String expName) {

        FileOutputStream fileOutputStream = null;
       
        try {
           

            BitmapFactory.Options options=new BitmapFactory.Options();
           
            options.inSampleSize = scaleFactor;
       
           
            Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,
                    imageData.length,options);

           
            fileOutputStream = new FileOutputStream(FileUtils.TMPFILE_PATH);
                           
 
            BufferedOutputStream bos = new BufferedOutputStream(
                    fileOutputStream);

            myImage.compress(CompressFormat.JPEG, quality, bos);

            bos.flush();
            bos.close();

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return true;
    }

}

2.Replace the String.xml resource with this

<?xml version=”1.0″ encoding=”utf-8″?>
    <!–
        Copyright (C) 2009 University of Washington Licensed under the Apache
        License, Version 2.0 (the “License”); you may not use this file except
        in compliance with the License. You may obtain a copy of the License
        at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
        applicable law or agreed to in writing, software distributed under the
        License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR
        CONDITIONS OF ANY KIND, either express or implied. See the License for
        the specific language governing permissions and limitations under the
        License.
    –>
<resources xmlns:android=”http://schemas.android.com/apk/res/android”>
    <string name=”accept_location”>Record Location</string>
    <string name=”accuracy”>Accuracy</string>
    <string name=”ack”>Acknowledge</string>
    <string name=”acked”>Acknowledged</string>
    <string name=”add_another”>Add Group</string>
    <string name=”add_another_repeat”>Add another “%s” group?</string>
    <string name=”add_file”>Add Selected File(s)</string>
    <string name=”add_repeat”>Add a new “%s” group?</string>
    <string name=”add_repeat_no”>Do Not Add</string>
    <string name=”advance”>advance to next question</string>
    <string name=”altitude”>Altitude</string>
    <string name=”app_name”>ODK Collect</string>
    <string name=”audio_file_error”>No audio file was specified.</string>
    <string name=”audio_file_invalid”>File: %s is not a valid audio file.</string>
    <string name=”audio_file_missing”>Audio File: %s is missing.</string>
    <string name=”backup”>return to previous question</string>
    <string name=”barcode_scanner_error”>Sorry, Barcode Scanner is not installed!</string>
    <string name=”cancel”>Cancel</string>
    <string name=”cancel_loading_form”>Stop Loading</string>
    <string name=”cancel_location”>Do Not Record</string>
    <string name=”cancel_saving_form”>Stop Saving</string>
    <string name=”capture_audio”>Record Sound</string>
    <string name=”capture_image”>Take Picture</string>
    <string name=”capture_video”>Record Video</string>
    <string name=”change_language”>Change Language</string>
    <string name=”change_password”>Change Password</string>
    <string name=”change_server”>Change Server</string>
    <string name=”change_user”>Change Username</string>
    <string name=”clearanswer_confirm”>Remove the response to “%s”?</string>
    <string name=”clear_answer”>Remove Response</string>
    <string name=”clear_answer_ask”>Remove This Response?</string>
    <string name=”clear_answer_no”>Do Not Remove</string>
    <string name=”collapsed_group”>Collapsed Group</string>
    <string name=”completed_data”>Complete (%s)</string>
    <string name=”continue_form”>Do Not Exit</string>
    <string name=”data”>Data</string>
    <string name=”data_saved_error”>Sorry, data save failed!</string>
    <string name=”data_saved_ok”>Data successfully saved!</string>
    <string name=”default_server”>http://opendatakit.appspot.com</string>
    <string name=”delete_confirm”>Delete %s item(s)?</string>
    <string name=”delete_file”>Delete Selected</string>
    <string name=”delete_no”>Do Not Delete</string>
    <string name=”delete_repeat”>Remove Group</string>
    <string name=”delete_repeat_ask”>Remove This Group?</string>
    <string name=”delete_repeat_confirm”>Remove group “%s” and all of its sub-groups?</string>
    <string name=”delete_repeat_no”>Do Not Remove</string>
    <string name=”delete_yes”>Delete Items</string>
    <string name=”discard_answer”>Remove Response</string>
    <string name=”discard_group”>Remove Group</string>
    <string name=”download”>Get Selected</string>
    <string name=”downloading_data”>Connecting to Server</string>
    <string name=”download_all_successful”>All forms downloaded successfully.</string>
    <string name=”download_complete”>Form Get Complete</string>
    <string name=”download_failed_with_error”>Form “%1$s” failed. %2$s.</string>
    <string name=”download_some_failed”>Sorry, %s form(s) not downloaded!</string>
    <string name=”do_not_change”>Do Not Change</string>
    <string name=”do_not_exit”>Do Not Exit</string>
    <string name=”do_not_save”>Discard Changes And Exit</string>
    <string name=”enter”>enter</string>
    <string name=”entering_repeat”>Add Group</string>
    <string name=”entering_repeat_ask”>Add New Group?</string>
    <string name=”enter_data”>Start New Form</string>
    <string name=”enter_data_button”>Start New Form (%s)</string>
    <string name=”enter_data_description”>%s has been selected.</string>
    <string name=”enter_data_message”>To navigate, swipe your finger horizontally on the screen as if turning pages in a book. Press the Menu button for more choices.</string>
    <string name=”entry_exit_confirm”>Exiting now will discard unsaved changes.</string>
    <string name=”error_downloading”>Error Getting Form</string>
    <string name=”expanded_group”>Expanded Group</string>
    <string name=”fetching_file”>”Getting “%1$s”.nnForm %2$s of %3$s form(s)…”</string>
    <string name=”file_deleted_error”>Sorry, %s item(s) failed to delete!</string>
    <string name=”file_deleted_ok”>%s item(s) successfully deleted!</string>
    <string name=”file_download_error”>File %1$s failed. %2$s</string>
    <string name=”file_missing”>File: %s is missing.</string>
    <string name=”finalize_for_send”>Save As Complete</string>
    <string name=”form”>Form</string>
    <string name=”forms”>Forms</string>
    <string name=”form_path”>Form Path: /</string>
    <string name=”form_renamed”>%1$s was renamed %2$s.</string>
    <string name=”getting_location”>Loading Location…</string>
    <string name=”get_barcode”>Get Barcode</string>
    <string name=”get_forms”>Get New Forms</string>
    <string name=”get_location”>Record Location</string>
    <string name=”goto_previous_level”>Go to previous level</string>
    <string name=”gps_disabled_error”>Sorry, GPS is disabled!</string>
    <string name=”group_contains”>Contains %s items</string>
    <string name=”image_file_error”>No image file was specified.</string>
    <string name=”image_file_invalid”>File: %s is not a valid image file.</string>
    <string name=”image_file_missing”>Image File: %s is missing.</string>
    <string name=”invalid_answer_error”>Sorry, this response is invalid!</string>
    <string name=”jump_to_beginning”>Go To Start</string>
    <string name=”jump_to_end”>Go To End</string>
    <string name=”jump_to_previous”>Go Up</string>
    <string name=”latitude”>Latitude</string>
    <string name=”leave_repeat_yes”>Do Not Add</string>
    <string name=”leaving_repeat”>Add Group</string>
    <string name=”leaving_repeat_ask”>And One More Group?</string>
    <string name=”list_failed_with_error”>Form listing failed. %s.</string>
    <string name=”loading_form”>Loading Form…</string>
    <string name=”load_error”>Sorry, unable to load form %s</string>
    <string name=”load_remote_form_error”>Error Getting Form List</string>
    <string name=”local_files”>Local</string>
    <string name=”location_accuracy”>Accuracy is %s meters.</string>
    <string name=”longitude”>Longitude</string>
    <string name=”main_menu”>Main Menu</string>
    <string name=”main_menu_details”>Magnifying human resources with technology</string>
    <string name=”main_menu_message”>ODK Collect v1.1.6</string>
    <string name=”manage_files”>Manage Forms And Data</string>
    <string name=”mark_finished”>Mark Data as Finished</string>
    <string name=”no”>No</string>
    <string name=”noselect_error”>Sorry, you have not selected any items!</string>
    <string name=”no_capture”>Nothing recorded yet.</string>
    <string name=”no_items_display”>Nothing available to display.</string>
    <string name=”no_items_error”>Nothing available to %s!</string>
    <string name=”no_sd_error”>Sorry, your memory card is not working!</string>
    <string name=”ok”>OK</string>
    <string name=”one_capture”>Multimedia recorded.</string>
    <string name=”password”>Password</string>
    <string name=”play_audio”>Play Sound</string>
    <string name=”play_video”>Play Video</string>
    <string name=”please_wait”>Please wait a few moments.</string>
    <string name=”quit_application”>Exit Without Saving?</string>
    <string name=”quit_entry”>Save Data And Exit</string>
    <string name=”refresh”>Refresh</string>
    <string name=”remote_files”>Remote</string>
    <string name=”replace_audio”>Replace Sound</string>
    <string name=”replace_barcode”>Replace Barcode</string>
    <string name=”replace_image”>Replace Picture</string>
    <string name=”replace_location”>Replace Location</string>
    <string name=”replace_video”>Replace Video</string>
    <string name=”required_answer_error”>Sorry, this response is required!</string>
    <string name=”review”>review</string>
    <string name=”review_data”>Continue Saved Form</string>
    <string name=”review_data_button”>Continue Saved Form (%s)</string>
    <string name=”saved_data”>Incomplete (%s)</string>
    <string name=”save_all_answers”>Save Data</string>
    <string name=”save_data_message”>Please save data to keep your responses.</string>
    <string name=”save_enter_data_description”>You have reached the end of %s.</string>
    <string name=”save_for_later”>Save As Incomplete </string>
    <string name=”saving_form”>Saving Form…</string>
    <string name=”select_repeat”>Select to see repeated element: </string>
    <string name=”send”>send</string>
    <string name=”sending_items”>Sending %1$s of %2$s item(s)”</string>
    <string name=”send_data”>Send Finished Data</string>
    <string name=”send_data_button”>Send Finished Data (%s)</string>
    <string name=”send_selected_data”>Send Selected</string>
    <string name=”server”>Server</string>
    <string name=”server_preferences”>Server Preferences</string>
    <string name=”toggle_selected”>Toggle All</string>
    <string name=”trigger”>OK. Ready to Continue.</string>
    <string name=”uploading_data”>Sending Data</string>
    <string name=”upload_all_successful”>%s item(s) sent successfully.</string>
    <string name=”upload_some_failed”>Sorry, %s item(s) failed to send!</string>
    <string name=”url_error”>Sorry, invalid URL!</string>
    <string name=”username”>Username</string>
    <string name=”view_hierarchy”>Go To Prompt</string>
    <string name=”yes”>Yes</string>
    <string name=”camera_alert”>Camera Being Activated</string>
    <string name=”camera_campture”>snap it</string>
    <string name=”compression_quality”>Compression Quality</string>
</resources>

3.Replace the Manifest File with this
<?xml version=”1.0″ encoding=”utf-8″?>
<!– Copyright (C) 2009 University of Washington

Licensed under the Apache License, Version 2.0 (the “License”); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
–>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”org.odk.collect.android” android:versionCode=”10″ android:versionName=”1.1.6″>
    <uses-permission android:name=”android.permission.CAMERA”></uses-permission>
    <uses-permission android:name=”android.permission.FLASHLIGHT”></uses-permission>
    <uses-permission android:name=”android.permission.VIBRATE”></uses-permission>
  <application android:icon=”@drawable/notes” android:label=”@string/app_name” android:theme=”@android:style/Theme.Light” android:name=”.application.Collect”>
  <activity android:label=”@string/app_name” android:configChanges=”orientation” android:name=”.activities.MainMenuActivity”>
      <intent-filter>
        <action android:name=”android.intent.action.MAIN”/>
        <category android:name=”android.intent.category.DEFAULT”/>
        <category android:name=”android.intent.category.LAUNCHER”/>
      </intent-filter>
    </activity>
    <activity android:name=”.activities.FormEntryActivity” android:label=”@string/app_name”
                android:windowSoftInputMode=”adjustResize” >
    <!– the intent filter below is a bit of a hack until we create a content provider for forms –>
    <intent-filter>
        <action android:name=”org.odk.collect.android.action.FormEntry”/>
        <category android:name=”android.intent.category.DEFAULT”/>
    </intent-filter>
    <!– this is what we should be doing once we have the content provider working –>
    <intent-filter>
        <action android:name=”android.intent.action.VIEW” />
        <action android:name=”android.intent.action.EDIT” />
        <category android:name=”android.intent.category.DEFAULT”/>
        <!– need to add something like:
         <data android:mimeType=”vnd.android.cursor.item/vnd.google.note” />
         here once we make a contentProvider for forms.
         –>
    </intent-filter>  
    </activity>
    <activity android:name=”.activities.InstanceChooserList” android:label=”@string/app_name”/>
    <activity android:name=”.activities.InstanceChooserTabs” android:label=”@string/app_name”>
    </activity>
    <activity android:name=”.activities.FormChooserList” android:label=”@string/app_name”/>
  
    <activity android:name=”.activities.FormManagerList” android:label=”@string/app_name”/>
    <activity android:name=”.activities.FormDownloadList” android:label=”@string/app_name”/>
    <activity android:name=”.activities.DataManagerList” android:label=”@string/app_name”/>
    <activity android:name=”.activities.FileManagerTabs” android:label=”@string/app_name”/>
    <activity android:name=”.activities.InstanceUploaderList” android:label=”@string/app_name”/>
    <activity android:name=”.activities.InstanceUploaderActivity” android:label=”@string/app_name”/>
    <activity android:name=”.preferences.ServerPreferences” android:label=”@string/app_name”/>
    <activity android:name=”.activities.FormHierarchyActivity” android:label=”@string/app_name”/>
    <activity android:name=”.activities.GeoPointActivity” android:label=”@string/app_name”/>
     <activity android:label=”@string/app_name” android:name=”.widgets.CamaraView”/>
     <activity android:label=”@string/app_name” android:name=”.widgets.ImageSettingsEditor”>
         <intent-filter>
             <action android:name=”org.odk.collect.android.widgets.action.CAMERA_SETTINGS”></action>
         </intent-filter>
     </activity>
  </application>
  <uses-permission android:name=”android.permission.READ_PHONE_STATE” xmlns:android=”http://schemas.android.com/apk/res/android”/>
  <uses-permission android:name=”android.permission.INTERNET” xmlns:android=”http://schemas.android.com/apk/res/android”/>
  <uses-permission xmlns:android=”http://schemas.android.com/apk/res/android” android:name=”android.permission.ACCESS_SURFACE_FLINGER”/>
  <uses-permission xmlns:android=”http://schemas.android.com/apk/res/android” android:name=”android.permission.ACCESS_FINE_LOCATION”/>
  <uses-permission xmlns:android=”http://schemas.android.com/apk/res/android” android:name=”android.permission.WRITE_EXTERNAL_STORAGE”/>
<uses-sdk android:minSdkVersion=”3″></uses-sdk>
</manifest>

4.Replace the ImageWidget with this
/*
 * Copyright (C) 2009 University of Washington
 *
 * Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package org.odk.collect.android.widgets;

import org.javarosa.core.model.data.IAnswerData;
import org.javarosa.core.model.data.StringData;
import org.javarosa.form.api.FormEntryPrompt;
import org.odk.collect.android.R;
import org.odk.collect.android.activities.FormEntryActivity;
import org.odk.collect.android.utilities.FileUtils;
import org.odk.collect.android.views.AbstractFolioView;
import org.odk.collect.android.widgets.AbstractQuestionWidget.OnDescendantRequestFocusChangeListener.FocusChangeState;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Handler;
import android.provider.MediaStore.Images;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.File;

/**
 * Widget that allows user to take pictures, sounds or video and add them to the form.
 *
 * @author Carl Hartung (carlhartung@gmail.com)
 * @author Yaw Anokwa (yanokwa@gmail.com)
 */
public class ImageWidget extends AbstractQuestionWidget implements IBinaryWidget {

    private final static String t = “MediaWidget”;

    private Button mCaptureButton;
    private ImageView mImageView;

    private String mBinaryName;
    private TextView mDisplayText;

    private Uri mExternalUri;
    private String mCaptureIntent;
    private String mInstanceFolder;
    private int mRequestCode;
    private int mCaptureText;
    private int mReplaceText;

    public ImageWidget(Handler handler, Context context, FormEntryPrompt prompt, String instancePath) {
        super(handler, context, prompt);
        initialize(instancePath);
    }

    private void initialize(String instancePath) {
        mInstanceFolder = instancePath.substring(0, instancePath.lastIndexOf(“/”) + 1);
        mExternalUri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        mCaptureIntent = android.provider.MediaStore.ACTION_IMAGE_CAPTURE;
        mRequestCode = FormEntryActivity.IMAGE_CAPTURE;
        mCaptureText = R.string.capture_image;
        mReplaceText = R.string.replace_image;
    }

    private void deleteMedia() {
        // non-existent?
        if ( mBinaryName == null ) return;

        Log.i(t, “Deleting current answer: ” + mBinaryName);
       
        // release image…
        mImageView.setImageBitmap(null);
        // get the file path and delete the file
        //
        // There’s only 1 in this case, but android 1.6 doesn’t implement delete on
        // android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI only on
        // android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI + a #
        String[] projection = {
            Images.ImageColumns._ID
        };
        Cursor c =
            getContext().getContentResolver().query(mExternalUri, projection,
                “_data='” + mInstanceFolder + mBinaryName + “‘”, null, null);
        int del = 0;
        if (c.getCount() > 0) {
            c.moveToFirst();
            String id = c.getString(c.getColumnIndex(Images.ImageColumns._ID));

            Log.i(t, “attempting to delete: ” + Uri.withAppendedPath(mExternalUri, id));
            del =
                getContext().getContentResolver().delete(Uri.withAppendedPath(mExternalUri, id),
                    null, null);
        }
        c.close();

        // clean up variables
        mBinaryName = null;
        Log.i(t, “Deleted ” + del + ” rows from media content provider”);
    }

    @Override
    public IAnswerData getAnswer() {
        if (mBinaryName != null) {
            return new StringData(mBinaryName.toString());
        } else {
            return null;
        }
    }

    @Override
    protected void buildViewBodyImpl() {
       
        // setup capture button
        mCaptureButton = new Button(getContext());
        mCaptureButton.setText(getContext().getString(mCaptureText));
        mCaptureButton
                .setTextSize(TypedValue.COMPLEX_UNIT_DIP, AbstractFolioView.APPLICATION_FONTSIZE);
        mCaptureButton.setPadding(20, 20, 20, 20);
        mCaptureButton.setEnabled(!prompt.isReadOnly());

        // launch capture intent on click
        mCaptureButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ( signalDescendant(FocusChangeState.DIVERGE_VIEW_FROM_MODEL) ) {
                 //   Intent i = new Intent(mCaptureIntent);
                    // We give the camera an absolute filename/path where to put the
                    // picture because of bug:
                    // http://code.google.com/p/android/issues/detail?id=1480
                    // The bug appears to be fixed in Android 2.0+, but as of feb 2,
                    // 2010, G1 phones only run 1.6. Without specifying the path the
                    // images returned by the camera in 1.6 (and earlier) are ~1/4
                    // the size. boo.
   
                    // if this gets modified, the onActivityResult in
                    // FormEntyActivity will also need to be updated.
                  //  i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(
                  //          FileUtils.TMPFILE_PATH)));
                   
                    Intent i= new Intent(getContext(),CamaraView.class);
                     i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(
                              FileUtils.TMPFILE_PATH)));
                   
                    ((Activity) getContext()).startActivityForResult(i, mRequestCode);
                }
            }
        });

        // finish complex layout
        addView(mCaptureButton);

        mDisplayText = new TextView(getContext());
        mDisplayText.setPadding(5, 0, 0, 0);

        mImageView = new ImageView(getContext());
        mImageView.setPadding(10, 10, 10, 10);
        mImageView.setAdjustViewBounds(true);
        mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ( signalDescendant(FocusChangeState.DIVERGE_VIEW_FROM_MODEL)) {
                    // do nothing if no image
                    if ( mBinaryName == null ) return;
                    Intent i = new Intent(“android.intent.action.VIEW”);
                    String[] projection = {“_id”};
                    Cursor c =
                        getContext().getContentResolver().query(mExternalUri, projection,
                            “_data='” + mInstanceFolder + mBinaryName + “‘”, null, null);
                    if (c.getCount() > 0) {
                        c.moveToFirst();
                        String id = c.getString(c.getColumnIndex(“_id”));

                        Log.i(t, “setting view path to: ” + Uri.withAppendedPath(mExternalUri, id));

                        i.setDataAndType(Uri.withAppendedPath(mExternalUri, id), “image/*”);
                        getContext().startActivity(i);
                    }
                    c.close();
                }
            }
        });
        addView(mImageView);
    }

    protected void updateViewAfterAnswer() {
       
        String newAnswer = prompt.getAnswerText();
        if ( mBinaryName != null && !mBinaryName.equals(newAnswer)) {
            deleteMedia();
        }
        mBinaryName = newAnswer;
       
        if (mBinaryName != null) {
            mCaptureButton.setText(getContext().getString(mReplaceText));
            mDisplayText.setText(getContext().getString(R.string.one_capture));
           
            Display display =
                ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
                        .getDefaultDisplay();
            int screenWidth = display.getWidth();
            int screenHeight = display.getHeight();

            File f = new File(mInstanceFolder + “/” + mBinaryName);
            Bitmap bmp = FileUtils.getBitmapScaledToDisplay(f, screenHeight, screenWidth);
            mImageView.setImageBitmap(bmp);
        } else {
            mCaptureButton.setText(getContext().getString(mCaptureText));
            mDisplayText.setText(getContext().getString(R.string.no_capture));
           
            mImageView.setImageBitmap(null);
        }
    }

    private String getPathFromUri(Uri uri) {
        // find entry in content provider
        Cursor c = getContext().getContentResolver().query(uri, null, null, null, null);
        c.moveToFirst();

        // get data path
        String colString = c.getString(c.getColumnIndex(“_data”));
        c.close();
        return colString;
    }

    @Override
    public void setBinaryData(Object binaryuri) {
        // you are replacing an answer. delete the previous image using the
        // content provider.
        if (mBinaryName != null) {
            deleteMedia();
        }
        String binarypath = getPathFromUri((Uri) binaryuri);
        File f = new File(binarypath);
        mBinaryName = f.getName();
        Log.i(t, “Setting current answer to ” + mBinaryName);
        saveAnswer(true); // and evaluate constraints and trigger UI update…
    }

    @Override
    public void setEnabled(boolean isEnabled) {
        if (mBinaryName != null) {
            mImageView.setEnabled(isEnabled);
            mCaptureButton.setEnabled(isEnabled && !prompt.isReadOnly());
        } else {
            mImageView.setEnabled(false);
            mCaptureButton.setEnabled(isEnabled && !prompt.isReadOnly());
        }
    }
}
5.Add this layout
<?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
    android:layout_width=”fill_parent” android:layout_height=”fill_parent”
    android:orientation=”vertical”>
    <SurfaceView android:id=”@+id/surface_camera”
        android:layout_width=”fill_parent” android:layout_weight=”1″
        android:layout_height=”fill_parent”>
    </SurfaceView>
    <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
        android:layout_width=”fill_parent” android:layout_height=”48px” android:orientation=”horizontal”>
        <Button android:layout_width=”wrap_content”
            android:layout_height=”wrap_content” android:id=”@+id/button_camera_capture” android:text=”@string/camera_campture”></Button>
        <ScrollView android:layout_width=”fill_parent” android:layout_height=”48px” >
        <RadioGroup android:layout_width=”fill_parent”
                android:layout_height=”wrap_content” android:orientation=”vertical”
                android:id=”@+id/RadioImageC”>
                <RadioButton android:checked=”true” android:id=”@+id/radio_low”
                    android:text=”Low” />
                    <RadioButton android:checked=”false” android:id=”@+id/radio_normal”
                    android:text=”Normal” />
                <RadioButton android:checked=”false” android:id=”@+id/radio_high”
                    android:text=”High Detail” />
                    <RadioButton android:checked=”false” android:id=”@+id/radio_super”
                    android:text=”Super High Detail” />
            </RadioGroup>
        </ScrollView>
    </LinearLayout>
</LinearLayout>

LEAVE A REPLY

Please enter your comment!
Please enter your name here