/** * 用户操作,取消分享 * * @return 是否成功取消等待提示框 */ public static boolean cancelShare() { if (waitProgressDialog.isShowing()) { // 取消下载 waitProgressDialog.dismiss(); waitProgressDialog = null; return true; } return false; }
/** * 取消分享 * * @return 是否成功取消等待提示框 */ public static boolean dismissWatiTinyUrlDialog() { if (waitTinyUrlDialog != null) { waitTinyUrlDialog.cancel(); waitTinyUrlDialog.dismiss(); waitTinyUrlDialog = null; return true; } return false; }
/** * 弹出分享等待对话框 * * @param mContext Context */ public static void showShareWaitDialog(Context mContext) { if (waitProgressDialog == null) { // waitProgressDialog = ProgressDialog.show(mContext, null, mContext // .getString(R.string.share_waiting), false, true); waitProgressDialog = new BdWaitingDialog(mContext); waitProgressDialog.setMessage(mContext.getString(R.string.share_waiting)); waitProgressDialog.setOnKeyListener( new OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { return cancelShare(); } return false; } }); } waitProgressDialog.show(); }
/** * 分享文本 * * @param mContext app上下文 * @param templateId 文本内容模版 * @param text1 文本内容字段一 * @param text2 文本内容字段二 * @return 是否发送成功 */ public static boolean sendTextShare( final Context mContext, final int templateId, final String text1, final String text2) { BdLog.d(text1 + ", " + text2); final BdSharerOM shareContentMeta = new BdSharerOM(); shareContentMeta.setContentType(BdSharerOM.TYPE_TEXT); waitTinyUrlDialog = new BdWaitingDialog(mContext); waitTinyUrlDialog.setMessage(mContext.getString(R.string.share_waiting)); waitTinyUrlDialog.setCancelable(true); waitTinyUrlDialog.setOnCancelListener( new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { willCancelShare = true; } }); waitTinyUrlDialog.show(); willCancelShare = false; BdTinyUrlGenerator generator = new BdTinyUrlGenerator(); generator.setEventListener( new BdTinyUrlRecievedListener() { @Override public void onTinyUrlRecieved(String tinyUrl) { String extra1 = text1; String extra2 = tinyUrl; if (text1 == null) { extra1 = ""; } // if (extra1 != "") { // extra1 = text1 + TextUtil.COMMA; // } if (tinyUrl == null) { extra2 = ""; } // if (extra2 != "") { // extra2 = Sharer.SHARE_DETAIL_TIP + tinyUrl; // } if (!"".equals(extra1) && "".equals(extra2)) { extra1 = text1; } BdLog.d(extra1 + ", " + extra2); String text = mContext.getString(templateId, extra1, extra2); shareContentMeta.setContent(text); shareContentMeta.setExtra1(text1); shareContentMeta.setExtra2(tinyUrl); shareContentMeta.setContent(preProcContent(mContext, shareContentMeta)); if (!willCancelShare) { sendOk = BdSharer.sendShare( mContext, shareContentMeta, false, SHARE_RERQUEST_CODE_DEFAULT, false); } if (waitTinyUrlDialog != null) { waitTinyUrlDialog.cancel(); waitTinyUrlDialog = null; } } }); generator.generate(text2); return sendOk; }