Advertisement
Guest User

OpenColloActivity.java

a guest
Oct 17th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.14 KB | None | 0 0
  1. package com.be20innovation.conservaturichecker.open_object_activity;
  2.  
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.os.Environment;
  7. import android.provider.MediaStore;
  8. import android.support.v4.content.FileProvider;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.support.v7.widget.Toolbar;
  11. import android.text.Editable;
  12. import android.text.TextWatcher;
  13. import android.util.Log;
  14. import android.view.Menu;
  15. import android.view.View;
  16. import android.widget.Button;
  17. import android.widget.CheckBox;
  18. import android.widget.CompoundButton;
  19. import android.widget.EditText;
  20. import android.widget.RadioButton;
  21. import android.widget.RadioGroup;
  22. import android.widget.TextView;
  23.  
  24. import com.be20innovation.conservaturichecker.R;
  25. import com.be20innovation.conservaturichecker.database.DbManager;
  26. import com.be20innovation.conservaturichecker.object.Collo;
  27. import com.be20innovation.conservaturichecker.object.ColloImage;
  28. import com.be20innovation.conservaturichecker.object.Ordine;
  29. import com.be20innovation.conservaturichecker.object.Spedizione;
  30. import com.be20innovation.conservaturichecker.utility.Constants;
  31. import com.be20innovation.conservaturichecker.utility.Utility;
  32.  
  33. import java.io.File;
  34. import java.io.IOException;
  35. import java.text.SimpleDateFormat;
  36. import java.util.ArrayList;
  37. import java.util.Date;
  38. import java.util.UUID;
  39.  
  40.  
  41. public class OpenColloActivity extends AppCompatActivity{
  42.  
  43.     public final static int CAMERA_PIC_REQUEST= 1034;
  44.     DbManager db;
  45.     String currentPhotoPath;
  46.     Collo collo;
  47.     Ordine ordine;
  48.     ArrayList<ColloImage> colliImmagini  = new ArrayList<ColloImage>();
  49.     TextView textView1;
  50.     TextView textView3;
  51.     TextView textView_sequence;
  52.     TextView textView5;
  53.     TextView textView7;
  54.     TextView textView9;
  55.     TextView textView11;
  56.     TextView textView13;
  57.  
  58.     EditText editText_in;
  59.     EditText editText_out;
  60.  
  61.     RadioGroup radioGroup_in;
  62.     RadioButton radioButton_in;
  63.     RadioButton radioButton_in_no;
  64.  
  65.  
  66.     RadioGroup radioGroup_out;
  67.     RadioButton radioButton_out;
  68.     RadioButton radioButton_out_no;
  69.  
  70.     File photoFile;
  71.     Uri uri;
  72.     @Override
  73.     protected void onCreate(Bundle savedInstanceState) {
  74.         super.onCreate(savedInstanceState);
  75.         setContentView(R.layout.activity_open_collo);
  76.         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_open_collo);
  77.         setSupportActionBar(toolbar);
  78.  
  79.         TextView title = (TextView) toolbar.findViewById(R.id.toolbar_subtitle);
  80.         title.setText(R.string.title_detail_collo);
  81.  
  82.         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  83.         getSupportActionBar().setDisplayShowHomeEnabled(true);
  84.  
  85.         db = new DbManager(getApplicationContext());
  86.  
  87.         collo = new Collo();
  88.         collo.PLNRDO = getIntent().getStringExtra(Constants.extra_PLNRDO);
  89.         collo.PLNREC = getIntent().getStringExtra(Constants.extra_PLNREC);
  90.  
  91.         collo = db.getCollo(collo);
  92.         ordine = db.getOrdineCollo(collo);
  93.  
  94.  
  95.         colliImmagini = db.getColliImagesWhere(collo);
  96.         if (colliImmagini == null) {
  97.             colliImmagini = new ArrayList<ColloImage>();
  98.         }
  99.         textView1 = (TextView) findViewById(R.id.textView1);
  100.         textView1.setText(collo.PLNRDO);
  101.  
  102.  
  103.         textView3 = (TextView) findViewById(R.id.textView3);
  104.         textView3.setText(collo.PLNREC);
  105.  
  106.         textView_sequence = (TextView) findViewById(R.id.textView_sequence);
  107.         textView_sequence.setText(ordine.TDSCOR);
  108.  
  109.  
  110.         textView5 = (TextView) findViewById(R.id.textView5);
  111.         textView5.setText(collo.PLBARC);
  112.  
  113.  
  114.         textView7 = (TextView) findViewById(R.id.textView7);
  115.         textView7.setText(collo.PLDART);
  116.  
  117.  
  118.         textView9 = (TextView) findViewById(R.id.textView9);
  119.         textView9.setText(collo.PLDIM1 + "x" + collo.PLDIM2 + "x" + collo.PLDIM3);
  120.  
  121.  
  122.         textView11 = (TextView) findViewById(R.id.textView11);
  123.         textView11.setText(collo.PLDTSC + " " + collo.PLHMSC);
  124.  
  125.         radioButton_in = (RadioButton) findViewById(R.id.radioButton_in);
  126.         radioButton_in_no = (RadioButton) findViewById(R.id.radioButton_in_no);
  127.         if (collo.PLFNCA.equalsIgnoreCase(Collo.yes)){
  128.             radioButton_in_no.setSelected(true);
  129.             radioButton_in_no.toggle();
  130.         }
  131.         else {
  132.             if(!collo.PLDTSC.equalsIgnoreCase(Collo.null_date)){
  133.                 radioButton_in.setSelected(true);
  134.                 radioButton_in.toggle();
  135.             }
  136.  
  137.         }
  138.  
  139.         radioGroup_in = (RadioGroup) findViewById(R.id.radioGroup_in);
  140.         radioGroup_in.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  141.             @Override
  142.             public void onCheckedChanged(RadioGroup group, int checkedId) {
  143.  
  144.                 switch (checkedId){
  145.                     case R.id.radioButton_in:
  146.                         collo.setDate(Collo.state_in);
  147.                         collo.PLFNCA = "";
  148.                         break;
  149.  
  150.                     case R.id.radioButton_in_no:
  151.                         collo.resetDate(Collo.state_in);
  152.                         collo.PLFNCA = Collo.yes;
  153.                         break;
  154.                 }
  155.             }
  156.         });
  157.  
  158.         editText_in = (EditText) findViewById(R.id.editText_in);
  159.         editText_in.setText(collo.PLNOSC);
  160.         editText_in.addTextChangedListener(new TextWatcher() {
  161.  
  162.             @Override
  163.             public void afterTextChanged(Editable s) {}
  164.  
  165.             @Override
  166.             public void beforeTextChanged(CharSequence s, int start,
  167.                                           int count, int after) {
  168.             }
  169.  
  170.             @Override
  171.             public void onTextChanged(CharSequence s, int start,
  172.                                       int before, int count) {
  173.                 collo.PLNOSC = s.toString();
  174.             }
  175.         });
  176.  
  177.  
  178.         textView13 = (TextView) findViewById(R.id.textView13);
  179.         textView13.setText(collo.PLDTSS + " " + collo.PLHMSS);
  180.  
  181.         radioButton_out = (RadioButton) findViewById(R.id.radioButton_out);
  182.         radioButton_out_no = (RadioButton) findViewById(R.id.radioButton_out_no);
  183.         if (collo.PLFNSC.equalsIgnoreCase(Collo.yes)){
  184.             radioButton_out_no.setSelected(true);
  185.             radioButton_out_no.toggle();
  186.         }
  187.         else {
  188.             if(!collo.PLDTSS.equalsIgnoreCase(Collo.null_date)){
  189.                 radioButton_out.setSelected(true);
  190.                 radioButton_out.toggle();
  191.             }
  192.  
  193.         }
  194.  
  195.         radioGroup_out = (RadioGroup) findViewById(R.id.radioGroup_out);
  196.         radioGroup_out.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  197.             @Override
  198.             public void onCheckedChanged(RadioGroup group, int checkedId) {
  199.  
  200.                 switch (checkedId){
  201.                     case R.id.radioButton_out:
  202.                         collo.setDate(Collo.state_out);
  203.                         collo.PLFNSC = "";
  204.                         break;
  205.  
  206.                     case R.id.radioButton_out_no:
  207.                         collo.resetDate(Collo.state_out);
  208.                         collo.PLFNSC = Collo.yes;
  209.                         break;
  210.                 }
  211.             }
  212.         });
  213.  
  214.         editText_out = (EditText) findViewById(R.id.editText_out);
  215.         editText_out.setText(collo.PLNOSS);
  216.         editText_out.addTextChangedListener(new TextWatcher() {
  217.  
  218.             @Override
  219.             public void afterTextChanged(Editable s) {}
  220.  
  221.             @Override
  222.             public void beforeTextChanged(CharSequence s, int start,
  223.                                           int count, int after) {
  224.             }
  225.  
  226.             @Override
  227.             public void onTextChanged(CharSequence s, int start,
  228.                                       int before, int count) {
  229.                 collo.PLNOSS = s.toString();
  230.             }
  231.         });
  232.  
  233.  
  234.         CheckBox checkBox_error = (CheckBox) findViewById(R.id.checkBox_error);
  235.         if (collo.PLFNCO.equalsIgnoreCase(Collo.yes)){
  236.             checkBox_error.setChecked(true);
  237.         }
  238.         else {
  239.             checkBox_error.setChecked(false);
  240.         }
  241.         checkBox_error.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  242.             @Override
  243.             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  244.                 if (isChecked){
  245.                     collo.PLFNCO = Collo.yes;
  246.                 }
  247.                 else {
  248.                     collo.PLFNCO = Collo.no;
  249.                 }
  250.             }
  251.         });
  252.  
  253. /**        Button buttonShowImage = (Button) findViewById(R.id.openFoto);
  254.         if (collo.PLFOTO.equalsIgnoreCase(Collo.state_null)){
  255.             buttonShowImage.setVisibility(View.INVISIBLE);
  256.         }
  257.         else {
  258.  
  259.             buttonShowImage.setVisibility(View.VISIBLE);
  260.         }
  261.  
  262.         buttonShowImage.setOnClickListener(new View.OnClickListener() {
  263.  
  264.             public void onClick(View v) {
  265.                 Intent inf = new Intent(OpenColloActivity.this, ShowImageActivity.class);
  266.                 inf.putExtra(Constants.extra_PLNRDO, collo.PLNRDO);
  267.                 inf.putExtra(Constants.extra_PLNREC, collo.PLNREC);
  268.                 startActivity(inf);
  269.             }
  270.         });
  271. */
  272.         Button b = (Button)findViewById(R.id.openCamera);
  273.  
  274.         b.setOnClickListener(new View.OnClickListener(){
  275.             public void onClick(View v) {
  276.                 Intent takePictureIntent = new Intent(
  277.                         MediaStore.ACTION_IMAGE_CAPTURE
  278.                 );
  279.                 if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
  280.                     // Create the File where the photo should go
  281.                     File photoFile = null;
  282.                     try {
  283.                         photoFile = createImageFile();
  284.                     } catch (IOException ex) {
  285.                         Log.d("foto", "onClick: error file");
  286.                     }
  287.                     // Continue only if the File was successfully created
  288.                     if (photoFile != null) {
  289.                         Uri photoURI = FileProvider.getUriForFile(getApplicationContext(),
  290.                                 "com.be20innovation.conservaturichecker.fileprovider",
  291.                                 photoFile);
  292.                         takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
  293.                         startActivityForResult(takePictureIntent, CAMERA_PIC_REQUEST);
  294.                     }
  295.                 }
  296.             }
  297.         });
  298.  
  299.  
  300.         Button button_save_collo = (Button) findViewById(R.id.button_save_ordine);
  301.         button_save_collo.setOnClickListener(new View.OnClickListener() {
  302.             @Override
  303.             public void onClick(View v) {
  304.                 db.updateCollo(collo);
  305.                 for (ColloImage c : colliImmagini){
  306.                     if(db.getColloImage(c) == null){
  307.                         db.inserColloImages(c);
  308.                     }
  309.  
  310.                     Log.d("in loop", c.FCODIC);
  311.                 }
  312.                 Ordine ordine = db.getOrdineCollo(collo);
  313.                 ordine.updateState(getApplicationContext());
  314.  
  315.                 Spedizione spedizione = db.getSpedizioneCollo(collo);
  316.                 spedizione.updateState(getApplicationContext());
  317.  
  318.                 Utility.showToast(getApplicationContext(), getString(R.string.info_saved));
  319.  
  320.                 Intent intent = new Intent(getApplicationContext(), OpenColloActivity.class);
  321.                 intent.putExtra(Constants.extra_PLNRDO, collo.PLNRDO);
  322.                 intent.putExtra(Constants.extra_PLNREC, collo.PLNREC);
  323.                 startActivity(intent);
  324.                 finish();
  325.             }
  326.         });
  327.  
  328.     }
  329.     private File createImageFile() throws IOException {
  330.         // Create an image file name
  331.         String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
  332.         String imageFileName = "JPEG_" + timeStamp + "_";
  333.         File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
  334.         File image = File.createTempFile(
  335.                 imageFileName,  /* prefix */
  336.                 ".jpg",         /* suffix */
  337.                 storageDir      /* directory */
  338.         );
  339.  
  340.         // Save a file: path for use with ACTION_VIEW intents
  341.         currentPhotoPath = image.getAbsolutePath();
  342.         return image;
  343.     }
  344.     @Override
  345.     protected void onActivityResult(int requestCode, int resultCode,
  346.                                     Intent data) {
  347.         String name;
  348.         if (requestCode ==  CAMERA_PIC_REQUEST &&
  349.                 resultCode == RESULT_OK) {
  350.             if (resultCode == RESULT_OK) {
  351.                 /**
  352.                 Bitmap imageBitmap = BitmapFactory.decodeFile(currentPhotoPath);
  353.                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
  354.                 imageBitmap.compress(Bitmap.CompressFormat.JPEG,100,baos);
  355.                 byte[] b = baos.toByteArray();
  356.                 String encImage = Base64.encodeToString(b, Base64.DEFAULT);**/
  357.  
  358.                 name = UUID.randomUUID().toString();
  359.                 ColloImage temp = new ColloImage(name, collo.PLNRDO, collo.PLNREC, currentPhotoPath);
  360.                 colliImmagini.add(temp);
  361.             }
  362.         }
  363.     }
  364.  
  365.  
  366.     @Override
  367.     public boolean onSupportNavigateUp() {
  368.         onBackPressed();
  369.         return true;
  370.     }
  371.  
  372.     @Override
  373.     public boolean onCreateOptionsMenu(Menu menu) {
  374.         // Inflate the menu; this adds items to the action bar if it is present.
  375.         getMenuInflater().inflate(R.menu.main, menu);
  376.         return true;
  377.     }
  378.  
  379.     /*
  380.     @Override
  381.     public boolean onOptionsItemSelected(MenuItem item) {
  382.         // Handle action bar item clicks here. The action bar will
  383.         // automatically handle clicks on the Home/Up button, so long
  384.         // as you specify a parent activity in AndroidManifest.xml.
  385.         int id = item.getItemId();
  386.  
  387.         //noinspection SimplifiableIfStatement
  388.         if (id == R.id.action_settings) {
  389.             return true;
  390.         }
  391.  
  392.         return super.onOptionsItemSelected(item);
  393.     }
  394.  
  395.     */
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement