1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-22 17:02:21 -05:00

Micro optimized full screen code. Made starvation mode leaner.

Conflicts:

	application/src/org/yaaic/activity/ConversationActivity.java
This commit is contained in:
Rey Rey 2011-07-02 18:05:46 +02:00 committed by Sebastian Kaspari
parent 5c48724425
commit 2e2aebf2c4
4 changed files with 65 additions and 36 deletions

View File

@ -26,6 +26,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="#ff181818"> android:background="#ff181818">
<LinearLayout <LinearLayout
android:id="@+id/status_layout"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -252,16 +252,15 @@ public class ConversationActivity extends Activity implements ServiceConnection,
if (settings.autoCapSentences()) { if (settings.autoCapSentences()) {
setInputTypeFlags |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; setInputTypeFlags |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
} }
if (isLandscape && !settings.imeExtract()) {
/* Replace the Enter key with a smiley instead of Send, to make it if (isLandscape && settings.imeExtract()) {
more difficult to accidentally hit send
We'd like to do this in portrait too, but wouldn't have a Send
button in that case */
setInputTypeFlags |= InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE; setInputTypeFlags |= InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE;
input.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
} else {
input.setImeOptions(input.getImeOptions() & EditorInfo.IME_FLAG_NO_EXTRACT_UI);
} }
if (!settings.imeExtract()) {
input.setImeOptions(input.getImeOptions() | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
}
input.setInputType(input.getInputType() | setInputTypeFlags); input.setInputType(input.getInputType() | setInputTypeFlags);
// Create a new scrollback history // Create a new scrollback history

View File

@ -32,9 +32,7 @@ import android.util.AttributeSet;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
/** /**
* ConversationLayout: LinearLayout that resizes correctly when an IME * ConversationLayout: LinearLayout that resizes correctly when an IME
@ -45,10 +43,10 @@ import android.widget.TextView;
public class ConversationLayout extends LinearLayout public class ConversationLayout extends LinearLayout
{ {
private Activity activity; private Activity activity;
private TextView title;
private ImageView status;
int curHeight = 0; int curHeight = 0;
boolean fullscreen = false, isLandscape = false; boolean fullscreen = false;
boolean isLandscape = false;
boolean redoLayout = false; boolean redoLayout = false;
/** /**
@ -95,37 +93,65 @@ public class ConversationLayout extends LinearLayout
} }
/** /**
* onMeasure (ask the view how much space it wants) * Check if starving the gui is necessary, and starves
* This is called when the window size changes, so we can hook into it to * Starves when less then a vertical inch is available to us
* resize ourselves when the IME comes up * @return true if we are able to check, false if not.
* @author Steven Luo <stevenandroid@steven676.net>
* @author Reynaldo Cortorreal <reyncor@gmail.com> * @author Reynaldo Cortorreal <reyncor@gmail.com>
*/ */
@Override private boolean setStarvationMode(int height)
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{ {
super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (height == 0) {
return false;
if(!fullscreen && !isLandscape){ } else if (height == curHeight){
return; return false;
} }
int height = getWindowHeight(); LinearLayout status = (LinearLayout) findViewById(R.id.status_layout);
if (curHeight != height) { ConversationSwitcher dots = (ConversationSwitcher) findViewById(R.id.dots);
curHeight = height;
status = (ImageView) findViewById(R.id.status); float scale = getResources().getDisplayMetrics().density;
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. //Give us at least an inch, or we'll have to make sacrifices.
if (height < 160*scale) { if (height < 160*scale) {
status.setVisibility(GONE); status.setVisibility(GONE);
title.setVisibility(GONE); dots.setVisibility(GONE);
} else if (status.getVisibility() == GONE || title.getVisibility() == GONE){ } else {
status.setVisibility(VISIBLE); status.setVisibility(VISIBLE);
title.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 <stevenandroid@steven676.net>
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int height = getWindowHeight();
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 params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT,
@ -135,7 +161,10 @@ public class ConversationLayout extends LinearLayout
params.gravity = Gravity.BOTTOM | Gravity.CLIP_VERTICAL; params.gravity = Gravity.BOTTOM | Gravity.CLIP_VERTICAL;
setLayoutParams(params); setLayoutParams(params);
redoLayout = true; redoLayout = true;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
return;
} }
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
} }
/** /**

View File

@ -42,8 +42,8 @@ public class MessageListView extends ListView
private final View parent; private final View parent;
private int parentWidth; private int parentWidth;
private int parentHeight; private int parentHeight;
private int padding; private final int padding;
private int paddingWide; private final int paddingWide;
/** /**
* Create a new MessageListView * Create a new MessageListView
@ -139,11 +139,11 @@ public class MessageListView extends ListView
if (switched) { if (switched) {
setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.FILL_PARENT, Gallery.LayoutParams.FILL_PARENT)); setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.FILL_PARENT, Gallery.LayoutParams.FILL_PARENT));
setTranscriptMode(TRANSCRIPT_MODE_NORMAL); setTranscriptMode(TRANSCRIPT_MODE_NORMAL);
setPadding(paddingWide, padding, paddingWide, padding); setPadding(paddingWide, padding, paddingWide, 0);
} else { } else {
setLayoutParams(new Gallery.LayoutParams(parentWidth*85/100, parentHeight)); setLayoutParams(new Gallery.LayoutParams(parentWidth*85/100, parentHeight));
setTranscriptMode(TRANSCRIPT_MODE_ALWAYS_SCROLL); setTranscriptMode(TRANSCRIPT_MODE_ALWAYS_SCROLL);
setPadding(padding, padding, padding, padding); setPadding(padding, padding, padding, 0);
} }
} }
} }