From 2e2aebf2c4b62ffda0698c9bf8aaf3c7f8936ee5 Mon Sep 17 00:00:00 2001 From: Rey Rey Date: Sat, 2 Jul 2011 18:05:46 +0200 Subject: [PATCH] Micro optimized full screen code. Made starvation mode leaner. Conflicts: application/src/org/yaaic/activity/ConversationActivity.java --- application/res/layout/conversations.xml | 1 + .../yaaic/activity/ConversationActivity.java | 15 ++-- .../org/yaaic/view/ConversationLayout.java | 77 +++++++++++++------ .../src/org/yaaic/view/MessageListView.java | 8 +- 4 files changed, 65 insertions(+), 36 deletions(-) diff --git a/application/res/layout/conversations.xml b/application/res/layout/conversations.xml index fea7b56..73bc732 100644 --- a/application/res/layout/conversations.xml +++ b/application/res/layout/conversations.xml @@ -26,6 +26,7 @@ along with Yaaic. If not, see . android:layout_height="fill_parent" android:background="#ff181818"> + */ + private boolean setStarvationMode(int height) + { + if (height == 0) { + return false; + } else if (height == curHeight){ + return false; + } + + LinearLayout status = (LinearLayout) findViewById(R.id.status_layout); + ConversationSwitcher dots = (ConversationSwitcher) findViewById(R.id.dots); + + float scale = getResources().getDisplayMetrics().density; + + //Give us at least an inch, or we'll have to make sacrifices. + if (height < 160*scale) { + status.setVisibility(GONE); + dots.setVisibility(GONE); + } else { + status.setVisibility(VISIBLE); + dots.setVisibility(VISIBLE); + } + return true; + } + /** * onMeasure (ask the view how much space it wants) * This is called when the window size changes, so we can hook into it to * resize ourselves when the IME comes up * @author Steven Luo - * @author Reynaldo Cortorreal */ @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - - if(!fullscreen && !isLandscape){ - return; - } int height = getWindowHeight(); - if (curHeight != height) { - curHeight = height; - status = (ImageView) findViewById(R.id.status); - title = (TextView) findViewById(R.id.title); - final float scale = getResources().getDisplayMetrics().density; - - //Give us at least an inch, or we'll have to make sacrifices. - if (height < 160*scale) { - status.setVisibility(GONE); - title.setVisibility(GONE); - } else if (status.getVisibility() == GONE || title.getVisibility() == GONE){ - status.setVisibility(VISIBLE); - title.setVisibility(VISIBLE); + if(!fullscreen) { + if (setStarvationMode(height)){ + curHeight = height; + redoLayout = true; + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + return; + } else { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + return; } + } + + //here to forth the code applies only to full screen + if (isLandscape && !setStarvationMode(height)) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + return; + } else if (curHeight != height && height != 0) { + curHeight = height; FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.FILL_PARENT, @@ -135,7 +161,10 @@ public class ConversationLayout extends LinearLayout params.gravity = Gravity.BOTTOM | Gravity.CLIP_VERTICAL; setLayoutParams(params); redoLayout = true; + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + return; } + super.onMeasure(widthMeasureSpec, heightMeasureSpec); } /** diff --git a/application/src/org/yaaic/view/MessageListView.java b/application/src/org/yaaic/view/MessageListView.java index ff1f6d4..40c395f 100644 --- a/application/src/org/yaaic/view/MessageListView.java +++ b/application/src/org/yaaic/view/MessageListView.java @@ -42,8 +42,8 @@ public class MessageListView extends ListView private final View parent; private int parentWidth; private int parentHeight; - private int padding; - private int paddingWide; + private final int padding; + private final int paddingWide; /** * Create a new MessageListView @@ -139,11 +139,11 @@ public class MessageListView extends ListView if (switched) { setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.FILL_PARENT, Gallery.LayoutParams.FILL_PARENT)); setTranscriptMode(TRANSCRIPT_MODE_NORMAL); - setPadding(paddingWide, padding, paddingWide, padding); + setPadding(paddingWide, padding, paddingWide, 0); } else { setLayoutParams(new Gallery.LayoutParams(parentWidth*85/100, parentHeight)); setTranscriptMode(TRANSCRIPT_MODE_ALWAYS_SCROLL); - setPadding(padding, padding, padding, padding); + setPadding(padding, padding, padding, 0); } } }