@OnClick(R.id.picReadyButton) void picTakerReady() { _picTakerService.submitReady(_picFrameNumber); _registerStepContainer.setVisibility(View.GONE); _submitOrderStepContainer.setVisibility(View.GONE); _readyStepContainer.setVisibility(View.GONE); initializeCamera(); }
@Override protected void onStop() { super.onStop(); if (_picTakerService != null) { // TODO: If we want the master app to accurately update ordered and ready PicTaker counts, we // TODO: would need to send along a "isReady" boolean value along with this call _picTakerService.submitUnRegister(_picFrameNumber); } if (_systemCamera != null) { _systemCamera.release(); } }
@OnClick(R.id.picRegisterButton) void startPicRegister() { String ipAddr = _serverAddrEditText.getText().toString(); _appPrefs.edit().putString(PicTakerService.PICTAKER_HOST_IP_PREF, ipAddr).apply(); _picTakerService = new PicTakerService(ipAddr); _picTakerService .subscribeConnection() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( pair -> handleServerMessage(pair.first, pair.second), err -> Toast.makeText( this, getString(R.string.server_connect_error_message), Toast.LENGTH_LONG) .show()); InputMethodManager inputMethodManager = (InputMethodManager) PicTakerActivity.this.getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow( PicTakerActivity.this.getCurrentFocus().getWindowToken(), 0); }
@Override public void onPictureTaken(byte[] bytes, Camera camera) { _capturedImageBytes = bytes; String fileName = "FT3D_" + _picFrameNumber + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()).toString() + ".jpg"; File sdRoot = Environment.getExternalStorageDirectory(); String dir = "/FT3D/"; File mkDir = new File(sdRoot, dir); mkDir.mkdirs(); File pictureFile = new File(sdRoot, dir + fileName); try { FileOutputStream purge = new FileOutputStream(pictureFile); purge.write(bytes); purge.close(); } catch (FileNotFoundException e) { Log.d("DG_DEBUG", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("DG_DEBUG", "Error accessing file: " + e.getMessage()); } AsyncHttpPost reqPost = new AsyncHttpPost("http://" + _picTakerService.getServerIP() + ":7373/fileUpload"); MultipartFormDataBody body = new MultipartFormDataBody(); body.addFilePart("framePic", pictureFile); body.addStringPart("frameNumber", String.valueOf(_picFrameNumber)); reqPost.setBody(body); Future<String> uploadReturn = AsyncHttpClient.getDefaultInstance().executeString(reqPost); uploadReturn.setCallback( new FutureCallback<String>() { @Override public void onCompleted(Exception e, String s) { if (_uploadingDialog != null) { _uploadingDialog.cancel(); } if (_systemCamera != null) { _systemCamera.release(); } _mainLayout.removeView(_cameraPreviewWindow); _registerStepContainer.setVisibility(View.VISIBLE); _submitOrderStepContainer.setVisibility(View.VISIBLE); _readyStepContainer.setVisibility(View.VISIBLE); _framePreviewImageView.setImageBitmap( BitmapFactory.decodeByteArray( _capturedImageBytes, 0, _capturedImageBytes.length)); _framePreviewImageView.setVisibility(View.VISIBLE); _picReadyButton.setVisibility(View.GONE); } }); try { _uploadingDialog = ProgressDialog.show( PicTakerActivity.this, "Uploading Frame", "Uploading your frame to FT3D server."); uploadReturn.get(); } catch (Exception e) { // Do we need to handle the specific timeout exception? e.printStackTrace(); } }
@OnClick(R.id.submitPicOrderButton) void submitPicOrder() { _picTakerService.submitOrder(); }