summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMindy Pereira <mindyp@google.com>2011-09-16 15:42:09 -0700
committerMindy Pereira <mindyp@google.com>2011-09-19 10:03:01 -0700
commit22b680b63446e2b50f0f5e7d5307c7198387cebf (patch)
treef106158d1bff5ac2326ba46c4b0491e183af33d7
parenta9c5969299cf942278391a569bb6fdd1c4a8bb6b (diff)
downloadandroid_frameworks_ex-22b680b63446e2b50f0f5e7d5307c7198387cebf.tar.gz
android_frameworks_ex-22b680b63446e2b50f0f5e7d5307c7198387cebf.tar.bz2
android_frameworks_ex-22b680b63446e2b50f0f5e7d5307c7198387cebf.zip
Make sure we get the correct more chip on orientation changes.
Fixes bug:5334556 Turning device orientation to landscape is deleting recipient from compose mail. Change-Id: I5b96c7288ef84bc9585d8a553106bdc044c55b61
-rw-r--r--chips/src/com/android/ex/chips/RecipientEditTextView.java37
1 files changed, 30 insertions, 7 deletions
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java
index 3da731f..25fab2d 100644
--- a/chips/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java
@@ -33,6 +33,7 @@ import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
+import android.os.Parcelable;
import android.text.Editable;
import android.text.InputType;
import android.text.Layout;
@@ -259,6 +260,15 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
super.onSelectionChanged(start, end);
}
+ @Override
+ public void onRestoreInstanceState(Parcelable state) {
+ if (!TextUtils.isEmpty(getText())) {
+ super.onRestoreInstanceState(null);
+ } else {
+ super.onRestoreInstanceState(state);
+ }
+ }
+
/**
* Convenience method: Append the specified text slice to the TextView's
* display buffer, upgrading it to BufferType.EDITABLE if it was
@@ -609,7 +619,6 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
return;
}
synchronized (mPendingChips) {
- mTemporaryRecipients = new ArrayList<RecipientChip>(mPendingChipsCount);
Editable editable = getText();
// Tokenize!
for (int i = 0; i < mPendingChips.size(); i++) {
@@ -628,7 +637,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
mPendingChipsCount--;
}
sanitizeSpannable();
- if (mTemporaryRecipients != null
+ if (mTemporaryRecipients != null && mTemporaryRecipients.size() > 0
&& mTemporaryRecipients.size() <= RecipientAlternatesAdapter.MAX_LOOKUPS) {
if (hasFocus() || mTemporaryRecipients.size() < CHIP_LIMIT) {
new RecipientReplacementTask().execute();
@@ -643,8 +652,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
}
} else {
// There are too many recipients to look up, so just fall back
- // to
- // showing addresses for all of them.
+ // to showing addresses for all of them.
mTemporaryRecipients = null;
createMoreChip();
}
@@ -662,6 +670,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
if (chips != null && chips.length > 0) {
int end;
ImageSpan lastSpan;
+ mMoreChip = getMoreChip();
if (mMoreChip != null) {
lastSpan = mMoreChip;
} else {
@@ -712,10 +721,12 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
} catch (NullPointerException e) {
Log.e(TAG, e.getMessage(), e);
}
-
editable.replace(tokenStart, tokenEnd, chipText);
// Add this chip to the list of entries "to replace"
if (chip != null) {
+ if (mTemporaryRecipients == null) {
+ mTemporaryRecipients = new ArrayList<RecipientChip>();
+ }
chip.setOriginalText(chipText.toString());
mTemporaryRecipients.add(chip);
}
@@ -1319,6 +1330,13 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
return false;
}
+
+ private ImageSpan getMoreChip() {
+ MoreImageSpan[] moreSpans = getSpannable().getSpans(0, getText().length(),
+ MoreImageSpan.class);
+ return moreSpans != null && moreSpans.length > 0 ? moreSpans[0] : null;
+ }
+
/**
* Create the more chip. The more chip is text that replaces any chips that
* do not fit in the pre-defined available space when the
@@ -1350,8 +1368,12 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
int height = getLineHeight();
Bitmap drawable = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(drawable);
- canvas.drawText(moreText, 0, moreText.length(), 0, height - getLayout().getLineDescent(0),
- morePaint);
+ int adjustedHeight = height;
+ Layout layout = getLayout();
+ if (layout != null) {
+ adjustedHeight -= layout.getLineDescent(0);
+ }
+ canvas.drawText(moreText, 0, moreText.length(), 0, adjustedHeight, morePaint);
Drawable result = new BitmapDrawable(getResources(), drawable);
result.setBounds(0, 0, width, height);
@@ -1739,6 +1761,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ // Do nothing.
}
}