2009-12-17 15:27:57 -05:00
|
|
|
/*
|
|
|
|
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.view;
|
|
|
|
|
|
|
|
import org.yaaic.R;
|
|
|
|
import org.yaaic.Yaaic;
|
|
|
|
import org.yaaic.irc.IRCBinder;
|
|
|
|
import org.yaaic.irc.IRCService;
|
2010-03-02 14:18:44 -05:00
|
|
|
import org.yaaic.listener.ChannelListener;
|
2009-12-17 15:27:57 -05:00
|
|
|
import org.yaaic.listener.FlingListener;
|
2010-03-02 14:18:44 -05:00
|
|
|
import org.yaaic.model.Broadcast;
|
|
|
|
import org.yaaic.model.Channel;
|
2009-12-17 15:27:57 -05:00
|
|
|
import org.yaaic.model.Server;
|
2010-03-02 14:18:44 -05:00
|
|
|
import org.yaaic.receiver.ChannelReceiver;
|
|
|
|
import org.yaaic.receiver.ServerReceiver;
|
2009-12-17 15:27:57 -05:00
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Intent;
|
2010-03-02 14:18:44 -05:00
|
|
|
import android.content.IntentFilter;
|
2009-12-17 15:27:57 -05:00
|
|
|
import android.content.ServiceConnection;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.IBinder;
|
|
|
|
import android.view.GestureDetector;
|
|
|
|
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.ImageView;
|
|
|
|
import android.widget.TextView;
|
2010-03-02 14:28:32 -05:00
|
|
|
import android.widget.Toast;
|
2009-12-17 15:27:57 -05:00
|
|
|
import android.widget.ViewFlipper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Connected to server
|
|
|
|
*
|
|
|
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
|
|
|
*/
|
2010-03-02 14:18:44 -05:00
|
|
|
public class ServerActivity extends Activity implements ServiceConnection, ChannelListener
|
2009-12-17 15:27:57 -05:00
|
|
|
{
|
|
|
|
protected static final String TextView = null;
|
2010-03-02 14:18:44 -05:00
|
|
|
private Server server;
|
|
|
|
private ChannelReceiver receiver;
|
2009-12-17 15:27:57 -05:00
|
|
|
private IRCBinder binder;
|
|
|
|
private int serverId;
|
|
|
|
|
|
|
|
private GestureDetector flingDetector;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
this.serverId = getIntent().getExtras().getInt("serverId");
|
|
|
|
|
2010-03-02 14:18:44 -05:00
|
|
|
server = (Server) Yaaic.getInstance().getServerById(serverId);
|
2009-12-17 15:27:57 -05:00
|
|
|
|
|
|
|
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)));
|
2010-03-02 14:18:44 -05:00
|
|
|
|
|
|
|
receiver = new ChannelReceiver(this);
|
|
|
|
registerReceiver(receiver, new IntentFilter(Broadcast.CHANNEL_MESSAGE));
|
2009-12-17 15:27:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event)
|
|
|
|
{
|
|
|
|
return flingDetector.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume()
|
|
|
|
{
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
Intent intent = new Intent(this, IRCService.class);
|
|
|
|
bindService(intent, this, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause()
|
|
|
|
{
|
|
|
|
super.onPause();
|
|
|
|
|
|
|
|
unbindService(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onServiceConnected(ComponentName name, IBinder service)
|
|
|
|
{
|
|
|
|
this.binder = (IRCBinder) service;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onServiceDisconnected(ComponentName name)
|
|
|
|
{
|
|
|
|
this.binder = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
super.onCreateOptionsMenu(menu);
|
|
|
|
|
|
|
|
// inflate from xml
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.server, menu);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemSelected(int featureId, MenuItem item)
|
|
|
|
{
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.disconnect:
|
|
|
|
binder.getService().getConnection(serverId).quitServer();
|
|
|
|
setResult(RESULT_OK);
|
|
|
|
finish();
|
|
|
|
break;
|
|
|
|
case R.id.join:
|
|
|
|
final Dialog dialog = new Dialog(this);
|
|
|
|
dialog.setContentView(R.layout.channeldialog);
|
|
|
|
dialog.setTitle(R.string.channel);
|
|
|
|
|
|
|
|
Button button = (Button) dialog.findViewById(R.id.join);
|
|
|
|
button.setOnClickListener(new OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
String channel = ((EditText) v.getRootView().findViewById(R.id.channel)).getText().toString();
|
|
|
|
binder.getService().getConnection(serverId).joinChannel(channel);
|
|
|
|
dialog.cancel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-02 14:18:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On channel message
|
|
|
|
*/
|
2010-03-02 14:28:32 -05:00
|
|
|
public void onChannelMessage(String target)
|
2010-03-02 14:18:44 -05:00
|
|
|
{
|
2010-03-02 14:28:32 -05:00
|
|
|
String message = server.getChannel(target).pollMessage();
|
|
|
|
|
|
|
|
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
2010-03-02 14:18:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On new channel
|
|
|
|
*/
|
|
|
|
public void onNewChannel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On channel remove
|
|
|
|
*/
|
|
|
|
public void onRemoveChannel()
|
|
|
|
{
|
|
|
|
}
|
2009-12-17 15:27:57 -05:00
|
|
|
}
|