package wordroid.activitys;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import wordroid.model.BookList;
import wordroid.model.R;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import wordroid.business.OperationOfBooks;
import wordroid.database.DataAccess;
import wordroid.model.WordList;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
public class ReviewMain extends TabActivity implements TabHost.TabContentFactory{
private int week=0;
public ArrayList<WordList> wordlist;
private ArrayList<String> listShould ;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
TabHost th = getTabHost();
DataAccess data = new DataAccess(this);
wordlist=data.QueryList("BOOKID ='"+DataAccess.bookID+"'", null);
BookList book =data.QueryBook("ID ='"+DataAccess.bookID+"'", null).get(0);
listShould = new ArrayList<String>(wordlist.size());
for(int i=0;i<wordlist.size();i++){
if (wordlist.get(i).getShouldReview().equals("1")){
listShould.add(wordlist.get(i).getList());
}
}
this.setTitle("复习-"+book.getName());
th.addTab(th.newTabSpec("shouldreview").setIndicator("该复习的LIST",ReviewMain.this.getResources().getDrawable(R.drawable.should)).setContent(this));
th.addTab(th.newTabSpec("alllists").setIndicator("所有LIST",ReviewMain.this.getResources().getDrawable(R.drawable.all)).setContent(this));
th.addTab(th.newTabSpec("plan").setIndicator("我的复习计划",ReviewMain.this.getResources().getDrawable(R.drawable.plan)).setContent(this));
}
@Override
public View createTabContent(final String tag) {
// TODO Auto-generated method stub
final TextView textview = new TextView(this);
textview.setTextColor(Color.BLACK);
textview.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.main_budget_lv_header));
final ListView lv = new ListView(this);
lv.setCacheColorHint(0);
LinearLayout ll= new LinearLayout(this);
ll.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.main_back));
ll.setOrientation(LinearLayout.VERTICAL);
if (tag.equals("shouldreview")){
textview.setText(" 需要进行复习的LIST");
ll.addView(textview);
lv.setAdapter(new SimpleAdapter(this, getData(tag), R.layout.list1, new String[]{"label","times","lasttime","image"}, new int[]{R.id.label,R.id.times,R.id.lasttime,R.id.list1_image}));
lv.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
final int arg2, long arg3) {
// TODO Auto-generated method stub
startReview(arg2,1);
}
});
lv.setOnItemLongClickListener(new OnItemLongClickListener(){
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
final int arg2, long arg3) {
// TODO Auto-generated method stub
Dialog dialog = new AlertDialog.Builder(ReviewMain.this)
.setIcon(R.drawable.dialog_icon)
.setTitle("操作")
.setItems(new String[]{"标记为已复习"}, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
if (which==0){
DataAccess data = new DataAccess(ReviewMain.this);
WordList labelList = wordlist.get(Integer.parseInt(listShould.get(arg2))-1);
labelList.setShouldReview("0");
labelList.setReview_times(String.valueOf((Integer.parseInt(labelList.getReview_times())+1)));
Calendar cal = Calendar.getInstance();
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
String date=f.format(cal.getTime());
labelList.setReviewTime(date);
data.UpdateList(labelList);
Intent intent = new Intent();
intent.setClass(ReviewMain.this, ReviewMain.class);
finish();
startActivity(intent);
}
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.create();
dialog.show();
return false;
}
});
ll.addView(lv);
}
if (tag.equals("alllists")){
textview.setText(" 所有的LIST");
ll.addView(textview);
lv.setAdapter(new SimpleAdapter(this, getData(tag), R.layout.list2, new String[]{"label","state","image"}, new int[]{R.id.label,R.id.state,R.id.list2_image}));
lv.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
final int arg2, long arg3) {
// TODO Auto-generated method stub
if(wordlist.get(arg2).getLearned().equals("0")){
Dialog dialog = new AlertDialog.Builder(ReviewMain.this)
.setIcon(R.drawable.dialog_icon)
.setTitle("提醒")
.setMessage("这个单元(LIST-"+(arg2+1)+")还没有学习过,要现在学习吗?")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK so do some stuff */
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("list", String.valueOf(arg2+1));
intent.setClass(ReviewMain.this, studyWord.class);
intent.putExtras(bundle);
finish();
startActivity(intent);
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK so do some stuff */
}
}).create();
dialog.show();
}
else if(wordlist.get(arg2).getShouldReview().equals("1")){
startReview(arg2+1,2);
}
else if(wordlist.get(arg2).getShouldReview().equals("0")){
Dialog dialog = new AlertDialog.Builder(ReviewMain.this)
.setIcon(R.drawable.dialog_icon)
.setTitle("提醒")
.setMessage("这个单元(LIST-"+(arg2+1)+")暂时不需要进行复习,确定要现在复习吗?")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK so do some stuff */
startReview(arg2+1,2);
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK so do some stuff */
}
}).create();
dialog.show();
}
}
});
ll.addView(lv);
}
if (tag.equals("plan")){
textview.