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.setText("v_debug");
mEditHandle.setText("");
return view;
}

View file

@ -1,20 +1,27 @@
package org.sufficientlysecure.keychain.ui.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.*;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.widget.EditText;
/** */
public class HttpsPrefixedText extends EditText {
import org.sufficientlysecure.keychain.R;
private String mPrefix; // can be hardcoded for demo purposes
public class PrefixedEditText extends EditText {
private String mPrefix;
private Rect mPrefixRect = new Rect();
public HttpsPrefixedText(Context context, AttributeSet attrs) {
public PrefixedEditText(Context context, AttributeSet 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

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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_height="match_parent">
@ -37,7 +38,7 @@
android:textAppearance="?android:attr/textAppearanceMedium"
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:layout_width="match_parent"
android:layout_height="wrap_content"
@ -46,6 +47,7 @@
android:ems="10"
android:inputType="textUri"
android:layout_gravity="center_horizontal"
custom:prefix="https://"
/>
<TextView

View file

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

View file

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