public class TempExpandableListActivity extends Activity {
ExpandableListView expd;
private ArrayList<ArrayList<String>> childrenbillableList,childrentaskList,childrenprojectList,childrentimeList;
public static ArrayList<String>
enddateList,isbillableList,projectidList,projectnameList,startdateList,
starttimeList,starttimeList24,stoptimeList,stoptimeList24,taskidList,tasknameList,totalhoursList,trackdescriptionList,
trackidList,trackprojectidList,tracktaskidList,parentdatelist,differencelist,sortedfinalhrslist;
public static ArrayList<Integer>differList,temptimeList,sortedtotalhrsList;
public static ArrayList<String>tempbillableList,temptasklist,tempprojectList,temptime1List;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
expd=(ExpandableListView)findViewById(R.id.expandable);
temptime1List=new ArrayList<String>();
tempbillableList=new ArrayList<String>();
temptasklist=new ArrayList<String>();
tempprojectList=new ArrayList<String>();
childrenbillableList=new ArrayList<ArrayList<String>>();
childrentaskList=new ArrayList<ArrayList<String>>();
childrenprojectList=new ArrayList<ArrayList<String>>();
childrentimeList=new ArrayList<ArrayList<String>>();
sortedtotalhrsList=new ArrayList<Integer>();
sortedfinalhrslist=new ArrayList<String>();
temptimeList=new ArrayList<Integer>();
differList=new ArrayList<Integer>();
differencelist=new ArrayList<String>();
starttimeList24=new ArrayList<String>();
stoptimeList24=new ArrayList<String>();
parentdatelist=new ArrayList<String>();
enddateList=new ArrayList<String>();
isbillableList=new ArrayList<String>();
projectidList=new ArrayList<String>();
projectnameList=new ArrayList<String>();
startdateList=new ArrayList<String>();
starttimeList=new ArrayList<String>();
stoptimeList=new ArrayList<String>();
taskidList=new ArrayList<String>();
tasknameList=new ArrayList<String>();
totalhoursList=new ArrayList<String>();
trackdescriptionList=new ArrayList<String>();
trackidList=new ArrayList<String>();
trackprojectidList=new ArrayList<String>();
tracktaskidList=new ArrayList<String>();
new BackgroundTask().execute();
}
public class BackgroundTask extends AsyncTask < Void, Void, Void >
{
private ProgressDialog Dialog = new ProgressDialog(TempExpandableListActivity.this);
protected void onPreExecute()
{
Dialog.setMessage("Downloading");
Dialog.show();
}
protected Void doInBackground(Void... params)
{
// write here the code to download or to perform any background task.
childrenbillableList.clear();
childrenprojectList.clear();
childrentaskList.clear();
childrentimeList.clear();
sortedfinalhrslist.clear();
differencelist.clear();
differList.clear();
parentdatelist.clear();
sortedtotalhrsList.clear();
enddateList.clear();
starttimeList24.clear();
stoptimeList24.clear();
isbillableList.clear();
projectidList.clear();
projectnameList.clear();
startdateList.clear();
starttimeList.clear();
stoptimeList.clear();
taskidList.clear();
tasknameList.clear();
totalhoursList.clear();
trackdescriptionList.clear();
trackidList.clear();
trackprojectidList.clear();
tracktaskidList.clear();
getTimeEntryInfo();
for(int i=0;i<startdateList.size();i++)
{
if(!parentdatelist.contains(startdateList.get(i)))
{
parentdatelist.add(startdateList.get(i));
}
}
for(int i=0;i<parentdatelist.size();i++)
{
temptime1List.clear();
temptimeList.clear();
tempbillableList.clear();
temptasklist.clear();
tempprojectList.clear();
for(int j=0;j<startdateList.size();j++)
{
if(parentdatelist.get(i).equalsIgnoreCase(startdateList.get(j)))
{
int total=differList.get(j);
temptimeList.add(total);
//children.add(object);temptime1List
int hr=total/60;
int mi=total%60;
String temh=String.valueOf(hr);
String temmi=String.valueOf(mi);
if(temh.length()== 1)
{
temh="0"+temh;
}
if(temmi.length()== 1)
{
temmi="0"+temmi;
}
temptime1List.add(temh+":"+temmi);
tempbillableList.add(isbillableList.get(j));
temptasklist.add(tasknameList.get(j));
tempprojectList.add(projectnameList.get(j));
}
}
childrenbillableList.add(tempbillableList);
tempbillableList=new ArrayList<String>();
childrenprojectList.add(tempprojectList);
tempprojectList=new ArrayList<String>();
childrentaskList.add(temptasklist);
temptasklist=new ArrayList<String>();
childrentimeList.add(temptime1List);
temptime1List=new ArrayList<String>();
int temp =0;
if(temptimeList.size()>0)
{
for(int x=0;x<temptimeList.size();x++)
{
if(temptimeList.size()==1)
{
temp=temptimeList.get(x);
}
else
{
temp=temp+temptimeList.get(x);
}
}
sortedtotalhrsList.add(temp);
}
}
for(int z=0;z<sortedtotalhrsList.size();z++)
{
int hrs=sortedtotalhrsList.get(z)/60;
int min=sortedtotalhrsList.get(z)%60;
String temhr=String.valueOf(hrs);
String temmin=String.valueOf(min);
if(temhr.length()== 1)
{
temhr="0"+temhr;
}
if(temmin.length()== 1)
{
temmin="0"+temmin;
}
sortedfinalhrslist.add(temhr+":"+temmin+" "+"hr");
}
return null;
}
protected void onPostExecute(Void unused)
{
Dialog.dismiss();
expd.setAdapter(new ExpandableAdapter());
}
}
public class ExpandableAdapter extends BaseExpandableListAdapter
{
@Override
public boolean areAllItemsEnabled()
{
return true;
}
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childrenbillableList.get(groupPosition).get(childPosition);
}
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder1 holder1;
LayoutInflater inflater=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
if (convertView == null)
{
convertView=inflater.inflate(R.layout.child, null);
holder1 = new ViewHolder1();
}
else
{
holder1 = (ViewHolder1) convertView.getTag();
}
holder1.dollar=(ImageView)convertView.findViewById(R.id.isbillable);
holder1.taskname=(TextView)convertView.findViewById(R.id.taskname);
holder1.projectname=(TextView)convertView.findViewById(R.id.projectname);
holder1.tasktime=(TextView)convertView.findViewById(R.id.tasktime);
if(childrenbillableList.get(groupPosition).get(childPosition).equalsIgnoreCase("false"))
{
holder1.dollar.setVisibility(View.GONE);
}
else
{
holder1.dollar.setVisibility(View.VISIBLE);
}
holder1.taskname.setText(childrentaskList.get(groupPosition).get(childPosition));
holder1.projectname.setText(childrenprojectList.get(groupPosition).get(childPosition));
holder1.tasktime.setText(childrentimeList.get(groupPosition).get(childPosition));
convertView.setTag(holder1);
return convertView;
}
class ViewHolder1 {
ImageView dollar;
TextView taskname;
TextView projectname;
TextView tasktime;
}
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return childrenbillableList.get(groupPosition).size();
}
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return parentdatelist.get(groupPosition);
}
public int getGroupCount() {
// TODO Auto-generated method stub
return parentdatelist.size();
}
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
LayoutInflater inflater=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
if (convertView == null)
{
convertView=inflater.inflate(R.layout.parent, null);
holder = new ViewHolder();
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.day=(TextView)convertView.findViewById(R.id.day);
holder.time=(TextView)convertView.findViewById(R.id.time);
holder.day.setText(parentdatelist.get(groupPosition));
holder.time.setText(sortedfinalhrslist.get(groupPosition));
convertView.setTag(holder);
return convertView;
}
class ViewHolder {
TextView day;
TextView time;
}
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}
public void getTimeEntryInfo()
{
enddateList.add("02/08/2012");
enddateList.add("02/07/2012");
enddateList.add("02/07/2012");
enddateList.add("02/07/2012");
enddateList.add("02/07/2012");
enddateList.add("02/07/2012");
enddateList.add("02/06/2012");
enddateList.add("02/02/2012");
enddateList.add("02/02/2012");
enddateList.add("01/31/2012");
enddateList.add("01/30/2012");
enddateList.add("01/30/2012");
enddateList.add("01/30/2012");
isbillableList.add("false");
isbillableList.add("false");
isbillableList.add("false");
isbillableList.add("false");
isbillableList.add("false");
isbillableList.add("false");
isbillableList.add("false");
isbillableList.add("false");
isbillableList.add("false");
isbillableList.add("false");
isbillableList.add("false");
isbillableList.add("false");
isbillableList.add("false");
projectidList.add("16");
projectidList.add("0");
projectidList.add("0");
projectidList.add("7");
projectidList.add("7");
projectidList.add("7");
projectidList.add("7");
projectidList.add("0");
projectidList.add("0");
projectidList.add("7");
projectidList.add("0");
projectidList.add("0");
projectidList.add("6");
projectnameList.add("4FebNewProject");
projectnameList.add("NO DESCRIPTION");
projectnameList.add("NO DESCRIPTION");
projectnameList.add("Coggl Company Admin");
projectnameList.add("Coggl Company Admin");
projectnameList.add("Coggl Company Admin");
projectnameList.add("Coggl Company Admin");
projectnameList.add("NO DESCRIPTION");
projectnameList.add("NO DESCRIPTION");
projectnameList.add("Test Project1");
projectnameList.add("NO DESCRIPTION");
projectnameList.add("NO DESCRIPTION");
projectnameList.add("Test Project");
startdateList.add("02/07/2012");
startdateList.add("02/07/2012");
startdateList.add("02/07/2012");
startdateList.add("02/07/2012");
startdateList.add("02/06/2012");
startdateList.add("02/07/2012");
startdateList.add("02/06/2012");
startdateList.add("02/02/2012");
startdateList.add("02/02/2012");
startdateList.add("01/30/2012");
startdateList.add("01/30/2012");
startdateList.add("01/30/2012");
startdateList.add("01/30/2012");
starttimeList.add("9:45 PM");
starttimeList.add("9:19 AM");
starttimeList.add("9:18 AM");
starttimeList.add("5:52 AM");
starttimeList.add("9:33 PM");
starttimeList.add("5:25 AM");
starttimeList.add("1:04 AM");
starttimeList.add("1:52 AM");
starttimeList.add("1:51 AM");
starttimeList.add("1:18 PM");
starttimeList.add("12:56 PM");
starttimeList.add("5:10 AM");
starttimeList.add("11:29 AM");
stoptimeList.add("11:43 PM");
stoptimeList.add("9:19 AM");
stoptimeList.add("9:18 AM");
stoptimeList.add("5:52 AM");
stoptimeList.add("3:44 AM");
stoptimeList.add("5:27 AM");
stoptimeList.add("2:04 AM");
stoptimeList.add("1:52 AM");
stoptimeList.add("1:52 AM");
stoptimeList.add("1:21 PM");
stoptimeList.add("12:56 PM");
stoptimeList.add("12:58 PM");
stoptimeList.add("11:29 AM");
taskidList.add("9");
taskidList.add("0");
taskidList.add("0");
taskidList.add("2");
taskidList.add("1");
taskidList.add("13");
taskidList.add("2");
taskidList.add("0");
taskidList.add("0");
taskidList.add("4");
taskidList.add("0");
taskidList.add("0");
taskidList.add("1");
tasknameList.add("New Task......");
tasknameList.add("NO TASK");
tasknameList.add("NO TASK");
tasknameList.add("Create Company Admin Dashboard");
tasknameList.add("Create Company Admin Login Screen");
tasknameList.add("Create Company Admin Dashboard");
tasknameList.add("Create Company Admin Dashboard");
tasknameList.add("NO TASK");
tasknameList.add("NO TASK");
tasknameList.add("Design");
tasknameList.add("NO TASK");
tasknameList.add("NO TASK");
tasknameList.add("Development");
totalhoursList.add("7080");
totalhoursList.add("0");
totalhoursList.add("19");
totalhoursList.add("0");
totalhoursList.add("22260");
totalhoursList.add("120");
totalhoursList.add("3621");
totalhoursList.add("8");
totalhoursList.add("7");
totalhoursList.add("180");
totalhoursList.add("8");
totalhoursList.add("2880");
totalhoursList.add("9");
trackdescriptionList.add("eryewr bewryer1s");
trackdescriptionList.add("eryewr bewryer1");
trackdescriptionList.add("No Description");
trackdescriptionList.add("test1233");
trackdescriptionList.add("Careful");
trackdescriptionList.add("New Test Job");
trackdescriptionList.add("test");
trackdescriptionList.add("No Description");
trackdescriptionList.add("fgfdsgfd");
trackdescriptionList.add("Design Test");
trackdescriptionList.add("123456");
trackdescriptionList.add("New Test232");
trackdescriptionList.add("New Test232");
trackidList.add("149");
trackidList.add("147");
trackidList.add("146");
trackidList.add("142");
trackidList.add("141");
trackidList.add("140");
trackidList.add("139");
trackidList.add("137");
trackidList.add("136");
trackidList.add("127");
trackidList.add("126");
trackidList.add("125");
trackidList.add("124");
trackprojectidList.add("72");
trackprojectidList.add("0");
trackprojectidList.add("0");
trackprojectidList.add("69");
trackprojectidList.add("68");
trackprojectidList.add("67");
trackprojectidList.add("66");
trackprojectidList.add("0");
trackprojectidList.add("0");
trackprojectidList.add("65");
trackprojectidList.add("0");
trackprojectidList.add("0");
trackprojectidList.add("64");
tracktaskidList.add("55");
tracktaskidList.add("0");
tracktaskidList.add("0");
tracktaskidList.add("54");
tracktaskidList.add("53");
tracktaskidList.add("52");
tracktaskidList.add("51");
tracktaskidList.add("0");
tracktaskidList.add("0");
tracktaskidList.add("50");
tracktaskidList.add("0");
tracktaskidList.add("0");
tracktaskidList.add("49");
SimpleDateFormat displayFormat = new SimpleDateFormat("HH:mm");
SimpleDateFormat parseFormat = new SimpleDateFormat("hh:mm a");
for(int i=0;i<starttimeList.size();i++)
{
Date stdate = null;
try {
stdate = parseFormat.parse(starttimeList.get(i));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String st24time=displayFormat.format(stdate);
starttimeList24.add(st24time);
Date etdate = null;
try {
etdate = parseFormat.parse(stoptimeList.get(i));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String et24time=displayFormat.format(etdate);
stoptimeList24.add(et24time);
String edate[]=enddateList.get(i).split("/");
String etime[]=et24time.split(":");
String sdate[]=startdateList.get(i).split("/");
String stime[]=st24time.split(":");
Date ed = new GregorianCalendar(Integer.parseInt(edate[2]), Integer.parseInt(edate[0]),Integer.parseInt(edate[1]), Integer.parseInt(etime[0]), Integer.parseInt(etime[1])).getTime();
Date sd = new GregorianCalendar(Integer.parseInt(sdate[2]), Integer.parseInt(sdate[0]),Integer.parseInt(sdate[1]), Integer.parseInt(stime[0]), Integer.parseInt(stime[1])).getTime();
int diffmin= (int) ((ed.getTime() - sd.getTime())/60000);
int hrs=diffmin/60;
int min=diffmin%60;
differList.add(diffmin);
differencelist.add(hrs+":"+min);
}
}
}