Advertisement
Guest User

Activity1

a guest
Nov 7th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.74 KB | None | 0 0
  1. public class DairyFragment extends Fragment {
  2.  
  3.     public static final String TAG = DairyFragment.class.getSimpleName();
  4.  
  5.     final String LOG_TAG = "DairyFragmentLogs";
  6.     XMLParser parser = new XMLParser();
  7.     PullToRefreshListView pullToRefreshView;
  8.     String dairy_url;
  9.     ExpandableListView elview;
  10.     View v;
  11.     MyViewPager mPager;
  12.     MyAdapter mAdapter;
  13.     ImageLoader imageLoader;
  14.     Fragment[] frs = new Fragment[4];
  15.  
  16.     private static final String ABOUT_SCHEME = "dairy_scheme";
  17.     private static final String ABOUT_AUTHORITY = "dairy_auth";
  18.     public static final Uri DAIRY_URI = new Uri.Builder().scheme(ABOUT_SCHEME)
  19.             .authority(ABOUT_AUTHORITY).build();
  20.  
  21.     @Override
  22.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  23.             Bundle savedInstanceState) {
  24.        
  25.        
  26.  
  27.         v = inflater.inflate(R.layout.dairy, container, false);
  28.  
  29.         mPager = (MyViewPager) v.findViewById(R.id.pager);
  30.  
  31.         mPager.setPagingEnabled(true);
  32.  
  33.         imageLoader = new ImageLoader(getActivity());
  34.  
  35.         Log.d("SESSION_DATE", AppState.getCurrentSessionDate());
  36.  
  37.         FragmentManager fm = getChildFragmentManager();
  38.  
  39.         updateData("http://iapp.remsmed.mosfile.ru/"
  40.                 + AppState.getCurrentSessionDate() + "/patients/dashboard");
  41.  
  42.         mAdapter = new MyAdapter(fm);
  43.  
  44.         mPager.setAdapter(mAdapter);
  45.        
  46.        
  47.        
  48.         if (AppState.getUserRoleID().equals(AppState.DOCTOR)) {
  49.             ImageView img = (ImageView) v.findViewById(R.id.dairy_foto);
  50.             img.setVisibility(View.VISIBLE);
  51.             imageLoader.DisplayRemsmedImage(
  52.                     AppState.attached_patient.get("user_img"), img);
  53.         } else if (AppState.getUserRoleID().equals(AppState.PATIENT))
  54.             mPager.setOnPageChangeListener(new OnPageChangeListener() {
  55.  
  56.                 @Override
  57.                 public void onPageSelected(int position) {
  58.                     Log.d("PageNumber", "**** onPageSelected = " + position);
  59.                     switch (position) {
  60.                     case 0:
  61.                         ((Button) v.findViewById(R.id.add))
  62.                                 .setVisibility(View.GONE);
  63.                         break;
  64.                     case 1:
  65.                         ((Button) v.findViewById(R.id.add))
  66.                                 .setVisibility(View.VISIBLE);
  67.                         break;
  68.                     case 2:
  69.                         ((Button) v.findViewById(R.id.add))
  70.                                 .setVisibility(View.GONE);
  71.                         break;
  72.                     default:
  73.                         break;
  74.                     }
  75.                 }
  76.  
  77.                 @Override
  78.                 public void onPageScrolled(int arg0, float arg1, int arg2) {
  79.                 }
  80.  
  81.                 @Override
  82.                 public void onPageScrollStateChanged(int arg0) {
  83.                 }
  84.  
  85.             });
  86.  
  87.         ((Button) v.findViewById(R.id.add))
  88.                 .setOnClickListener(new View.OnClickListener() {
  89.                     public void onClick(View v) {
  90.  
  91.                         ExamplesActivity a = (ExamplesActivity) getActivity();
  92.                         DairyRootFragment drf = ((DairyRootFragment) a
  93.                                 .getSupportFragmentManager().findFragmentByTag(
  94.                                         DairyRootFragment.TAG));
  95.                         DairySupportFragment sf = (DairySupportFragment) drf
  96.                                 .getSupportFragment();
  97.                         sf.changeFragment(1, null);
  98.                         drf.getMyViewPager().setCurrentItem(1, true);
  99.  
  100.                         getActivity().findViewById(R.id.btn_back)
  101.                                 .setVisibility(View.VISIBLE);
  102.                         getActivity().findViewById(R.id.btn_menu)
  103.                                 .setVisibility(View.GONE);
  104.                         ((ExamplesActivity) getActivity()).setOnClickBtnBack(2);
  105.  
  106.                     }
  107.                 });
  108.  
  109.         ((Button) v.findViewById(R.id.calendar))
  110.                 .setOnClickListener(new View.OnClickListener() {
  111.                     public void onClick(View v) {
  112.  
  113.                         /*
  114.                          * Intent intent = new Intent(getActivity(),
  115.                          * CalendarFragment.class);
  116.                          * startActivityForResult(intent, 1);
  117.                          */
  118.                        
  119.                         mAdapter.getItem(0);
  120.                         mAdapter.getItem(1);
  121.                         mAdapter.getItem(2);
  122.                         mAdapter.getItem(3);
  123.  
  124.                         ExamplesActivity a = (ExamplesActivity) getActivity();
  125.                         DairyRootFragment drf = ((DairyRootFragment) a
  126.                                 .getSupportFragmentManager().findFragmentByTag(
  127.                                         DairyRootFragment.TAG));
  128.                         DairySupportFragment sf = (DairySupportFragment) drf
  129.                                 .getSupportFragment();
  130.                         sf.changeFragment(4, null);
  131.                         drf.getMyViewPager().setCurrentItem(1, true);
  132.  
  133.                         getActivity().findViewById(R.id.btn_back)
  134.                                 .setVisibility(View.VISIBLE);
  135.                         getActivity().findViewById(R.id.btn_menu)
  136.                                 .setVisibility(View.GONE);
  137.                         ((ExamplesActivity) getActivity()).setOnClickBtnBack(2);
  138.  
  139.                     }
  140.                 });
  141.  
  142.         return v;
  143.     }
  144.  
  145.     public void onActivityResult(int requestCode, int resultCode, Intent data) {
  146.         switch (requestCode) {
  147.         case 1:
  148.             if (resultCode == getActivity().RESULT_OK) {
  149.  
  150.                 Bundle bundle = data.getExtras();
  151.  
  152.                 TextView mtv = (TextView) getActivity().findViewById(
  153.                         R.id.dairy_date);
  154.                 mtv.setText(bundle.getString("dateSelected"));
  155.                 dairy_url = "http://iapp.remsmed.mosfile.ru/"
  156.                         + bundle.getString("year") + "/"
  157.                         + bundle.getString("month") + "/"
  158.                         + bundle.getString("day") + "/patients/dashboard";
  159.  
  160.                 Log.d(LOG_TAG, dairy_url);
  161.  
  162.                 updateData(dairy_url);
  163.  
  164.                 break;
  165.             }
  166.         }
  167.  
  168.     }
  169.  
  170.     private class GetNewDairy extends AsyncTask<String, Void, Document> {
  171.  
  172.         protected void onPostExecute(Document result) {
  173.             super.onPostExecute(result);
  174.         }
  175.  
  176.         @Override
  177.         protected Document doInBackground(String... params) {
  178.             // TODO Auto-generated method stub
  179.             NetHelper a = NetHelper.getInstance(getActivity()
  180.                     .getApplicationContext());
  181.  
  182.             return parser.getDomElement(a.executeHttpGet(params[0]));
  183.  
  184.         }
  185.     }
  186.  
  187.     private void updateData(String url) {
  188.  
  189.         GetNewDairy gDry = new GetNewDairy();
  190.         gDry.execute(url);
  191.         Document doc = null;
  192.         try {
  193.             doc = gDry.get();
  194.         } catch (InterruptedException e1) {
  195.             // TODO Auto-generated catch block
  196.             e1.printStackTrace();
  197.         } catch (ExecutionException e1) {
  198.             // TODO Auto-generated catch block
  199.             e1.printStackTrace();
  200.         }
  201.  
  202.         ArrayList<HashMap<String, Object>> menuItems = new ArrayList<HashMap<String, Object>>();
  203.        
  204.        
  205.  
  206.         // inquirer
  207.         ArrayList<HashMap<String, Object>> inq_parents_list = new ArrayList<HashMap<String, Object>>();
  208.         ArrayList<ArrayList<HashMap<String, String>>> inq_childs_lists = new ArrayList<ArrayList<HashMap<String, String>>>();
  209.  
  210.         // eprscr
  211.         ArrayList<HashMap<String, Object>> eprscr_parents_list = new ArrayList<HashMap<String, Object>>();
  212.         ArrayList<ArrayList<HashMap<String, String>>> eprscr_childs_lists = new ArrayList<ArrayList<HashMap<String, String>>>();
  213.  
  214.         // comments
  215.         ArrayList<HashMap<String, Object>> comment_parents_list = new ArrayList<HashMap<String, Object>>();
  216.         ArrayList<ArrayList<HashMap<String, String>>> comment_childs_lists = new ArrayList<ArrayList<HashMap<String, String>>>();
  217.  
  218.         NodeList nl = doc.getElementsByTagName("events").item(0)
  219.                 .getChildNodes();
  220.         for (int i = 0; i < nl.getLength(); i++) // по ivents
  221.         {
  222.             if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) {
  223.                 Element e = (Element) nl.item(i);
  224.                 Log.d(LOG_TAG, "comm " + e.getNodeName());
  225.                 HashMap<String, Object> map = new HashMap<String, Object>();
  226.                 // выбор типа ivents
  227.                 if (e.getNodeName().equals("user_comment")) {
  228.  
  229.                     map.put("ivent", "user_comment");
  230.                     map.put("user_comment_id",
  231.                             parser.getValue(e, "user_comment_id"));
  232.                     map.put("comment_text", parser.getValue(e, "comment_text"));
  233.                     map.put("date", parser.getValue(e, "date"));
  234.                     map.put("time", parser.getValue(e, "time"));
  235.  
  236.                     NodeList comm_nl = e.getElementsByTagName("comments")
  237.                             .item(0).getChildNodes();
  238.                     ArrayList<HashMap<String, String>> menuItems_childs = new ArrayList<HashMap<String, String>>();
  239.                     for (int j = 0; j < comm_nl.getLength(); j++) // по childs
  240.                     {
  241.                         if (comm_nl.item(j).getNodeType() == Node.ELEMENT_NODE) {
  242.                             HashMap<String, String> map_childs = new HashMap<String, String>();
  243.                             Element e_nl = (Element) comm_nl.item(j);
  244.  
  245.                             map_childs.put("comm",
  246.                                     parser.getValue(e_nl, "comment_text"));
  247.                             map_childs.put("user_img",
  248.                                     parser.getValue(e_nl, "user_img"));
  249.                             map_childs.put("comment_datetime",
  250.                                     parser.getValue(e_nl, "comment_datetime"));
  251.                             map_childs.put("user_fio",
  252.                                     parser.getValue(e_nl, "user_fio"));
  253.                             Log.d(LOG_TAG, "commenti");
  254.                             menuItems_childs.add(map_childs);
  255.  
  256.                         }
  257.                     }
  258.  
  259.                     comment_childs_lists.add(menuItems_childs);
  260.                     comment_parents_list.add(map);
  261.  
  262.                     // map.put("comments", menuItems_childs);
  263.                     // menuItems.add(map);
  264.                     Log.d(LOG_TAG, "menu input  " + e.getNodeName());
  265.  
  266.                 } else if (e.getNodeName().equals("user_measurement")) {
  267.  
  268.                     map.put("ivent", "user_measurement");
  269.                     map.put("measurement_name",
  270.                             parser.getValue(e, "measurement_name"));
  271.                     map.put("measurement_value",
  272.                             parser.getValue(e, "measurement_value"));
  273.                     map.put("date", parser.getValue(e, "date"));
  274.  
  275.                     String time = parser.getValue(e, "time");
  276.                     String[] d = time.split(":");
  277.                     String data = d[0] + ":" + d[1];
  278.  
  279.                     map.put("time", data);
  280.  
  281.                     menuItems.add(map);
  282.                 } else if (e.getNodeName().equals("user_inquirer")) {
  283.  
  284.                     map.put("ivent", "user_inquirer");
  285.                     map.put("inquirer_id", parser.getValue(e, "inquirer_id"));
  286.                     map.put("inquirer_value",
  287.                             parser.getValue(e, "inquirer_value"));
  288.                     map.put("date", parser.getValue(e, "date"));
  289.                     map.put("time", parser.getValue(e, "time"));
  290.  
  291.                     NodeList comm_nl = e.getElementsByTagName("questions")
  292.                             .item(0).getChildNodes();
  293.  
  294.                     ArrayList<HashMap<String, String>> child_childs = new ArrayList<HashMap<String, String>>();
  295.                     for (int j = 0; j < comm_nl.getLength(); j++) // по childs
  296.                     {
  297.                         if (comm_nl.item(j).getNodeType() == Node.ELEMENT_NODE) {
  298.  
  299.                             HashMap<String, String> map_childs = new HashMap<String, String>();
  300.                             Element e_nl = (Element) comm_nl.item(j);
  301.  
  302.                             map_childs.put("question_text",
  303.                                     parser.getValue(e_nl, "question_text"));
  304.                             map_childs.put("question_value",
  305.                                     parser.getValue(e_nl, "question_value"));
  306.                             child_childs.add(map_childs);
  307.                             Log.d(LOG_TAG, "questions_inquirer");
  308.                         }
  309.                     }
  310.                     inq_childs_lists.add(child_childs);
  311.                     // map.put("questions", menuItems_childs);
  312.  
  313.                     inq_parents_list.add(map);
  314.  
  315.                 } else if (e.getNodeName().equals("exec_prescription")) {
  316.  
  317.                     map.put("ivent", "exec_prescription");
  318.                     map.put("name", parser.getValue(e, "name"));
  319.                     map.put("date", parser.getValue(e, "date"));
  320.                     map.put("time", parser.getValue(e, "time"));
  321.                     map.put("exec_id", parser.getValue(e, "exec_id"));
  322.                     map.put("exec_status", parser.getValue(e, "exec_status"));
  323.                     map.put("comment_doctor",
  324.                             parser.getValue(e, "comment_doctor"));
  325.  
  326.                     NodeList comm_nl = e.getElementsByTagName("comments")
  327.                             .item(0).getChildNodes();
  328.                     ArrayList<HashMap<String, String>> menuItems_childs = new ArrayList<HashMap<String, String>>();
  329.                     for (int j = 0; j < comm_nl.getLength(); j++) // по childs
  330.                     {
  331.                         if (comm_nl.item(j).getNodeType() == Node.ELEMENT_NODE) {
  332.  
  333.                             HashMap<String, String> map_childs = new HashMap<String, String>();
  334.                             Element e_nl = (Element) comm_nl.item(j);
  335.  
  336.                             map_childs.put("comm",
  337.                                     parser.getValue(e_nl, "comment_text"));
  338.                             map_childs.put("user_img",
  339.                                     parser.getValue(e_nl, "user_img"));
  340.                             menuItems_childs.add(map_childs);
  341.                             Log.d(LOG_TAG, "commenti prscr");
  342.                         }
  343.                     }
  344.  
  345.                     eprscr_childs_lists.add(menuItems_childs);
  346.                     eprscr_parents_list.add(map);
  347.                     // map.put("comments", menuItems_childs);
  348.  
  349.                     // menuItems.add(map);
  350.                 }
  351.  
  352.             }
  353.         }
  354.  
  355.         if (frs[2] == null) {
  356.  
  357.             frs[2] = DairyEPrscrFragment.newInstance(eprscr_parents_list,
  358.                     eprscr_childs_lists);
  359.         } else {
  360.  
  361.             ((DairyEPrscrFragment) frs[2]).setargs(eprscr_parents_list,
  362.                     eprscr_childs_lists);
  363.             ((DairyEPrscrFragment) frs[2]).setchanges();
  364.             // mAdapter.notifyDataSetChanged();
  365.         }
  366.  
  367.         if (frs[1] == null) {
  368.  
  369.             frs[1] = DairyCommentFragment.newInstance(comment_parents_list,
  370.                     comment_childs_lists);
  371.         } else {
  372.  
  373.             ((DairyCommentFragment) frs[1]).setargs(comment_parents_list,
  374.                     comment_childs_lists);
  375.             ((DairyCommentFragment) frs[1]).setchanges();
  376.             // mAdapter.notifyDataSetChanged();
  377.         }
  378.  
  379.         if (frs[0] == null) {
  380.  
  381.             frs[0] = DairyMsrmFragment.newInstance(menuItems);
  382.         } else {
  383.  
  384.             ((DairyMsrmFragment) frs[0]).setargs(menuItems);
  385.             ((DairyMsrmFragment) frs[0]).setchanges();
  386.             // mAdapter.notifyDataSetChanged();
  387.         }
  388.  
  389.         if (frs[3] == null) {
  390.  
  391.             frs[3] = DairyInqFragment.newInstance(inq_parents_list,
  392.                     inq_childs_lists);
  393.  
  394.         } else {
  395.  
  396.             ((DairyInqFragment) frs[3]).setargs(inq_parents_list,
  397.                     inq_childs_lists);
  398.             ((DairyInqFragment) frs[3]).setchanges();
  399.             // mAdapter.notifyDataSetChanged();
  400.         }
  401.  
  402.     }
  403.  
  404.     public class MyAdapter extends FragmentPagerAdapter {
  405.         public MyAdapter(FragmentManager fm) {
  406.             super(fm);
  407.             /*
  408.              * this.getItem(0); this.getItem(1); this.getItem(2);
  409.              * this.getItem(3); this.getItem(0);
  410.              */
  411.         }
  412.  
  413.         @Override
  414.         public int getCount() {
  415.             return 4;
  416.         }
  417.  
  418.         @Override
  419.         public Fragment getItem(int position) {
  420.  
  421.             switch (position) {
  422.             case 0:
  423.  
  424.                 return frs[0];
  425.             case 1:
  426.  
  427.                 return frs[1];
  428.             case 2:
  429.  
  430.                 return frs[2];
  431.             case 3:
  432.  
  433.                 return frs[3];
  434.             default:
  435.  
  436.                 Fragment fr = new EPrscrFragment();
  437.  
  438.                 return fr;
  439.             }
  440.  
  441.         }
  442.  
  443.         @Override
  444.         public CharSequence getPageTitle(int position) {
  445.             // Locale l = Locale.getDefault();
  446.             switch (position) {
  447.             case 0:
  448.                 return "\u2460";
  449.             case 1:
  450.                 return "\u2461";
  451.             case 2:
  452.                 return "\u2462";
  453.             case 3:
  454.                 return "\u2463";
  455.             }
  456.             return null;
  457.         }
  458.  
  459.     }
  460.  
  461.     public void setDate(int year, int month, int day) {
  462.  
  463.         TextView mtv = (TextView) getActivity().findViewById(R.id.dairy_date);
  464.         mtv.setText(String.valueOf(year) + "/" + String.valueOf(month) + "/"
  465.                 + String.valueOf(day));
  466.         dairy_url = "http://iapp.remsmed.mosfile.ru/" + String.valueOf(year)
  467.                 + "/" + String.valueOf(month) + "/" + String.valueOf(day)
  468.                 + "/patients/dashboard";
  469.  
  470.         Log.d(LOG_TAG, dairy_url);
  471.  
  472.         updateData(dairy_url);
  473.     }
  474.  
  475. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement