Android Open Source - ShareSDK-for-Android Yixin Page






From Project

Back to project page ShareSDK-for-Android.

License

The source code is released under:

MIT License

If you think the Android project ShareSDK-for-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Offical Website:http://www.mob.com/*  w  w w.ja v  a2 s  . c  o m*/
 * Support QQ: 4006852216
 * Offical Wechat Account:ShareSDK   (We will inform you our updated news at the first time by Wechat, if we release a new version. If you get any problem, you can also contact us with Wechat, we will reply you within 24 hours.)
 *
 * Copyright (c) 2013 mob.com. All rights reserved.
 */

package cn.sharesdk.demo;

import java.util.HashMap;
import m.framework.ui.widget.slidingmenu.SlidingMenu;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.utils.UIHandler;
import cn.sharesdk.framework.Platform.ShareParams;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.framework.TitleLayout;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CheckedTextView;
import android.widget.Toast;

/** page to show Yixin apis. */
public class YixinPage extends SlidingMenuPage implements
    OnClickListener, PlatformActionListener {
  private TitleLayout llTitle;
  private CheckedTextView[] ctvPlats;
  private View pageView;

  public YixinPage(SlidingMenu menu) {
    super(menu);
    pageView = getPage();
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("BypassApproval", false);
    ShareSDK.setPlatformDevInfo("Yixin", map);
    ShareSDK.setPlatformDevInfo("YixinMoments", map);

    llTitle = (TitleLayout) pageView.findViewById(R.id.llTitle);
    llTitle.getBtnBack().setOnClickListener(this);
    llTitle.getTvTitle().setText(R.string.sm_item_yixin);

    ctvPlats = new CheckedTextView[] {
        (CheckedTextView) pageView.findViewById(R.id.ctvStWc),
        (CheckedTextView) pageView.findViewById(R.id.ctvStWm),
        (CheckedTextView) pageView.findViewById(R.id.ctvStWf)
    };
    int[] labels = new int[] {
        R.string.share_to_yixin,
        R.string.share_to_yixin_moment,
        R.string.share_to_yixin_favorite
    };
    for (int i = 0; i < ctvPlats.length; i++) {
      ctvPlats[i].setText(labels[i]);
      ctvPlats[i].setOnClickListener(this);
    }
    ViewGroup vp = (ViewGroup) ctvPlats[0].getParent().getParent();
    for (int i = 0, size = vp.getChildCount(); i < size; i++) {
      vp.getChildAt(i).setOnClickListener(this);
    }

    ctvPlats[0].setChecked(true);
    int[] invIds = new int[] {
        R.id.btnEmoji,
        R.id.btnEmojiUrl,
        R.id.btnEmojiBitmap,
        R.id.btnApp,
        R.id.btnAppExt,
        R.id.btnFile
    };
    for (int id : invIds) {
      pageView.findViewById(id).setVisibility(View.GONE);
    }
    ctvPlats[2].setVisibility(View.GONE);
  }

  protected View initPage() {
    return LayoutInflater.from(getContext())
        .inflate(R.layout.page_wechate, null);
  }

  public void onClick(View v) {
    if (v.equals(llTitle.getBtnBack())) {
      if (isMenuShown()) {
        hideMenu();
      }
      else {
        showMenu();
      }
      return;
    }

    if (v instanceof CheckedTextView) {
      for (CheckedTextView ctv : ctvPlats) {
        ctv.setChecked(ctv.equals(v));
      }

      int[] visIds = null;
      int[] invIds = null;
      if (v.equals(ctvPlats[0])) {
        visIds = new int[] {
            R.id.btnUpdate,
            R.id.btnUpload,
            R.id.btnUploadBm,
            R.id.btnUploadUrl,
            R.id.btnMusic,
            R.id.btnVideo,
            R.id.btnWebpage,
            R.id.btnWebpageBm,
            R.id.btnWebpageUrl
        };
        invIds = new int[] {
            R.id.btnEmoji,
            R.id.btnEmojiUrl,
            R.id.btnEmojiBitmap,
            R.id.btnApp,
            R.id.btnAppExt,
            R.id.btnFile
        };
      } else if (v.equals(ctvPlats[1])) {
        visIds = new int[] {
            R.id.btnUpdate,
            R.id.btnUpload,
            R.id.btnUploadBm,
            R.id.btnUploadUrl,
            R.id.btnMusic,
            R.id.btnVideo,
            R.id.btnWebpage,
            R.id.btnWebpageBm,
            R.id.btnWebpageUrl
        };
        invIds = new int[] {
            R.id.btnEmoji,
            R.id.btnEmojiUrl,
            R.id.btnEmojiBitmap,
            R.id.btnApp,
            R.id.btnAppExt,
            R.id.btnFile
        };
      } else {
        visIds = new int[] {
            R.id.btnUpdate,
            R.id.btnUpload,
            R.id.btnUploadBm,
            R.id.btnUploadUrl,
            R.id.btnMusic,
            R.id.btnVideo,
            R.id.btnWebpage,
            R.id.btnWebpageBm,
            R.id.btnWebpageUrl
        };
        invIds = new int[] {
            R.id.btnEmoji,
            R.id.btnEmojiUrl,
            R.id.btnEmojiBitmap,
            R.id.btnApp,
            R.id.btnAppExt,
            R.id.btnFile
        };
      }

      for (int id : visIds) {
        findViewById(id).setVisibility(View.VISIBLE);
      }
      for (int id : invIds) {
        findViewById(id).setVisibility(View.GONE);
      }
      return;
    }

    Platform plat = null;
    ShareParams sp = getShareParams(v);
    if (ctvPlats[0].isChecked()) {
      plat = ShareSDK.getPlatform("Yixin");
    } else if (ctvPlats[1].isChecked()) {
      plat = ShareSDK.getPlatform("YixinMoments");
    }
    plat.setPlatformActionListener(this);
    plat.share(sp);
  }

  private ShareParams getShareParams(View v) {
    ShareParams sp = new ShareParams();
    sp.setTitle(getContext().getString(R.string.wechat_demo_title));
    sp.setText(getContext().getString(R.string.share_content));
    sp.setShareType(Platform.SHARE_TEXT);
    switch (v.getId()) {
      case R.id.btnUpload: {
        sp.setShareType(Platform.SHARE_IMAGE);
        sp.setImagePath(MainActivity.TEST_IMAGE);
      }
      break;
      case R.id.btnUploadBm: {
        sp.setShareType(Platform.SHARE_IMAGE);
        Bitmap imageData = BitmapFactory.decodeResource(v.getResources(), R.drawable.ic_launcher);
        sp.setImageData(imageData);
      }
      break;
      case R.id.btnUploadUrl: {
        sp.setShareType(Platform.SHARE_IMAGE);
        sp.setImageUrl(MainActivity.TEST_IMAGE_URL);
      }
      break;
      case R.id.btnMusic: {
        sp.setShareType(Platform.SHARE_MUSIC);
        String musicUrl = "http://ubuntuone.com/45XSEOwdODtXSH0WYGAcR7";
        sp.setMusicUrl(musicUrl);
        sp.setUrl("http://mob.com");
        sp.setImagePath(MainActivity.TEST_IMAGE);
      }
      break;
      case R.id.btnVideo: {
        sp.setShareType(Platform.SHARE_VIDEO);
        sp.setUrl("http://t.cn/zT7cZAo");
        sp.setImagePath(MainActivity.TEST_IMAGE);
      }
      break;
      case R.id.btnWebpage: {
        sp.setShareType(Platform.SHARE_WEBPAGE);
        sp.setUrl("http://t.cn/zT7cZAo");
        sp.setImagePath(MainActivity.TEST_IMAGE);
      }
      break;
      case R.id.btnWebpageBm: {
        sp.setShareType(Platform.SHARE_WEBPAGE);
        sp.setUrl("http://t.cn/zT7cZAo");
        Bitmap imageData = BitmapFactory.decodeResource(v.getResources(), R.drawable.ic_launcher);
        sp.setImageData(imageData);
      }
      break;
      case R.id.btnWebpageUrl: {
        sp.setShareType(Platform.SHARE_WEBPAGE);
        sp.setUrl("http://t.cn/zT7cZAo");
        sp.setImageUrl(MainActivity.TEST_IMAGE_URL);
      }
      break;
    }
    return sp;
  }

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

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

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

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

  public boolean handleMessage(Message msg) {
    String text = MainActivity.actionToString(msg.arg2);
    switch (msg.arg1) {
      case 1: {
        // success
        Platform plat = (Platform) msg.obj;
        text = plat.getName() + " completed at " + text;
      }
      break;
      case 2: {
        // failed
        if ("YixinClientNotExistException".equals(msg.obj.getClass().getSimpleName())) {
          text = getContext().getString(R.string.yixin_client_inavailable);
        } else if ("YixinClientNotExistException".equals(msg.obj.getClass().getSimpleName())) {
          text = getContext().getString(R.string.yixin_client_inavailable);
        } else {
          text = getContext().getString(R.string.share_failed);
        }
      }
      break;
      case 3: {
        // canceled
        Platform plat = (Platform) msg.obj;
        text = plat.getName() + " canceled at " + text;
      }
      break;
    }

    Toast.makeText(getContext(), text, Toast.LENGTH_LONG).show();
    return false;
  }

}




Java Source Code List

cn.sharesdk.demo.AuthPage.java
cn.sharesdk.demo.CustomShareFieldsPage.java
cn.sharesdk.demo.CustomerPage.java
cn.sharesdk.demo.DemoPage.java
cn.sharesdk.demo.GetInforPage.java
cn.sharesdk.demo.GetTokenPage.java
cn.sharesdk.demo.JsonPage.java
cn.sharesdk.demo.Laiwang.java
cn.sharesdk.demo.MainActivity.java
cn.sharesdk.demo.MainAdapter.java
cn.sharesdk.demo.MyAdapter.java
cn.sharesdk.demo.MyQZoneWebShareAdapter.java
cn.sharesdk.demo.OneKeyShareCallback.java
cn.sharesdk.demo.ShareContentCustomizeDemo.java
cn.sharesdk.demo.SlidingMenuPage.java
cn.sharesdk.demo.WechatPage.java
cn.sharesdk.demo.YixinPage.java
cn.sharesdk.demo.wxapi.WXEntryActivity.java
cn.sharesdk.demo.yxapi.YXEntryActivity.java
cn.sharesdk.onekeyshare.CustomerLogo.java
cn.sharesdk.onekeyshare.CustomerLogo.java
cn.sharesdk.onekeyshare.EditPageFakeActivity.java
cn.sharesdk.onekeyshare.EditPageFakeActivity.java
cn.sharesdk.onekeyshare.FollowerListFakeActivity.java
cn.sharesdk.onekeyshare.FollowerListFakeActivity.java
cn.sharesdk.onekeyshare.OnekeyShareTheme.java
cn.sharesdk.onekeyshare.OnekeyShareTheme.java
cn.sharesdk.onekeyshare.OnekeyShare.java
cn.sharesdk.onekeyshare.OnekeyShare.java
cn.sharesdk.onekeyshare.PicViewer.java
cn.sharesdk.onekeyshare.PicViewer.java
cn.sharesdk.onekeyshare.PlatformListFakeActivity.java
cn.sharesdk.onekeyshare.PlatformListFakeActivity.java
cn.sharesdk.onekeyshare.Shake2Share.java
cn.sharesdk.onekeyshare.Shake2Share.java
cn.sharesdk.onekeyshare.ShareContentCustomizeCallback.java
cn.sharesdk.onekeyshare.ShareContentCustomizeCallback.java
cn.sharesdk.onekeyshare.ShareCore.java
cn.sharesdk.onekeyshare.ShareCore.java
cn.sharesdk.onekeyshare.ThemeShareCallback.java
cn.sharesdk.onekeyshare.ThemeShareCallback.java
cn.sharesdk.onekeyshare.theme.classic.EditPage.java
cn.sharesdk.onekeyshare.theme.classic.EditPage.java
cn.sharesdk.onekeyshare.theme.classic.FollowListPage.java
cn.sharesdk.onekeyshare.theme.classic.FollowListPage.java
cn.sharesdk.onekeyshare.theme.classic.PlatformGridView.java
cn.sharesdk.onekeyshare.theme.classic.PlatformGridView.java
cn.sharesdk.onekeyshare.theme.classic.PlatformListPage.java
cn.sharesdk.onekeyshare.theme.classic.PlatformListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.EditPage.java
cn.sharesdk.onekeyshare.theme.skyblue.EditPage.java
cn.sharesdk.onekeyshare.theme.skyblue.FollowListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.FollowListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformGridViewAdapter.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformGridViewAdapter.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformListPage.java
cn.sharesdk.socialization.sample.MainActivity.java
cn.sharesdk.socialization.sample.MyPlatform.java
cn.sharesdk.socialization.sample.wxapi.WXEntryActivity.java
cn.sharesdk.socialization.sample.yxapi.YXEntryActivity.java