From 785524344358a8b97d970a390a6aaf1396eaa4f3 Mon Sep 17 00:00:00 2001 From: althafvly Date: Sun, 4 Dec 2022 20:58:07 +0530 Subject: [PATCH] Camera: Change multi lens switch icon --- .../sourceforge/opencamera/MainActivity.java | 47 ++++++++++++++----- .../main/res/drawable/ic_lens_background.xml | 9 ++++ .../res/drawable/ic_switch_multi_camera.xml | 25 ---------- app/src/main/res/layout/activity_main.xml | 9 ++-- app/src/main/res/values/strings.xml | 2 + 5 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 app/src/main/res/drawable/ic_lens_background.xml delete mode 100644 app/src/main/res/drawable/ic_switch_multi_camera.xml diff --git a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java index 8c66d6398..cac48b2de 100644 --- a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java +++ b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java @@ -111,6 +111,7 @@ import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.WindowInsets; import android.view.WindowManager; +import android.widget.Button; import android.widget.EditText; import android.widget.ImageButton; import android.widget.SeekBar; @@ -2224,20 +2225,8 @@ public class MainActivity extends AppCompatActivity { Log.e(TAG, "getNextMultiCameraId() called but not in multi-cam mode"); throw new RuntimeException("getNextMultiCameraId() called but not in multi-cam mode"); } - List camera_set; - // don't use preview.getCameraController(), as it may be null if user quickly switches between cameras int currCameraId = getActualCameraId(); - switch( preview.getCameraControllerManager().getFacing(currCameraId) ) { - case FACING_BACK: - camera_set = back_camera_ids; - break; - case FACING_FRONT: - camera_set = front_camera_ids; - break; - default: - camera_set = other_camera_ids; - break; - } + List camera_set = getCameraSet(currCameraId); int cameraId; int indx = camera_set.indexOf(currCameraId); if( indx == -1 ) { @@ -2254,6 +2243,24 @@ public class MainActivity extends AppCompatActivity { return cameraId; } + private List getCameraSet(int currCameraId) { + // don't use preview.getCameraController(), as it may be null if user quickly switches between cameras + List camera_set; + switch( preview.getCameraControllerManager().getFacing(currCameraId) ) { + case FACING_BACK: + camera_set = back_camera_ids; + break; + case FACING_FRONT: + camera_set = front_camera_ids; + break; + default: + camera_set = other_camera_ids; + break; + } + + return camera_set; + } + private void pushCameraIdToast(int cameraId) { if( MyDebug.LOG ) Log.d(TAG, "pushCameraIdToast: " + cameraId); @@ -2338,6 +2345,18 @@ public class MainActivity extends AppCompatActivity { } } + private void updateMultiCameraIcon() { + Button multiCameraButton = findViewById(R.id.switch_multi_camera); + + if (multiCameraButton.getVisibility() != View.GONE) { + int currCameraId = getActualCameraId(); + List camera_set = getCameraSet(currCameraId); + int index = camera_set.indexOf(currCameraId); + String text = getString(R.string.switch_multi_camera_lens) + " " + (index + 1); + multiCameraButton.setText(text); + } + } + /** * Toggles Photo/Video mode */ @@ -3146,6 +3165,8 @@ public class MainActivity extends AppCompatActivity { View button = findViewById(R.id.switch_multi_camera); changed = changed || (button.getVisibility() != View.GONE); button.setVisibility(View.GONE); + } else { + updateMultiCameraIcon(); } if( MyDebug.LOG ) Log.d(TAG, "checkDisableGUIIcons: " + changed); diff --git a/app/src/main/res/drawable/ic_lens_background.xml b/app/src/main/res/drawable/ic_lens_background.xml new file mode 100644 index 000000000..27e3ec4a4 --- /dev/null +++ b/app/src/main/res/drawable/ic_lens_background.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_switch_multi_camera.xml b/app/src/main/res/drawable/ic_switch_multi_camera.xml deleted file mode 100644 index 8d17d9266..000000000 --- a/app/src/main/res/drawable/ic_switch_multi_camera.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 59e4cf579..5cb4c8bff 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -135,15 +135,14 @@ android:layout_height="wrap_content" android:background="@color/navigation_background"/> - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 659b0d7a9..6e988910f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1083,4 +1083,6 @@ Back Next Skip + + LENS -- GitLab