@Override public boolean onOptionsItemSelected(MenuItem item) { Intent i = null; switch (item.getItemId()) { case android.R.id.home: return UIUtils.startActivity(MainActivity.class, this); case R.id.menu_about: DialogAboutFragment dial = new DialogAboutFragment(); dial.show(getFragmentManager(), getResources().getString(R.string.about_titre)); return true; case R.id.menu_twitter: return UIUtils.startActivity(SocialActivity.class, this); case R.id.menu_refresh: refresh(); return true; case R.id.menu_compose_google: sendMessage(SendSocial.plus); return true; case R.id.menu_compose_twitter: sendMessage(SendSocial.twitter); return true; case R.id.menu_sync: chargementDonnees(); return true; default: return super.onOptionsItemSelected(item); } }
/** * Permet d'envoyer un message en filtrant les intents * * @param type */ private void sendMessage(SendSocial type) { Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_TEXT, getString(R.string.hastag)); if (!UIUtils.filterIntent(this, type.name(), i)) { Toast.makeText( getBaseContext(), SendSocial.plus.equals(type) ? R.string.description_no_google : R.string.description_no_twitter, Toast.LENGTH_SHORT) .show(); } startActivity(Intent.createChooser(i, "Share URL")); }
private void chargementDonnees() { if (UIUtils.isNetworkAvailable(getBaseContext())) { if (FileUtils.isExternalStorageWritable()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder .setTitle(getString(R.string.sync_message_title)) .setMessage(getString(R.string.dial_message)) .setPositiveButton( R.string.dial_oui, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { appelerSynchronizer(true); } }) .setNeutralButton( R.string.dial_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // On ne fait rien } }) .setNegativeButton( R.string.dial_non, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { appelerSynchronizer(false); } }); builder.create(); builder.show(); } else { Toast.makeText(getBaseContext(), getText(R.string.sync_erreur), Toast.LENGTH_LONG).show(); } } else { Toast.makeText(getBaseContext(), getText(R.string.sync_erreur_reseau), Toast.LENGTH_LONG) .show(); } }