-
-
Save joeykrim/3487283 to your computer and use it in GitHub Desktop.
Whats New Dialog with Follow on Twitter Button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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