From 76e0c6fb5f606d63f8a9f41fa8dbe97eec049e6f Mon Sep 17 00:00:00 2001 From: ram <623910786@qq.com> Date: Thu, 18 Aug 2016 21:29:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=90=E8=88=AA=20=E6=BB=91=E5=B1=8F?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/stone/shop/adapter/ClassroomAdapter.java | 69 ++++++ .../src/com/stone/shop/model/Classroom.java | 22 ++ .../src/com/stone/shop/model/Reservation.java | 44 ++++ .../src/com/stone/shop/view/ClassroomActivity.java | 93 ++++++++ .../com/stone/shop/view/ReservationActivity.java | 138 ++++++++++++ .../src/com/stone/shop/view/SplashActivity.java | 75 +++++++ .../src/com/stone/slide/MyScrollLayout.java | 200 ++++++++++++++++++ .../src/com/stone/slide/OnViewChangeListener.java | 5 + .../在这里1.0/src/com/stone/slide/TestOpen.java | 102 +++++++++ .../src/com/stone/ui/DateTimePickDialogUtil.java | 188 ++++++++++++++++ 10 files changed, 936 insertions(+) create mode 100644 代码/在这里1.0/src/com/stone/shop/adapter/ClassroomAdapter.java create mode 100644 代码/在这里1.0/src/com/stone/shop/model/Classroom.java create mode 100644 代码/在这里1.0/src/com/stone/shop/model/Reservation.java create mode 100644 代码/在这里1.0/src/com/stone/shop/view/ClassroomActivity.java create mode 100644 代码/在这里1.0/src/com/stone/shop/view/ReservationActivity.java create mode 100644 代码/在这里1.0/src/com/stone/shop/view/SplashActivity.java create mode 100644 代码/在这里1.0/src/com/stone/slide/MyScrollLayout.java create mode 100644 代码/在这里1.0/src/com/stone/slide/OnViewChangeListener.java create mode 100644 代码/在这里1.0/src/com/stone/slide/TestOpen.java create mode 100644 代码/在这里1.0/src/com/stone/ui/DateTimePickDialogUtil.java diff --git a/代码/在这里1.0/src/com/stone/shop/adapter/ClassroomAdapter.java b/代码/在这里1.0/src/com/stone/shop/adapter/ClassroomAdapter.java new file mode 100644 index 0000000..7deb441 --- /dev/null +++ b/代码/在这里1.0/src/com/stone/shop/adapter/ClassroomAdapter.java @@ -0,0 +1,69 @@ +package com.stone.shop.adapter; + +import java.util.List; + +import com.stone.shop.R; +import com.stone.shop.model.Classroom; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +public class ClassroomAdapter extends BaseAdapter { + + private Context mContext; + private List mNewsList; // 商品列表信息 + private LayoutInflater mInflater = null; + + public ClassroomAdapter(Context context, List newsList) { + mContext = context; + mNewsList = newsList; + mInflater = LayoutInflater.from(context); + } + + @Override + public int getCount() { + return mNewsList.size(); + } + + @Override + public Object getItem(int position) { + return mNewsList.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + // 刷新列表中的数据 + public void refresh(List list) { + mNewsList = list; + notifyDataSetChanged(); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder; + if (convertView == null) { + convertView = mInflater.inflate(R.layout.gv_item_classroom, null); + viewHolder = new ViewHolder(); + viewHolder.tv_chooseText = (TextView) convertView.findViewById(R.id.tv_chooseText); + convertView.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) convertView.getTag(); + } + viewHolder.tv_chooseText.setText(mNewsList.get(position).getName()); + return convertView; + } + + class ViewHolder { + + public TextView tv_chooseText; // 博学堂讲座标题 + + } + +} diff --git a/代码/在这里1.0/src/com/stone/shop/model/Classroom.java b/代码/在这里1.0/src/com/stone/shop/model/Classroom.java new file mode 100644 index 0000000..85c64eb --- /dev/null +++ b/代码/在这里1.0/src/com/stone/shop/model/Classroom.java @@ -0,0 +1,22 @@ +package com.stone.shop.model; + +import cn.bmob.v3.BmobObject; + +public class Classroom extends BmobObject { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "ClassRoom [name=" + name + "]"; + } + +} diff --git a/代码/在这里1.0/src/com/stone/shop/model/Reservation.java b/代码/在这里1.0/src/com/stone/shop/model/Reservation.java new file mode 100644 index 0000000..d1fafaa --- /dev/null +++ b/代码/在这里1.0/src/com/stone/shop/model/Reservation.java @@ -0,0 +1,44 @@ +package com.stone.shop.model; + +import cn.bmob.v3.BmobObject; + +public class Reservation extends BmobObject { + + private String roomId; + private String roomName; + private String userId; + private String dateTime; + + public String getRoomId() { + return roomId; + } + + public void setRoomId(String roomId) { + this.roomId = roomId; + } + + public String getRoomName() { + return roomName; + } + + public void setRoomName(String roomName) { + this.roomName = roomName; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getDateTime() { + return dateTime; + } + + public void setDateTime(String dateTime) { + this.dateTime = dateTime; + } + +} diff --git a/代码/在这里1.0/src/com/stone/shop/view/ClassroomActivity.java b/代码/在这里1.0/src/com/stone/shop/view/ClassroomActivity.java new file mode 100644 index 0000000..7707d63 --- /dev/null +++ b/代码/在这里1.0/src/com/stone/shop/view/ClassroomActivity.java @@ -0,0 +1,93 @@ +package com.stone.shop.view; + +import java.util.ArrayList; +import java.util.List; + +import cn.bmob.v3.BmobQuery; +import cn.bmob.v3.listener.FindListener; + +import com.stone.shop.R; +import com.stone.shop.adapter.BXTListAdapter; +import com.stone.shop.adapter.ClassroomAdapter; +import com.stone.shop.model.Classroom; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.GridView; +import android.widget.ListView; +import android.widget.TextView; +import android.widget.Toast; + +public class ClassroomActivity extends Activity implements OnItemClickListener { + + private static final String TAG = "BXTActivity"; + + private GridView lvBXTNews; + private ClassroomAdapter mBxtListAdapter; + private List mBXTNewsList; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_classroom); + + initView(); + initData(); + + } + + private void initView() { + lvBXTNews = (GridView) findViewById(R.id.gv_classroom); + mBXTNewsList = new ArrayList(); + mBxtListAdapter = new ClassroomAdapter(this, mBXTNewsList); + lvBXTNews.setAdapter(mBxtListAdapter); + lvBXTNews.setOnItemClickListener(this); + + TextView tv_title = (TextView) findViewById(R.id.tv_title); + tv_title.setText("教室"); + } + + private void initData() { + BmobQuery query = new BmobQuery(); + query.findObjects(this, new FindListener() { + + @Override + public void onSuccess(List newsList) { + // toast("查询商品成功, 共" + newsList.size()); + if (newsList.size() == 0) + toast("亲, 暂时还木有教室哦"); + else { + mBXTNewsList = newsList; + mBxtListAdapter.refresh(newsList); + mBxtListAdapter.notifyDataSetChanged(); + + } + + } + + @Override + public void onError(int arg0, String arg1) { + toast("查询失败"); + } + }); + } + + private void toast(String toast) { + Toast.makeText(this, toast, Toast.LENGTH_SHORT).show(); + } + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Intent intent = new Intent(ClassroomActivity.this, ReservationActivity.class); + Classroom classroom = mBXTNewsList.get(position); + intent.putExtra("roomId", classroom.getObjectId()); + intent.putExtra("roomName", classroom.getName()); + startActivity(intent); + + } + +} diff --git a/代码/在这里1.0/src/com/stone/shop/view/ReservationActivity.java b/代码/在这里1.0/src/com/stone/shop/view/ReservationActivity.java new file mode 100644 index 0000000..90bf398 --- /dev/null +++ b/代码/在这里1.0/src/com/stone/shop/view/ReservationActivity.java @@ -0,0 +1,138 @@ +package com.stone.shop.view; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +import com.stone.shop.R; +import com.stone.shop.model.Reservation; +import com.stone.shop.model.User; +import com.stone.ui.DateTimePickDialogUtil; +import com.stone.ui.DateTimePickDialogUtil.DateTimeListener; + +import android.app.Activity; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; +import cn.bmob.v3.BmobQuery; +import cn.bmob.v3.listener.DeleteListener; +import cn.bmob.v3.listener.FindListener; +import cn.bmob.v3.listener.SaveListener; + +public class ReservationActivity extends Activity { + + private Button btn_login; + private SimpleDateFormat dateFormat; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.layout_reservation); + + TextView tv_title = (TextView) findViewById(R.id.tv_title); + tv_title.setText("教室预定"); + + final String roomId = getIntent().getStringExtra("roomId"); + final String roomName = getIntent().getStringExtra("roomName"); + + TextView tv_room = (TextView) findViewById(R.id.tv_room); + tv_room.setText("教室:" + roomName); + + btn_login = (Button) findViewById(R.id.btn_login); + + dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm"); + + // 查找Person表里面id为6b6c11c537的数据 + BmobQuery bmobQuery = new BmobQuery(); + bmobQuery.addWhereEqualTo("userId", User.userId); + bmobQuery.addWhereEqualTo("roomId", roomId); + bmobQuery.findObjects(ReservationActivity.this, new FindListener() { + + @Override + public void onSuccess(List newsList) { + // toast("查询商品成功, 共" + newsList.size()); + if (newsList.size() != 0) { + + String dateTime = newsList.get(0).getDateTime(); + + try { + if (dateFormat.parse(dateTime).before(new Date())) { + + Reservation gameScore = new Reservation(); + gameScore.setObjectId(newsList.get(0).getObjectId()); + gameScore.delete(ReservationActivity.this); + + } else { + btn_login.setEnabled(false); + btn_login.setText("已经预定" + (TextUtils.isEmpty(dateTime) ? "" : (" " + dateTime))); + } + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + } + + @Override + public void onError(int arg0, String arg1) { + toast("查询失败"); + } + }); + + btn_login.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + + DateTimePickDialogUtil dateTimePicKDialog = new DateTimePickDialogUtil(ReservationActivity.this, + dateFormat.format(new Date())); + dateTimePicKDialog.dateTimePicKDialog(new DateTimeListener() { + + @Override + public void onDateTimeChane(final String dateTime) { + // TODO Auto-generated method stub + + Reservation reservation = new Reservation(); + reservation.setRoomId(roomId); + reservation.setRoomName(roomName); + reservation.setUserId(User.userId); + reservation.setDateTime(dateTime); + + reservation.save(ReservationActivity.this, new SaveListener() { + + @Override + public void onSuccess() { + // TODO Auto-generated method stub + toast("预定成功"); + btn_login.setEnabled(false); + btn_login.setText("已经预定 " + dateTime); + + } + + @Override + public void onFailure(int arg0, String arg1) { + // TODO Auto-generated method stub + toast("预定失败"); + + } + }); + } + }); + + } + }); + + } + + private void toast(String toast) { + Toast.makeText(this, toast, Toast.LENGTH_SHORT).show(); + } +} diff --git a/代码/在这里1.0/src/com/stone/shop/view/SplashActivity.java b/代码/在这里1.0/src/com/stone/shop/view/SplashActivity.java new file mode 100644 index 0000000..7c44dbf --- /dev/null +++ b/代码/在这里1.0/src/com/stone/shop/view/SplashActivity.java @@ -0,0 +1,75 @@ +package com.stone.shop.view; + +import com.stone.shop.R; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.animation.AlphaAnimation; +import android.view.animation.Animation; +import android.view.animation.Animation.AnimationListener; +import android.view.animation.AnimationSet; +import android.view.animation.RotateAnimation; +import android.view.animation.ScaleAnimation; +import android.widget.RelativeLayout; + +public class SplashActivity extends Activity { + private RelativeLayout rlSplash; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + initView(); + initAnimation(); + } + + private void initView() { + setContentView(R.layout.activity_splash); + rlSplash = (RelativeLayout) findViewById(R.id.rl_splash); + } + + private void initAnimation() { + AnimationSet set = new AnimationSet(false); + RotateAnimation rtAnimation = new RotateAnimation(0, 360, + Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, + 0.5f); + rtAnimation.setDuration(2000); + rtAnimation.setFillAfter(true); + + ScaleAnimation scAnimation = new ScaleAnimation(0, 1, 0, 1, + Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, + 0.5f); + scAnimation.setDuration(2000); + scAnimation.setFillAfter(true); + + AlphaAnimation alAnimation = new AlphaAnimation(0, 1); + alAnimation.setDuration(2000); + alAnimation.setFillAfter(true); + + set.addAnimation(rtAnimation); + set.addAnimation(scAnimation); + set.addAnimation(alAnimation); + + set.setAnimationListener(new AnimationListener() { + + @Override + public void onAnimationStart(Animation arg0) { + + } + + @Override + public void onAnimationRepeat(Animation arg0) { + + } + + @Override + public void onAnimationEnd(Animation arg0) { + startActivity(new Intent(SplashActivity.this, + LoginActivity.class)); + finish(); + } + }); + + rlSplash.startAnimation(set); + } +} diff --git a/代码/在这里1.0/src/com/stone/slide/MyScrollLayout.java b/代码/在这里1.0/src/com/stone/slide/MyScrollLayout.java new file mode 100644 index 0000000..bfab194 --- /dev/null +++ b/代码/在这里1.0/src/com/stone/slide/MyScrollLayout.java @@ -0,0 +1,200 @@ +package com.stone.slide; + +import android.R.bool; +import android.content.Context; +import android.util.AttributeSet; +import android.util.Log; +import android.view.MotionEvent; +import android.view.VelocityTracker; +import android.view.View; +import android.view.ViewConfiguration; +import android.view.ViewGroup; +import android.view.View.MeasureSpec; +import android.widget.Scroller; + +public class MyScrollLayout extends ViewGroup { + + private static final String TAG = "ScrollLayout"; + private VelocityTracker mVelocityTracker; // 用于判断甩动手势 + private static final int SNAP_VELOCITY = 600; //X轴速度基值,大于该值时进行切换 + private Scroller mScroller; // 滑动控制�? + private int mCurScreen; //当前页面为第几屏 + private int mDefaultScreen = 0; + private float mLastMotionX; + + + private OnViewChangeListener mOnViewChangeListener; + + public MyScrollLayout(Context context) { + super(context); + // TODO Auto-generated constructor stub + init(context); + } + + public MyScrollLayout(Context context, AttributeSet attrs) { + super(context, attrs); + // TODO Auto-generated constructor stub + init(context); + } + + private void init(Context context) { + mCurScreen = mDefaultScreen; + mScroller = new Scroller(context); + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + // TODO Auto-generated method stub + + Log.e("a", "a"); + if (changed) { + int childLeft = 0; + final int childCount = getChildCount(); + Log.e("count", childCount+""); + for (int i = 0; i < childCount; i++) { + final View childView = getChildAt(i); + if (childView.getVisibility() != View.GONE) { + final int childWidth = childView.getMeasuredWidth(); + childView.layout(childLeft, 0, childLeft + childWidth, + childView.getMeasuredHeight()); + childLeft += childWidth; + } + } + } + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + // TODO Auto-generated method stub + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + Log.e("b", "b"); + final int width = MeasureSpec.getSize(widthMeasureSpec); + + final int count = getChildCount(); + for (int i = 0; i < count; i++) { + getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec); + } + + scrollTo(mCurScreen * width, 0); + + } + + public void snapToDestination() { + final int screenWidth = getWidth(); + + final int destScreen = (getScrollX() + screenWidth / 2) / screenWidth; + snapToScreen(destScreen); + } + + //使屏幕移动到第whichScreen+1屏 + public void snapToScreen(int whichScreen) { + + if (getScrollX() != (whichScreen * getWidth())) { + final int delta = whichScreen * getWidth() - getScrollX(); + mScroller.startScroll(getScrollX(), 0, delta, 0, + Math.abs(delta) * 2); + mCurScreen = whichScreen; + invalidate(); + + if (mOnViewChangeListener != null) { + mOnViewChangeListener.OnViewChange(mCurScreen); + } + } + } + + @Override + public void computeScroll() { + // TODO Auto-generated method stub + if (mScroller.computeScrollOffset()) { + scrollTo(mScroller.getCurrX(), mScroller.getCurrY()); + postInvalidate(); + } + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + // TODO Auto-generated method stub + + final int action = event.getAction(); + final float x = event.getX(); + final float y = event.getY(); + + switch (action) { + case MotionEvent.ACTION_DOWN: + + Log.i("", "onTouchEvent ACTION_DOWN"); + if (mVelocityTracker == null) { + mVelocityTracker = VelocityTracker.obtain(); + mVelocityTracker.addMovement(event); + } + if (!mScroller.isFinished()) { + mScroller.abortAnimation(); + } + mLastMotionX = x; + break; + + case MotionEvent.ACTION_MOVE: + + int deltaX = (int) (mLastMotionX - x); + if (IsCanMove(deltaX)) { + if (mVelocityTracker != null) { + mVelocityTracker.addMovement(event); + } + mLastMotionX = x; + //正向或者负向移动,屏幕跟随手指移动 + scrollBy(deltaX, 0); + } + break; + + case MotionEvent.ACTION_UP: + + int velocityX = 0; + if (mVelocityTracker != null) { + mVelocityTracker.addMovement(event); + mVelocityTracker.computeCurrentVelocity(1000); + //得到X轴方向手指移动速度 + velocityX = (int) mVelocityTracker.getXVelocity(); + } + //velocityX为正值说明手指向右滑动,为负值说明手指向左滑动 + if (velocityX > SNAP_VELOCITY && mCurScreen > 0) { + // Fling enough to move left + Log.e(TAG, "snap left"); + snapToScreen(mCurScreen - 1); + } else if (velocityX < -SNAP_VELOCITY + && mCurScreen < getChildCount() - 1) { + // Fling enough to move right + Log.e(TAG, "snap right"); + snapToScreen(mCurScreen + 1); + } else { + snapToDestination(); + } + + if (mVelocityTracker != null) { + mVelocityTracker.recycle(); + mVelocityTracker = null; + } + + break; + } + return true; + } + + + private boolean IsCanMove(int deltaX) { + //deltaX<0说明手指向右划 + if (getScrollX() <= 0 && deltaX < 0) { + return false; + } + //deltaX>0说明手指向左划 + if (getScrollX() >= (getChildCount() - 1) * getWidth() && deltaX > 0) { + return false; + } + return true; + } + + public void SetOnViewChangeListener(OnViewChangeListener listener) { + mOnViewChangeListener = listener; + } + +} diff --git a/代码/在这里1.0/src/com/stone/slide/OnViewChangeListener.java b/代码/在这里1.0/src/com/stone/slide/OnViewChangeListener.java new file mode 100644 index 0000000..32e77de --- /dev/null +++ b/代码/在这里1.0/src/com/stone/slide/OnViewChangeListener.java @@ -0,0 +1,5 @@ +package com.stone.slide; + +public interface OnViewChangeListener { + public void OnViewChange(int view); +} diff --git a/代码/在这里1.0/src/com/stone/slide/TestOpen.java b/代码/在这里1.0/src/com/stone/slide/TestOpen.java new file mode 100644 index 0000000..996e630 --- /dev/null +++ b/代码/在这里1.0/src/com/stone/slide/TestOpen.java @@ -0,0 +1,102 @@ +package com.stone.slide; + + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.view.animation.Animation; +import android.view.animation.Animation.AnimationListener; +import android.view.animation.AnimationUtils; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; + +public class TestOpen extends Activity implements OnViewChangeListener{ + + private MyScrollLayout mScrollLayout; + private ImageView[] imgs; + private int count; + private int currentItem; + private Button startBtn; + private RelativeLayout mainRLayout; + private LinearLayout pointLLayout; + private LinearLayout leftLayout; + private LinearLayout rightLayout; + private LinearLayout animLayout; + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + initView(); + } + + private void initView() { + mScrollLayout = (MyScrollLayout) findViewById(R.id.ScrollLayout); + pointLLayout = (LinearLayout) findViewById(R.id.llayout); + mainRLayout = (RelativeLayout) findViewById(R.id.mainRLayout); + startBtn = (Button) findViewById(R.id.startBtn); + startBtn.setOnClickListener(onClick); + animLayout = (LinearLayout) findViewById(R.id.animLayout); + leftLayout = (LinearLayout) findViewById(R.id.leftLayout); + rightLayout = (LinearLayout) findViewById(R.id.rightLayout); + count = mScrollLayout.getChildCount(); + imgs = new ImageView[count]; + for(int i = 0; i< count;i++) { + imgs[i] = (ImageView) pointLLayout.getChildAt(i); + imgs[i].setEnabled(true); + imgs[i].setTag(i); + } + currentItem = 0; + imgs[currentItem].setEnabled(false); + mScrollLayout.SetOnViewChangeListener(this); + } + + private View.OnClickListener onClick = new View.OnClickListener() { + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.startBtn: + mScrollLayout.setVisibility(View.GONE); + pointLLayout.setVisibility(View.GONE); + animLayout.setVisibility(View.VISIBLE); + mainRLayout.setBackgroundResource(R.drawable.whatsnew_bg); + Animation leftOutAnimation = AnimationUtils.loadAnimation(TestWeiXinOpen.this, R.anim.translate_left); + Animation rightOutAnimation = AnimationUtils.loadAnimation(TestWeiXinOpen.this, R.anim.translate_right); + leftLayout.startAnimation(leftOutAnimation); + rightLayout.startAnimation(rightOutAnimation); + leftOutAnimation.setAnimationListener(new AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + mainRLayout.setBackgroundColor(R.color.bgColor); + } + @Override + public void onAnimationRepeat(Animation animation) { + } + @Override + public void onAnimationEnd(Animation animation) { + leftLayout.setVisibility(View.GONE); + rightLayout.setVisibility(View.GONE); + } + }); + break; + } + } + }; + + + @Override + public void OnViewChange(int position) { + setcurrentPoint(position); + } + + private void setcurrentPoint(int position) { + if(position < 0 || position > count -1 || currentItem == position) { + return; + } + imgs[currentItem].setEnabled(true); + imgs[position].setEnabled(false); + currentItem = position; + } +} \ No newline at end of file diff --git a/代码/在这里1.0/src/com/stone/ui/DateTimePickDialogUtil.java b/代码/在这里1.0/src/com/stone/ui/DateTimePickDialogUtil.java new file mode 100644 index 0000000..6ba2bfe --- /dev/null +++ b/代码/在这里1.0/src/com/stone/ui/DateTimePickDialogUtil.java @@ -0,0 +1,188 @@ +package com.stone.ui; + +import java.text.SimpleDateFormat; +import java.util.Calendar; + +import com.stone.shop.R; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.widget.DatePicker; +import android.widget.DatePicker.OnDateChangedListener; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TimePicker; +import android.widget.TimePicker.OnTimeChangedListener; + +/** + * 日期时间选择控件 使用方法: private EditText inputDate;//需要设置的日期时间文本编辑框 private String + * initDateTime="2012年9月3日 14:44",//初始日期时间值 在点击事件中使用: + * inputDate.setOnClickListener(new OnClickListener() { + * + * @Override public void onClick(View v) { DateTimePickDialogUtil + * dateTimePicKDialog=new + * DateTimePickDialogUtil(SinvestigateActivity.this,initDateTime); + * dateTimePicKDialog.dateTimePicKDialog(inputDate); + * + * } }); + * + * @author + */ +public class DateTimePickDialogUtil implements OnDateChangedListener, OnTimeChangedListener { + private DatePicker datePicker; + private TimePicker timePicker; + private AlertDialog ad; + private String dateTime; + private String initDateTime; + private Activity activity; + private DateTimeListener dateTimeListener; + + /** + * 日期时间弹出选择框构造函数 + * + * @param activity + * :调用的父activity + * @param initDateTime + * 初始日期时间值,作为弹出窗口的标题和日期时间初始值 + */ + public DateTimePickDialogUtil(Activity activity, String initDateTime) { + this.activity = activity; + this.initDateTime = initDateTime; + + } + + public void init(DatePicker datePicker, TimePicker timePicker) { + Calendar calendar = Calendar.getInstance(); + if (!(null == initDateTime || "".equals(initDateTime))) { + calendar = this.getCalendarByInintData(initDateTime); + } else { + initDateTime = calendar.get(Calendar.YEAR) + "年" + calendar.get(Calendar.MONTH) + "月" + + calendar.get(Calendar.DAY_OF_MONTH) + "日 " + calendar.get(Calendar.HOUR_OF_DAY) + ":" + + calendar.get(Calendar.MINUTE); + } + + datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), + this); + timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY)); + timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE)); + } + + /** + * 弹出日期时间选择框方法 + * + * @param inputDate + * :为需要设置的日期时间文本编辑框 + * @return + */ + public AlertDialog dateTimePicKDialog(final DateTimeListener dateTimeListener) { + LinearLayout dateTimeLayout = (LinearLayout) activity.getLayoutInflater().inflate(R.layout.common_datetime, + null); + datePicker = (DatePicker) dateTimeLayout.findViewById(R.id.datepicker); + timePicker = (TimePicker) dateTimeLayout.findViewById(R.id.timepicker); + init(datePicker, timePicker); + timePicker.setIs24HourView(true); + timePicker.setOnTimeChangedListener(this); + + ad = new AlertDialog.Builder(activity).setTitle(initDateTime).setView(dateTimeLayout) + .setPositiveButton("设置", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + + if (dateTimeListener != null) { + dateTimeListener.onDateTimeChane(dateTime); + } + } + }).setNegativeButton("取消", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + + } + }).show(); + + onDateChanged(null, 0, 0, 0); + return ad; + } + + public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { + onDateChanged(null, 0, 0, 0); + } + + public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { + // 获得日历实例 + Calendar calendar = Calendar.getInstance(); + + calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth(), + timePicker.getCurrentHour(), timePicker.getCurrentMinute()); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm"); + + dateTime = sdf.format(calendar.getTime()); + ad.setTitle(dateTime); + } + + /** + * 实现将初始日期时间2012年07月02日 16:45 拆分成年 月 日 时 分 秒,并赋值给calendar + * + * @param initDateTime + * 初始日期时间值 字符串型 + * @return Calendar + */ + private Calendar getCalendarByInintData(String initDateTime) { + Calendar calendar = Calendar.getInstance(); + + // 将初始日期时间2012年07月02日 16:45 拆分成年 月 日 时 分 秒 + String date = spliteString(initDateTime, "日", "index", "front"); // 日期 + String time = spliteString(initDateTime, "日", "index", "back"); // 时间 + + String yearStr = spliteString(date, "年", "index", "front"); // 年份 + String monthAndDay = spliteString(date, "年", "index", "back"); // 月日 + + String monthStr = spliteString(monthAndDay, "月", "index", "front"); // 月 + String dayStr = spliteString(monthAndDay, "月", "index", "back"); // 日 + + String hourStr = spliteString(time, ":", "index", "front"); // 时 + String minuteStr = spliteString(time, ":", "index", "back"); // 分 + + int currentYear = Integer.valueOf(yearStr.trim()).intValue(); + int currentMonth = Integer.valueOf(monthStr.trim()).intValue() - 1; + int currentDay = Integer.valueOf(dayStr.trim()).intValue(); + int currentHour = Integer.valueOf(hourStr.trim()).intValue(); + int currentMinute = Integer.valueOf(minuteStr.trim()).intValue(); + + calendar.set(currentYear, currentMonth, currentDay, currentHour, currentMinute); + return calendar; + } + + /** + * 截取子串 + * + * @param srcStr + * 源串 + * @param pattern + * 匹配模式 + * @param indexOrLast + * @param frontOrBack + * @return + */ + public static String spliteString(String srcStr, String pattern, String indexOrLast, String frontOrBack) { + String result = ""; + int loc = -1; + if (indexOrLast.equalsIgnoreCase("index")) { + loc = srcStr.indexOf(pattern); // 取得字符串第一次出现的位置 + } else { + loc = srcStr.lastIndexOf(pattern); // 最后一个匹配串的位置 + } + if (frontOrBack.equalsIgnoreCase("front")) { + if (loc != -1) + result = srcStr.substring(0, loc); // 截取子串 + } else { + if (loc != -1) + result = srcStr.substring(loc + 1, srcStr.length()); // 截取子串 + } + return result; + } + + public interface DateTimeListener { + + void onDateTimeChane(String dateTime); + + } +}