Skip to content

Commit

Permalink
paste receiver address (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2049r authored May 20, 2019
1 parent 331d88e commit 830d9da
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
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;
Expand Down Expand Up @@ -92,6 +94,7 @@ public interface Listener {
private View llPaymentId;
private TextView tvXmrTo;
private View llXmrTo;
private ImageButton bPasteAddress;

private boolean resolvingOA = false;
private boolean resolvingPP = false;
Expand Down Expand Up @@ -197,6 +200,21 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});

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() {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/m2049r/xmrwallet/util/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -281,6 +282,16 @@ static public void clipBoardCopy(Context context, String label, String text) {
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) {
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_content_paste_orange_24dp.xml
Original file line number Diff line number Diff line change
@@ -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>
47 changes: 36 additions & 11 deletions app/src/main/res/layout/fragment_send_address.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 830d9da

Please sign in to comment.