1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-25 02:12:16 -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" xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> android:shape="rectangle">
<stroke <stroke
android:width="1px" android:width="1dp"
android:color="#55ffffff" /> android:color="#3f5d9b" />
<padding <padding
android:left="3px" android:left="3dp"
android:top="3px" android:top="3dp"
android:right="3px" android:right="3dp"
android:bottom="3px" /> android:bottom="3dp" />
<solid <solid
android:color="#cc000000" /> android:color="#ff181818" />
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
</shape> </shape>

View File

@ -24,28 +24,11 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:orientation="vertical" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="#ff181818"> android:background="#ff000000">
<LinearLayout <com.viewpagerindicator.TitlePageIndicator
android:id="@+id/status_layout" android:id="@+id/titleIndicator"
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" 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.support.v4.view.ViewPager <android.support.v4.view.ViewPager
android:id="@+id/pager" android:id="@+id/pager"
android:layout_width="fill_parent" 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_weight="1"
android:layout_margin="0px" android:layout_margin="0px"
android:unselectedAlpha="100" android:unselectedAlpha="100"
android:spacing="5dp"
android:padding="0dp" /> android:padding="0dp" />
<org.yaaic.view.ConversationSwitcher
android:id="@+id/dots"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" 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.IRCBinder;
import org.yaaic.irc.IRCConnection; import org.yaaic.irc.IRCConnection;
import org.yaaic.irc.IRCService; import org.yaaic.irc.IRCService;
import org.yaaic.layout.NonScalingBackgroundDrawable;
import org.yaaic.listener.ConversationListener; import org.yaaic.listener.ConversationListener;
import org.yaaic.listener.ConversationSelectedListener;
import org.yaaic.listener.ServerListener; import org.yaaic.listener.ServerListener;
import org.yaaic.listener.SpeechClickListener; import org.yaaic.listener.SpeechClickListener;
import org.yaaic.model.Broadcast; import org.yaaic.model.Broadcast;
import org.yaaic.model.Channel;
import org.yaaic.model.Conversation; import org.yaaic.model.Conversation;
import org.yaaic.model.Extra; import org.yaaic.model.Extra;
import org.yaaic.model.Message; import org.yaaic.model.Message;
@ -51,7 +48,6 @@ import org.yaaic.model.Status;
import org.yaaic.model.User; import org.yaaic.model.User;
import org.yaaic.receiver.ConversationReceiver; import org.yaaic.receiver.ConversationReceiver;
import org.yaaic.receiver.ServerReceiver; import org.yaaic.receiver.ServerReceiver;
import org.yaaic.view.ConversationSwitcher;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -63,12 +59,14 @@ import android.content.ServiceConnection;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.speech.RecognizerIntent; import android.speech.RecognizerIntent;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.text.InputType; import android.text.InputType;
import android.util.DisplayMetrics;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -81,10 +79,10 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.viewpagerindicator.TitlePageIndicator;
/** /**
* The server view with a scrollable list of all channels * 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 ConversationPagerAdapter pagerAdapter;
private Scrollback scrollback; private Scrollback scrollback;
private ConversationSwitcher dots;
// XXX: This is ugly. This is a buffer for a channel that should be joined after showing the // 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" // 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); boolean isLandscape = (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);
((TextView) findViewById(R.id.title)).setText(server.getTitle());
EditText input = (EditText) findViewById(R.id.input); EditText input = (EditText) findViewById(R.id.input);
input.setOnKeyListener(inputKeyListener); input.setOnKeyListener(inputKeyListener);
pager = (ViewPager) findViewById(R.id.pager); pager = (ViewPager) findViewById(R.id.pager);
dots = (ConversationSwitcher) findViewById(R.id.dots); pagerAdapter = new ConversationPagerAdapter(server);
dots.setServer(server);
pagerAdapter = new ConversationPagerAdapter();
pager.setAdapter(pagerAdapter); pager.setAdapter(pagerAdapter);
pager.setPageMargin(5);
pager.setOnPageChangeListener( TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.titleIndicator);
new ConversationSelectedListener( indicator.setTypeface(Typeface.MONOSPACE);
this, indicator.setViewPager(pager);
server,
(TextView) findViewById(R.id.title),
pagerAdapter,
dots
)
);
pager.setBackgroundDrawable(new NonScalingBackgroundDrawable(this, pager, R.drawable.background));
historySize = settings.getHistorySize(); historySize = settings.getHistorySize();
@ -228,6 +211,10 @@ public class ConversationActivity extends Activity implements ServiceConnection,
server.getConversation(ServerInfo.DEFAULT_NAME).setHistorySize(historySize); 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 // Optimization : cache field lookups
Collection<Conversation> mConversations = server.getConversations(); 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 // Start service
Intent intent = new Intent(this, IRCService.class); Intent intent = new Intent(this, IRCService.class);
intent.setAction(IRCService.ACTION_FOREGROUND); intent.setAction(IRCService.ACTION_FOREGROUND);
@ -539,10 +524,6 @@ public class ConversationActivity extends Activity implements ServiceConnection,
conversation.setStatus(status); conversation.setStatus(status);
} }
} }
if (dots != null) {
dots.invalidate();
}
} }
/** /**
@ -586,17 +567,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
@Override @Override
public void onTopicChanged(String target) public void onTopicChanged(String target)
{ {
String selected = server.getSelectedConversation(); // No implementation
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());
}
} }
/** /**
@ -605,8 +576,6 @@ public class ConversationActivity extends Activity implements ServiceConnection,
@Override @Override
public void onStatusUpdate() public void onStatusUpdate()
{ {
((ImageView) findViewById(R.id.status)).setImageResource(server.getStatusIcon());
EditText input = (EditText) findViewById(R.id.input); EditText input = (EditText) findViewById(R.id.input);
if (server.isConnected()) { if (server.isConnected()) {
@ -845,7 +814,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
word = text.substring(cursor, sel_end); word = text.substring(cursor, sel_end);
} else { } else {
// use the word at the curent cursor position // use the word at the curent cursor position
while(true) { while (true) {
cursor -= 1; cursor -= 1;
if (cursor <= 0 || text.charAt(cursor) == ' ') { if (cursor <= 0 || text.charAt(cursor) == ' ') {
break; break;
@ -938,6 +907,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
openSoftKeyboard(input); openSoftKeyboard(input);
} }
}); });
input.requestFocus(); input.requestFocus();
} }

View File

@ -25,19 +25,24 @@ import java.util.LinkedList;
import org.yaaic.listener.MessageClickListener; import org.yaaic.listener.MessageClickListener;
import org.yaaic.model.Conversation; import org.yaaic.model.Conversation;
import org.yaaic.model.Server;
import org.yaaic.view.MessageListView; import org.yaaic.view.MessageListView;
import android.support.v4.view.PagerAdapter; import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.view.View; import android.view.View;
import com.viewpagerindicator.TitlePageIndicator;
import com.viewpagerindicator.TitleProvider;
/** /**
* Adapter for displaying a pager of conversations. * Adapter for displaying a pager of conversations.
* *
* @author Sebastian Kaspari <sebastian@yaaic.org> * @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 LinkedList<ConversationInfo> conversations;
private final HashMap<Integer, View> views; private final HashMap<Integer, View> views;
@ -59,7 +64,9 @@ public class ConversationPagerAdapter extends PagerAdapter
/** /**
* Create a new {@link ConversationPagerAdapter} instance. * Create a new {@link ConversationPagerAdapter} instance.
*/ */
public ConversationPagerAdapter() { public ConversationPagerAdapter(Server server) {
this.server = server;
conversations = new LinkedList<ConversationInfo>(); conversations = new LinkedList<ConversationInfo>();
views = new HashMap<Integer, View>(); views = new HashMap<Integer, View>();
} }
@ -254,4 +261,19 @@ public class ConversationPagerAdapter extends PagerAdapter
((ViewPager) collection).removeView((View) view); ((ViewPager) collection).removeView((View) view);
views.remove(position); 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; package org.yaaic.view;
import org.yaaic.R;
import org.yaaic.model.Settings; import org.yaaic.model.Settings;
import android.app.Activity; import android.app.Activity;
@ -91,35 +90,6 @@ public class ConversationLayout extends LinearLayout
return visible.height(); 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 * Adjust the height of the view to avoid scrolling and hide UI components
* if necessary to save space * if necessary to save space
@ -132,17 +102,11 @@ public class ConversationLayout extends LinearLayout
int height = getWindowHeight(); int height = getWindowHeight();
if (!fullscreen) { if (!fullscreen) {
if (setStarvationMode(height)) {
curHeight = height;
redoLayout = true;
}
return; return;
} }
//here to forth the code applies only to full screen //here to forth the code applies only to full screen
if (isLandscape && !setStarvationMode(height)) { if (curHeight != height && height != 0) {
return;
} else if (curHeight != height && height != 0) {
curHeight = height; curHeight = height;
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(

View File

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