按钮状态保存

zhenghaoyuan_branch
zhenghaoyuan20 2 years ago
parent 7bff3f6be8
commit 9b17695cb4

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\郑皓原\.android\avd\Pixel_2_XL_API_22_2.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-06-22T00:46:45.782451800Z" />
</component>
</project>

@ -3,10 +3,15 @@
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/drawable/txt_radiuborder.xml" value="0.2505" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout-v26/activity_setting.xml" value="0.264" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/activity_control.xml" value="0.25364583333333335" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/activity_main.xml" value="0.25364583333333335" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/activity_setting.xml" value="0.264" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/activity_setting.xml" value="0.1" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/activity_video.xml" value="0.25364583333333335" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/custom_info_contents.xml" value="0.1125" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/custom_info_window.xml" value="0.1125" />
<entry key="..\:/AndroidTool/AndriodProject/Shaobing/src/sixaunyi/app/src/main/res/layout/fragment_second.xml" value="0.1125" />
<entry key="..\:/MiNote_maintain/new_MiCode/src/sixaunyi/app/src/main/res/drawable/icon_favorite_red.xml" value="0.12" />
<entry key="..\:/MiNote_maintain/new_MiCode/src/sixaunyi/app/src/main/res/layout/activity_detect.xml" value="0.1" />
<entry key="..\:/MiNote_maintain/new_MiCode/src/sixaunyi/app/src/main/res/layout/activity_main.xml" value="0.1" />

@ -31,7 +31,6 @@ android {
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

@ -38,11 +38,6 @@
android:name="com.amap.api.v2.apikey"
android:value="530a964ff05e45d9efb905abc9480690" />
<activity
android:name=".VideoActivity"
android:exported="false"
android:screenOrientation="landscape"
/>
<activity
android:name=".DetectActivity"
android:exported="false"
@ -54,6 +49,11 @@
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat">
</activity>
<activity
android:name=".VideoActivity"
android:exported="false"
android:screenOrientation="landscape"
/>
<activity
android:name=".LoginActivity"
android:exported="true"

@ -4,14 +4,25 @@ import static androidx.constraintlayout.motion.utils.Oscillator.TAG;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -19,66 +30,132 @@ import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class SettingActivity extends AppCompatActivity {
private final static String SEND_to_IP = "192.168.39.47";
private SeekBar Speed_btn;
private Button Battery_btn;
private ImageButton return_btn;
private final static int SEND_PORT = 8888;
private ExecutorService mThreadPool = Executors.newCachedThreadPool();
private Switch photo_btn;
private Context context;
private SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
Speed_btn= findViewById(R.id.speed);
return_btn=findViewById(R.id.returns);
photo_btn = findViewById(R.id.photo);
TextView tvProgress = (TextView) findViewById(R.id.tvProgress);
sharedPreferences = getSharedPreferences("control_state", MODE_PRIVATE);
boolean photo_btn_state= sharedPreferences.getBoolean("photo_btn_state", false);
photo_btn.setChecked(photo_btn_state);
// 恢复SeekBar状态
int speedProgress = sharedPreferences.getInt("speed_progress", 0);
Speed_btn.setProgress(speedProgress);
tvProgress.setText(String.valueOf(speedProgress+10));
photo_btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// 保存Switch状态
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("photo_btn_state", isChecked);
editor.apply();
}
});
Speed_btn.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
tvProgress.setText(String.valueOf(progress+10));
int speed=progress+10;
String s = "SPEED " + Integer.toString(speed);
try {
InitUdpSend(s);
sendCommand(s);
} catch (UnknownHostException e) {
e.printStackTrace();
}
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt("speed_progress", progress);
editor.apply();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});
return_btn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent intent = new Intent(SettingActivity.this, VideoActivity.class);
// 启动目标 Activity
startActivity(intent);
}
});
photo_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (photo_btn.isChecked()) {
try {
sendCommand("photo_high");
} catch (UnknownHostException e) {
e.printStackTrace();
}
}else
{
try {
sendCommand("photo_low");
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
});
}
/*
* UDP线
* */
public static class UdpSendThread extends Thread {
private InetAddress sendToIP; // 目标 IP 地址
private int sendPort; // 目标端口号
private byte[] sendData; // 要发送的数据
public UdpSendThread(InetAddress sendToIP, int sendPort, byte[] sendData) {
this.sendToIP = sendToIP;
this.sendPort = sendPort;
this.sendData = sendData;
class SendRunnable implements Runnable {
byte[] mData;
InetAddress mAddress;
int mPort;
public SendRunnable(byte[] data, InetAddress address, int port) {
mData = data;
mAddress = address;
mPort = port;
}
@Override
public void run() {
try {
DatagramSocket sendSocket = new DatagramSocket(); // 创建一个新的 DatagramSocket 对象
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, sendToIP, sendPort); // 将要发送的数据打包成一个 DatagramPacket 对象
sendSocket.send(sendPacket); // 发送 DatagramPacket
sendSocket.close(); // 发送完毕后关闭 DatagramSocket
} catch (Exception e) {
// 创建发送数据报文
DatagramPacket packet = new DatagramPacket(mData, mData.length, mAddress, mPort);
// 创建 DatagramSocket 对象并发送数据报文
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
// 关闭 DatagramSocket 对象
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void InitUdpSend(String Sendstr) throws UnknownHostException {
InetAddress sendIP = InetAddress.getByName(SEND_to_IP); // 目标 IP 地址
int sendPort = 8888; // 目标端口号
byte[] sendData = Sendstr.getBytes(); // 要发送的数据
VideoActivity.UdpSendThread sendThread = new VideoActivity.UdpSendThread(sendIP, sendPort, sendData); // 创建新的线程对象
sendThread.start(); // 启动线程发送数据
/*封装函数*/
private void sendCommand(String str) throws UnknownHostException {
byte[] sendData = str.getBytes();
InetAddress address = InetAddress.getByName(SEND_to_IP);
SendRunnable sendRunnable1 = new SendRunnable(sendData, address, SEND_PORT);
mThreadPool.execute(sendRunnable1);
}
}

@ -1,497 +0,0 @@
package com.example.sixaunyi;
import static androidx.constraintlayout.motion.utils.Oscillator.TAG;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.*;
import android.os.Bundle;
public class VideoActivity extends AppCompatActivity {
private final static String SEND_to_IP = "192.168.39.47"; //填写接收方IP
private final static String Recieve_IP = "192.168.39.47";//填服务器IP与send_to_IP为同一个
private final static int SEND_PORT = 8888; //发送端口号
private final static int RECEIVE_PORT = 9999; //接收端口号
private static boolean listenStatus = true; //接收线程的循环标识
private byte[] buf;
static Bitmap bp;
private DatagramSocket reveSocket;
private DatagramSocket sendSocket;
private static InetAddress serverAddr;
private SendHandler sendHandler = new SendHandler();
private ReceiveHandler receiveHandler = new ReceiveHandler();
private Button Trans_to_Detect;
private ImageView imgShow;
private Button btn;
private ImageButton Forward_btn;
private ImageButton Back_btn;
private ImageButton Left_btn;
private ImageButton Right_btn;
private ImageButton Down_btn;
private ImageButton Up_btn;
private ImageButton TurnLeft_btn;
private ImageButton TurnRight_btn;
private ImageButton Setting_btn;
private ImageButton TakeOff_btn;
private Button Landing_btn;
private String angle;
private float distance;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_control);
imgShow = findViewById(R.id.imageView);
Forward_btn = findViewById(R.id.forward_button);
Back_btn = findViewById(R.id.backward_button);
Left_btn = findViewById(R.id.left_button);
Right_btn = findViewById(R.id.right_button);
Down_btn = findViewById(R.id.down_button);
Up_btn = findViewById(R.id.up_button);
TurnLeft_btn = findViewById(R.id.rotate_left_button);
TurnRight_btn = findViewById(R.id.rotate_right_button);
TakeOff_btn = findViewById(R.id.takeoff_button);
TakeOff_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new UdpReceiveThread().start();
Log.i(TAG, "onClick: BBBBBBBBackward");
}
});
Setting_btn = findViewById(R.id.setting_button);
Button_Init();
Intent i = getIntent();
distance = i.getFloatExtra("Distance",0);
angle = i.getStringExtra("Angle");
}
private void Button_Init(){
Forward_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
InitUdpSend("FORWARD");
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
Log.i(TAG, "onClick: FFFFFFFForward");
}
});
Back_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
InitUdpSend("BACKWORD");
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
Log.i(TAG, "onClick: BBBBBBBBackward");
}
});
Left_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
InitUdpSend("LEFT");
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
Log.i(TAG, "onClick: LLLLLLLLLLLLeft");
}
});
Right_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
InitUdpSend("RIGHT");
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
Log.i(TAG, "onClick: RRRRRRRRRRight");
}
});
Down_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
InitUdpSend("DOWN");
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
Log.i(TAG, "onClick: DDDDDDDDDown");
}
});
Up_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
InitUdpSend("UP");
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
Log.i(TAG, "onClick: UUUUUUUUUUUUUUp");
}
});
TurnLeft_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
InitUdpSend("TURN_LEFT");
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
Log.i(TAG, "onClick: TTTTTTTTTurnLLLLLLLLLLeft");
}
});
TurnRight_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
InitUdpSend("TURN_RIGHT");
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
Log.i(TAG, "onClick: TTTTTTTTTTTTurnRRRRRRRRRRight");
}
});
Setting_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(VideoActivity.this, SettingActivity.class);
startActivity(intent);
}
});
}
class ReceiveHandler extends Handler{
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
imgShow.setImageBitmap(bp);
}
}
class SendHandler extends Handler {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
}
}
/*
* UDP线
* */
public class UdpReceiveThread extends Thread
{
@Override
public void run()
{
try
{
reveSocket = new DatagramSocket(RECEIVE_PORT);
serverAddr = InetAddress.getByName(Recieve_IP);
//ByteArrayOutputStream out = new ByteArrayOutputStream();
while(listenStatus)
{
byte[] inBuf= new byte[1024*1024];
DatagramPacket inPacket=new DatagramPacket(inBuf,inBuf.length);
//out.write(inPacket.getData());
reveSocket.receive(inPacket);
if(!inPacket.getAddress().equals(serverAddr)){
throw new IOException("未知名的报文");
}
ByteArrayInputStream in = new ByteArrayInputStream(inPacket.getData());
receiveHandler.sendEmptyMessage(1);
bp = BitmapFactory.decodeStream(in);
}
} catch (Exception e)
{
e.printStackTrace();
}finally {
// reveSocket.close();
}
}
}
/*
* UDP线
* */
public static class UdpSendThread extends Thread {
private InetAddress sendToIP; // 目标 IP 地址
private int sendPort; // 目标端口号
private byte[] sendData; // 要发送的数据
public UdpSendThread(InetAddress sendToIP, int sendPort, byte[] sendData) {
this.sendToIP = sendToIP;
this.sendPort = sendPort;
this.sendData = sendData;
}
@Override
public void run() {
try {
DatagramSocket sendSocket = new DatagramSocket(); // 创建一个新的 DatagramSocket 对象
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, sendToIP, sendPort); // 将要发送的数据打包成一个 DatagramPacket 对象
sendSocket.send(sendPacket); // 发送 DatagramPacket
sendSocket.close(); // 发送完毕后关闭 DatagramSocket
} catch (Exception e) {
e.printStackTrace();
}
}
}
//初始化UDP发送线程
private static void InitUdpSend(String Sendstr) throws UnknownHostException {
InetAddress sendIP = InetAddress.getByName(SEND_to_IP); // 目标 IP 地址
int sendPort = 8888; // 目标端口号
byte[] sendData = Sendstr.getBytes(); // 要发送的数据
UdpSendThread sendThread = new UdpSendThread(sendIP, sendPort, sendData); // 创建新的线程对象
sendThread.start(); // 启动线程发送数据
}
//设置按钮
// public void showDialog(View view) {
// Dialog dialog = new Dialog(VideoActivity.this);
// dialog.setContentView(R.layout.dialog_takeoff);
//
// SlideUnlockView slideUnlockView = (SlideUnlockView) dialog.findViewById(R.id.slide_unlock_view);
// slideUnlockView.setOnUnlockListener(new SlideUnlockView.OnUnlockListener() {
// @Override
// public void onUnlock() {
// // 在用户滑动解锁后执行操作
//// try {
//// InitUdpSend("TAKEOFF"+"___"+angle+"___"+String.valueOf(distance));
//// } catch (UnknownHostException e) {
//// throw new RuntimeException(e);
//// }
// UdpReceiveThread udpReceiveThread = new UdpReceiveThread();
// udpReceiveThread.start();
//
// Log.i(TAG, "onClick: 2222222222222222222222222");
//
// }
// });
// dialog.show();
// }
//////////////////////////////滑动开关//////////////////////////////
public static class SlideUnlockView extends View{
private final int BG_COLOR = Color.parseColor("#2D2E32"); // 背景颜色
private static final int GUIDE_TEXT_COLOR = Color.WHITE; // 引导文本颜色
private static final int GUIDE_TEXT_SIZE = 100; // 引导文本大小
private static final int INDICATOR_COLOR = Color.WHITE; // 指示器颜色
private static final int INDICATOR_RADIUS = 40; // 指示器半径
private static final int INDICATOR_GAP = 300; // 指示器间距
private static final int ARROW_COLOR = Color.WHITE; // 箭头颜色
private static final int ARROW_SIZE = 20; // 箭头大小
private static final int STATE_LOCKED = 0; // 锁屏状态
private static final int STATE_DRAGGING = 1; // 拖动状态
private static final int STATE_UNLOCKED = 2; // 解锁状态
private Paint mPaint;
private Path mPath;
private int mViewWidth;
private int mViewHeight;
private int mIndicatorCount;
private int mCurrentIndex;
private float mLastX;
private boolean mIsUnlocked;
private int mState;
private OnUnlockListener mOnUnlockListener;
public abstract static class OnUnlockListener {
public class SimpleOnUnlockListener extends OnUnlockListener {
@Override
public void onUnlock() {
// 默认空实现
}
}
public abstract void onUnlock();
}
public void setOnUnlockListener(OnUnlockListener listener) {
this.mOnUnlockListener = listener;
}
public SlideUnlockView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
mPaint = new Paint();
mPaint.setAntiAlias(true); // 抗锯齿
mPaint.setStyle(Paint.Style.FILL);
mPath = new Path();
mIsUnlocked = false;
mState = STATE_LOCKED;
// 指示器个数为 3
mIndicatorCount = 3;
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mViewWidth = w;
mViewHeight = h;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
switch (mState) {
case STATE_LOCKED:
drawGuideText(canvas);
drawIndicatorCircles(canvas);
break;
case STATE_DRAGGING:
drawUnlockPath(canvas);
drawUnlockArrow(canvas);
break;
case STATE_UNLOCKED:
if (mOnUnlockListener != null) {
mOnUnlockListener.onUnlock();
}
break;
}
}
private void drawGuideText(Canvas canvas) {
mPaint.setColor(BG_COLOR);
canvas.drawRect(0, 0, mViewWidth, mViewHeight, mPaint);
mPaint.setColor(GUIDE_TEXT_COLOR);
mPaint.setTextSize(GUIDE_TEXT_SIZE);
String guideText = "即将起飞";
float textWidth = mPaint.measureText(guideText);
float textX = mViewWidth / 2 - textWidth / 2;
float textY = mViewHeight * 2 / 3;
canvas.drawText(guideText, textX, textY, mPaint);
}
private void drawIndicatorCircles(Canvas canvas) {
mPaint.setColor(INDICATOR_COLOR);
float cy = mViewHeight / 2;
float startX = mViewWidth / 2 - INDICATOR_GAP * (mIndicatorCount - 1) / 2;
float radius = INDICATOR_RADIUS;
Path path = new Path();
for (int i = 0; i < mIndicatorCount; i++) {
float cx = startX + INDICATOR_GAP * i;
path.addCircle(cx, cy, radius, Path.Direction.CCW);
}
canvas.drawPath(path, mPaint);
}
private void drawUnlockPath(Canvas canvas) {
mPaint.setColor(INDICATOR_COLOR);
float cy = mViewHeight / 2;
float startX = mViewWidth / 2 - INDICATOR_GAP * (mIndicatorCount - 1) / 2;
float currentX = Math.max(Math.min(mLastX, mViewWidth - INDICATOR_RADIUS), startX + INDICATOR_GAP * mCurrentIndex);
Path path = new Path();
path.moveTo(startX + INDICATOR_RADIUS, cy);
path.lineTo(currentX - INDICATOR_RADIUS, cy);
path.arcTo(new RectF(currentX - INDICATOR_RADIUS, cy - INDICATOR_RADIUS,
currentX + INDICATOR_RADIUS, cy + INDICATOR_RADIUS), -90, 180);
path.lineTo(startX + INDICATOR_GAP * (mIndicatorCount - 1), cy);
canvas.drawPath(path, mPaint);
}
private void drawUnlockArrow(Canvas canvas) {
mPaint.setColor(ARROW_COLOR);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
Path arrowPath = new Path();
float x = Math.max(Math.min(mLastX, mViewWidth - INDICATOR_RADIUS - ARROW_SIZE), mViewWidth / 2 + INDICATOR_GAP * (mCurrentIndex - 1));
float y = mViewHeight / 2;
arrowPath.moveTo(x - ARROW_SIZE, y - ARROW_SIZE);
arrowPath.lineTo(x, y);
arrowPath.lineTo(x - ARROW_SIZE, y + ARROW_SIZE);
canvas.drawPath(arrowPath, mPaint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (mState == STATE_LOCKED) {
mState = STATE_DRAGGING;
mCurrentIndex = 0;
invalidate();
return true;
}
break;
case MotionEvent.ACTION_MOVE:
if (mState == STATE_DRAGGING) {
mLastX = x;
int index = (int) ((x - mViewWidth / 2) / INDICATOR_GAP);
index = Math.max(Math.min(index, mIndicatorCount - 1), 0);
if (index != mCurrentIndex) {
mCurrentIndex = index;
invalidate();
}
if (mCurrentIndex == mIndicatorCount - 1) {
mState = STATE_UNLOCKED;
mIsUnlocked = true;
}
return true;
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (mState == STATE_DRAGGING) {
mState = STATE_LOCKED;
mCurrentIndex = 0;
invalidate();
return true;
}
break;
}
return super.onTouchEvent(event);
}
}
}

@ -6,6 +6,7 @@
android:layout_height="match_parent"
tools:context=".VideoActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_margin="5dp"

@ -19,6 +19,4 @@
<item name="android:windowIsTranslucent">true</item>
</style>
</resources>
Loading…
Cancel
Save