package com.lvtaozi.ui;
import java.util.Timer;
import java.util.TimerTask;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import com.lvtaozi.activity.R;
import com.lvtaozi.cellview.ShouYePMzhanshituCellView;
import com.lvtaozi.cellviewmodel.ShouYePMzhanshituCellViewVM;
public class ShouYeUI extends FrameLayout {
private TitlebarUI shouyeTitlebarUI;
private ShouYePMzhanshituCellView shouYePMzhanshituCellView;
private ShouYePMzhanshituCellViewVM shouYePMzhanshituCellViewVM = new ShouYePMzhanshituCellViewVM();
private float mPosX;
private float mPosY;
private float mCurrentPosX;
private float mCurrentPosY;
private int zhanshidibutuxiabuzhi = 0;
public ShouYeUI(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public void init() {
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.ui_shouye, this);
shouyeTitlebarUI = (TitlebarUI) findViewById(R.id.shouyetitlebar);
shouyeTitlebarUI.setLeftButtonImage(R.drawable.ic_launcher);
shouyeTitlebarUI.setLeftButtonText("");
shouyeTitlebarUI.setMidButtonText("锦融物业");
shouyeTitlebarUI.setMidButtonTextSize(20);
shouyeTitlebarUI.setRightTextViewImage(R.drawable.ic_launcher);
shouyeTitlebarUI.setRightTextViewText("");
shouYePMzhanshituCellView = (ShouYePMzhanshituCellView) findViewById(R.id.shouyepmzhanshitu);
final Handler myHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
if (zhanshidibutuxiabuzhi == 2) {
zhanshidibutuxiabuzhi = -1;
}
zhanshidibutuxiabuzhi = zhanshidibutuxiabuzhi + 1;
initpmzhanshi(zhanshidibutuxiabuzhi);
Log.d("Mytest", "timmer is running "+zhanshidibutuxiabuzhi);
super.handleMessage(msg);
}
};
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
Message message = new Message();
message.what = 2;
myHandler.sendMessage(message);
}
}, 0, 5000);
shouYePMzhanshituCellView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mPosX = event.getX();
mPosY = event.getY();
return true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
mCurrentPosX = event.getX();
mCurrentPosY = event.getY();
//横向拖动大于50出发该事件
if (mCurrentPosX - mPosX > 0
&& Math.abs(mCurrentPosX - mPosX) > 50) {
Log.d("Mytest", "向右" + mCurrentPosX + " " + mPosX
+ " " + zhanshidibutuxiabuzhi);
if (zhanshidibutuxiabuzhi == 0) {
zhanshidibutuxiabuzhi = 3;
}
zhanshidibutuxiabuzhi = zhanshidibutuxiabuzhi - 1;
initpmzhanshi(zhanshidibutuxiabuzhi);
} else if (mCurrentPosX - mPosX < 0
&& Math.abs(mCurrentPosX - mPosX) > 50) {
Log.d("Mytest", "向左" + mCurrentPosX + " " + mPosX
+ " " + zhanshidibutuxiabuzhi);
if (zhanshidibutuxiabuzhi == 2) {
zhanshidibutuxiabuzhi = -1;
}
zhanshidibutuxiabuzhi = zhanshidibutuxiabuzhi + 1;
initpmzhanshi(zhanshidibutuxiabuzhi);
}
return true;
}
return false;
}
});
}
private void initpmzhanshi(int index) {
if (index == 0) {
Log.d("Mytest", "this is index " + index);
shouYePMzhanshituCellViewVM.shiwaipmzhi = "左888";
shouYePMzhanshituCellViewVM.shinei1pmzhi = "左44";
shouYePMzhanshituCellViewVM.shinei2pmzhi = "左33";
shouYePMzhanshituCellViewVM.xiabiaotu = String
.valueOf(zhanshidibutuxiabuzhi);
}
if (index == 1) {
Log.d("Mytest", "this is index " + index);
shouYePMzhanshituCellViewVM.shiwaipmzhi = "中间888";
shouYePMzhanshituCellViewVM.shinei1pmzhi = "中间44";
shouYePMzhanshituCellViewVM.shinei2pmzhi = "中间33";
shouYePMzhanshituCellViewVM.xiabiaotu = String
.valueOf(zhanshidibutuxiabuzhi);
}
if (index == 2) {
Log.d("Mytest", "this is index " + index);
shouYePMzhanshituCellViewVM.shiwaipmzhi = "右888";
shouYePMzhanshituCellViewVM.shinei1pmzhi = "右44";
shouYePMzhanshituCellViewVM.shinei2pmzhi = "右33";
shouYePMzhanshituCellViewVM.xiabiaotu = String
.valueOf(zhanshidibutuxiabuzhi);
}
shouYePMzhanshituCellView.bind(shouYePMzhanshituCellViewVM);
}
}