Skip to content

Commit

Permalink
implemented sharing via android share provider
Browse files Browse the repository at this point in the history
  • Loading branch information
konradrenner committed Jul 17, 2015
1 parent 1dab415 commit 72109d1
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 13 deletions.
13 changes: 12 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@
<activity
android:name=".DetailActivity"
android:windowSoftInputMode="adjustPan"
android:label="" >
android:label="@string/app_name" >

<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/html" />
</intent-filter>
</activity>
<activity
android:name=".security.AuthenticatorActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import org.kore.kolabnotes.android.fragment.DetailFragment;
import org.kore.kolabnotes.android.fragment.OnFragmentCallback;

public class DetailActivity extends AppCompatActivity implements OnFragmentCallback {

public static String FROM_DETAIL = "fromDetailTrue";

private DetailFragment detailFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if(toolbar != null){
toolbar.setTitle("");
}

detailFragment = (DetailFragment)getFragmentManager().findFragmentById(R.id.detail_fragment);

Intent startIntent = getIntent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
Expand All @@ -25,6 +26,7 @@
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.support.v7.widget.ShareActionProvider;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.Toast;
Expand Down Expand Up @@ -167,10 +169,6 @@ public void onFocusChange(View view, boolean b) {
});
initEditor();

//shareIntent = new Intent();
//shareIntent.setAction(Intent.ACTION_SEND);
//shareIntent.setType("text/plain");

// Handle Back Navigation :D
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -187,6 +185,24 @@ public void onClick(View v) {
String accountEmail = startIntent.getStringExtra(Utils.INTENT_ACCOUNT_EMAIL);
String rootFolder = startIntent.getStringExtra(Utils.INTENT_ACCOUNT_ROOT_FOLDER);

String action = startIntent.getAction();

if (Intent.ACTION_SEND.equals(action)) {
String description = startIntent.getStringExtra(Intent.EXTRA_TEXT);
String summary = startIntent.getStringExtra(Intent.EXTRA_SUBJECT);

if(!TextUtils.isEmpty(description)) {
String updatedDesc = initImageMap(description);
editor.setHtml(updatedDesc);
}

if(!TextUtils.isEmpty(summary)) {
EditText esummary = (EditText) activity.findViewById(R.id.detail_summary);
esummary.setText(summary);

}
}

Log.d("onCreate", "accountEmail:" + accountEmail);
Log.d("onCreate","rootFolder:"+rootFolder);
Log.d("onCreate","notebook-uid:"+notebook);
Expand Down Expand Up @@ -548,13 +564,41 @@ void setSpinnerSelection(String notebookSummary){
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.detail_toolbar, menu);
}

String setShareIntentSubject(Intent shareIntent){
EditText summary = (EditText) activity.findViewById(R.id.detail_summary);
String ssummary = summary.getText().toString();
if(!TextUtils.isEmpty(ssummary)) {
shareIntent.putExtra(Intent.EXTRA_SUBJECT, ssummary);
return ssummary;
}
return null;
}

//MenuItem item = menu.findItem(R.id.share);
String setShareIntentDescription(Intent shareIntent){
String descriptionValue = repairImages(getDescriptionFromView());
if(descriptionValue != null) {
if(!descriptionValue.startsWith("<!DOCTYPE HTML")) {
descriptionValue = HTMLSTART + repairImages(getDescriptionFromView()) + HTMLEND;
}

//shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
shareIntent.putExtra(Intent.EXTRA_TEXT, descriptionValue);
return descriptionValue;
}
return null;
}

public boolean shareNote(Intent shareIntent) {
setShareIntentSubject(shareIntent);
String descriptionValue = setShareIntentDescription(shareIntent);

//shareActionProvider.setShareIntent(shareIntent);
//shareActionProvider.setOnShareTargetSelectedListener(this);
if(!TextUtils.isEmpty(descriptionValue)) {
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
}else{
Toast.makeText(activity,R.string.empty_note,Toast.LENGTH_LONG).show();
}
return false;
}

@Override
Expand All @@ -575,6 +619,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.colorpicker:
chooseColor();
break;
case R.id.share:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/html");
shareNote(shareIntent);
break;
}
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/menu/detail_toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
app:showAsAction="ifRoom"
android:icon="@drawable/ic_action_choose_color"
android:title="@string/title_colorpicker"/>
<!--

<item android:id="@+id/share"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_action_share"
android:title="@string/title_share"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/> -->
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>

<item android:id="@id/ok_menu"
app:showAsAction="always"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,6 @@
<string name="dialog_delete_nb_warning">Notizbuch löschen</string>
<string name="no_nb_selected">Kein Notizbuch ausgewählt</string>
<string name="dialog_question_delete_nb">Das Notizbuch und alle sein Notizen werden gelöscht, sind Sie sicher?</string>
<string name="send_to">Noitz teilen mit...</string>
<string name="empty_note">Leere Notiz kann nicht geteilt werden</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@
<string name="note_saved">Note saved</string>
<string name="sync_failed">Synchronisation failed</string>
<string name="title_delete_notebook">Delete notebook</string>
<string name="send_to">Share note with...</string>
<string name="empty_note">Note is empty</string>
</resources>

0 comments on commit 72109d1

Please sign in to comment.