com.sina.weibo.sdk.api.ImageObject Java Examples

The following examples show how to use com.sina.weibo.sdk.api.ImageObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WeiboBaseShareInstance.java    From SimpleProject with MIT License 6 votes vote down vote up
/**
 * 普通分享,支持文字,链接,图片  注意:微博分享设置title无效,链接应追加在desc后面
 * @param activity
 * @param desc
 * @param url
 * @param bitmap
 */
private void shareMediaByWeibo(Activity activity, String desc, String url, Bitmap bitmap) {
	WeiboMultiMessage multiMessage = new WeiboMultiMessage();
	if (!TextUtils.isEmpty(desc)) {
		TextObject textObject = new TextObject();
		textObject.text = desc + " " + url;
		multiMessage.textObject = textObject;
	}
	if (bitmap != null && !bitmap.isRecycled()) {
		ImageObject imageObject = new ImageObject();
		imageObject.setImageObject(bitmap);
		multiMessage.imageObject = imageObject;
	}

	shareHandler.shareMessage(multiMessage, false);
}
 
Example #2
Source File: Share.java    From UPMiss with GNU General Public License v3.0 6 votes vote down vote up
private static void shareToWeibo(Activity activity, String title, String summary, Bitmap img) {
    ImageObject imageObject = new ImageObject();
    imageObject.imageData = bmpToByteArray(img);

    TextObject textObject = new TextObject();
    textObject.text = title + "\n" + summary + Constants.SUMMARY;

    WeiboMultiMessage message = new WeiboMultiMessage();
    message.textObject = textObject;
    message.imageObject = imageObject;

    WbShareHandler wbApi = getWbApi(activity);
    wbApi.shareMessage(message, false);
    // Bind cache
    activity.getWindow().getDecorView().setTag(wbApi);
}
 
Example #3
Source File: SharePresenter.java    From the-tech-frontier-app with MIT License 6 votes vote down vote up
/**
 * 分享文章到新浪微博
 * 
 * @param title
 * @param url
 */
public void share(Activity activity, String title, String url) {
    WeiboMultiMessage weiboMessage = new WeiboMultiMessage();// 初始化微博的分享消息
    TextObject textObject = new TextObject();
    textObject.text = "《" + title + "》" + "这篇文章不错, 文章地址 : " + url
            + "。本文来自: 开发技术前线, http://www.devtf.cn 。";
    weiboMessage.textObject = textObject;
    ImageObject imageObject = new ImageObject();
    imageObject.setImageObject(BitmapFactory.decodeResource(activity.getResources(),
            R.drawable.ic_launcher));
    weiboMessage.imageObject = imageObject;
    SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
    request.transaction = String.valueOf(System.currentTimeMillis());
    request.multiMessage = weiboMessage;
    mWeiboShareAPI.sendRequest(activity, request); // 发送请求消息到微博,唤起微博分享界面
}
 
Example #4
Source File: WeiboShareInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
/**
 * 创建图片消息对象。
 * String、Bitmap、Resource type image change to pair to share
 *
 * @return 图片消息对象。
 */
private ImageObject getImageObj(Pair<String, byte[]> object) {
    ImageObject imageObject = new ImageObject();
    imageObject.imagePath = object.first;
    imageObject.imageData = object.second;
    return imageObject;
}
 
Example #5
Source File: WBShare.java    From sdk3rd with Apache License 2.0 5 votes vote down vote up
ImageObject toImage(ImageResource resource) {
    ImageObject object = new ImageObject();
    object.imagePath = resource.toUri();
    if (TextUtils.isEmpty(object.imagePath)) {
        object.imageData = resource.toBytes();
    }
    return object;
}
 
Example #6
Source File: LoginShare.java    From LoginSharePay with Apache License 2.0 5 votes vote down vote up
@Override
protected ImageObject getImageObject(WeiboMessageBody weiboMessageBody) {
    ImageObject imageObject = new ImageObject();
    Bitmap bitmap = BitmapFactory.decodeFile(weiboMessageBody.getLocalImage());
    imageObject.setImageObject(bitmap);
    return imageObject;
}
 
Example #7
Source File: WBHelper.java    From SocialHelper with Apache License 2.0 5 votes vote down vote up
private ImageObject getImageObj(Bundle params) {
    ImageObject imgObj = new ImageObject();
    if (params.containsKey(WBShareEntity.KEY_WB_IMG_LOCAL)) {//分为本地文件和应用内资源图片
        String imgUrl = params.getString(WBShareEntity.KEY_WB_IMG_LOCAL);
        if (notFoundFile(imgUrl)) {
            return null;
        }
        imgObj.imagePath = imgUrl;
    } else {
        Bitmap bitmap = BitmapFactory.decodeResource(activity.getResources(), params.getInt(WBShareEntity.KEY_WB_IMG_RES));
        imgObj.setImageObject(bitmap);
        bitmap.recycle();
    }
    return imgObj;
}
 
Example #8
Source File: WbPlatform.java    From SocialSdkLibrary with Apache License 2.0 5 votes vote down vote up
private ImageObject getImageObj(String localPath, byte[] data) {
    ImageObject imageObject = new ImageObject();
    //设置缩略图。 注意:最终压缩过的缩略图大小不得超过 32kb。
    imageObject.imageData = data;
    imageObject.imagePath = localPath;
    return imageObject;
}
 
Example #9
Source File: SinaShareHandler.java    From BiliShare with Apache License 2.0 5 votes vote down vote up
/**
 * 创建图片消息对象。
 *
 * @return 图片消息对象。
 */
private ImageObject getImageObj(ShareImage image) {
    ImageObject imageObject = new ImageObject();

    if (image == null) {
        return imageObject;
    }

    if (image.isLocalImage()) {
        imageObject.imagePath = image.getLocalPath();
    } else {
        imageObject.imageData = mImageHelper.buildThumbData(image);
    }
    return imageObject;
}
 
Example #10
Source File: SinaShareImpl.java    From ChinaShare with MIT License 5 votes vote down vote up
/**
 * 创建图片消息对象。
 *
 * @return 图片消息对象。
 */
private ImageObject getImageObj(String imageUrl) {
    ImageObject imageObject = new ImageObject();
    Bitmap bmp = BitmapFactory.decodeFile(imageUrl);
    imageObject.setImageObject(bmp);
    return imageObject;
}
 
Example #11
Source File: SharePopWindow.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
/**
 * 创建图片消息对象。
 * 
 * @return 图片消息对象。
 */
private ImageObject getImageObj() {
	Bitmap bitmap = BitmapUtil.getBitmapFromCache(mJoke.getImgUrl());
	if(bitmap == null) {
		return null;
	}
    ImageObject imageObject = new ImageObject();
    imageObject.setImageObject(bitmap);
    imageObject.title = title;
    imageObject.description = description;
    imageObject.actionUrl = targetUrl + mJoke.getId();
    return imageObject;
}
 
Example #12
Source File: WeiboShareInstance.java    From ShareUtil with Apache License 2.0 4 votes vote down vote up
private void shareTextOrImage(final ShareImageObject shareImageObject, final String text,
        final Activity activity, final ShareListener listener) {

    Observable.fromEmitter(new Action1<Emitter<Pair<String, byte[]>>>() {
        @Override
        public void call(Emitter<Pair<String, byte[]>> emitter) {
            try {
                String path = ImageDecoder.decode(activity, shareImageObject);
                emitter.onNext(Pair.create(path,
                        ImageDecoder.compress2Byte(path, TARGET_SIZE, TARGET_LENGTH)));
                emitter.onCompleted();
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    }, Emitter.BackpressureMode.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnRequest(new Action1<Long>() {
                @Override
                public void call(Long aLong) {
                    listener.shareRequest();
                }
            })
            .subscribe(new Action1<Pair<String, byte[]>>() {
                @Override
                public void call(Pair<String, byte[]> pair) {
                    ImageObject imageObject = new ImageObject();
                    imageObject.imageData = pair.second;
                    imageObject.imagePath = pair.first;

                    WeiboMultiMessage message = new WeiboMultiMessage();
                    message.imageObject = imageObject;
                    if (!TextUtils.isEmpty(text)) {
                        TextObject textObject = new TextObject();
                        textObject.text = text;

                        message.textObject = textObject;
                    }

                    sendRequest(activity, message);
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    activity.finish();
                    listener.shareFailure(new Exception(throwable));
                }
            });
}
 
Example #13
Source File: WeiboShareInstance.java    From smart-farmer-android with Apache License 2.0 4 votes vote down vote up
private void shareTextOrImage(final ShareImageObject shareImageObject, final String text,
        final Activity activity, final ShareListener listener) {

    Flowable.create(new FlowableOnSubscribe<Pair<String, byte[]>>() {
        @Override
        public void subscribe(@NonNull FlowableEmitter<Pair<String, byte[]>> emitter) throws Exception {
            try {
                String path = ImageDecoder.decode(activity, shareImageObject);
                emitter.onNext(Pair.create(path,
                        ImageDecoder.compress2Byte(path, TARGET_SIZE, TARGET_LENGTH)));
                emitter.onComplete();
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    }, BackpressureStrategy.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnRequest(new LongConsumer() {
                @Override
                public void accept(long aLong) {
                    listener.shareRequest();
                }
            })
            .subscribe(new Consumer<Pair<String,byte[]>>() {
                @Override
                public void accept(Pair<String, byte[]> pair) {
                    ImageObject imageObject = new ImageObject();
                    imageObject.imageData = pair.second;
                    imageObject.imagePath = pair.first;

                    WeiboMultiMessage message = new WeiboMultiMessage();
                    message.imageObject = imageObject;
                    if (!TextUtils.isEmpty(text)) {
                        TextObject textObject = new TextObject();
                        textObject.text = text;

                        message.textObject = textObject;
                    }

                    sendRequest(activity, message);
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) {
                    activity.finish();
                    listener.shareFailure(new Exception(throwable));
                }
            });
}
 
Example #14
Source File: SinaWBHandler.java    From SocialSDKAndroid with Apache License 2.0 4 votes vote down vote up
@Override
    public void share(Activity activity, IShareMedia shareMedia, ShareListener shareListener) {
        this.mActivity = activity;
        this.mShareListener = shareListener;

        this.mSsoHandler = new SsoHandler(mActivity, mAuthInfo);

        WeiboMultiMessage weiboMessage = new WeiboMultiMessage();

        if(shareMedia instanceof ShareTextImageMedia) {       //文字图片分享
            ShareTextImageMedia shareTextImageMedia = (ShareTextImageMedia) shareMedia;

            if(shareTextImageMedia.getText().length() > 0) {
                TextObject textObject = new TextObject();
                textObject.text = shareTextImageMedia.getText();
                weiboMessage.textObject = textObject;
            }

            if(shareTextImageMedia.getImage() != null) {
                ImageObject imageObject = new ImageObject();
                imageObject.setImageObject(shareTextImageMedia.getImage());
                weiboMessage.imageObject = imageObject;
            }
        } else {
            if(this.mShareListener != null) {
                this.mShareListener.onError(this.mConfig.getName(), "weibo is not support this shareMedia");
            }
            return ;
        }

        SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
        request.transaction = String.valueOf(System.currentTimeMillis());
        request.multiMessage = weiboMessage;

        Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(mContext.getApplicationContext());
        String token = "";
        if (accessToken != null) {
            token = accessToken.getToken();
        }
        mWeiboShareAPI.sendRequest(mActivity, request, mAuthInfo, token, new WeiboAuthListener() {

            @Override
            public void onWeiboException( WeiboException arg0 ) {
            }

            @Override
            public void onComplete( Bundle bundle ) {
                // TODO Auto-generated method stub
                Oauth2AccessToken newToken = Oauth2AccessToken.parseAccessToken(bundle);
                AccessTokenKeeper.writeAccessToken(mContext.getApplicationContext(), newToken);
            }

            @Override
            public void onCancel() {
            }
        });

//        mWeiboShareAPI.sendRequest(mActivity, request);
    }
 
Example #15
Source File: WeiboShareManager.java    From sharesdk with Apache License 2.0 4 votes vote down vote up
/**
 * 创建图片消息对象。
 *
 * @return 图片消息对象。
 */
private ImageObject getImageObj(Bitmap bitmap) {
    ImageObject imageObject = new ImageObject();
    imageObject.setImageObject(bitmap);
    return imageObject;
}
 
Example #16
Source File: ShareImpl.java    From LoginSharePay with Apache License 2.0 votes vote down vote up
protected abstract ImageObject getImageObject(WeiboMessageBody weiboMessageBody);