Advertisement
markella92

Untitled

May 24th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. public class TwoFragment extends Fragment{
  2.  
  3. private View v;
  4. Intent chooser=null;
  5. String myInt="";
  6.  
  7. public TwoFragment() {
  8. // Required empty public constructor
  9. }
  10.  
  11. @Override
  12. public void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. }
  15.  
  16. @Override
  17. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  18. Bundle savedInstanceState) {
  19. // Inflate the layout for this fragment
  20. View rootView = inflater.inflate(R.layout.fragment_two, container, false);
  21. Button mButton = (Button) rootView.findViewById(R.id.newbutton);
  22. mButton.setOnClickListener(new View.OnClickListener() {
  23. public void onClick(View v) {
  24.  
  25. //sendemail();
  26. createPDF();
  27. viewPDF();
  28.  
  29.  
  30.  
  31. }
  32. });
  33. TextView titolo3 = (TextView)rootView.findViewById(R.id.result);
  34. TextView titolo2 = (TextView)rootView.findViewById(R.id.result2);
  35. TextView titolo4 = (TextView)rootView.findViewById(R.id.resultpizze);
  36.  
  37. //TextView titolo = (TextView)rootView.findViewById(R.id.quantità3);
  38.  
  39. /* Bundle bundle2=getArguments();
  40. if(bundle2 != null){
  41. String string = bundle2.getString("scelta2", null);
  42. titolo3.setText(string);
  43. }*/
  44.  
  45. Bundle bundle2=getArguments();
  46. if(bundle2 != null){
  47. myInt = bundle2.getString("scelta2", null);
  48. titolo3.setText(myInt);
  49. }
  50.  
  51. Bundle bundle3=getArguments();
  52. if(bundle3 != null){
  53. // String myInt3 = bundle3.getString("totalebirre", null);
  54. // cazzo2=Integer.parseInt(myInt3);
  55. int cazzo2=bundle3.getInt("totalebirre");
  56. titolo2.setText(String.valueOf(cazzo2));
  57.  
  58.  
  59.  
  60. }
  61. Bundle bundle=getArguments();
  62. if(bundle != null){
  63. // String myInt2 = bundle2.getString("totalepizze", null);
  64. // cazzo=Integer.parseInt(myInt2);
  65. //titolo2.setText(myInt2);
  66. String string=bundle.getString("scelta3", null);
  67. titolo4.setText(string);
  68.  
  69. }
  70.  
  71.  
  72.  
  73. return rootView;
  74. }
  75. /* public void sendemail(){
  76.  
  77. Intent intent = new Intent(Intent.ACTION_SEND);
  78. intent.setData(Uri.parse("mailto:"));
  79. String[] to={"marco_marcoletto@hotmail.it"};
  80. intent.putExtra(Intent.EXTRA_EMAIL,to);
  81. intent.putExtra(Intent.EXTRA_SUBJECT, "ciao");
  82. intent.putExtra(Intent.EXTRA_TEXT, "zao");
  83. intent.setType("message/rfc822");
  84. chooser=intent.createChooser(intent,"manda email");
  85. startActivity(chooser);
  86. }*/
  87. public void createPDF() {
  88.  
  89. Document doc = new Document();
  90.  
  91. try {
  92. String path = Environment.getExternalStorageDirectory()
  93. .getAbsolutePath() + "/droidText";
  94.  
  95. File dir = new File(path);
  96. if (!dir.exists())
  97. dir.mkdirs();
  98.  
  99. Log.d("PDFCreator", "PDF Path: " + path);
  100.  
  101. //File file = new File(dir, "sample.pdf");
  102. File file = new File(dir, "salve.pdf");
  103.  
  104. FileOutputStream fOut = new FileOutputStream(file);
  105.  
  106. PdfWriter.getInstance(doc, fOut);
  107.  
  108. // open the document
  109. doc.open();
  110. ByteArrayOutputStream stream = new ByteArrayOutputStream();
  111. Bitmap bitmap = BitmapFactory.decodeResource(getContext()
  112. .getResources(), R.drawable.androtuto);
  113. bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  114. Image myImg = Image.getInstance(stream.toByteArray());
  115. myImg.setAlignment(Image.MIDDLE);
  116.  
  117. // add image to document
  118. doc.add(myImg);
  119.  
  120. Paragraph p1 = new Paragraph(myInt);
  121. p1.add(myInt);
  122. System.out.println(myInt);
  123. Font paraFont = new Font(Font.COURIER);
  124. p1.setAlignment(Paragraph.ALIGN_CENTER);
  125. p1.setFont(paraFont);
  126.  
  127. // add paragraph to document
  128. doc.add(p1);
  129.  
  130. Paragraph p2 = new Paragraph("Bonjour Android Tuto");
  131. Font paraFont2 = new Font(Font.COURIER, 14.0f, Color.GREEN);
  132. p2.setAlignment(Paragraph.ALIGN_CENTER);
  133. p2.setFont(paraFont2);
  134.  
  135. doc.add(p2);
  136.  
  137. stream = new ByteArrayOutputStream();
  138. bitmap = BitmapFactory.decodeResource(getContext()
  139. .getResources(), R.drawable.android);
  140. bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  141. myImg = Image.getInstance(stream.toByteArray());
  142. myImg.setAlignment(Image.MIDDLE);
  143.  
  144. // add image to document
  145. doc.add(myImg);
  146.  
  147. // set footer
  148. Phrase footerText = new Phrase("Pied de page ");
  149. HeaderFooter pdfFooter = new HeaderFooter(footerText, false);
  150. doc.setFooter(pdfFooter);
  151.  
  152. } catch (DocumentException de) {
  153. Log.e("PDFCreator", "DocumentException:" + de);
  154. } catch (IOException e) {
  155. Log.e("PDFCreator", "ioException:" + e);
  156. } finally {
  157. doc.close();
  158. }
  159.  
  160. }
  161. public void viewPDF(){
  162. String path = "/sdcard/droidText/salve.pdf";
  163. File targetFile = new File(path);
  164. Uri targetUri = Uri.fromFile(targetFile);
  165.  
  166. Intent intent;
  167. intent = new Intent(Intent.ACTION_VIEW);
  168. intent.setDataAndType(targetUri, "application/pdf");
  169.  
  170. startActivity(intent);
  171. }
  172.  
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement