Skip to content

Commit

Permalink
Sharing Intent Added to TCD
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Kadyan authored and znck-graveyard committed Dec 26, 2013
1 parent 83c31d4 commit b74b8a7
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package org.techniche.technothlon.katana;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.ShareActionProvider;
import android.view.*;
import android.widget.TextView;
import android.widget.Toast;
import org.techniche.technothlon.katana.tcd.TCDContent;

import java.util.Locale;

public class TCDSingleViewer extends ActionBarActivity implements ViewPager.OnPageChangeListener {
private static int pages;
private ShareActionProvider mShareActionProvider;
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
Expand Down Expand Up @@ -51,19 +56,40 @@ public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.tcdsingle_viewer, menu);
return true;

MenuItem item = menu.findItem(R.id.action_share);
mShareActionProvider = (ShareActionProvider)
MenuItemCompat.getActionProvider(item);
mShareActionProvider.setShareIntent(getDefaultIntent());
return super.onCreateOptionsMenu(menu);
}

private Intent getDefaultIntent() {
Toast.makeText(getApplicationContext(), "Creating Intent with "+activePage, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_SEND);
TCDContent.TCDQuestion q = TCDContent.ITEM_MAP.get(TCDContent.ITEMS.get(this.activePage).id);
if (q != null)
{
intent.putExtra(Intent.EXTRA_SUBJECT, "Techno Coup D'œil #" + q.id + " - " + q.title);
intent.putExtra(Intent.EXTRA_TITLE, "Techno Coup D'œil #" + q.id + " - " + q.title);
// intent.putExtra(Intent.EXTRA_TEXT, "Hey! Check out this. " + q.facebook + "\nFollow Technothlon for more.");
intent.putExtra(Intent.EXTRA_TEXT, "Hey! Check out this Technothlon's question.\n" + q.question);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, R.drawable.ic_launcher);
}
intent.setType("text/*");
return intent;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
switch (item.getItemId()){
case R.id.action_settings: return true;
case R.id.action_share: mShareActionProvider.setShareIntent(getDefaultIntent()); return false;
default: return super.onOptionsItemSelected(item);
}
return super.onOptionsItemSelected(item);
}

@Override
Expand Down
169 changes: 85 additions & 84 deletions app/src/main/res/layout/fragment_tcdsingle_viewer.xml
Original file line number Diff line number Diff line change
@@ -1,95 +1,96 @@
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="org.techniche.technothlon.katana.TCDSingleViewer$PlaceholderFragment">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="@dimen/default_gap"
android:padding="@dimen/default_gap"
android:background="@drawable/tcd_content_back">

<TextView
android:layout_width="wrap_content"
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView">
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="org.techniche.technothlon.katana.TCDSingleViewer$PlaceholderFragment">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Question Title"
android:id="@+id/tcd_title"
android:textColor="@color/tcd_color_title_text"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
android:layout_alignParentTop="false"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:layout_marginTop="@dimen/default_gap"
android:padding="@dimen/default_gap"
android:background="@drawable/tcd_content_back"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Question Title"
android:id="@+id/tcd_title"
android:textColor="@color/tcd_color_title_text"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView"
android:layout_alignRight="@+id/tcd_title"
android:layout_alignEnd="@+id/tcd_title"
android:scrollbars="none"
android:layout_below="@+id/tcd_title"
android:layout_marginTop="@dimen/default_gap">

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="A Japanese ship was en route to the open sea. The Japanese captain went for a shower removing his diamond ring and Rolex watch on the table. When he returned, his valuables were missing. \n A Japanese ship was en route to the open sea. The Japanese captain went for a shower removing his diamond ring and Rolex watch on the table. When he returned, his valuables were missing."
android:id="@+id/tcd_question"
android:textColor="@color/tcd_color_content_text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_alignParentStart="true"
android:ellipsize="end"
android:layout_alignEnd="@+id/tcd_title"
android:paddingBottom="8dp"/>

<TextView
android:layout_width="match_parent"
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Posted By"
android:id="@+id/tcd_posted_by"
android:textAlignment="viewEnd"
android:gravity="right"/>
android:layout_below="@+id/tcd_title"
android:layout_marginTop="@dimen/default_gap">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Date and status"
android:id="@+id/tcd_status"
android:textColor="@color/tcd_color_status_text"
/>
</LinearLayout>
</ScrollView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="A Japanese ship was en route to the open sea. The Japanese captain went for a shower removing his diamond ring and Rolex watch on the table. When he returned, his valuables were missing. \n A Japanese ship was en route to the open sea. The Japanese captain went for a shower removing his diamond ring and Rolex watch on the table. When he returned, his valuables were missing."
android:id="@+id/tcd_question"
android:textColor="@color/tcd_color_content_text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_alignParentStart="true"
android:ellipsize="end"
android:layout_alignEnd="@+id/tcd_title"
android:paddingBottom="8dp"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Posted By"
android:autoLink="all"
android:id="@+id/tcd_posted_by"
android:textAlignment="viewEnd"
android:gravity="right"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Date and status"
android:id="@+id/tcd_status"
android:textColor="@color/tcd_color_status_text" />
</LinearLayout>

</RelativeLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#60"
android:singleLine="true"
android:id="@+id/tcd_id"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:padding="@dimen/default_gap"
android:background="@drawable/tcd_background_1"
android:textColor="@color/tcd_color_id_text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
/>
</RelativeLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#60"
android:singleLine="true"
android:id="@+id/tcd_id"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:padding="@dimen/default_gap"
android:background="@drawable/tcd_background_1"
android:textColor="@color/tcd_color_id_text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
/>
</RelativeLayout>
</ScrollView>
7 changes: 6 additions & 1 deletion app/src/main/res/menu/tcdsingle_viewer.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:yourapp="http://schemas.android.com/apk/res-auto"
tools:context="org.techniche.technothlon.katana.TCDSingleViewer">

<item android:id="@+id/action_share"
android:title="@string/str_action_share"
yourapp:showAsAction="ifRoom"
yourapp:actionProviderClass="android.support.v7.widget.ShareActionProvider"
/>
<item
android:id="@+id/action_facebook"
android:title="@string/str_action_facebook" />
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<string name="str_action_google">Read on Google+</string>
<string name="str_action_tumblr">Read on Tumblr</string>
<string name="str_action_disqus">Discuss Answer</string>
<string name="str_action_share">Share</string>

</resources>
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
dependencies {
}

0 comments on commit b74b8a7

Please sign in to comment.