am 8d454af4: am 87f06033: am d900b90d: Merge "Prep for RAM footprint optimization for Emoji palettes"

* commit '8d454af44bb000ccbbcc2e00b15856e680017596':
  Prep for RAM footprint optimization for Emoji palettes
main
Ken Wakasa 2013-10-09 21:26:33 -07:00 committed by Android Git Automerger
commit 86c6aff4aa
3 changed files with 15 additions and 10 deletions

View File

@ -459,6 +459,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
mEmojiPager.setAdapter(mEmojiPalettesAdapter); mEmojiPager.setAdapter(mEmojiPalettesAdapter);
mEmojiPager.setOnPageChangeListener(this); mEmojiPager.setOnPageChangeListener(this);
mEmojiPager.setOffscreenPageLimit(0); mEmojiPager.setOffscreenPageLimit(0);
mEmojiPager.setPersistentDrawingCache(ViewPager.PERSISTENT_NO_CACHE);
final Resources res = getResources(); final Resources res = getResources();
final EmojiLayoutParams emojiLp = new EmojiLayoutParams(res); final EmojiLayoutParams emojiLp = new EmojiLayoutParams(res);
emojiLp.setPagerProperties(mEmojiPager); emojiLp.setPagerProperties(mEmojiPager);
@ -607,7 +608,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
private static class EmojiPalettesAdapter extends PagerAdapter { private static class EmojiPalettesAdapter extends PagerAdapter {
private final ScrollKeyboardView.OnKeyClickListener mListener; private final ScrollKeyboardView.OnKeyClickListener mListener;
private final DynamicGridKeyboard mRecentsKeyboard; private final DynamicGridKeyboard mRecentsKeyboard;
private final SparseArray<ScrollKeyboardView> mActiveKeyboardView = private final SparseArray<ScrollKeyboardView> mActiveKeyboardViews =
CollectionUtils.newSparseArray(); CollectionUtils.newSparseArray();
private final EmojiCategory mEmojiCategory; private final EmojiCategory mEmojiCategory;
private int mActivePosition = 0; private int mActivePosition = 0;
@ -623,7 +624,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
public void flushPendingRecentKeys() { public void flushPendingRecentKeys() {
mRecentsKeyboard.flushPendingRecentKeys(); mRecentsKeyboard.flushPendingRecentKeys();
final KeyboardView recentKeyboardView = final KeyboardView recentKeyboardView =
mActiveKeyboardView.get(mEmojiCategory.getRecentTabId()); mActiveKeyboardViews.get(mEmojiCategory.getRecentTabId());
if (recentKeyboardView != null) { if (recentKeyboardView != null) {
recentKeyboardView.invalidateAllKeys(); recentKeyboardView.invalidateAllKeys();
} }
@ -636,7 +637,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
} }
mRecentsKeyboard.addKeyFirst(key); mRecentsKeyboard.addKeyFirst(key);
final KeyboardView recentKeyboardView = final KeyboardView recentKeyboardView =
mActiveKeyboardView.get(mEmojiCategory.getRecentTabId()); mActiveKeyboardViews.get(mEmojiCategory.getRecentTabId());
if (recentKeyboardView != null) { if (recentKeyboardView != null) {
recentKeyboardView.invalidateAllKeys(); recentKeyboardView.invalidateAllKeys();
} }
@ -652,7 +653,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
if (mActivePosition == position) { if (mActivePosition == position) {
return; return;
} }
final ScrollKeyboardView oldKeyboardView = mActiveKeyboardView.get(mActivePosition); final ScrollKeyboardView oldKeyboardView = mActiveKeyboardViews.get(mActivePosition);
if (oldKeyboardView != null) { if (oldKeyboardView != null) {
oldKeyboardView.releaseCurrentKey(); oldKeyboardView.releaseCurrentKey();
oldKeyboardView.deallocateMemory(); oldKeyboardView.deallocateMemory();
@ -662,11 +663,11 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
@Override @Override
public Object instantiateItem(final ViewGroup container, final int position) { public Object instantiateItem(final ViewGroup container, final int position) {
final ScrollKeyboardView oldKeyboardView = mActiveKeyboardView.get(position); final ScrollKeyboardView oldKeyboardView = mActiveKeyboardViews.get(position);
if (oldKeyboardView != null) { if (oldKeyboardView != null) {
oldKeyboardView.deallocateMemory(); oldKeyboardView.deallocateMemory();
// This may be redundant but wanted to be safer.. // This may be redundant but wanted to be safer..
mActiveKeyboardView.remove(position); mActiveKeyboardViews.remove(position);
} }
final Keyboard keyboard = final Keyboard keyboard =
mEmojiCategory.getKeyboardFromPagePosition(position); mEmojiCategory.getKeyboardFromPagePosition(position);
@ -681,7 +682,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
R.id.emoji_keyboard_scroller); R.id.emoji_keyboard_scroller);
keyboardView.setScrollView(scrollView); keyboardView.setScrollView(scrollView);
container.addView(view); container.addView(view);
mActiveKeyboardView.put(position, keyboardView); mActiveKeyboardViews.put(position, keyboardView);
return view; return view;
} }
@ -693,12 +694,13 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
@Override @Override
public void destroyItem(final ViewGroup container, final int position, public void destroyItem(final ViewGroup container, final int position,
final Object object) { final Object object) {
final ScrollKeyboardView keyboardView = mActiveKeyboardView.get(position); ScrollKeyboardView keyboardView = mActiveKeyboardViews.get(position);
if (keyboardView != null) { if (keyboardView != null) {
keyboardView.deallocateMemory(); keyboardView.deallocateMemory();
mActiveKeyboardView.remove(position); mActiveKeyboardViews.remove(position);
} }
container.removeView(keyboardView); container.removeView(keyboardView);
keyboardView = null;
} }
} }

View File

@ -243,6 +243,8 @@ public class KeyboardView extends View {
} }
private void freeOffscreenBuffer() { private void freeOffscreenBuffer() {
mOffscreenCanvas.setBitmap(null);
mOffscreenCanvas.setMatrix(null);
if (mOffscreenBuffer != null) { if (mOffscreenBuffer != null) {
mOffscreenBuffer.recycle(); mOffscreenBuffer.recycle();
mOffscreenBuffer = null; mOffscreenBuffer = null;

View File

@ -30,8 +30,9 @@ import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
/** /**
* This is an extended {@link KeyboardView} class that hosts a scroll keyboard. * This is an extended {@link KeyboardView} class that hosts a vertical scroll keyboard.
* Multi-touch unsupported. No {@link PointerTracker}s. No gesture support. * Multi-touch unsupported. No {@link PointerTracker}s. No gesture support.
* TODO: Vertical scroll capability should be removed from this class because it's no longer used.
*/ */
// TODO: Implement key popup preview. // TODO: Implement key popup preview.
public final class ScrollKeyboardView extends KeyboardView implements public final class ScrollKeyboardView extends KeyboardView implements