Skip to content

Commit 8c4527f

Browse files
committed
Add unstyled button for uploading a custom screenshot
1 parent b503dae commit 8c4527f

File tree

4 files changed

+47
-14
lines changed

4 files changed

+47
-14
lines changed

firebase-appdistribution/firebase-appdistribution.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ dependencies {
7171

7272
compileOnly 'com.google.auto.value:auto-value-annotations:1.6.5'
7373
annotationProcessor 'com.google.auto.value:auto-value:1.6.5'
74-
implementation 'androidx.appcompat:appcompat:1.3.1'
75-
implementation "androidx.browser:browser:1.3.0"
76-
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
74+
implementation 'androidx.activity:activity:1.6.1'
75+
implementation 'androidx.appcompat:appcompat:1.6.0'
76+
implementation 'androidx.browser:browser:1.4.0'
77+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
7778

7879
androidTestImplementation project(':integ-testing')
7980
androidTestImplementation 'androidx.test.ext:junit:1.1.1'

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/FeedbackActivity.java

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import android.widget.ImageView;
2828
import android.widget.TextView;
2929
import android.widget.Toast;
30+
import androidx.activity.result.ActivityResultLauncher;
31+
import androidx.activity.result.PickVisualMediaRequest;
32+
import androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia;
3033
import androidx.annotation.NonNull;
3134
import androidx.annotation.Nullable;
3235
import androidx.appcompat.app.AppCompatActivity;
@@ -100,19 +103,42 @@ private void setupView() {
100103
findViewById(R.id.backButton).setOnClickListener(v -> finish());
101104
findViewById(R.id.sendButton).setOnClickListener(this::submitFeedback);
102105

106+
// Registers a photo picker activity launcher in single-select mode
107+
ActivityResultLauncher<PickVisualMediaRequest> pickMedia =
108+
registerForActivityResult(
109+
new PickVisualMedia(),
110+
uri -> {
111+
if (uri != null) {
112+
LogWrapper.d(TAG, "Selected custom screenshot URI: " + uri);
113+
screenshotUri = uri;
114+
setupScreenshot();
115+
} else {
116+
LogWrapper.d(TAG, "No custom screenshot selected. Not changing screenshot URI.");
117+
}
118+
});
119+
120+
findViewById(R.id.chooseScreenshotButton)
121+
.setOnClickListener(
122+
v ->
123+
pickMedia.launch(
124+
new PickVisualMediaRequest.Builder()
125+
.setMediaType(new PickVisualMedia.SingleMimeType("image/png"))
126+
.build()));
127+
103128
setupScreenshot();
104129
}
105130

106131
private void setupScreenshot() {
107132
blockingExecutor.execute(
108133
() -> {
109-
// do I/O on separate thread in order to not block the UI
110-
Bitmap screenshot = screenshotUri == null ? null : readScreenshot();
134+
// Do I/O on separate thread in order to not block the UI
135+
Bitmap screenshot = readScreenshot(screenshotUri);
111136
if (screenshot != null) {
112137
runOnUiThread(
113138
() -> {
114139
ImageView imageView = findViewById(R.id.screenshotImageView);
115140
imageView.setImageBitmap(screenshot);
141+
imageView.setVisibility(VISIBLE);
116142
CheckBox checkBox = findViewById(R.id.screenshotCheckBox);
117143
checkBox.setChecked(true);
118144
checkBox.setOnClickListener(
@@ -132,21 +158,21 @@ private void setupScreenshot() {
132158
}
133159

134160
@Nullable
135-
private Bitmap readScreenshot() {
161+
private Bitmap readScreenshot(@Nullable Uri uri) {
162+
if (uri == null) {
163+
return null;
164+
}
136165
Bitmap bitmap;
137166
try {
138167
bitmap =
139168
ImageUtils.readScaledImage(
140-
getContentResolver(),
141-
screenshotUri,
142-
SCREENSHOT_TARGET_WIDTH_PX,
143-
SCREENSHOT_TARGET_HEIGHT_PX);
169+
getContentResolver(), uri, SCREENSHOT_TARGET_WIDTH_PX, SCREENSHOT_TARGET_HEIGHT_PX);
144170
} catch (IOException | SecurityException e) {
145-
LogWrapper.e(TAG, "Could not read screenshot image from URI: " + screenshotUri, e);
171+
LogWrapper.e(TAG, "Could not read screenshot image from URI: " + uri, e);
146172
return null;
147173
}
148174
if (bitmap == null) {
149-
LogWrapper.e(TAG, "Could not decode screenshot image: " + screenshotUri);
175+
LogWrapper.e(TAG, "Could not decode screenshot image: " + uri);
150176
}
151177
return bitmap;
152178
}

firebase-appdistribution/src/main/res/layout/activity_feedback.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@
113113
android:scaleType="centerInside"
114114
android:adjustViewBounds="true"
115115
android:contentDescription="@string/screenshot_image_description" />
116+
117+
<Button
118+
android:id="@+id/chooseScreenshotButton"
119+
android:layout_width="wrap_content"
120+
android:layout_height="wrap_content"
121+
android:text="Gallery" />
116122
</LinearLayout>
117123
</LinearLayout>
118124
</ScrollView>

firebase-appdistribution/test-app/test-app.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ android {
2525
applicationId "com.googletest.firebase.appdistribution.testapp"
2626
minSdkVersion 23
2727
targetSdkVersion 33
28-
versionName "3.1"
29-
versionCode 6
28+
versionName "3.2"
29+
versionCode 7
3030

3131
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3232
}

0 commit comments

Comments
 (0)