Android Programming Tutorials

(Romina) #1
No, Really Listening To Your Friends

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)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;
}
};


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


status=(EditText)findViewById(R.id.status);


Button send=(Button)findViewById(R.id.send);


send.setOnClickListener(onSend);


prefs=PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(prefListener);


bindService(new Intent(this, PostMonitor.class), svcConn,
BIND_AUTO_CREATE);


adapter=new TimelineAdapter();
((ListView)findViewById(R.id.timeline)).setAdapter(adapter);
}


@Override
public void onDestroy() {
super.onDestroy();


194
Free download pdf