航班機票座位選擇-android
定義列舉把座位分為已選,要選,未選。
座位分左中右
艙位分頭等,二等,經濟,末尾。
enum SeatState {
Normal, Selected, Selecting
}
enum SeatType {
Left, Middle, Right
}
enum CabinType {
Frist, Second, Tourist, Last
}
定義HashMap來存放位置資訊
HashMap<String, RectF> mSeats= new HashMap<>();
HashMap的key是位置的序號,比如4排5坐 「4#5」未做唯一標識。
value的型別是RectF來判斷點是否在改區域中,來控制選中和未選中的區分。
RectF.contains(x, y)
利用Matrix對機艙和機翼放縮和平移
機艙和機翼都是利用貝賽爾曲線畫的,這個就不具體貼程式碼了
matrix.postScale(sx,sy);
matrix.postTranslate(dx,dy);
canvas.drawBitmap(getBitmapFuselage(rectFCabinWidth), matrix, mPaint);
public Bitmap getBitmapFuselage(float rectFCabinWidth) {
Canvas canvas = null;
int w = getMeasuredWidth();
int h = getMeasuredHeight();
if (mBitmapFuselage == null) {
mBitmapFuselage = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
canvas = new Canvas(mBitmapFuselage);
pathFuselage.moveTo(w / 2f - rectFCabinWidth / 2f - dip2px(2),
rectFCabin.top + rectFCabinWidth / 2f);
pathFuselage.cubicTo(
w / 2f - rectFCabinWidth / 4f,
rectFCabin.top - rectFCabinWidth * 1.2f,
w / 2f + rectFCabinWidth / 4f,
rectFCabin.top - rectFCabinWidth * 1.2f,
w / 2f + rectFCabinWidth / 2f + dip2px(2),
rectFCabin.top + rectFCabinWidth / 2f
);
rectFCabin.top = rectFCabin.top + dip2px(10);//機翼向下平移距離
pathFuselage.lineTo(w / 2f + rectFCabinWidth / 2f + dip2px(2)
, rectFCabin.top + rectFCabin.height() / 3f);
pathFuselage.lineTo(w
, rectFCabin.top + rectFCabin.height() * 0.55f);
pathFuselage.lineTo(w
, rectFCabin.top + rectFCabin.height() * 0.55f + rectFCabin.width() * 0.8f);
pathFuselage.lineTo(rectFCabin.right + rectFCabin.width() / 2 * 1.5f
, rectFCabin.top + rectFCabin.height() / 2f + rectFCabin.height() / 6f / 2f);
pathFuselage.lineTo(w / 2f + rectFCabinWidth / 2f + dip2px(2)
, rectFCabin.top + rectFCabin.height() / 2f + rectFCabin.height() / 6f / 2f);
//
pathFuselage.lineTo(w / 2f + rectFCabinWidth / 2f + dip2px(2)
, rectFCabin.bottom - rectFCabinWidth / 2f);
pathFuselage.cubicTo(
w / 2f + rectFCabinWidth / 4f,
rectFCabin.bottom + rectFCabinWidth * 2.5f,
w / 2f - rectFCabinWidth / 4f,
rectFCabin.bottom + rectFCabinWidth * 2.5f,
w / 2f - rectFCabinWidth / 2f - dip2px(2)
, rectFCabin.bottom - rectFCabinWidth / 2f
);
pathFuselage.lineTo(w / 2f - rectFCabinWidth / 2f - dip2px(2)
, rectFCabin.top + rectFCabin.height() / 2f + rectFCabin.height() / 6f / 2f);
pathFuselage.lineTo(rectFCabin.left - rectFCabin.width() / 2 * 1.5f
, rectFCabin.top + rectFCabin.height() / 2f + rectFCabin.height() / 6f / 2f);
pathFuselage.lineTo(0
, rectFCabin.top + rectFCabin.height() * 0.55f + rectFCabin.width() * 0.8f);
pathFuselage.lineTo(0
, rectFCabin.top + rectFCabin.height() * 0.55f);
pathFuselage.lineTo(w / 2f - rectFCabinWidth / 2f - dip2px(2)
, rectFCabin.top + rectFCabin.height() / 3f);
pathFuselage.close();
mPaint.setColor(Color.WHITE);
mPaint.setAlpha(150);
canvas.drawPath(pathFuselage, mPaint);
}
return mBitmapFuselage;
}
自定義手勢滑動監聽
public abstract class MoveListerner implements OnTouchListener,
OnGestureListener {
public static final int MOVE_TO_LEFT = 0;
public static final int MOVE_TO_RIGHT = MOVE_TO_LEFT + 1;
public static final int MOVE_TO_UP = MOVE_TO_RIGHT + 1;
public static final int MOVE_TO_DOWN = MOVE_TO_UP + 1;
private static final int FLING_MIN_DISTANCE = 150;
private static final int FLING_MIN_VELOCITY = 50;
private boolean isScorllStart = false;
private boolean isUpAndDown = false;
GestureDetector mGestureDetector;
float x1 = 0;
float x2 = 0;
float y1 = 0;
float y2 = 0;
public MoveListerner(Activity context) {
super();
mGestureDetector = new GestureDetector(context, this);
}
float startX = 0;
float startY = 0;
@Override
public boolean onTouch(View v, MotionEvent event) {
if (mGestureDetector.onTouchEvent(event)) {
if (MotionEvent.ACTION_DOWN == event.getAction()) {
// Touch(event.getX(), event.getY());
startX = event.getX();
startY = event.getY();
return true;
} else if (MotionEvent.ACTION_UP == event.getAction()) {
if (Math.abs(event.getX() - startX) < 5 &&
Math.abs(event.getY() - startY) < 5) {
Touch(event.getX(), event.getY());
return true;
}
}
}
// 處理手勢結束
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
endGesture();
break;
}
return false;
}
private void endGesture() {
isScorllStart = false;
isUpAndDown = false;
// Log.e("a", "AA:over");
moveOver();
}
public abstract void moveDirection(View v, int direction, float distanceX, float distanceY);
public abstract void moveUpAndDownDistance(MotionEvent event, int distance, int distanceY);
public abstract void moveOver();
public abstract void Touch(float x, float y);
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return true;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return true;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
float mOldY = e1.getY();
int y = (int) e2.getRawY();
if (!isScorllStart) {
if (Math.abs(distanceX) / Math.abs(distanceY) > 2) {
// 左右滑動
isUpAndDown = false;
isScorllStart = true;
} else if (Math.abs(distanceY) / Math.abs(distanceX) > 3) {
// 上下滑動
isUpAndDown = true;
isScorllStart = true;
} else {
isScorllStart = false;
}
} else {
// 算滑動速度的問題了
if (isUpAndDown) {
// 是上下滑動,關閉左右檢測
if (mOldY + 5 < y) {
moveUpAndDownDistance(e2, -3, (int) distanceY);
} else if (mOldY + 5 > y) {
moveUpAndDownDistance(e2, 3, (int) distanceY);
}
}
}
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// Log.e("a", "AA:A" + velocityX + ":" + velocityY);
if (isUpAndDown)
return false;
if (e1.getX() - e2.getX() > FLING_MIN_DISTANCE
&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {
// Fling left
moveDirection(null, MOVE_TO_LEFT, e1.getX() - e2.getX(), e1.getY() - e2.getY());
} else if (e2.getX() - e1.getX() > FLING_MIN_DISTANCE
&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {
// Fling right
moveDirection(null, MOVE_TO_RIGHT, e2.getX() - e1.getX(), e2.getY() - e1.getY());
} else if (e1.getY() - e2.getY() > FLING_MIN_DISTANCE
&& Math.abs(velocityY) > FLING_MIN_VELOCITY) {
// Fling up
moveDirection(null, MOVE_TO_UP, 0, e1.getY() - e2.getY());
} else {
// Fling down
moveDirection(null, MOVE_TO_DOWN, 0, e2.getY() - e1.getY());
}
return false;
}
}
Usage
mFlightSeatView.startAnim(true);// false zoom in,true zoom out
mFlightSeatView.setEmptySelecting();//clear
mFlightSeatView.setSeatSelected(row, column);
如果覺得還不錯,就給我打賞顆星星吧^^
程式碼下載
相關文章
- jsp+servlet+mysql實現機票預訂航班系統(含原始碼、MySQL、包執行)JSServletMySql原始碼
- Android為什麼選擇binderAndroid
- Daguerre Android 影像視訊選擇器Android
- Android 頭像選擇功能實戰Android
- Daguerre Android 影象視訊選擇器Android
- Android 拍照、選擇圖片並裁剪Android
- android自定義佈局——城市選擇介面Android
- 002---選擇器(標籤選擇器、類選擇器、id選擇器、偽類選擇器、萬用字元選擇器)字元
- jQuery選擇器介紹:基本選擇器、層次選擇器、過濾選擇器、表單選擇器jQuery
- Nielsen:2011年3月31%表示將選擇Android 30%將選擇iOSAndroidiOS
- Android圖片(視訊)選擇器:android-media-pickerAndroid
- jQuery選擇器——基本選擇器jQuery
- Android自定義View之區塊選擇器AndroidView
- [譯] Android 如何實現氣泡選擇動畫Android動畫
- Android View 自定義 RangeSeekBar 範圍選擇器AndroidView
- 選擇iOS還是Android?這很重要嗎?iOSAndroid
- Android Compose 使用 照片選擇器 Photo PickerAndroid
- 基本CSS選擇器,複合選擇器,後代選擇器CSS
- JQuery選擇器——可見性篩選選擇器和屬性篩選選擇器jQuery
- jQuery選擇器——層次選擇器jQuery
- Kotlin對決Java:Android開發的選擇?KotlinJavaAndroid
- Xamarin.Android編譯CPU型別選擇方式Android編譯型別
- Android 自定義 View 實戰之角度選擇器AndroidView
- Android 中如何選擇 compileSdkVersion, minSdkVersion 和 targetSdkVersionAndroidCompile
- PlayJam: 60%開發商將選擇Android平臺Android
- Android UI 設計(12):ListView 練習(製作水果選擇選單)AndroidUIView
- CSS3新增選擇器(屬性選擇器、結構偽類選擇器、偽元素選擇器)CSSS3
- jQuery選擇器之層次選擇器jQuery
- 怎樣選擇TCP還是選擇UDPTCPUDP
- CSS選擇器(5)——屬性選擇器CSS
- jQuery選擇器——基本過濾選擇器jQuery
- CSS ID選擇器與CLASS選擇器CSS
- SQL 選擇SQL
- 模型選擇模型
- 選擇排序排序
- 快速選擇
- CSS-選擇器6-兄弟選擇器CSS
- jQuery選擇器——內容過濾選擇器jQuery