Android Programming Tutorials

(Romina) #1
Your Friends Seem Remote

package apt.tutorial.two;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import winterwell.jtwitter.Twitter;
import apt.tutorial.IPostListener;
import apt.tutorial.IPostMonitor;


public class Patchy extends Activity {
private EditText status=null;
private SharedPreferences prefs=null;
private Twitter client=null;
private List timeline=new ArrayList();
private TimelineAdapter adapter=null;
private IPostMonitor service=null;
private ServiceConnection svcConn=new ServiceConnection() {
public void onServiceConnected(ComponentName className,
IBinder binder) {
service=IPostMonitor.Stub.asInterface(binder);


try {
service.registerAccount(prefs.getString("user", null),
prefs.getString("password", null),
listener);
}
catch (Throwable t) {
Log.e("Patchy", "Exception in call to registerAccount()", t);
goBlooey(t);
}
}


public void onServiceDisconnected(ComponentName className) {
service=null;


210
Free download pdf