Skip to content

Commit 89a1588

Browse files
committed
Show an UI feedback when copying to clipboard
Instead of using a snackbar show a checkmark and a text view when user copy the qr scan result.
1 parent 3d1d1ff commit 89a1588

3 files changed

Lines changed: 60 additions & 8 deletions

File tree

app/src/main/java/app/grapheneos/camera/ui/activities/MainActivity.kt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,17 +1198,29 @@ open class MainActivity : AppCompatActivity(),
11981198
})
11991199

12001200
val ctc: ImageButton = dialogBinding.copyQrText
1201+
val confirmationLabel = dialogBinding.copyConfirmation
1202+
12011203
ctc.setOnClickListener {
1202-
val clipboardManager = getSystemService(
1203-
Context.CLIPBOARD_SERVICE
1204-
) as ClipboardManager
1205-
val clipData = ClipData.newPlainText(
1206-
"text",
1207-
textView.text
1208-
)
1204+
val clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
1205+
val clipData = ClipData.newPlainText("text", textView.text)
12091206
clipboardManager.setPrimaryClip(clipData)
12101207

1211-
showMessage(getString(R.string.copied_text_to_clipboard))
1208+
ctc.setImageResource(R.drawable.ic_check)
1209+
ctc.imageTintList = null
1210+
ctc.animate().scaleX(1.2f).scaleY(1.2f).setDuration(100).withEndAction {
1211+
ctc.animate().scaleX(1.0f).scaleY(1.0f).setDuration(100)
1212+
}
1213+
confirmationLabel.visibility = View.VISIBLE
1214+
confirmationLabel.postDelayed({
1215+
confirmationLabel.visibility = View.GONE
1216+
}, 2000)
1217+
1218+
ctc.postDelayed({
1219+
ctc.animate().alpha(0f).setDuration(150).withEndAction {
1220+
ctc.setImageResource(R.drawable.copy_to_clipboard)
1221+
ctc.animate().alpha(1f).setDuration(150).start()
1222+
}
1223+
}, 2000)
12121224
}
12131225

12141226
val sButton: ImageButton = dialogBinding.shareQrText
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
~ Copyright (C) 2026 The Android Open Source Project
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:height="24dp"
18+
android:width="24dp"
19+
android:viewportHeight="24"
20+
android:viewportWidth="24">
21+
22+
<path
23+
android:fillColor="?attr/colorPrimary"
24+
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
25+
</vector>

app/src/main/res/layout/scan_result_dialog.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,19 @@
8484
android:layout_width="match_parent"
8585
android:textColor="?android:attr/textColorPrimary"/>
8686

87+
<TextView
88+
android:id="@+id/copy_confirmation"
89+
android:layout_width="match_parent"
90+
android:layout_height="wrap_content"
91+
android:layout_marginTop="12dp"
92+
android:gravity="center"
93+
android:padding="10dp"
94+
android:text="@string/copied_text_to_clipboard"
95+
android:backgroundTint="?attr/colorSecondaryContainer"
96+
android:background="@drawable/qr_result_background"
97+
android:textColor="?attr/colorOnSecondaryContainer"
98+
android:textStyle="bold"
99+
android:textSize="14sp"
100+
android:visibility="gone" />
101+
87102
</LinearLayout>

0 commit comments

Comments
 (0)