1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-29 04:12:18 -05:00
This commit is contained in:
pocmo 2009-05-15 17:32:49 +02:00
commit d451e9dd28
70 changed files with 1496 additions and 0 deletions

7
.classpath Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="lib/pircbot.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

33
.project Normal file
View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Yaaic2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

29
AndroidManifest.xml Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.yaaic.client"
android:versionCode="1" android:versionName="0.1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name="YaaicApplication">
<activity android:name=".ServerList"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ServerAdd"
android:label="@string/server_add_title">
</activity>
<activity android:name=".Settings"
android:label="@string/settings_title">
</activity>
<activity android:name=".About"
android:label="@string/about_title"
android:theme="@android:style/Theme.Dialog" >
</activity>
<activity android:name=".ServerWindow"
android:label="ServerWindow">
</activity>
<service android:name=".YaaicService"/>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>

BIN
bin/Yaaic2.apk Normal file

Binary file not shown.

BIN
bin/classes.dex Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
bin/resources.ap_ Normal file

Binary file not shown.

62
lib/.svn/entries Normal file
View File

@ -0,0 +1,62 @@
9
dir
4
svn://svn.pocmo.de/yaaic/lib
svn://svn.pocmo.de/yaaic
2009-03-08T17:11:52.298008Z
1
pocmo
svn:special svn:externals svn:needs-lock
a7894ac8-149d-4e17-93c0-b356fc648384
pircbot.jar
file
2009-03-08T17:14:26.000000Z
24c1232877573f3e8291803a7b8a7d79
2009-03-08T17:11:52.298008Z
1
pocmo
has-props
76667

1
lib/.svn/format Normal file
View File

@ -0,0 +1 @@
9

View File

@ -0,0 +1,5 @@
K 13
svn:mime-type
V 24
application/octet-stream
END

Binary file not shown.

BIN
lib/pircbot.jar Normal file

Binary file not shown.

BIN
res/drawable/add.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 B

BIN
res/drawable/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
res/drawable/settings.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 865 B

35
res/layout/about.xml Normal file
View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about_text"
android:autoLink="all"
android:clickable="true"
android:linksClickable="true"/>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Homepage"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Donate"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>

33
res/layout/main.xml Normal file
View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FF333333"
android:padding="5px">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yaaic"
android:textSize="22px" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yet Another Android IRC Client"
android:paddingLeft="10px"/>
</LinearLayout>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
</LinearLayout>

61
res/layout/serveradd.xml Normal file
View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Title:"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/server_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:text="Host:"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/server_host"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:text="Port:"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/server_port"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6667" />
<TextView
android:text="Password:"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/server_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/server_autoconnect"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Auto connect on startup" />
<CheckBox
android:id="@+id/server_usessl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Use SSL" />
<Button
android:id="@+id/server_add"
android:drawableLeft="@android:drawable/ic_input_add"
android:drawablePadding="3px"
android:text="Add to list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>

41
res/layout/serveritem.xml Normal file
View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" android:padding="3px">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/presence_away"
android:layout_margin="5px"
android:drawablePadding="5px"
android:text="" />
<!-- <RadioButton
android:id="@+id/server_checkbox"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="5px"/>
-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/server_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="22px"/>
<TextView
android:id="@+id/server_host"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Host" />
<TextView
android:id="@+id/server_channels"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Channels" />
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/server_title"
android:text=""
android:textSize="22px"
android:drawableLeft="@android:drawable/presence_away"
android:padding="5px"
android:drawablePadding="5px"
android:background="#FF333333" />
<ExpandableListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FF333333"
android:padding="5px">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/server_log"
android:text="Connecting..." />
</ScrollView>
<EditText
android:id="@+id/server_input"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>

15
res/menu/main.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/server_add"
android:title="Add Server"
android:icon="@android:drawable/ic_menu_add" />
<item
android:id="@+id/settings"
android:title="Settings"
android:icon="@android:drawable/ic_menu_preferences" />
<item
android:id="@+id/about"
android:title="About"
android:icon="@android:drawable/ic_menu_help" />
</menu>

7
res/menu/server.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/server_quit"
android:title="Quit"
android:icon="@android:drawable/ic_menu_close_clear_cancel" />
</menu>

9
res/values/array.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="server_popup">
<item>Connect</item>
<!-- <item>Edit</item> -->
<item>Delete</item>
<item>Disconnect</item>
</array>
</resources>

25
res/values/strings.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Yaaic</string>
<string name="server_add_title">Yaaic: New Server</string>
<string name="settings_title">Yaaic: Settings</string>
<string name="about_title">About Yaaic</string>
<string name="about_text">\
Yaaic 0.1\n\
Yet Another Android IRC Client\n\
Sebastian Kaspari\n\
http://www.yaaic.org\n\
\n\
Yaaic is free and will remain free! If you like Yaaic you can support Yaaic by donating a small amount. :)\n\
\n\
Thanks to:\n\
- Bonko -\n\
For Beta-Testing and Reporting Bugs\n\
\n\
- Paul Mutton -\n\
For the awesome PircBot IRC API\n\
</string>
</resources>

64
res/xml/settings.xml Normal file
View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Chat">
<EditTextPreference
android:key="foreground_color"
android:title="Foreground color"
android:summary="Color of the text"
android:defaultValue="#ffffff" />
<EditTextPreference
android:key="background_color"
android:title="Background color"
android:summary="Color of the background"
android:defaultValue="#000000" />
<CheckBoxPreference
android:key="strip_mirc_colors"
android:title="Strip mIRC colors"
android:summary="Strip colors used by mIRC"
android:defaultValue="true" />
<ListPreference
android:key="font_size"
android:title="Font size"
android:summary="Size of the font" />
<CheckBoxPreference
android:key="show_colors"
android:title="Show colors"
android:summary="Use colors to highlight special events"
android:defaultValue="true" />
<CheckBoxPreference
android:key="show_smileys"
android:title="Show Smileys"
android:summary="Show smiley icons instead of text"
android:defaultValue="true" />
<CheckBoxPreference
android:key="show_icons"
android:title="Show Icons"
android:summary="Show icons to highlight special events"
android:defaultValue="true" />
<CheckBoxPreference
android:key="show_timestamp"
android:title="Show timestamp"
android:summary="Show timestamp in front of messages"
android:defaultValue="false" />
<EditTextPreference
android:key="timestamp_format"
android:title="Timestamp format"
android:summary="Format of the timestamp"
android:defaultValue="[H:i]"
android:dependency="show_timestamp"
android:layout="?android:attr/preferenceLayoutChild" />
</PreferenceCategory>
<PreferenceCategory
android:title="Misc">
<ListPreference
android:key="language"
android:title="Language"
android:summary="Select language" />
<CheckBoxPreference
android:key="log_sdcard"
android:title="Log on SD Card"
android:summary="Save logs on SD Card in /yaaic/logs/"
android:defaultValue="false" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -0,0 +1,14 @@
package org.yaaic.client;
import android.app.Activity;
import android.os.Bundle;
public class About extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
}
}

View File

@ -0,0 +1,57 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package org.yaaic.client;
public final class R {
public static final class array {
public static final int server_popup=0x7f050000;
}
public static final class attr {
}
public static final class drawable {
public static final int add=0x7f020000;
public static final int icon=0x7f020001;
public static final int settings=0x7f020002;
}
public static final class id {
public static final int about=0x7f08000b;
public static final int server_add=0x7f080006;
public static final int server_autoconnect=0x7f080004;
public static final int server_channels=0x7f080007;
public static final int server_host=0x7f080001;
public static final int server_input=0x7f080009;
public static final int server_log=0x7f080008;
public static final int server_password=0x7f080003;
public static final int server_port=0x7f080002;
public static final int server_quit=0x7f08000c;
public static final int server_title=0x7f080000;
public static final int server_usessl=0x7f080005;
public static final int settings=0x7f08000a;
}
public static final class layout {
public static final int about=0x7f030000;
public static final int main=0x7f030001;
public static final int serveradd=0x7f030002;
public static final int serveritem=0x7f030003;
public static final int serverwindow=0x7f030004;
}
public static final class menu {
public static final int main=0x7f070000;
public static final int server=0x7f070001;
}
public static final class string {
public static final int about_text=0x7f060004;
public static final int about_title=0x7f060003;
public static final int app_name=0x7f060000;
public static final int server_add_title=0x7f060001;
public static final int settings_title=0x7f060002;
}
public static final class xml {
public static final int settings=0x7f040000;
}
}

View File

@ -0,0 +1,45 @@
package org.yaaic.client;
import org.yaaic.client.db.ServerDatabase;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
public class ServerAdd extends Activity implements OnClickListener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.serveradd);
Button button = (Button) findViewById(R.id.server_add);
button.setOnClickListener(this);
}
public void onClick(View v)
{
switch (v.getId()) {
case R.id.server_add:
String title = ((EditText) findViewById(R.id.server_title)).getText().toString();
String host = ((EditText) findViewById(R.id.server_host)).getText().toString();
int port = Integer.parseInt(((EditText) findViewById(R.id.server_port)).getText().toString());
String password = ((EditText) findViewById(R.id.server_password)).getText().toString();
boolean autoConnect = ((CheckBox) findViewById(R.id.server_autoconnect)).isChecked();
boolean useSSL = ((CheckBox) findViewById(R.id.server_usessl)).isChecked();
ServerDatabase db = new ServerDatabase(this);
db.addServer(title, host, port, password, autoConnect, useSSL);
db.close();
this.finish();
break;
}
}
}

View File

@ -0,0 +1,243 @@
package org.yaaic.client;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemLongClickListener;
import org.yaaic.client.db.ServerConstants;
import org.yaaic.client.db.ServerDatabase;
import org.yaaic.client.irc.IrcBinder;
import org.yaaic.client.irc.IrcService;
public class ServerList extends ListActivity implements OnItemLongClickListener, ServiceConnection {
public static final String TAG = "Yaaic/ServerList";
private ServerDatabase db;
private static final String[] FROM = { ServerConstants.TITLE, ServerConstants.HOST };
private static final int[] TO = { R.id.server_title, R.id.server_host };
private Cursor cursor;
private IrcBinder binder;
@Override
public void onCreate(Bundle savedInstanceState)
{
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
// Start Service
Intent serviceIntent = new Intent(this, IrcService.class);
startService(serviceIntent);
boolean binding = bindService(serviceIntent, this, 0);
Log.d(TAG, "Binding to Service: " + binding);
setContentView(R.layout.main);
/*
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon, "#pocmo <Henna> Hallo Pocmo", System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 123, new Intent(this, ServerAdd.class), 0);
notification.setLatestEventInfo(this, "#pocmo", "<Henna> Hallo Pocmo", contentIntent);
manager.notify(1234, notification);
*/
db = new ServerDatabase(this);
cursor = db.getServers();
this.startManagingCursor(cursor);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.serveritem, cursor, FROM, TO);
this.setListAdapter(adapter);
this.getListView().setOnItemLongClickListener(this);
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(100);
set.addAnimation(animation);
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(300);
set.addAnimation(animation);
LayoutAnimationController controller =
new LayoutAnimationController(set, 0.5f);
ListView lv = (ListView) getListView();
lv.setLayoutAnimation(controller);
}
public void onResume()
{
Log.d(TAG, "onResume");
super.onResume();
}
public void onPause()
{
Log.d(TAG, "onPause");
super.onPause();
}
public void onDestroy()
{
Log.d(TAG, "onDestroy");
super.onDestroy();
db.close();
unbindService(this);
}
public void onListItemClick(ListView listView, View view, int position, long id)
{
TextView tv = (TextView) view.findViewById(R.id.server_title);
Intent serverIntent = new Intent(this, ServerWindow.class);
serverIntent.putExtra("server_title", tv.getText());
startActivity(serverIntent);
//Toast.makeText(this, tv.getText().toString(), Toast.LENGTH_SHORT).show();
//db.removeServer(tv.getText().toString());
//cursor.requery();
}
public boolean onItemLongClick(AdapterView<?> av, View v, int position, long id) {
final TextView tv = (TextView) v.findViewById(R.id.server_title);
new AlertDialog.Builder(this)
.setTitle(tv.getText())
.setItems(R.array.server_popup,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
onServerDialogSelect(i, tv.getText().toString());
}
}
).show();
return true;
}
public void onServerDialogSelect(int item, String title)
{
Log.d(TAG, "ServerDialogSelect: Item #" + item);
switch (item)
{
case 0: // Connect
if (!binder.isConnected(title)) {
connectToServer(title);
} else {
Toast toast = Toast.makeText(this, "You are already connected to " + title, Toast.LENGTH_SHORT);
toast.show();
}
break;
case 1: // Delete
db.removeServer(title);
cursor.requery();
break;
case 2: // Disconnect
binder.disconnect(title);
break;
}
}
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.server_add:
Intent serverAddIntent = new Intent(this, ServerAdd.class);
startActivity(serverAddIntent);
return true;
case R.id.settings:
Intent settingsIntent = new Intent(this, Settings.class);
startActivity(settingsIntent);
return true;
case R.id.about:
Intent aboutIntent = new Intent(this, About.class);
startActivity(aboutIntent);
return true;
}
return false;
}
public void onServiceConnected(ComponentName name, IBinder service)
{
Log.d(TAG, "Service connected");
binder = (IrcBinder) service;
// AutoConnect
Cursor autoCursor = db.getAutoConnectServers();
while(autoCursor.moveToNext()) {
binder.connect(
autoCursor.getString(autoCursor.getColumnIndex(ServerConstants.TITLE)),
autoCursor.getString(autoCursor.getColumnIndex(ServerConstants.HOST)),
autoCursor.getInt(autoCursor.getColumnIndex(ServerConstants.PORT)),
autoCursor.getString(autoCursor.getColumnIndex(ServerConstants.PASSWORD))
);
}
autoCursor.close();
}
public void onServiceDisconnected(ComponentName name)
{
Log.d(TAG, "Service disconnected");
}
private void connectToServer(String title)
{
Cursor cursor = db.getServer(title);
if (cursor.moveToNext()) {
binder.connect(
cursor.getString(cursor.getColumnIndex(ServerConstants.TITLE)),
cursor.getString(cursor.getColumnIndex(ServerConstants.HOST)),
cursor.getInt(cursor.getColumnIndex(ServerConstants.PORT)),
cursor.getString(cursor.getColumnIndex(ServerConstants.PASSWORD))
);
} else {
Log.d(TAG, "Could not find server: " + title);
}
cursor.close();
}
}

View File

@ -0,0 +1,115 @@
package org.yaaic.client;
import org.yaaic.client.db.ServerConstants;
import org.yaaic.client.db.ServerDatabase;
import org.yaaic.client.irc.IrcBinder;
import org.yaaic.client.irc.IrcService;
import android.app.ExpandableListActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
public class ServerWindow extends ExpandableListActivity implements ServiceConnection
{
private static final String TAG = "Yaaic/ServerWindow";
private IrcBinder binder;
private String title;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.serverwindow);
title = getIntent().getStringExtra("server_title");
setTitle(title);
((TextView) findViewById(R.id.server_title)).setText(title);
setListAdapter(new ServerWindowListAdapter(this));
//registerForContextMenu(getExpandableListView());
Intent serviceIntent = new Intent(this, IrcService.class);
boolean binding = bindService(serviceIntent, this, 0);
Log.d(TAG, "Binding to Service: " + binding);
}
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.server, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.server_quit:
finish();
return true;
}
return false;
}
public void onServiceConnected(ComponentName name, IBinder service)
{
Log.d(TAG, "Service connected");
binder = (IrcBinder) service;
ServerDatabase db = new ServerDatabase(this);
Cursor cursor = db.getServer(title);
if (cursor.moveToNext()) {
binder.connect(
cursor.getString(cursor.getColumnIndex(ServerConstants.TITLE)),
cursor.getString(cursor.getColumnIndex(ServerConstants.HOST)),
cursor.getInt(cursor.getColumnIndex(ServerConstants.PORT)),
cursor.getString(cursor.getColumnIndex(ServerConstants.PASSWORD))
);
}
cursor.close();
db.close();
TextView tv = (TextView) findViewById(R.id.server_title);
if (binder.isConnected(title)) {
tv.setCompoundDrawablesWithIntrinsicBounds(
getResources().getDrawable(android.R.drawable.presence_online),
null,
null,
null
);
} else {
tv.setCompoundDrawablesWithIntrinsicBounds(
getResources().getDrawable(android.R.drawable.presence_offline),
null,
null,
null
);
}
}
public void onServiceDisconnected(ComponentName name)
{
Log.d(TAG, "Service disconnected");
}
public void onDestroy()
{
Log.d(TAG, "onDestroy");
super.onDestroy();
unbindService(this);
}
}

View File

@ -0,0 +1,78 @@
package org.yaaic.client;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
public class ServerWindowListAdapter extends BaseExpandableListAdapter
{
private ServerWindow serverWindow;
private String[] groups = { "Channels (0)", "Queries (0)" };
public ServerWindowListAdapter(ServerWindow serverWindow)
{
this.serverWindow = serverWindow;
}
public Object getChild(int groupPosition, int childPosition) {
return "Child";
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getChild(groupPosition, childPosition).toString());
return textView;
}
public int getChildrenCount(int groupPosition) {
return 0;
}
public Object getGroup(int groupPosition) {
return groups[groupPosition];
}
public int getGroupCount() {
return groups.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 64);
TextView textView = new TextView(serverWindow);
textView.setLayoutParams(lp);
// Center the text vertically
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
textView.setPadding(36, 0, 0, 0);
return textView;
}
}

View File

@ -0,0 +1,14 @@
package org.yaaic.client;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Settings extends PreferenceActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}

View File

@ -0,0 +1,7 @@
package org.yaaic.client;
import android.app.Application;
public class YaaicApplication extends Application {
}

View File

@ -0,0 +1,18 @@
package org.yaaic.client.db;
import android.provider.BaseColumns;
public interface ChannelConstants extends BaseColumns
{
public static final String TABLE_NAME = "channels";
public static final String NAME = "name";
public static final String PASSWORD = "password";
public static final String SERVER = "server";
public static final String[] ALL = {
NAME,
PASSWORD,
SERVER
};
}

View File

@ -0,0 +1,5 @@
package org.yaaic.client.db;
public class IdentityConstants {
}

View File

@ -0,0 +1,26 @@
package org.yaaic.client.db;
import android.provider.BaseColumns;
public interface ServerConstants extends BaseColumns
{
public static final String TABLE_NAME = "servers";
public static final String TITLE = "title";
public static final String HOST = "host";
public static final String PORT = "port";
public static final String PASSWORD = "password";
public static final String AUTOCONNECT = "autoConnect";
public static final String USE_SSL = "useSSL";
public static final String IDENTITY = "identity";
public static final String[] ALL = {
_ID,
TITLE,
HOST,
PORT,
PASSWORD,
AUTOCONNECT,
USE_SSL
};
}

View File

@ -0,0 +1,144 @@
package org.yaaic.client.db;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class ServerDatabase extends SQLiteOpenHelper
{
private static final String DATABASE_NAME = "servers.db";
private static final int DATABASE_VERSION = 1;
public ServerDatabase(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL("CREATE TABLE " + ServerConstants.TABLE_NAME + " ( "
+ ServerConstants._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ ServerConstants.TITLE + " TEXT NOT NULL, "
+ ServerConstants.HOST + " TEXT NOT NULL, "
+ ServerConstants.PORT + " INTEGER, "
+ ServerConstants.PASSWORD + " TEXT, "
+ ServerConstants.AUTOCONNECT + " BOOLEAN, " // XXX: Does SQLLite support boolean?
+ ServerConstants.USE_SSL + " BOOLEAN, "
+ ServerConstants.IDENTITY + " INTEGER"
+ ");"
);
db.execSQL("CREATE TABLE " + ChannelConstants.TABLE_NAME + " ("
+ ChannelConstants._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ ChannelConstants.NAME + " TEXT NOT NULL, "
+ ChannelConstants.PASSWORD + " TEXT, "
+ ChannelConstants.SERVER + " INTEGER"
+ ");"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
// XXX: We delete the database currently, in future we want to
// migrate the database to the new version (add or remove rows..)
db.execSQL("DROP TABLE IF EXISTS " + ServerConstants.TABLE_NAME + ";");
db.execSQL("DROP TABLE IF EXISTS " + ChannelConstants.TABLE_NAME + ";");
onCreate(db);
}
public void addServer(String title, String host, int port, String password, boolean autoConnect, boolean useSSL)
{
ContentValues values = new ContentValues();
values.put(ServerConstants.TITLE, title);
values.put(ServerConstants.HOST, host);
values.put(ServerConstants.PORT, port);
values.put(ServerConstants.PASSWORD, password);
values.put(ServerConstants.AUTOCONNECT, autoConnect);
values.put(ServerConstants.USE_SSL, useSSL);
this.getWritableDatabase().insert(ServerConstants.TABLE_NAME, null, values);
}
public void addChannel(int server, String name, String password)
{
ContentValues values = new ContentValues();
values.put(ChannelConstants.NAME, name);
values.put(ChannelConstants.PASSWORD, password);
values.put(ChannelConstants.SERVER, server);
this.getWritableDatabase().insert(ServerConstants.TABLE_NAME, null, values);
}
public Cursor getServers()
{
return this.getReadableDatabase().query(
ServerConstants.TABLE_NAME,
ServerConstants.ALL,
null,
null,
null,
null,
ServerConstants.TITLE + " ASC"
);
}
public Cursor getAutoConnectServers()
{
return this.getReadableDatabase().query(
ServerConstants.TABLE_NAME,
ServerConstants.ALL,
ServerConstants.AUTOCONNECT + " = 1",
null,
null,
null,
ServerConstants.TITLE + " ASC"
);
}
public Cursor getChannels()
{
return this.getReadableDatabase().query(
ChannelConstants.TABLE_NAME,
ChannelConstants.ALL,
null,
null,
null,
null,
ChannelConstants.NAME + " ASC");
}
public Cursor getChannelsByServer(int server)
{
return this.getReadableDatabase().query(
ChannelConstants.TABLE_NAME,
ChannelConstants.ALL,
ChannelConstants.SERVER + "=" + server,
null,
null,
null,
ChannelConstants.NAME + " ASC");
}
public Cursor getServer(String title)
{
return this.getReadableDatabase().query(
ServerConstants.TABLE_NAME,
ServerConstants.ALL,
ServerConstants.TITLE + " = '" + title + "'",
null,
null,
null,
ServerConstants.TITLE + " ASC"
);
}
public void removeServer(String title)
{
this.getWritableDatabase().execSQL("DELETE FROM " + ServerConstants.TABLE_NAME + " WHERE title = '" + title + "';");
}
}

View File

@ -0,0 +1,5 @@
package org.yaaic.client.irc;
public class ChannelBuffer extends MessageBuffer {
}

View File

@ -0,0 +1,72 @@
package org.yaaic.client.irc;
import android.os.Binder;
import android.util.Log;
/**
*
* @author Sebastian Kaspari <pocmo@yaaic.org>
*/
public class IrcBinder extends Binder
{
private IrcService service;
private String TAG = "YaaicBinder";
/**
*
* @param service
*/
public IrcBinder(IrcService service)
{
Log.d(TAG, "Binder created");
this.service = service;
}
/**
*
* @param title
* @param host
* @param port
* @param password
*/
public void connect(final String title, final String host, final int port, final String password)
{
Thread thread = new Thread() {
public void run() {
service.connect(title, host, port, password);
}
};
thread.start();
}
/**
*
* @param title
* @return
*/
public boolean isConnected(String title) {
IrcServer server = this.service.getIrcServer(title);
if (server != null) {
return server.isConnected();
}
return false;
}
/**
*
* @param title
* @return
*/
public boolean disconnect(String title)
{
IrcServer server = this.service.getIrcServer(title);
if (server != null) {
if (server.isConnected()) {
server.quitServer("Yaaic - Yet Another Android IRC Client - www.yaaic.org");
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,13 @@
package org.yaaic.client.irc;
import org.jibble.pircbot.PircBot;
public class IrcServer extends PircBot
{
public IrcServer()
{
this.setName("Yaaic");
this.setAutoNickChange(true);
this.setLogin("yaaic");
}
}

View File

@ -0,0 +1,114 @@
package org.yaaic.client.irc;
import java.io.IOException;
import java.util.HashMap;
import org.jibble.pircbot.IrcException;
import org.jibble.pircbot.NickAlreadyInUseException;
import org.yaaic.client.db.ServerDatabase;
import android.app.Service;
import android.content.Intent;
import android.database.Cursor;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
/**
*
* @author Sebastian Kaspari
*/
public class IrcService extends Service
{
private static final String TAG = "Yaaic/Service";
private int createCounter = 0;
private IrcBinder binder;
private Handler handler;
private HashMap<String, IrcServer> servers = new HashMap<String, IrcServer>();
@Override
public void onCreate()
{
Log.d(TAG, "onCreate(" + createCounter + ")");
super.onCreate();
createCounter++;
}
@Override
public IBinder onBind(Intent intent)
{
Log.d(TAG, "onBind");
if (binder == null) {
binder = new IrcBinder(this);
}
return binder;
}
public int getCounter()
{
return createCounter;
}
public Handler getHandler()
{
return handler;
}
@Override
public void onDestroy()
{
Log.d(TAG, "onDestroy(" + createCounter + ")");
super.onDestroy();
createCounter--;
}
/**
* Connect to server
*
* @param title Title of the IRC-Network
* @param host
* @param port
* @param password (If needed, else an empty string)
*/
public void connect(String title, String host, int port, String password)
{
if(!servers.containsKey(title)) {
Log.d(TAG, "Connect to " + title + ": " + host + ":" + port + "[" + password + "]");
IrcServer irc = new IrcServer();
try {
irc.connect(host, port);
servers.put(title, irc);
}
catch(NickAlreadyInUseException e) {
Log.d(TAG, e.getMessage());
}
catch(IrcException e) {
Log.d(TAG, e.getMessage());
}
catch(IOException e) {
Log.d(TAG, e.getMessage());
}
} else {
Log.d(TAG, "Already connected to: " + title);
}
}
/**
* Get IrcServer Object by Title
*
* @param title Title of the IRC-Network (PK)
* @return IrcServer Object or null
*/
public IrcServer getIrcServer(String title)
{
return servers.get(title);
}
}

View File

@ -0,0 +1,57 @@
package org.yaaic.client.irc;
import java.util.ArrayList;
import android.text.SpannableString;
/**
*
* @author Sebastian Kaspari <pocmo@yaaic.org>
*/
public class MessageBuffer
{
private ArrayList<SpannableString> messageBuffer;
/**
* Maximum Buffer Size
*/
private static final int MAX_SIZE = 30;
/**
* Maximum Buffer Size in Emergencies, e.g. if we are low on memory
*/
private static final int EMERGENCY_MAX_SIZE = 10;
/**
*
*/
public MessageBuffer()
{
messageBuffer = new ArrayList<SpannableString>();
}
/**
*
* @param s
* @return
*/
public boolean add(SpannableString s)
{
if (messageBuffer.size() > MAX_SIZE) {
messageBuffer.remove(0);
}
return messageBuffer.add(s);
}
/**
* Truncate the buffer to the maximum size (emergency)
*
* Use this if we are low on memory
*/
public void truncate()
{
while (messageBuffer.size() > EMERGENCY_MAX_SIZE) {
messageBuffer.remove(0);
}
}
}

View File

@ -0,0 +1,5 @@
package org.yaaic.client.irc;
public class ServerBuffer extends MessageBuffer {
}