Advertisement
markella92

Untitled

May 24th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 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. FileOutputStream fOut = new FileOutputStream(file);
  103.  
  104. PdfWriter.getInstance(doc, fOut);
  105.  
  106. // open the document
  107. doc.open();
  108. ByteArrayOutputStream stream = new ByteArrayOutputStream();
  109. Bitmap bitmap = BitmapFactory.decodeResource(getContext()
  110. .getResources(), R.drawable.androtuto);
  111. bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  112. Image myImg = Image.getInstance(stream.toByteArray());
  113. myImg.setAlignment(Image.MIDDLE);
  114.  
  115. // add image to document
  116. doc.add(myImg);
  117.  
  118. Paragraph p1 = new Paragraph(myInt);
  119. Log.d("ciao",myInt);
  120.  
  121. Font paraFont = new Font(Font.COURIER);
  122. p1.setAlignment(Paragraph.ALIGN_CENTER);
  123. p1.setFont(paraFont);
  124.  
  125. // add paragraph to document
  126. doc.add(p1);
  127.  
  128. Paragraph p2 = new Paragraph("Ciao");
  129. Font paraFont2 = new Font(Font.COURIER, 14.0f, Color.GREEN);
  130. p2.setAlignment(Paragraph.ALIGN_CENTER);
  131. p2.setFont(paraFont2);
  132.  
  133. doc.add(p2);
  134.  
  135. stream = new ByteArrayOutputStream();
  136. bitmap = BitmapFactory.decodeResource(getContext()
  137. .getResources(), R.drawable.android);
  138. bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  139. myImg = Image.getInstance(stream.toByteArray());
  140. myImg.setAlignment(Image.MIDDLE);
  141.  
  142. // add image to document
  143. doc.add(myImg);
  144.  
  145. // set footer
  146. Phrase footerText = new Phrase("Pied de page ");
  147. HeaderFooter pdfFooter = new HeaderFooter(footerText, false);
  148. doc.setFooter(pdfFooter);
  149.  
  150. } catch (DocumentException de) {
  151. Log.e("PDFCreator", "DocumentException:" + de);
  152. } catch (IOException e) {
  153. Log.e("PDFCreator", "ioException:" + e);
  154. } finally {
  155. doc.close();
  156. }
  157.  
  158. }
  159. public void viewPDF(){
  160. String path = "/sdcard/droidText/sample.pdf";
  161. File targetFile = new File(path);
  162. Uri targetUri = Uri.fromFile(targetFile);
  163.  
  164. Intent intent;
  165. intent = new Intent(Intent.ACTION_VIEW);
  166. intent.setDataAndType(targetUri, "application/pdf");
  167.  
  168. startActivity(intent);
  169. }
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement