diff --git a/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java b/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java index c8597e1e..11e4fcd2 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java @@ -33,7 +33,9 @@ import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; import android.widget.Button; import android.widget.EditText; +import android.widget.ImageButton; import android.widget.TextView; +import android.widget.Toast; import com.m2049r.xmrwallet.R; import com.m2049r.xmrwallet.data.BarcodeData; @@ -92,6 +94,7 @@ public class SendAddressWizardFragment extends SendWizardFragment { private View llPaymentId; private TextView tvXmrTo; private View llXmrTo; + private ImageButton bPasteAddress; private boolean resolvingOA = false; private boolean resolvingPP = false; @@ -197,6 +200,21 @@ public class SendAddressWizardFragment extends SendWizardFragment { } }); + bPasteAddress = view.findViewById(R.id.bPasteAddress); + bPasteAddress.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final String clip = Helper.getClipBoardText(getActivity()); + if (clip == null) return; + // clean it up + final String address = clip.replaceAll("[^0-9A-Z-a-z]", ""); + if (Wallet.isAddressValid(address) || BitcoinAddressValidator.validate(address)) + etAddress.getEditText().setText(address); + else + Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show(); + } + }); + etPaymentId = view.findViewById(R.id.etPaymentId); etPaymentId.getEditText().setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); etPaymentId.getEditText().setOnEditorActionListener(new TextView.OnEditorActionListener() { diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java b/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java index 968dbe10..21814a54 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java @@ -21,6 +21,7 @@ import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.ClipData; +import android.content.ClipDescription; import android.content.ClipboardManager; import android.content.Context; import android.content.DialogInterface; @@ -281,6 +282,16 @@ public class Helper { clipboardManager.setPrimaryClip(clip); } + static public String getClipBoardText(Context context) { + final ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + if (clipboardManager.hasPrimaryClip() + && clipboardManager.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { + final ClipData.Item item = clipboardManager.getPrimaryClip().getItemAt(0); + return item.getText().toString(); + } + return null; + } + static private Animation ShakeAnimation; static public Animation getShakeAnimation(Context context) { diff --git a/app/src/main/res/drawable/ic_content_paste_orange_24dp.xml b/app/src/main/res/drawable/ic_content_paste_orange_24dp.xml new file mode 100644 index 00000000..f22f482f --- /dev/null +++ b/app/src/main/res/drawable/ic_content_paste_orange_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="@color/gradientOrange" + 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" /> +</vector> diff --git a/app/src/main/res/layout/fragment_send_address.xml b/app/src/main/res/layout/fragment_send_address.xml index e1e0f2b6..b874980d 100644 --- a/app/src/main/res/layout/fragment_send_address.xml +++ b/app/src/main/res/layout/fragment_send_address.xml @@ -20,21 +20,46 @@ android:layout_width="0dp" android:layout_height="0dp" /> - <android.support.design.widget.TextInputLayout - android:id="@+id/etAddress" + <RelativeLayout + android:id="@+id/llAddress" android:layout_width="match_parent" android:layout_height="wrap_content" - app:errorEnabled="true"> + android:layout_gravity="center" + android:layout_marginBottom="4dp" + android:orientation="horizontal"> - <android.support.design.widget.TextInputEditText - style="@style/MoneroEdit" - android:layout_width="match_parent" + <android.support.design.widget.TextInputLayout + android:id="@+id/etAddress" + android:layout_width="0dp" android:layout_height="wrap_content" - android:hint="@string/send_address_hint" - android:imeOptions="actionNext" - android:inputType="textMultiLine" - android:textAlignment="textStart" /> - </android.support.design.widget.TextInputLayout> + android:layout_alignParentStart="true" + android:layout_toStartOf="@+id/bPasteAddress" + app:counterEnabled="true" + app:counterMaxLength="16" + app:errorEnabled="true"> + + <android.support.design.widget.TextInputEditText + style="@style/MoneroEdit" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_weight="10" + android:hint="@string/send_address_hint" + android:imeOptions="actionNext" + android:inputType="textMultiLine" + android:textAlignment="textStart" /> + </android.support.design.widget.TextInputLayout> + + <ImageButton + android:id="@+id/bPasteAddress" + style="@style/MoneroText.Button.Small" + android:layout_width="56dp" + android:layout_height="56dp" + android:layout_alignParentEnd="true" + android:layout_gravity="center" + android:layout_marginStart="8dp" + android:background="?android:selectableItemBackgroundBorderless" + android:src="@drawable/ic_content_paste_orange_24dp" /> + </RelativeLayout> <FrameLayout android:layout_width="match_parent"