Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.be20innovation.conservaturichecker.open_object_activity;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Bundle;
- import android.os.Environment;
- import android.provider.MediaStore;
- import android.support.v4.content.FileProvider;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.Toolbar;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.util.Log;
- import android.view.Menu;
- import android.view.View;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.CompoundButton;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.TextView;
- import com.be20innovation.conservaturichecker.R;
- import com.be20innovation.conservaturichecker.database.DbManager;
- import com.be20innovation.conservaturichecker.object.Collo;
- import com.be20innovation.conservaturichecker.object.ColloImage;
- import com.be20innovation.conservaturichecker.object.Ordine;
- import com.be20innovation.conservaturichecker.object.Spedizione;
- import com.be20innovation.conservaturichecker.utility.Constants;
- import com.be20innovation.conservaturichecker.utility.Utility;
- import java.io.File;
- import java.io.IOException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.UUID;
- public class OpenColloActivity extends AppCompatActivity{
- public final static int CAMERA_PIC_REQUEST= 1034;
- DbManager db;
- String currentPhotoPath;
- Collo collo;
- Ordine ordine;
- ArrayList<ColloImage> colliImmagini = new ArrayList<ColloImage>();
- TextView textView1;
- TextView textView3;
- TextView textView_sequence;
- TextView textView5;
- TextView textView7;
- TextView textView9;
- TextView textView11;
- TextView textView13;
- EditText editText_in;
- EditText editText_out;
- RadioGroup radioGroup_in;
- RadioButton radioButton_in;
- RadioButton radioButton_in_no;
- RadioGroup radioGroup_out;
- RadioButton radioButton_out;
- RadioButton radioButton_out_no;
- File photoFile;
- Uri uri;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_open_collo);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_open_collo);
- setSupportActionBar(toolbar);
- TextView title = (TextView) toolbar.findViewById(R.id.toolbar_subtitle);
- title.setText(R.string.title_detail_collo);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- getSupportActionBar().setDisplayShowHomeEnabled(true);
- db = new DbManager(getApplicationContext());
- collo = new Collo();
- collo.PLNRDO = getIntent().getStringExtra(Constants.extra_PLNRDO);
- collo.PLNREC = getIntent().getStringExtra(Constants.extra_PLNREC);
- collo = db.getCollo(collo);
- ordine = db.getOrdineCollo(collo);
- colliImmagini = db.getColliImagesWhere(collo);
- if (colliImmagini == null) {
- colliImmagini = new ArrayList<ColloImage>();
- }
- textView1 = (TextView) findViewById(R.id.textView1);
- textView1.setText(collo.PLNRDO);
- textView3 = (TextView) findViewById(R.id.textView3);
- textView3.setText(collo.PLNREC);
- textView_sequence = (TextView) findViewById(R.id.textView_sequence);
- textView_sequence.setText(ordine.TDSCOR);
- textView5 = (TextView) findViewById(R.id.textView5);
- textView5.setText(collo.PLBARC);
- textView7 = (TextView) findViewById(R.id.textView7);
- textView7.setText(collo.PLDART);
- textView9 = (TextView) findViewById(R.id.textView9);
- textView9.setText(collo.PLDIM1 + "x" + collo.PLDIM2 + "x" + collo.PLDIM3);
- textView11 = (TextView) findViewById(R.id.textView11);
- textView11.setText(collo.PLDTSC + " " + collo.PLHMSC);
- radioButton_in = (RadioButton) findViewById(R.id.radioButton_in);
- radioButton_in_no = (RadioButton) findViewById(R.id.radioButton_in_no);
- if (collo.PLFNCA.equalsIgnoreCase(Collo.yes)){
- radioButton_in_no.setSelected(true);
- radioButton_in_no.toggle();
- }
- else {
- if(!collo.PLDTSC.equalsIgnoreCase(Collo.null_date)){
- radioButton_in.setSelected(true);
- radioButton_in.toggle();
- }
- }
- radioGroup_in = (RadioGroup) findViewById(R.id.radioGroup_in);
- radioGroup_in.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(RadioGroup group, int checkedId) {
- switch (checkedId){
- case R.id.radioButton_in:
- collo.setDate(Collo.state_in);
- collo.PLFNCA = "";
- break;
- case R.id.radioButton_in_no:
- collo.resetDate(Collo.state_in);
- collo.PLFNCA = Collo.yes;
- break;
- }
- }
- });
- editText_in = (EditText) findViewById(R.id.editText_in);
- editText_in.setText(collo.PLNOSC);
- editText_in.addTextChangedListener(new TextWatcher() {
- @Override
- public void afterTextChanged(Editable s) {}
- @Override
- public void beforeTextChanged(CharSequence s, int start,
- int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start,
- int before, int count) {
- collo.PLNOSC = s.toString();
- }
- });
- textView13 = (TextView) findViewById(R.id.textView13);
- textView13.setText(collo.PLDTSS + " " + collo.PLHMSS);
- radioButton_out = (RadioButton) findViewById(R.id.radioButton_out);
- radioButton_out_no = (RadioButton) findViewById(R.id.radioButton_out_no);
- if (collo.PLFNSC.equalsIgnoreCase(Collo.yes)){
- radioButton_out_no.setSelected(true);
- radioButton_out_no.toggle();
- }
- else {
- if(!collo.PLDTSS.equalsIgnoreCase(Collo.null_date)){
- radioButton_out.setSelected(true);
- radioButton_out.toggle();
- }
- }
- radioGroup_out = (RadioGroup) findViewById(R.id.radioGroup_out);
- radioGroup_out.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(RadioGroup group, int checkedId) {
- switch (checkedId){
- case R.id.radioButton_out:
- collo.setDate(Collo.state_out);
- collo.PLFNSC = "";
- break;
- case R.id.radioButton_out_no:
- collo.resetDate(Collo.state_out);
- collo.PLFNSC = Collo.yes;
- break;
- }
- }
- });
- editText_out = (EditText) findViewById(R.id.editText_out);
- editText_out.setText(collo.PLNOSS);
- editText_out.addTextChangedListener(new TextWatcher() {
- @Override
- public void afterTextChanged(Editable s) {}
- @Override
- public void beforeTextChanged(CharSequence s, int start,
- int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start,
- int before, int count) {
- collo.PLNOSS = s.toString();
- }
- });
- CheckBox checkBox_error = (CheckBox) findViewById(R.id.checkBox_error);
- if (collo.PLFNCO.equalsIgnoreCase(Collo.yes)){
- checkBox_error.setChecked(true);
- }
- else {
- checkBox_error.setChecked(false);
- }
- checkBox_error.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (isChecked){
- collo.PLFNCO = Collo.yes;
- }
- else {
- collo.PLFNCO = Collo.no;
- }
- }
- });
- /** Button buttonShowImage = (Button) findViewById(R.id.openFoto);
- if (collo.PLFOTO.equalsIgnoreCase(Collo.state_null)){
- buttonShowImage.setVisibility(View.INVISIBLE);
- }
- else {
- buttonShowImage.setVisibility(View.VISIBLE);
- }
- buttonShowImage.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- Intent inf = new Intent(OpenColloActivity.this, ShowImageActivity.class);
- inf.putExtra(Constants.extra_PLNRDO, collo.PLNRDO);
- inf.putExtra(Constants.extra_PLNREC, collo.PLNREC);
- startActivity(inf);
- }
- });
- */
- Button b = (Button)findViewById(R.id.openCamera);
- b.setOnClickListener(new View.OnClickListener(){
- public void onClick(View v) {
- Intent takePictureIntent = new Intent(
- MediaStore.ACTION_IMAGE_CAPTURE
- );
- if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
- // Create the File where the photo should go
- File photoFile = null;
- try {
- photoFile = createImageFile();
- } catch (IOException ex) {
- Log.d("foto", "onClick: error file");
- }
- // Continue only if the File was successfully created
- if (photoFile != null) {
- Uri photoURI = FileProvider.getUriForFile(getApplicationContext(),
- "com.be20innovation.conservaturichecker.fileprovider",
- photoFile);
- takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
- startActivityForResult(takePictureIntent, CAMERA_PIC_REQUEST);
- }
- }
- }
- });
- Button button_save_collo = (Button) findViewById(R.id.button_save_ordine);
- button_save_collo.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- db.updateCollo(collo);
- for (ColloImage c : colliImmagini){
- if(db.getColloImage(c) == null){
- db.inserColloImages(c);
- }
- Log.d("in loop", c.FCODIC);
- }
- Ordine ordine = db.getOrdineCollo(collo);
- ordine.updateState(getApplicationContext());
- Spedizione spedizione = db.getSpedizioneCollo(collo);
- spedizione.updateState(getApplicationContext());
- Utility.showToast(getApplicationContext(), getString(R.string.info_saved));
- Intent intent = new Intent(getApplicationContext(), OpenColloActivity.class);
- intent.putExtra(Constants.extra_PLNRDO, collo.PLNRDO);
- intent.putExtra(Constants.extra_PLNREC, collo.PLNREC);
- startActivity(intent);
- finish();
- }
- });
- }
- private File createImageFile() throws IOException {
- // Create an image file name
- String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
- String imageFileName = "JPEG_" + timeStamp + "_";
- File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
- File image = File.createTempFile(
- imageFileName, /* prefix */
- ".jpg", /* suffix */
- storageDir /* directory */
- );
- // Save a file: path for use with ACTION_VIEW intents
- currentPhotoPath = image.getAbsolutePath();
- return image;
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode,
- Intent data) {
- String name;
- if (requestCode == CAMERA_PIC_REQUEST &&
- resultCode == RESULT_OK) {
- if (resultCode == RESULT_OK) {
- /**
- Bitmap imageBitmap = BitmapFactory.decodeFile(currentPhotoPath);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- imageBitmap.compress(Bitmap.CompressFormat.JPEG,100,baos);
- byte[] b = baos.toByteArray();
- String encImage = Base64.encodeToString(b, Base64.DEFAULT);**/
- name = UUID.randomUUID().toString();
- ColloImage temp = new ColloImage(name, collo.PLNRDO, collo.PLNREC, currentPhotoPath);
- colliImmagini.add(temp);
- }
- }
- }
- @Override
- public boolean onSupportNavigateUp() {
- onBackPressed();
- return true;
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- /*
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement