1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-26 19:02:17 -05:00

Added AddCommandsActivity and views

This commit is contained in:
Sebastian Kaspari 2010-04-25 12:17:59 +02:00
parent 53bc6c3bd8
commit e6525258d0
3 changed files with 244 additions and 0 deletions

68
res/layout/commandadd.xml Normal file
View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Yaaic - Yet Another Android IRC Client
Copyright 2009-2010 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">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="These commands will be executed after connect."
android:padding="5px" />
<ListView
android:id="@+id/commands"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/command"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="/"
android:layout_weight="1" />
<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ok"
android:text="Ok" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cancel"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Yaaic - Yet Another Android IRC Client
Copyright 2009-2010 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/>.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/host"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="7px"
android:text=""
android:textSize="12px" />

View File

@ -0,0 +1,148 @@
/*
Yaaic - Yet Another Android IRC Client
Copyright 2009-2010 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.activity;
import java.util.ArrayList;
import org.yaaic.R;
import org.yaaic.command.CommandParser;
import org.yaaic.model.Extra;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
/**
* Adding commands (to execute after connect) to a server
*
* @author Sebastian Kaspari <sebastian@yaaic.org>
*/
public class AddCommandsActivity extends Activity implements OnClickListener, OnItemClickListener
{
private EditText commandInput;
private ArrayAdapter<String> adapter;
private ArrayList<String> commands;
/**
* On create
*/
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.commandadd);
commandInput = (EditText) findViewById(R.id.command);
adapter = new ArrayAdapter<String>(this, R.layout.commanditem);
ListView list = (ListView) findViewById(R.id.commands);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
((Button) findViewById(R.id.add)).setOnClickListener(this);
((Button) findViewById(R.id.ok)).setOnClickListener(this);
((Button) findViewById(R.id.cancel)).setOnClickListener(this);
commands = getIntent().getExtras().getStringArrayList(Extra.COMMANDS);
for (String command : commands) {
adapter.add(command);
}
}
/**
* On Click
*/
public void onClick(View v)
{
switch (v.getId()) {
case R.id.add:
String command = commandInput.getText().toString().trim();
if (command.startsWith("/")) {
command = command.substring(1); // cut the slash
}
String[] params = command.split(" ");
String type = params[0];
if (!CommandParser.getInstance().isValidCommand(type)) {
Toast.makeText(this, "Invalid command: " + params[0], Toast.LENGTH_SHORT).show();
return;
}
commands.add("/" + command);
adapter.add("/" + command);
commandInput.setText("/");
break;
case R.id.cancel:
setResult(RESULT_CANCELED);
finish();
break;
case R.id.ok:
// Get list and return as result
Intent intent = new Intent();
intent.putExtra(Extra.COMMANDS, commands);
setResult(RESULT_OK, intent);
finish();
break;
}
}
/**
* On item clicked
*/
public void onItemClick(AdapterView<?> list, View item, int position, long id)
{
final String command = adapter.getItem(position);
String[] items = { "Remove" };
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(command);
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
switch (item) {
case 0: // Remove
adapter.remove(command);
commands.remove(command);
break;
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
}