Merge "Updating sample to use Android M permissions model." into mnc-dev
diff --git a/content/DirectShare/Application/.gitignore b/content/DirectShare/Application/.gitignore
new file mode 100644
index 0000000..6eb878d
--- /dev/null
+++ b/content/DirectShare/Application/.gitignore
@@ -0,0 +1,16 @@
+# Copyright 2013 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+src/template/
+src/common/
+build.gradle
diff --git a/content/DirectShare/Application/README-singleview.txt b/content/DirectShare/Application/README-singleview.txt
new file mode 100644
index 0000000..0cacd46
--- /dev/null
+++ b/content/DirectShare/Application/README-singleview.txt
@@ -0,0 +1,47 @@
+<#--
+        Copyright 2013 The Android Open Source Project
+
+        Licensed under the Apache License, Version 2.0 (the "License");
+        you may not use this file except in compliance with the License.
+        You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+-->
+
+Steps to implement SingleView template:
+-in template-params.xml.ftl:
+    -add the following line to common imports
+        <common src="activities"/>
+
+    -add a string for the action button's text using the element name "sample_action".
+    This element should be a child of <strings>:
+        <strings>
+        ...
+        <sample_action>ButtonText</sample_action>
+        ...
+        </strings>
+
+
+
+-Add a Fragment to handle behavior.  In your MainActivity.java class, it will reference a Fragment
+ called (yourProjectName)Fragment.java.  Create that file in your project, using the "main" source
+ folder instead of "common" or "templates".
+   For instance, if your package name is com.example.foo, create the file
+   src/main/java/com/example/foo/FooFragment.java
+
+
+-Within this fragment, make sure that the onCreate method has the line
+ "setHasOptionsMenu(true);", to enable the fragment to handle menu events.
+
+-In order to override menu events, override onOptionsItemSelected.
+
+-refer to sampleSamples/singleViewSample for a reference implementation of a
+project built on this template.
+
+
diff --git a/content/DirectShare/Application/proguard-project.txt b/content/DirectShare/Application/proguard-project.txt
new file mode 100644
index 0000000..f2fe155
--- /dev/null
+++ b/content/DirectShare/Application/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
diff --git a/content/DirectShare/Application/src/androidTest/java/com/example/android/directshare/test/SampleTests.java b/content/DirectShare/Application/src/androidTest/java/com/example/android/directshare/test/SampleTests.java
new file mode 100644
index 0000000..1cd5402
--- /dev/null
+++ b/content/DirectShare/Application/src/androidTest/java/com/example/android/directshare/test/SampleTests.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.directshare.test;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+/**
+ * Tests for DirectShare sample.
+ */
+public class SampleTests extends ActivityInstrumentationTestCase2<MainActivity> {
+
+    private MainActivity mTestActivity;
+
+    public SampleTests() {
+        super(MainActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mTestActivity = getActivity();
+    }
+
+    /**
+     * Test if the test fixture has been set up correctly.
+     */
+    public void testPreconditions() {
+        assertNotNull("mTestActivity is null", mTestActivity);
+    }
+
+}
diff --git a/content/DirectShare/Application/src/main/AndroidManifest.xml b/content/DirectShare/Application/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..f760d68
--- /dev/null
+++ b/content/DirectShare/Application/src/main/AndroidManifest.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.example.android.directshare"
+    android:versionCode="1"
+    android:versionName="1.0">
+
+    <application
+        android:allowBackup="true"
+        android:icon="@mipmap/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/DirectShareTheme">
+
+        <activity
+            android:name=".MainActivity"
+            android:label="@string/app_name">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+        <activity
+            android:name=".SendMessageActivity"
+            android:label="@string/app_name"
+            android:theme="@style/DirectShareDialogTheme">
+            <intent-filter>
+                <action android:name="android.intent.action.SEND" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <data android:mimeType="text/plain" />
+            </intent-filter>
+            <meta-data
+                android:name="android.service.chooser.chooser_target_service"
+                android:value=".SampleChooserTargetService" />
+        </activity>
+
+        <activity
+            android:name=".SelectContactActivity"
+            android:label="@string/app_name"
+            android:theme="@style/DirectShareDialogTheme" />
+
+        <service
+            android:name=".SampleChooserTargetService"
+            android:label="@string/app_name"
+            android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE">
+            <intent-filter>
+                <action android:name="android.service.chooser.ChooserTargetService" />
+            </intent-filter>
+        </service>
+
+    </application>
+
+</manifest>
diff --git a/content/DirectShare/Application/src/main/java/com/example/android/directshare/Contact.java b/content/DirectShare/Application/src/main/java/com/example/android/directshare/Contact.java
new file mode 100644
index 0000000..4a1665e
--- /dev/null
+++ b/content/DirectShare/Application/src/main/java/com/example/android/directshare/Contact.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.directshare;
+
+/**
+ * Provides the list of dummy contacts. This sample implements this as constants, but real-life apps
+ * should use a database and such.
+ */
+public class Contact {
+
+    /**
+     * The list of dummy contacts.
+     */
+    public static final Contact[] CONTACTS = {
+            new Contact("Tereasa"),
+            new Contact("Chang"),
+            new Contact("Kory"),
+            new Contact("Clare"),
+            new Contact("Landon"),
+            new Contact("Kyle"),
+            new Contact("Deana"),
+            new Contact("Daria"),
+            new Contact("Melisa"),
+            new Contact("Sammie"),
+    };
+
+    /**
+     * The contact ID.
+     */
+    public static final String ID = "contact_id";
+
+    /**
+     * Representative invalid contact ID.
+     */
+    public static final int INVALID_ID = -1;
+
+    /**
+     * The name of this contact.
+     */
+    private final String mName;
+
+    /**
+     * Instantiates a new {@link Contact}.
+     *
+     * @param name The name of the contact.
+     */
+    public Contact(String name) {
+        mName = name;
+    }
+
+    /**
+     * Finds a {@link Contact} specified by a contact ID.
+     *
+     * @param id The contact ID. This needs to be a valid ID.
+     * @return A {@link Contact}
+     */
+    public static Contact byId(int id) {
+        return CONTACTS[id];
+    }
+
+    /**
+     * Gets the name of this contact.
+     *
+     * @return The name of this contact.
+     */
+    public String getName() {
+        return mName;
+    }
+
+    /**
+     * Gets the icon of this contact.
+     *
+     * @return The icon.
+     */
+    public int getIcon() {
+        return R.mipmap.logo_avatar;
+    }
+
+}
diff --git a/content/DirectShare/Application/src/main/java/com/example/android/directshare/ContactViewBinder.java b/content/DirectShare/Application/src/main/java/com/example/android/directshare/ContactViewBinder.java
new file mode 100644
index 0000000..5287b1c
--- /dev/null
+++ b/content/DirectShare/Application/src/main/java/com/example/android/directshare/ContactViewBinder.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.directshare;
+
+import android.widget.TextView;
+
+/**
+ * A simple utility to bind a {@link TextView} with a {@link Contact}.
+ */
+public class ContactViewBinder {
+
+    /**
+     * Binds the {@code textView} with the specified {@code contact}.
+     *
+     * @param contact  The contact.
+     * @param textView The TextView.
+     */
+    public static void bind(Contact contact, TextView textView) {
+        textView.setText(contact.getName());
+        textView.setCompoundDrawablesRelativeWithIntrinsicBounds(contact.getIcon(), 0, 0, 0);
+    }
+
+}
diff --git a/content/DirectShare/Application/src/main/java/com/example/android/directshare/MainActivity.java b/content/DirectShare/Application/src/main/java/com/example/android/directshare/MainActivity.java
new file mode 100644
index 0000000..d680186
--- /dev/null
+++ b/content/DirectShare/Application/src/main/java/com/example/android/directshare/MainActivity.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.directshare;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.Toolbar;
+
+/**
+ * Provides the landing screen of this sample. There is nothing particularly interesting here. All
+ * the codes related to the Direct Share feature are in {@link SampleChooserTargetService}.
+ */
+public class MainActivity extends Activity {
+
+    private EditText mEditBody;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.main);
+        setActionBar((Toolbar) findViewById(R.id.toolbar));
+        mEditBody = (EditText) findViewById(R.id.body);
+        findViewById(R.id.share).setOnClickListener(mOnClickListener);
+    }
+
+    private View.OnClickListener mOnClickListener = new View.OnClickListener() {
+        @Override
+        public void onClick(View v) {
+            switch (v.getId()) {
+                case R.id.share:
+                    share();
+                    break;
+            }
+        }
+    };
+
+    /**
+     * Emits a sample share {@link Intent}.
+     */
+    private void share() {
+        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
+        sharingIntent.setType("text/plain");
+        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, mEditBody.getText().toString());
+        startActivity(Intent.createChooser(sharingIntent, getString(R.string.send_intent_title)));
+    }
+
+}
diff --git a/content/DirectShare/Application/src/main/java/com/example/android/directshare/SampleChooserTargetService.java b/content/DirectShare/Application/src/main/java/com/example/android/directshare/SampleChooserTargetService.java
new file mode 100644
index 0000000..1e32599
--- /dev/null
+++ b/content/DirectShare/Application/src/main/java/com/example/android/directshare/SampleChooserTargetService.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.directshare;
+
+import android.content.ComponentName;
+import android.content.IntentFilter;
+import android.graphics.drawable.Icon;
+import android.os.Bundle;
+import android.service.chooser.ChooserTarget;
+import android.service.chooser.ChooserTargetService;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Provides the Direct Share items to the system.
+ */
+public class SampleChooserTargetService extends ChooserTargetService {
+
+    @Override
+    public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,
+                                                   IntentFilter matchedFilter) {
+        ComponentName componentName = new ComponentName(getPackageName(),
+                SendMessageActivity.class.getCanonicalName());
+        // The list of Direct Share items. The system will show the items the way they are sorted
+        // in this list.
+        ArrayList<ChooserTarget> targets = new ArrayList<>();
+        for (int i = 0; i < Contact.CONTACTS.length; ++i) {
+            Contact contact = Contact.byId(i);
+            Bundle extras = new Bundle();
+            extras.putInt(Contact.ID, i);
+            targets.add(new ChooserTarget(
+                    // The name of this target.
+                    contact.getName(),
+                    // The icon to represent this target.
+                    Icon.createWithResource(this, contact.getIcon()),
+                    // The ranking score for this target (0.0-1.0); the system will omit items with
+                    // low scores when there are too many Direct Share items.
+                    0.5f,
+                    // The name of the component to be launched if this target is chosen.
+                    componentName,
+                    // The extra values here will be merged into the Intent when this target is
+                    // chosen.
+                    extras));
+        }
+        return targets;
+    }
+
+}
diff --git a/content/DirectShare/Application/src/main/java/com/example/android/directshare/SelectContactActivity.java b/content/DirectShare/Application/src/main/java/com/example/android/directshare/SelectContactActivity.java
new file mode 100644
index 0000000..440facb
--- /dev/null
+++ b/content/DirectShare/Application/src/main/java/com/example/android/directshare/SelectContactActivity.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.directshare;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.ListAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+
+/**
+ * The dialog for selecting a contact to share the text with. This dialog is shown when the user
+ * taps on this sample's icon rather than any of the Direct Share contacts.
+ */
+public class SelectContactActivity extends Activity {
+
+    /**
+     * The action string for Intents.
+     */
+    public static final String ACTION_SELECT_CONTACT
+            = "com.example.android.directshare.intent.action.SELECT_CONTACT";
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.select_contact);
+        Intent intent = getIntent();
+        if (!ACTION_SELECT_CONTACT.equals(intent.getAction())) {
+            finish();
+            return;
+        }
+        // Set up the list of contacts
+        ListView list = (ListView) findViewById(R.id.list);
+        list.setAdapter(mAdapter);
+        list.setOnItemClickListener(mOnItemClickListener);
+    }
+
+    private final ListAdapter mAdapter = new BaseAdapter() {
+        @Override
+        public int getCount() {
+            return Contact.CONTACTS.length;
+        }
+
+        @Override
+        public Object getItem(int i) {
+            return Contact.byId(i);
+        }
+
+        @Override
+        public long getItemId(int i) {
+            return i;
+        }
+
+        @Override
+        public View getView(int i, View view, ViewGroup parent) {
+            if (view == null) {
+                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.contact, parent,
+                        false);
+            }
+            TextView textView = (TextView) view;
+            Contact contact = (Contact) getItem(i);
+            ContactViewBinder.bind(contact, textView);
+            return textView;
+        }
+    };
+
+    private final AdapterView.OnItemClickListener mOnItemClickListener
+            = new AdapterView.OnItemClickListener() {
+        @Override
+        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
+            Intent data = new Intent();
+            data.putExtra(Contact.ID, i);
+            setResult(RESULT_OK, data);
+            finish();
+        }
+    };
+
+}
diff --git a/content/DirectShare/Application/src/main/java/com/example/android/directshare/SendMessageActivity.java b/content/DirectShare/Application/src/main/java/com/example/android/directshare/SendMessageActivity.java
new file mode 100644
index 0000000..d291172
--- /dev/null
+++ b/content/DirectShare/Application/src/main/java/com/example/android/directshare/SendMessageActivity.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.directshare;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.TextView;
+import android.widget.Toast;
+
+/**
+ * Provides the UI for sharing a text with a {@link Contact}.
+ */
+public class SendMessageActivity extends Activity {
+
+    /**
+     * The request code for {@link SelectContactActivity}. This is used when the user doesn't select
+     * any of Direct Share icons.
+     */
+    private static final int REQUEST_SELECT_CONTACT = 1;
+
+    /**
+     * The text to share.
+     */
+    private String mBody;
+
+    /**
+     * The ID of the contact to share the text with.
+     */
+    private int mContactId;
+
+    // View references.
+    private TextView mTextContactName;
+    private TextView mTextMessageBody;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.send_message);
+        setTitle(R.string.sending_message);
+        // View references.
+        mTextContactName = (TextView) findViewById(R.id.contact_name);
+        mTextMessageBody = (TextView) findViewById(R.id.message_body);
+        // Resolve the share Intent.
+        boolean resolved = resolveIntent(getIntent());
+        if (!resolved) {
+            finish();
+            return;
+        }
+        // Bind event handlers.
+        findViewById(R.id.send).setOnClickListener(mOnClickListener);
+        // Set up the UI.
+        prepareUi();
+        // The contact ID will not be passed on when the user clicks on the app icon rather than any
+        // of the Direct Share icons. In this case, we show another dialog for selecting a contact.
+        if (mContactId == Contact.INVALID_ID) {
+            selectContact();
+        }
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        switch (requestCode) {
+            case REQUEST_SELECT_CONTACT:
+                if (resultCode == RESULT_OK) {
+                    mContactId = data.getIntExtra(Contact.ID, Contact.INVALID_ID);
+                }
+                // Give up sharing the send_message if the user didn't choose a contact.
+                if (mContactId == Contact.INVALID_ID) {
+                    finish();
+                    return;
+                }
+                prepareUi();
+                break;
+            default:
+                super.onActivityResult(requestCode, resultCode, data);
+        }
+    }
+
+    /**
+     * Resolves the passed {@link Intent}. This method can only resolve intents for sharing a plain
+     * text. {@link #mBody} and {@link #mContactId} are modified accordingly.
+     *
+     * @param intent The {@link Intent}.
+     * @return True if the {@code intent} is resolved properly.
+     */
+    private boolean resolveIntent(Intent intent) {
+        if (Intent.ACTION_SEND.equals(intent.getAction()) &&
+                "text/plain".equals(intent.getType())) {
+            mBody = intent.getStringExtra(Intent.EXTRA_TEXT);
+            mContactId = intent.getIntExtra(Contact.ID, Contact.INVALID_ID);
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Sets up the UI.
+     */
+    private void prepareUi() {
+        if (mContactId != Contact.INVALID_ID) {
+            Contact contact = Contact.byId(mContactId);
+            ContactViewBinder.bind(contact, mTextContactName);
+        }
+        mTextMessageBody.setText(mBody);
+    }
+
+    /**
+     * Delegates selection of a {@Contact} to {@link SelectContactActivity}.
+     */
+    private void selectContact() {
+        Intent intent = new Intent(this, SelectContactActivity.class);
+        intent.setAction(SelectContactActivity.ACTION_SELECT_CONTACT);
+        startActivityForResult(intent, REQUEST_SELECT_CONTACT);
+    }
+
+    private View.OnClickListener mOnClickListener = new View.OnClickListener() {
+        @Override
+        public void onClick(View view) {
+            switch (view.getId()) {
+                case R.id.send:
+                    send();
+                    break;
+            }
+        }
+    };
+
+    /**
+     * Pretends to send the text to the contact. This only shows a dummy message.
+     */
+    private void send() {
+        Toast.makeText(this,
+                getString(R.string.message_sent, mBody, Contact.byId(mContactId).getName()),
+                Toast.LENGTH_SHORT).show();
+        finish();
+    }
+
+}
diff --git a/content/DirectShare/Application/src/main/res/layout/contact.xml b/content/DirectShare/Application/src/main/res/layout/contact.xml
new file mode 100644
index 0000000..81122e1
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/layout/contact.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/contact_name"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:drawablePadding="16dp"
+    android:gravity="center_vertical"
+    android:paddingBottom="4dp"
+    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+    android:paddingTop="4dp"
+    android:textAppearance="@android:style/TextAppearance.Material.Body1"
+    tools:drawableStart="@mipmap/logo_avatar"
+    tools:text="Taro" />
diff --git a/content/DirectShare/Application/src/main/res/layout/main.xml b/content/DirectShare/Application/src/main/res/layout/main.xml
new file mode 100644
index 0000000..5b24b4a
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/layout/main.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <Toolbar
+        android:id="@+id/toolbar"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="?android:attr/colorPrimary"
+        android:elevation="4dp"
+        android:minHeight="?android:attr/actionBarSize"
+        android:popupTheme="@android:style/ThemeOverlay.Material.Light"
+        android:theme="@android:style/ThemeOverlay.Material.Dark.ActionBar" />
+
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_margin="16dp"
+        android:text="@string/explanation"
+        android:textAppearance="@android:style/TextAppearance.Material.Body1" />
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="1dp"
+        android:background="@android:color/darker_gray" />
+
+    <EditText
+        android:id="@+id/body"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="16dp"
+        android:layout_marginStart="16dp"
+        android:layout_marginTop="16dp"
+        android:hint="@string/text_to_share"
+        android:text="@string/hello" />
+
+    <Button
+        android:id="@+id/share"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="end"
+        android:layout_marginEnd="16dp"
+        android:layout_marginStart="16dp"
+        android:text="@string/share" />
+
+</LinearLayout>
diff --git a/content/DirectShare/Application/src/main/res/layout/send_message.xml b/content/DirectShare/Application/src/main/res/layout/send_message.xml
new file mode 100644
index 0000000..86671fc
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/layout/send_message.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="@dimen/dialog_padding"
+        android:layout_marginStart="@dimen/dialog_padding"
+        android:layout_marginTop="@dimen/dialog_padding"
+        android:orientation="horizontal">
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:gravity="center_vertical"
+            android:text="@string/to"
+            android:textAppearance="@android:style/TextAppearance.Material.Caption" />
+
+        <TextView
+            android:id="@+id/contact_name"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="16dp"
+            android:layout_weight="1"
+            android:drawablePadding="16dp"
+            android:gravity="center_vertical"
+            android:textAppearance="@android:style/TextAppearance.Material.Body1"
+            tools:drawableStart="@mipmap/logo_avatar"
+            tools:text="Taro" />
+
+    </LinearLayout>
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="@dimen/dialog_padding"
+        android:layout_marginStart="@dimen/dialog_padding"
+        android:layout_marginTop="16dp"
+        android:gravity="center_vertical"
+        android:text="@string/body"
+        android:textAppearance="@android:style/TextAppearance.Material.Caption" />
+
+    <TextView
+        android:id="@+id/message_body"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="@dimen/dialog_padding"
+        android:layout_marginStart="@dimen/dialog_padding"
+        android:gravity="top"
+        android:hint="@string/hint_body"
+        android:padding="8dp"
+        android:textAppearance="@android:style/TextAppearance.Material.Body1"
+        tools:text="Hello, world!" />
+
+    <Button
+        android:id="@+id/send"
+        style="@android:style/Widget.Material.Button.Borderless.Colored"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="end"
+        android:layout_marginBottom="@dimen/dialog_button_padding"
+        android:layout_marginEnd="@dimen/dialog_button_padding"
+        android:text="@string/send" />
+
+</LinearLayout>
diff --git a/content/DirectShare/Application/src/main/res/mipmap-hdpi/ic_launcher.png b/content/DirectShare/Application/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..988f2ec
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/mipmap-hdpi/ic_launcher.png
Binary files differ
diff --git a/content/DirectShare/Application/src/main/res/mipmap-hdpi/logo_avatar.png b/content/DirectShare/Application/src/main/res/mipmap-hdpi/logo_avatar.png
new file mode 100644
index 0000000..8892c08
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/mipmap-hdpi/logo_avatar.png
Binary files differ
diff --git a/content/DirectShare/Application/src/main/res/mipmap-mdpi/ic_launcher.png b/content/DirectShare/Application/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..0baa1cc
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/mipmap-mdpi/ic_launcher.png
Binary files differ
diff --git a/content/DirectShare/Application/src/main/res/mipmap-mdpi/logo_avatar.png b/content/DirectShare/Application/src/main/res/mipmap-mdpi/logo_avatar.png
new file mode 100644
index 0000000..c2de774
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/mipmap-mdpi/logo_avatar.png
Binary files differ
diff --git a/content/DirectShare/Application/src/main/res/mipmap-xhdpi/ic_launcher.png b/content/DirectShare/Application/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..da0aa2f
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary files differ
diff --git a/content/DirectShare/Application/src/main/res/mipmap-xhdpi/logo_avatar.png b/content/DirectShare/Application/src/main/res/mipmap-xhdpi/logo_avatar.png
new file mode 100644
index 0000000..10c2dc9
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/mipmap-xhdpi/logo_avatar.png
Binary files differ
diff --git a/content/DirectShare/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png b/content/DirectShare/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..e1cc1ff
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/content/DirectShare/Application/src/main/res/mipmap-xxhdpi/logo_avatar.png b/content/DirectShare/Application/src/main/res/mipmap-xxhdpi/logo_avatar.png
new file mode 100644
index 0000000..df02f04
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/mipmap-xxhdpi/logo_avatar.png
Binary files differ
diff --git a/content/DirectShare/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/content/DirectShare/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..8b0f60c
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/content/DirectShare/Application/src/main/res/mipmap-xxxhdpi/logo_avatar.png b/content/DirectShare/Application/src/main/res/mipmap-xxxhdpi/logo_avatar.png
new file mode 100644
index 0000000..dc8d376
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/mipmap-xxxhdpi/logo_avatar.png
Binary files differ
diff --git a/content/DirectShare/Application/src/main/res/values/colors.xml b/content/DirectShare/Application/src/main/res/values/colors.xml
new file mode 100644
index 0000000..c5a6a3d
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/values/colors.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+    <color name="primary">#3F51B5</color>
+    <color name="primary_dark">#303F9F</color>
+    <color name="primary_light">#C5CAE9</color>
+    <color name="accent">#00BCD4</color>
+    <color name="primary_text">#212121</color>
+    <color name="secondary_text">#727272</color>
+    <color name="icons">#FFFFFF</color>
+    <color name="divider">#B6B6B6</color>
+</resources>
diff --git a/content/DirectShare/Application/src/main/res/values/dimens.xml b/content/DirectShare/Application/src/main/res/values/dimens.xml
new file mode 100644
index 0000000..2d05f5d
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/values/dimens.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+    <dimen name="dialog_padding">24dp</dimen>
+    <dimen name="dialog_button_padding">8dp</dimen>
+</resources>
diff --git a/content/DirectShare/Application/src/main/res/values/strings.xml b/content/DirectShare/Application/src/main/res/values/strings.xml
new file mode 100644
index 0000000..ddc858a
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/values/strings.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+
+    <!-- MainActivity -->
+
+    <string name="explanation">
+        This app demonstrates how to implement Direct Share. Use some other app and share a text.
+        For your convenience, you can also use the input below to share the text.
+    </string>
+    <string name="hello">Hello!</string>
+    <string name="share">Share</string>
+    <string name="send_intent_title">Send a message via:</string>
+
+    <!-- SendMessageActivity -->
+
+    <string name="sending_message">Sending a message</string>
+    <string name="to">To:</string>
+    <string name="send">Send</string>
+    <string name="body">Body:</string>
+    <string name="hint_body">Edit your message.</string>
+    <string name="message_sent">Sent a message \"%1$s\" to %2$s.</string>
+    <string name="text_to_share">Text to share</string>
+
+</resources>
diff --git a/content/DirectShare/Application/src/main/res/values/styles.xml b/content/DirectShare/Application/src/main/res/values/styles.xml
new file mode 100644
index 0000000..ae312cc
--- /dev/null
+++ b/content/DirectShare/Application/src/main/res/values/styles.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+
+    <style name="DirectShareTheme" parent="android:Theme.Material.Light.NoActionBar">
+        <item name="android:colorPrimary">@color/primary</item>
+        <item name="android:colorPrimaryDark">@color/primary_dark</item>
+        <item name="android:colorAccent">@color/accent</item>
+    </style>
+
+    <style name="DirectShareDialogTheme" parent="android:Theme.Material.Light.Dialog">
+        <item name="android:colorPrimary">@color/primary</item>
+        <item name="android:colorPrimaryDark">@color/primary_dark</item>
+        <item name="android:colorAccent">@color/accent</item>
+    </style>
+
+</resources>
diff --git a/content/DirectShare/build.gradle b/content/DirectShare/build.gradle
new file mode 100644
index 0000000..9b6a9ce
--- /dev/null
+++ b/content/DirectShare/build.gradle
@@ -0,0 +1,12 @@
+
+
+// BEGIN_EXCLUDE
+import com.example.android.samples.build.SampleGenPlugin
+apply plugin: SampleGenPlugin
+
+samplegen {
+  pathToBuild "../../../../build"
+  pathToSamplesCommon "../../common"
+}
+apply from: "../../../../build/build.gradle"
+// END_EXCLUDE
diff --git a/content/DirectShare/buildSrc/build.gradle b/content/DirectShare/buildSrc/build.gradle
new file mode 100644
index 0000000..d77115d
--- /dev/null
+++ b/content/DirectShare/buildSrc/build.gradle
@@ -0,0 +1,16 @@
+
+repositories {
+    jcenter()
+}
+dependencies {
+    compile 'org.freemarker:freemarker:2.3.20'
+}
+
+sourceSets {
+    main {
+        groovy {
+            srcDir new File(rootDir, "../../../../../build/buildSrc/src/main/groovy")
+        }
+    }
+}
+
diff --git a/content/DirectShare/gradle/wrapper/gradle-wrapper.jar b/content/DirectShare/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..8c0fb64
--- /dev/null
+++ b/content/DirectShare/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/content/DirectShare/gradle/wrapper/gradle-wrapper.properties b/content/DirectShare/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..afb3296
--- /dev/null
+++ b/content/DirectShare/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Wed Apr 10 15:27:10 PDT 2013
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-bin.zip
diff --git a/content/DirectShare/gradlew b/content/DirectShare/gradlew
new file mode 100755
index 0000000..91a7e26
--- /dev/null
+++ b/content/DirectShare/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+    [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/content/DirectShare/gradlew.bat b/content/DirectShare/gradlew.bat
new file mode 100644
index 0000000..aec9973
--- /dev/null
+++ b/content/DirectShare/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off

+@rem ##########################################################################

+@rem

+@rem  Gradle startup script for Windows

+@rem

+@rem ##########################################################################

+

+@rem Set local scope for the variables with windows NT shell

+if "%OS%"=="Windows_NT" setlocal

+

+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.

+set DEFAULT_JVM_OPTS=

+

+set DIRNAME=%~dp0

+if "%DIRNAME%" == "" set DIRNAME=.

+set APP_BASE_NAME=%~n0

+set APP_HOME=%DIRNAME%

+

+@rem Find java.exe

+if defined JAVA_HOME goto findJavaFromJavaHome

+

+set JAVA_EXE=java.exe

+%JAVA_EXE% -version >NUL 2>&1

+if "%ERRORLEVEL%" == "0" goto init

+

+echo.

+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

+echo.

+echo Please set the JAVA_HOME variable in your environment to match the

+echo location of your Java installation.

+

+goto fail

+

+:findJavaFromJavaHome

+set JAVA_HOME=%JAVA_HOME:"=%

+set JAVA_EXE=%JAVA_HOME%/bin/java.exe

+

+if exist "%JAVA_EXE%" goto init

+

+echo.

+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%

+echo.

+echo Please set the JAVA_HOME variable in your environment to match the

+echo location of your Java installation.

+

+goto fail

+

+:init

+@rem Get command-line arguments, handling Windowz variants

+

+if not "%OS%" == "Windows_NT" goto win9xME_args

+if "%@eval[2+2]" == "4" goto 4NT_args

+

+:win9xME_args

+@rem Slurp the command line arguments.

+set CMD_LINE_ARGS=

+set _SKIP=2

+

+:win9xME_args_slurp

+if "x%~1" == "x" goto execute

+

+set CMD_LINE_ARGS=%*

+goto execute

+

+:4NT_args

+@rem Get arguments from the 4NT Shell from JP Software

+set CMD_LINE_ARGS=%$

+

+:execute

+@rem Setup the command line

+

+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

+

+@rem Execute Gradle

+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

+

+:end

+@rem End local scope for the variables with windows NT shell

+if "%ERRORLEVEL%"=="0" goto mainEnd

+

+:fail

+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of

+rem the _cmd.exe /c_ return code!

+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1

+exit /b 1

+

+:mainEnd

+if "%OS%"=="Windows_NT" endlocal

+

+:omega

diff --git a/content/DirectShare/screenshots/1-main.png b/content/DirectShare/screenshots/1-main.png
new file mode 100644
index 0000000..a0d46e4
--- /dev/null
+++ b/content/DirectShare/screenshots/1-main.png
Binary files differ
diff --git a/content/DirectShare/screenshots/2-intent.png b/content/DirectShare/screenshots/2-intent.png
new file mode 100644
index 0000000..4d6f7d0
--- /dev/null
+++ b/content/DirectShare/screenshots/2-intent.png
Binary files differ
diff --git a/content/DirectShare/screenshots/3-message.png b/content/DirectShare/screenshots/3-message.png
new file mode 100644
index 0000000..54f9e9f
--- /dev/null
+++ b/content/DirectShare/screenshots/3-message.png
Binary files differ
diff --git a/content/DirectShare/screenshots/icon-web.png b/content/DirectShare/screenshots/icon-web.png
new file mode 100644
index 0000000..ee7c557
--- /dev/null
+++ b/content/DirectShare/screenshots/icon-web.png
Binary files differ
diff --git a/content/DirectShare/settings.gradle b/content/DirectShare/settings.gradle
new file mode 100644
index 0000000..0a5c310
--- /dev/null
+++ b/content/DirectShare/settings.gradle
@@ -0,0 +1,2 @@
+
+include 'Application'
diff --git a/content/DirectShare/template-params.xml b/content/DirectShare/template-params.xml
new file mode 100644
index 0000000..d1a6f20
--- /dev/null
+++ b/content/DirectShare/template-params.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<sample>
+    <name>DirectShare</name>
+    <group>Content</group>
+    <package>com.example.android.directshare</package>
+    <minSdk>23</minSdk>
+    <targetSdkVersion>23</targetSdkVersion>
+    <compileSdkVersion>23</compileSdkVersion>
+
+    <strings>
+        <intro>
+            <![CDATA[
+This sample demonstrates how to provide the Direct Share feature. The app shows some options
+directly in the list of share intent candidates.
+            ]]>
+        </intro>
+    </strings>
+
+    <template src="base"/>
+
+    <metadata>
+        <status>PUBLISHED</status>
+        <categories>Content</categories>
+        <technologies>Android</technologies>
+        <languages>Java</languages>
+        <solutions>Mobile</solutions>
+        <level>INTERMEDIATE</level>
+        <icon>screenshots/icon-web.png</icon>
+        <screenshots>
+            <img>screenshots/1-main.png</img>
+            <img>screenshots/2-intent.png</img>
+            <img>screenshots/3-message.png</img>
+        </screenshots>
+        <api_refs>
+            <android>android.service.chooser.ChooserTargetService</android>
+            <android>android.service.chooser.ChooserTarget</android>
+        </api_refs>
+        <description>
+            <![CDATA[
+Sample demonstrating how to show some options directly in the list of share intent candidates.
+            ]]>
+        </description>
+        <intro>
+            <![CDATA[
+[Direct Share][1] is a feature that allows apps to show their internal options directly in the
+system Intent chooser dialog. This sample is a dummy messaging app, and just like any other
+messaging apps, it receives intents for sharing a plain text. When a user shares some text from some
+other app, this sample app will be listed as an option. Using the Direct Share feature, this app
+also shows some of contacts directly in the chooser dialog.
+
+To enable Direct Share, apps need to implement a Service extending
+[ChooserTargetService][2]. Override the method [onGetChooserTargets][3] and return a list of Direct
+Share options.
+
+In your AndroidManifest.xml, add a meta-data tag in your Activity that receives the Intent. Specify
+android:name as android.service.chooser.chooser_target_service, and point the android:value to the
+Service.
+
+[1]: https://developer.android.com/reference/android/service/chooser/package-summary.html
+[2]: https://developer.android.com/reference/android/service/chooser/ChooserTargetService.html
+[3]: https://developer.android.com/reference/android/service/chooser/ChooserTargetService.html#onGetChooserTargets(android.content.ComponentName, android.content.IntentFilter)
+            ]]>
+        </intro>
+    </metadata>
+</sample>