change HttpsEditText to generic PrefixEditText

This commit is contained in:
Vincent Breitmoser 2015-04-25 03:39:40 +02:00
parent 24d407bce3
commit 608b66d192
5 changed files with 27 additions and 10 deletions

View File

@ -107,7 +107,7 @@ public class LinkedIdCreateTwitterStep1Fragment extends Fragment {
}); });
mEditHandle = (EditText) view.findViewById(R.id.linked_create_twitter_handle); mEditHandle = (EditText) view.findViewById(R.id.linked_create_twitter_handle);
mEditHandle.setText("v_debug"); mEditHandle.setText("");
return view; return view;
} }

View File

@ -1,20 +1,27 @@
package org.sufficientlysecure.keychain.ui.widget; package org.sufficientlysecure.keychain.ui.widget;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.*; import android.graphics.*;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.EditText; import android.widget.EditText;
/** */ import org.sufficientlysecure.keychain.R;
public class HttpsPrefixedText extends EditText {
private String mPrefix; // can be hardcoded for demo purposes public class PrefixedEditText extends EditText {
private String mPrefix;
private Rect mPrefixRect = new Rect(); private Rect mPrefixRect = new Rect();
public HttpsPrefixedText(Context context, AttributeSet attrs) { public PrefixedEditText(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mPrefix = "https://"; TypedArray style = context.getTheme().obtainStyledAttributes(
attrs, R.styleable.PrefixedEditText, 0, 0);
mPrefix = style.getString(R.styleable.PrefixedEditText_prefix);
if (mPrefix == null) {
mPrefix = "";
}
} }
@Override @Override

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -37,7 +38,7 @@
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/linked_create_https_1_3" /> android:text="@string/linked_create_https_1_3" />
<org.sufficientlysecure.keychain.ui.widget.HttpsPrefixedText <org.sufficientlysecure.keychain.ui.widget.PrefixedEditText
android:id="@+id/linked_create_https_uri" android:id="@+id/linked_create_https_uri"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -46,6 +47,7 @@
android:ems="10" android:ems="10"
android:inputType="textUri" android:inputType="textUri"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
custom:prefix="https://"
/> />
<TextView <TextView

View File

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent"> android:layout_height="match_parent"
>
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
@ -37,7 +39,7 @@
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/linked_create_twitter_1_3" /> android:text="@string/linked_create_twitter_1_3" />
<EditText <org.sufficientlysecure.keychain.ui.widget.PrefixedEditText
android:id="@+id/linked_create_twitter_handle" android:id="@+id/linked_create_twitter_handle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -45,7 +47,9 @@
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:ems="10" android:ems="10"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:hint="@string/linked_create_twitter_handle"/> android:hint="@string/linked_create_twitter_handle"
custom:prefix="\@"
/>
</LinearLayout> </LinearLayout>

View File

@ -29,4 +29,8 @@
<attr name="color_strong" format="color" /> <attr name="color_strong" format="color" />
</declare-styleable> </declare-styleable>
<declare-styleable name="PrefixedEditText">
<attr name="prefix" format="string" />
</declare-styleable>
</resources> </resources>