Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit f7ddc0f3 authored by gokul swaminathan's avatar gokul swaminathan Committed by GitHub
Browse files

Merge pull request #113 from Fs00/clipdata

Miscellaneous fixes to sharing intents
parents b633abd9 8213ae42
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -24,10 +24,12 @@

package com.gsnathan.pdfviewer;

import android.content.ActivityNotFoundException;
import android.os.Bundle;

import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.franmontiel.attributionpresenter.AttributionPresenter;
import com.franmontiel.attributionpresenter.entities.Attribution;
@@ -92,17 +94,9 @@ public class AboutActivity extends CyaneaAppCompatActivity {
                                .setWebsite("https://github.com/barteksc/AndroidPdfViewer")
                                .build()
                )
                .addAttributions(
                        new Attribution.Builder("AndroidAnnotations")
                                .addCopyrightNotice("Copyright 2012-2016 eBusiness Information\n" +
                                        "Copyright 2016-2017 the AndroidAnnotations project")
                                .addLicense(License.APACHE)
                                .setWebsite("https://github.com/androidannotations/androidannotations")
                                .build()
                )
                .addAttributions(
                        new Attribution.Builder("AppIntro")
                                .addCopyrightNotice("Copyright 2018 paorotolo")
                                .addCopyrightNotice("Copyright 2018 Paolo Rotolo")
                                .addLicense(License.APACHE)
                                .setWebsite("https://github.com/paolorotolo/AppIntro")
                                .build()
@@ -149,7 +143,12 @@ public class AboutActivity extends CyaneaAppCompatActivity {
    }

    public void emailDev(View v) {
        startActivity(Utils.emailIntent("gokulswamilive@gmail.com", "Pdf Viewer Plus", APP_VERSION_RELEASE, "Send email..."));
        String email = "gokulswamilive@gmail.com";
        try {
            startActivity(Utils.emailIntent(email, "Pdf Viewer Plus", APP_VERSION_RELEASE));
        } catch (ActivityNotFoundException e) {
            Toast.makeText(this, email, Toast.LENGTH_SHORT).show();
        }
    }

    public void navToGit(View v) {
+7 −1
Original line number Diff line number Diff line
@@ -178,7 +178,13 @@ public class MainActivity extends CyaneaAppCompatActivity {
    }

    void shareFile() {
        startActivity(Utils.emailIntent(pdfFileName, "", getResources().getString(R.string.share), uri));
        Intent sharingIntent;
        if (uri.getScheme() != null && uri.getScheme().startsWith("http")) {
            sharingIntent = Utils.plainTextShareIntent(getString(R.string.share), uri.toString());
        } else {
            sharingIntent = Utils.fileShareIntent(getString(R.string.share), pdfFileName, uri);
        }
        startActivity(sharingIntent);
    }

    private void openSelectedDocument(Uri selectedDocumentUri) {
+19 −12
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@

package com.gsnathan.pdfviewer;

import android.content.ClipData;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
@@ -61,22 +62,28 @@ public class Utils {
        log.show(context.getSupportFragmentManager(), "Log");
    }

    static Intent emailIntent(String emailAddress, String subject, String text, String title) {
        Intent email = new Intent(Intent.ACTION_SEND);
        email.setType("text/email");
        email.putExtra(Intent.EXTRA_EMAIL, new String[]{emailAddress});
    static Intent emailIntent(String emailAddress, String subject, String text) {
        Intent email = new Intent(Intent.ACTION_SENDTO);
        email.setData(Uri.parse("mailto:" + emailAddress));
        email.putExtra(Intent.EXTRA_SUBJECT, subject);
        email.putExtra(Intent.EXTRA_TEXT, text);
        return Intent.createChooser(email, title);
        return email;
    }

    static Intent emailIntent(String subject, String text, String title, Uri filePath) {
        Intent email = new Intent(Intent.ACTION_SEND);
        email.setType("text/email");
        email.putExtra(Intent.EXTRA_SUBJECT, subject);
        email.putExtra(Intent.EXTRA_TEXT, text);
        email.putExtra(Intent.EXTRA_STREAM, filePath);
        return Intent.createChooser(email, title);
    static Intent plainTextShareIntent(String chooserTitle, String text) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, text);
        return Intent.createChooser(intent, chooserTitle);
    }

    static Intent fileShareIntent(String chooserTitle, String fileName, Uri fileUri) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("application/pdf");
        intent.putExtra(Intent.EXTRA_STREAM, fileUri);
        intent.setClipData(new ClipData(fileName, new String[] { "application/pdf" }, new ClipData.Item(fileUri)));
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        return Intent.createChooser(intent, chooserTitle);
    }

    static Intent linkIntent(String url) {