增加配置设置、修改数据目录

serial
BlueMatthew 2 years ago
parent 1d79350e49
commit 5676cb6696

@ -64,6 +64,7 @@
<application
android:allowBackup="true"
android:requestLegacyExternalStorage="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
@ -150,6 +151,17 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
</application>
</manifest>

@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
@ -103,21 +104,45 @@ public class ChannelActivity extends AppCompatActivity {
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);
File channelFile = new File(appPath + "data/channels/" + String.valueOf(channel) + ".json");
StringBuilder stringBuilder = null;
if (channelFile.exists()) {
inputStreamReader = new InputStreamReader(new FileInputStream(channelFile), "UTF-8");
bufferedReader = new BufferedReader(inputStreamReader);
String line;
stringBuilder = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
}
JSONObject jsonObject = new JSONObject(stringBuilder.toString());
JSONObject jsonObject = stringBuilder != null ? (new JSONObject(stringBuilder.toString())) : new JSONObject();
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)));
binding.orientations.setSelection(jsonObject.optInt("orientation", 0));
binding.recognization.setSelection(jsonObject.optInt("recognization", 0));
if (jsonObject.has("cameraId")) {
binding.cameraId.setText(Integer.toString(jsonObject.optInt("cameraId", channel - 1)));
} else {
binding.cameraId.setText("");
}
JSONObject osdJsonObj = jsonObject.optJSONObject("osd");
if (osdJsonObj != null) {
binding.osdLeftTop.setText(osdJsonObj.optString("leftTop", ""));
binding.osdRightTop.setText(osdJsonObj.optString("rightTop", ""));
binding.osdRightBottom.setText(osdJsonObj.optString("rightBottom", ""));
binding.osdLeftBottom.setText(osdJsonObj.optString("leftBottom", ""));
} else {
binding.osdLeftTop.setText("");
binding.osdRightTop.setText("");
binding.osdRightBottom.setText("");
binding.osdLeftBottom.setText("");
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
@ -196,9 +221,25 @@ public class ChannelActivity extends AppCompatActivity {
jsonObject.put("exposureTime", Integer.parseInt(binding.exposuretime.getText().toString()));
jsonObject.put("sensibility", Integer.parseInt(binding.sensitivity.getText().toString()));
jsonObject.put("orientation", binding.orientations.getSelectedItemPosition());
jsonObject.put("recognization", binding.recognization.getSelectedItemPosition());
// binding.cameraId.setText(jsonObject.optString("cameraId", ""));
if (!TextUtils.isEmpty(binding.cameraId.getText().toString())) {
jsonObject.put("cameraId", Integer.parseInt(binding.cameraId.getText().toString()));
} else {
jsonObject.remove("cameraId");
}
} catch (JSONException ex) {
JSONObject osdJsonObj = jsonObject.optJSONObject("osd");
if (osdJsonObj == null) {
osdJsonObj = jsonObject.put("osd", new JSONObject());
}
osdJsonObj.put("leftTop", binding.osdLeftTop.getText().toString());
osdJsonObj.put("rightTop", binding.osdRightTop.getText().toString());
osdJsonObj.put("rightBottom", binding.osdRightBottom.getText().toString());
osdJsonObj.put("leftBottom", binding.osdLeftBottom.getText().toString());
} catch (JSONException ex) {
}
OutputStreamWriter outputStreamWriter = null;
try {

@ -4,11 +4,13 @@ import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.FileObserver;
@ -22,6 +24,7 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.core.app.ActivityCompat;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import android.os.Bundle;
import android.telephony.SubscriptionManager;
@ -51,6 +54,7 @@ import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import org.json.JSONException;
@ -144,6 +148,8 @@ public class MainActivity extends AppCompatActivity {
binding.logs.setScrollbarFadingEnabled(false);
// binding.logs.setMaxLines(16);
// Context appContext = getApplicationContext();
mHandler = new Handler(Looper.myLooper()) {
@Override
public void handleMessage(@NonNull Message msg) {

@ -17,9 +17,12 @@ import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
@ -29,6 +32,7 @@ import android.os.RemoteException;
import android.os.SystemClock;
import androidx.core.app.NotificationCompat;
import androidx.core.content.FileProvider;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionManager;
@ -673,6 +677,7 @@ public class MicroPhotoService extends Service {
public static String buildAppDir(Context contxt) {
/*
File[] paths = contxt.getExternalFilesDirs(null);
if (paths == null || paths.length == 0) {
@ -680,6 +685,9 @@ public class MicroPhotoService extends Service {
}
File path = paths[0];
*/
File path = new File(Environment.getExternalStorageDirectory(), contxt.getPackageName() + "/");
if (!path.exists() && !path.mkdirs()) {
return null;
@ -727,6 +735,13 @@ public class MicroPhotoService extends Service {
return true;
}
public static Uri getUriForFile(Context context, File file) {
if (Build.VERSION.SDK_INT > 24) {
return FileProvider.getUriForFile(context, context.getPackageName() + ".fileProvider", file);
}
return Uri.fromFile(file);
}
public boolean requestPosition() {
try {

@ -58,7 +58,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:ems="10"
android:inputType="none|number"
android:inputType="none"
android:imeOptions="actionDone"
android:text="47.96.238.157"
app:layout_constraintStart_toStartOf="@+id/cmdid"

@ -17,14 +17,26 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/cameraId"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
app:layout_constraintStart_toEndOf="@+id/channels"
app:layout_constraintTop_toTopOf="@+id/channels"
app:layout_constraintBottom_toBottomOf="@+id/channels" />
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_marginTop="6dp"
android:text="保存"
app:layout_constraintStart_toEndOf="@+id/channels"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -75,7 +87,7 @@
android:ems="10"
android:inputType="numberDecimal"
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
android:layout_marginTop="12dp"
app:layout_constraintStart_toEndOf="@+id/textViewExplosure"
app:layout_constraintTop_toBottomOf="@+id/btnAutoExplosure" />
@ -121,4 +133,71 @@
app:layout_constraintStart_toEndOf="@+id/textViewOrientations"
app:layout_constraintTop_toBottomOf="@+id/exposuretime" />
<Spinner
android:id="@+id/recognization"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:entries="@array/recog_options"
android:layout_marginStart="6dp"
app:layout_constraintStart_toEndOf="@+id/orientations"
app:layout_constraintTop_toTopOf="@+id/orientations" />
<EditText
android:id="@+id/osdLeftTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_marginTop="6dp"
android:hint="@string/osd_left_top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recognization" />
<EditText
android:id="@+id/osdRightTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_marginTop="6dp"
android:hint="@string/osd_right_top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/osdLeftTop" />
<EditText
android:id="@+id/osdRightBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_marginTop="6dp"
android:hint="@string/osd_right_bottom"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/osdRightTop" />
<EditText
android:id="@+id/osdLeftBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_marginTop="6dp"
android:hint="@string/osd_left_bottom"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/osdRightBottom" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -55,7 +55,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:ems="10"
android:inputType=""
android:inputType="none"
android:text="47.96.238.157"
app:layout_constraintStart_toStartOf="@+id/cmdid"
app:layout_constraintTop_toBottomOf="@+id/cmdid" />

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="recog_options">
<item>0-关闭AI识别</item>
<item>1-打开但不绘制</item>
<item>2-打开并绘制</item>
</string-array>
</resources>

@ -1,4 +1,8 @@
<resources>
<string name="app_name">MicroPhoto</string>
<string name="text_name_notification">Notification Name</string>
<string name="osd_left_top">左上 OSD</string>
<string name="osd_right_top">右上 OSD</string>
<string name="osd_right_bottom">右下 OSD</string>
<string name="osd_left_bottom">左下 OSD</string>
</resources>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-files-path name="external-files" path="" />
</paths>

@ -19,8 +19,8 @@ buildscript {
}
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
}

@ -1,6 +1,6 @@
#Mon May 22 15:39:17 CST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.5-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

Loading…
Cancel
Save