Permalink
Browse files

ActionBar implementation

  • Loading branch information...
1 parent cb8080b commit ad67f27bd5e902c612d1ea2f812c03f279656f91 Mike Wolfson committed Dec 3, 2012
View
@@ -5,7 +5,7 @@
android:versionName="1.0" >
<uses-sdk
- android:minSdkVersion="8"
+ android:minSdkVersion="14"
android:targetSdkVersion="16" />
<application
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,20 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <item
+ android:id="@+id/menu_main"
+ android:icon="@drawable/menu_main"
+ android:showAsAction="never"
+ android:title="@string/expenses_main"/>
+ <item
+ android:id="@+id/menu_email"
+ android:icon="@drawable/menu_email"
+ android:showAsAction="ifRoom"
+ android:title="@string/email_dev"/>
+ <item
+ android:id="@+id/menu_share"
+ android:icon="@drawable/menu_share"
+ android:showAsAction="ifRoom"
+ android:title="@string/share"
+ android:actionProviderClass="android.widget.ShareActionProvider" />
+
+</menu>
View
@@ -14,5 +14,10 @@
<string name="details_example_text">Example text : $11.11</string>
<string name="tax_deductable">Tax Deductable?</string>
<string name="receipt">Receipt</string>
+ <string name="expense_detail">Expense Detail</string>
+ <string name="email_dev">Email Dev</string>
+ <string name="expenses_main">Expenses Main</string>
+ <string name="example">Example</string>
+ <string name="share">Share</string>
</resources>
@@ -4,24 +4,93 @@
package com.andevcon.bootcamp;
import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
import android.os.Bundle;
+import android.util.Log;
import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.ShareActionProvider;
+import android.widget.Toast;
/**
*
*/
public class DetailActivity extends Activity {
-
+ private ShareActionProvider provider;
+
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
+
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ getActionBar().setTitle(R.string.expense_detail);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.activity_main, menu);
+ getMenuInflater().inflate(R.menu.detail_menu, menu);
+
+ //Setup share functionality
+ MenuItem item = menu.findItem(R.id.menu_share);
+ provider = (ShareActionProvider) item.getActionProvider();
+ setShareIntent();
+
return true;
}
+
+ /* Handles item selections */
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ Intent homeIntent = new Intent(this, MainActivity.class);
+ startActivity(homeIntent);
+ return true;
+ case R.id.menu_main:
+ Intent mainIntent = new Intent(this, MainActivity.class);
+ startActivity(mainIntent);
+ return true;
+ case R.id.menu_email:
+ String[] mailto = new String[] { "adcbootcamp@email.com" };
+ String subject = "Subject: ";
+ String body = "Body:";
+
+ Intent email = new Intent(Intent.ACTION_SEND);
+ email.setType("message/rfc822");
+ email.putExtra(Intent.EXTRA_EMAIL, mailto);
+ email.putExtra(Intent.EXTRA_SUBJECT, subject);
+ email.putExtra(Intent.EXTRA_TEXT, body);
+
+ try {
+ startActivity(email);
+ } catch (Exception e) {
+ Context context = getApplicationContext();
+ String text = "Oops, does your email work?";
+ int duration = Toast.LENGTH_LONG;
+
+ Toast toast = Toast.makeText(context, text, duration);
+ toast.show();
+ return true;
+ }
+ return false;
+ }
+ return false;
+ }
+
+ public void setShareIntent() {
+ String shareSubject = "Expense to share: ";
+ String shareText = "Expense info: ";
+
+ final Intent intent = new Intent(Intent.ACTION_SEND);
+ intent.setType("text/plain");
+ intent.putExtra(Intent.EXTRA_SUBJECT, shareSubject);
+ intent.putExtra(Intent.EXTRA_TEXT, shareText);
+ if (provider != null) {
+ provider.setShareIntent(intent);
+ }
+ }
}

0 comments on commit ad67f27

Please sign in to comment.