Android Programming Tutorials

(Romina) #1
Opening a JAR

import android.widget.EditText;
import winterwell.jtwitter.Twitter;


public class Patchy extends Activity {
private EditText status=null;
private SharedPreferences prefs=null;
private Twitter client=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);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
new MenuInflater(getApplication())
.inflate(R.menu.option, menu);


return(super.onCreateOptionsMenu(menu));
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.prefs) {
startActivity(new Intent(this, EditPreferences.class));


return(true);
}


return(super.onOptionsItemSelected(item));
}


synchronized private Twitter getClient() {
if (client==null) {
client=new Twitter(prefs.getString("user", ""),
prefs.getString("password", ""));


client.setAPIRootUrl("https://identi.ca/api");
}


return(client);
}


synchronized private void resetClient() {


173
Free download pdf