Advertisement
Guest User

Untitled

a guest
May 26th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.41 KB | None | 0 0
  1. myInt = bundle2.getString("scelta2", null);
  2. titolo3.setText(myInt);
  3.  
  4. public class TwoFragment extends Fragment{
  5.  
  6. private View v;
  7. Intent chooser=null;
  8. String myInt="";
  9.  
  10. public TwoFragment() {
  11. // Required empty public constructor
  12. }
  13.  
  14. @Override
  15. public void onCreate(Bundle savedInstanceState) {
  16. super.onCreate(savedInstanceState);
  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. //TextView titolo = (TextView)rootView.findViewById(R.id.quantità3);
  41.  
  42. /* Bundle bundle2=getArguments();
  43. if(bundle2 != null){
  44. String string = bundle2.getString("scelta2", null);
  45. titolo3.setText(string);
  46. }*/
  47.  
  48. Bundle bundle2=getArguments();
  49. if(bundle2 != null){
  50. myInt = bundle2.getString("scelta2", null);
  51. titolo3.setText(myInt);
  52. }
  53.  
  54. Bundle bundle3=getArguments();
  55. if(bundle3 != null){
  56. // String myInt3 = bundle3.getString("totalebirre", null);
  57. // cazzo2=Integer.parseInt(myInt3);
  58. int cazzo2=bundle3.getInt("totalebirre");
  59. titolo2.setText(String.valueOf(cazzo2));
  60.  
  61.  
  62.  
  63. }
  64. Bundle bundle=getArguments();
  65. if(bundle != null){
  66. // String myInt2 = bundle2.getString("totalepizze", null);
  67. // cazzo=Integer.parseInt(myInt2);
  68. //titolo2.setText(myInt2);
  69. String string=bundle.getString("scelta3", null);
  70. titolo4.setText(string);
  71.  
  72. }
  73.  
  74.  
  75.  
  76. return rootView;
  77. }
  78. /* public void sendemail(){
  79.  
  80. Intent intent = new Intent(Intent.ACTION_SEND);
  81. intent.setData(Uri.parse("mailto:"));
  82. String[] to={"marco_marcoletto@hotmail.it"};
  83. intent.putExtra(Intent.EXTRA_EMAIL,to);
  84. intent.putExtra(Intent.EXTRA_SUBJECT, "ciao");
  85. intent.putExtra(Intent.EXTRA_TEXT, "zao");
  86. intent.setType("message/rfc822");
  87. chooser=intent.createChooser(intent,"manda email");
  88. startActivity(chooser);
  89. }*/
  90. public void createPDF() {
  91.  
  92. Document doc = new Document();
  93.  
  94. try {
  95. String path = Environment.getExternalStorageDirectory()
  96. .getAbsolutePath() + "/droidText";
  97.  
  98. File dir = new File(path);
  99. if (!dir.exists())
  100. dir.mkdirs();
  101.  
  102. Log.d("PDFCreator", "PDF Path: " + path);
  103.  
  104. File file = new File(dir, "sample.pdf");
  105. FileOutputStream fOut = new FileOutputStream(file);
  106.  
  107. PdfWriter.getInstance(doc, fOut);
  108.  
  109. // open the document
  110. doc.open();
  111. ByteArrayOutputStream stream = new ByteArrayOutputStream();
  112. Bitmap bitmap = BitmapFactory.decodeResource(getContext()
  113. .getResources(), R.drawable.androtuto);
  114. bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  115. Image myImg = Image.getInstance(stream.toByteArray());
  116. myImg.setAlignment(Image.MIDDLE);
  117.  
  118. // add image to document
  119. doc.add(myImg);
  120.  
  121. Paragraph p1 = new Paragraph(myInt);
  122. Log.d("ciao",myInt);
  123.  
  124. Font paraFont = new Font(Font.COURIER);
  125. p1.setAlignment(Paragraph.ALIGN_CENTER);
  126. p1.setFont(paraFont);
  127.  
  128. // add paragraph to document
  129. doc.add(p1);
  130.  
  131. Paragraph p2 = new Paragraph("Ciao");
  132. Font paraFont2 = new Font(Font.COURIER, 14.0f, Color.GREEN);
  133. p2.setAlignment(Paragraph.ALIGN_CENTER);
  134. p2.setFont(paraFont2);
  135.  
  136. doc.add(p2);
  137.  
  138. stream = new ByteArrayOutputStream();
  139. bitmap = BitmapFactory.decodeResource(getContext()
  140. .getResources(), R.drawable.android);
  141. bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  142. myImg = Image.getInstance(stream.toByteArray());
  143. myImg.setAlignment(Image.MIDDLE);
  144.  
  145. // add image to document
  146. doc.add(myImg);
  147.  
  148. // set footer
  149. Phrase footerText = new Phrase("Pied de page ");
  150. HeaderFooter pdfFooter = new HeaderFooter(footerText, false);
  151. doc.setFooter(pdfFooter);
  152.  
  153. } catch (DocumentException de) {
  154. Log.e("PDFCreator", "DocumentException:" + de);
  155. } catch (IOException e) {
  156. Log.e("PDFCreator", "ioException:" + e);
  157. } finally {
  158. doc.close();
  159. }
  160.  
  161. }
  162. public void viewPDF(){
  163. String path = "/sdcard/droidText/sample.pdf";
  164. File targetFile = new File(path);
  165. Uri targetUri = Uri.fromFile(targetFile);
  166.  
  167. Intent intent;
  168. intent = new Intent(Intent.ACTION_VIEW);
  169. intent.setDataAndType(targetUri, "application/pdf");
  170.  
  171. startActivity(intent);
  172. }
  173.  
  174. }
  175.  
  176. public class ThreeFragment extends Fragment implements
  177. android.widget.CompoundButton.OnCheckedChangeListener {
  178.  
  179. ListView lv2;
  180. ArrayList<Planet> planetList;
  181. ListView lv;
  182.  
  183. ArrayList<Birra> birraList;
  184. BirraAdapter biAdapter;
  185. PlanetAdapter plAdapter;
  186. Planet p;
  187. String myInt="";
  188.  
  189.  
  190.  
  191. PlanetAdapter.PlanetHolder holder;
  192.  
  193.  
  194. public ThreeFragment() {
  195. // Required empty public constructor
  196. }
  197.  
  198.  
  199. @Override
  200. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  201. Bundle savedInstanceState) {
  202. // Inflate the layout for this fragment
  203.  
  204. final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_three, container, false);
  205.  
  206. Button mButton = (Button) rootView.findViewById(R.id.button2);
  207. mButton.setOnClickListener(new View.OnClickListener() {
  208. public void onClick(View v) {
  209. MyListFragment mlf=new MyListFragment();
  210.  
  211. mlf.showResult(v);
  212. // MyListFragment.showResult(v);
  213. showResult2(v);
  214.  
  215.  
  216. }
  217. });
  218. //return inflater.inflate(R.layout.fragment_list2, container, false);
  219. return rootView;
  220. }
  221.  
  222.  
  223. @Override
  224. public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  225. super.onViewCreated(view, savedInstanceState);
  226.  
  227. lv2 = (ListView) getView().findViewById(R.id.listview2);
  228. displayBirraList();
  229. }
  230.  
  231.  
  232. private void displayBirraList() {
  233.  
  234. birraList = new ArrayList<Birra>();
  235. birraList.add(new Birra("Paulaner", 6, "€"));
  236. birraList.add(new Birra("Forst", 7, "€"));
  237. birraList.add(new Birra("Peroni", 5, "€"));
  238. birraList.add(new Birra("Corona", 5, "€"));
  239. birraList.add(new Birra("Nastro Azzurro", 4, "€"));
  240. biAdapter = new BirraAdapter(birraList, getContext()) {
  241. @Override
  242. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  243. int pos = lv2.getPositionForView(buttonView);
  244. if (pos != ListView.INVALID_POSITION) {
  245. Birra b = birraList.get(pos);
  246. b.setSelected(isChecked);
  247.  
  248.  
  249. /*Toast.makeText(
  250. getActivity(),
  251. "Clicked on Pizza: " + p.getName() + ". State: is "
  252. + isChecked, Toast.LENGTH_SHORT).show();*/
  253. }
  254.  
  255.  
  256. }
  257.  
  258.  
  259. };
  260.  
  261.  
  262. lv2.setAdapter(biAdapter);
  263. }
  264.  
  265.  
  266. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  267.  
  268.  
  269. /*int pos = lv.getPositionForView(buttonView);
  270. if (pos != ListView.INVALID_POSITION) {
  271. Planet p = planetList.get(pos);
  272. p.setSelected(isChecked);
  273.  
  274.  
  275. *//**//**//**//*Toast.makeText(
  276. getActivity(),
  277. "Clicked on Planet: " + p.getName() + ". State: is "
  278. + isChecked, Toast.LENGTH_SHORT).show();*//**//**//**//*
  279. }
  280. */
  281. }
  282.  
  283.  
  284. public void showResult2(View v) {
  285. String result = "Selected Product are :";
  286. int totalAmount = 0;
  287. // String a = "";
  288.  
  289.  
  290. for (Birra b : biAdapter.getBox()) {
  291.  
  292. if (b.selected) {
  293.  
  294. result += "n" + b.name + " " + b.distance + "€" + "q.tà :" + b.getQuantità();
  295. int quantitaInt = Integer.parseInt(b.getQuantità());
  296. totalAmount += b.distance * quantitaInt;
  297. // a=String.valueOf(totalAmount);
  298.  
  299.  
  300. }
  301. }
  302. /* for (Planet p : plAdapter.getBox()) {
  303. if (p.isSelected()) {
  304.  
  305.  
  306. result += "n" + p.getName() + " " + p.getDistance() + "€" + "q.tà :" + p.getQuantità();
  307. int quantitaInt = Integer.parseInt(p.getQuantità());
  308. //totalAmount2+=p.distance * quantitaInt;
  309. //z=String.valueOf(totalAmount2);
  310.  
  311.  
  312. }
  313. }*/
  314.  
  315.  
  316.  
  317. Toast.makeText(getActivity(), result + "n" +myInt + "n" + "Total Amount:=" + totalAmount + "€", Toast.LENGTH_LONG).show();
  318. Bundle bun2 = new Bundle();
  319. bun2.putString("scelta2", result);
  320. TwoFragment fgsearch2 = new TwoFragment();
  321. fgsearch2.setArguments(bun2);
  322. android.support.v4.app.FragmentTransaction transaction2 = getActivity().getSupportFragmentManager().beginTransaction();
  323. transaction2.replace(R.id.content_main, fgsearch2);
  324. transaction2.commit();
  325.  
  326. Bundle bun = new Bundle();
  327. // bun.putString("totalebirre", a);
  328. bun.putInt("totalebirre", totalAmount);
  329. TwoFragment fgsearch = new TwoFragment();
  330. fgsearch.setArguments(bun);
  331. android.support.v4.app.FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
  332. transaction.replace(R.id.content_main2, fgsearch);
  333. transaction.commit();
  334.  
  335.  
  336.  
  337.  
  338. }
  339. }
  340.  
  341. public class MainBirra extends AppCompatActivity {
  342.  
  343.  
  344. @Override
  345. protected void onCreate(Bundle savedInstanceState) {
  346. super.onCreate(savedInstanceState);
  347. setContentView(R.layout.mainbirra);
  348.  
  349. getSupportFragmentManager().beginTransaction().
  350.  
  351. replace(R.id.fragmentContainer2, new ThreeFragment()).commit();
  352.  
  353.  
  354.  
  355. }
  356. /* @Override protected void onDestroy() {
  357. SharedPreferences preferences=getSharedPreferences("states", Context.MODE_PRIVATE);
  358. SharedPreferences.Editor editor=preferences.edit();
  359. editor.clear().apply();
  360. super.onDestroy();
  361. Log.e("OnDestroy", " callback_2");
  362.  
  363. }*/
  364.  
  365.  
  366.  
  367. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement