private void initAtUserView() { LinearLayout atLayout = (LinearLayout) findViewByResName("atLayout"); for (Platform platform : platforms) { String platformName = platform.getName(); if (isShowAtUserLayout(platformName)) { View view = LayoutInflater.from(activity) .inflate(getLayoutRes(activity, "skyblue_editpage_at_layout"), null); TextView atDescTextView = (TextView) view.findViewById(getIdRes(activity, "atDescTextView")); TextView atTextView = (TextView) view.findViewById(getIdRes(activity, "atTextView")); OnClickListener atBtnClickListener = new OnClickListener() { public void onClick(View v) { FollowListPage subPage = new FollowListPage(); subPage.setPlatform((Platform) v.getTag()); subPage.showForResult(activity, null, EditPage.this); } }; atTextView.setTag(platform); atTextView.setOnClickListener(atBtnClickListener); atDescTextView.setTag(platform); atDescTextView.setOnClickListener(atBtnClickListener); atTextView.setText(getAtUserButtonText(platformName)); atDescTextView.setText( getContext() .getString(getStringRes(activity, "list_friends"), getLogoName(platformName))); atLayout.addView(view); } } }
@SuppressWarnings("unchecked") public boolean handleMessage(Message msg) { dismissDialog(); switch (msg.what) { case MSG_AUTH_CANCEL: { // 取消授权 Toast.makeText(this, R.string.auth_cancel, Toast.LENGTH_SHORT).show(); } break; case MSG_AUTH_ERROR: { // 授权失败 Toast.makeText(this, R.string.auth_error, Toast.LENGTH_SHORT).show(); } break; case MSG_AUTH_COMPLETE: { // 授权成功 Toast.makeText(this, R.string.auth_complete, Toast.LENGTH_SHORT).show(); Object[] objs = (Object[]) msg.obj; String platform = (String) objs[0]; Platform plat = ShareSDK.getPlatform(platform); userid = plat.getDb().getUserId(); username = plat.getDb().getUserName(); // edtUsername.setText(usericon); presenter.otherSigin(username, userid, usericon, layWx); } break; } return false; }
public void onClick(View v) { Platform plat = (Platform) v.getTag(); if (plat != null) { if (silent) { HashMap<Platform, HashMap<String, Object>> shareData = new HashMap<Platform, HashMap<String, Object>>(); shareData.put(plat, reqData); parent.share(shareData); return; } String name = plat.getName(); parent.setPlatform(name); // EditPage不支持微信平台、Google+、QQ分享、信息和邮件,总是执行直接分享 if ("Wechat".equals(name) || "WechatMoments".equals(name) || "ShortMessage".equals(name) || "Email".equals(name) || "GooglePlus".equals(name) || "QQ".equals(name)) { HashMap<Platform, HashMap<String, Object>> shareData = new HashMap<Platform, HashMap<String, Object>>(); shareData.put(plat, reqData); parent.share(shareData); return; } // 跳转SharePage分享 EditPage page = new EditPage(); page.setShareData(reqData); page.setParent(parent); page.show(parent.getContext(), null); parent.finish(); } }
private void authorize(Platform plat) { showDialog("正在调起授权"); if (plat == null) { // popupOthers(); return; } /** 清除之前的账户 */ if (plat.isValid()) { plat.removeAccount(); } // 判断指定平台是否已经完成授权 // if (plat.isAuthValid()) { // String userId = plat.getDb().getUserId(); // if (userId != null) { // handler.sendEmptyMessage(MSG_USERID_FOUND); //// login(plat.getName(), userId, null); // return; // } // } plat.setPlatformActionListener(this); // true不使用SSO授权,false使用SSO授权 plat.SSOSetting(false); // 获取用户资料 plat.showUser(null); }
// 设置数据至bean对象 private void setDataToBean(LoginBean bean, Platform platform) { bean.setToken(platform.getDb().getToken()); // 获取授权token bean.setExpiresTime(platform.getDb().getExpiresTime()); // 获取token时间 bean.setUserId(platform.getDb().getUserId()); // 获取用户在此平台的ID bean.setNickName(platform.getDb().get("nickname")); // 获取用户昵称 bean.setIco(platform.getDb().getUserIcon()); }
/** * 向指定平台分享内容 * * <p><b>注意:</b><br> * 参数data的键值需要严格按照{@link ShareParams}不同子类具体字段来命名, 否则无法反射此字段,也无法设置其值。 */ public boolean share(Platform plat, HashMap<String, Object> data) { if (plat == null || data == null) { return false; } try { String imagePath = (String) data.get("imagePath"); Bitmap viewToShare = (Bitmap) data.get("viewToShare"); if (TextUtils.isEmpty(imagePath) && viewToShare != null && !viewToShare.isRecycled()) { String path = R.getCachePath(plat.getContext(), "screenshot"); File ss = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg"); FileOutputStream fos = new FileOutputStream(ss); viewToShare.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); data.put("imagePath", ss.getAbsolutePath()); } } catch (Throwable t) { t.printStackTrace(); return false; } ShareParams sp = new ShareParams(data); if (customizeCallback != null) { customizeCallback.onShare(plat, sp); } plat.share(sp); return true; }
@Override public void onCancel(Platform platform, int i) { Toast.makeText( this, getResources().getString(R.string.authorization_cancle), Toast.LENGTH_SHORT) .show(); String name = platform.getDb().getUserName(); String userIcon = platform.getDb().getUserIcon(); }
@Override public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) { Toast.makeText( this, getResources().getString(R.string.authorization_success), Toast.LENGTH_SHORT) .show(); String name = platform.getDb().getUserName(); String userIcon = platform.getDb().getUserIcon(); }
/** display platform list */ @SuppressLint("NewApi") public void afterPlatformListGot() { int size = platformList == null ? 0 : platformList.length; views = new View[size]; final int dp_24 = dipToPx(getContext(), 24); LayoutParams lpItem = new LayoutParams(dp_24, dp_24); final int dp_9 = dipToPx(getContext(), 9); lpItem.setMargins(0, 0, dp_9, 0); FrameLayout.LayoutParams lpMask = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); lpMask.gravity = Gravity.LEFT | Gravity.TOP; int selection = 0; for (int i = 0; i < size; i++) { FrameLayout fl = new FrameLayout(getContext()); fl.setLayoutParams(lpItem); if (i >= size - 1) { fl.setLayoutParams(new LayoutParams(dp_24, dp_24)); } llPlat.addView(fl); fl.setOnClickListener(this); ImageView iv = new ImageView(getContext()); iv.setScaleType(ScaleType.CENTER_INSIDE); iv.setImageBitmap(getPlatLogo(platformList[i])); iv.setLayoutParams( new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); fl.addView(iv); views[i] = new View(getContext()); views[i].setBackgroundColor(0xcfffffff); views[i].setOnClickListener(this); String platformName = platformList[i].getName(); for (Platform plat : platforms) { if (platformName.equals(plat.getName())) { views[i].setVisibility(View.INVISIBLE); selection = i; } } views[i].setLayoutParams(lpMask); fl.addView(views[i]); } final int postSel = selection; UIHandler.sendEmptyMessageDelayed( 0, 333, new Callback() { @SuppressLint("NewApi") public boolean handleMessage(Message msg) { HorizontalScrollView hsv = (HorizontalScrollView) llPlat.getParent(); hsv.scrollTo(postSel * (dp_24 + dp_9), 0); return false; } }); }
public boolean handleMessage(Message msg) { LoginActivity activity; Platform plat = (Platform) msg.obj; String text = null; switch (msg.arg1) { case 1: { // 成功 text = plat.getName() + " 授权成功 "; if (plat.getName().equals("SinaWeibo")) sinax = true; if (plat.getName().equals("TecentWeibo")) tecentx = true; if (plat.getName().equals("Renren")) renrenx = true; if (plat.getName().equals("Douban")) doubanx = true; Toast.makeText(SubmitActivity.this, text, Toast.LENGTH_SHORT).show(); } break; case 2: { // 失败 text = plat.getName() + " 授权失败 "; Toast.makeText(SubmitActivity.this, text, Toast.LENGTH_SHORT).show(); return false; } case 3: { // 取消 text = plat.getName() + " 授权取消 "; if (plat.getName().equals("SinaWeibo")) { sinax = false; sinaweiboTextView.setTextColor(getResources().getColor(R.color.unchoose_color)); } if (plat.getName().equals("TecentWeibo")) { tecentx = false; tencentweiboTextView.setTextColor(getResources().getColor(R.color.unchoose_color)); } if (plat.getName().equals("Renren")) { renrenx = false; renrenTextView.setTextColor(getResources().getColor(R.color.unchoose_color)); } if (plat.getName().equals("Douban")) { doubanx = false; doubanTextView.setTextColor(getResources().getColor(R.color.unchoose_color)); } Toast.makeText(SubmitActivity.this, text, Toast.LENGTH_SHORT).show(); return false; } } return false; }
protected void setResultAndFinish() { ArrayList<String> imageArray = new ArrayList<String>(); if (shareImageList != null) { for (ImageInfo imageInfo : shareImageList) { if ("imagePath".equals(imageInfo.paramName) || "imageUrl".equals(imageInfo.paramName)) { shareParamMap.put(imageInfo.paramName, imageInfo.srcValue); } else if ("viewToShare".equals(imageInfo.paramName)) { shareParamMap.put(imageInfo.paramName, imageInfo.bitmap); } else if ("imageArray".equals(imageInfo.paramName)) { imageArray.add(imageInfo.srcValue); } } shareImageList.clear(); if (imageArray.size() == 0) { shareParamMap.put("imageArray", null); } else { shareParamMap.put("imageArray", imageArray.toArray(new String[imageArray.size()])); } } HashMap<Platform, HashMap<String, Object>> editRes = new HashMap<Platform, HashMap<String, Object>>(); for (Platform platform : platforms) { if ("FacebookMessenger".equals(platform.getName())) { HashMap<String, Object> param = new HashMap<String, Object>(shareParamMap); if (toFriendList != null && toFriendList.size() > 0) { param.put("address", toFriendList.get(toFriendList.size() - 1)); } if (param.get("address") == null) { int resId = getStringRes(activity, "select_a_friend"); if (resId > 0) { Toast.makeText( getContext(), activity.getString(resId) + " - " + platform.getName(), Toast.LENGTH_SHORT) .show(); } return; } editRes.put(platform, param); continue; } editRes.put(platform, shareParamMap); } HashMap<String, Object> res = new HashMap<String, Object>(); res.put("editRes", editRes); setResult(res); finish(); }
private String getName(Platform plat) { if (plat == null) { return ""; } String name = plat.getName(); if (name == null) { return ""; } int resId = cn.sharesdk.framework.utils.R.getStringRes(getContext(), plat.getName()); return getContext().getString(resId); }
/** 初始化数据 */ private void initData() { String gender = ""; if (platform != null) { gender = platform.getDb().getUserGender(); if (gender.equals("m")) { userInfo.setUserGender(UserInfo.Gender.BOY); gender = getContext().getString(R.string.tpl_boy); } else { userInfo.setUserGender(UserInfo.Gender.GIRL); gender = getContext().getString(R.string.tpl_girl); } userInfo.setUserIcon(platform.getDb().getUserIcon()); userInfo.setUserName(platform.getDb().getUserName()); userInfo.setUserNote(platform.getDb().getUserId()); } tvUserName.setText(userInfo.getUserName()); tvUserGender.setText(gender); tvUserNote.setText("USER ID : " + userInfo.getUserNote()); // 加载头像 if (!TextUtils.isEmpty(userInfo.getUserIcon())) { loadIcon(); } // 初始化照片保存地址 if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { String thumPicture = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + activity.getPackageName() + "/download"; File pictureParent = new File(thumPicture); File pictureFile = new File(pictureParent, PICTURE_NAME); if (!pictureParent.exists()) { pictureParent.mkdirs(); } try { if (!pictureFile.exists()) { pictureFile.createNewFile(); } } catch (Exception e) { e.printStackTrace(); } picturePath = pictureFile.getAbsolutePath(); Log.e("picturePath ==>>", picturePath); } else { Log.e("change user icon ==>>", "there is not sdcard!"); } }
private Bitmap getIcon(Platform plat) { if (plat == null) { return null; } String name = plat.getName(); if (name == null) { return null; } String resName = "logo_" + plat.getName(); int resId = cn.sharesdk.framework.utils.R.getResId(R.drawable.class, resName); return BitmapFactory.decodeResource(getResources(), resId); }
private Bitmap getIcon(Platform plat) { if (plat == null) { return null; } String name = plat.getName(); if (name == null) { return null; } String resName = "logo_" + plat.getName(); int resId = getBitmapRes(getContext(), resName.toLowerCase()); return BitmapFactory.decodeResource(getResources(), resId); }
private String getName(Platform plat) { if (plat == null) { return ""; } String name = plat.getName(); if (name == null) { return ""; } int resId = com.mob.tools.utils.R.getStringRes(getContext(), plat.getName().toLowerCase()); if (resId > 0) { return getContext().getString(resId); } return null; }
@Override public void onError(Platform platform, int i, Throwable throwable) { if (BuildConfigUtil.DEBUG) { Log.e(LoginActivity.TAG, "登录错误:" + throwable.toString()); } platform.removeAccount(); }
private Platform.ShareParams getShareParams(Platform plat, HashMap<String, Object> data) throws Throwable { String className = plat.getClass().getName() + "$ShareParams"; Class<?> cls = Class.forName(className); if (cls == null) { return null; } Object sp = cls.newInstance(); if (sp == null) { return null; } for (Entry<String, Object> ent : data.entrySet()) { try { Field fld = cls.getField(ent.getKey()); if (fld != null) { fld.setAccessible(true); fld.set(sp, ent.getValue()); } } catch (Throwable t) { } } return (Platform.ShareParams) sp; }
/** 加载头像 */ public void loadIcon() { final String imageUrl = platform.getDb().getUserIcon(); new Thread( new Runnable() { @Override public void run() { try { URL picUrl = new URL(imageUrl); Bitmap userIcon = BitmapFactory.decodeStream(picUrl.openStream()); FileOutputStream b = null; try { b = new FileOutputStream(picturePath); userIcon.compress(Bitmap.CompressFormat.JPEG, 100, b); // 把数据写入文件 } catch (FileNotFoundException e) { e.printStackTrace(); } finally { try { b.flush(); b.close(); } catch (IOException e) { e.printStackTrace(); } } userInfo.setUserIcon(picturePath); Message msg = new Message(); msg.what = LOAD_USER_ICON; UIHandler.sendMessage(msg, SignupPage.this); } catch (Exception e) { e.printStackTrace(); } } }) .start(); }
private Bitmap getPlatLogo(Platform plat) { if (plat == null) { return null; } String name = plat.getName(); if (name == null) { return null; } String resName = "logo_" + plat.getName(); int resId = getBitmapRes(activity, resName); if (resId > 0) { return BitmapFactory.decodeResource(activity.getResources(), resId); } return null; }
public void onComplete(Platform platform, int action, HashMap<String, Object> res) { dismissDialog(); if (action == Platform.ACTION_USER_INFOR) { this.res = res; Message msg = new Message(); msg.what = MSG_AUTH_COMPLETE; if (platform.getName().equals("QZone")) usericon = res.get("figureurl_qq_2").toString(); else { usericon = platform.getDb().getUserIcon(); // usericon=res.get("profile_image_url").toString();//头像链接 } msg.obj = new Object[] {platform.getName(), res}; String s = platform.getDb().getToken().toString(); String ss = platform.getDb().getTokenSecret().toString(); handler.sendMessage(msg); } }
// #endif public static boolean isUseClientToShare(Context context, String platform) { if ("Wechat".equals(platform) || "WechatMoments".equals(platform) || "ShortMessage".equals(platform) || "Email".equals(platform) || "GooglePlus".equals(platform) || "QQ".equals(platform) || "Pinterest".equals(platform) || "Instagram".equals(platform)) { return true; } else if ("Evernote".equals(platform)) { Platform plat = ShareSDK.getPlatform(context, platform); if ("true".equals(plat.getDevinfo("ShareByAppClient"))) { return true; } } return false; }
/** 判断指定平台是否使用客户端分享 */ public static boolean isUseClientToShare(String platform) { if ("Wechat".equals(platform) || "WechatMoments".equals(platform) || "WechatFavorite".equals(platform) || "ShortMessage".equals(platform) || "Email".equals(platform) || "GooglePlus".equals(platform) || "QQ".equals(platform) || "Pinterest".equals(platform) || "Instagram".equals(platform) || "Yixin".equals(platform) || "YixinMoments".equals(platform) || "QZone".equals(platform) || "Mingdao".equals(platform) || "Line".equals(platform) || "KakaoStory".equals(platform) || "KakaoTalk".equals(platform) || "Bluetooth".equals(platform) || "WhatsApp".equals(platform) || "BaiduTieba".equals(platform) || "Laiwang".equals(platform) || "LaiwangMoments".equals(platform)) { return true; } else if ("Evernote".equals(platform)) { Platform plat = ShareSDK.getPlatform(platform); if ("true".equals(plat.getDevinfo("ShareByAppClient"))) { return true; } } else if ("SinaWeibo".equals(platform)) { Platform plat = ShareSDK.getPlatform(platform); if ("true".equals(plat.getDevinfo("ShareByAppClient"))) { Intent test = new Intent(Intent.ACTION_SEND); test.setPackage("com.sina.weibo"); test.setType("image/*"); ResolveInfo ri = plat.getContext().getPackageManager().resolveActivity(test, 0); return (ri != null); } } return false; }
public PlatformAdapter(PlatformGridView platformGridView) { this.platformGridView = platformGridView; logos = new ArrayList<Object>(); Platform[] platforms = platformGridView.platformList; HashMap<String, String> hiddenPlatforms = platformGridView.hiddenPlatforms; if (platforms != null) { if (hiddenPlatforms != null && hiddenPlatforms.size() > 0) { ArrayList<Platform> ps = new ArrayList<Platform>(); for (Platform p : platforms) { if (hiddenPlatforms.containsKey(p.getName())) { continue; } ps.add(p); } platforms = new Platform[ps.size()]; for (int i = 0; i < platforms.length; i++) { platforms[i] = ps.get(i); } } logos.addAll(Arrays.asList(platforms)); } ArrayList<CustomerLogo> customers = platformGridView.customers; if (customers != null) { logos.addAll(customers); } this.callback = platformGridView; girds = null; if (logos != null) { int size = logos.size(); int PAGE_SIZE = platformGridView.PAGE_SIZE; int pageCount = size / PAGE_SIZE; if (size % PAGE_SIZE > 0) { pageCount++; } girds = new GridView[pageCount]; } }
public void onCancel(Platform platform, int action) { if (ShareSDKUtils.DEBUG) { System.out.println("onCancel"); } HashMap<String, Object> map = new HashMap<String, Object>(); map.put("platform", ShareSDK.platformNameToId(platform.getName())); map.put("action", action); map.put("status", 3); // Success = 1, Fail = 2, Cancel = 3 map.put("reqID", reqID); Message msg = new Message(); msg.obj = new Hashon().fromHashMap(map); UIHandler.sendMessage(msg, c2dCallback); }
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String name = platform.getName(); if ("FacebookMessenger".equals(name)) { if (lastPosition >= 0) { Following lastFollwing = adapter.getItem(lastPosition); lastFollwing.checked = false; } lastPosition = position; } Following following = adapter.getItem(position); following.checked = !following.checked; adapter.notifyDataSetChanged(); }
// 点击事件的实现 public void loginOperate(View view) { if (view != null) { int id = view.getId(); switch (id) { // 回退按键退出当前的Activity case R.id.login_back: finish(); break; // 登录按键 case R.id.login_button: break; // 忘记密码处理 case R.id.login_forgetpwd: break; // 注册新用户 case R.id.login_new_user_register: break; // 第三方微信登录 case R.id.login_wechat: Platform wechat = ShareSDK.getPlatform(this, Wechat.NAME); wechat.SSOSetting(false); wechat.setPlatformActionListener(this); wechat.authorize(); break; // 第三方qq登录 case R.id.login_qq: Platform qq = ShareSDK.getPlatform(this, QQ.NAME); qq.setPlatformActionListener(this); qq.authorize(); break; // 第三方新浪登录 case R.id.login_sina: Platform sina = ShareSDK.getPlatform(this, SinaWeibo.NAME); sina.setPlatformActionListener(this); sina.authorize(); break; } } }
public void onComplete(Platform platform, int action, HashMap<String, Object> res) { if (ShareSDKUtils.DEBUG) { System.out.println("onComplete"); System.out.println(res == null ? "" : res.toString()); } HashMap<String, Object> map = new HashMap<String, Object>(); map.put("platform", ShareSDK.platformNameToId(platform.getName())); map.put("action", action); map.put("status", 1); // Success = 1, Fail = 2, Cancel = 3 if (action == 8 || action == 2) { // action = 2, 8, 获取用户列表与用户信息才放入 map.put("res", res); } map.put("reqID", reqID); Message msg = new Message(); msg.obj = new Hashon().fromHashMap(map); UIHandler.sendMessage(msg, c2dCallback); }
public void onClick(View v) { String name = platform.getName(); if (v.equals(llTitle.getBtnRight())) { ArrayList<String> selected = new ArrayList<String>(); if ("SinaWeibo".equals(name)) { for (int i = 0, size = adapter.getCount(); i < size; i++) { if (adapter.getItem(i).checked) { selected.add(adapter.getItem(i).screeName); } } } else if ("TencentWeibo".equals(name)) { for (int i = 0, size = adapter.getCount(); i < size; i++) { if (adapter.getItem(i).checked) { selected.add(adapter.getItem(i).uid); } } } else if ("Facebook".equals(name)) { for (int i = 0, size = adapter.getCount(); i < size; i++) { if (adapter.getItem(i).checked) { selected.add("[" + adapter.getItem(i).uid + "]"); } } } else if ("Twitter".equals(name)) { for (int i = 0, size = adapter.getCount(); i < size; i++) { if (adapter.getItem(i).checked) { selected.add(adapter.getItem(i).uid); } } } else if ("FacebookMessenger".equals(name)) { for (int i = 0, size = adapter.getCount(); i < size; i++) { if (adapter.getItem(i).checked) { selected.add(adapter.getItem(i).uid); } } } HashMap<String, Object> res = new HashMap<String, Object>(); res.put("selected", selected); setResult(res); } finish(); }
// #endif public boolean share(Platform plat, HashMap<String, Object> data) { if (plat == null || data == null) { return false; } Platform.ShareParams sp = null; try { sp = getShareParams(plat, data); } catch (Throwable t) { sp = null; } if (sp != null) { if (customizeCallback != null) { customizeCallback.onShare(plat, sp); } plat.share(sp); } return true; }