Advertisement
kusha45

AsyncTask

Feb 8th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.13 KB | None | 0 0
  1. //My Main Class - It's a Calendar
  2.  
  3. final TextView tvDate[] = new TextView[7];
  4. final TextView tvIssue[] = new TextView[7];
  5.  
  6. Class Calender extends Activity{
  7.     @Override
  8.     public void onCreate(Bundle savedInstanceState) {
  9.         super.onCreate(savedInstanceState);
  10.         setContentView(R.layout.calender);
  11.        
  12.         tvDate[0] = (TextView) findViewById(R.id.tvFirstDate);
  13.         tvDate[1] = (TextView) findViewById(R.id.tvSecondDate);
  14.         tvDate[2] = (TextView) findViewById(R.id.tvThirdDate);
  15.         tvDate[3] = (TextView) findViewById(R.id.tvFourthDate);
  16.         tvDate[4] = (TextView) findViewById(R.id.tvFifthDate);
  17.         tvDate[5] = (TextView) findViewById(R.id.tvSixthDate);
  18.         tvDate[6] = (TextView) findViewById(R.id.tvSeventhDate);
  19.  
  20.         for (int i = 0; i < 7; i++) {
  21.             tvIssue[i] = new TextView(Calender.this);
  22.         }
  23.        
  24.         layoutLinear[0] = (LinearLayout) findViewById(R.id.Llfirstday);
  25.         layoutLinear[1] = (LinearLayout) findViewById(R.id.LlSecondDay);
  26.         layoutLinear[2] = (LinearLayout) findViewById(R.id.LlThirdDay);
  27.         layoutLinear[3] = (LinearLayout) findViewById(R.id.LlFourthDay);
  28.         layoutLinear[4] = (LinearLayout) findViewById(R.id.LlFifthDay);
  29.         layoutLinear[5] = (LinearLayout) findViewById(R.id.LlSixthDay);
  30.         layoutLinear[6] = (LinearLayout) findViewById(R.id.LlSeventhDay);
  31.        
  32.         calendar = Calendar.getInstance();
  33.         calendar.clear();
  34.         calendar.set(Calendar.YEAR, year);
  35.         calendar.set(Calendar.WEEK_OF_YEAR, week);
  36.         date = calendar.getTime();
  37.         String dt;
  38.        
  39.         dt = sdf.format(date);
  40.         calendar.add(Calendar.DATE, 1);
  41.         calendar.set(Calendar.YEAR, year);
  42.         calendar.set(Calendar.WEEK_OF_YEAR, week);
  43.        
  44.         try {
  45.             calendar.setTime(sdf.parse(dt));
  46.         } catch (ParseException e2) {
  47.            
  48.             e2.printStackTrace();
  49.         }
  50.         calendar.add(Calendar.DATE, -1);
  51.        
  52.         new AsyncIssue().execute();
  53. }
  54.  
  55. class AsyncIssue extends AsyncTask<Void, Void, Void>{
  56.        
  57.          @Override
  58.          protected Void doInBackground(Void... params) {
  59.              for(int i = 0; i < 7; i++) {
  60.                     SimpleDateFormat sdf = new SimpleDateFormat("M-dd-yyyy");
  61.                     strDate = "";
  62.                     calendar.add(Calendar.DATE, 1);
  63.                     strDate = sdf.format(calendar.getTime());
  64.                     System.out.println("Date in AsyncIssue is :"+strDate);
  65.                     tvDate[i].setText(strDate);
  66.                    
  67.                     try{
  68.                         String LDID = "";
  69.                         JSONObject[] arrJSONCalData = null;
  70.                        
  71.                         arrJSONCalData = gd.FillCalendarData(Login.userId, strDate, Login.userName);
  72.                        
  73.                         for(int k = 0 ; k < arrJSONCalData.length;k++){
  74.                            
  75.                             String leaveTitle = arrJSONCalData[k].get("leaveTitle").toString();
  76.                             LDID = arrJSONCalData[k].get("LDID").toString();
  77.                            
  78.                             final String calDisplay = arrJSONCalData[k].get("detail").toString();
  79.                             final String headerinIssue = arrJSONCalData[k].get("Header").toString();
  80.                             final String deleteReason = arrJSONCalData[k].get("Delete_reason").toString();
  81.                            
  82.                             System.out.println(i + " :=> LeaveTitle      : " + leaveTitle);
  83.                             System.out.println(i + " :=> Detail : " + arrJSONCalData[k].get("detail").toString());
  84.                             System.out.println(i + " :=> Header     : " + arrJSONCalData[k].get("Header").toString());
  85.                             System.out.println(i + " :=> Delete_Reason  : " + arrJSONCalData[k].get("Delete_reason").toString());
  86.                             System.out.println(i + " :=> LDID : " + arrJSONCalData[k].get("LDID").toString());
  87.                            
  88.                             tvIssue[i] = new TextView(Calender.this);
  89.                             tvIssue[i].setText("> " + leaveTitle);
  90.                             tvIssue[i].setTag(LDID);
  91.                             tvIssue[i].setTextColor(Color.parseColor("#000000"));
  92.                            
  93.                             if(k % 2 == 0 || k == 0){
  94.                                 tvIssue[i].setBackgroundColor(Color.parseColor("#bdc3bd"));
  95.                             }
  96.                            
  97.                             tvIssue[i].setWidth(150);
  98.                             tvIssue[i].setTextSize(11);
  99.                             tvIssue[i].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  100.                             tvIssue[i].offsetTopAndBottom(5);
  101.                             layoutLinear[i].addView(tvIssue[i]);
  102.                            
  103.                             tvIssue[i].setOnClickListener(new OnClickListener() {
  104.                                 public void onClick(View v) {
  105.                                     try {
  106.                                        
  107.                                         System.out.println("Reason in CLick :"+deleteReason);
  108.                                         System.out.println("LDID in CLick :"+ v.getTag().toString());
  109.                                         System.out.println("calDisplay in CLick :" + calDisplay);
  110.                                         System.out.println("headerinIssue in CLick :"+ headerinIssue);
  111.                                        
  112.                                         Intent intent = new Intent(Calender.this,AddDisplayIssue.class);
  113.                                         intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  114.                                         intent.putExtra("Detail",calDisplay);
  115.                                         intent.putExtra("LDID", v.getTag().toString());
  116.                                         intent.putExtra("Header", headerinIssue);
  117.                                         intent.putExtra("Delete Reason",deleteReason);
  118.                                         intent.putExtra("Flag", "DisplayIssueDetail");
  119.                                        
  120.                                         startActivity(intent);
  121.                                     }
  122.                                     catch (Exception e) {
  123.                                         System.out.println("Error on click of Issue :"+e);
  124.                                     }
  125.                                 }  
  126.                             });
  127.                         }
  128.                     }
  129.                     catch (Exception e) {
  130.                         System.out.println("Error in AsyncIssue :"+e);
  131.                     }
  132.              }
  133.              
  134.              return null;
  135.          }
  136.  
  137.             @Override
  138.             protected void onPostExecute(Void result) {
  139.                // new AsyncIssue().execute();
  140.             }
  141.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement