结队项目3

package com.pwp.activity;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.AlertDialog.Builder;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Display;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.GestureDetector.OnGestureListener;
import android.view.View.OnTouchListener;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.DatePicker;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.ViewFlipper;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout.LayoutParams;
import com.pwp.activity.CalendarConvert;
import com.pwp.activity.CalendarView;
import com.pwp.activity.ScheduleAll;
import com.pwp.activity.ScheduleInfoView;
import com.pwp.activity.ScheduleView;
import com.pwp.borderText.BorderText;
import com.pwp.dao.ScheduleDAO;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class CalendarActivity extends Activity implements OnGestureListener {
private ViewFlipper flipper = null;
private GestureDetector gestureDetector = null;
private CalendarView calV = null;
private GridView gridView = null;
private BorderText topText = null;
private Drawable draw = null;
private static int jumpMonth = 0;
private static int jumpYear = 0;
private int year_c = 0;
private int month_c = 0;
private int day_c = 0;
private String currentDate = "";
private ScheduleDAO dao = null;

public CalendarActivity() {
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");
    this.currentDate = sdf.format(date);
    this.year_c = Integer.parseInt(this.currentDate.split("-")[0]);
    this.month_c = Integer.parseInt(this.currentDate.split("-")[1]);
    this.day_c = Integer.parseInt(this.currentDate.split("-")[2]);
    this.dao = new ScheduleDAO(this);
}

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(2130903042);
    this.gestureDetector = new GestureDetector(this);
    this.flipper = (ViewFlipper)this.findViewById(2131099654);
    this.flipper.removeAllViews();
    this.calV = new CalendarView(this, this.getResources(), jumpMonth, jumpYear, this.year_c, this.month_c, this.day_c);
    this.addGridView();
    this.gridView.setAdapter(this.calV);
    this.flipper.addView(this.gridView, 0);
    this.topText = (BorderText)this.findViewById(2131099653);
    this.addTextToTopTextView(this.topText);
}

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
byte gvFlag = 0;
int gvFlag1;
if(e1.getX() - e2.getX() > 120.0F) {
this.addGridView();
++jumpMonth;
this.calV = new CalendarView(this, this.getResources(), jumpMonth, jumpYear, this.year_c, this.month_c, this.day_c);
this.gridView.setAdapter(this.calV);
this.addTextToTopTextView(this.topText);
gvFlag1 = gvFlag + 1;
this.flipper.addView(this.gridView, gvFlag1);
this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, 2130968576));
this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, 2130968577));
this.flipper.showNext();
this.flipper.removeViewAt(0);
return true;
} else if(e1.getX() - e2.getX() < -120.0F) {
this.addGridView();
--jumpMonth;
this.calV = new CalendarView(this, this.getResources(), jumpMonth, jumpYear, this.year_c, this.month_c, this.day_c);
this.gridView.setAdapter(this.calV);
gvFlag1 = gvFlag + 1;
this.addTextToTopTextView(this.topText);
this.flipper.addView(this.gridView, gvFlag1);
this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, 2130968578));
this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, 2130968579));
this.flipper.showPrevious();
this.flipper.removeViewAt(0);
return true;
} else {
return false;
}
}

public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 1, 1, "今天");
menu.add(0, 1 + 1, 1 + 1, "跳转");
menu.add(0, 1 + 2, 1 + 2, "日程");
menu.add(0, 1 + 3, 1 + 3, "日期转换");
return super.onCreateOptionsMenu(menu);
}

public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch(item.getItemId()) {
    case 1:
        int xMonth = jumpMonth;
        int xYear = jumpYear;
        byte gvFlag = 0;
        jumpMonth = 0;
        jumpYear = 0;
        this.addGridView();
        this.year_c = Integer.parseInt(this.currentDate.split("-")[0]);
        this.month_c = Integer.parseInt(this.currentDate.split("-")[1]);
        this.day_c = Integer.parseInt(this.currentDate.split("-")[2]);
        this.calV = new CalendarView(this, this.getResources(), jumpMonth, jumpYear, this.year_c, this.month_c, this.day_c);
        this.gridView.setAdapter(this.calV);
        this.addTextToTopTextView(this.topText);
        int gvFlag1 = gvFlag + 1;
        this.flipper.addView(this.gridView, gvFlag1);
        if(xMonth != 0 || xYear != 0) {
            if((xYear != 0 || xMonth <= 0) && xYear <= 0) {
                this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, 2130968578));
                this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, 2130968579));
                this.flipper.showPrevious();
            } else {
                this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, 2130968576));
                this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, 2130968577));
                this.flipper.showNext();
            }
        }

        this.flipper.removeViewAt(0);
        break;
    case 2:
        (new DatePickerDialog(this, new OnDateSetListener() {
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                if(year >= 1901 && year <= 2049) {
                    byte gvFlag = 0;
                    CalendarActivity.this.addGridView();
                    CalendarActivity.this.calV = new CalendarView(CalendarActivity.this, CalendarActivity.this.getResources(), year, monthOfYear + 1, dayOfMonth);
                    CalendarActivity.this.gridView.setAdapter(CalendarActivity.this.calV);
                    CalendarActivity.this.addTextToTopTextView(CalendarActivity.this.topText);
                    int gvFlag1 = gvFlag + 1;
                    CalendarActivity.this.flipper.addView(CalendarActivity.this.gridView, gvFlag1);
                    if(year == CalendarActivity.this.year_c) {
                        ;
                    }

                    if((year != CalendarActivity.this.year_c || monthOfYear + 1 <= CalendarActivity.this.month_c) && year <= CalendarActivity.this.year_c) {
                        CalendarActivity.this.flipper.setInAnimation(AnimationUtils.loadAnimation(CalendarActivity.this, 2130968578));
                        CalendarActivity.this.flipper.setOutAnimation(AnimationUtils.loadAnimation(CalendarActivity.this, 2130968579));
                        CalendarActivity.this.flipper.showPrevious();
                    } else {
                        CalendarActivity.this.flipper.setInAnimation(AnimationUtils.loadAnimation(CalendarActivity.this, 2130968576));
                        CalendarActivity.this.flipper.setOutAnimation(AnimationUtils.loadAnimation(CalendarActivity.this, 2130968577));
                        CalendarActivity.this.flipper.showNext();
                    }

CalendarActivity.this.flipper.removeViewAt(0);
CalendarActivity.this.year_c = year;
CalendarActivity.this.month_c = monthOfYear + 1;
CalendarActivity.this.day_c = dayOfMonth;
CalendarActivity.jumpMonth = 0;
CalendarActivity.jumpYear = 0;
} else {
(new Builder(CalendarActivity.this)).setTitle("错误日期").setMessage("跳转日期范围(1901/1/1-2049/12/31)").setPositiveButton("确认", (OnClickListener)null).show();
}

            }
        }, this.year_c, this.month_c - 1, this.day_c)).show();
        break;
    case 3:
        Intent intent = new Intent();
        intent.setClass(this, ScheduleAll.class);
        this.startActivity(intent);
        break;
    case 4:
        Intent intent1 = new Intent();
        intent1.setClass(this, CalendarConvert.class);
        intent1.putExtra("date", new int[]{this.year_c, this.month_c, this.day_c});
        this.startActivity(intent1);
    }

    return super.onMenuItemSelected(featureId, item);
}

public boolean onTouchEvent(MotionEvent event) {
    return this.gestureDetector.onTouchEvent(event);
}

public boolean onDown(MotionEvent e) {
    return false;
}

public void onLongPress(MotionEvent e) {
}

public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    return false;
}

public void onShowPress(MotionEvent e) {
}

public boolean onSingleTapUp(MotionEvent e) {
    return false;
}

public void addTextToTopTextView(TextView view) {
    StringBuffer textDate = new StringBuffer();
    this.draw = this.getResources().getDrawable(2130837519);
    view.setBackgroundDrawable(this.draw);
    textDate.append(this.calV.getShowYear()).append("年").append(this.calV.getShowMonth()).append("月").append("\t");
    if(!this.calV.getLeapMonth().equals("") && this.calV.getLeapMonth() != null) {
        textDate.append("闰").append(this.calV.getLeapMonth()).append("月").append("\t");
    }

    textDate.append(this.calV.getAnimalsYear()).append("年").append("(").append(this.calV.getCyclical()).append("年)");
    view.setText(textDate);
    view.setTextColor(-16777216);
    view.setTypeface(Typeface.DEFAULT_BOLD);
}

private void addGridView() {
    LayoutParams params = new LayoutParams(-1, -2);
    WindowManager windowManager = this.getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    int Width = display.getWidth();
    int Height = display.getHeight();
    this.gridView = new GridView(this);
    this.gridView.setNumColumns(7);
    this.gridView.setColumnWidth(46);
    if(Width == 480 && Height == 800) {
        this.gridView.setColumnWidth(69);
    }

    this.gridView.setGravity(16);
    this.gridView.setSelector(new ColorDrawable(0));
    this.gridView.setVerticalSpacing(1);
    this.gridView.setHorizontalSpacing(1);
    this.gridView.setBackgroundResource(2130837508);
    this.gridView.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            return CalendarActivity.this.gestureDetector.onTouchEvent(event);
        }
    });

this.gridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
int startPosition = CalendarActivity.this.calV.getStartPositon();
int endPosition = CalendarActivity.this.calV.getEndPosition();
if(startPosition <= position && position <= endPosition) {
String scheduleDay = CalendarActivity.this.calV.getDateByClickItem(position).split("\.")[0];
String scheduleYear = CalendarActivity.this.calV.getShowYear();
String scheduleMonth = CalendarActivity.this.calV.getShowMonth();
String week = "";
String[] scheduleIDs = CalendarActivity.this.dao.getScheduleByTagDate(Integer.parseInt(scheduleYear), Integer.parseInt(scheduleMonth), Integer.parseInt(scheduleDay));
if(scheduleIDs != null && scheduleIDs.length > 0) {
Intent scheduleDate1 = new Intent();
scheduleDate1.setClass(CalendarActivity.this, ScheduleInfoView.class);
scheduleDate1.putExtra("scheduleID", scheduleIDs);
CalendarActivity.this.startActivity(scheduleDate1);
} else {
switch(position % 7) {
case 0:
week = "星期日";
break;
case 1:
week = "星期一";
break;
case 2:
week = "星期二";
break;
case 3:
week = "星期三";
break;
case 4:
week = "星期四";
break;
case 5:
week = "星期五";
break;
case 6:
week = "星期六";
}

                    ArrayList scheduleDate = new ArrayList();
                    scheduleDate.add(scheduleYear);
                    scheduleDate.add(scheduleMonth);
                    scheduleDate.add(scheduleDay);
                    scheduleDate.add(week);
                    Intent intent = new Intent();
                    intent.putStringArrayListExtra("scheduleDate", scheduleDate);
                    intent.setClass(CalendarActivity.this, ScheduleView.class);
                    CalendarActivity.this.startActivity(intent);
                }
            }

        }
    });
    this.gridView.setLayoutParams(params);
}

}

posted on 2017-06-15 09:26  SB小吴  阅读(129)  评论(0编辑  收藏  举报

导航