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

Use a gallery for switching channels

This commit is contained in:
Sebastian Kaspari 2010-03-05 15:56:57 +01:00
parent 5fe3e01f30
commit ebf72421cb
5 changed files with 213 additions and 132 deletions

27
res/layout/channel.xml Normal file
View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Yaaic - Yet Another Android IRC Client
Copyright 2009 Sebastian Kaspari
This file is part of Yaaic.
Yaaic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Yaaic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>

View File

@ -42,36 +42,20 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:textSize="16px"
android:layout_weight="1" />
</LinearLayout>
<ViewFlipper
android:id="@+id/channels"
<ViewSwitcher
android:id="@+id/switcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
<Gallery
android:id="@+id/deck"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="1"
android:background="#990000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="2"
android:background="#009900" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="3"
android:background="#000099" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="4"
android:background="#009999" />
</ViewFlipper>
android:layout_margin="10px"
android:spacing="5px"
android:unselectedAlpha="100"/>
</ViewSwitcher>
<!--
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
@ -92,4 +76,5 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:layout_height="wrap_content"
android:text="&gt;" />
</LinearLayout>
-->
</LinearLayout>

View File

@ -0,0 +1,110 @@
/*
Yaaic - Yet Another Android IRC Client
Copyright 2009 Sebastian Kaspari
This file is part of Yaaic.
Yaaic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Yaaic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.adapter;
import java.util.HashMap;
import java.util.LinkedList;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
/**
* The adapter for the "DeckView"
*
* @author Sebastian Kaspari <sebastian@yaaic.org>
*/
public class DeckAdapter extends BaseAdapter
{
private HashMap<String, View> map = new HashMap<String, View>();
private LinkedList<View> views = new LinkedList<View>();
/**
* Get number of item
*/
public int getCount()
{
return views.size();
}
/**
* Get item at position
*/
public View getItem(int position)
{
return views.get(position);
}
/**
* Get id of item at position
*/
public long getItemId(int position)
{
return position;
}
/**
* Add an item
*
* @param channel Name of the channel
* @param view The view object
*/
public void addItem(String channel, View view)
{
map.put(channel, view);
views.add(view);
notifyDataSetChanged();
}
/**
* Get an item by the channel's name
*
* @param channel
* @return The item
*/
public View getItemByName(String channel)
{
return map.get(channel);
}
/**
* Remove an item
*
* @param channel
*/
public void removeItem(String channel)
{
View view = map.get(channel);
views.remove(view);
map.remove(channel);
notifyDataSetChanged();
}
/**
* Get view at given position
*/
public View getView(int position, View convertView, ViewGroup parent)
{
return views.get(position);
}
}

View File

@ -1,53 +0,0 @@
package org.yaaic.listener;
import org.yaaic.R;
import android.view.MotionEvent;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;
public class FlingListener extends SimpleOnGestureListener
{
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private Animation slideLeftIn;
private Animation slideLeftOut;
private Animation slideRightIn;
private Animation slideRightOut;
private ViewFlipper flipper;
public FlingListener(ViewFlipper flipper)
{
this.flipper = flipper;
slideLeftIn = AnimationUtils.loadAnimation(flipper.getContext(), R.anim.slide_left_in);
slideLeftOut = AnimationUtils.loadAnimation(flipper.getContext(), R.anim.slide_left_out);
slideRightIn = AnimationUtils.loadAnimation(flipper.getContext(), R.anim.slide_right_in);
slideRightOut = AnimationUtils.loadAnimation(flipper.getContext(), R.anim.slide_right_out);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
return false;
}
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
flipper.setInAnimation(slideLeftIn);
flipper.setOutAnimation(slideLeftOut);
flipper.showNext();
}
else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
flipper.setInAnimation(slideRightIn);
flipper.setOutAnimation(slideRightOut);
flipper.showPrevious();
}
return false;
}
}

View File

@ -20,16 +20,6 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.view;
import org.yaaic.R;
import org.yaaic.Yaaic;
import org.yaaic.irc.IRCBinder;
import org.yaaic.irc.IRCService;
import org.yaaic.listener.ChannelListener;
import org.yaaic.listener.FlingListener;
import org.yaaic.model.Broadcast;
import org.yaaic.model.Server;
import org.yaaic.receiver.ChannelReceiver;
import android.app.Activity;
import android.app.Dialog;
import android.content.ComponentName;
@ -38,19 +28,30 @@ import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.GestureDetector;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;
import android.widget.ViewSwitcher;
import org.yaaic.R;
import org.yaaic.Yaaic;
import org.yaaic.adapter.DeckAdapter;
import org.yaaic.irc.IRCBinder;
import org.yaaic.irc.IRCService;
import org.yaaic.listener.ChannelListener;
import org.yaaic.model.Broadcast;
import org.yaaic.model.Server;
import org.yaaic.receiver.ChannelReceiver;
/**
* Connected to server
@ -59,58 +60,35 @@ import android.widget.ViewFlipper;
*/
public class ServerActivity extends Activity implements ServiceConnection, ChannelListener
{
protected static final String TextView = null;
private Server server;
private ChannelReceiver receiver;
private IRCBinder binder;
private int serverId;
public static final String TAG = "Yaaic/ServerActivity";
private GestureDetector flingDetector;
private int serverId;
private Server server;
private IRCBinder binder;
private ChannelReceiver receiver;
private ViewSwitcher switcher;
private Gallery deck;
private DeckAdapter deckAdapter;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.serverId = getIntent().getExtras().getInt("serverId");
serverId = getIntent().getExtras().getInt("serverId");
server = (Server) Yaaic.getInstance().getServerById(serverId);
setTitle("Yaaic - " + server.getTitle());
setContentView(R.layout.server);
((TextView) findViewById(R.id.title)).setText(server.getTitle());
((ImageView) findViewById(R.id.status)).setImageResource(server.getStatusIcon());
/*
((Button) findViewById(R.id.next)).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ViewFlipper vf = (ViewFlipper) v.getRootView().findViewById(R.id.channels);
vf.setInAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.slide_left_in));
vf.setOutAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.slide_left_out));
vf.showNext();
}
});
((Button) findViewById(R.id.previous)).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ViewFlipper vf = (ViewFlipper) v.getRootView().findViewById(R.id.channels);
vf.setInAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.slide_right_in));
vf.setOutAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.slide_right_out));
vf.showPrevious();
}
});
*/
flingDetector = new GestureDetector(new FlingListener((ViewFlipper) findViewById(R.id.channels)));
receiver = new ChannelReceiver(this);
registerReceiver(receiver, new IntentFilter(Broadcast.CHANNEL_MESSAGE));
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
return flingDetector.onTouchEvent(event);
deckAdapter = new DeckAdapter();
deck = (Gallery) findViewById(R.id.deck);
deck.setAdapter(deckAdapter);
switcher = (ViewSwitcher) findViewById(R.id.switcher);
}
@Override
@ -120,6 +98,11 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann
Intent intent = new Intent(this, IRCService.class);
bindService(intent, this, 0);
receiver = new ChannelReceiver(this);
registerReceiver(receiver, new IntentFilter(Broadcast.CHANNEL_MESSAGE));
registerReceiver(receiver, new IntentFilter(Broadcast.CHANNEL_NEW));
registerReceiver(receiver, new IntentFilter(Broadcast.CHANNEL_REMOVE));
}
@Override
@ -128,6 +111,7 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann
super.onPause();
unbindService(this);
unregisterReceiver(receiver);
}
public void onServiceConnected(ComponentName name, IBinder service)
@ -196,7 +180,36 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann
*/
public void onNewChannel(String target)
{
Log.d(TAG, "onNewChannel() " + target);
TextView canvas = new TextView(this);
canvas.setText(target);
canvas.setTextColor(0xff000000);
// XXX: Refactor this crap :)
Display d = getWindowManager().getDefaultDisplay();
int width = d.getWidth();
int height = d.getHeight();
float fw = (float) width;
float fh = (float) height;
float vwf = fw / 100 * 80;
float vhf = fh / 100 * 80;
int w = (int) vwf;
int h = (int) vhf;
canvas.setPadding(10, 10, 10, 10);
canvas.setBackgroundColor(0xff888888);
canvas.setLayoutParams(new Gallery.LayoutParams(w, h));
deckAdapter.addItem(target, canvas);
/*
deck.addView(child)
containers.put(target, new ChannelContainer(channel, canvas));
*/
}
/**
@ -204,6 +217,5 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann
*/
public void onRemoveChannel(String target)
{
}
}