Skip to content

Commit 830d9da

Browse files
authored
paste receiver address (#592)
1 parent 331d88e commit 830d9da

File tree

4 files changed

+74
-11
lines changed

4 files changed

+74
-11
lines changed

app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
import android.view.inputmethod.EditorInfo;
3434
import android.widget.Button;
3535
import android.widget.EditText;
36+
import android.widget.ImageButton;
3637
import android.widget.TextView;
38+
import android.widget.Toast;
3739

3840
import com.m2049r.xmrwallet.R;
3941
import com.m2049r.xmrwallet.data.BarcodeData;
@@ -92,6 +94,7 @@ public interface Listener {
9294
private View llPaymentId;
9395
private TextView tvXmrTo;
9496
private View llXmrTo;
97+
private ImageButton bPasteAddress;
9598

9699
private boolean resolvingOA = false;
97100
private boolean resolvingPP = false;
@@ -197,6 +200,21 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
197200
}
198201
});
199202

203+
bPasteAddress = view.findViewById(R.id.bPasteAddress);
204+
bPasteAddress.setOnClickListener(new View.OnClickListener() {
205+
@Override
206+
public void onClick(View v) {
207+
final String clip = Helper.getClipBoardText(getActivity());
208+
if (clip == null) return;
209+
// clean it up
210+
final String address = clip.replaceAll("[^0-9A-Z-a-z]", "");
211+
if (Wallet.isAddressValid(address) || BitcoinAddressValidator.validate(address))
212+
etAddress.getEditText().setText(address);
213+
else
214+
Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show();
215+
}
216+
});
217+
200218
etPaymentId = view.findViewById(R.id.etPaymentId);
201219
etPaymentId.getEditText().setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
202220
etPaymentId.getEditText().setOnEditorActionListener(new TextView.OnEditorActionListener() {

app/src/main/java/com/m2049r/xmrwallet/util/Helper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.app.AlertDialog;
2222
import android.app.Dialog;
2323
import android.content.ClipData;
24+
import android.content.ClipDescription;
2425
import android.content.ClipboardManager;
2526
import android.content.Context;
2627
import android.content.DialogInterface;
@@ -281,6 +282,16 @@ static public void clipBoardCopy(Context context, String label, String text) {
281282
clipboardManager.setPrimaryClip(clip);
282283
}
283284

285+
static public String getClipBoardText(Context context) {
286+
final ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
287+
if (clipboardManager.hasPrimaryClip()
288+
&& clipboardManager.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
289+
final ClipData.Item item = clipboardManager.getPrimaryClip().getItemAt(0);
290+
return item.getText().toString();
291+
}
292+
return null;
293+
}
294+
284295
static private Animation ShakeAnimation;
285296

286297
static public Animation getShakeAnimation(Context context) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="@color/gradientOrange"
8+
android:pathData="M19,2h-4.18C14.4,0.84 13.3,0 12,0c-1.3,0 -2.4,0.84 -2.82,2L5,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM12,2c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM19,20L5,20L5,4h2v3h10L17,4h2v16z" />
9+
</vector>

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

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,46 @@
2020
android:layout_width="0dp"
2121
android:layout_height="0dp" />
2222

23-
<android.support.design.widget.TextInputLayout
24-
android:id="@+id/etAddress"
23+
<RelativeLayout
24+
android:id="@+id/llAddress"
2525
android:layout_width="match_parent"
2626
android:layout_height="wrap_content"
27-
app:errorEnabled="true">
27+
android:layout_gravity="center"
28+
android:layout_marginBottom="4dp"
29+
android:orientation="horizontal">
2830

29-
<android.support.design.widget.TextInputEditText
30-
style="@style/MoneroEdit"
31-
android:layout_width="match_parent"
31+
<android.support.design.widget.TextInputLayout
32+
android:id="@+id/etAddress"
33+
android:layout_width="0dp"
3234
android:layout_height="wrap_content"
33-
android:hint="@string/send_address_hint"
34-
android:imeOptions="actionNext"
35-
android:inputType="textMultiLine"
36-
android:textAlignment="textStart" />
37-
</android.support.design.widget.TextInputLayout>
35+
android:layout_alignParentStart="true"
36+
android:layout_toStartOf="@+id/bPasteAddress"
37+
app:counterEnabled="true"
38+
app:counterMaxLength="16"
39+
app:errorEnabled="true">
40+
41+
<android.support.design.widget.TextInputEditText
42+
style="@style/MoneroEdit"
43+
android:layout_width="match_parent"
44+
android:layout_height="wrap_content"
45+
android:layout_weight="10"
46+
android:hint="@string/send_address_hint"
47+
android:imeOptions="actionNext"
48+
android:inputType="textMultiLine"
49+
android:textAlignment="textStart" />
50+
</android.support.design.widget.TextInputLayout>
51+
52+
<ImageButton
53+
android:id="@+id/bPasteAddress"
54+
style="@style/MoneroText.Button.Small"
55+
android:layout_width="56dp"
56+
android:layout_height="56dp"
57+
android:layout_alignParentEnd="true"
58+
android:layout_gravity="center"
59+
android:layout_marginStart="8dp"
60+
android:background="?android:selectableItemBackgroundBorderless"
61+
android:src="@drawable/ic_content_paste_orange_24dp" />
62+
</RelativeLayout>
3863

3964
<FrameLayout
4065
android:layout_width="match_parent"

0 commit comments

Comments
 (0)