Advertisement
markella92

Untitled

May 25th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.50 KB | None | 0 0
  1. public class TwoFragment extends Fragment {
  2.  
  3. private View v;
  4. String myInt="";
  5. int cazzo2;
  6. String scelta3;
  7.  
  8. public TwoFragment() {
  9. // Required empty public constructor
  10. }
  11. public static TwoFragment getInstance(String myInt,int cazzo2,String scelta3){
  12. TwoFragment twoFragment=new TwoFragment();
  13. twoFragment.myInt=myInt;
  14. twoFragment.cazzo2=cazzo2;
  15. twoFragment.scelta3=scelta3;
  16. return twoFragment;
  17. }
  18.  
  19. @Override
  20. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  21. Bundle savedInstanceState) {
  22. // Inflate the layout for this fragment
  23. View rootView = inflater.inflate(R.layout.fragment_two, container, false);
  24. Button mButton = (Button) rootView.findViewById(R.id.newbutton);
  25. mButton.setOnClickListener(new View.OnClickListener() {
  26. public void onClick(View v) {
  27.  
  28. //sendemail();
  29. createPDF();
  30. viewPDF();
  31.  
  32.  
  33.  
  34. }
  35. });
  36. TextView titolo3 = (TextView)rootView.findViewById(R.id.result);
  37. TextView titolo2 = (TextView)rootView.findViewById(R.id.result2);
  38. TextView titolo4 = (TextView)rootView.findViewById(R.id.resultpizze);
  39.  
  40. titolo3.setText(myInt);
  41. titolo2.setText(String.valueOf(cazzo2));
  42. titolo4.setText(scelta3);
  43.  
  44. return rootView;
  45. }
  46. /* public void sendemail(){
  47.  
  48. Intent intent = new Intent(Intent.ACTION_SEND);
  49. intent.setData(Uri.parse("mailto:"));
  50. String[] to={"marco_marcoletto@hotmail.it"};
  51. intent.putExtra(Intent.EXTRA_EMAIL,to);
  52. intent.putExtra(Intent.EXTRA_SUBJECT, "ciao");
  53. intent.putExtra(Intent.EXTRA_TEXT, "zao");
  54. intent.setType("message/rfc822");
  55. chooser=intent.createChooser(intent,"manda email");
  56. startActivity(chooser);
  57. }*/
  58. public void createPDF() {
  59.  
  60. Document doc = new Document();
  61.  
  62. try {
  63. String path = Environment.getExternalStorageDirectory()
  64. .getAbsolutePath() + "/droidText";
  65.  
  66. File dir = new File(path);
  67. if (!dir.exists())
  68. dir.mkdirs();
  69.  
  70. Log.d("PDFCreator", "PDF Path: " + path);
  71.  
  72. File file = new File(dir, "sample.pdf");
  73. FileOutputStream fOut = new FileOutputStream(file);
  74.  
  75. PdfWriter.getInstance(doc, fOut);
  76.  
  77. // open the document
  78. doc.open();
  79. ByteArrayOutputStream stream = new ByteArrayOutputStream();
  80. Bitmap bitmap = BitmapFactory.decodeResource(getContext()
  81. .getResources(), R.drawable.androtuto);
  82. bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  83. Image myImg = Image.getInstance(stream.toByteArray());
  84. myImg.setAlignment(Image.MIDDLE);
  85.  
  86. // add image to document
  87. doc.add(myImg);
  88.  
  89. Paragraph p1 = new Paragraph(myInt);
  90. Log.d("ciao",myInt);
  91.  
  92. Font paraFont = new Font(Font.COURIER);
  93. p1.setAlignment(Paragraph.ALIGN_CENTER);
  94. p1.setFont(paraFont);
  95.  
  96. // add paragraph to document
  97. doc.add(p1);
  98.  
  99. Paragraph p2 = new Paragraph("Ciao");
  100. Font paraFont2 = new Font(Font.COURIER, 14.0f, Color.GREEN);
  101. p2.setAlignment(Paragraph.ALIGN_CENTER);
  102. p2.setFont(paraFont2);
  103.  
  104. doc.add(p2);
  105.  
  106. stream = new ByteArrayOutputStream();
  107. bitmap = BitmapFactory.decodeResource(getContext()
  108. .getResources(), R.drawable.android);
  109. bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  110. myImg = Image.getInstance(stream.toByteArray());
  111. myImg.setAlignment(Image.MIDDLE);
  112.  
  113. // add image to document
  114. doc.add(myImg);
  115.  
  116. // set footer
  117. Phrase footerText = new Phrase("Pied de page ");
  118. HeaderFooter pdfFooter = new HeaderFooter(footerText, false);
  119. doc.setFooter(pdfFooter);
  120.  
  121. } catch (DocumentException de) {
  122. Log.e("PDFCreator", "DocumentException:" + de);
  123. } catch (IOException e) {
  124. Log.e("PDFCreator", "ioException:" + e);
  125. } finally {
  126. doc.close();
  127. }
  128.  
  129. }
  130. public void viewPDF(){
  131. String path = "/sdcard/droidText/sample.pdf";
  132. File targetFile = new File(path);
  133. Uri targetUri = Uri.fromFile(targetFile);
  134.  
  135. Intent intent;
  136. intent = new Intent(Intent.ACTION_VIEW);
  137. intent.setDataAndType(targetUri, "application/pdf");
  138.  
  139. startActivity(intent);
  140. }
  141.  
  142. }
  143.  
  144.  
  145. OTHER FRAGMENT:
  146.  
  147. public class ThreeFragment extends Fragment implements
  148. android.widget.CompoundButton.OnCheckedChangeListener {
  149.  
  150. ListView lv2;
  151. ArrayList<Planet> planetList;
  152. ListView lv;
  153.  
  154. ArrayList<Birra> birraList;
  155. BirraAdapter biAdapter;
  156. PlanetAdapter plAdapter;
  157. Planet p;
  158. String myInt="";
  159.  
  160.  
  161.  
  162. PlanetAdapter.PlanetHolder holder;
  163.  
  164.  
  165. public ThreeFragment() {
  166. // Required empty public constructor
  167. }
  168.  
  169.  
  170. @Override
  171. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  172. Bundle savedInstanceState) {
  173. // Inflate the layout for this fragment
  174.  
  175. final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_three, container, false);
  176.  
  177. Button mButton = (Button) rootView.findViewById(R.id.button2);
  178. mButton.setOnClickListener(new View.OnClickListener() {
  179. public void onClick(View v) {
  180. MyListFragment mlf=new MyListFragment();
  181.  
  182. mlf.showResult(v);
  183. // MyListFragment.showResult(v);
  184. showResult2(v);
  185.  
  186.  
  187. }
  188. });
  189. //return inflater.inflate(R.layout.fragment_list2, container, false);
  190. return rootView;
  191. }
  192.  
  193.  
  194. @Override
  195. public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  196. super.onViewCreated(view, savedInstanceState);
  197.  
  198. lv2 = (ListView) getView().findViewById(R.id.listview2);
  199. displayBirraList();
  200. }
  201.  
  202.  
  203. private void displayBirraList() {
  204.  
  205. birraList = new ArrayList<Birra>();
  206. birraList.add(new Birra("Paulaner", 6, "€"));
  207. birraList.add(new Birra("Forst", 7, "€"));
  208. birraList.add(new Birra("Peroni", 5, "€"));
  209. birraList.add(new Birra("Corona", 5, "€"));
  210. birraList.add(new Birra("Nastro Azzurro", 4, "€"));
  211. biAdapter = new BirraAdapter(birraList, getContext()) {
  212. @Override
  213. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  214. int pos = lv2.getPositionForView(buttonView);
  215. if (pos != ListView.INVALID_POSITION) {
  216. Birra b = birraList.get(pos);
  217. b.setSelected(isChecked);
  218.  
  219.  
  220. /*Toast.makeText(
  221. getActivity(),
  222. "Clicked on Pizza: " + p.getName() + ". State: is "
  223. + isChecked, Toast.LENGTH_SHORT).show();*/
  224. }
  225.  
  226.  
  227. }
  228.  
  229.  
  230. };
  231.  
  232.  
  233. lv2.setAdapter(biAdapter);
  234. }
  235.  
  236.  
  237. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  238.  
  239.  
  240. /*int pos = lv.getPositionForView(buttonView);
  241. if (pos != ListView.INVALID_POSITION) {
  242. Planet p = planetList.get(pos);
  243. p.setSelected(isChecked);
  244.  
  245.  
  246. *//**//**//**//*Toast.makeText(
  247. getActivity(),
  248. "Clicked on Planet: " + p.getName() + ". State: is "
  249. + isChecked, Toast.LENGTH_SHORT).show();*//**//**//**//*
  250. }
  251. */
  252. }
  253.  
  254.  
  255. public void showResult2(View v) {
  256. String result = "Selected Product are :";
  257. int totalAmount = 0;
  258. // String a = "";
  259.  
  260.  
  261. for (Birra b : biAdapter.getBox()) {
  262.  
  263. if (b.selected) {
  264.  
  265. result += "\n" + b.name + " " + b.distance + "€" + "q.tà :" + b.getQuantità();
  266. int quantitaInt = Integer.parseInt(b.getQuantità());
  267. totalAmount += b.distance * quantitaInt;
  268. // a=String.valueOf(totalAmount);
  269.  
  270.  
  271. }
  272. }
  273. /* for (Planet p : plAdapter.getBox()) {
  274. if (p.isSelected()) {
  275.  
  276.  
  277. result += "\n" + p.getName() + " " + p.getDistance() + "€" + "q.tà :" + p.getQuantità();
  278. int quantitaInt = Integer.parseInt(p.getQuantità());
  279. //totalAmount2+=p.distance * quantitaInt;
  280. //z=String.valueOf(totalAmount2);
  281.  
  282.  
  283. }
  284. }*/
  285.  
  286.  
  287.  
  288. Toast.makeText(getActivity(), result + "\n" +myInt + "\n" + "Total Amount:=" + totalAmount + "€", Toast.LENGTH_LONG).show();
  289. TwoFragment fgsearch2 = TwoFragment.getInstance(result,totalAmount,"test");
  290. android.support.v4.app.FragmentTransaction transaction2 = getActivity().getSupportFragmentManager().beginTransaction();
  291. transaction2.replace(R.id.content_main, fgsearch2);
  292. transaction2.commit();
  293.  
  294.  
  295.  
  296.  
  297. }
  298. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement