Package com. cons. dcg. collect;
Import java. io. File;
Import java. text. SimpleDateFormat;
Import java. util. ArrayList;
Import java. util. Date;
Import java. util. HashMap;
Import java. util. List;
Import android. app. Activity;
Import android. app. Notification;
Import android. app. icationicationmanager;
Import android. app. PendingIntent;
Import android. app. ProgressDialog;
Import android. content. Intent;
Import android. database. Cursor;
Import android.net. Uri;
Import android. OS. AsyncTask;
Import android. OS. Bundle;
Import android. OS. Environment;
Import android. provider. MediaStore;
Import android. view. KeyEvent;
Import android. view. Menu;
Import android. view. MenuInflater;
Import android. view. MenuItem;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. AdapterView;
Import android. widget. ArrayAdapter;
Import android. widget. Button;
Import android. widget. EditText;
Import android. widget. Spinner;
Import android. widget. Toast;
Public class ProblemReport extends Activity implements OnClickListener {
Private static final int RESULT_CAPTURE_IMAGE = 1; // The requestCode of the photo.
Private static final int REQUEST_CODE_TAKE_VIDEO = 2; // The requestCode of the camera.
Private static final int RESULT_CAPTURE_RECORDER_SOUND = 3; // The requestCode of the recording
Private String strImgPath = ""; // absolute path of the photo file
Private String strVideoPath = ""; // absolute path of the video file
Private String strRecorderPath = ""; // absolute path of the recording file
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
This. setContentView (R. layout. problem_report );
}
@ Override
Protected void onActivityResult (int requestCode, int resultCode, Intent data ){
Super. onActivityResult (requestCode, resultCode, data );
Switch (requestCode ){
Case RESULT_CAPTURE_IMAGE: // take a photo
If (resultCode = RESULT_ OK ){
Toast. makeText (this, strImgPath, Toast. LENGTH_SHORT). show ();
}
Break;
Case REQUEST_CODE_TAKE_VIDEO: // video shooting
If (resultCode = RESULT_ OK ){
Uri uriVideo = data. getData ();
Cursor cursor = this. getContentResolver (). query (uriVideo, null );
If (cursor. moveToNext ()){
/* _ Data: absolute path of the file, _ display_name: file name */
StrVideoPath = cursor. getString (cursor. getColumnIndex ("_ data "));
Toast. makeText (this, strVideoPath, Toast. LENGTH_SHORT). show ();
}
}
Break;
Case RESULT_CAPTURE_RECORDER_SOUND: // recording
If (resultCode = RESULT_ OK ){
Uri uriRecorder = data. getData ();
Cursor cursor = this. getContentResolver (). query (uriRecorder, null );
If (cursor. moveToNext ()){
/* _ Data: absolute path of the file, _ display_name: file name */
StrRecorderPath = cursor. getString (cursor. getColumnIndex ("_ data "));
Toast. makeText (this, strRecorderPath, Toast. LENGTH_SHORT). show ();
}
}
Break;
}
}
/**
* Photography
*/
Private void cameraMethod (){
Intent imageCaptureIntent = new Intent (MediaStore. ACTION_IMAGE_CAPTURE );
StrImgPath = Environment. getExternalStorageDirectory (). toString () + "/CONSDCGMPIC/"; // folder for storing photos
String fileName = new SimpleDateFormat ("yyyyMMddHHmmss"). format (new Date () + ". jpg"; // name the photo
File out = new File (strImgPath );
If (! Out. exists ()){
Out. mkdirs ();
}
Out = new File (strImgPath, fileName );
StrImgPath = strImgPath + fileName; // the absolute path of the photo
Uri uri = Uri. fromFile (out );
ImageCaptureIntent. putExtra (MediaStore. EXTRA_OUTPUT, uri );
ImageCaptureIntent. putExtra (MediaStore. EXTRA_VIDEO_QUALITY, 1 );
StartActivityForResult (imageCaptureIntent, RESULT_CAPTURE_IMAGE );
}
/**
* Video shooting
*/
Private void videoMethod (){
Intent intent = new Intent (MediaStore. ACTION_VIDEO_CAPTURE );
Intent. putExtra (MediaStore. EXTRA_VIDEO_QUALITY, 0 );
StartActivityForResult (intent, REQUEST_CODE_TAKE_VIDEO );
}
/**
* Recording function
*/
Private void soundRecorderMethod (){
Intent intent = new Intent (Intent. ACTION_GET_CONTENT );
Intent. setType ("audio/amr ");
StartActivityForResult (intent, RESULT_CAPTURE_RECORDER_SOUND );
}
/**
* Prompt information
* @ Param text
* @ Param duration
*/
Private void showToast (String text, int duration ){
Toast. makeText (ProblemReport. this, text, duration). show ();
}
}