Skip to content

Instantly share code, notes, and snippets.

@joeykrim
Forked from koush/poop.java
Created August 27, 2012 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeykrim/3487283 to your computer and use it in GitHub Desktop.
Save joeykrim/3487283 to your computer and use it in GitHub Desktop.
Whats New Dialog with Follow on Twitter Button
//Credits:
//http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application
//https://gist.github.com/3087486
private void whatsNewDialog() {
//requestWindowFeature(Window.FEATURE_NO_TITLE);
//Dialog dialog = new Dialog(main.this);
final Dialog dialog = new Dialog(this, R.style.NoTitleDialog);
dialog.setContentView(R.layout.whatsnew);
//dialog.setTitle(getString(R.string.app_name) + " v" + currentAppVersion);
dialog.setCancelable(false);
//set up Title
TextView textWhatsNewTitle = (TextView) dialog.findViewById(R.id.whatsNewTitle);
textWhatsNewTitle.setText(getString(R.string.mainTitle) + " v" + currentAppVersion);
//set up text content
TextView textWhatsNewContent = (TextView) dialog.findViewById(R.id.tvWhatsNew);
textWhatsNewContent.setText(R.string.whatsNew);
//set up image view
ImageView img = (ImageView) dialog.findViewById(R.id.whatsNewRootIcon);
img.setImageResource(R.drawable.icon);
//set up Okay button
Button btnOkay = (Button) dialog.findViewById(R.id.whatsNewBtnOkay);
btnOkay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
editor.putLong(PREF_WHATS_NEW_LAST_VERSION, currentAppVersionCode);
editor.commit();
dialog.dismiss();
}
});
//check for Twitter application
boolean twitterInstalled = false;;
try {
PackageManager packman = getPackageManager();
packman.getPackageInfo("com.twitter.android", 0);
twitterInstalled = true;
} catch (Exception ex) {
//ex.printStackTrace();
twitterInstalled = false;
}
//set up Twitter button
Button btnFollow = (Button) dialog.findViewById(R.id.followOnTwitter);
btnFollow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// this is the intent you actually want.
// grabbed this by hooking a debugger up to twitter and debugging into android framework source.
// this let me inspect the contents of the intent.
Intent i = new Intent();
i.setClassName("com.twitter.android", "com.twitter.android.ProfileActivity");
i.putExtra("screen_name", "joeykrim");
try {
startActivity(i);
}
catch (Exception ex) {
// uh something failed
ex.printStackTrace();
}
}
});
//Log.d(LOG_TAG, "twiterinstalled: " + twitterInstalled);
if (twitterInstalled) btnFollow.setVisibility(VISIBILITY_VISIBLE);
//now that the dialog is set up, it's time to show it
dialog.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment