diff --git a/app/build.gradle b/app/build.gradle
index bd563b43..d2ae772e 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -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'
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index ecfe7e9f..eaac3ee5 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -10,29 +10,56 @@
-
-
-
-
+
+
+
+
-
+
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
+
+
+ android:exported="true">
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
-
+
+
+
+
-
-
-
+
+
-
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) {
+ }
+
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/xypower/mpapp/MainActivity.java b/app/src/main/java/com/xypower/mpapp/MainActivity.java
index a35d6ae9..73f9f957 100644
--- a/app/src/main/java/com/xypower/mpapp/MainActivity.java
+++ b/app/src/main/java/com/xypower/mpapp/MainActivity.java
@@ -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 {
diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml
index 33692594..f9bdf388 100644
--- a/app/src/main/res/layout-land/activity_main.xml
+++ b/app/src/main/res/layout-land/activity_main.xml
@@ -136,6 +136,16 @@
app:layout_constraintStart_toEndOf="@+id/simchange"
app:layout_constraintTop_toBottomOf="@+id/startServBtn" />
+
+