1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-24 09:52:18 -05:00

Refactor ConversationActivity to ConversationFragment.

This commit also removes the speech recognition setting. This feature is part of most modern keyboards nowadays.
This commit is contained in:
Sebastian Kaspari 2015-04-04 12:55:24 +02:00
parent 06591a9b4e
commit b374f2972d
8 changed files with 222 additions and 373 deletions

View File

@ -38,6 +38,7 @@ import android.widget.TextView;
import org.yaaic.R; import org.yaaic.R;
import org.yaaic.Yaaic; import org.yaaic.Yaaic;
import org.yaaic.fragment.ConversationFragment;
import org.yaaic.fragment.OverviewFragment; import org.yaaic.fragment.OverviewFragment;
import org.yaaic.fragment.SettingsFragment; import org.yaaic.fragment.SettingsFragment;
import org.yaaic.irc.IRCBinder; import org.yaaic.irc.IRCBinder;
@ -139,15 +140,20 @@ public class MainActivity extends ActionBarActivity implements OverviewFragment.
@Override @Override
public void onServerSelected(Server server) { public void onServerSelected(Server server) {
Intent intent = new Intent(this, ConversationActivity.class); Bundle arguments = new Bundle();
if (server.getStatus() == Status.DISCONNECTED && !server.mayReconnect()) { if (server.getStatus() == Status.DISCONNECTED && !server.mayReconnect()) {
server.setStatus(Status.PRE_CONNECTING); server.setStatus(Status.PRE_CONNECTING);
intent.putExtra(Extra.CONNECT, true);
arguments.putBoolean(Extra.CONNECT, true);
} }
intent.putExtra(Extra.SERVER_ID, server.getId()); arguments.putInt(Extra.SERVER_ID, server.getId());
startActivity(intent);
ConversationFragment fragment = new ConversationFragment();
fragment.setArguments(arguments);
switchToFragment(fragment, ConversationFragment.TRANSACTION_TAG);
} }

View File

@ -2,6 +2,7 @@
Yaaic - Yet Another Android IRC Client Yaaic - Yet Another Android IRC Client
Copyright 2009-2015 Sebastian Kaspari Copyright 2009-2015 Sebastian Kaspari
Copyright 2012 Daniel E. Moctezuma <democtezuma@gmail.com>
This file is part of Yaaic. This file is part of Yaaic.
@ -18,42 +19,43 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Yaaic. If not, see <http://www.gnu.org/licenses/>. along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.yaaic.activity; package org.yaaic.fragment;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Fragment;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.speech.RecognizerIntent; import android.speech.RecognizerIntent;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.text.InputType; import android.text.InputType;
import android.text.method.TextKeyListener; import android.text.method.TextKeyListener;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.View.OnKeyListener; import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.Toast; import android.widget.Toast;
import org.yaaic.R; import org.yaaic.R;
import org.yaaic.Yaaic; import org.yaaic.Yaaic;
import org.yaaic.activity.JoinActivity;
import org.yaaic.activity.UserActivity;
import org.yaaic.activity.UsersActivity;
import org.yaaic.adapter.ConversationPagerAdapter; import org.yaaic.adapter.ConversationPagerAdapter;
import org.yaaic.adapter.MessageListAdapter; import org.yaaic.adapter.MessageListAdapter;
import org.yaaic.command.CommandParser; import org.yaaic.command.CommandParser;
@ -62,7 +64,6 @@ import org.yaaic.irc.IRCConnection;
import org.yaaic.irc.IRCService; import org.yaaic.irc.IRCService;
import org.yaaic.listener.ConversationListener; import org.yaaic.listener.ConversationListener;
import org.yaaic.listener.ServerListener; import org.yaaic.listener.ServerListener;
import org.yaaic.listener.SpeechClickListener;
import org.yaaic.model.Broadcast; import org.yaaic.model.Broadcast;
import org.yaaic.model.Conversation; import org.yaaic.model.Conversation;
import org.yaaic.model.Extra; import org.yaaic.model.Extra;
@ -83,12 +84,10 @@ import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
* The server view with a scrollable list of all channels * The server view with a scrollable pager of all conversations.
*
* @author Sebastian Kaspari <sebastian@yaaic.org>
*/ */
public class ConversationActivity extends ActionBarActivity implements ServiceConnection, ServerListener, ConversationListener public class ConversationFragment extends Fragment implements ServerListener, ConversationListener, ServiceConnection {
{ public static final String TRANSACTION_TAG = "fragment_conversation";
public static final int REQUEST_CODE_SPEECH = 99; public static final int REQUEST_CODE_SPEECH = 99;
private static final int REQUEST_CODE_JOIN = 1; private static final int REQUEST_CODE_JOIN = 1;
@ -116,17 +115,14 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
// channel name in onActivityResult() and run the join command in onResume(). // channel name in onActivityResult() and run the join command in onResume().
private String joinChannelBuffer; private String joinChannelBuffer;
private int historySize;
private boolean reconnectDialogActive = false; private boolean reconnectDialogActive = false;
private final OnKeyListener inputKeyListener = new OnKeyListener() { private final View.OnKeyListener inputKeyListener = new View.OnKeyListener() {
/** /**
* On key pressed (input line) * On key pressed (input line)
*/ */
@Override @Override
public boolean onKey(View view, int keyCode, KeyEvent event) public boolean onKey(View view, int keyCode, KeyEvent event) {
{
EditText input = (EditText) view; EditText input = (EditText) view;
if (event.getAction() != KeyEvent.ACTION_DOWN) { if (event.getAction() != KeyEvent.ACTION_DOWN) {
@ -169,50 +165,43 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* On create * On create
*/ */
@Override @Override
protected void onCreate(Bundle savedInstanceState) public void onCreate(Bundle savedInstanceState) {
{
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
serverId = getIntent().getExtras().getInt("serverId"); serverId = getArguments().getInt("serverId");
server = Yaaic.getInstance().getServerById(serverId); server = Yaaic.getInstance().getServerById(serverId);
Settings settings = new Settings(this);
// Finish activity if server does not exist anymore - See #55 // Create a new scrollback history
if (server == null) { scrollback = new Scrollback();
this.finish();
} }
setTitle(server.getTitle()); @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_conversations, container, false);
setContentView(R.layout.activity_conversations); Settings settings = new Settings(getActivity());
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setElevation(0);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
boolean isLandscape = (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE); boolean isLandscape = (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);
input = (EditText) findViewById(R.id.input); input = (EditText) view.findViewById(R.id.input);
input.setOnKeyListener(inputKeyListener); input.setOnKeyListener(inputKeyListener);
pager = (ViewPager) findViewById(R.id.pager); pager = (ViewPager) view.findViewById(R.id.pager);
pagerAdapter = new ConversationPagerAdapter(this, server); pagerAdapter = new ConversationPagerAdapter(getActivity(), server);
pager.setAdapter(pagerAdapter); pager.setAdapter(pagerAdapter);
tabLayout = (ConversationTabLayout) findViewById(R.id.indicator); tabLayout = (ConversationTabLayout) view.findViewById(R.id.indicator);
tabLayout.setViewPager(pager); tabLayout.setViewPager(pager);
tabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.accent)); tabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.accent));
tabLayout.setDividerColors(getResources().getColor(R.color.divider)); tabLayout.setDividerColors(getResources().getColor(R.color.divider));
historySize = settings.getHistorySize();
if (server.getStatus() == Status.PRE_CONNECTING) { if (server.getStatus() == Status.PRE_CONNECTING) {
server.clearConversations(); server.clearConversations();
pagerAdapter.clearConversations(); pagerAdapter.clearConversations();
server.getConversation(ServerInfo.DEFAULT_NAME).setHistorySize(historySize); server.getConversation(ServerInfo.DEFAULT_NAME).setHistorySize(
settings.getHistorySize()
);
} }
// Optimization : cache field lookups // Optimization : cache field lookups
@ -245,7 +234,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
input.setInputType(input.getInputType() | setInputTypeFlags); input.setInputType(input.getInputType() | setInputTypeFlags);
ImageButton sendButton = (ImageButton) findViewById(R.id.send); ImageButton sendButton = (ImageButton) view.findViewById(R.id.send);
sendButton.setOnClickListener(new View.OnClickListener() { sendButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -254,6 +243,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
} }
} }
}); });
sendButton.setOnLongClickListener(new View.OnLongClickListener() { sendButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override @Override
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
@ -262,51 +252,33 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
} }
}); });
// Create a new scrollback history return view;
scrollback = new Scrollback();
} }
/** /**
* On resume * On resume
*/ */
@Override @Override
public void onResume() public void onResume() {
{
// register the receivers as early as possible, otherwise we may loose a broadcast message // register the receivers as early as possible, otherwise we may loose a broadcast message
channelReceiver = new ConversationReceiver(server.getId(), this); channelReceiver = new ConversationReceiver(server.getId(), this);
registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_MESSAGE)); getActivity().registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_MESSAGE));
registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_NEW)); getActivity().registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_NEW));
registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_REMOVE)); getActivity().registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_REMOVE));
registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_TOPIC)); getActivity().registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_TOPIC));
serverReceiver = new ServerReceiver(this); serverReceiver = new ServerReceiver(this);
registerReceiver(serverReceiver, new IntentFilter(Broadcast.SERVER_UPDATE)); getActivity().registerReceiver(serverReceiver, new IntentFilter(Broadcast.SERVER_UPDATE));
super.onResume(); super.onResume();
// Check if speech recognition is enabled and available
if (new Settings(this).isVoiceRecognitionEnabled()) {
PackageManager pm = getPackageManager();
Button speechButton = (Button) findViewById(R.id.speech);
List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() != 0) {
((Button) findViewById(R.id.speech)).setOnClickListener(new SpeechClickListener(this));
speechButton.setVisibility(View.VISIBLE);
}
}
// Start service // Start service
Intent intent = new Intent(this, IRCService.class); Intent intent = new Intent(getActivity(), IRCService.class);
intent.setAction(IRCService.ACTION_FOREGROUND); intent.setAction(IRCService.ACTION_FOREGROUND);
startService(intent); getActivity().startService(intent);
bindService(intent, this, 0); getActivity().bindService(intent, this, 0);
if (!server.isConnected()) { input.setEnabled(server.isConnected());
((EditText) findViewById(R.id.input)).setEnabled(false);
} else {
((EditText) findViewById(R.id.input)).setEnabled(true);
}
// Optimization - cache field lookup // Optimization - cache field lookup
Collection<Conversation> mConversations = server.getConversations(); Collection<Conversation> mConversations = server.getConversations();
@ -329,11 +301,11 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
// Clear new message notifications for the selected conversation // Clear new message notifications for the selected conversation
if (conversation.getStatus() == Conversation.STATUS_SELECTED && conversation.getNewMentions() > 0) { if (conversation.getStatus() == Conversation.STATUS_SELECTED && conversation.getNewMentions() > 0) {
Intent ackIntent = new Intent(this, IRCService.class); Intent ackIntent = new Intent(getActivity(), IRCService.class);
ackIntent.setAction(IRCService.ACTION_ACK_NEW_MENTIONS); ackIntent.setAction(IRCService.ACTION_ACK_NEW_MENTIONS);
ackIntent.putExtra(IRCService.EXTRA_ACK_SERVERID, serverId); ackIntent.putExtra(IRCService.EXTRA_ACK_SERVERID, serverId);
ackIntent.putExtra(IRCService.EXTRA_ACK_CONVTITLE, name); ackIntent.putExtra(IRCService.EXTRA_ACK_CONVTITLE, name);
startService(ackIntent); getActivity().startService(ackIntent);
} }
} }
@ -366,8 +338,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* On Pause * On Pause
*/ */
@Override @Override
public void onPause() public void onPause() {
{
super.onPause(); super.onPause();
server.setIsForeground(false); server.setIsForeground(false);
@ -376,21 +347,20 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
binder.getService().checkServiceStatus(); binder.getService().checkServiceStatus();
} }
unbindService(this); getActivity().unbindService(this);
unregisterReceiver(channelReceiver); getActivity().unregisterReceiver(channelReceiver);
unregisterReceiver(serverReceiver); getActivity().unregisterReceiver(serverReceiver);
} }
/** /**
* On service connected * On service connected
*/ */
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) public void onServiceConnected(ComponentName name, IBinder service) {
{
this.binder = (IRCBinder) service; this.binder = (IRCBinder) service;
// connect to irc server if connect has been requested // connect to irc server if connect has been requested
if (server.getStatus() == Status.PRE_CONNECTING && getIntent().hasExtra("connect")) { if (server.getStatus() == Status.PRE_CONNECTING && getArguments().containsKey("connect")) {
server.setStatus(Status.CONNECTING); server.setStatus(Status.CONNECTING);
binder.connect(server); binder.connect(server);
} else { } else {
@ -402,40 +372,27 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* On service disconnected * On service disconnected
*/ */
@Override @Override
public void onServiceDisconnected(ComponentName name) public void onServiceDisconnected(ComponentName name) {
{
this.binder = null; this.binder = null;
} }
/** /**
* On options menu requested * On options menu requested
*/ */
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
{ super.onCreateOptionsMenu(menu, inflater);
super.onCreateOptionsMenu(menu);
// inflate from xml
MenuInflater inflater = new MenuInflater(this);
inflater.inflate(R.menu.conversations, menu); inflater.inflate(R.menu.conversations, menu);
return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
case R.id.disconnect: case R.id.disconnect:
server.setStatus(Status.DISCONNECTED); server.setStatus(Status.DISCONNECTED);
server.setMayReconnect(false); server.setMayReconnect(false);
binder.getService().getConnection(serverId).quitServer(); binder.getService().getConnection(serverId).quitServer();
server.clearConversations(); server.clearConversations();
setResult(RESULT_OK);
finish();
break; break;
case R.id.close: case R.id.close:
@ -448,18 +405,18 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
server.removeConversation(conversationToClose.getName()); server.removeConversation(conversationToClose.getName());
onRemoveConversation(conversationToClose.getName()); onRemoveConversation(conversationToClose.getName());
} else { } else {
Toast.makeText(this, getResources().getString(R.string.close_server_window), Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), getResources().getString(R.string.close_server_window), Toast.LENGTH_SHORT).show();
} }
break; break;
case R.id.join: case R.id.join:
startActivityForResult(new Intent(this, JoinActivity.class), REQUEST_CODE_JOIN); startActivityForResult(new Intent(getActivity(), JoinActivity.class), REQUEST_CODE_JOIN);
break; break;
case R.id.users: case R.id.users:
Conversation conversationForUserList = pagerAdapter.getItem(pager.getCurrentItem()); Conversation conversationForUserList = pagerAdapter.getItem(pager.getCurrentItem());
if (conversationForUserList.getType() == Conversation.TYPE_CHANNEL) { if (conversationForUserList.getType() == Conversation.TYPE_CHANNEL) {
Intent intent = new Intent(this, UsersActivity.class); Intent intent = new Intent(getActivity(), UsersActivity.class);
intent.putExtra( intent.putExtra(
Extra.USERS, Extra.USERS,
binder.getService().getConnection(server.getId()).getUsersAsStringArray( binder.getService().getConnection(server.getId()).getUsersAsStringArray(
@ -468,7 +425,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
); );
startActivityForResult(intent, REQUEST_CODE_USERS); startActivityForResult(intent, REQUEST_CODE_USERS);
} else { } else {
Toast.makeText(this, getResources().getString(R.string.only_usable_from_channel), Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), getResources().getString(R.string.only_usable_from_channel), Toast.LENGTH_SHORT).show();
} }
break; break;
} }
@ -481,8 +438,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* *
* @return the server object * @return the server object
*/ */
public Server getServer() public Server getServer() {
{
return server; return server;
} }
@ -490,8 +446,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* On conversation message * On conversation message
*/ */
@Override @Override
public void onConversationMessage(String target) public void onConversationMessage(String target) {
{
Conversation conversation = server.getConversation(target); Conversation conversation = server.getConversation(target);
if (conversation == null) { if (conversation == null) {
@ -522,17 +477,13 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
conversation.setStatus(status); conversation.setStatus(status);
} }
} }
// indicator.updateStateColors();
} }
/** /**
* On new conversation * On new conversation
*/ */
@Override @Override
public void onNewConversation(String target) public void onNewConversation(String target) {
{
createNewConversation(target); createNewConversation(target);
pager.setCurrentItem(pagerAdapter.getCount() - 1); pager.setCurrentItem(pagerAdapter.getCount() - 1);
@ -544,8 +495,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* *
* @param target * @param target
*/ */
public void createNewConversation(String target) public void createNewConversation(String target) {
{
pagerAdapter.addConversation(server.getConversation(target)); pagerAdapter.addConversation(server.getConversation(target));
tabLayout.update(); tabLayout.update();
@ -555,8 +505,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* On conversation remove * On conversation remove
*/ */
@Override @Override
public void onRemoveConversation(String target) public void onRemoveConversation(String target) {
{
int position = pagerAdapter.getPositionByName(target); int position = pagerAdapter.getPositionByName(target);
if (position != -1) { if (position != -1) {
@ -570,8 +519,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* On topic change * On topic change
*/ */
@Override @Override
public void onTopicChanged(String target) public void onTopicChanged(String target) {
{
// No implementation // No implementation
} }
@ -579,10 +527,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* On server status update * On server status update
*/ */
@Override @Override
public void onStatusUpdate() public void onStatusUpdate() {
{
EditText input = (EditText) findViewById(R.id.input);
if (server.isConnected()) { if (server.isConnected()) {
input.setEnabled(true); input.setEnabled(true);
} else { } else {
@ -599,7 +544,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
if (!binder.getService().getSettings().isReconnectEnabled() && !reconnectDialogActive) { if (!binder.getService().getSettings().isReconnectEnabled() && !reconnectDialogActive) {
reconnectDialogActive = true; reconnectDialogActive = true;
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getResources().getString(R.string.reconnect_after_disconnect, server.getTitle())) builder.setMessage(getResources().getString(R.string.reconnect_after_disconnect, server.getTitle()))
.setCancelable(false) .setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() { .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@ -635,9 +580,8 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* On activity result * On activity result
*/ */
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) public void onActivityResult(int requestCode, int resultCode, Intent data) {
{ if (resultCode != Activity.RESULT_OK) {
if (resultCode != RESULT_OK) {
// ignore other result codes // ignore other result codes
return; return;
} }
@ -646,19 +590,19 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
case REQUEST_CODE_SPEECH: case REQUEST_CODE_SPEECH:
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if (matches.size() > 0) { if (matches.size() > 0) {
((EditText) findViewById(R.id.input)).setText(matches.get(0)); input.setText(matches.get(0));
} }
break; break;
case REQUEST_CODE_JOIN: case REQUEST_CODE_JOIN:
joinChannelBuffer = data.getExtras().getString("channel"); joinChannelBuffer = data.getExtras().getString("channel");
break; break;
case REQUEST_CODE_USERS: case REQUEST_CODE_USERS:
Intent intent = new Intent(this, UserActivity.class); Intent intent = new Intent(getActivity(), UserActivity.class);
intent.putExtra(Extra.USER, data.getStringExtra(Extra.USER)); intent.putExtra(Extra.USER, data.getStringExtra(Extra.USER));
startActivityForResult(intent, REQUEST_CODE_USER); startActivityForResult(intent, REQUEST_CODE_USER);
break; break;
case REQUEST_CODE_NICK_COMPLETION: case REQUEST_CODE_NICK_COMPLETION:
insertNickCompletion((EditText) findViewById(R.id.input), data.getExtras().getString(Extra.USER)); insertNickCompletion(input, data.getExtras().getString(Extra.USER));
break; break;
case REQUEST_CODE_USER: case REQUEST_CODE_USER:
final int actionId = data.getExtras().getInt(Extra.ACTION); final int actionId = data.getExtras().getInt(Extra.ACTION);
@ -698,7 +642,6 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
EditText input = (EditText) findViewById(R.id.input);
input.setText(replyText); input.setText(replyText);
input.setSelection(replyText.length()); input.setSelection(replyText.length());
} }
@ -880,7 +823,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
input.setSelection(cursor, sel_end); input.setSelection(cursor, sel_end);
insertNickCompletion(input, users[result.get(0).intValue()]); insertNickCompletion(input, users[result.get(0).intValue()]);
} else if (result.size() > 0) { } else if (result.size() > 0) {
Intent intent = new Intent(this, UsersActivity.class); Intent intent = new Intent(getActivity(), UsersActivity.class);
String[] extra = new String[result.size()]; String[] extra = new String[result.size()];
int i = 0; int i = 0;
@ -901,7 +844,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* @param input The input line widget, with the incomplete nick selected * @param input The input line widget, with the incomplete nick selected
* @param nick The completed nick * @param nick The completed nick
*/ */
private void insertNickCompletion(EditText input, String nick) { private void insertNickCompletion(final EditText input, String nick) {
int start = input.getSelectionStart(); int start = input.getSelectionStart();
int end = input.getSelectionEnd(); int end = input.getSelectionEnd();
nick = removeStatusChar(nick); nick = removeStatusChar(nick);
@ -919,7 +862,6 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
@Override @Override
public void run() { public void run() {
// make the softkeyboard come up again (only if no hw keyboard is attached) // make the softkeyboard come up again (only if no hw keyboard is attached)
EditText input = (EditText) findViewById(R.id.input);
openSoftKeyboard(input); openSoftKeyboard(input);
} }
}); });
@ -931,7 +873,8 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* Open the soft keyboard (helper function) * Open the soft keyboard (helper function)
*/ */
private void openSoftKeyboard(View view) { private void openSoftKeyboard(View view) {
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
} }
/** /**
@ -940,8 +883,7 @@ public class ConversationActivity extends ActionBarActivity implements ServiceCo
* @param nick * @param nick
* @return nick without statuschar * @return nick without statuschar
*/ */
private String removeStatusChar(String nick) private String removeStatusChar(String nick) {
{
/* Discard status characters */ /* Discard status characters */
if (nick.startsWith("@") || nick.startsWith("+") if (nick.startsWith("@") || nick.startsWith("+")
|| nick.startsWith("%")) { || nick.startsWith("%")) {

View File

@ -1,64 +0,0 @@
/*
Yaaic - Yet Another Android IRC Client
Copyright 2009-2013 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.listener;
import org.yaaic.activity.ConversationActivity;
import android.app.Activity;
import android.content.Intent;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.View.OnClickListener;
/**
* OnClickListener for the Speech Recognition Button
*
* @author Sebastian Kaspari <sebastian@yaaic.org>
*/
public class SpeechClickListener implements OnClickListener
{
private final Activity activity;
/**
* Create a new listener for speech button
*
* @param activity
* @param input
*/
public SpeechClickListener(Activity activity)
{
this.activity = activity;
}
/**
* On Click on speech button
*/
@Override
public void onClick(View v)
{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "");
activity.startActivityForResult(intent, ConversationActivity.REQUEST_CODE_SPEECH);
}
}

View File

@ -1,7 +1,7 @@
/* /*
Yaaic - Yet Another Android IRC Client Yaaic - Yet Another Android IRC Client
Copyright 2009-2013 Sebastian Kaspari Copyright 2009-2015 Sebastian Kaspari
Copyright 2012 Daniel E. Moctezuma <democtezuma@gmail.com> Copyright 2012 Daniel E. Moctezuma <democtezuma@gmail.com>
This file is part of Yaaic. This file is part of Yaaic.
@ -21,13 +21,13 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.yaaic.model; package org.yaaic.model;
import org.yaaic.R;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import org.yaaic.R;
/** /**
* The settings class is a helper class to access the different preferences via * The settings class is a helper class to access the different preferences via
* small and simple methods. * small and simple methods.
@ -198,19 +198,6 @@ public class Settings
)); ));
} }
/**
* Is voice recognition enabled?
*
* @return True if voice recognition is enabled, false otherwise
*/
public boolean isVoiceRecognitionEnabled()
{
return preferences.getBoolean(
resources.getString(R.string.key_voice_recognition),
Boolean.parseBoolean(resources.getString(R.string.default_voice_recognition))
);
}
/** /**
* Play notification sound on highlight? * Play notification sound on highlight?
* *

View File

@ -1,104 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Yaaic - Yet Another Android IRC Client
Copyright 2009-2015 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/>.
-->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/item_toolbar" />
<org.yaaic.view.ConversationTabLayout
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary" />
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_margin="4dp"
card_view:cardBackgroundColor="@color/cardview_background">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:padding="0dp" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_margin="4dp"
card_view:cardBackgroundColor="@color/cardview_background">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<EditText
android:id="@+id/input"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:imeOptions="actionSend"
android:background="@android:color/transparent"
android:inputType="textShortMessage" />
<ImageButton
android:id="@+id/send"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_action_send"
style="?android:attr/borderlessButtonStyle" />
<Button
android:id="@+id/speech"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_btn_speak_now"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<include layout="@layout/item_drawer" />
</android.support.v4.widget.DrawerLayout>

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"
<!--
Yaaic - Yet Another Android IRC Client
Copyright 2009-2015 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"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<org.yaaic.view.ConversationTabLayout
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="4dp"
android:layout_weight="1"
card_view:cardBackgroundColor="@color/cardview_background">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:padding="0dp" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
card_view:cardBackgroundColor="@color/cardview_background">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<EditText
android:id="@+id/input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:imeOptions="actionSend"
android:inputType="textShortMessage" />
<ImageButton
android:id="@+id/send"
style="?android:attr/borderlessButtonStyle"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_action_send" />
<Button
android:id="@+id/speech"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_btn_speak_now"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

View File

@ -33,9 +33,6 @@
<string name="key_fontsize" translatable="false">fontsize</string> <string name="key_fontsize" translatable="false">fontsize</string>
<string name="default_fontsize" translatable="false">11</string> <string name="default_fontsize" translatable="false">11</string>
<string name="key_voice_recognition" translatable="false">voice_recognition</string>
<string name="default_voice_recognition" translatable="false">false</string>
<string name="key_show_joinpartquit" translatable="false">show_joinpartquit</string> <string name="key_show_joinpartquit" translatable="false">show_joinpartquit</string>
<string name="default_show_joinpartquit" translatable="false">true</string> <string name="default_show_joinpartquit" translatable="false">true</string>

View File

@ -148,11 +148,6 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/settings_misc"> android:title="@string/settings_misc">
<CheckBoxPreference
android:title="@string/settings_voice_recognition_title"
android:summary="@string/settings_voice_recognition_desc"
android:key="@string/key_voice_recognition"
android:defaultValue="@string/default_voice_recognition" />
<EditTextPreference <EditTextPreference
android:title="@string/settings_quitmessage_title" android:title="@string/settings_quitmessage_title"
android:summary="@string/settings_quitmessage_desc" android:summary="@string/settings_quitmessage_desc"