Search in sources :

Example 1 with ShareActionProvider

use of android.widget.ShareActionProvider in project android-support-v4-googlemaps by petedoyle.

the class ShareCompatICS method configureMenuItem.

public static void configureMenuItem(MenuItem item, Activity callingActivity, Intent intent) {
    ActionProvider itemProvider = item.getActionProvider();
    ShareActionProvider provider = null;
    if (!(itemProvider instanceof ShareActionProvider)) {
        provider = new ShareActionProvider(callingActivity);
    } else {
        provider = (ShareActionProvider) itemProvider;
    }
    provider.setShareHistoryFileName(HISTORY_FILENAME_PREFIX + callingActivity.getClass().getName());
    provider.setShareIntent(intent);
    item.setActionProvider(provider);
}
Also used : ShareActionProvider(android.widget.ShareActionProvider) ActionProvider(android.view.ActionProvider) ShareActionProvider(android.widget.ShareActionProvider)

Example 2 with ShareActionProvider

use of android.widget.ShareActionProvider in project weiciyuan by qii.

the class StatusSingleChoiceModeListener method onActionItemClicked.

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    if (listView.getCheckedItemCount() == 0) {
        return true;
    }
    Intent intent;
    long[] ids = listView.getCheckedItemIds();
    switch(item.getItemId()) {
        case R.id.menu_repost:
            intent = new Intent(getActivity(), WriteRepostActivity.class);
            intent.putExtra("token", GlobalContext.getInstance().getSpecialToken());
            intent.putExtra("id", String.valueOf(ids[0]));
            intent.putExtra("msg", bean);
            getActivity().startActivity(intent);
            listView.clearChoices();
            mode.finish();
            break;
        case R.id.menu_comment:
            intent = new Intent(getActivity(), WriteCommentActivity.class);
            intent.putExtra("token", GlobalContext.getInstance().getSpecialToken());
            intent.putExtra("id", String.valueOf(ids[0]));
            intent.putExtra("msg", bean);
            getActivity().startActivity(intent);
            listView.clearChoices();
            mode.finish();
            break;
        case R.id.menu_fav:
            if (Utility.isTaskStopped(favTask) && Utility.isTaskStopped(unFavTask)) {
                favTask = new FavAsyncTask(GlobalContext.getInstance().getSpecialToken(), bean.getId());
                favTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
            }
            listView.clearChoices();
            mode.finish();
            break;
        case R.id.menu_unfav:
            if (Utility.isTaskStopped(favTask) && Utility.isTaskStopped(unFavTask)) {
                unFavTask = new UnFavAsyncTask(GlobalContext.getInstance().getSpecialToken(), bean.getId());
                unFavTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
            }
            listView.clearChoices();
            mode.finish();
            break;
        case R.id.menu_remove:
            int position = listView.getCheckedItemPosition() - listView.getHeaderViewsCount();
            RemoveDialog dialog = new RemoveDialog(position);
            dialog.setTargetFragment(fragment, 0);
            dialog.show(fragment.getFragmentManager(), "");
            break;
        case R.id.menu_share:
            if (fragment.getActivity() != null) {
                Utility.setShareIntent(fragment.getActivity(), mShareActionProvider, bean);
            }
            mShareActionProvider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() {

                @Override
                public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
                    finish();
                    return false;
                }
            });
            break;
        case R.id.menu_copy:
            ClipboardManager cm = (ClipboardManager) fragment.getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
            cm.setPrimaryClip(ClipData.newPlainText("sinaweibo", bean.getText()));
            Toast.makeText(fragment.getActivity(), fragment.getString(R.string.copy_successfully), Toast.LENGTH_SHORT).show();
            mode.finish();
            break;
    }
    return true;
}
Also used : UnFavAsyncTask(org.qii.weiciyuan.ui.task.UnFavAsyncTask) ClipboardManager(android.content.ClipboardManager) WriteRepostActivity(org.qii.weiciyuan.ui.send.WriteRepostActivity) UnFavAsyncTask(org.qii.weiciyuan.ui.task.UnFavAsyncTask) FavAsyncTask(org.qii.weiciyuan.ui.task.FavAsyncTask) Intent(android.content.Intent) ShareActionProvider(android.widget.ShareActionProvider) WriteCommentActivity(org.qii.weiciyuan.ui.send.WriteCommentActivity)

Example 3 with ShareActionProvider

use of android.widget.ShareActionProvider in project weiciyuan by qii.

the class StatusSingleChoiceModeListener method onPrepareActionMode.

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    MenuInflater inflater = mode.getMenuInflater();
    menu.clear();
    if (bean.getUser().getId().equals(GlobalContext.getInstance().getCurrentAccountId())) {
        inflater.inflate(R.menu.contextual_menu_fragment_status_listview_myself, menu);
    } else {
        inflater.inflate(R.menu.contextual_menu_fragment_status_listview, menu);
    }
    mode.setTitle(bean.getUser().getScreen_name());
    //fuck sina weibo
    //        MenuItem favItem = menu.findItem(R.id.menu_fav);
    //        MenuItem unFavItem = menu.findItem(R.id.menu_unfav);
    //        if (bean.isFavorited()) {
    //            favItem.setVisible(false);
    //            unFavItem.setVisible(true);
    //        } else {
    //            favItem.setVisible(true);
    //            unFavItem.setVisible(false);
    //        }
    MenuItem item = menu.findItem(R.id.menu_share);
    mShareActionProvider = (ShareActionProvider) item.getActionProvider();
    if (fragment.getActivity() != null) {
        Utility.setShareIntent(fragment.getActivity(), mShareActionProvider, bean);
    }
    mShareActionProvider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() {

        @Override
        public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
            finish();
            return false;
        }
    });
    return true;
}
Also used : MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) Intent(android.content.Intent) ShareActionProvider(android.widget.ShareActionProvider)

Example 4 with ShareActionProvider

use of android.widget.ShareActionProvider in project weiciyuan by qii.

the class CommentSingleChoiceModeListener method onActionItemClicked.

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    Intent intent;
    switch(item.getItemId()) {
        case R.id.menu_view:
            intent = new Intent(getActivity(), BrowserCommentActivity.class);
            intent.putExtra("comment", bean);
            intent.putExtra("token", GlobalContext.getInstance().getSpecialToken());
            getActivity().startActivity(intent);
            listView.clearChoices();
            mode.finish();
            break;
        case R.id.menu_comment:
            intent = new Intent(getActivity(), WriteReplyToCommentActivity.class);
            intent.putExtra("token", GlobalContext.getInstance().getSpecialToken());
            intent.putExtra("msg", bean);
            getActivity().startActivity(intent);
            listView.clearChoices();
            mode.finish();
            break;
        case R.id.menu_share:
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            sharingIntent.putExtra(Intent.EXTRA_TEXT, bean.getText());
            PackageManager packageManager = getActivity().getPackageManager();
            List<ResolveInfo> activities = packageManager.queryIntentActivities(sharingIntent, 0);
            boolean isIntentSafe = activities.size() > 0;
            if (isIntentSafe && mShareActionProvider != null) {
                mShareActionProvider.setShareIntent(sharingIntent);
            }
            mShareActionProvider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() {

                @Override
                public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
                    finish();
                    return false;
                }
            });
            break;
        case R.id.menu_copy:
            ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
            cm.setPrimaryClip(ClipData.newPlainText("sinaweibo", bean.getText()));
            Toast.makeText(getActivity(), getActivity().getString(R.string.copy_successfully), Toast.LENGTH_SHORT).show();
            listView.clearChoices();
            mode.finish();
            break;
        case R.id.menu_remove:
            int position = listView.getCheckedItemPosition() - listView.getHeaderViewsCount();
            RemoveDialog dialog = new RemoveDialog(position);
            dialog.setTargetFragment(fragment, 0);
            dialog.show(fragment.getFragmentManager(), "");
            break;
    }
    return true;
}
Also used : ClipboardManager(android.content.ClipboardManager) WriteReplyToCommentActivity(org.qii.weiciyuan.ui.send.WriteReplyToCommentActivity) BrowserCommentActivity(org.qii.weiciyuan.ui.browser.BrowserCommentActivity) Intent(android.content.Intent) ShareActionProvider(android.widget.ShareActionProvider) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager)

Example 5 with ShareActionProvider

use of android.widget.ShareActionProvider in project glimmr by brk3.

the class PhotoViewerFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (BuildConfig.DEBUG)
        Log.d(getLogTag(), "onCreateOptionsMenu");
    inflater.inflate(R.menu.photoviewer_menu, menu);
    mFavoriteButton = menu.findItem(R.id.menu_favorite);
    mWallpaperButton = menu.findItem(R.id.menu_set_wallpaper);
    /* The task could return before this has inflated, so make sure it's up
         * to date */
    if (mPhotoExtendedInfo != null) {
        updateFavoriteButtonIcon(mPhotoExtendedInfo.isFavorite());
    }
    /* Set file with share history to the provider and set the share
         * intent. */
    MenuItem shareActionItem = menu.findItem(R.id.menu_share);
    ShareActionProvider shareActionProvider = (ShareActionProvider) shareActionItem.getActionProvider();
    shareActionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
    shareActionProvider.setShareIntent(createShareIntent());
}
Also used : MenuItem(android.view.MenuItem) ShareActionProvider(android.widget.ShareActionProvider)

Aggregations

ShareActionProvider (android.widget.ShareActionProvider)7 Intent (android.content.Intent)4 MenuItem (android.view.MenuItem)4 MenuInflater (android.view.MenuInflater)3 ClipboardManager (android.content.ClipboardManager)2 PackageManager (android.content.pm.PackageManager)2 ResolveInfo (android.content.pm.ResolveInfo)2 ActionProvider (android.view.ActionProvider)1 BrowserCommentActivity (org.qii.weiciyuan.ui.browser.BrowserCommentActivity)1 WriteCommentActivity (org.qii.weiciyuan.ui.send.WriteCommentActivity)1 WriteReplyToCommentActivity (org.qii.weiciyuan.ui.send.WriteReplyToCommentActivity)1 WriteRepostActivity (org.qii.weiciyuan.ui.send.WriteRepostActivity)1 FavAsyncTask (org.qii.weiciyuan.ui.task.FavAsyncTask)1 UnFavAsyncTask (org.qii.weiciyuan.ui.task.UnFavAsyncTask)1