Skip to content

Commit f3b492d

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

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

firebase-appdistribution/firebase-appdistribution.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ 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.activity:activity:1.6.1'
7475
implementation 'androidx.appcompat:appcompat:1.3.1'
7576
implementation "androidx.browser:browser:1.3.0"
7677
implementation "androidx.constraintlayout:constraintlayout:2.1.4"

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

Lines changed: 34 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,14 +103,36 @@ 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
() -> {
@@ -132,21 +157,21 @@ private void setupScreenshot() {
132157
}
133158

134159
@Nullable
135-
private Bitmap readScreenshot() {
160+
private Bitmap readScreenshot(@Nullable Uri uri) {
161+
if (uri == null) {
162+
return null;
163+
}
136164
Bitmap bitmap;
137165
try {
138166
bitmap =
139167
ImageUtils.readScaledImage(
140-
getContentResolver(),
141-
screenshotUri,
142-
SCREENSHOT_TARGET_WIDTH_PX,
143-
SCREENSHOT_TARGET_HEIGHT_PX);
168+
getContentResolver(), uri, SCREENSHOT_TARGET_WIDTH_PX, SCREENSHOT_TARGET_HEIGHT_PX);
144169
} catch (IOException | SecurityException e) {
145-
LogWrapper.e(TAG, "Could not read screenshot image from URI: " + screenshotUri, e);
170+
LogWrapper.e(TAG, "Could not read screenshot image from URI: " + uri, e);
146171
return null;
147172
}
148173
if (bitmap == null) {
149-
LogWrapper.e(TAG, "Could not decode screenshot image: " + screenshotUri);
174+
LogWrapper.e(TAG, "Could not decode screenshot image: " + uri);
150175
}
151176
return bitmap;
152177
}

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: 3 additions & 3 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
}
@@ -53,7 +53,7 @@ android {
5353

5454
firebaseAppDistribution {
5555
releaseNotes "Beta variant of Android SDK test app"
56-
// testers "your email here"
56+
5757
}
5858
}
5959
}

0 commit comments

Comments
 (0)