再次上传代码

chenghonghao_branch
MikkoAyaka 1 year ago
parent 55faf2f930
commit ec7d8f7b5f

@ -1 +0,0 @@
Subproject commit 7b77e1557b2185a361eb64db6ec6b173a679a10c

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="WIFIRobot-android_code_public" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,26 @@
apply plugin: 'com.android.application'
android {
compileSdk 34
compileOptions.encoding = "GBK"
defaultConfig {
applicationId "my.wificar"
minSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
namespace 'my.wificar'
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="adnroid.permission.CHANGE_WIFI_STATE" /> <!-- 在SDCard中创建与删除文件权限 -->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <!-- 往SDCard写入数据权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RESTART_PACKAGES" /> <!-- 在SDCard中创建与删除文件权限 -->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <!-- 往SDCard写入数据权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RESTART_PACKAGES" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<activity
android:name="wificar.SettingsActivity"
android:exported="false" />
<activity
android:name="wificar.MyMainFrm"
android:label="@string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <!-- 这里是另外一个Activity的配置 -->
<activity
android:name="wificar.MyVideo"
android:label="@string/app_name"
android:screenOrientation="landscape" />
<activity
android:name="wificar.BgPictureShowActivity"
android:label="拍摄的照片"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Dialog" />
</application>
</manifest>

@ -0,0 +1,184 @@
package wificar;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.ViewSwitcher;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import my.wificar.R;
public class BgPictureShowActivity extends Activity implements
AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory {
/*
*
* gallerySD
*
*
* */
private List<String> ImageList;
private String[] list;
private ImageSwitcher mSwitcher;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pictureshow);
try {
ImageList = getSD();
list = ImageList.toArray(new String[ImageList.size()]);
mSwitcher = findViewById(R.id.switcher);
mSwitcher.setFactory(this);
mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
mSwitcher.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Toast.makeText(BgPictureShowActivity.this, "点击了", Toast.LENGTH_SHORT).show();
}
});
Gallery g = findViewById(R.id.mygallery);
g.setAdapter(new ImageAdapter(this, getSD()));
g.setOnItemSelectedListener(this);
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View v, int position, long id) {
Toast.makeText(BgPictureShowActivity.this, "第" + (position + 1) + "张图片", Toast.LENGTH_SHORT).show();
}
});
} catch (Exception e) {
Toast.makeText(this, "没有图片", Toast.LENGTH_SHORT).show();
}
}
private List<String> getSD() {
List<String> it = new ArrayList<String>();
File f = new File("/sdcard/demo/");
File[] files = f.listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (getImageFile(file.getPath()))
it.add(file.getPath());
}
return it;
}
private boolean getImageFile(String fName) {
boolean re;
String end = fName.substring(fName.lastIndexOf(".") + 1
).toLowerCase();
re = end.equals("jpg") || end.equals("gif") || end.equals("png")
|| end.equals("jpeg") || end.equals("bmp");
return re;
}
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
String photoURL = list[position];
Log.i("A", String.valueOf(position));
mSwitcher.setImageURI(Uri.parse(photoURL));
}
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
public View makeView() {
ImageView i = new ImageView(this);
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ImageSwitcher.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
return i;
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private final Context mContext;
private final List<String> lis;
public ImageAdapter(Context c, List<String> li) {
mContext = c;
lis = li;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return lis.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView,
ViewGroup parent) {
ImageView i = new ImageView(mContext);
Bitmap bm = BitmapFactory.decodeFile(lis.
get(position));
i.setImageBitmap(bm);
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setLayoutParams(new Gallery.LayoutParams(480, 320));
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
}

@ -0,0 +1,14 @@
package wificar;
/*Rwww.xiao-r.com
* FPV-WIFI·www.wifi-robots.com
*
* R
* */
import android.content.Context;
import android.os.Handler;
public class Constant {
public static Context context;
public static Handler handler = null;
}

@ -0,0 +1,104 @@
package wificar;
/*Rwww.xiao-r.com
* FPV-WIFI·www.wifi-robots.com
*
* R
* */
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import my.wificar.R;
public class MyMainFrm extends Activity {
public static String CameraIp;
EditText CameraIP, ControlIP, Port;
Button Button_go;
String videoUrl, controlUrl, port;
/*
* 退
* */
private long exitTime = 0;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
/*
* 线
* edIP
* Button_go
*
* */
setContentView(R.layout.mymainfrm);
CameraIP = findViewById(R.id.editIP);
ControlIP = findViewById(R.id.ip);
Port = findViewById(R.id.port);
Button_go = findViewById(R.id.button_go);
videoUrl = CameraIP.getText().toString();
controlUrl = ControlIP.getText().toString();
port = Port.getText().toString();
Button_go.requestFocusFromTouch();
Button_go.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
//生成一个Intent对象
Intent intent = new Intent();
//在Intent对象当中添加一个键值对
intent.putExtra("CameraIp", videoUrl);
intent.putExtra("ControlUrl", controlUrl);
intent.putExtra("Port", port);
intent.putExtra("Is_Scale", true);
//设置Intent对象要启动的Activity
intent.setClass(MyMainFrm.this, MyVideo.class);
//通过Intent对象启动另外一个Activity
MyMainFrm.this.startActivity(intent);
finish();
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
if ((System.currentTimeMillis() - exitTime) > 2000) //System.currentTimeMillis()无论何时调用肯定大于2000
{
Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
} else {
finish();
System.exit(0);
}
return true;
}
return super.onKeyDown(keyCode, event);
}
}

@ -0,0 +1,380 @@
package wificar;
/*Rwww.xiao-r.com
* FPV-WIFI·www.wifi-robots.com
*
* R
* */
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.widget.Toast;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class MySurfaceView extends SurfaceView implements Callback {
private static int mScreenWidth;
private static int mScreenHeight;
public boolean Is_Scale = false;
URL videoUrl;
HttpURLConnection conn;
Bitmap bmp;
InputStream inputstream = null;
private final SurfaceHolder sfh;
private Canvas canvas;
private String urlstr;
private final Paint p;
private Bitmap mBitmap;
private boolean isThreadRunning = true;
public MySurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
Constant.context = context;
initialize();
p = new Paint();
p.setAntiAlias(true);
sfh = this.getHolder();
sfh.addCallback(this);
this.setKeepScreenOn(true);
setFocusable(true);
this.getWidth();
this.getHeight();
Constant.handler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == 1) {
if (null != mBitmap) {
saveMyBitmap("snapshot", mBitmap);
} else {
Toast.makeText(Constant.context, "拍照失败,未能获取摄像头图像",
Toast.LENGTH_SHORT).show();
}
}
super.handleMessage(msg);
}
};
}
private void initialize() {
DisplayMetrics dm = getResources().getDisplayMetrics();
mScreenWidth = dm.widthPixels;
mScreenHeight = dm.heightPixels;
this.setKeepScreenOn(true);// 保持屏幕常亮
}
public void saveMyBitmap(String bitName, Bitmap mBitmap) {
File f = new File("/sdcard/demo/");
if (!f.exists()) {
f.mkdirs();
}
f = new File("/sdcard/demo/" + bitName + System.currentTimeMillis() + ".png");
try {
f.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
}
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Log.d("MySurface", "bitmap is:" + mBitmap + "fout is:" + fOut);
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
try {
fOut.flush();
Toast.makeText(Constant.context, "拍照成功!路径:/SDCard/Demo/",
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
public void surfaceDestroyed(SurfaceHolder holder) {
isThreadRunning = false;
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void GetCameraIP(String p) {
urlstr = p;
}
public void surfaceCreated(SurfaceHolder holder) {
isThreadRunning = true;
new DrawVideo().start();
}
class DrawVideo extends Thread {
public DrawVideo() {
}
@Override
protected Object clone() throws CloneNotSupportedException {
// TODO Auto-generated method stub
return super.clone();
}
public void run() {
Paint pt = new Paint();
pt.setAntiAlias(true);
pt.setColor(Color.GREEN);
pt.setTextSize(20);
pt.setStrokeWidth(1);
int bufSize = 512 * 1024; // 视频图片缓冲
byte[] jpg_buf = new byte[bufSize]; // buffer to read jpg
int readSize = 4096; // 每次最大获取的流
byte[] buffer = new byte[readSize]; // buffer to read stream
while (isThreadRunning) {
long Time = 0;
long Span = 0;
int fps = 0;
String str_fps = "0 fps";
URL url = null;
HttpURLConnection urlConn = null;
try {
url = new URL(urlstr);
urlConn = (HttpURLConnection) url.openConnection(); // 使用HTTPURLConnetion打开连接
Time = System.currentTimeMillis();
int read = 0;
int status = 0;
int jpg_count = 0; // jpg数据下标
while (true) {
read = urlConn.getInputStream().read(buffer, 0,
readSize);
if (read > 0) {
for (int i = 0; i < read; i++) {
switch (status) {
// Content-Length:
case 0:
if (buffer[i] == (byte) 'C')
status++;
else
status = 0;
break;
case 1:
if (buffer[i] == (byte) 'o')
status++;
else
status = 0;
break;
case 2:
if (buffer[i] == (byte) 'n')
status++;
else
status = 0;
break;
case 3:
if (buffer[i] == (byte) 't')
status++;
else
status = 0;
break;
case 4:
if (buffer[i] == (byte) 'e')
status++;
else
status = 0;
break;
case 5:
if (buffer[i] == (byte) 'n')
status++;
else
status = 0;
break;
case 6:
if (buffer[i] == (byte) 't')
status++;
else
status = 0;
break;
case 7:
if (buffer[i] == (byte) '-')
status++;
else
status = 0;
break;
case 8:
if (buffer[i] == (byte) 'L')
status++;
else
status = 0;
break;
case 9:
if (buffer[i] == (byte) 'e')
status++;
else
status = 0;
break;
case 10:
if (buffer[i] == (byte) 'n')
status++;
else
status = 0;
break;
case 11:
if (buffer[i] == (byte) 'g')
status++;
else
status = 0;
break;
case 12:
if (buffer[i] == (byte) 't')
status++;
else
status = 0;
break;
case 13:
if (buffer[i] == (byte) 'h')
status++;
else
status = 0;
break;
case 14:
if (buffer[i] == (byte) ':')
status++;
else
status = 0;
break;
case 15:
if (buffer[i] == (byte) 0xFF)
status++;
jpg_count = 0;
jpg_buf[jpg_count++] = buffer[i];
break;
case 16:
if (buffer[i] == (byte) 0xD8) {
status++;
jpg_buf[jpg_count++] = buffer[i];
} else {
if (buffer[i] != (byte) 0xFF)
status = 15;
}
break;
case 17:
jpg_buf[jpg_count++] = buffer[i];
if (buffer[i] == (byte) 0xFF)
status++;
if (jpg_count >= bufSize)
status = 0;
break;
case 18:
jpg_buf[jpg_count++] = buffer[i];
if (buffer[i] == (byte) 0xD9) {
status = 0;
// jpg接收完成
fps++;
Span = System.currentTimeMillis()
- Time;
if (Span > 1000L) {
Time = System.currentTimeMillis();
str_fps = fps
+ " fps";
fps = 0;
}
// 显示图像
//if (null != canvas)
{
canvas = sfh.lockCanvas();
canvas.drawColor(Color.BLACK);
Bitmap bmp = BitmapFactory.decodeStream(new ByteArrayInputStream(jpg_buf));
int width = mScreenWidth;
int height = mScreenHeight;
if (null != bmp) {
float rate_width = (float) mScreenWidth / (float) bmp.getWidth();
float rate_height = (float) mScreenHeight / (float) bmp.getHeight();
}
// if (Is_Scale) {
// if (rate_width > rate_height)
// width = (int) ((float) bmp
// .getWidth() * rate_height);
// if (rate_width < rate_height)
// height = (int) ((float) bmp
// .getHeight() * rate_width);
//
// }
Log.d("bmp", "bmp" + bmp);
Log.d("width", "width" + width);
Log.d("height", "height" + height);
if (null != bmp) {
mBitmap = Bitmap
.createScaledBitmap(bmp,
width, height,
false);
canvas.drawBitmap(
mBitmap,
(mScreenWidth - width) / 2,
(mScreenHeight - height) / 2,
null);
canvas.drawText(str_fps, 2, 22, pt);
}
sfh.unlockCanvasAndPost(canvas);// 画完一副图像,解锁画布
}
} else {
if (buffer[i] != (byte) 0xFF)
status = 17;
}
break;
default:
status = 0;
break;
}
}
}
}
} catch (IOException ex) {
urlConn.disconnect();
ex.printStackTrace();
}
}
}
}
}

@ -0,0 +1,186 @@
package wificar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.os.StrictMode;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;
import java.net.UnknownHostException;
import my.wificar.R;
public class MyVideo extends Activity {
public static String CameraIp;
public static String CtrlIp;
public static String CtrlPort;
URL videoUrl;
MySurfaceView r;
OutputStream socketWriter;
private Button TakePhotos;
private Button ViewPhotos;
private Button BtnForward, BtnBackward, BtnLeft, BtnRight, BtnStop;
private Socket socket;
private long exitTime = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//隐去标题应用的名字必须要写在setContentView之前否则会有异常
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.myvideo);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
r = findViewById(R.id.mySurfaceViewVideo);
TakePhotos = findViewById(R.id.TakePhoto);
ViewPhotos = findViewById(R.id.ViewPhoto);
BtnForward = findViewById(R.id.button_forward);
BtnBackward = findViewById(R.id.button_backward);
BtnLeft = findViewById(R.id.button_left);
BtnRight = findViewById(R.id.button_right);
BtnStop = findViewById(R.id.button_stop);
Intent intent = getIntent();
//从Intent当中根据key取得value
CameraIp = intent.getStringExtra("CameraIp");
CtrlIp = intent.getStringExtra("ControlUrl");
CtrlPort = intent.getStringExtra("Port");
Log.d("wifirobot", "control is :++++" + CtrlIp);
Log.d("wifirobot", "CtrlPort is :++++" + CtrlPort);
r.GetCameraIP(CameraIp);
InitSocket();
BtnForward.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
try {
socketWriter.write(new byte[]{(byte) 0xff, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0xff});
socketWriter.flush();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
BtnBackward.setOnClickListener(arg0 -> {
// TODO Auto-generated method stub
try {
socketWriter.write(new byte[]{(byte) 0xff, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0xff});
socketWriter.flush();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
BtnRight.setOnClickListener(arg0 -> {
// TODO Auto-generated method stub
try {
socketWriter.write(new byte[]{(byte) 0xff, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0xff});
socketWriter.flush();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
BtnLeft.setOnClickListener(arg0 -> {
// TODO Auto-generated method stub
try {
socketWriter.write(new byte[]{(byte) 0xff, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0xff});
socketWriter.flush();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
BtnStop.setOnClickListener(arg0 -> {
// TODO Auto-generated method stub
try {
socketWriter.write(new byte[]{(byte) 0xff, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xff});
socketWriter.flush();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
TakePhotos.setOnClickListener(arg0 -> {
// TODO Auto-generated method stub
if (null != Constant.handler) {
Message message = new Message();
message.what = 1;
Constant.handler.sendMessage(message);
}
});
ViewPhotos.setOnClickListener(arg0 -> {
// TODO Auto-generated method stub
Intent intent1 = new Intent();
intent1.setClass(MyVideo.this, BgPictureShowActivity.class);
//通过Intent对象启动另外一个Activity
MyVideo.this.startActivity(intent1);
});
}
public void InitSocket() {
try {
socket = new Socket(InetAddress.getByName(CtrlIp), Integer.parseInt(CtrlPort));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
socketWriter = socket.getOutputStream();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Toast.makeText(this,"初始化网络失败!"+e.getMessage(),Toast.LENGTH_LONG).show();
}
public void onDestroy() {
super.onDestroy();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
if ((System.currentTimeMillis() - exitTime) > 2500) //System.currentTimeMillis()无论何时调用肯定大于2500
{
Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
} else {
finish();
System.exit(0);
}
return true;
}
return super.onKeyDown(keyCode, event);
}
}

@ -0,0 +1,16 @@
package wificar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import my.wificar.R;
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="wificar.SettingsActivity">
<LinearLayout
android:layout_width="180dp"
android:layout_height="180dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:orientation="vertical"
>
<Button
android:layout_width="135dp"
android:layout_height="60dp"
android:text="开始"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
/>
<Button
android:layout_width="135dp"
android:layout_height="60dp"
android:text="设置"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="440dp"
android:layout_height="180dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="连接模式"
android:textSize="20dp"
android:textColor="#000000"
android:layout_marginTop="60dp"
android:layout_marginEnd="20dp"
/>
<Button
android:layout_width="135dp"
android:layout_height="60dp"
android:layout_marginTop="60dp"
android:text="WIFI模式"
/>
<Button
android:layout_width="135dp"
android:layout_height="60dp"
android:layout_marginTop="60dp"
android:layout_marginStart="20dp"
android:text="蓝牙模式"
/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/textViewIP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="视频地址" />
<EditText
android:id="@+id/editIP"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="http://192.168.1.1:8080/?action=stream" />
<EditText
android:id="@+id/ip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="192.168.1.1" />
<EditText
android:id="@+id/port"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="2001" />
<Button
android:id="@+id/button_go"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="启动" />
</LinearLayout>

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<wificar.MySurfaceView
android:id="@+id/mySurfaceViewVideo"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/TakePhoto"
android:layout_width="66dp"
android:layout_height="55dp"
android:text="拍照" />
<Button
android:layout_toRightOf="@+id/TakePhoto"
android:id="@+id/ViewPhoto"
android:layout_width="66dp"
android:layout_height="55dp"
android:layout_x="90dp"
android:text="查看" />
<Button
android:layout_below="@+id/TakePhoto"
android:id="@+id/button_forward"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/button_left"
android:layout_width="100dip"
android:text="前"
/>
<Button
android:layout_centerInParent="true"
android:layout_below="@+id/button_forward"
android:id="@+id/button_backward"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/button_left"
android:layout_width="100dip"
android:text="后" />
<Button
android:layout_below="@+id/button_forward"
android:id="@+id/button_left"
android:layout_height="wrap_content"
android:layout_width="100dip"
android:text="左"
/>
<Button
android:id="@+id/button_right"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/button_backward"
android:layout_below="@+id/button_forward"
android:layout_width="100dip"
android:text="右"
/>
<Button
android:id="@+id/button_stop"
android:layout_height="wrap_content"
android:layout_width="100dip"
android:layout_toRightOf="@+id/button_right"
android:text="停" />
</RelativeLayout>

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#55000000"
>
<ImageSwitcher
android:id="@+id/switcher"
android:layout_width="wrap_content"
android:layout_height="350dip"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
/>
<Gallery
android:id="@+id/mygallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:spacing="16dp"
/>
</RelativeLayout>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Gallery">
<attr name="android:galleryItemBackground" />
</declare-styleable>
</resources>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">hello</string>
<string name="app_name">智能搜救机器人</string>
</resources>

@ -0,0 +1,17 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.1'
}
}
allprojects {
repositories {
jcenter()
google()
}
}

@ -0,0 +1,4 @@
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
android.nonTransitiveRClass=false
android.useAndroidX=true

@ -0,0 +1 @@
include ':app'
Loading…
Cancel
Save