Android Programming Tutorials

(Romina) #1
Opening a JAR

Twitter client=new Twitter(user.getText().toString(),
password.getText().toString());

client.setAPIRootUrl("https://identi.ca/api");
client.updateStatus(status.getText().toString());
}
catch (Throwable t) {
Log.e("Patchy", "Exception in updateStatus()", t);
goBlooey(t);
}
}

private void goBlooey(Throwable t) {
AlertDialog.Builder builder=new AlertDialog.Builder(this);

builder
.setTitle("Exception!")
.setMessage(t.toString())
.setPositiveButton("OK", null)
.show();
}

private View.OnClickListener onSend=new View.OnClickListener() {
public void onClick(View v) {
updateStatus();
}
};
}

Besides getting rid of all HttpClient references, we reimplemented


updateStatus() to create a Twitter object (with our user name and


password), then called its own updateStatus() method with the typed-in


status.


If you rebuild and reinstall Patchy, you can once again update your status,


just with half of the lines of code.


Step #3: Create Preferences for Account Information.....................


Rather than have the user enter their account information every time they


run Patchy, we should store that information in user preferences, so it can


be entered only on occasion.


First, we need a preference XML file, so create a new file,


Patchy/res/xml/preferences.xml, with the following contents:


167
Free download pdf