by swapsnil » Tue Apr 15, 2008 12:03 pm
Hi all,
I am using tatasu's code for creating a gtalk service(chat client).
Here two classes are used one is messaging.java and other is simpletalk.java.
In the methods of messaging.java we have many methods overridden.
But this methods are not overridded in the code i am getting.
The messaging.java is as below....can you plz tell me how can this be done....i have tried the overridding phenomenon(as how a method is overrided), but i am still facing the problem..
The lines creating problems are made red....
package com.tatsu.android.simpletalk;
import android.app.ListActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.Resources;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.IBinder;
import android.provider.Im;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import com.google.android.gtalkservice.GTalkServiceConstants;
import com.google.android.gtalkservice.IChatSession;
import com.google.android.gtalkservice.IGTalkService;
import com.google.android.gtalkservice.IGTalkSession;
public class Messaging extends ListActivity implements ServiceConnection {
private IGTalkSession mIGTalkSession;
private String mAccountName;
private String mContactName;
@Override
protected void onCreate(Bundle icicle) {
final String[] from = new String[] { Im.Messages.TYPE, Im.Messages.BODY };
final int[] to = new int[] { R.id.message_from, R.id.message_body };
super.onCreate(icicle);
setContentView(R.layout.messaging);
bindService(new Intent().setComponent(GTalkServiceConstants.GTALK_SERVICE_COMPONENT), this, 0);
Resources res = getResources();
Bundle extras = getIntent().getExtras();
mAccountName = extras.getString(res.getString(R.string.name_account).toString());
mContactName = extras.getString(res.getString(R.string.name_contact).toString());
setListAdapter(new SimpleCursorAdapter(this, R.layout.message_line, managedQuery(Im.Messages.CONTENT_URI, null,
Im.Messages.CONTACT + "='" + mContactName + "'", Im.Messages.DATE + " ASC"), from, to) {
@Override
public void setViewText(TextView v, String text) {
super.setViewText(v, convText(v, text));
}
});
EditText inputMessage = (EditText) findViewById(R.id.input_message);
inputMessage.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) { switch (event.getAction()) { case KeyEvent.ACTION_UP:
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_NEWLINE:
sendMessage(mContactName, ((EditText) v).getText().toString());
((EditText) v).setText("");
return true;
default:
break;
}
break;
default:
break;
}
return false;
}
});
}
@Override
protected void onDestroy() {
unbindService(this);
super.onDestroy();
}
@Override
public void onContentChanged() {
super.onContentChanged();
int count = getListView().getCount();
if (count > 0) {
getListView().setSelection(count - 1);
}
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) { try {
mIGTalkSession = IGTalkService.Stub.asInterface(service).getDefaultSession();
} catch (DeadObjectException e) {
mIGTalkSession = null;
}
}
@Override
public void onServiceDisconnected(ComponentName name) { mIGTalkSession = null;
}
private String convText(TextView v, String text) {
switch (v.getId()) {
case R.id.message_from:
return Integer.valueOf(text).equals(Im.MessageType.INCOMING) ? mContactName : mAccountName;
}
return text;
}
private void sendMessage(String message_to, String message_body) {
IChatSession chatSession;
if (mIGTalkSession != null) {
try {
chatSession = mIGTalkSession.createChatSession(message_to);
chatSession.sendTextMessage(message_body);
} catch (DeadObjectException e) {
;
}
}
}
}