Refactored nearly everything
@ -3,6 +3,5 @@
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="lib" path="lib/pircbot.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -1,56 +1,28 @@
|
||||
<?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/>.
|
||||
-->
|
||||
<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">
|
||||
package="org.yaaic"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.1">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<activity
|
||||
android:name=".view.ServerListActivity"
|
||||
android:name=".view.ServersActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".view.ServerAddActivity"
|
||||
android:label="@string/server_add_title">
|
||||
android:name=".view.AddServerActivity"
|
||||
android:label="@string/add_server_label">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".view.SettingsActivity"
|
||||
android:label="@string/settings_title">
|
||||
android:name=".view.ServerActivity">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".view.AboutActivity"
|
||||
android:label="@string/about_title"
|
||||
android:theme="@android:style/Theme.Dialog" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".view.ServerActivity"
|
||||
android:label="">
|
||||
</activity>
|
||||
<service android:name=".irc.IrcService"/>
|
||||
<service android:name=".irc.IRCService"></service>
|
||||
|
||||
</application>
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
<uses-sdk android:minSdkVersion="4" />
|
||||
<uses-sdk android:minSdkVersion="4" />
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
|
||||
</manifest>
|
BIN
lib/pircbot.jar
19
res/anim/slide_left_in.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2007 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
|
||||
<translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="150" />
|
||||
</set>
|
19
res/anim/slide_left_out.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2007 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
|
||||
<translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="150" />
|
||||
</set>
|
19
res/anim/slide_right_in.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2007 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
|
||||
<translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="150" />
|
||||
</set>
|
19
res/anim/slide_right_out.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2007 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
|
||||
<translate android:fromXDelta="0" android:toXDelta="100%p" android:duration="150" />
|
||||
</set>
|
BIN
res/drawable-hdpi/icon.png
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
res/drawable-ldpi/icon.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
res/drawable-mdpi/icon.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 733 B |
BIN
res/drawable/connected.png
Normal file
After Width: | Height: | Size: 264 B |
BIN
res/drawable/connecting.png
Normal file
After Width: | Height: | Size: 264 B |
BIN
res/drawable/disconnected.png
Normal file
After Width: | Height: | Size: 264 B |
Before Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 865 B |
@ -1,55 +0,0 @@
|
||||
<?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: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>
|
18
res/layout/channeldialog.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:padding="3px">
|
||||
<EditText
|
||||
android:id="@+id/channel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="#"
|
||||
android:minEms="10"
|
||||
android:singleLine="true" />
|
||||
<Button
|
||||
android:id="@+id/join"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/join" />
|
||||
</LinearLayout>
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Yaaic - Yet Another Android IRC Client
|
||||
|
||||
@ -20,38 +20,76 @@ 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:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
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:padding="5px">
|
||||
<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="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5px"
|
||||
android:textSize="16px"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
<ViewFlipper
|
||||
android:id="@+id/channels"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
<TextView
|
||||
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>
|
||||
<LinearLayout
|
||||
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" />
|
||||
android:gravity="right">
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:singleLine="true" />
|
||||
<Button
|
||||
android:id="@+id/previous"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="<" />
|
||||
<Button
|
||||
android:id="@+id/next"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=">" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
@ -28,60 +28,74 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<TextView
|
||||
android:text="Title:"
|
||||
android:text="@string/server_title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<EditText
|
||||
android:id="@+id/server_title"
|
||||
android:id="@+id/title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true" />
|
||||
<TextView
|
||||
android:text="Host:"
|
||||
android:text="@string/server_host"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<EditText
|
||||
android:id="@+id/server_host"
|
||||
android:id="@+id/host"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true" />
|
||||
<TextView
|
||||
android:text="Port:"
|
||||
android:text="@string/server_port"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<EditText
|
||||
android:id="@+id/server_port"
|
||||
android:id="@+id/port"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:minEms="6"
|
||||
android:text="6667" />
|
||||
<TextView
|
||||
android:text="Password:"
|
||||
android:text="@string/server_password"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<EditText
|
||||
android:id="@+id/server_password"
|
||||
android:layout_width="fill_parent"
|
||||
android:id="@+id/password"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:password="true" />
|
||||
android:password="true"
|
||||
android:minEms="10"
|
||||
android:maxEms="10" />
|
||||
<CheckBox
|
||||
android:id="@+id/server_autoconnect"
|
||||
android:id="@+id/autoconnect"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Auto connect on startup"
|
||||
android:text="@string/server_port"
|
||||
android:visibility="gone" />
|
||||
<CheckBox
|
||||
android:id="@+id/server_usessl"
|
||||
android:id="@+id/useSSL"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Use SSL"
|
||||
android:text="@string/server_useSSL"
|
||||
android:visibility="gone" />
|
||||
<Button
|
||||
android:id="@+id/server_add"
|
||||
android:drawablePadding="3px"
|
||||
android:text="Add server"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<Button
|
||||
android:id="@+id/add"
|
||||
android:text="@string/add_server"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
<Button
|
||||
android:id="@+id/cancel"
|
||||
android:text="@string/cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Yaaic - Yet Another Android IRC Client
|
||||
|
||||
@ -19,44 +19,33 @@ 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:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal" android:padding="3px">
|
||||
<TextView
|
||||
android:id="@+id/server_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableLeft="@android:drawable/presence_offline"
|
||||
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">
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="5px">
|
||||
<ImageView
|
||||
android:id="@+id/status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/disconnected"
|
||||
android:layout_gravity="center_vertical" />
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="5px">
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""
|
||||
android:textSize="16px" />
|
||||
<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>
|
||||
android:id="@+id/host"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""
|
||||
android:textSize="12px" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
@ -1,53 +0,0 @@
|
||||
<?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
|
||||
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>
|
@ -19,11 +19,12 @@ 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/>.
|
||||
-->
|
||||
<resources>
|
||||
<array name="server_popup">
|
||||
<item>Connect</item>
|
||||
<!-- <item>Edit</item> -->
|
||||
<item>Delete</item>
|
||||
<item>Disconnect</item>
|
||||
</array>
|
||||
</resources>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
</LinearLayout>
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Yaaic - Yet Another Android IRC Client
|
||||
|
||||
@ -20,8 +20,12 @@ You should have received a copy of the GNU General Public License
|
||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<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" />
|
||||
<item
|
||||
android:id="@+id/join"
|
||||
android:title="@string/join_channel"
|
||||
android:icon="@android:drawable/ic_menu_add" />
|
||||
<item
|
||||
android:id="@+id/disconnect"
|
||||
android:title="@string/disconnect"
|
||||
android:icon="@android:drawable/ic_menu_close_clear_cancel" />
|
||||
</menu>
|
@ -1,37 +0,0 @@
|
||||
<?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/>.
|
||||
-->
|
||||
<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"
|
||||
android:visible="false" />
|
||||
<item
|
||||
android:id="@+id/about"
|
||||
android:title="About"
|
||||
android:icon="@android:drawable/ic_menu_help"
|
||||
android:visible="false" />
|
||||
</menu>
|
6
res/menu/servers.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/add"
|
||||
android:title="@string/add_server_menu"
|
||||
android:icon="@android:drawable/ic_menu_add" />
|
||||
</menu>
|
@ -1,36 +1,25 @@
|
||||
<?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/>.
|
||||
-->
|
||||
<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="add_server_menu">Add server</string>
|
||||
|
||||
<string name="about_text">\
|
||||
Yaaic 0.1\n\
|
||||
Yet Another Android IRC Client\n\
|
||||
Sebastian Kaspari\n\
|
||||
http://www.yaaic.org\n\
|
||||
</string>
|
||||
<string name="add_server_label">Add new server</string>
|
||||
<string name="server_title">Title</string>
|
||||
<string name="server_host">Host</string>
|
||||
<string name="server_port">Port</string>
|
||||
<string name="server_password">Password</string>
|
||||
<string name="server_useSSL">Use SSL</string>
|
||||
<string name="server_autoconnect">Auto connect on startup</string>
|
||||
<string name="server_channels">Channels</string>
|
||||
<string name="add_server">Add server</string>
|
||||
|
||||
<string name="cancel">Cancel</string>
|
||||
|
||||
<string name="channel">Channel</string>
|
||||
<string name="join">Join</string>
|
||||
<string name="join_channel">Join Channel</string>
|
||||
<string name="connect">Connect</string>
|
||||
<string name="disconnect">Disconnect</string>
|
||||
<string name="delete">Delete</string>
|
||||
</resources>
|
||||
|
@ -1,84 +0,0 @@
|
||||
<?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/>.
|
||||
-->
|
||||
<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>
|
293
src/org/jibble/pircbot/Colors.java
Normal file
@ -0,0 +1,293 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
/**
|
||||
* The Colors class provides several static fields and methods that you may
|
||||
* find useful when writing an IRC Bot.
|
||||
* <p>
|
||||
* This class contains constants that are useful for formatting lines
|
||||
* sent to IRC servers. These constants allow you to apply various
|
||||
* formatting to the lines, such as colours, boldness, underlining
|
||||
* and reverse text.
|
||||
* <p>
|
||||
* The class contains static methods to remove colours and formatting
|
||||
* from lines of IRC text.
|
||||
* <p>
|
||||
* Here are some examples of how to use the contants from within a
|
||||
* class that extends PircBot and imports org.jibble.pircbot.*;
|
||||
*
|
||||
* <pre> sendMessage("#cs", Colors.BOLD + "A bold hello!");
|
||||
* <b>A bold hello!</b>
|
||||
* sendMessage("#cs", Colors.RED + "Red" + Colors.NORMAL + " text");
|
||||
* <font color="red">Red</font> text
|
||||
* sendMessage("#cs", Colors.BOLD + Colors.RED + "Bold and red");
|
||||
* <b><font color="red">Bold and red</font></b></pre>
|
||||
*
|
||||
* Please note that some IRC channels may be configured to reject any
|
||||
* messages that use colours. Also note that older IRC clients may be
|
||||
* unable to correctly display lines that contain colours and other
|
||||
* control characters.
|
||||
* <p>
|
||||
* Note that this class name has been spelt in the American style in
|
||||
* order to remain consistent with the rest of the Java API.
|
||||
*
|
||||
*
|
||||
* @since 0.9.12
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||
*/
|
||||
public class Colors {
|
||||
|
||||
|
||||
/**
|
||||
* Removes all previously applied color and formatting attributes.
|
||||
*/
|
||||
public static final String NORMAL = "\u000f";
|
||||
|
||||
|
||||
/**
|
||||
* Bold text.
|
||||
*/
|
||||
public static final String BOLD = "\u0002";
|
||||
|
||||
|
||||
/**
|
||||
* Underlined text.
|
||||
*/
|
||||
public static final String UNDERLINE = "\u001f";
|
||||
|
||||
|
||||
/**
|
||||
* Reversed text (may be rendered as italic text in some clients).
|
||||
*/
|
||||
public static final String REVERSE = "\u0016";
|
||||
|
||||
|
||||
/**
|
||||
* White coloured text.
|
||||
*/
|
||||
public static final String WHITE = "\u000300";
|
||||
|
||||
|
||||
/**
|
||||
* Black coloured text.
|
||||
*/
|
||||
public static final String BLACK = "\u000301";
|
||||
|
||||
|
||||
/**
|
||||
* Dark blue coloured text.
|
||||
*/
|
||||
public static final String DARK_BLUE = "\u000302";
|
||||
|
||||
|
||||
/**
|
||||
* Dark green coloured text.
|
||||
*/
|
||||
public static final String DARK_GREEN = "\u000303";
|
||||
|
||||
|
||||
/**
|
||||
* Red coloured text.
|
||||
*/
|
||||
public static final String RED = "\u000304";
|
||||
|
||||
|
||||
/**
|
||||
* Brown coloured text.
|
||||
*/
|
||||
public static final String BROWN = "\u000305";
|
||||
|
||||
|
||||
/**
|
||||
* Purple coloured text.
|
||||
*/
|
||||
public static final String PURPLE = "\u000306";
|
||||
|
||||
|
||||
/**
|
||||
* Olive coloured text.
|
||||
*/
|
||||
public static final String OLIVE = "\u000307";
|
||||
|
||||
|
||||
/**
|
||||
* Yellow coloured text.
|
||||
*/
|
||||
public static final String YELLOW = "\u000308";
|
||||
|
||||
|
||||
/**
|
||||
* Green coloured text.
|
||||
*/
|
||||
public static final String GREEN = "\u000309";
|
||||
|
||||
|
||||
/**
|
||||
* Teal coloured text.
|
||||
*/
|
||||
public static final String TEAL = "\u000310";
|
||||
|
||||
|
||||
/**
|
||||
* Cyan coloured text.
|
||||
*/
|
||||
public static final String CYAN = "\u000311";
|
||||
|
||||
|
||||
/**
|
||||
* Blue coloured text.
|
||||
*/
|
||||
public static final String BLUE = "\u000312";
|
||||
|
||||
|
||||
/**
|
||||
* Magenta coloured text.
|
||||
*/
|
||||
public static final String MAGENTA = "\u000313";
|
||||
|
||||
|
||||
/**
|
||||
* Dark gray coloured text.
|
||||
*/
|
||||
public static final String DARK_GRAY = "\u000314";
|
||||
|
||||
|
||||
/**
|
||||
* Light gray coloured text.
|
||||
*/
|
||||
public static final String LIGHT_GRAY = "\u000315";
|
||||
|
||||
|
||||
/**
|
||||
* This class should not be constructed.
|
||||
*/
|
||||
private Colors() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes all colours from a line of IRC text.
|
||||
*
|
||||
* @since PircBot 1.2.0
|
||||
*
|
||||
* @param line the input text.
|
||||
*
|
||||
* @return the same text, but with all colours removed.
|
||||
*/
|
||||
public static String removeColors(String line) {
|
||||
int length = line.length();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int i = 0;
|
||||
while (i < length) {
|
||||
char ch = line.charAt(i);
|
||||
if (ch == '\u0003') {
|
||||
i++;
|
||||
// Skip "x" or "xy" (foreground color).
|
||||
if (i < length) {
|
||||
ch = line.charAt(i);
|
||||
if (Character.isDigit(ch)) {
|
||||
i++;
|
||||
if (i < length) {
|
||||
ch = line.charAt(i);
|
||||
if (Character.isDigit(ch)) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// Now skip ",x" or ",xy" (background color).
|
||||
if (i < length) {
|
||||
ch = line.charAt(i);
|
||||
if (ch == ',') {
|
||||
i++;
|
||||
if (i < length) {
|
||||
ch = line.charAt(i);
|
||||
if (Character.isDigit(ch)) {
|
||||
i++;
|
||||
if (i < length) {
|
||||
ch = line.charAt(i);
|
||||
if (Character.isDigit(ch)) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Keep the comma.
|
||||
i--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Keep the comma.
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ch == '\u000f') {
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
buffer.append(ch);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove formatting from a line of IRC text.
|
||||
*
|
||||
* @since PircBot 1.2.0
|
||||
*
|
||||
* @param line the input text.
|
||||
*
|
||||
* @return the same text, but without any bold, underlining, reverse, etc.
|
||||
*/
|
||||
public static String removeFormatting(String line) {
|
||||
int length = line.length();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (int i = 0; i < length; i++) {
|
||||
char ch = line.charAt(i);
|
||||
if (ch == '\u000f' || ch == '\u0002' || ch == '\u001f' || ch == '\u0016') {
|
||||
// Don't add this character.
|
||||
}
|
||||
else {
|
||||
buffer.append(ch);
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes all formatting and colours from a line of IRC text.
|
||||
*
|
||||
* @since PircBot 1.2.0
|
||||
*
|
||||
* @param line the input text.
|
||||
*
|
||||
* @return the same text, but without formatting and colour characters.
|
||||
*
|
||||
*/
|
||||
public static String removeFormattingAndColors(String line) {
|
||||
return removeFormatting(removeColors(line));
|
||||
}
|
||||
|
||||
}
|
227
src/org/jibble/pircbot/DccChat.java
Normal file
@ -0,0 +1,227 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This class is used to allow the bot to interact with a DCC Chat session.
|
||||
*
|
||||
* @since 0.9c
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||
*/
|
||||
public class DccChat {
|
||||
|
||||
|
||||
/**
|
||||
* This constructor is used when we are accepting a DCC CHAT request
|
||||
* from somebody. It attempts to connect to the client that issued the
|
||||
* request.
|
||||
*
|
||||
* @param bot An instance of the underlying PircBot.
|
||||
* @param sourceNick The nick of the sender.
|
||||
* @param address The address to connect to.
|
||||
* @param port The port number to connect to.
|
||||
*
|
||||
* @throws IOException If the connection cannot be made.
|
||||
*/
|
||||
DccChat(PircBot bot, String nick, String login, String hostname, long address, int port) {
|
||||
_bot = bot;
|
||||
_address = address;
|
||||
_port = port;
|
||||
_nick = nick;
|
||||
_login = login;
|
||||
_hostname = hostname;
|
||||
_acceptable = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This constructor is used after we have issued a DCC CHAT request to
|
||||
* somebody. If the client accepts the chat request, then the socket we
|
||||
* obtain is passed to this constructor.
|
||||
*
|
||||
* @param bot An instance of the underlying PircBot.
|
||||
* @param sourceNick The nick of the user we are sending the request to.
|
||||
* @param socket The socket which will be used for the DCC CHAT session.
|
||||
*
|
||||
* @throws IOException If the socket cannot be read from.
|
||||
*/
|
||||
DccChat(PircBot bot, String nick, Socket socket) throws IOException {
|
||||
_bot = bot;
|
||||
_nick = nick;
|
||||
_socket = socket;
|
||||
_reader = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
|
||||
_writer = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream()));
|
||||
_acceptable = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Accept this DccChat connection.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
*/
|
||||
public synchronized void accept() throws IOException {
|
||||
if (_acceptable) {
|
||||
_acceptable = false;
|
||||
int[] ip = _bot.longToIp(_address);
|
||||
String ipStr = ip[0] + "." + ip[1] + "." + ip[2] + "." + ip[3];
|
||||
_socket = new Socket(ipStr, _port);
|
||||
_reader = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
|
||||
_writer = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads the next line of text from the client at the other end of our DCC Chat
|
||||
* connection. This method blocks until something can be returned.
|
||||
* If the connection has closed, null is returned.
|
||||
*
|
||||
* @return The next line of text from the client. Returns null if the
|
||||
* connection has closed normally.
|
||||
*
|
||||
* @throws IOException If an I/O error occurs.
|
||||
*/
|
||||
public String readLine() throws IOException {
|
||||
if (_acceptable) {
|
||||
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
|
||||
}
|
||||
return _reader.readLine();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends a line of text to the client at the other end of our DCC Chat
|
||||
* connection.
|
||||
*
|
||||
* @param line The line of text to be sent. This should not include
|
||||
* linefeed characters.
|
||||
*
|
||||
* @throws IOException If an I/O error occurs.
|
||||
*/
|
||||
public void sendLine(String line) throws IOException {
|
||||
if (_acceptable) {
|
||||
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
|
||||
}
|
||||
// No need for synchronization here really...
|
||||
_writer.write(line + "\r\n");
|
||||
_writer.flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes the DCC Chat connection.
|
||||
*
|
||||
* @throws IOException If an I/O error occurs.
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
if (_acceptable) {
|
||||
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
|
||||
}
|
||||
_socket.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the nick of the other user taking part in this file transfer.
|
||||
*
|
||||
* @return the nick of the other user.
|
||||
*
|
||||
*/
|
||||
public String getNick() {
|
||||
return _nick;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the login of the DCC Chat initiator.
|
||||
*
|
||||
* @return the login of the DCC Chat initiator. null if we sent it.
|
||||
*
|
||||
*/
|
||||
public String getLogin() {
|
||||
return _login;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the hostname of the DCC Chat initiator.
|
||||
*
|
||||
* @return the hostname of the DCC Chat initiator. null if we sent it.
|
||||
*
|
||||
*/
|
||||
public String getHostname() {
|
||||
return _hostname;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the BufferedReader used by this DCC Chat.
|
||||
*
|
||||
* @return the BufferedReader used by this DCC Chat.
|
||||
*/
|
||||
public BufferedReader getBufferedReader() {
|
||||
return _reader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the BufferedReader used by this DCC Chat.
|
||||
*
|
||||
* @return the BufferedReader used by this DCC Chat.
|
||||
*/
|
||||
public BufferedWriter getBufferedWriter() {
|
||||
return _writer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the raw Socket used by this DCC Chat.
|
||||
*
|
||||
* @return the raw Socket used by this DCC Chat.
|
||||
*/
|
||||
public Socket getSocket() {
|
||||
return _socket;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the address of the sender as a long.
|
||||
*
|
||||
* @return the address of the sender as a long.
|
||||
*/
|
||||
public long getNumericalAddress() {
|
||||
return _address;
|
||||
}
|
||||
|
||||
|
||||
private PircBot _bot;
|
||||
private String _nick;
|
||||
private String _login = null;
|
||||
private String _hostname = null;
|
||||
private BufferedReader _reader;
|
||||
private BufferedWriter _writer;
|
||||
private Socket _socket;
|
||||
private boolean _acceptable;
|
||||
private long _address = 0;
|
||||
private int _port = 0;
|
||||
|
||||
}
|
505
src/org/jibble/pircbot/DccFileTransfer.java
Normal file
@ -0,0 +1,505 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This class is used to administer a DCC file transfer.
|
||||
*
|
||||
* @since 1.2.0
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||
*/
|
||||
public class DccFileTransfer {
|
||||
|
||||
/**
|
||||
* The default buffer size to use when sending and receiving files.
|
||||
*/
|
||||
public static final int BUFFER_SIZE = 1024;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor used for receiving files.
|
||||
*/
|
||||
DccFileTransfer(PircBot bot, DccManager manager, String nick, String login, String hostname, String type, String filename, long address, int port, long size) {
|
||||
_bot = bot;
|
||||
_manager = manager;
|
||||
_nick = nick;
|
||||
_login = login;
|
||||
_hostname = hostname;
|
||||
_type = type;
|
||||
_file = new File(filename);
|
||||
_address = address;
|
||||
_port = port;
|
||||
_size = size;
|
||||
_received = false;
|
||||
|
||||
_incoming = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor used for sending files.
|
||||
*/
|
||||
DccFileTransfer(PircBot bot, DccManager manager, File file, String nick, int timeout) {
|
||||
_bot = bot;
|
||||
_manager = manager;
|
||||
_nick = nick;
|
||||
_file = file;
|
||||
_size = file.length();
|
||||
_timeout = timeout;
|
||||
_received = true;
|
||||
|
||||
_incoming = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Receives a DccFileTransfer and writes it to the specified file.
|
||||
* Resuming allows a partial download to be continue from the end of
|
||||
* the current file contents.
|
||||
*
|
||||
* @param file The file to write to.
|
||||
* @param resume True if you wish to try and resume the download instead
|
||||
* of overwriting an existing file.
|
||||
*
|
||||
*/
|
||||
public synchronized void receive(File file, boolean resume) {
|
||||
if (!_received) {
|
||||
_received = true;
|
||||
_file = file;
|
||||
|
||||
if (_type.equals("SEND") && resume) {
|
||||
_progress = file.length();
|
||||
if (_progress == 0) {
|
||||
doReceive(file, false);
|
||||
}
|
||||
else {
|
||||
_bot.sendCTCPCommand(_nick, "DCC RESUME file.ext " + _port + " " + _progress);
|
||||
_manager.addAwaitingResume(this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
_progress = file.length();
|
||||
doReceive(file, resume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Receive the file in a new thread.
|
||||
*/
|
||||
void doReceive(final File file, final boolean resume) {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
|
||||
BufferedOutputStream foutput = null;
|
||||
Exception exception = null;
|
||||
|
||||
try {
|
||||
|
||||
// Convert the integer address to a proper IP address.
|
||||
int[] ip = _bot.longToIp(_address);
|
||||
String ipStr = ip[0] + "." + ip[1] + "." + ip[2] + "." + ip[3];
|
||||
|
||||
// Connect the socket and set a timeout.
|
||||
_socket = new Socket(ipStr, _port);
|
||||
_socket.setSoTimeout(30*1000);
|
||||
_startTime = System.currentTimeMillis();
|
||||
|
||||
// No longer possible to resume this transfer once it's underway.
|
||||
_manager.removeAwaitingResume(DccFileTransfer.this);
|
||||
|
||||
BufferedInputStream input = new BufferedInputStream(_socket.getInputStream());
|
||||
BufferedOutputStream output = new BufferedOutputStream(_socket.getOutputStream());
|
||||
|
||||
// Following line fixed for jdk 1.1 compatibility.
|
||||
foutput = new BufferedOutputStream(new FileOutputStream(file.getCanonicalPath(), resume));
|
||||
|
||||
byte[] inBuffer = new byte[BUFFER_SIZE];
|
||||
byte[] outBuffer = new byte[4];
|
||||
int bytesRead = 0;
|
||||
while ((bytesRead = input.read(inBuffer, 0, inBuffer.length)) != -1) {
|
||||
foutput.write(inBuffer, 0, bytesRead);
|
||||
_progress += bytesRead;
|
||||
// Send back an acknowledgement of how many bytes we have got so far.
|
||||
outBuffer[0] = (byte) ((_progress >> 24) & 0xff);
|
||||
outBuffer[1] = (byte) ((_progress >> 16) & 0xff);
|
||||
outBuffer[2] = (byte) ((_progress >> 8) & 0xff);
|
||||
outBuffer[3] = (byte) ((_progress >> 0) & 0xff);
|
||||
output.write(outBuffer);
|
||||
output.flush();
|
||||
delay();
|
||||
}
|
||||
foutput.flush();
|
||||
}
|
||||
catch (Exception e) {
|
||||
exception = e;
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
foutput.close();
|
||||
_socket.close();
|
||||
}
|
||||
catch (Exception anye) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
_bot.onFileTransferFinished(DccFileTransfer.this, exception);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to send the file inside a new thread.
|
||||
*/
|
||||
void doSend(final boolean allowResume) {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
|
||||
BufferedInputStream finput = null;
|
||||
Exception exception = null;
|
||||
|
||||
try {
|
||||
|
||||
ServerSocket ss = null;
|
||||
|
||||
int[] ports = _bot.getDccPorts();
|
||||
if (ports == null) {
|
||||
// Use any free port.
|
||||
ss = new ServerSocket(0);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < ports.length; i++) {
|
||||
try {
|
||||
ss = new ServerSocket(ports[i]);
|
||||
// Found a port number we could use.
|
||||
break;
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Do nothing; go round and try another port.
|
||||
}
|
||||
}
|
||||
if (ss == null) {
|
||||
// No ports could be used.
|
||||
throw new IOException("All ports returned by getDccPorts() are in use.");
|
||||
}
|
||||
}
|
||||
|
||||
ss.setSoTimeout(_timeout);
|
||||
_port = ss.getLocalPort();
|
||||
InetAddress inetAddress = _bot.getDccInetAddress();
|
||||
if (inetAddress == null) {
|
||||
inetAddress = _bot.getInetAddress();
|
||||
}
|
||||
byte[] ip = inetAddress.getAddress();
|
||||
long ipNum = _bot.ipToLong(ip);
|
||||
|
||||
// Rename the filename so it has no whitespace in it when we send it.
|
||||
// .... I really should do this a bit more nicely at some point ....
|
||||
String safeFilename = _file.getName().replace(' ', '_');
|
||||
safeFilename = safeFilename.replace('\t', '_');
|
||||
|
||||
if (allowResume) {
|
||||
_manager.addAwaitingResume(DccFileTransfer.this);
|
||||
}
|
||||
|
||||
// Send the message to the user, telling them where to connect to in order to get the file.
|
||||
_bot.sendCTCPCommand(_nick, "DCC SEND " + safeFilename + " " + ipNum + " " + _port + " " + _file.length());
|
||||
|
||||
// The client may now connect to us and download the file.
|
||||
_socket = ss.accept();
|
||||
_socket.setSoTimeout(30000);
|
||||
_startTime = System.currentTimeMillis();
|
||||
|
||||
// No longer possible to resume this transfer once it's underway.
|
||||
if (allowResume) {
|
||||
_manager.removeAwaitingResume(DccFileTransfer.this);
|
||||
}
|
||||
|
||||
// Might as well close the server socket now; it's finished with.
|
||||
ss.close();
|
||||
|
||||
BufferedOutputStream output = new BufferedOutputStream(_socket.getOutputStream());
|
||||
BufferedInputStream input = new BufferedInputStream(_socket.getInputStream());
|
||||
finput = new BufferedInputStream(new FileInputStream(_file));
|
||||
|
||||
// Check for resuming.
|
||||
if (_progress > 0) {
|
||||
long bytesSkipped = 0;
|
||||
while (bytesSkipped < _progress) {
|
||||
bytesSkipped += finput.skip(_progress - bytesSkipped);
|
||||
}
|
||||
}
|
||||
|
||||
byte[] outBuffer = new byte[BUFFER_SIZE];
|
||||
byte[] inBuffer = new byte[4];
|
||||
int bytesRead = 0;
|
||||
while ((bytesRead = finput.read(outBuffer, 0, outBuffer.length)) != -1) {
|
||||
output.write(outBuffer, 0, bytesRead);
|
||||
output.flush();
|
||||
input.read(inBuffer, 0, inBuffer.length);
|
||||
_progress += bytesRead;
|
||||
delay();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
exception = e;
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
finput.close();
|
||||
_socket.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
_bot.onFileTransferFinished(DccFileTransfer.this, exception);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Package mutator for setting the progress of the file transfer.
|
||||
*/
|
||||
void setProgress(long progress) {
|
||||
_progress = progress;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delay between packets.
|
||||
*/
|
||||
private void delay() {
|
||||
if (_packetDelay > 0) {
|
||||
try {
|
||||
Thread.sleep(_packetDelay);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the nick of the other user taking part in this file transfer.
|
||||
*
|
||||
* @return the nick of the other user.
|
||||
*
|
||||
*/
|
||||
public String getNick() {
|
||||
return _nick;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the login of the file sender.
|
||||
*
|
||||
* @return the login of the file sender. null if we are sending.
|
||||
*
|
||||
*/
|
||||
public String getLogin() {
|
||||
return _login;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the hostname of the file sender.
|
||||
*
|
||||
* @return the hostname of the file sender. null if we are sending.
|
||||
*
|
||||
*/
|
||||
public String getHostname() {
|
||||
return _hostname;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the suggested file to be used for this transfer.
|
||||
*
|
||||
* @return the suggested file to be used.
|
||||
*
|
||||
*/
|
||||
public File getFile() {
|
||||
return _file;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the port number to be used when making the connection.
|
||||
*
|
||||
* @return the port number.
|
||||
*
|
||||
*/
|
||||
public int getPort() {
|
||||
return _port;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the file transfer is incoming (somebody is sending
|
||||
* the file to us).
|
||||
*
|
||||
* @return true if the file transfer is incoming.
|
||||
*
|
||||
*/
|
||||
public boolean isIncoming() {
|
||||
return _incoming;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the file transfer is outgoing (we are sending the
|
||||
* file to someone).
|
||||
*
|
||||
* @return true if the file transfer is outgoing.
|
||||
*
|
||||
*/
|
||||
public boolean isOutgoing() {
|
||||
return !isIncoming();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the delay time between sending or receiving each packet.
|
||||
* Default is 0.
|
||||
* This is useful for throttling the speed of file transfers to maintain
|
||||
* a good quality of service for other things on the machine or network.
|
||||
*
|
||||
* @param millis The number of milliseconds to wait between packets.
|
||||
*
|
||||
*/
|
||||
public void setPacketDelay(long millis) {
|
||||
_packetDelay = millis;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns the delay time between each packet that is send or received.
|
||||
*
|
||||
* @return the delay between each packet.
|
||||
*
|
||||
*/
|
||||
public long getPacketDelay() {
|
||||
return _packetDelay;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the size (in bytes) of the file being transfered.
|
||||
*
|
||||
* @return the size of the file. Returns -1 if the sender did not
|
||||
* specify this value.
|
||||
*/
|
||||
public long getSize() {
|
||||
return _size;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the progress (in bytes) of the current file transfer.
|
||||
* When resuming, this represents the total number of bytes in the
|
||||
* file, which may be greater than the amount of bytes resumed in
|
||||
* just this transfer.
|
||||
*
|
||||
* @return the progress of the transfer.
|
||||
*/
|
||||
public long getProgress() {
|
||||
return _progress;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the progress of the file transfer as a percentage.
|
||||
* Note that this should never be negative, but could become
|
||||
* greater than 100% if you attempt to resume a larger file
|
||||
* onto a partially downloaded file that was smaller.
|
||||
*
|
||||
* @return the progress of the transfer as a percentage.
|
||||
*/
|
||||
public double getProgressPercentage() {
|
||||
return 100 * (getProgress() / (double) getSize());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stops the DCC file transfer by closing the connection.
|
||||
*/
|
||||
public void close() {
|
||||
try {
|
||||
_socket.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Let the DCC manager worry about anything that may go wrong.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the rate of data transfer in bytes per second.
|
||||
* This value is an estimate based on the number of bytes
|
||||
* transfered since the connection was established.
|
||||
*
|
||||
* @return data transfer rate in bytes per second.
|
||||
*/
|
||||
public long getTransferRate() {
|
||||
long time = (System.currentTimeMillis() - _startTime) / 1000;
|
||||
if (time <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return getProgress() / time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the address of the sender as a long.
|
||||
*
|
||||
* @return the address of the sender as a long.
|
||||
*/
|
||||
public long getNumericalAddress() {
|
||||
return _address;
|
||||
}
|
||||
|
||||
|
||||
private PircBot _bot;
|
||||
private DccManager _manager;
|
||||
private String _nick;
|
||||
private String _login = null;
|
||||
private String _hostname = null;
|
||||
private String _type;
|
||||
private long _address;
|
||||
private int _port;
|
||||
private long _size;
|
||||
private boolean _received;
|
||||
|
||||
private Socket _socket = null;
|
||||
private long _progress = 0;
|
||||
private File _file = null;
|
||||
private int _timeout = 0;
|
||||
private boolean _incoming;
|
||||
private long _packetDelay = 0;
|
||||
|
||||
private long _startTime = 0;
|
||||
|
||||
}
|
151
src/org/jibble/pircbot/DccManager.java
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class is used to process DCC events from the server.
|
||||
*
|
||||
* @since 1.2.0
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||
*/
|
||||
public class DccManager {
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a DccManager to look after all DCC SEND and CHAT events.
|
||||
*
|
||||
* @param bot The PircBot whose DCC events this class will handle.
|
||||
*/
|
||||
DccManager(PircBot bot) {
|
||||
_bot = bot;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes a DCC request.
|
||||
*
|
||||
* @return True if the type of request was handled successfully.
|
||||
*/
|
||||
boolean processRequest(String nick, String login, String hostname, String request) {
|
||||
StringTokenizer tokenizer = new StringTokenizer(request);
|
||||
tokenizer.nextToken();
|
||||
String type = tokenizer.nextToken();
|
||||
String filename = tokenizer.nextToken();
|
||||
|
||||
if (type.equals("SEND")) {
|
||||
long address = Long.parseLong(tokenizer.nextToken());
|
||||
int port = Integer.parseInt(tokenizer.nextToken());
|
||||
long size = -1;
|
||||
try {
|
||||
size = Long.parseLong(tokenizer.nextToken());
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Stick with the old value.
|
||||
}
|
||||
|
||||
DccFileTransfer transfer = new DccFileTransfer(_bot, this, nick, login, hostname, type, filename, address, port, size);
|
||||
_bot.onIncomingFileTransfer(transfer);
|
||||
|
||||
}
|
||||
else if (type.equals("RESUME")) {
|
||||
int port = Integer.parseInt(tokenizer.nextToken());
|
||||
long progress = Long.parseLong(tokenizer.nextToken());
|
||||
|
||||
DccFileTransfer transfer = null;
|
||||
synchronized (_awaitingResume) {
|
||||
for (int i = 0; i < _awaitingResume.size(); i++) {
|
||||
transfer = (DccFileTransfer) _awaitingResume.elementAt(i);
|
||||
if (transfer.getNick().equals(nick) && transfer.getPort() == port) {
|
||||
_awaitingResume.removeElementAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (transfer != null) {
|
||||
transfer.setProgress(progress);
|
||||
_bot.sendCTCPCommand(nick, "DCC ACCEPT file.ext " + port + " " + progress);
|
||||
}
|
||||
|
||||
}
|
||||
else if (type.equals("ACCEPT")) {
|
||||
int port = Integer.parseInt(tokenizer.nextToken());
|
||||
long progress = Long.parseLong(tokenizer.nextToken());
|
||||
|
||||
DccFileTransfer transfer = null;
|
||||
synchronized (_awaitingResume) {
|
||||
for (int i = 0; i < _awaitingResume.size(); i++) {
|
||||
transfer = (DccFileTransfer) _awaitingResume.elementAt(i);
|
||||
if (transfer.getNick().equals(nick) && transfer.getPort() == port) {
|
||||
_awaitingResume.removeElementAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (transfer != null) {
|
||||
transfer.doReceive(transfer.getFile(), true);
|
||||
}
|
||||
|
||||
}
|
||||
else if (type.equals("CHAT")) {
|
||||
long address = Long.parseLong(tokenizer.nextToken());
|
||||
int port = Integer.parseInt(tokenizer.nextToken());
|
||||
|
||||
final DccChat chat = new DccChat(_bot, nick, login, hostname, address, port);
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
_bot.onIncomingChatRequest(chat);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add this DccFileTransfer to the list of those awaiting possible
|
||||
* resuming.
|
||||
*
|
||||
* @param transfer the DccFileTransfer that may be resumed.
|
||||
*/
|
||||
void addAwaitingResume(DccFileTransfer transfer) {
|
||||
synchronized (_awaitingResume) {
|
||||
_awaitingResume.addElement(transfer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove this transfer from the list of those awaiting resuming.
|
||||
*/
|
||||
void removeAwaitingResume(DccFileTransfer transfer) {
|
||||
_awaitingResume.removeElement(transfer);
|
||||
}
|
||||
|
||||
|
||||
private PircBot _bot;
|
||||
private Vector _awaitingResume = new Vector();
|
||||
|
||||
}
|
119
src/org/jibble/pircbot/IdentServer.java
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* A simple IdentServer (also know as "The Identification Protocol").
|
||||
* An ident server provides a means to determine the identity of a
|
||||
* user of a particular TCP connection.
|
||||
* <p>
|
||||
* Most IRC servers attempt to contact the ident server on connecting
|
||||
* hosts in order to determine the user's identity. A few IRC servers
|
||||
* will not allow you to connect unless this information is provided.
|
||||
* <p>
|
||||
* So when a PircBot is run on a machine that does not run an ident server,
|
||||
* it may be necessary to provide a "faked" response by starting up its
|
||||
* own ident server and sending out apparently correct responses.
|
||||
* <p>
|
||||
* An instance of this class can be used to start up an ident server
|
||||
* only if it is possible to do so. Reasons for not being able to do
|
||||
* so are if there is already an ident server running on port 113, or
|
||||
* if you are running as an unprivileged user who is unable to create
|
||||
* a server socket on that port number.
|
||||
*
|
||||
* @since 0.9c
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||
*/
|
||||
public class IdentServer extends Thread {
|
||||
|
||||
/**
|
||||
* Constructs and starts an instance of an IdentServer that will
|
||||
* respond to a client with the provided login. Rather than calling
|
||||
* this constructor explicitly from your code, it is recommended that
|
||||
* you use the startIdentServer method in the PircBot class.
|
||||
* <p>
|
||||
* The ident server will wait for up to 60 seconds before shutting
|
||||
* down. Otherwise, it will shut down as soon as it has responded
|
||||
* to an ident request.
|
||||
*
|
||||
* @param bot The PircBot instance that will be used to log to.
|
||||
* @param login The login that the ident server will respond with.
|
||||
*/
|
||||
IdentServer(PircBot bot, String login) {
|
||||
_bot = bot;
|
||||
_login = login;
|
||||
|
||||
try {
|
||||
_ss = new ServerSocket(113);
|
||||
_ss.setSoTimeout(60000);
|
||||
}
|
||||
catch (Exception e) {
|
||||
_bot.log("*** Could not start the ident server on port 113.");
|
||||
return;
|
||||
}
|
||||
|
||||
_bot.log("*** Ident server running on port 113 for the next 60 seconds...");
|
||||
this.setName(this.getClass() + "-Thread");
|
||||
this.start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Waits for a client to connect to the ident server before making an
|
||||
* appropriate response. Note that this method is started by the class
|
||||
* constructor.
|
||||
*/
|
||||
public void run() {
|
||||
try {
|
||||
Socket socket = _ss.accept();
|
||||
socket.setSoTimeout(60000);
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
|
||||
|
||||
String line = reader.readLine();
|
||||
if (line != null) {
|
||||
_bot.log("*** Ident request received: " + line);
|
||||
line = line + " : USERID : UNIX : " + _login;
|
||||
writer.write(line + "\r\n");
|
||||
writer.flush();
|
||||
_bot.log("*** Ident reply sent: " + line);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// We're not really concerned with what went wrong, are we?
|
||||
}
|
||||
|
||||
try {
|
||||
_ss.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Doesn't really matter...
|
||||
}
|
||||
|
||||
_bot.log("*** The Ident server has been shut down.");
|
||||
}
|
||||
|
||||
private PircBot _bot;
|
||||
private String _login;
|
||||
private ServerSocket _ss = null;
|
||||
|
||||
}
|
169
src/org/jibble/pircbot/InputThread.java
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A Thread which reads lines from the IRC server. It then
|
||||
* passes these lines to the PircBot without changing them.
|
||||
* This running Thread also detects disconnection from the server
|
||||
* and is thus used by the OutputThread to send lines to the server.
|
||||
*
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||
*/
|
||||
public class InputThread extends Thread {
|
||||
|
||||
/**
|
||||
* The InputThread reads lines from the IRC server and allows the
|
||||
* PircBot to handle them.
|
||||
*
|
||||
* @param bot An instance of the underlying PircBot.
|
||||
* @param breader The BufferedReader that reads lines from the server.
|
||||
* @param bwriter The BufferedWriter that sends lines to the server.
|
||||
*/
|
||||
InputThread(PircBot bot, Socket socket, BufferedReader breader, BufferedWriter bwriter) {
|
||||
_bot = bot;
|
||||
_socket = socket;
|
||||
_breader = breader;
|
||||
_bwriter = bwriter;
|
||||
this.setName(this.getClass() + "-Thread");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends a raw line to the IRC server as soon as possible, bypassing the
|
||||
* outgoing message queue.
|
||||
*
|
||||
* @param line The raw line to send to the IRC server.
|
||||
*/
|
||||
void sendRawLine(String line) {
|
||||
OutputThread.sendRawLine(_bot, _bwriter, line);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this InputThread is connected to an IRC server.
|
||||
* The result of this method should only act as a rough guide,
|
||||
* as the result may not be valid by the time you act upon it.
|
||||
*
|
||||
* @return True if still connected.
|
||||
*/
|
||||
boolean isConnected() {
|
||||
return _isConnected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called to start this Thread reading lines from the IRC server.
|
||||
* When a line is read, this method calls the handleLine method
|
||||
* in the PircBot, which may subsequently call an 'onXxx' method
|
||||
* in the PircBot subclass. If any subclass of Throwable (i.e.
|
||||
* any Exception or Error) is thrown by your method, then this
|
||||
* method will print the stack trace to the standard output. It
|
||||
* is probable that the PircBot may still be functioning normally
|
||||
* after such a problem, but the existance of any uncaught exceptions
|
||||
* in your code is something you should really fix.
|
||||
*/
|
||||
public void run() {
|
||||
try {
|
||||
boolean running = true;
|
||||
while (running) {
|
||||
try {
|
||||
String line = null;
|
||||
while ((line = _breader.readLine()) != null) {
|
||||
try {
|
||||
_bot.handleLine(line);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
// Stick the whole stack trace into a String so we can output it nicely.
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
t.printStackTrace(pw);
|
||||
pw.flush();
|
||||
StringTokenizer tokenizer = new StringTokenizer(sw.toString(), "\r\n");
|
||||
synchronized (_bot) {
|
||||
_bot.log("### Your implementation of PircBot is faulty and you have");
|
||||
_bot.log("### allowed an uncaught Exception or Error to propagate in your");
|
||||
_bot.log("### code. It may be possible for PircBot to continue operating");
|
||||
_bot.log("### normally. Here is the stack trace that was produced: -");
|
||||
_bot.log("### ");
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
_bot.log("### " + tokenizer.nextToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (line == null) {
|
||||
// The server must have disconnected us.
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
catch (InterruptedIOException iioe) {
|
||||
// This will happen if we haven't received anything from the server for a while.
|
||||
// So we shall send it a ping to check that we are still connected.
|
||||
this.sendRawLine("PING " + (System.currentTimeMillis() / 1000));
|
||||
// Now we go back to listening for stuff from the server...
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
// If we reach this point, then we must have disconnected.
|
||||
try {
|
||||
_socket.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Just assume the socket was already closed.
|
||||
}
|
||||
|
||||
if (!_disposed) {
|
||||
_bot.log("*** Disconnected.");
|
||||
_isConnected = false;
|
||||
_bot.onDisconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes the socket without onDisconnect being called subsequently.
|
||||
*/
|
||||
public void dispose () {
|
||||
try {
|
||||
_disposed = true;
|
||||
_socket.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
private PircBot _bot = null;
|
||||
private Socket _socket = null;
|
||||
private BufferedReader _breader = null;
|
||||
private BufferedWriter _bwriter = null;
|
||||
private boolean _isConnected = true;
|
||||
private boolean _disposed = false;
|
||||
|
||||
public static final int MAX_LINE_LENGTH = 512;
|
||||
|
||||
}
|
35
src/org/jibble/pircbot/IrcException.java
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
/**
|
||||
* An IrcException class.
|
||||
*
|
||||
* @since 0.9
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||
*/
|
||||
public class IrcException extends Exception {
|
||||
|
||||
/**
|
||||
* Constructs a new IrcException.
|
||||
*
|
||||
* @param e The error message to report.
|
||||
*/
|
||||
public IrcException(String e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
}
|
38
src/org/jibble/pircbot/NickAlreadyInUseException.java
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
/**
|
||||
* A NickAlreadyInUseException class. This exception is
|
||||
* thrown when the PircBot attempts to join an IRC server
|
||||
* with a user name that is already in use.
|
||||
*
|
||||
* @since 0.9
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||
*/
|
||||
public class NickAlreadyInUseException extends IrcException {
|
||||
|
||||
/**
|
||||
* Constructs a new IrcException.
|
||||
*
|
||||
* @param e The error message to report.
|
||||
*/
|
||||
public NickAlreadyInUseException(String e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
}
|
105
src/org/jibble/pircbot/OutputThread.java
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
* A Thread which is responsible for sending messages to the IRC server.
|
||||
* Messages are obtained from the outgoing message queue and sent
|
||||
* immediately if possible. If there is a flood of messages, then to
|
||||
* avoid getting kicked from a channel, we put a small delay between
|
||||
* each one.
|
||||
*
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||
*/
|
||||
public class OutputThread extends Thread {
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an OutputThread for the underlying PircBot. All messages
|
||||
* sent to the IRC server are sent by this OutputThread to avoid hammering
|
||||
* the server. Messages are sent immediately if possible. If there are
|
||||
* multiple messages queued, then there is a delay imposed.
|
||||
*
|
||||
* @param bot The underlying PircBot instance.
|
||||
* @param outQueue The Queue from which we will obtain our messages.
|
||||
*/
|
||||
OutputThread(PircBot bot, Queue outQueue) {
|
||||
_bot = bot;
|
||||
_outQueue = outQueue;
|
||||
this.setName(this.getClass() + "-Thread");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A static method to write a line to a BufferedOutputStream and then pass
|
||||
* the line to the log method of the supplied PircBot instance.
|
||||
*
|
||||
* @param bot The underlying PircBot instance.
|
||||
* @param out The BufferedOutputStream to write to.
|
||||
* @param line The line to be written. "\r\n" is appended to the end.
|
||||
* @param encoding The charset to use when encoing this string into a
|
||||
* byte array.
|
||||
*/
|
||||
static void sendRawLine(PircBot bot, BufferedWriter bwriter, String line) {
|
||||
if (line.length() > bot.getMaxLineLength() - 2) {
|
||||
line = line.substring(0, bot.getMaxLineLength() - 2);
|
||||
}
|
||||
synchronized(bwriter) {
|
||||
try {
|
||||
bwriter.write(line + "\r\n");
|
||||
bwriter.flush();
|
||||
bot.log(">>>" + line);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Silent response - just lose the line.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method starts the Thread consuming from the outgoing message
|
||||
* Queue and sending lines to the server.
|
||||
*/
|
||||
public void run() {
|
||||
try {
|
||||
boolean running = true;
|
||||
while (running) {
|
||||
// Small delay to prevent spamming of the channel
|
||||
Thread.sleep(_bot.getMessageDelay());
|
||||
|
||||
String line = (String) _outQueue.next();
|
||||
if (line != null) {
|
||||
_bot.sendRawLine(line);
|
||||
}
|
||||
else {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
// Just let the method return naturally...
|
||||
}
|
||||
}
|
||||
|
||||
private PircBot _bot = null;
|
||||
private Queue _outQueue = null;
|
||||
|
||||
}
|
3098
src/org/jibble/pircbot/PircBot.java
Normal file
146
src/org/jibble/pircbot/Queue.java
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Queue is a definition of a data structure that may
|
||||
* act as a queue - that is, data can be added to one end of the
|
||||
* queue and data can be requested from the head end of the queue.
|
||||
* This class is thread safe for multiple producers and a single
|
||||
* consumer. The next() method will block until there is data in
|
||||
* the queue.
|
||||
*
|
||||
* This has now been modified so that it is compatible with
|
||||
* the earlier JDK1.1 in order to be suitable for running on
|
||||
* mobile appliances. This means replacing the LinkedList with
|
||||
* a Vector, which is hardly ideal, but this Queue is typically
|
||||
* only polled every second before dispatching messages.
|
||||
*
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||
*/
|
||||
public class Queue {
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a Queue object of unlimited size.
|
||||
*/
|
||||
public Queue() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds an Object to the end of the Queue.
|
||||
*
|
||||
* @param o The Object to be added to the Queue.
|
||||
*/
|
||||
public void add(Object o) {
|
||||
synchronized(_queue) {
|
||||
_queue.addElement(o);
|
||||
_queue.notify();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds an Object to the front of the Queue.
|
||||
*
|
||||
* @param o The Object to be added to the Queue.
|
||||
*/
|
||||
public void addFront(Object o) {
|
||||
synchronized(_queue) {
|
||||
_queue.insertElementAt(o, 0);
|
||||
_queue.notify();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Object at the front of the Queue. This
|
||||
* Object is then removed from the Queue. If the Queue
|
||||
* is empty, then this method shall block until there
|
||||
* is an Object in the Queue to return.
|
||||
*
|
||||
* @return The next item from the front of the queue.
|
||||
*/
|
||||
public Object next() {
|
||||
|
||||
Object o = null;
|
||||
|
||||
// Block if the Queue is empty.
|
||||
synchronized(_queue) {
|
||||
if (_queue.size() == 0) {
|
||||
try {
|
||||
_queue.wait();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the Object.
|
||||
try {
|
||||
o = _queue.firstElement();
|
||||
_queue.removeElementAt(0);
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new InternalError("Race hazard in Queue object.");
|
||||
}
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the Queue is not empty. If another
|
||||
* Thread empties the Queue before <b>next()</b> is
|
||||
* called, then the call to <b>next()</b> shall block
|
||||
* until the Queue has been populated again.
|
||||
*
|
||||
* @return True only if the Queue not empty.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return (this.size() != 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clears the contents of the Queue.
|
||||
*/
|
||||
public void clear() {
|
||||
synchronized(_queue) {
|
||||
_queue.removeAllElements();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the size of the Queue.
|
||||
*
|
||||
* @return The current size of the queue.
|
||||
*/
|
||||
public int size() {
|
||||
return _queue.size();
|
||||
}
|
||||
|
||||
|
||||
private Vector _queue = new Vector();
|
||||
|
||||
}
|
176
src/org/jibble/pircbot/ReplyConstants.java
Normal file
@ -0,0 +1,176 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
/**
|
||||
* This interface contains the values of all numeric replies specified
|
||||
* in section 6 of RFC 1459. Refer to RFC 1459 for further information.
|
||||
* <p>
|
||||
* If you override the onServerResponse method in the PircBot class,
|
||||
* you may find these constants useful when comparing the numeric
|
||||
* value of a given code.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||
*/
|
||||
public interface ReplyConstants {
|
||||
|
||||
|
||||
// Error Replies.
|
||||
public static final int ERR_NOSUCHNICK = 401;
|
||||
public static final int ERR_NOSUCHSERVER = 402;
|
||||
public static final int ERR_NOSUCHCHANNEL = 403;
|
||||
public static final int ERR_CANNOTSENDTOCHAN = 404;
|
||||
public static final int ERR_TOOMANYCHANNELS = 405;
|
||||
public static final int ERR_WASNOSUCHNICK = 406;
|
||||
public static final int ERR_TOOMANYTARGETS = 407;
|
||||
public static final int ERR_NOORIGIN = 409;
|
||||
public static final int ERR_NORECIPIENT = 411;
|
||||
public static final int ERR_NOTEXTTOSEND = 412;
|
||||
public static final int ERR_NOTOPLEVEL = 413;
|
||||
public static final int ERR_WILDTOPLEVEL = 414;
|
||||
public static final int ERR_UNKNOWNCOMMAND = 421;
|
||||
public static final int ERR_NOMOTD = 422;
|
||||
public static final int ERR_NOADMININFO = 423;
|
||||
public static final int ERR_FILEERROR = 424;
|
||||
public static final int ERR_NONICKNAMEGIVEN = 431;
|
||||
public static final int ERR_ERRONEUSNICKNAME = 432;
|
||||
public static final int ERR_NICKNAMEINUSE = 433;
|
||||
public static final int ERR_NICKCOLLISION = 436;
|
||||
public static final int ERR_USERNOTINCHANNEL = 441;
|
||||
public static final int ERR_NOTONCHANNEL = 442;
|
||||
public static final int ERR_USERONCHANNEL = 443;
|
||||
public static final int ERR_NOLOGIN = 444;
|
||||
public static final int ERR_SUMMONDISABLED = 445;
|
||||
public static final int ERR_USERSDISABLED = 446;
|
||||
public static final int ERR_NOTREGISTERED = 451;
|
||||
public static final int ERR_NEEDMOREPARAMS = 461;
|
||||
public static final int ERR_ALREADYREGISTRED = 462;
|
||||
public static final int ERR_NOPERMFORHOST = 463;
|
||||
public static final int ERR_PASSWDMISMATCH = 464;
|
||||
public static final int ERR_YOUREBANNEDCREEP = 465;
|
||||
public static final int ERR_KEYSET = 467;
|
||||
public static final int ERR_CHANNELISFULL = 471;
|
||||
public static final int ERR_UNKNOWNMODE = 472;
|
||||
public static final int ERR_INVITEONLYCHAN = 473;
|
||||
public static final int ERR_BANNEDFROMCHAN = 474;
|
||||
public static final int ERR_BADCHANNELKEY = 475;
|
||||
public static final int ERR_NOPRIVILEGES = 481;
|
||||
public static final int ERR_CHANOPRIVSNEEDED = 482;
|
||||
public static final int ERR_CANTKILLSERVER = 483;
|
||||
public static final int ERR_NOOPERHOST = 491;
|
||||
public static final int ERR_UMODEUNKNOWNFLAG = 501;
|
||||
public static final int ERR_USERSDONTMATCH = 502;
|
||||
|
||||
|
||||
// Command Responses.
|
||||
public static final int RPL_TRACELINK = 200;
|
||||
public static final int RPL_TRACECONNECTING = 201;
|
||||
public static final int RPL_TRACEHANDSHAKE = 202;
|
||||
public static final int RPL_TRACEUNKNOWN = 203;
|
||||
public static final int RPL_TRACEOPERATOR = 204;
|
||||
public static final int RPL_TRACEUSER = 205;
|
||||
public static final int RPL_TRACESERVER = 206;
|
||||
public static final int RPL_TRACENEWTYPE = 208;
|
||||
public static final int RPL_STATSLINKINFO = 211;
|
||||
public static final int RPL_STATSCOMMANDS = 212;
|
||||
public static final int RPL_STATSCLINE = 213;
|
||||
public static final int RPL_STATSNLINE = 214;
|
||||
public static final int RPL_STATSILINE = 215;
|
||||
public static final int RPL_STATSKLINE = 216;
|
||||
public static final int RPL_STATSYLINE = 218;
|
||||
public static final int RPL_ENDOFSTATS = 219;
|
||||
public static final int RPL_UMODEIS = 221;
|
||||
public static final int RPL_STATSLLINE = 241;
|
||||
public static final int RPL_STATSUPTIME = 242;
|
||||
public static final int RPL_STATSOLINE = 243;
|
||||
public static final int RPL_STATSHLINE = 244;
|
||||
public static final int RPL_LUSERCLIENT = 251;
|
||||
public static final int RPL_LUSEROP = 252;
|
||||
public static final int RPL_LUSERUNKNOWN = 253;
|
||||
public static final int RPL_LUSERCHANNELS = 254;
|
||||
public static final int RPL_LUSERME = 255;
|
||||
public static final int RPL_ADMINME = 256;
|
||||
public static final int RPL_ADMINLOC1 = 257;
|
||||
public static final int RPL_ADMINLOC2 = 258;
|
||||
public static final int RPL_ADMINEMAIL = 259;
|
||||
public static final int RPL_TRACELOG = 261;
|
||||
public static final int RPL_NONE = 300;
|
||||
public static final int RPL_AWAY = 301;
|
||||
public static final int RPL_USERHOST = 302;
|
||||
public static final int RPL_ISON = 303;
|
||||
public static final int RPL_UNAWAY = 305;
|
||||
public static final int RPL_NOWAWAY = 306;
|
||||
public static final int RPL_WHOISUSER = 311;
|
||||
public static final int RPL_WHOISSERVER = 312;
|
||||
public static final int RPL_WHOISOPERATOR = 313;
|
||||
public static final int RPL_WHOWASUSER = 314;
|
||||
public static final int RPL_ENDOFWHO = 315;
|
||||
public static final int RPL_WHOISIDLE = 317;
|
||||
public static final int RPL_ENDOFWHOIS = 318;
|
||||
public static final int RPL_WHOISCHANNELS = 319;
|
||||
public static final int RPL_LISTSTART = 321;
|
||||
public static final int RPL_LIST = 322;
|
||||
public static final int RPL_LISTEND = 323;
|
||||
public static final int RPL_CHANNELMODEIS = 324;
|
||||
public static final int RPL_NOTOPIC = 331;
|
||||
public static final int RPL_TOPIC = 332;
|
||||
public static final int RPL_TOPICINFO = 333;
|
||||
public static final int RPL_INVITING = 341;
|
||||
public static final int RPL_SUMMONING = 342;
|
||||
public static final int RPL_VERSION = 351;
|
||||
public static final int RPL_WHOREPLY = 352;
|
||||
public static final int RPL_NAMREPLY = 353;
|
||||
public static final int RPL_LINKS = 364;
|
||||
public static final int RPL_ENDOFLINKS = 365;
|
||||
public static final int RPL_ENDOFNAMES = 366;
|
||||
public static final int RPL_BANLIST = 367;
|
||||
public static final int RPL_ENDOFBANLIST = 368;
|
||||
public static final int RPL_ENDOFWHOWAS = 369;
|
||||
public static final int RPL_INFO = 371;
|
||||
public static final int RPL_MOTD = 372;
|
||||
public static final int RPL_ENDOFINFO = 374;
|
||||
public static final int RPL_MOTDSTART = 375;
|
||||
public static final int RPL_ENDOFMOTD = 376;
|
||||
public static final int RPL_YOUREOPER = 381;
|
||||
public static final int RPL_REHASHING = 382;
|
||||
public static final int RPL_TIME = 391;
|
||||
public static final int RPL_USERSSTART = 392;
|
||||
public static final int RPL_USERS = 393;
|
||||
public static final int RPL_ENDOFUSERS = 394;
|
||||
public static final int RPL_NOUSERS = 395;
|
||||
|
||||
|
||||
// Reserved Numerics.
|
||||
public static final int RPL_TRACECLASS = 209;
|
||||
public static final int RPL_STATSQLINE = 217;
|
||||
public static final int RPL_SERVICEINFO = 231;
|
||||
public static final int RPL_ENDOFSERVICES = 232;
|
||||
public static final int RPL_SERVICE = 233;
|
||||
public static final int RPL_SERVLIST = 234;
|
||||
public static final int RPL_SERVLISTEND = 235;
|
||||
public static final int RPL_WHOISCHANOP = 316;
|
||||
public static final int RPL_KILLDONE = 361;
|
||||
public static final int RPL_CLOSING = 362;
|
||||
public static final int RPL_CLOSEEND = 363;
|
||||
public static final int RPL_INFOSTART = 373;
|
||||
public static final int RPL_MYPORTIS = 384;
|
||||
public static final int ERR_YOUWILLBEBANNED = 466;
|
||||
public static final int ERR_BADCHANMASK = 476;
|
||||
public static final int ERR_NOSERVICEHOST = 492;
|
||||
|
||||
}
|
161
src/org/jibble/pircbot/User.java
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
/**
|
||||
* This class is used to represent a user on an IRC server.
|
||||
* Instances of this class are returned by the getUsers method
|
||||
* in the PircBot class.
|
||||
* <p>
|
||||
* Note that this class no longer implements the Comparable interface
|
||||
* for Java 1.1 compatibility reasons.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||
*/
|
||||
public class User {
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a User object with a known prefix and nick.
|
||||
*
|
||||
* @param prefix The status of the user, for example, "@".
|
||||
* @param nick The nick of the user.
|
||||
*/
|
||||
User(String prefix, String nick) {
|
||||
_prefix = prefix;
|
||||
_nick = nick;
|
||||
_lowerNick = nick.toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the prefix of the user. If the User object has been obtained
|
||||
* from a list of users in a channel, then this will reflect the user's
|
||||
* status in that channel.
|
||||
*
|
||||
* @return The prefix of the user. If there is no prefix, then an empty
|
||||
* String is returned.
|
||||
*/
|
||||
public String getPrefix() {
|
||||
return _prefix;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether or not the user represented by this object is an
|
||||
* operator. If the User object has been obtained from a list of users
|
||||
* in a channel, then this will reflect the user's operator status in
|
||||
* that channel.
|
||||
*
|
||||
* @return true if the user is an operator in the channel.
|
||||
*/
|
||||
public boolean isOp() {
|
||||
return _prefix.indexOf('@') >= 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether or not the user represented by this object has
|
||||
* voice. If the User object has been obtained from a list of users
|
||||
* in a channel, then this will reflect the user's voice status in
|
||||
* that channel.
|
||||
*
|
||||
* @return true if the user has voice in the channel.
|
||||
*/
|
||||
public boolean hasVoice() {
|
||||
return _prefix.indexOf('+') >= 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the nick of the user.
|
||||
*
|
||||
* @return The user's nick.
|
||||
*/
|
||||
public String getNick() {
|
||||
return _nick;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the nick of the user complete with their prefix if they
|
||||
* have one, e.g. "@Dave".
|
||||
*
|
||||
* @return The user's prefix and nick.
|
||||
*/
|
||||
public String toString() {
|
||||
return this.getPrefix() + this.getNick();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the nick represented by this User object is the same
|
||||
* as the argument. A case insensitive comparison is made.
|
||||
*
|
||||
* @return true if the nicks are identical (case insensitive).
|
||||
*/
|
||||
public boolean equals(String nick) {
|
||||
return nick.toLowerCase().equals(_lowerNick);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the nick represented by this User object is the same
|
||||
* as the nick of the User object given as an argument.
|
||||
* A case insensitive comparison is made.
|
||||
*
|
||||
* @return true if o is a User object with a matching lowercase nick.
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof User) {
|
||||
User other = (User) o;
|
||||
return other._lowerNick.equals(_lowerNick);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the hash code of this User object.
|
||||
*
|
||||
* @return the hash code of the User object.
|
||||
*/
|
||||
public int hashCode() {
|
||||
return _lowerNick.hashCode();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the result of calling the compareTo method on lowercased
|
||||
* nicks. This is useful for sorting lists of User objects.
|
||||
*
|
||||
* @return the result of calling compareTo on lowercased nicks.
|
||||
*/
|
||||
public int compareTo(Object o) {
|
||||
if (o instanceof User) {
|
||||
User other = (User) o;
|
||||
return other._lowerNick.compareTo(_lowerNick);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
private String _prefix;
|
||||
private String _nick;
|
||||
private String _lowerNick;
|
||||
|
||||
}
|
116
src/org/yaaic/Yaaic.java
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.yaaic.model.Server;
|
||||
|
||||
/**
|
||||
* Global Master Class :)
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class Yaaic
|
||||
{
|
||||
public static Yaaic instance;
|
||||
|
||||
private HashMap<Integer, Server> servers;
|
||||
|
||||
/**
|
||||
* Private constructor, you may want to use static getInstance()
|
||||
*/
|
||||
private Yaaic()
|
||||
{
|
||||
servers = new HashMap<Integer, Server>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global Yaaic instance
|
||||
*
|
||||
* @return the global Yaaic instance
|
||||
*/
|
||||
public static Yaaic getInstance()
|
||||
{
|
||||
if (instance == null) {
|
||||
instance = new Yaaic();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get server by id
|
||||
*
|
||||
* @return Server object with given unique id
|
||||
*/
|
||||
public Server getServerById(int serverId)
|
||||
{
|
||||
return servers.get(serverId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove server with given unique id from list
|
||||
*
|
||||
* @param serverId
|
||||
*/
|
||||
public void removeServerById(int serverId)
|
||||
{
|
||||
servers.remove(serverId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set servers
|
||||
*
|
||||
* @param servers
|
||||
*/
|
||||
public void setServers(HashMap<Integer, Server> servers)
|
||||
{
|
||||
this.servers = servers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add server to list
|
||||
*/
|
||||
public void addServer(Server server)
|
||||
{
|
||||
if (!servers.containsKey(server.getId())) {
|
||||
servers.put(server.getId(), server);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of servers
|
||||
*
|
||||
* @return list of servers
|
||||
*/
|
||||
public ArrayList<Server> getServersAsArrayList()
|
||||
{
|
||||
ArrayList<Server> serverList = new ArrayList<Server>();
|
||||
|
||||
for (int key : servers.keySet()) {
|
||||
serverList.add(servers.get(key));
|
||||
}
|
||||
|
||||
return serverList;
|
||||
}
|
||||
}
|
110
src/org/yaaic/adapter/ServerListAdapter.java
Normal 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.ArrayList;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.yaaic.R;
|
||||
import org.yaaic.Yaaic;
|
||||
import org.yaaic.model.Server;
|
||||
import org.yaaic.model.Status;
|
||||
|
||||
/**
|
||||
* Adapter for server lists
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class ServerListAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Server> servers;
|
||||
|
||||
/**
|
||||
* Create a new adapter for server lists
|
||||
*/
|
||||
public ServerListAdapter()
|
||||
{
|
||||
loadServers();
|
||||
}
|
||||
|
||||
public void loadServers()
|
||||
{
|
||||
servers = Yaaic.getInstance().getServersAsArrayList();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of items
|
||||
*/
|
||||
public int getCount()
|
||||
{
|
||||
return servers.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item at position
|
||||
*
|
||||
* @param position
|
||||
*/
|
||||
public Server getItem(int position)
|
||||
{
|
||||
return servers.get(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id of item at position
|
||||
*
|
||||
* @param position
|
||||
*/
|
||||
public long getItemId(int position)
|
||||
{
|
||||
return getItem(position).getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get view for item at given position
|
||||
*
|
||||
* @param position
|
||||
* @param convertView
|
||||
* @param parent
|
||||
*/
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
Server server = getItem(position);
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View v = inflater.inflate(R.layout.serveritem, null);
|
||||
|
||||
((TextView) v.findViewById(R.id.title)).setText(server.getTitle());
|
||||
((TextView) v.findViewById(R.id.host)).setText(server.getHost());
|
||||
|
||||
((ImageView) v.findViewById(R.id.status)).setImageResource(server.getStatusIcon());
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
/*
|
||||
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.client.adapter;
|
||||
|
||||
import org.yaaic.client.R;
|
||||
import org.yaaic.client.irc.IrcBinder;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.database.Cursor;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.SimpleCursorAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* ServerListAdapter
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
*/
|
||||
public class ServerListAdapter extends SimpleCursorAdapter
|
||||
{
|
||||
/**
|
||||
* Debugging/Log tag
|
||||
*/
|
||||
public static final String TAG = "Yaaic/ServerListAdapter";
|
||||
|
||||
/**
|
||||
* Activity that uses the ServerListAdapter
|
||||
*/
|
||||
private Activity context;
|
||||
|
||||
/**
|
||||
* IrcBinder for IrcService
|
||||
*/
|
||||
private IrcBinder binder;
|
||||
|
||||
/**
|
||||
* Create a new, fresh ServerListAdapter
|
||||
*
|
||||
* @param context
|
||||
* @param layout
|
||||
* @param cursor
|
||||
* @param from
|
||||
* @param to
|
||||
*/
|
||||
public ServerListAdapter(Activity context, int layout, Cursor cursor, String[] from, int[] to)
|
||||
{
|
||||
super(context, layout, cursor, from, to);
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void setIrcBinder(IrcBinder binder)
|
||||
{
|
||||
this.binder = binder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get view for a row
|
||||
*/
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
// Get row from simple cursor adapter
|
||||
View row = super.getView(position, convertView, parent);
|
||||
|
||||
TextView tvServerTitle = (TextView) row.findViewById(R.id.server_title);
|
||||
TextView tvServerIcon = (TextView) row.findViewById(R.id.server_icon);
|
||||
String title = tvServerTitle.getText().toString();
|
||||
|
||||
Log.d(TAG, "Generating view for: " + title);
|
||||
|
||||
if (binder != null) {
|
||||
Log.d(TAG, "Got a binder..");
|
||||
|
||||
|
||||
if (binder.isConnected(title)) {
|
||||
tvServerIcon.setCompoundDrawablesWithIntrinsicBounds(
|
||||
context.getResources().getDrawable(android.R.drawable.presence_online),
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
} else {
|
||||
tvServerIcon.setCompoundDrawablesWithIntrinsicBounds(
|
||||
context.getResources().getDrawable(android.R.drawable.presence_offline),
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
/*
|
||||
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.client.adapter;
|
||||
|
||||
import org.yaaic.client.view.ServerActivity;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.BaseExpandableListAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* ServerWindowListAdapater
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
*/
|
||||
public class ServerWindowListAdapter extends BaseExpandableListAdapter
|
||||
{
|
||||
private ServerActivity serverWindow;
|
||||
private String[] groups = { "Channels (0)", "Queries (0)" };
|
||||
|
||||
public ServerWindowListAdapter(ServerActivity 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;
|
||||
}
|
||||
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
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.client.irc;
|
||||
|
||||
import android.os.Binder;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* IrcBinder
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
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.client.irc;
|
||||
|
||||
import org.jibble.pircbot.PircBot;
|
||||
import org.yaaic.client.YaaicApplication;
|
||||
|
||||
/**
|
||||
* IrcServer
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
*/
|
||||
public class IrcServer extends PircBot
|
||||
{
|
||||
public IrcServer()
|
||||
{
|
||||
this.setName("Yaaic");
|
||||
this.setLogin("yaaic");
|
||||
|
||||
this.setVersion("Yaaic " + YaaicApplication.VERSION);
|
||||
|
||||
this.setAutoNickChange(true);
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
/*
|
||||
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.client.irc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jibble.pircbot.IrcException;
|
||||
import org.jibble.pircbot.NickAlreadyInUseException;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* IrcService
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
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.client.irc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.text.SpannableString;
|
||||
|
||||
/**
|
||||
* A MessageBuffer for storing SpannableString Objects
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* Constructor - Create a fresh new MessageBuffer
|
||||
*/
|
||||
public MessageBuffer()
|
||||
{
|
||||
messageBuffer = new ArrayList<SpannableString>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a SpannableString to the Buffer
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
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.client.view;
|
||||
|
||||
import org.yaaic.client.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* About Activity
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
*/
|
||||
public class AboutActivity extends Activity
|
||||
{
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.about);
|
||||
}
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
/*
|
||||
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.client.view;
|
||||
|
||||
import org.yaaic.client.R;
|
||||
import org.yaaic.client.adapter.ServerWindowListAdapter;
|
||||
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;
|
||||
|
||||
/**
|
||||
* ServerWindow Activity
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
*/
|
||||
public class ServerActivity 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.server);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,332 +0,0 @@
|
||||
/*
|
||||
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.client.view;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
import android.content.ComponentName;
|
||||
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.R;
|
||||
import org.yaaic.client.adapter.ServerListAdapter;
|
||||
import org.yaaic.client.db.ServerConstants;
|
||||
import org.yaaic.client.db.ServerDatabase;
|
||||
import org.yaaic.client.irc.IrcBinder;
|
||||
import org.yaaic.client.irc.IrcService;
|
||||
|
||||
/**
|
||||
* ServerList Activity
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
*/
|
||||
public class ServerListActivity extends ListActivity implements OnItemLongClickListener, ServiceConnection
|
||||
{
|
||||
/**
|
||||
* Debugging/Log tag
|
||||
*/
|
||||
public static final String TAG = "Yaaic/ServerList";
|
||||
|
||||
private ServerDatabase db;
|
||||
|
||||
/**
|
||||
* Mapping for servers database to servers list view
|
||||
*/
|
||||
private static final String[] FROM = { ServerConstants.TITLE, ServerConstants.HOST };
|
||||
|
||||
/**
|
||||
* Mapping for servers database to servers list view
|
||||
*/
|
||||
private static final int[] TO = { R.id.server_title, R.id.server_host };
|
||||
|
||||
/**
|
||||
* Cursor for servers database
|
||||
*/
|
||||
private Cursor cursor;
|
||||
|
||||
/**
|
||||
* Binder for IrcService
|
||||
*/
|
||||
private IrcBinder binder;
|
||||
|
||||
/**
|
||||
* On Create
|
||||
*/
|
||||
@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.serverlist);
|
||||
|
||||
db = new ServerDatabase(this);
|
||||
|
||||
cursor = db.getServers();
|
||||
this.startManagingCursor(cursor);
|
||||
|
||||
SimpleCursorAdapter adapter = new ServerListAdapter(this, R.layout.serveritem, cursor, FROM, TO);
|
||||
this.setListAdapter(adapter);
|
||||
|
||||
this.getListView().setOnItemLongClickListener(this);
|
||||
|
||||
this.initAnimation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and apply animations for the server list (on create)
|
||||
*/
|
||||
public void initAnimation()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* On Resume
|
||||
*/
|
||||
public void onResume()
|
||||
{
|
||||
Log.d(TAG, "onResume");
|
||||
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
/**
|
||||
* On Pause
|
||||
*/
|
||||
public void onPause()
|
||||
{
|
||||
Log.d(TAG, "onPause");
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
/**
|
||||
* On Destroy
|
||||
*/
|
||||
public void onDestroy()
|
||||
{
|
||||
Log.d(TAG, "onDestroy");
|
||||
|
||||
super.onDestroy();
|
||||
|
||||
db.close();
|
||||
unbindService(this); // disconnect service
|
||||
}
|
||||
|
||||
/**
|
||||
* Click Listener
|
||||
*/
|
||||
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, ServerActivity.class);
|
||||
serverIntent.putExtra("server_title", tv.getText());
|
||||
startActivity(serverIntent);
|
||||
//cursor.requery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Long Click Listener
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Server selected (Long click)
|
||||
*
|
||||
* @param item id/position of item selected
|
||||
* @param title title of item (server title [unique id])
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Options Menu (Menu Button pressed)
|
||||
*/
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
super.onCreateOptionsMenu(menu);
|
||||
|
||||
// inflate from xml
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.serverlist, menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener for menu items
|
||||
*/
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
switch (item.getItemId())
|
||||
{
|
||||
// Add a new server
|
||||
case R.id.server_add:
|
||||
Intent serverAddIntent = new Intent(this, ServerAddActivity.class);
|
||||
startActivity(serverAddIntent);
|
||||
return true;
|
||||
// Show settings
|
||||
case R.id.settings:
|
||||
Intent settingsIntent = new Intent(this, SettingsActivity.class);
|
||||
startActivity(settingsIntent);
|
||||
return true;
|
||||
// Show about window
|
||||
case R.id.about:
|
||||
Intent aboutIntent = new Intent(this, AboutActivity.class);
|
||||
startActivity(aboutIntent);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener: IrcService connected to activity
|
||||
*/
|
||||
public void onServiceConnected(ComponentName name, IBinder service)
|
||||
{
|
||||
Log.d(TAG, "Service connected");
|
||||
|
||||
binder = (IrcBinder) service;
|
||||
|
||||
// Look for AutoConnect servers and connect if needed
|
||||
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();
|
||||
|
||||
ServerListAdapter adapter = (ServerListAdapter) getListAdapter();
|
||||
adapter.setIrcBinder(binder);
|
||||
cursor.requery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener: IrcServers disconnected from activity
|
||||
*/
|
||||
public void onServiceDisconnected(ComponentName name)
|
||||
{
|
||||
Log.d(TAG, "Service disconnected");
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to given server
|
||||
*
|
||||
* @param title Title of server (unique id)
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
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.client.view;
|
||||
|
||||
import org.yaaic.client.R;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
|
||||
/**
|
||||
* Settings Activity
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
*/
|
||||
public class SettingsActivity extends PreferenceActivity
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.settings);
|
||||
}
|
||||
}
|
@ -18,14 +18,14 @@ 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.client.db;
|
||||
package org.yaaic.db;
|
||||
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
/**
|
||||
* ChannelConstants
|
||||
* Constants for the channel database
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public interface ChannelConstants extends BaseColumns
|
||||
{
|
||||
@ -36,6 +36,9 @@ public interface ChannelConstants extends BaseColumns
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String SERVER = "server";
|
||||
|
||||
/**
|
||||
* All fields in the database
|
||||
*/
|
||||
public static final String[] ALL = {
|
||||
NAME,
|
||||
PASSWORD,
|
@ -18,7 +18,12 @@ 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.client.db;
|
||||
package org.yaaic.db;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.yaaic.model.Server;
|
||||
import org.yaaic.model.Status;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
@ -27,20 +32,30 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
/**
|
||||
* ServerDatabase
|
||||
* Database Helper for the servers and channels tables
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class ServerDatabase extends SQLiteOpenHelper
|
||||
public class Database extends SQLiteOpenHelper
|
||||
{
|
||||
public static final String TAG = "Yaaic/Database";
|
||||
|
||||
private static final String DATABASE_NAME = "servers.db";
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
|
||||
public ServerDatabase(Context context)
|
||||
/**
|
||||
* Create a new helper for database access
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public Database(Context context)
|
||||
{
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create all needed tables on first start
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db)
|
||||
{
|
||||
@ -65,10 +80,13 @@ public class ServerDatabase extends SQLiteOpenHelper
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate existing databases to
|
||||
*/
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
|
||||
{
|
||||
// XXX: We delete the database currently, in future we want to
|
||||
// XXX: We delete the database currently, in future versions 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 + ";");
|
||||
@ -76,9 +94,20 @@ public class ServerDatabase extends SQLiteOpenHelper
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
public void addServer(String title, String host, int port, String password, boolean autoConnect, boolean useSSL)
|
||||
/**
|
||||
* Add a new server to the database
|
||||
*
|
||||
* @param title Unique title of the server
|
||||
* @param host Hostname of the server
|
||||
* @param port Port (default: 3337)
|
||||
* @param password Password if needed
|
||||
* @param autoConnect Autoconnect to this server on startup?
|
||||
* @param useSSL Does the server use SSL?
|
||||
*/
|
||||
public long 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);
|
||||
@ -86,12 +115,20 @@ public class ServerDatabase extends SQLiteOpenHelper
|
||||
values.put(ServerConstants.AUTOCONNECT, autoConnect);
|
||||
values.put(ServerConstants.USE_SSL, useSSL);
|
||||
|
||||
this.getWritableDatabase().insert(ServerConstants.TABLE_NAME, null, values);
|
||||
return this.getWritableDatabase().insert(ServerConstants.TABLE_NAME, null, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a channel to the database
|
||||
*
|
||||
* @param server Unique id of server
|
||||
* @param name Name of channel
|
||||
* @param password Password to join (if needed)
|
||||
*/
|
||||
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);
|
||||
@ -99,9 +136,16 @@ public class ServerDatabase extends SQLiteOpenHelper
|
||||
this.getWritableDatabase().insert(ServerConstants.TABLE_NAME, null, values);
|
||||
}
|
||||
|
||||
public Cursor getServers()
|
||||
/**
|
||||
* Get all servers from database
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public HashMap<Integer, Server> getServers()
|
||||
{
|
||||
return this.getReadableDatabase().query(
|
||||
HashMap<Integer, Server> servers = new HashMap<Integer, Server>();
|
||||
|
||||
Cursor cursor = this.getReadableDatabase().query(
|
||||
ServerConstants.TABLE_NAME,
|
||||
ServerConstants.ALL,
|
||||
null,
|
||||
@ -110,21 +154,45 @@ public class ServerDatabase extends SQLiteOpenHelper
|
||||
null,
|
||||
ServerConstants.TITLE + " ASC"
|
||||
);
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
Server server = new Server();
|
||||
|
||||
server.setTitle(cursor.getString(cursor.getColumnIndex((ServerConstants.TITLE))));
|
||||
server.setHost(cursor.getString(cursor.getColumnIndex((ServerConstants.HOST))));
|
||||
server.setPort(cursor.getInt(cursor.getColumnIndex((ServerConstants.PORT))));
|
||||
server.setId(cursor.getInt(cursor.getColumnIndex((ServerConstants._ID))));
|
||||
server.setStatus(Status.DISCONNECTED);
|
||||
|
||||
servers.put(server.getId(), server);
|
||||
}
|
||||
|
||||
return servers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all servers with autoconnect enabled
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Cursor getAutoConnectServers()
|
||||
{
|
||||
return this.getReadableDatabase().query(
|
||||
ServerConstants.TABLE_NAME,
|
||||
ServerConstants.ALL,
|
||||
ServerConstants.AUTOCONNECT + " = 1",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
ServerConstants.TITLE + " ASC"
|
||||
);
|
||||
ServerConstants.TABLE_NAME,
|
||||
ServerConstants.ALL,
|
||||
ServerConstants.AUTOCONNECT + " = 1",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
ServerConstants.TITLE + " ASC"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all channels
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Cursor getChannels()
|
||||
{
|
||||
return this.getReadableDatabase().query(
|
||||
@ -134,36 +202,38 @@ public class ServerDatabase extends SQLiteOpenHelper
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
ChannelConstants.NAME + " ASC");
|
||||
ChannelConstants.NAME + " ASC"
|
||||
);
|
||||
}
|
||||
|
||||
public Cursor getChannelsByServer(int server)
|
||||
/**
|
||||
* Get all channels of server
|
||||
*
|
||||
* @param server Unique id of server
|
||||
* @return
|
||||
*/
|
||||
public Cursor getChannelsById(int serverId)
|
||||
{
|
||||
return this.getReadableDatabase().query(
|
||||
ChannelConstants.TABLE_NAME,
|
||||
ChannelConstants.ALL,
|
||||
ChannelConstants.SERVER + "=" + server,
|
||||
ChannelConstants.SERVER + "=" + serverId,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
ChannelConstants.NAME + " ASC");
|
||||
ChannelConstants.NAME + " ASC"
|
||||
);
|
||||
}
|
||||
|
||||
public Cursor getServer(String title)
|
||||
/**
|
||||
* Remove server from database by unique id
|
||||
*
|
||||
* @param title
|
||||
*/
|
||||
public void removeServerById(int serverId)
|
||||
{
|
||||
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 + "';");
|
||||
this.getWritableDatabase().execSQL(
|
||||
"DELETE FROM " + ServerConstants.TABLE_NAME + " WHERE " + ServerConstants._ID + " = " + serverId + ";"
|
||||
);
|
||||
}
|
||||
}
|
@ -18,14 +18,14 @@ 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.client.db;
|
||||
package org.yaaic.db;
|
||||
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
/**
|
||||
* Server Constants
|
||||
* Constants for the server database
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public interface ServerConstants extends BaseColumns
|
||||
{
|
||||
@ -40,6 +40,9 @@ public interface ServerConstants extends BaseColumns
|
||||
public static final String USE_SSL = "useSSL";
|
||||
public static final String IDENTITY = "identity";
|
||||
|
||||
/**
|
||||
* All fields in the table
|
||||
*/
|
||||
public static final String[] ALL = {
|
||||
_ID,
|
||||
TITLE,
|
78
src/org/yaaic/irc/IRCBinder.java
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
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.irc;
|
||||
|
||||
import org.yaaic.model.Server;
|
||||
|
||||
import android.os.Binder;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Binder for service communication
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class IRCBinder extends Binder
|
||||
{
|
||||
public static final String TAG = "Yaaic/IRCBinder";
|
||||
|
||||
private IRCService service;
|
||||
|
||||
/**
|
||||
* Create a new binder for given service
|
||||
*
|
||||
* @param service
|
||||
*/
|
||||
public IRCBinder(IRCService service)
|
||||
{
|
||||
super();
|
||||
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to given server
|
||||
*
|
||||
* @param server
|
||||
*/
|
||||
public void connect(final Server server)
|
||||
{
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
getService().getConnection(server.getId()).connect(server.getHost());
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.d(TAG, "Exception: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get service associated with this service
|
||||
* @return
|
||||
*/
|
||||
public IRCService getService()
|
||||
{
|
||||
return service;
|
||||
}
|
||||
}
|
78
src/org/yaaic/irc/IRCConnection.java
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
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.irc;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import org.jibble.pircbot.PircBot;
|
||||
|
||||
import org.yaaic.Yaaic;
|
||||
import org.yaaic.model.Broadcast;
|
||||
import org.yaaic.model.Server;
|
||||
import org.yaaic.model.Status;
|
||||
|
||||
public class IRCConnection extends PircBot
|
||||
{
|
||||
private IRCService service;
|
||||
private Server server;
|
||||
|
||||
public IRCConnection(IRCService service, int serverId)
|
||||
{
|
||||
this.server = Yaaic.getInstance().getServerById(serverId);
|
||||
this.service = service;
|
||||
|
||||
this.setName("Yaaic");
|
||||
this.setLogin("Yaaic");
|
||||
this.setAutoNickChange(true);
|
||||
this.setVersion("Yaaic - Yet another Android IRC client - http://www.yaaic.org");
|
||||
}
|
||||
|
||||
/**
|
||||
* On connect
|
||||
*/
|
||||
@Override
|
||||
public void onConnect()
|
||||
{
|
||||
server.setStatus(Status.CONNECTED);
|
||||
|
||||
service.sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));
|
||||
}
|
||||
|
||||
/**
|
||||
* On disconnect
|
||||
*/
|
||||
@Override
|
||||
public void onDisconnect()
|
||||
{
|
||||
server.setStatus(Status.DISCONNECTED);
|
||||
|
||||
service.sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Quits from the IRC server with default reason.
|
||||
*/
|
||||
@Override
|
||||
public void quitServer()
|
||||
{
|
||||
quitServer("Yaaic - Yet another Android IRC client - http://www.yaaic.org");
|
||||
}
|
||||
}
|
110
src/org/yaaic/irc/IRCService.java
Normal 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.irc;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.yaaic.Yaaic;
|
||||
import org.yaaic.db.Database;
|
||||
import org.yaaic.model.Broadcast;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* The background service for managing the irc connections
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class IRCService extends Service
|
||||
{
|
||||
public final static String TAG = "Yaaic/IRCService";
|
||||
|
||||
private IRCBinder binder;
|
||||
private HashMap<Integer, IRCConnection> connections;
|
||||
|
||||
/**
|
||||
* Create new service
|
||||
*/
|
||||
public IRCService()
|
||||
{
|
||||
super();
|
||||
|
||||
Log.d(TAG, "Service created...");
|
||||
|
||||
this.connections = new HashMap<Integer, IRCConnection>();
|
||||
this.binder = new IRCBinder(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
super.onCreate();
|
||||
|
||||
Log.d(TAG, "Loading servers from database");
|
||||
|
||||
// Load servers from Database
|
||||
Database db = new Database(this);
|
||||
Yaaic.getInstance().setServers(db.getServers());
|
||||
db.close();
|
||||
|
||||
// Broadcast changed server list
|
||||
sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Intent intent, int startId)
|
||||
{
|
||||
Log.d(TAG, "onStart()");
|
||||
super.onStart(intent, startId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get connection for given server
|
||||
*
|
||||
* @param serverId
|
||||
* @return
|
||||
*/
|
||||
public synchronized IRCConnection getConnection(int serverId)
|
||||
{
|
||||
IRCConnection connection = connections.get(serverId);
|
||||
|
||||
if (connection == null) {
|
||||
connection = new IRCConnection(this, serverId);
|
||||
connections.put(serverId, connection);
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* On Activity binding to this service
|
||||
*
|
||||
* @param intent
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public IRCBinder onBind(Intent intent)
|
||||
{
|
||||
return binder;
|
||||
}
|
||||
}
|
53
src/org/yaaic/listener/FlingListener.java
Normal file
@ -0,0 +1,53 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Yaaic - Yet Another Android IRC Client
|
||||
Yaaic - Yet Another Android IRC Client
|
||||
|
||||
Copyright 2009 Sebastian Kaspari
|
||||
|
||||
@ -18,14 +18,9 @@ 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.client.db;
|
||||
package org.yaaic.listener;
|
||||
|
||||
/**
|
||||
* IdentityConstants
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
*/
|
||||
public class IdentityConstants
|
||||
public interface ServerListener
|
||||
{
|
||||
|
||||
public void onStatusUpdate();
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Yaaic - Yet Another Android IRC Client
|
||||
Yaaic - Yet Another Android IRC Client
|
||||
|
||||
Copyright 2009 Sebastian Kaspari
|
||||
|
||||
@ -18,14 +18,9 @@ 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.client.irc;
|
||||
package org.yaaic.model;
|
||||
|
||||
/**
|
||||
* ServerBuffer
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
*/
|
||||
public class ServerBuffer extends MessageBuffer
|
||||
public class Broadcast
|
||||
{
|
||||
|
||||
public static final String SERVER_UPDATE = "org.yaaic.server.status";
|
||||
}
|
171
src/org/yaaic/model/Server.java
Normal file
@ -0,0 +1,171 @@
|
||||
/*
|
||||
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.model;
|
||||
|
||||
import org.yaaic.R;
|
||||
|
||||
/**
|
||||
* A server as we know it
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class Server
|
||||
{
|
||||
private int id;
|
||||
private String title;
|
||||
private String host;
|
||||
private int port;
|
||||
|
||||
private int status = Status.DISCONNECTED;
|
||||
|
||||
/**
|
||||
* Get unique id of server
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
public int getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set unique id of server
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void setId(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title of server
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title of server
|
||||
*
|
||||
* @param title
|
||||
*/
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hostname of server
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getHost()
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set hostname of server
|
||||
*
|
||||
* @param host
|
||||
*/
|
||||
public void setHost(String host)
|
||||
{
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get port of server
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getPort()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set port of server
|
||||
*
|
||||
* @param port
|
||||
*/
|
||||
public void setPort(int port)
|
||||
{
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set connection status of server
|
||||
*
|
||||
* @status See constants Status.*
|
||||
*/
|
||||
public void setStatus(int status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get connection status of server
|
||||
*
|
||||
* @return See constants Status.*
|
||||
*/
|
||||
public int getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is disconnected?
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isDisconnected()
|
||||
{
|
||||
return status == Status.DISCONNECTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is connected?
|
||||
* @return
|
||||
*/
|
||||
public boolean isConnected()
|
||||
{
|
||||
return status == Status.CONNECTED;
|
||||
}
|
||||
|
||||
public int getStatusIcon()
|
||||
{
|
||||
switch (status) {
|
||||
case Status.CONNECTED:
|
||||
return R.drawable.connected;
|
||||
case Status.DISCONNECTED:
|
||||
return R.drawable.disconnected;
|
||||
case Status.CONNECTING:
|
||||
return R.drawable.connecting;
|
||||
}
|
||||
|
||||
return R.drawable.connecting;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Yaaic - Yet Another Android IRC Client
|
||||
Yaaic - Yet Another Android IRC Client
|
||||
|
||||
Copyright 2009 Sebastian Kaspari
|
||||
|
||||
@ -18,14 +18,10 @@ 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.client.irc;
|
||||
|
||||
/**
|
||||
* ChannelBuffer
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
*/
|
||||
public class ChannelBuffer extends MessageBuffer
|
||||
{
|
||||
package org.yaaic.model;
|
||||
|
||||
public class Status {
|
||||
public static final int DISCONNECTED = 0;
|
||||
public static final int CONNECTING = 1;
|
||||
public static final int CONNECTED = 2;
|
||||
}
|
@ -18,16 +18,26 @@ 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.client;
|
||||
package org.yaaic.receiver;
|
||||
|
||||
import android.app.Application;
|
||||
import org.yaaic.listener.ServerListener;
|
||||
|
||||
/**
|
||||
* YaaicApplication
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
*/
|
||||
public class YaaicApplication extends Application
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public class ServerReceiver extends BroadcastReceiver
|
||||
{
|
||||
public static final String VERSION = " Alpha 1";
|
||||
private ServerListener listener;
|
||||
|
||||
public ServerReceiver(ServerListener listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
listener.onStatusUpdate();
|
||||
}
|
||||
}
|
@ -18,26 +18,83 @@ 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.client.view;
|
||||
|
||||
import org.yaaic.client.R;
|
||||
import org.yaaic.client.db.ServerDatabase;
|
||||
package org.yaaic.view;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
|
||||
import org.yaaic.R;
|
||||
import org.yaaic.Yaaic;
|
||||
import org.yaaic.db.Database;
|
||||
import org.yaaic.model.Server;
|
||||
import org.yaaic.model.Status;
|
||||
|
||||
/**
|
||||
* ServerAdd Activity
|
||||
* Add a new server to the list
|
||||
*
|
||||
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class ServerAddActivity extends Activity implements OnClickListener
|
||||
public class AddServerActivity extends Activity implements OnClickListener
|
||||
{
|
||||
public static final String TAG = "Yaaic/AddServerActivity";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.serveradd);
|
||||
|
||||
((Button) findViewById(R.id.add)).setOnClickListener(this);
|
||||
((Button) findViewById(R.id.cancel)).setOnClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* On click add server or cancel activity
|
||||
*/
|
||||
public void onClick(View v)
|
||||
{
|
||||
switch (v.getId()) {
|
||||
case R.id.add:
|
||||
String title = ((EditText) findViewById(R.id.title)).getText().toString();
|
||||
String host = ((EditText) findViewById(R.id.host)).getText().toString();
|
||||
int port = Integer.parseInt(((EditText) findViewById(R.id.port)).getText().toString());
|
||||
String password = ((EditText) findViewById(R.id.password)).getText().toString();
|
||||
boolean autoConnect = ((CheckBox) findViewById(R.id.autoconnect)).isChecked();
|
||||
boolean useSSL = ((CheckBox) findViewById(R.id.useSSL)).isChecked();
|
||||
|
||||
Database db = new Database(this);
|
||||
long id = db.addServer(title, host, port, password, autoConnect, useSSL);
|
||||
db.close();
|
||||
|
||||
Server server = new Server();
|
||||
server.setId((int) id);
|
||||
server.setHost(host);
|
||||
server.setPort(port);
|
||||
server.setTitle(title);
|
||||
server.setStatus(Status.DISCONNECTED);
|
||||
Yaaic.getInstance().addServer(server);
|
||||
|
||||
Log.d(TAG, "Saved server " + title);
|
||||
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
@ -68,4 +125,4 @@ public class ServerAddActivity extends Activity implements OnClickListener
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
174
src/org/yaaic/view/ServerActivity.java
Normal file
@ -0,0 +1,174 @@
|
||||
/*
|
||||
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;
|
||||
import org.yaaic.listener.FlingListener;
|
||||
import org.yaaic.model.Server;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
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.view.animation.AnimationUtils;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ViewFlipper;
|
||||
|
||||
/**
|
||||
* Connected to server
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class ServerActivity extends Activity implements ServiceConnection
|
||||
{
|
||||
protected static final String TextView = null;
|
||||
private IRCBinder binder;
|
||||
private int serverId;
|
||||
|
||||
private GestureDetector flingDetector;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
this.serverId = getIntent().getExtras().getInt("serverId");
|
||||
|
||||
Server server = (Server) Yaaic.getInstance().getServerById(serverId);
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
230
src/org/yaaic/view/ServersActivity.java
Normal file
@ -0,0 +1,230 @@
|
||||
/*
|
||||
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 android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
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.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
|
||||
import org.yaaic.R;
|
||||
import org.yaaic.Yaaic;
|
||||
import org.yaaic.adapter.ServerListAdapter;
|
||||
import org.yaaic.db.Database;
|
||||
import org.yaaic.irc.IRCBinder;
|
||||
import org.yaaic.irc.IRCService;
|
||||
import org.yaaic.listener.ServerListener;
|
||||
import org.yaaic.model.Broadcast;
|
||||
import org.yaaic.model.Server;
|
||||
import org.yaaic.model.Status;
|
||||
import org.yaaic.receiver.ServerReceiver;
|
||||
|
||||
/**
|
||||
* List of servers
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class ServersActivity extends ListActivity implements ServiceConnection, ServerListener, OnItemLongClickListener {
|
||||
public static final String TAG = "Yaaic/ServersActivity";
|
||||
|
||||
private IRCBinder binder;
|
||||
private ServerReceiver receiver;
|
||||
private ServerListAdapter adapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.servers);
|
||||
|
||||
adapter = new ServerListAdapter();
|
||||
setListAdapter(adapter);
|
||||
|
||||
getListView().setOnItemLongClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
|
||||
// Start and connect to service
|
||||
Intent intent = new Intent(this, IRCService.class);
|
||||
startService(intent);
|
||||
bindService(intent, this, 0);
|
||||
|
||||
receiver = new ServerReceiver(this);
|
||||
|
||||
registerReceiver(receiver, new IntentFilter(Broadcast.SERVER_UPDATE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
|
||||
unbindService(this);
|
||||
unregisterReceiver(receiver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Service connected to Activity
|
||||
*/
|
||||
public void onServiceConnected(ComponentName name, IBinder service)
|
||||
{
|
||||
binder = (IRCBinder) service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Service disconnected from Activity
|
||||
*/
|
||||
public void onServiceDisconnected(ComponentName name)
|
||||
{
|
||||
binder = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* On server selected
|
||||
*/
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
final Server server = adapter.getItem(position);
|
||||
|
||||
switch (server.getStatus()) {
|
||||
case Status.DISCONNECTED:
|
||||
server.setStatus(Status.CONNECTING);
|
||||
adapter.notifyDataSetChanged();
|
||||
binder.connect(server);
|
||||
break;
|
||||
case Status.CONNECTED:
|
||||
Intent intent = new Intent(this, ServerActivity.class);
|
||||
intent.putExtra("serverId", server.getId());
|
||||
startActivityForResult(intent, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On long click
|
||||
*/
|
||||
public boolean onItemLongClick(AdapterView<?> l, View v, int position, long id)
|
||||
{
|
||||
final Server server = adapter.getItem(position);
|
||||
|
||||
final CharSequence[] items = {
|
||||
getString(R.string.connect),
|
||||
getString(R.string.disconnect),
|
||||
getString(R.string.delete)
|
||||
};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(server.getTitle());
|
||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
switch (item) {
|
||||
case 0: // Connect
|
||||
binder.connect(server);
|
||||
server.setStatus(Status.CONNECTING);
|
||||
adapter.notifyDataSetChanged();
|
||||
break;
|
||||
case 1: // Disconnect
|
||||
binder.getService().getConnection(server.getId()).quitServer();
|
||||
break;
|
||||
case 2: // Delete
|
||||
deleteServer(server.getId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options Menu (Menu Button pressed)
|
||||
*/
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
super.onCreateOptionsMenu(menu);
|
||||
|
||||
// inflate from xml
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.servers, menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.add:
|
||||
startActivityForResult(new Intent(this, AddServerActivity.class), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
// Refresh list from database
|
||||
adapter.loadServers();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete server
|
||||
*
|
||||
* @param serverId
|
||||
*/
|
||||
public void deleteServer(int serverId)
|
||||
{
|
||||
Database db = new Database(this);
|
||||
db.removeServerById(serverId);
|
||||
|
||||
Yaaic.getInstance().removeServerById(serverId);
|
||||
adapter.loadServers();
|
||||
}
|
||||
|
||||
/**
|
||||
* On server status updat
|
||||
*/
|
||||
public void onStatusUpdate()
|
||||
{
|
||||
Log.d(TAG, "Received server status update");
|
||||
adapter.loadServers();
|
||||
}
|
||||
|
||||
}
|