1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-21 16:35:09 -05:00

ConversationActivity: Add ViewPagerIndicator.

This commit is contained in:
Sebastian Kaspari 2012-01-21 11:30:41 +01:00
parent 706a864f44
commit 25cf7eb2ad
6 changed files with 56 additions and 127 deletions

View File

@ -23,18 +23,13 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1px"
android:color="#55ffffff" />
android:width="1dp"
android:color="#3f5d9b" />
<padding
android:left="3px"
android:top="3px"
android:right="3px"
android:bottom="3px" />
android:left="3dp"
android:top="3dp"
android:right="3dp"
android:bottom="3dp" />
<solid
android:color="#cc000000" />
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
android:color="#ff181818" />
</shape>

View File

@ -24,28 +24,11 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff181818">
<LinearLayout
android:id="@+id/status_layout"
android:orientation="horizontal"
android:background="#ff000000">
<com.viewpagerindicator.TitlePageIndicator
android:id="@+id/titleIndicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dp">
<ImageView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/disconnected"/>
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:textSize="12sp"
android:text="Server"
android:maxLines="1"
android:layout_weight="1" />
</LinearLayout>
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
@ -53,12 +36,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:layout_weight="1"
android:layout_margin="0px"
android:unselectedAlpha="100"
android:spacing="5dp"
android:padding="0dp" />
<org.yaaic.view.ConversationSwitcher
android:id="@+id/dots"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"

View File

@ -32,13 +32,10 @@ import org.yaaic.command.CommandParser;
import org.yaaic.irc.IRCBinder;
import org.yaaic.irc.IRCConnection;
import org.yaaic.irc.IRCService;
import org.yaaic.layout.NonScalingBackgroundDrawable;
import org.yaaic.listener.ConversationListener;
import org.yaaic.listener.ConversationSelectedListener;
import org.yaaic.listener.ServerListener;
import org.yaaic.listener.SpeechClickListener;
import org.yaaic.model.Broadcast;
import org.yaaic.model.Channel;
import org.yaaic.model.Conversation;
import org.yaaic.model.Extra;
import org.yaaic.model.Message;
@ -51,7 +48,6 @@ import org.yaaic.model.Status;
import org.yaaic.model.User;
import org.yaaic.receiver.ConversationReceiver;
import org.yaaic.receiver.ServerReceiver;
import org.yaaic.view.ConversationSwitcher;
import android.app.Activity;
import android.app.AlertDialog;
@ -63,12 +59,14 @@ import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.speech.RecognizerIntent;
import android.support.v4.view.ViewPager;
import android.text.InputType;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
@ -81,10 +79,10 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.viewpagerindicator.TitlePageIndicator;
/**
* The server view with a scrollable list of all channels
*
@ -109,7 +107,6 @@ public class ConversationActivity extends Activity implements ServiceConnection,
private ConversationPagerAdapter pagerAdapter;
private Scrollback scrollback;
private ConversationSwitcher dots;
// XXX: This is ugly. This is a buffer for a channel that should be joined after showing the
// JoinActivity. As onActivityResult() is called before onResume() a "channel joined"
@ -194,31 +191,17 @@ public class ConversationActivity extends Activity implements ServiceConnection,
boolean isLandscape = (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);
((TextView) findViewById(R.id.title)).setText(server.getTitle());
EditText input = (EditText) findViewById(R.id.input);
input.setOnKeyListener(inputKeyListener);
pager = (ViewPager) findViewById(R.id.pager);
dots = (ConversationSwitcher) findViewById(R.id.dots);
dots.setServer(server);
pagerAdapter = new ConversationPagerAdapter();
pagerAdapter = new ConversationPagerAdapter(server);
pager.setAdapter(pagerAdapter);
pager.setPageMargin(5);
pager.setOnPageChangeListener(
new ConversationSelectedListener(
this,
server,
(TextView) findViewById(R.id.title),
pagerAdapter,
dots
)
);
pager.setBackgroundDrawable(new NonScalingBackgroundDrawable(this, pager, R.drawable.background));
TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.titleIndicator);
indicator.setTypeface(Typeface.MONOSPACE);
indicator.setViewPager(pager);
historySize = settings.getHistorySize();
@ -228,6 +211,10 @@ public class ConversationActivity extends Activity implements ServiceConnection,
server.getConversation(ServerInfo.DEFAULT_NAME).setHistorySize(historySize);
}
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
indicator.setTextSize(settings.getFontSize() * dm.scaledDensity);
// Optimization : cache field lookups
Collection<Conversation> mConversations = server.getConversations();
@ -298,8 +285,6 @@ public class ConversationActivity extends Activity implements ServiceConnection,
}
}
((ImageView) findViewById(R.id.status)).setImageResource(server.getStatusIcon());
// Start service
Intent intent = new Intent(this, IRCService.class);
intent.setAction(IRCService.ACTION_FOREGROUND);
@ -539,10 +524,6 @@ public class ConversationActivity extends Activity implements ServiceConnection,
conversation.setStatus(status);
}
}
if (dots != null) {
dots.invalidate();
}
}
/**
@ -586,17 +567,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
@Override
public void onTopicChanged(String target)
{
String selected = server.getSelectedConversation();
if (selected.equals(target)) {
// onTopicChanged is only called for channels
Channel channel = (Channel) server.getConversation(selected);
StringBuilder sb = new StringBuilder();
sb.append(server.getTitle() + " - " + channel.getName());
if (!(channel.getTopic()).equals("")) {
sb.append(" - " + channel.getTopic());
}
((TextView) findViewById(R.id.title)).setText(sb.toString());
}
// No implementation
}
/**
@ -605,8 +576,6 @@ public class ConversationActivity extends Activity implements ServiceConnection,
@Override
public void onStatusUpdate()
{
((ImageView) findViewById(R.id.status)).setImageResource(server.getStatusIcon());
EditText input = (EditText) findViewById(R.id.input);
if (server.isConnected()) {
@ -845,7 +814,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
word = text.substring(cursor, sel_end);
} else {
// use the word at the curent cursor position
while(true) {
while (true) {
cursor -= 1;
if (cursor <= 0 || text.charAt(cursor) == ' ') {
break;
@ -938,6 +907,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
openSoftKeyboard(input);
}
});
input.requestFocus();
}

View File

@ -25,19 +25,24 @@ import java.util.LinkedList;
import org.yaaic.listener.MessageClickListener;
import org.yaaic.model.Conversation;
import org.yaaic.model.Server;
import org.yaaic.view.MessageListView;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import com.viewpagerindicator.TitlePageIndicator;
import com.viewpagerindicator.TitleProvider;
/**
* Adapter for displaying a pager of conversations.
*
* @author Sebastian Kaspari <sebastian@yaaic.org>
*/
public class ConversationPagerAdapter extends PagerAdapter
public class ConversationPagerAdapter extends PagerAdapter implements TitleProvider
{
private final Server server;
private LinkedList<ConversationInfo> conversations;
private final HashMap<Integer, View> views;
@ -59,7 +64,9 @@ public class ConversationPagerAdapter extends PagerAdapter
/**
* Create a new {@link ConversationPagerAdapter} instance.
*/
public ConversationPagerAdapter() {
public ConversationPagerAdapter(Server server) {
this.server = server;
conversations = new LinkedList<ConversationInfo>();
views = new HashMap<Integer, View>();
}
@ -254,4 +261,19 @@ public class ConversationPagerAdapter extends PagerAdapter
((ViewPager) collection).removeView((View) view);
views.remove(position);
}
/**
* Get the title for the given position. Used by the {@link TitlePageIndicator}.
*/
@Override
public String getTitle(int position)
{
Conversation conversation = getItem(position);
if (conversation.getType() == Conversation.TYPE_SERVER) {
return server.getTitle();
} else {
return conversation.getName();
}
}
}

View File

@ -20,7 +20,6 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.view;
import org.yaaic.R;
import org.yaaic.model.Settings;
import android.app.Activity;
@ -36,7 +35,7 @@ import android.widget.LinearLayout;
/**
* ConversationLayout: LinearLayout that resizes correctly when an IME
* comes up in fullscreen mode
*
*
* @author Steven Luo <steven+android@steven676.net>
*/
public class ConversationLayout extends LinearLayout
@ -50,7 +49,7 @@ public class ConversationLayout extends LinearLayout
/**
* Create a new conversation linear layout
*
*
* @param context
*/
public ConversationLayout(Context context)
@ -61,7 +60,7 @@ public class ConversationLayout extends LinearLayout
/**
* Create a new conversation linear layout
*
*
* @param context
* @param attrs
*/
@ -91,35 +90,6 @@ public class ConversationLayout extends LinearLayout
return visible.height();
}
/**
* Check if starving the gui is necessary, and starves
* Starves when less then a vertical inch is available to us
*
* @return true if we are able to check, false if not.
* @author Reynaldo Cortorreal <reyncor@gmail.com>
*/
private boolean setStarvationMode(int height)
{
if (height == 0 || 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;
}
/**
* Adjust the height of the view to avoid scrolling and hide UI components
* if necessary to save space
@ -132,17 +102,11 @@ public class ConversationLayout extends LinearLayout
int height = getWindowHeight();
if (!fullscreen) {
if (setStarvationMode(height)) {
curHeight = height;
redoLayout = true;
}
return;
}
//here to forth the code applies only to full screen
if (isLandscape && !setStarvationMode(height)) {
return;
} else if (curHeight != height && height != 0) {
if (curHeight != height && height != 0) {
curHeight = height;
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(

View File

@ -47,8 +47,8 @@ public class MessageListView extends ListView
setDivider(null);
setBackgroundResource(R.layout.rounded);
setCacheColorHint(0xee000000);
setBackgroundResource(R.layout.border);
setCacheColorHint(0xFF181818);
setVerticalFadingEdgeEnabled(false);
setScrollBarStyle(SCROLLBARS_OUTSIDE_INSET);
setTranscriptMode(TRANSCRIPT_MODE_ALWAYS_SCROLL);