init
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package net.headlezz.androidjokepresenter;
|
||||
|
||||
import android.app.Application;
|
||||
import android.test.ApplicationTestCase;
|
||||
|
||||
/**
|
||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||
*/
|
||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
}
|
||||
9
androidjokepresenter/src/main/AndroidManifest.xml
Normal file
9
androidjokepresenter/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="net.headlezz.androidjokepresenter">
|
||||
|
||||
<application android:allowBackup="true" android:label="@string/app_name"
|
||||
android:supportsRtl="true">
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,69 @@
|
||||
package net.headlezz.androidjokepresenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.ShareActionProvider;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class JokePresenterActivity extends AppCompatActivity {
|
||||
|
||||
public static final String BUNDLE_ARG_JOKE = "joke";
|
||||
|
||||
TextView tvJokes;
|
||||
String joke;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.joke_presenster_activity);
|
||||
tvJokes = (TextView) findViewById(R.id.tvJokes);
|
||||
|
||||
if (savedInstanceState != null)
|
||||
setJokeFromBundle(savedInstanceState);
|
||||
else
|
||||
setJokeFromBundle(getIntent().getExtras());
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the joke from the bundle to the activity
|
||||
*
|
||||
* @param b undle
|
||||
*/
|
||||
private void setJokeFromBundle(Bundle b) {
|
||||
if (b.containsKey(BUNDLE_ARG_JOKE)) {
|
||||
joke = b.getString(BUNDLE_ARG_JOKE);
|
||||
tvJokes.setText(joke);
|
||||
} else
|
||||
throw new RuntimeException(JokePresenterActivity.class.getSimpleName() + " started without a joke!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Updated the share intent of the share action provider
|
||||
*/
|
||||
private void updateShareIntent(ShareActionProvider provider) {
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, joke);
|
||||
shareIntent.setType("text/plain");
|
||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_intent_title));
|
||||
provider.setShareIntent(shareIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.joke_presenter_activity_menu, menu);
|
||||
MenuItem item = menu.findItem(R.id.menu_item_share);
|
||||
ShareActionProvider mShareProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
|
||||
updateShareIntent(mShareProvider);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
outState.putString(BUNDLE_ARG_JOKE, joke);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
tools:text="A joke"
|
||||
android:id="@+id/tvJokes"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/menu_item_share"
|
||||
app:showAsAction="ifRoom"
|
||||
android:title="@string/share"
|
||||
app:actionProviderClass=
|
||||
"android.support.v7.widget.ShareActionProvider" />
|
||||
</menu>
|
||||
5
androidjokepresenter/src/main/res/values/strings.xml
Normal file
5
androidjokepresenter/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<resources>
|
||||
<string name="app_name">androidjokepresenter</string>
|
||||
<string name="share">Share</string>
|
||||
<string name="share_intent_title">I laughed so hard!</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.headlezz.androidjokepresenter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* To work on unit tests, switch the Test Artifact in the Build Variants view.
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user