Marco_Moscatelli

Untitled

Dec 2nd, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.26 KB | None | 0 0
  1. void prepareMainList(String data)
  2. {      
  3.                
  4. Document doc;
  5. NodeList nl;
  6.  
  7. newsNotificationData = new ArrayList<Map<String, String>>(); //set this struct in other case
  8.  
  9. groupData = new ArrayList<Map<String, String>>();
  10. childData = new ArrayList<List<Map<String, String>>>();
  11.  
  12. if ((data.compareTo("") != 0) && (data != null) )
  13. {
  14.     doc = parser.getDomElement(data); // getting DOM element
  15.        
  16.     nl = doc.getElementsByTagName(KEY_GROUP);
  17.  
  18.     categoryList = new HashSet<CategoryClass>();
  19.  
  20.     // looping through all song nodes &lt;song&gt;
  21. for (int i = 0; i < nl.getLength(); i++)
  22. {
  23.       // creating new HashMap
  24.   Map<String, String> curGroupMap = new HashMap<String, String>();
  25.   Map<String, String> curNewsMap = new HashMap<String, String>();
  26.   Element el = (Element) nl.item(i);
  27.  
  28.   CategoryClass myCat = new CategoryClass();
  29.   myCat.id = parser.getValue(el, "id");
  30.   myCat.name = parser.getValue(el, KEY_NAME);
  31.   myCat.subCategory = new HashSet<TournamentClass>();
  32.  
  33.    // adding each child node to HashMap key =&gt; value
  34.   curGroupMap.put(CATEGORY, parser.getValue(el, KEY_NAME));
  35.   Log.d("test", "category id added: " + myCat.id);
  36.  
  37.    // adding HashList to ArrayList
  38.   groupData.add(curGroupMap);
  39.  
  40.   //notification
  41.   curNewsMap.put("CID_" + myCat.id, getValueFromCategory(myCat.id));
  42.   newsNotificationData.add(curNewsMap);
  43.  
  44.   NodeList ls = el.getElementsByTagName("girone");
  45.  
  46.   //Log.d("test", "getDataFromWebService get children count : " + ls.getLength());
  47.   List<Map<String, String>> children = new ArrayList<Map<String, String>>();
  48.   for (int j = 0; j < ls.getLength(); j++)
  49.   {
  50.        Element elc = (Element) ls.item(j);
  51.        Map<String, String> curChildMap = new HashMap<String, String>();
  52.        
  53.        TournamentClass myTournament = new TournamentClass();
  54.        myTournament.id = elc.getAttribute("id");
  55.        myTournament.name = parser.getValue(elc, KEY_CHILD_NAME);
  56.      
  57.        curChildMap.put(TOURNAMENT,  parser.getValue(elc, KEY_CHILD_NAME));
  58.        
  59.        children.add(curChildMap);
  60.        
  61.        myCat.subCategory.add(myTournament);
  62.        
  63.        
  64.        //notification
  65.        curNewsMap.put("TID_" + myTournament.id, "-1");
  66.        newsNotificationData.get(i).put("TID_" + myTournament.id, getValueFromTournament(myTournament.id));
  67.        
  68.    }
  69.  
  70.    childData.add(children);
  71.    categoryList.add(myCat);
  72.    
  73.  
  74.    //newsNotificationData.add(curNewsMap);
  75.    }     
  76.  
  77. }
  78.  
  79. catList = (ExpandableListView) findViewById(R.id.expandableSettings);
  80. catList.setClickable(true);                        
  81.  
  82.  
  83. catList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
  84. public boolean onGroupClick(ExpandableListView parent, View v,
  85.     int groupPosition, long id) {
  86.     Log.d("test", "GROUP PRESSED");
  87.     return false;
  88. }
  89. });
  90.  
  91. // Set up our adapter
  92. mAdapter = new SimpleExpandableListAdapter(
  93.     this,
  94.     groupData,
  95.     R.layout.settings_header,
  96.     new String[] { CATEGORY, TOURNAMENT },
  97.     new int[] { R.id.settingsCatTitle, android.R.id.text2 },
  98.     childData,
  99.     R.layout.settings_child,
  100.     new String[] { CATEGORY, TOURNAMENT },
  101.     new int[] { android.R.id.text1, R.id.settingsSubTitle }
  102. ){
  103.  
  104. @Override
  105. public  View getGroupView (final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
  106. {
  107.     //final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
  108. final View v = super.getGroupView(groupPosition, isExpanded, convertView, parent);
  109.  
  110. //Log.d("test", "get tournament selected");
  111. TextView tv = (TextView)v.findViewById( R.id.settingsCatTitle );
  112. String catSel = tv.getText().toString();
  113.  
  114. //get objects
  115. String groupName  = groupData.get(groupPosition).get("CATEGORY");
  116. final CategoryClass myCat = getCategoryFromName(groupName);
  117.  
  118. RadioGroup groupNN;  
  119.  
  120. // *** Gestisce l'header della categoria ***
  121. groupNN = (RadioGroup) v.findViewById(R.id.radioGroupNN);
  122. groupNN.setOnCheckedChangeListener(new OnCheckedChangeListener()
  123. {
  124.     @Override
  125.      public void onCheckedChanged(RadioGroup group, int checkedId)
  126.      {
  127.         //Log.d("Header chk", "id" + checkedId);
  128.          if(!isDataLoaded) return;
  129.          for (int i = 0, l = group.getChildCount(); i < l; i++)
  130.          {
  131.                RadioButton xRadio = (RadioButton) group.getChildAt(i);
  132.                xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
  133.                xRadio.setTextColor(R.drawable.settings_gradient_on);
  134.          }
  135.            
  136.            //-----change data to send
  137.            String notifValue = "0";
  138.            
  139.            //get checked value
  140.            switch (checkedId)
  141.            {
  142.                 case R.id.button_News:
  143.                     notifValue = "0";
  144.                     break;
  145.                    
  146.                 case R.id.button_Notif:
  147.                     notifValue = "1";
  148.                     break;
  149.                    
  150.                 case R.id.button_All:
  151.                     notifValue = "2";
  152.                     break;
  153.                    
  154.                 case R.id.button_no:
  155.                     notifValue = "-1";
  156.                     break;
  157.                    
  158.                 default:
  159.                     break;
  160.                    
  161.             }
  162.            
  163.            
  164.             //set graphics on selected radio button
  165.             RadioButton radio = (RadioButton) v.findViewById(checkedId);
  166.             if (radio != null)
  167.             {
  168.                //radio.setTextSize(30);
  169.                 // Marco Moscatelli 28/11/2013 - imposto il check a true
  170.                 //radio.setChecked(true);
  171.                 radio.setBackgroundResource(R.drawable.settings_gradient_on);
  172.                 radio.setTextColor(Color.LTGRAY);
  173.             }
  174.            
  175.             updateNewsNotificationCenter(groupPosition, myCat.id, null, notifValue);
  176.            
  177.             isDataLoaded = false;
  178.            
  179.             //Log.d("test", "------END SET CATEGORY------- ");
  180.            
  181.         }
  182.     });
  183.     //-----data to send changed
  184.  
  185.     isDataLoaded = false;
  186.     //set default schema
  187.     //String defaultbtnValue = null;
  188.     String defaultbtnValue = newsNotificationData.get(groupPosition).get("CID_" + myCat.id);
  189.     //Log.d("test", "check current cat id :  "+ myCat.id);
  190.  
  191.     RadioButton defNNRadio = null;
  192.     //Log.d("test", "defaultbtnValue : "+ defaultbtnValue);
  193.    
  194.     if (defaultbtnValue == null)defaultbtnValue = "-1";
  195.    
  196.     switch(Integer.parseInt(defaultbtnValue))
  197.     {
  198.    
  199.         case 0:
  200.             defNNRadio = (RadioButton) v.findViewById(R.id.button_News);
  201.             break;
  202.         case 1:
  203.             defNNRadio = (RadioButton) v.findViewById(R.id.button_Notif);
  204.             break;
  205.         case 2:
  206.             defNNRadio = (RadioButton) v.findViewById(R.id.button_All);
  207.             break;
  208.         case -1:
  209.             defNNRadio = (RadioButton) v.findViewById(R.id.button_no);
  210.             break;
  211.            
  212.         default:
  213.                 break;
  214.     }
  215.  
  216.     //set default button
  217.     for (int i = 0, l = groupNN.getChildCount(); i < l; i++)
  218.     {
  219.            RadioButton xRadio = (RadioButton) groupNN.getChildAt(i);
  220.            xRadio.setChecked(false);
  221.            xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
  222.            xRadio.setTextColor(R.drawable.settings_gradient_on);
  223.         }
  224.    
  225.     if (defNNRadio != null)
  226.     {
  227.         defNNRadio.setChecked(true);
  228.         defNNRadio.setBackgroundResource(R.drawable.settings_gradient_on);
  229.         defNNRadio.setTextColor(Color.LTGRAY);
  230.    
  231.     }
  232.    
  233.    
  234.     return v;                              
  235. }
  236.  
  237.  
  238. @Override
  239.     public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
  240.     final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
  241.    
  242.     Log.d("test", "getChildView");
  243.    
  244.     RadioGroup groupNN;  
  245.     // *** gestisco i gironi della categoria ***   
  246.     groupNN = (RadioGroup) v.findViewById(R.id.radioGroupNN_child);
  247.                                  
  248.     //get objects
  249.     String groupName  = groupData.get(groupPosition).get("CATEGORY");
  250.     final CategoryClass myCat = getCategoryFromName(groupName);
  251.    
  252.    
  253.     Map<String, String> childName  = childData.get(groupPosition).get(childPosition);
  254.     final TournamentClass myTournament = getTournamentFromName(groupName, childName.get("TOURNAMENT"));
  255.                            
  256.        
  257.      groupNN.setOnCheckedChangeListener(new OnCheckedChangeListener()
  258.      {
  259.          @Override
  260.          public void onCheckedChanged(RadioGroup group, int checkedId)
  261.          {
  262.              //Log.d("Item chk", "id" + checkedId);
  263.              if(!isDataLoaded) return;
  264.              Log.d("test", "------INIT SET TOURNAMENT------- : " + myTournament.id);
  265.            
  266.              for (int i = 0, l = group.getChildCount(); i < l; i++)
  267.              {
  268.                     RadioButton xRadio = (RadioButton) group.getChildAt(i);
  269.                     xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
  270.                     xRadio.setTextColor(color.SettingsTextOffColor);
  271.                      
  272.              }
  273.        
  274.                //-----change data to send
  275.                String notifValue = "0";
  276.                
  277.                //get checked value
  278.                switch (checkedId)
  279.                {
  280.                     case R.id.button_News:
  281.                         notifValue = "0";
  282.                         break;
  283.                        
  284.                     case R.id.button_Notif:
  285.                         notifValue = "1";
  286.                         break;
  287.                        
  288.                     case R.id.button_All:
  289.                         notifValue = "2";
  290.                         break;
  291.                        
  292.                     case R.id.button_no:
  293.                         notifValue = "-1";
  294.                         break;
  295.                        
  296.                     default:
  297.                         break;
  298.                        
  299.                 }
  300.                
  301.                
  302.                 //Get Tournament and keep id of it...after save notification mode in a struct and send all on POSTS
  303.                 RadioButton radio = (RadioButton) v.findViewById(checkedId);
  304.                 if (radio != null)
  305.                 {
  306.                     // Marco Moscatelli 28/11/2013 - Imposto il check a true
  307.                     //radio.setChecked(true);
  308.                     //group.check(radio.getId());
  309.                     // end
  310.                     radio.setBackgroundResource(R.drawable.settings_gradient_on);
  311.                     radio.setTextColor(Color.LTGRAY);
  312.                 }
  313.            
  314.                 //prepare data
  315.                 updateNewsNotificationCenter(groupPosition, myCat.id, myTournament.id, notifValue);
  316.            
  317.                 Log.d("test", "------END SET TOURNAMENT-------  ");
  318.              }
  319.          //}
  320.        });
  321.      
  322.      
  323.         //set default schema
  324.         String defaultbtnValue = newsNotificationData.get(groupPosition).get("TID_" + myTournament.id);
  325.         RadioButton defNNRadio = null;
  326.         //Log.d("test", "defaultbtnValue : "+ defaultbtnValue);
  327.        
  328.         if (defaultbtnValue == null)defaultbtnValue = "-1";
  329.        
  330.         switch(Integer.parseInt(defaultbtnValue))
  331.         {
  332.             case 0:
  333.                 defNNRadio = (RadioButton) v.findViewById(R.id.button_News);
  334.                 break;
  335.             case 1:
  336.                 defNNRadio = (RadioButton) v.findViewById(R.id.button_Notif);
  337.                 break;
  338.             case 2:
  339.                 defNNRadio = (RadioButton) v.findViewById(R.id.button_All);
  340.                 break; 
  341.                
  342.             case -1:
  343.                 defNNRadio = (RadioButton) v.findViewById(R.id.button_no);
  344.                 break; 
  345.         }
  346.  
  347.         for (int i = 0, l = groupNN.getChildCount(); i < l; i++)
  348.         {
  349.                 RadioButton xRadio = (RadioButton) groupNN.getChildAt(i);
  350.                 xRadio.setChecked(false);
  351.                 xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
  352.                 xRadio.setTextColor(color.SettingsTextOffColor);
  353.                  
  354.          
  355.         }
  356.    
  357.        //set default schema
  358.        if (defNNRadio != null)
  359.        {
  360.            defNNRadio.setChecked(true);
  361.            defNNRadio.setBackgroundResource(R.drawable.settings_gradient_on);
  362.            defNNRadio.setTextColor(Color.LTGRAY);
  363.        }
  364.        
  365.        //isDataLoaded = true;
  366.    
  367.     return v;
  368. }
Add Comment
Please, Sign In to add comment