增加通道拍照参数的设置

serial
BlueMatthew 2 years ago
parent daddd080cc
commit c409a806d4

@ -75,6 +75,7 @@ dependencies {
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.material:material:1.8.0'
// implementation 'androidx.camera:camera-video:1.2.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'

@ -10,29 +10,56 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.SET_TIME" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.SET_TIME_ZONE" tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.SET_TIME"
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.CHANGE_CONFIGURATION"
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.SET_TIME_ZONE"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REBOOT" tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.REBOOT"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" tools:ignore="ProtectedPermissions" /> <!-- 关机权限 -->
<uses-permission android:name="android.permission.RECOVERY" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.SHUTDOWN" tools:ignore="ProtectedPermissions" /> <!-- 添加访问手机状态的权限 -->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.INSTALL_PACKAGES"
tools:ignore="ProtectedPermissions" /> <!-- 关机权限 -->
<uses-permission
android:name="android.permission.RECOVERY"
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.SHUTDOWN"
tools:ignore="ProtectedPermissions" /> <!-- 添加访问手机状态的权限 -->
<uses-permission
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" /> <!-- 接收短信权限 -->
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DEVICE_POWER" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND" tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.DEVICE_POWER"
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.MODIFY_PHONE_STATE"
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"
tools:ignore="ProtectedPermissions" />
<uses-feature android:name="android.hardware.camera" />
<application
@ -41,16 +68,18 @@
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/Theme.MicroPhoto"
android:networkSecurityConfig="@xml/network_security_config"
tools:targetApi="28">
<activity
android:name=".ChannelActivity"
android:exported="false" />
<service
android:name=".MicroPhotoService"
android:enabled="true"
android:exported="true"
>
android:exported="true">
<intent-filter android:priority="90000">
<action android:name="com.xypower.mpapp.MicroPhotoService" />
<action android:name="android.intent.action.USER_PRESENT" />
@ -58,35 +87,30 @@
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.USER_UNLOCKED" />
<category android:name="android.intent.category.default" />
</intent-filter>
</service>
<service android:name=".FloatingWindow"></service>
<service android:name=".FloatingWindow">
</service>
<receiver android:name=".MicroPhotoService$AlarmReceiver"
android:exported="true">
</receiver>
<receiver android:name=".BootBroadcastReceiver"
<receiver
android:name=".MicroPhotoService$AlarmReceiver"
android:exported="true"></receiver>
<receiver
android:name=".BootBroadcastReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter android:priority="90000">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.REBOOT" />
<category android:name="android.intent.category.default" />
</intent-filter>
</receiver>
<receiver android:name=".NetworkChangedReceiver" >
</receiver>
<receiver android:name=".ScreenActionReceiver"
<receiver android:name=".NetworkChangedReceiver"></receiver>
<receiver
android:name=".ScreenActionReceiver"
android:exported="true">
<intent-filter android:priority="90000">
<action android:name="android.intent.action.USER_PRESENT" />
@ -96,14 +120,12 @@
<action android:name="android.intent.action.USER_UNLOCKED" />
</intent-filter>
</receiver>
<receiver android:name=".SmsReceiver">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:exported="true"

@ -0,0 +1,222 @@
package com.xypower.mpapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import androidx.appcompat.app.ActionBar;
import com.xypower.mpapp.databinding.ActivityChannelBinding;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import android.widget.AdapterView;
public class ChannelActivity extends AppCompatActivity {
private ActivityChannelBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityChannelBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
binding.sensitivity.setOnFocusChangeListener(onFocusChangeListener);
binding.exposuretime.setOnFocusChangeListener(onFocusChangeListener);
int channel = binding.channels.getSelectedItemPosition();
loadChannelParams(channel);
binding.channels.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
int channel = i + 1;
loadChannelParams(channel);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
binding.btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int channel = binding.channels.getSelectedItemPosition() + 1;
saveChannelParams(channel);
}
});
}
private View.OnFocusChangeListener onFocusChangeListener = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
};
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// todo: goto back activity from here
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
protected void loadChannelParams(int channel) {
binding.btnAutoExplosure.setChecked(true);
binding.btnAutoFocus.setChecked(true);
binding.btnHdrMode.setChecked(true);
binding.exposuretime.setText("0");
binding.sensitivity.setText("0");
String appPath = MicroPhotoService.buildAppDir(getApplicationContext());
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
try {
inputStreamReader = new InputStreamReader(new FileInputStream(new File(appPath + "data/channels/" + String.valueOf(channel) + ".json")), "UTF-8");
bufferedReader = new BufferedReader(inputStreamReader);
String line;
StringBuilder stringBuilder = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
JSONObject jsonObject = new JSONObject(stringBuilder.toString());
binding.btnAutoExplosure.setChecked(jsonObject.optInt("autoExposure", 1) == 1);
binding.btnAutoFocus.setChecked(jsonObject.optInt("autoFocus", 1) == 1);
binding.btnHdrMode.setChecked(jsonObject.optInt("hdr", 1) == 1);
binding.exposuretime.setText(Integer.toString(jsonObject.optInt("exposureTime", 0)));
binding.sensitivity.setText(Integer.toString(jsonObject.optInt("sensibility", 0)));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (Exception ex) {
}
}
if (inputStreamReader != null) {
try {
inputStreamReader.close();
} catch (Exception ex) {
}
}
}
}
private void saveChannelParams(int channel) {
JSONObject jsonObject = null;
String appPath = MicroPhotoService.buildAppDir(this.getApplicationContext());
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
File dataPath = new File(appPath + "data/channels/");
File file = new File(dataPath, String.valueOf(channel) + ".json");
try {
StringBuilder stringBuilder = new StringBuilder();
if (file.exists()) {
inputStreamReader = new InputStreamReader(new FileInputStream(file), "UTF-8");
bufferedReader = new BufferedReader(inputStreamReader);
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
jsonObject =stringBuilder.length() > 0 ? (new JSONObject(stringBuilder.toString())) : (new JSONObject());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (Exception ex) {
}
}
if (inputStreamReader != null) {
try {
inputStreamReader.close();
} catch (Exception ex) {
}
}
}
if (jsonObject == null) {
jsonObject = new JSONObject();
}
try {
jsonObject.put("autoExposure", binding.btnAutoExplosure.isChecked() ? 1 : 0);
jsonObject.put("autoFocus", binding.btnAutoFocus.isChecked() ? 1 : 0);
jsonObject.put("hdrMode", binding.btnHdrMode.isChecked() ? 1 : 0);
jsonObject.put("exposureTime", Integer.parseInt(binding.exposuretime.getText().toString()));
jsonObject.put("sensibility", Integer.parseInt(binding.sensitivity.getText().toString()));
} catch (JSONException ex) {
}
OutputStreamWriter outputStreamWriter = null;
try {
if (!dataPath.exists()) {
dataPath.mkdirs();
}
outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
outputStreamWriter.write(jsonObject.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (outputStreamWriter != null) {
try {
outputStreamWriter.close();
} catch (Exception ex) {
}
}
}
}
}

@ -329,6 +329,14 @@ public class MainActivity extends AppCompatActivity {
}
});
binding.btnChannels.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ChannelActivity.class);
startActivity(intent);
}
});
binding.gps.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -562,11 +570,11 @@ public class MainActivity extends AppCompatActivity {
appConfig.protocol = DEFAULT_PROTOCOL;
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
// e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
// e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
// e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {

@ -136,6 +136,16 @@
app:layout_constraintStart_toEndOf="@+id/simchange"
app:layout_constraintTop_toBottomOf="@+id/startServBtn" />
<Button
android:id="@+id/btnChannels"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
android:text="通道设置"
app:layout_constraintStart_toEndOf="@+id/simchange2"
app:layout_constraintTop_toBottomOf="@+id/startServBtn" />
<Button
android:id="@+id/takePhotoBtn"
android:layout_width="wrap_content"

@ -0,0 +1,105 @@
<?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=".ChannelActivity">
<Spinner
android:id="@+id/channels"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:entries="@array/channels"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="6dp"
android:text="保存"
app:layout_constraintStart_toEndOf="@+id/channels"
app:layout_constraintTop_toTopOf="parent" />
<Switch
android:id="@+id/btnAutoExplosure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="6dp"
android:text="自动曝光"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnSave" />
<Switch
android:id="@+id/btnAutoFocus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="6dp"
android:text="自动对焦"
app:layout_constraintStart_toEndOf="@+id/btnAutoExplosure"
app:layout_constraintTop_toBottomOf="@+id/btnSave" />
<Switch
android:id="@+id/btnHdrMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="6dp"
android:text="HDR"
app:layout_constraintStart_toEndOf="@+id/btnAutoFocus"
app:layout_constraintTop_toBottomOf="@+id/btnSave" />
<TextView
android:id="@+id/textViewExplosure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="曝光时间(ms)"
android:layout_marginStart="12dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/exposuretime"
app:layout_constraintBottom_toBottomOf="@+id/exposuretime" />
<EditText
android:id="@+id/exposuretime"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
app:layout_constraintStart_toEndOf="@+id/textViewExplosure"
app:layout_constraintTop_toBottomOf="@+id/btnAutoExplosure" />
<TextView
android:id="@+id/textViewSensitivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ISO"
android:layout_marginStart="12dp"
app:layout_constraintStart_toEndOf="@+id/exposuretime"
app:layout_constraintTop_toTopOf="@+id/exposuretime"
app:layout_constraintBottom_toBottomOf="@+id/exposuretime" />
<EditText
android:id="@+id/sensitivity"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:layout_marginStart="4dp"
app:layout_constraintStart_toEndOf="@+id/textViewSensitivity"
app:layout_constraintTop_toTopOf="@+id/exposuretime"
app:layout_constraintBottom_toBottomOf="@+id/exposuretime" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -135,6 +135,16 @@
app:layout_constraintStart_toEndOf="@+id/simchange"
app:layout_constraintTop_toBottomOf="@+id/startServBtn" />
<Button
android:id="@+id/btnChannels"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
android:text="通道设置"
app:layout_constraintStart_toEndOf="@+id/simchange2"
app:layout_constraintTop_toBottomOf="@+id/startServBtn" />
<Button
android:id="@+id/takePhotoBtn"
android:layout_width="wrap_content"

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="channels">
<item>通道1</item>
<item>通道2</item>
<item>通道3</item>
<item>通道4</item>
</string-array>
</resources>
Loading…
Cancel
Save