Fix Android 4.0.3 display issue with hint
This commit is contained in:
parent
4672742b49
commit
bfd6a03497
2 changed files with 28 additions and 24 deletions
|
@ -9,14 +9,13 @@
|
||||||
android:id="@+id/Adress"
|
android:id="@+id/Adress"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="0.4"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:textSize="30dp"
|
|
||||||
android:background="@drawable/dialer_address_background"
|
android:background="@drawable/dialer_address_background"
|
||||||
android:inputType="textEmailAddress"
|
android:inputType="textEmailAddress"
|
||||||
android:hint="@string/addressHint"
|
android:hint="@string/addressHint"
|
||||||
android:paddingLeft="20dp"
|
android:paddingLeft="20dp"
|
||||||
android:paddingRight="20dp"
|
android:paddingRight="20dp"
|
||||||
android:layout_weight="0.4"
|
|
||||||
android:layout_gravity="center" />
|
android:layout_gravity="center" />
|
||||||
|
|
||||||
<org.linphone.ui.Numpad
|
<org.linphone.ui.Numpad
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.linphone.ui;
|
||||||
|
|
||||||
import org.linphone.DialerFragment;
|
import org.linphone.DialerFragment;
|
||||||
import org.linphone.LinphoneManager.AddressType;
|
import org.linphone.LinphoneManager.AddressType;
|
||||||
|
import org.linphone.R;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
@ -71,17 +72,21 @@ public class AddressText extends EditText implements AddressType {
|
||||||
this.displayedName = displayedName;
|
this.displayedName = displayedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getHintText() {
|
||||||
|
String resizedText = getContext().getString(R.string.addressHint);
|
||||||
|
if (getHint() != null) {
|
||||||
|
resizedText = getHint().toString();
|
||||||
|
}
|
||||||
|
return resizedText;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTextChanged(CharSequence text, int start, int before,
|
protected void onTextChanged(CharSequence text, int start, int before,
|
||||||
int after) {
|
int after) {
|
||||||
clearDisplayedName();
|
clearDisplayedName();
|
||||||
pictureUri = null;
|
pictureUri = null;
|
||||||
|
|
||||||
String resizedText = getText().toString();
|
refitText(getWidth(), getHeight());
|
||||||
if (resizedText.equals("") && getHint() != null) {
|
|
||||||
resizedText = getHint().toString();
|
|
||||||
}
|
|
||||||
refitText(resizedText, getWidth(), getHeight());
|
|
||||||
|
|
||||||
if (dialer != null) {
|
if (dialer != null) {
|
||||||
dialer.enableDisableAddContact();
|
dialer.enableDisableAddContact();
|
||||||
|
@ -93,19 +98,11 @@ public class AddressText extends EditText implements AddressType {
|
||||||
@Override
|
@Override
|
||||||
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
|
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
|
||||||
if (width != oldWidth) {
|
if (width != oldWidth) {
|
||||||
String resizedText = getText().toString();
|
refitText(getWidth(), getHeight());
|
||||||
if (resizedText.equals("") && getHint() != null) {
|
|
||||||
resizedText = getHint().toString();
|
|
||||||
}
|
|
||||||
refitText(resizedText, getWidth(), getHeight());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refitText(String text, int textWidth, int textHeight) {
|
private float getOptimizedTextSize(String text, int textWidth, int textHeight) {
|
||||||
if (textWidth <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int targetWidth = textWidth - getPaddingLeft() - getPaddingRight();
|
int targetWidth = textWidth - getPaddingLeft() - getPaddingRight();
|
||||||
int targetHeight = textHeight - getPaddingTop() - getPaddingBottom();
|
int targetHeight = textHeight - getPaddingTop() - getPaddingBottom();
|
||||||
float hi = 90;
|
float hi = 90;
|
||||||
|
@ -125,7 +122,19 @@ public class AddressText extends EditText implements AddressType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setTextSize(TypedValue.COMPLEX_UNIT_PX, lo);
|
return lo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refitText(int textWidth, int textHeight) {
|
||||||
|
if (textWidth <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float size = getOptimizedTextSize(getHintText(), textWidth, textHeight);
|
||||||
|
float entrySize = getOptimizedTextSize(getText().toString(), textWidth, textHeight);
|
||||||
|
if (entrySize < size)
|
||||||
|
size = entrySize;
|
||||||
|
setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
@ -133,11 +142,7 @@ public class AddressText extends EditText implements AddressType {
|
||||||
int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
|
int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
|
||||||
int height = getMeasuredHeight();
|
int height = getMeasuredHeight();
|
||||||
|
|
||||||
String resizedText = getText().toString();
|
refitText(parentWidth, height);
|
||||||
if (resizedText.equals("") && getHint() != null) {
|
|
||||||
resizedText = getHint().toString();
|
|
||||||
}
|
|
||||||
refitText(resizedText, parentWidth, height);
|
|
||||||
setMeasuredDimension(parentWidth, height);
|
setMeasuredDimension(parentWidth, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue