Search in sources :

Example 91 with ClipData

use of android.content.ClipData in project Slide by ccrama.

the class PopulateShadowboxInfo method showBottomSheet.

public static void showBottomSheet(final Activity mContext, final Submission submission, final View rootView) {
    int[] attrs = new int[] { R.attr.tintColor };
    TypedArray ta = mContext.obtainStyledAttributes(attrs);
    int color = ta.getColor(0, Color.WHITE);
    Drawable profile = mContext.getResources().getDrawable(R.drawable.profile);
    final Drawable sub = mContext.getResources().getDrawable(R.drawable.sub);
    final Drawable report = mContext.getResources().getDrawable(R.drawable.report);
    Drawable copy = mContext.getResources().getDrawable(R.drawable.ic_content_copy);
    Drawable open = mContext.getResources().getDrawable(R.drawable.openexternal);
    Drawable link = mContext.getResources().getDrawable(R.drawable.link);
    Drawable reddit = mContext.getResources().getDrawable(R.drawable.commentchange);
    profile.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    sub.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    report.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    open.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    link.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    reddit.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    ta.recycle();
    BottomSheet.Builder b = new BottomSheet.Builder(mContext).title(Html.fromHtml(submission.getTitle()));
    if (Authentication.didOnline) {
        b.sheet(1, profile, "/u/" + submission.getAuthor()).sheet(2, sub, "/r/" + submission.getSubredditName());
        if (Authentication.isLoggedIn) {
            b.sheet(12, report, mContext.getString(R.string.btn_report));
        }
    }
    b.sheet(7, open, mContext.getString(R.string.submission_link_extern)).sheet(4, link, mContext.getString(R.string.submission_share_permalink)).sheet(8, reddit, mContext.getString(R.string.submission_share_reddit_url)).listener(new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch(which) {
                case 1:
                    {
                        Intent i = new Intent(mContext, Profile.class);
                        i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
                        mContext.startActivity(i);
                    }
                    break;
                case 2:
                    {
                        Intent i = new Intent(mContext, SubredditView.class);
                        i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
                        mContext.startActivityForResult(i, 14);
                    }
                    break;
                case 7:
                    LinkUtil.openExternally(submission.getUrl(), mContext);
                    break;
                case 4:
                    Reddit.defaultShareText(submission.getTitle(), submission.getUrl(), mContext);
                    break;
                case 12:
                    reportReason = "";
                    new MaterialDialog.Builder(mContext).input(mContext.getString(R.string.input_reason_for_report), null, true, new MaterialDialog.InputCallback() {

                        @Override
                        public void onInput(MaterialDialog dialog, CharSequence input) {
                            reportReason = input.toString();
                        }
                    }).alwaysCallInputCallback().title(R.string.report_post).inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES).positiveText(R.string.btn_report).negativeText(R.string.btn_cancel).onNegative(null).onPositive(new MaterialDialog.SingleButtonCallback() {

                        @Override
                        public void onClick(MaterialDialog dialog, DialogAction which) {
                            new AsyncTask<Void, Void, Void>() {

                                @Override
                                protected Void doInBackground(Void... params) {
                                    try {
                                        new AccountManager(Authentication.reddit).report(submission, reportReason);
                                    } catch (ApiException e) {
                                        e.printStackTrace();
                                    }
                                    return null;
                                }

                                @Override
                                protected void onPostExecute(Void aVoid) {
                                    Snackbar s = Snackbar.make(rootView, R.string.msg_report_sent, Snackbar.LENGTH_SHORT);
                                    View view = s.getView();
                                    TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                                    tv.setTextColor(Color.WHITE);
                                    s.show();
                                }
                            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        }
                    }).show();
                    break;
                case 8:
                    if (SettingValues.shareLongLink) {
                        Reddit.defaultShareText(submission.getTitle(), "htts://reddit.com" + submission.getPermalink(), mContext);
                    } else {
                        Reddit.defaultShareText(submission.getTitle(), "https://redd.it/" + submission.getId(), mContext);
                    }
                    break;
                case 6:
                    {
                        ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("Link", submission.getUrl());
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(mContext, R.string.submission_link_copied, Toast.LENGTH_SHORT).show();
                    }
                    break;
            }
        }
    });
    b.show();
}
Also used : DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) TypedArray(android.content.res.TypedArray) TitleTextView(me.ccrama.redditslide.Views.TitleTextView) TextView(android.widget.TextView) ClipboardManager(android.content.ClipboardManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Drawable(android.graphics.drawable.Drawable) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) ImageView(android.widget.ImageView) TitleTextView(me.ccrama.redditslide.Views.TitleTextView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) DialogAction(com.afollestad.materialdialogs.DialogAction) AccountManager(net.dean.jraw.managers.AccountManager) BottomSheet(com.cocosw.bottomsheet.BottomSheet) ClipData(android.content.ClipData) ApiException(net.dean.jraw.ApiException) Snackbar(android.support.design.widget.Snackbar)

Example 92 with ClipData

use of android.content.ClipData in project Applozic-Android-SDK by AppLozic.

the class PictureUploadPopUpFragment method imageCapture.

public void imageCapture() {
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (!(getActivity() instanceof MobicomkitUriListener)) {
        Utils.printLog(getContext(), TAG, "Activity must implement MobicomkitUriListener to get image file uri");
        return;
    }
    if (cameraIntent.resolveActivity(getContext().getPackageManager()) != null) {
        Uri capturedImageUri = ((MobicomkitUriListener) getActivity()).getCurrentImageUri();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            ClipData clip = ClipData.newUri(getActivity().getContentResolver(), "a Photo", capturedImageUri);
            cameraIntent.setClipData(clip);
            cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
            List<ResolveInfo> resInfoList = getActivity().getPackageManager().queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                getActivity().grantUriPermission(packageName, capturedImageUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                getActivity().grantUriPermission(packageName, capturedImageUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }
        }
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri);
        getActivity().startActivityForResult(cameraIntent, ProfileFragment.REQUEST_CODE_TAKE_PHOTO);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) MobicomkitUriListener(com.applozic.mobicomkit.uiwidgets.uilistener.MobicomkitUriListener) Intent(android.content.Intent) List(java.util.List) Uri(android.net.Uri) ClipData(android.content.ClipData)

Example 93 with ClipData

use of android.content.ClipData in project Applozic-Android-SDK by AppLozic.

the class ConversationActivity method imageCapture.

public void imageCapture() {
    try {
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_" + ".jpeg";
        mediaFile = FileClientService.getFilePath(imageFileName, getApplicationContext(), "image/jpeg");
        capturedImageUri = FileProvider.getUriForFile(this, Utils.getMetaDataValue(this, MobiComKitConstants.PACKAGE_NAME) + ".provider", mediaFile);
        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            ClipData clip = ClipData.newUri(getContentResolver(), "a Photo", capturedImageUri);
            cameraIntent.setClipData(clip);
            cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
            List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                grantUriPermission(packageName, capturedImageUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                grantUriPermission(packageName, capturedImageUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }
        }
        if (cameraIntent.resolveActivity(getApplicationContext().getPackageManager()) != null) {
            if (mediaFile != null) {
                startActivityForResult(cameraIntent, MultimediaOptionFragment.REQUEST_CODE_TAKE_PHOTO);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Intent(android.content.Intent) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) ClipData(android.content.ClipData) Date(java.util.Date)

Example 94 with ClipData

use of android.content.ClipData in project AmazeFileManager by TeamAmaze.

the class AboutActivity method onClick.

@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.relative_layout_version:
            mCount++;
            if (mCount >= 5) {
                String text = getResources().getString(R.string.easter_egg_title) + " : " + mCount;
                if (snackbar != null && snackbar.isShown()) {
                    snackbar.setText(text);
                } else {
                    snackbar = Snackbar.make(v, text, Snackbar.LENGTH_SHORT);
                }
                snackbar.show();
                mSharedPref.edit().putInt(KEY_PREF_STUDIO, Integer.parseInt(Integer.toString(mCount) + "000")).apply();
            } else {
                mSharedPref.edit().putInt(KEY_PREF_STUDIO, 0).apply();
            }
            break;
        case R.id.relative_layout_issues:
            openURL(URL_REPO_ISSUES);
            break;
        case R.id.relative_layout_changelog:
            openURL(URL_REPO_CHANGELOG);
            break;
        case R.id.relative_layout_licenses:
            LibsBuilder libsBuilder = new LibsBuilder().withLibraries("commonscompress", "apachemina", // Not autodetected for some reason
            "volley").withActivityTitle(getString(R.string.libraries)).withAboutIconShown(true).withAboutVersionShownName(true).withAboutVersionShownCode(false).withAboutDescription(getString(R.string.about_amaze)).withAboutSpecial1(getString(R.string.license)).withAboutSpecial1Description(getString(R.string.amaze_license)).withLicenseShown(true);
            switch(getAppTheme().getSimpleTheme()) {
                case LIGHT:
                    libsBuilder.withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR);
                    break;
                case DARK:
                    libsBuilder.withActivityStyle(Libs.ActivityStyle.DARK);
                    break;
                case BLACK:
                    libsBuilder.withActivityTheme(R.style.AboutLibrariesTheme_Black);
                    break;
            }
            libsBuilder.start(this);
            break;
        case R.id.text_view_author_1_g_plus:
            openURL(URL_AUTHOR_1_G_PLUS);
            break;
        case R.id.text_view_author_1_donate:
            ClipboardManager clipManager1 = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            ClipData clip1 = ClipData.newPlainText(TAG_CLIPBOARD_DONATE, URL_AUTHOR_1_PAYPAL);
            clipManager1.setPrimaryClip(clip1);
            Snackbar.make(v, R.string.paypal_copy_message, Snackbar.LENGTH_LONG).show();
            break;
        case R.id.text_view_author_2_g_plus:
            openURL(URL_AUTHOR_2_G_PLUS);
            break;
        case R.id.text_view_author_2_donate:
            openURL(URL_AUTHOR_2_PAYPAL);
            break;
        case R.id.text_view_developer_1_github:
            openURL(URL_DEVELOPER1_GITHUB);
            break;
        case R.id.text_view_developer_1_donate:
            try {
                openURL(URL_DEVELOPER1_BITCOIN);
            } catch (ActivityNotFoundException e) {
                Snackbar.make(v, R.string.nobitcoinapp, Snackbar.LENGTH_LONG).show();
            }
            break;
        case R.id.relative_layout_translate:
            openURL(URL_REPO_TRANSLATE);
            break;
        case R.id.relative_layout_g_plus_community:
            openURL(URL_REPO_G_PLUS_COMMUNITY);
            break;
        case R.id.relative_layout_xda:
            openURL(URL_REPO_XDA);
            break;
        case R.id.relative_layout_rate:
            openURL(URL_REPO_RATE);
            break;
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) ActivityNotFoundException(android.content.ActivityNotFoundException) LibsBuilder(com.mikepenz.aboutlibraries.LibsBuilder) ClipData(android.content.ClipData)

Example 95 with ClipData

use of android.content.ClipData in project BaseProject by feer921.

the class Util method copyTextToClipboard.

@SuppressLint("NewApi")
public static void copyTextToClipboard(Context context, CharSequence toCopyChars) {
    ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData textClipData = ClipData.newPlainText("text", toCopyChars);
    clipboardManager.setPrimaryClip(textClipData);
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData) SuppressLint(android.annotation.SuppressLint)

Aggregations

ClipData (android.content.ClipData)343 ClipboardManager (android.content.ClipboardManager)190 Intent (android.content.Intent)83 Uri (android.net.Uri)65 View (android.view.View)38 MenuItem (android.view.MenuItem)34 TextView (android.widget.TextView)34 ArrayList (java.util.ArrayList)29 Paint (android.graphics.Paint)24 ImageView (android.widget.ImageView)20 Context (android.content.Context)19 DialogInterface (android.content.DialogInterface)19 PendingIntent (android.app.PendingIntent)16 Bundle (android.os.Bundle)16 RemoteException (android.os.RemoteException)14 SpannableStringBuilder (android.text.SpannableStringBuilder)14 SuppressLint (android.annotation.SuppressLint)12 TargetApi (android.annotation.TargetApi)12 Drawable (android.graphics.drawable.Drawable)11 RecyclerView (android.support.v7.widget.RecyclerView)11