/*
 * ¹ÙÍøµØÕ¾:http://www.mob.com
 * ¼¼ÊõÖ§³ÖQQ: 4006852216
 * ¹Ù·½Î¢ÐÅ:ShareSDK   £¨Èç¹û·¢²¼ÐÂ°æ±¾µÄ»°£¬ÎÒÃÇ½«»áµÚÒ»Ê±¼äÍ¨¹ýÎ¢ÐÅ½«°æ±¾¸üÐÂÄÚÈÝÍÆËÍ¸øÄú¡£Èç¹ûÊ¹ÓÃ¹ý³ÌÖÐÓÐÈÎºÎÎÊÌâ£¬Ò²¿ÉÒÔÍ¨¹ýÎ¢ÐÅÓëÎÒÃÇÈ¡µÃÁªÏµ£¬ÎÒÃÇ½«»áÔÚ24Ð¡Ê±ÄÚ¸øÓè»Ø¸´£©
 *
 * Copyright (c) 2013Äê mob.com. All rights reserved.
 */

package cn.sharesdk.onekeyshare;

import static com.mob.tools.utils.BitmapHelper.captureView;
import static com.mob.tools.utils.R.getStringRes;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;

import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler.Callback;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
import cn.sharesdk.framework.CustomPlatform;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import com.mob.tools.utils.UIHandler;

/**
 * ¿ì½Ý·ÖÏíµÄÈë¿Ú
 * <p>
 * Í¨¹ý²»Í¬µÄsetterÉèÖÃ²ÎÊý£¬È»ºóµ÷ÓÃ{@link #show(Context)}·½·¨Æô¶¯¿ì½Ý·ÖÏí
 */
public class OnekeyShare implements PlatformActionListener, Callback
{
	private static final int									MSG_TOAST				= 1;
	private static final int									MSG_ACTION_CCALLBACK	= 2;
	private static final int									MSG_CANCEL_NOTIFY		= 3;

	private HashMap<String, Object>								shareParamsMap;
	private ArrayList<CustomerLogo>								customers;
	private boolean												silent;
	private PlatformActionListener								callback;
	private ShareContentCustomizeCallback						customizeCallback;
	private boolean												dialogMode				= false;
	private boolean												disableSSO;
	private HashMap<String, String>								hiddenPlatforms;
	private View												bgView;
	private OnekeyShareTheme									theme;

	private Context												context;
	private PlatformListFakeActivity.OnShareButtonClickListener	onShareButtonClickListener;

	public OnekeyShare() {
		shareParamsMap = new HashMap<String, Object>();
		customers = new ArrayList<CustomerLogo>();
		callback = this;
		hiddenPlatforms = new HashMap<String, String>();
	}

	public void show(Context context)
	{
		ShareSDK.initSDK(context);
		this.context = context;

		// ´ò¿ª·ÖÏí²Ëµ¥µÄÍ³¼Æ
		ShareSDK.logDemoEvent(1, null);

		// ÏÔÊ¾·½Ê½ÊÇÓÉplatformºÍsilentÁ½¸ö×Ö¶Î¿ØÖÆµÄ
		// Èç¹ûplatformÉèÖÃÁË£¬ÔòÎÞÐëÏÔÊ¾¾Å¹¬¸ñ£¬·ñÔò¶¼»áÏÔÊ¾£»
		// Èç¹ûsilentÎªtrue£¬±íÊ¾²»½øÈë±à¼­Ò³Ãæ£¬·ñÔò»á½øÈë¡£
		// ±¾ÀàÖ»ÅÐ¶Ïplatform£¬ÒòÎª¾Å¹¬¸ñÏÔÊ¾ÒÔºó£¬ÊÂ¼þ½»¸øPlatformGridView¿ØÖÆ
		// µ±platformºÍsilent¶¼Îªtrue£¬ÔòÖ±½Ó½øÈë·ÖÏí£»
		// µ±platformÉèÖÃÁË£¬µ«ÊÇsilentÎªfalse£¬ÔòÅÐ¶ÏÊÇ·ñÊÇ¡°Ê¹ÓÃ¿Í»§¶Ë·ÖÏí¡±µÄÆ½Ì¨£¬
		// ÈôÎª¡°Ê¹ÓÃ¿Í»§¶Ë·ÖÏí¡±µÄÆ½Ì¨£¬ÔòÖ±½Ó·ÖÏí£¬·ñÔò½øÈë±à¼­Ò³Ãæ
		if (shareParamsMap.containsKey("platform"))
		{
			String name = String.valueOf(shareParamsMap.get("platform"));
			Platform platform = ShareSDK.getPlatform(name);

			if (silent
				|| ShareCore.isUseClientToShare(name)
				|| platform instanceof CustomPlatform)
			{
				HashMap<Platform, HashMap<String, Object>> shareData = new HashMap<Platform, HashMap<String, Object>>();
				shareData.put(ShareSDK.getPlatform(name), shareParamsMap);
				share(shareData);
				return;
			}
		}

		PlatformListFakeActivity platformListFakeActivity;
		try
		{
			if (OnekeyShareTheme.SKYBLUE == theme)
			{
				platformListFakeActivity = (PlatformListFakeActivity) Class.forName("cn.sharesdk.onekeyshare.theme.skyblue.PlatformListPage").newInstance();
			}
			else
			{
				platformListFakeActivity = (PlatformListFakeActivity) Class.forName("cn.sharesdk.onekeyshare.theme.classic.PlatformListPage").newInstance();
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return;
		}

		platformListFakeActivity.setDialogMode(dialogMode);
		platformListFakeActivity.setShareParamsMap(shareParamsMap);
		platformListFakeActivity.setSilent(silent);
		platformListFakeActivity.setCustomerLogos(customers);
		platformListFakeActivity.setBackgroundView(bgView);
		platformListFakeActivity.setHiddenPlatforms(hiddenPlatforms);
		platformListFakeActivity.setOnShareButtonClickListener(onShareButtonClickListener);
		platformListFakeActivity.setThemeShareCallback(new ThemeShareCallback() {

			@Override
			public void doShare(HashMap<Platform, HashMap<String, Object>> shareData)
			{
				share(shareData);
			}
		});
		if (shareParamsMap.containsKey("platform"))
		{
			String name = String.valueOf(shareParamsMap.get("platform"));
			Platform platform = ShareSDK.getPlatform(name);
			platformListFakeActivity.showEditPage(context, platform);
			return;
		}
		platformListFakeActivity.show(context, null);
	}

	public void setTheme(OnekeyShareTheme theme)
	{
		this.theme = theme;
	}

	/** addressÊÇ½ÓÊÕÈËµØÖ·£¬½öÔÚÐÅÏ¢ºÍÓÊ¼þÊ¹ÓÃ£¬·ñÔò¿ÉÒÔ²»Ìá¹© */
	public void setAddress(String address)
	{
		shareParamsMap.put("address", address);
	}

	/**
	 * title±êÌâ£¬ÔÚÓ¡Ïó±Ê¼Ç¡¢ÓÊÏä¡¢ÐÅÏ¢¡¢Î¢ÐÅ£¨°üÀ¨ºÃÓÑ¡¢ÅóÓÑÈ¦ºÍÊÕ²Ø£©¡¢ Ò×ÐÅ£¨°üÀ¨ºÃÓÑ¡¢ÅóÓÑÈ¦£©¡¢ÈËÈËÍøºÍQQ¿Õ¼äÊ¹ÓÃ£¬·ñÔò¿ÉÒÔ²»Ìá¹©
	 */
	public void setTitle(String title)
	{
		shareParamsMap.put("title", title);
	}

	/** titleUrlÊÇ±êÌâµÄÍøÂçÁ´½Ó£¬½öÔÚÈËÈËÍøºÍQQ¿Õ¼äÊ¹ÓÃ£¬·ñÔò¿ÉÒÔ²»Ìá¹© */
	public void setTitleUrl(String titleUrl)
	{
		shareParamsMap.put("titleUrl", titleUrl);
	}

	/** textÊÇ·ÖÏíÎÄ±¾£¬ËùÓÐÆ½Ì¨¶¼ÐèÒªÕâ¸ö×Ö¶Î */
	public void setText(String text)
	{
		shareParamsMap.put("text", text);
	}

	/** »ñÈ¡text×Ö¶ÎµÄÖµ */
	public String getText()
	{
		return shareParamsMap.containsKey("text") ? String.valueOf(shareParamsMap.get("text")) : null;
	}

	/** imagePathÊÇ±¾µØµÄÍ¼Æ¬Â·¾¶£¬³ýLinked-InÍâµÄËùÓÐÆ½Ì¨¶¼Ö§³ÖÕâ¸ö×Ö¶Î */
	public void setImagePath(String imagePath)
	{
		if (!TextUtils.isEmpty(imagePath)) shareParamsMap.put("imagePath", imagePath);
	}

	/** imageUrlÊÇÍ¼Æ¬µÄÍøÂçÂ·¾¶£¬ÐÂÀËÎ¢²©¡¢ÈËÈËÍø¡¢QQ¿Õ¼äºÍLinked-InÖ§³Ö´Ë×Ö¶Î */
	public void setImageUrl(String imageUrl)
	{
		if (!TextUtils.isEmpty(imageUrl)) shareParamsMap.put("imageUrl", imageUrl);
	}

	/** urlÔÚÎ¢ÐÅ£¨°üÀ¨ºÃÓÑ¡¢ÅóÓÑÈ¦ÊÕ²Ø£©ºÍÒ×ÐÅ£¨°üÀ¨ºÃÓÑºÍÅóÓÑÈ¦£©ÖÐÊ¹ÓÃ£¬·ñÔò¿ÉÒÔ²»Ìá¹© */
	public void setUrl(String url)
	{
		shareParamsMap.put("url", url);
	}

	/** filePathÊÇ´ý·ÖÏíÓ¦ÓÃ³ÌÐòµÄ±¾µØÂ·¾¢£¬½öÔÚÎ¢ÐÅ£¨Ò×ÐÅ£©ºÃÓÑºÍDropboxÖÐÊ¹ÓÃ£¬·ñÔò¿ÉÒÔ²»Ìá¹© */
	public void setFilePath(String filePath)
	{
		shareParamsMap.put("filePath", filePath);
	}

	/** commentÊÇÎÒ¶ÔÕâÌõ·ÖÏíµÄÆÀÂÛ£¬½öÔÚÈËÈËÍøºÍQQ¿Õ¼äÊ¹ÓÃ£¬·ñÔò¿ÉÒÔ²»Ìá¹© */
	public void setComment(String comment)
	{
		shareParamsMap.put("comment", comment);
	}

	/** siteÊÇ·ÖÏí´ËÄÚÈÝµÄÍøÕ¾Ãû³Æ£¬½öÔÚQQ¿Õ¼äÊ¹ÓÃ£¬·ñÔò¿ÉÒÔ²»Ìá¹© */
	public void setSite(String site)
	{
		shareParamsMap.put("site", site);
	}

	/** siteUrlÊÇ·ÖÏí´ËÄÚÈÝµÄÍøÕ¾µØÖ·£¬½öÔÚQQ¿Õ¼äÊ¹ÓÃ£¬·ñÔò¿ÉÒÔ²»Ìá¹© */
	public void setSiteUrl(String siteUrl)
	{
		shareParamsMap.put("siteUrl", siteUrl);
	}

	/** foursquare·ÖÏíÊ±µÄµØ·½Ãû */
	public void setVenueName(String venueName)
	{
		shareParamsMap.put("venueName", venueName);
	}

	/** foursquare·ÖÏíÊ±µÄµØ·½ÃèÊö */
	public void setVenueDescription(String venueDescription)
	{
		shareParamsMap.put("venueDescription", venueDescription);
	}

	/** ·ÖÏíµØÎ³¶È£¬ÐÂÀËÎ¢²©¡¢ÌÚÑ¶Î¢²©ºÍfoursquareÖ§³Ö´Ë×Ö¶Î */
	public void setLatitude(float latitude)
	{
		shareParamsMap.put("latitude", latitude);
	}

	/** ·ÖÏíµØ¾­¶È£¬ÐÂÀËÎ¢²©¡¢ÌÚÑ¶Î¢²©ºÍfoursquareÖ§³Ö´Ë×Ö¶Î */
	public void setLongitude(float longitude)
	{
		shareParamsMap.put("longitude", longitude);
	}

	/** ÊÇ·ñÖ±½Ó·ÖÏí */
	public void setSilent(boolean silent)
	{
		this.silent = silent;
	}

	/** ÉèÖÃ±à¼­Ò³µÄ³õÊ¼»¯Ñ¡ÖÐÆ½Ì¨ */
	public void setPlatform(String platform)
	{
		shareParamsMap.put("platform", platform);
	}

	/** ÉèÖÃKakaoTalkµÄÓ¦ÓÃÏÂÔØµØÖ· */
	public void setInstallUrl(String installurl)
	{
		shareParamsMap.put("installurl", installurl);
	}

	/** ÉèÖÃKakaoTalkµÄÓ¦ÓÃ´ò¿ªµØÖ· */
	public void setExecuteUrl(String executeurl)
	{
		shareParamsMap.put("executeurl", executeurl);
	}

	/** ÉèÖÃÎ¢ÐÅ·ÖÏíµÄÒôÀÖµÄµØÖ· */
	public void setMusicUrl(String musicUrl)
	{
		shareParamsMap.put("musicUrl", musicUrl);
	}

	/** ÉèÖÃ×Ô¶¨ÒåµÄÍâ²¿»Øµ÷ */
	public void setCallback(PlatformActionListener callback)
	{
		this.callback = callback;
	}

	/** ·µ»Ø²Ù×÷»Øµ÷ */
	public PlatformActionListener getCallback()
	{
		return callback;
	}

	/** ÉèÖÃÓÃÓÚ·ÖÏí¹ý³ÌÖÐ£¬¸ù¾Ý²»Í¬Æ½Ì¨×Ô¶¨Òå·ÖÏíÄÚÈÝµÄ»Øµ÷ */
	public void setShareContentCustomizeCallback(ShareContentCustomizeCallback callback)
	{
		customizeCallback = callback;
	}

	/** ·µ»Ø×Ô¶¨Òå·ÖÏíÄÚÈÝµÄ»Øµ÷ */
	public ShareContentCustomizeCallback getShareContentCustomizeCallback()
	{
		return customizeCallback;
	}

	/** ÉèÖÃ×Ô¼ºÍ¼±êºÍµã»÷ÊÂ¼þ£¬¿ÉÒÔÖØ¸´µ÷ÓÃÌí¼Ó¶à´Î */
	public void setCustomerLogo(Bitmap enableLogo, Bitmap disableLogo, String label, OnClickListener ocListener)
	{
		CustomerLogo cl = new CustomerLogo();
		cl.label = label;
		cl.enableLogo = enableLogo;
		cl.disableLogo = disableLogo;
		cl.listener = ocListener;
		customers.add(cl);
	}

	/** ÉèÖÃÒ»¸ö×Ü¿ª¹Ø£¬ÓÃÓÚÔÚ·ÖÏíÇ°ÈôÐèÒªÊÚÈ¨£¬Ôò½ûÓÃsso¹¦ÄÜ */
	public void disableSSOWhenAuthorize()
	{
		disableSSO = true;
	}

	/** ÉèÖÃ±à¼­Ò³ÃæµÄÏÔÊ¾Ä£Ê½ÎªDialogÄ£Ê½ */
	public void setDialogMode()
	{
		dialogMode = true;
		shareParamsMap.put("dialogMode", dialogMode);
	}

	/** Ìí¼ÓÒ»¸öÒþ²ØµÄplatform */
	public void addHiddenPlatform(String platform)
	{
		hiddenPlatforms.put(platform, platform);
	}

	/** ÉèÖÃÒ»¸ö½«±»½ØÍ¼·ÖÏíµÄView , surfaceViewÊÇ½Ø²»ÁËÍ¼Æ¬µÄ */
	public void setViewToShare(View viewToShare)
	{
		try
		{
			Bitmap bm = captureView(viewToShare, viewToShare.getWidth(), viewToShare.getHeight());
			shareParamsMap.put("viewToShare", bm);
		}
		catch (Throwable e)
		{
			e.printStackTrace();
		}
	}

	/** ÌÚÑ¶Î¢²©·ÖÏí¶àÕÅÍ¼Æ¬ */
	public void setImageArray(String[] imageArray)
	{
		shareParamsMap.put("imageArray", imageArray);
	}

	public void setEditPageBackground(View bgView)
	{
		this.bgView = bgView;
	}

	public void setOnShareButtonClickListener(PlatformListFakeActivity.OnShareButtonClickListener onShareButtonClickListener)
	{
		this.onShareButtonClickListener = onShareButtonClickListener;
	}

	/** Ñ­»·Ö´ÐÐ·ÖÏí */
	public void share(HashMap<Platform, HashMap<String, Object>> shareData)
	{
		boolean started = false;
		for (Entry<Platform, HashMap<String, Object>> ent : shareData.entrySet())
		{
			Platform plat = ent.getKey();
			plat.SSOSetting(disableSSO);
			String name = plat.getName();

			boolean isGooglePlus = "GooglePlus".equals(name);
			if (isGooglePlus && !plat.isClientValid())
			{
				Message msg = new Message();
				msg.what = MSG_TOAST;
				int resId = getStringRes(context, "google_plus_client_inavailable");
				msg.obj = context.getString(resId);
				UIHandler.sendMessage(msg, this);
				continue;
			}

			boolean isAlipay = "Alipay".equals(name);
			if (isAlipay && !plat.isClientValid())
			{
				Message msg = new Message();
				msg.what = MSG_TOAST;
				int resId = getStringRes(context, "alipay_client_inavailable");
				msg.obj = context.getString(resId);
				UIHandler.sendMessage(msg, this);
				continue;
			}

			boolean isKakaoTalk = "KakaoTalk".equals(name);
			if (isKakaoTalk && !plat.isClientValid())
			{
				Message msg = new Message();
				msg.what = MSG_TOAST;
				int resId = getStringRes(context, "kakaotalk_client_inavailable");
				msg.obj = context.getString(resId);
				UIHandler.sendMessage(msg, this);
				continue;
			}

			boolean isKakaoStory = "KakaoStory".equals(name);
			if (isKakaoStory && !plat.isClientValid())
			{
				Message msg = new Message();
				msg.what = MSG_TOAST;
				int resId = getStringRes(context, "kakaostory_client_inavailable");
				msg.obj = context.getString(resId);
				UIHandler.sendMessage(msg, this);
				continue;
			}

			boolean isLine = "Line".equals(name);
			if (isLine && !plat.isClientValid())
			{
				Message msg = new Message();
				msg.what = MSG_TOAST;
				int resId = getStringRes(context, "line_client_inavailable");
				msg.obj = context.getString(resId);
				UIHandler.sendMessage(msg, this);
				continue;
			}

			boolean isWhatsApp = "WhatsApp".equals(name);
			if (isWhatsApp && !plat.isClientValid())
			{
				Message msg = new Message();
				msg.what = MSG_TOAST;
				int resId = getStringRes(context, "whatsapp_client_inavailable");
				msg.obj = context.getString(resId);
				UIHandler.sendMessage(msg, this);
				continue;
			}

			boolean isPinterest = "Pinterest".equals(name);
			if (isPinterest && !plat.isClientValid())
			{
				Message msg = new Message();
				msg.what = MSG_TOAST;
				int resId = getStringRes(context, "pinterest_client_inavailable");
				msg.obj = context.getString(resId);
				UIHandler.sendMessage(msg, this);
				continue;
			}

			if ("Instagram".equals(name) && !plat.isClientValid())
			{
				Message msg = new Message();
				msg.what = MSG_TOAST;
				int resId = getStringRes(context, "instagram_client_inavailable");
				msg.obj = context.getString(resId);
				UIHandler.sendMessage(msg, this);
				continue;
			}

			boolean isLaiwang = "Laiwang".equals(name);
			boolean isLaiwangMoments = "LaiwangMoments".equals(name);
			if (isLaiwang || isLaiwangMoments)
			{
				if (!plat.isClientValid())
				{
					Message msg = new Message();
					msg.what = MSG_TOAST;
					int resId = getStringRes(context, "laiwang_client_inavailable");
					msg.obj = context.getString(resId);
					UIHandler.sendMessage(msg, this);
					continue;
				}
			}

			boolean isYixin = "YixinMoments".equals(name) || "Yixin".equals(name);
			if (isYixin && !plat.isClientValid())
			{
				Message msg = new Message();
				msg.what = MSG_TOAST;
				int resId = getStringRes(context, "yixin_client_inavailable");
				msg.obj = context.getString(resId);
				UIHandler.sendMessage(msg, this);
				continue;
			}

			HashMap<String, Object> data = ent.getValue();
			int shareType = Platform.SHARE_TEXT;
			String imagePath = String.valueOf(data.get("imagePath"));
			if (imagePath != null && (new File(imagePath)).exists())
			{
				shareType = Platform.SHARE_IMAGE;
				if (imagePath.endsWith(".gif"))
				{
					shareType = Platform.SHARE_EMOJI;
				}
				else if (data.containsKey("url") && !TextUtils.isEmpty(data.get("url").toString()))
				{
					shareType = Platform.SHARE_WEBPAGE;
					if (data.containsKey("musicUrl") && !TextUtils.isEmpty(data.get("musicUrl").toString()))
					{
						shareType = Platform.SHARE_MUSIC;
					}
				}
			}
			else
			{
				Bitmap viewToShare = (Bitmap) data.get("viewToShare");
				if (viewToShare != null && !viewToShare.isRecycled())
				{
					shareType = Platform.SHARE_IMAGE;
					if (data.containsKey("url") && !TextUtils.isEmpty(data.get("url").toString()))
					{
						shareType = Platform.SHARE_WEBPAGE;
						if (data.containsKey("musicUrl") && !TextUtils.isEmpty(data.get("musicUrl").toString()))
						{
							shareType = Platform.SHARE_MUSIC;
						}
					}
				}
				else
				{
					Object imageUrl = data.get("imageUrl");
					if (imageUrl != null && !TextUtils.isEmpty(String.valueOf(imageUrl)))
					{
						shareType = Platform.SHARE_IMAGE;
						if (String.valueOf(imageUrl).endsWith(".gif"))
						{
							shareType = Platform.SHARE_EMOJI;
						}
						else if (data.containsKey("url") && !TextUtils.isEmpty(data.get("url").toString()))
						{
							shareType = Platform.SHARE_WEBPAGE;
							if (data.containsKey("musicUrl") && !TextUtils.isEmpty(data.get("musicUrl").toString()))
							{
								shareType = Platform.SHARE_MUSIC;
							}
						}
					}
				}
			}
			data.put("shareType", shareType);

			if (!started)
			{
				started = true;
				// if (this == callback) {
				int resId = getStringRes(context, "sharing");
				if (resId > 0)
				{
					showNotification(context.getString(resId));
				}
				// }
			}
			plat.setPlatformActionListener(callback);
			ShareCore shareCore = new ShareCore();
			shareCore.setShareContentCustomizeCallback(customizeCallback);
			shareCore.share(plat, data);
		}
	}

	public void onComplete(Platform platform, int action,
							HashMap<String, Object> res)
	{
		Message msg = new Message();
		msg.what = MSG_ACTION_CCALLBACK;
		msg.arg1 = 1;
		msg.arg2 = action;
		msg.obj = platform;
		UIHandler.sendMessage(msg, this);
	}

	public void onError(Platform platform, int action, Throwable t)
	{
		t.printStackTrace();

		Message msg = new Message();
		msg.what = MSG_ACTION_CCALLBACK;
		msg.arg1 = 2;
		msg.arg2 = action;
		msg.obj = t;
		UIHandler.sendMessage(msg, this);

		// ·ÖÏíÊ§°ÜµÄÍ³¼Æ
		ShareSDK.logDemoEvent(4, platform);
	}

	public void onCancel(Platform platform, int action)
	{
		Message msg = new Message();
		msg.what = MSG_ACTION_CCALLBACK;
		msg.arg1 = 3;
		msg.arg2 = action;
		msg.obj = platform;
		UIHandler.sendMessage(msg, this);

		// ·ÖÏíÊ§°ÜµÄÍ³¼Æ
		ShareSDK.logDemoEvent(5, platform);
	}

	public boolean handleMessage(Message msg)
	{
		switch (msg.what)
		{
			case MSG_TOAST:
			{
				String text = String.valueOf(msg.obj);
				Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
			}
				break;
			case MSG_ACTION_CCALLBACK:
			{
				switch (msg.arg1)
				{
					case 1:
					{
						// ³É¹¦
						int resId = getStringRes(context, "share_completed");
						if (resId > 0)
						{
							showNotification(context.getString(resId));
						}
					}
						break;
					case 2:
					{
						// Ê§°Ü
						String expName = msg.obj.getClass().getSimpleName();
						if ("WechatClientNotExistException".equals(expName)
							|| "WechatTimelineNotSupportedException".equals(expName)
							|| "WechatFavoriteNotSupportedException".equals(expName))
						{
							int resId = getStringRes(context, "wechat_client_inavailable");
							if (resId > 0)
							{
								showNotification(context.getString(resId));
							}
						}
						else if ("GooglePlusClientNotExistException".equals(expName))
						{
							int resId = getStringRes(context, "google_plus_client_inavailable");
							if (resId > 0)
							{
								showNotification(context.getString(resId));
							}
						}
						else if ("QQClientNotExistException".equals(expName))
						{
							int resId = getStringRes(context, "qq_client_inavailable");
							if (resId > 0)
							{
								showNotification(context.getString(resId));
							}
						}
						else if ("YixinClientNotExistException".equals(expName)
									|| "YixinTimelineNotSupportedException".equals(expName))
						{
							int resId = getStringRes(context, "yixin_client_inavailable");
							if (resId > 0)
							{
								showNotification(context.getString(resId));
							}
						}
						else if ("KakaoTalkClientNotExistException".equals(expName))
						{
							int resId = getStringRes(context, "kakaotalk_client_inavailable");
							if (resId > 0)
							{
								showNotification(context.getString(resId));
							}
						}
						else if ("KakaoStoryClientNotExistException".equals(expName))
						{
							int resId = getStringRes(context, "kakaostory_client_inavailable");
							if (resId > 0)
							{
								showNotification(context.getString(resId));
							}
						}
						else if ("WhatsAppClientNotExistException".equals(expName))
						{
							int resId = getStringRes(context, "whatsapp_client_inavailable");
							if (resId > 0)
							{
								showNotification(context.getString(resId));
							}
						}
						else
						{
							int resId = getStringRes(context, "share_failed");
							if (resId > 0)
							{
								showNotification(context.getString(resId));
							}
						}
					}
						break;
					case 3:
					{
						// È¡Ïû
						int resId = getStringRes(context, "share_canceled");
						if (resId > 0)
						{
							showNotification(context.getString(resId));
						}
					}
						break;
				}
			}
				break;
			case MSG_CANCEL_NOTIFY:
			{
				NotificationManager nm = (NotificationManager) msg.obj;
				if (nm != null)
				{
					nm.cancel(msg.arg1);
				}
			}
				break;
		}
		return false;
	}

	// ÔÚ×´Ì¬À¸ÌáÊ¾·ÖÏí²Ù×÷
	private void showNotification(String text)
	{
		Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
	}

	/** ÊÇ·ñÖ§³ÖQQ,QZoneÊÚÈ¨µÇÂ¼ºó·¢Î¢²© */
	public void setShareFromQQAuthSupport(boolean shareFromQQLogin)
	{
		shareParamsMap.put("isShareTencentWeibo", shareFromQQLogin);
	}

}
