Guest User

Untitled

a guest
May 29th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. package br.com.diego.tecnologiadanet.fragments;
  2.  
  3.  
  4.  
  5. Spinner option;
  6. Button btnSend;
  7. EditText Nome;
  8. EditText Message;
  9. EditText Endereco;
  10. EditText Telefone;
  11. EditText Email;
  12. ImageView img;
  13. private Bitmap bitmap;
  14.  
  15.  
  16. @Override
  17. public View onCreateView(LayoutInflater inflater,
  18. ViewGroup container,
  19. Bundle savedInstanceState) {
  20. View view = inflater.inflate(R.layout.reclame, container, false);
  21.  
  22. img = (ImageView) view.findViewById(R.id.imageButton);
  23. img.setOnClickListener(new View.OnClickListener() {
  24. @Override
  25. public void onClick(View v) {
  26. abrirCamera();
  27. }
  28. });
  29.  
  30. Nome = (EditText) view.findViewById(R.id.nome1);
  31. Message = (EditText) view.findViewById(R.id.msg);
  32. Endereco = (EditText) view.findViewById(R.id.endereco);
  33. Telefone = (EditText) view.findViewById(R.id.telefone);
  34. Email = (EditText) view.findViewById(R.id.email);
  35. btnSend = (Button) view.findViewById(R.id.send);
  36. option = (Spinner)view.findViewById(R.id.spinner);
  37. img = (ImageView)view.findViewById(R.id.imageButton);
  38. option.setOnItemSelectedListener(this);
  39. ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.option, android.R.layout.simple_spinner_item);
  40. option.setAdapter(adapter);
  41.  
  42. btnSend.setOnClickListener(new View.OnClickListener() {
  43. @Override
  44. public void onClick(View v) {
  45.  
  46. String nome = Nome.getText().toString();
  47. String message = Message.getText().toString();
  48. String matricula = Endereco.getText().toString();
  49. String telefone = Telefone.getText().toString();
  50. String assunto = option.getSelectedItem().toString();
  51. String ema = Email.getText().toString();
  52. Intent email = new Intent(Intent.ACTION_SEND);
  53. email.putExtra(Intent.EXTRA_EMAIL, new String[]{"marcos@wfprojetos.com.br"});
  54. email.putExtra(Intent.EXTRA_SUBJECT, assunto);
  55. email.putExtra(Intent.EXTRA_TEXT, "Nome: " +nome +'n'+ "Endereço: "+matricula + 'n'+ "Telefone: "+telefone + 'n'+ "E-mail: "+ema + 'n'+ 'n'+message);
  56. email.setType("image/jpeg");
  57. File bitmapFile = new File(Environment.getExternalStorageDirectory()+"/image.jpg");
  58. Uri myUri = Uri.fromFile(bitmapFile);
  59. email.putExtra(Intent.EXTRA_STREAM, myUri);
  60.  
  61. email.setType("message/rfc822");
  62. startActivity(Intent.createChooser(email, "Selecione o serviço de e-mail:"));
  63. }
  64. });
  65. return view;
  66. }
  67.  
  68. @Override
  69. public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  70. TextView mtext = (TextView) view;
  71. //Toast.makeText(getActivity(), "Você selecionou: "+mtext.getText(), Toast.LENGTH_SHORT).show();
  72. }
  73.  
  74. @Override
  75. public void onNothingSelected(AdapterView<?> parent) {
  76.  
  77. }
  78.  
  79. public void abrirCamera(){
  80. Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  81. startActivityForResult(intent, 0);
  82. }
  83.  
  84. public void onActivityResult(int requestCode, int resultCode, Intent data){
  85. super.onActivityResult(requestCode, resultCode, data);
  86. InputStream stream = null;
  87.  
  88. if(requestCode == 0 && resultCode == Activity.RESULT_OK){
  89. try {
  90. if(bitmap != null){
  91. bitmap.recycle();
  92. }
  93. stream = getActivity().getContentResolver().openInputStream(data.getData());
  94. // bitmap = BitmapFactory.decodeStream(stream);
  95. //img.setImageBitmap(resizeImage(getActivity(), bitmap, 700, 600));
  96. }catch (FileNotFoundException e){
  97. e.printStackTrace();
  98. }finally {
  99. if (stream != null)
  100. try {
  101. stream.close();
  102. } catch (IOException e) {
  103. e.printStackTrace();
  104. }
  105. }
  106. }
  107. }
  108.  
  109.  
  110.  
  111. private static Bitmap resizeImage (Context context, Bitmap bpmOriginal, float newWidth, float newHeight){
  112. Bitmap novoBpm = null;
  113. int w = bpmOriginal.getWidth();
  114. int h = bpmOriginal.getHeight();
  115. float densityFactor = context.getResources().getDisplayMetrics().density;
  116. float novoW = newWidth * densityFactor;
  117. float novoH = newHeight * densityFactor;
  118.  
  119. float scalaW = novoW /w;
  120. float scalaH = novoH /h;
  121. Matrix matrix = new Matrix();
  122. matrix.postScale(scalaW, scalaH);
  123. novoBpm = Bitmap.createBitmap(bpmOriginal, 0, 0, w, h, matrix, true);
  124. return novoBpm;
  125. }
Add Comment
Please, Sign In to add comment