package com.example.ym;
import java.util.Map;
import java.util.Set;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.controller.listener.SocializeListeners.UMAuthListener;
import com.umeng.socialize.controller.listener.SocializeListeners.UMDataListener;
import com.umeng.socialize.exception.SocializeException;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.sso.QZoneSsoHandler;
import com.umeng.socialize.sso.UMQQSsoHandler;
import com.umeng.socialize.weixin.controller.UMWXHandler;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private UMSocialService mController;
private ImageView imageView;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dada);
imageView = (ImageView) findViewById(R.id.image);
textView = (TextView) findViewById(R.id.name);
mController = UMServiceFactory.getUMSocialService("com.umeng.login");
String appId = "100424468";
String appKey = "c7394704798a158208a74ab60104f0bas";
// 添加QQ支持, 并且设置QQ分享内容的target url
UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(MainActivity.this,
appId, appKey);
// qqSsoHandler.setTargetUrl("http://www.umeng.com");
// 设置QQ要分享的内容---- 网址
qqSsoHandler.setTargetUrl("http://www.baidu.com");
qqSsoHandler.addToSocialSDK();
// 添加QZone平台 --- 必须添加
QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(
MainActivity.this, appId, appKey);
qZoneSsoHandler.addToSocialSDK();
// 添加微信平台, ---必须添加
UMWXHandler wxHandler = new UMWXHandler(MainActivity.this, appId,
appKey);
wxHandler.addToSocialSDK();
}
// 第三方分享
public void fenxiang(View v) {
mController.setShareContent("www.baidu.com");
mController.setShareImage(new UMImage(MainActivity.this,
R.drawable.ic_launcher));
mController.openShare(MainActivity.this, false);
}
// 第三方登陆
public void QQ(View v) {
login(SHARE_MEDIA.QQ);
}
private void login(SHARE_MEDIA qq) {
mController.doOauthVerify(MainActivity.this, qq, new UMAuthListener() {
@Override
public void onStart(SHARE_MEDIA platform) {
Toast.makeText(MainActivity.this, "开始授权", Toast.LENGTH_SHORT)
.show();
}
@Override
public void onError(SocializeException e, SHARE_MEDIA platform) {
}
@Override
public void onComplete(Bundle value, SHARE_MEDIA platform) {
String uid = value.getString("uid");
if (!TextUtils.isEmpty(uid)) {
getUserInfo(platform);
} else {
Toast.makeText(MainActivity.this, "授权失败...",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancel(SHARE_MEDIA platform) {
Toast.makeText(MainActivity.this, "取消授权", Toast.LENGTH_SHORT)
.show();
}
});
}
private void getUserInfo(SHARE_MEDIA platform) {
mController.getPlatformInfo(MainActivity.this, platform,
new UMDataListener() {
@Override
public void onStart() {
}
@SuppressWarnings("null")
@Override
public void onComplete(int status, Map
info) {
Editor edit = MainActivity.this.getSharedPreferences(
"QQ", Context.MODE_PRIVATE).edit();
if (status == 200 && info != null) {
StringBuilder sb = new StringBuilder();
Set keys = info.keySet();
for (String key : keys) {
sb.append(key + "=" + info.get(key).toString()
+ "\r\n");
// QQ头像
if ("profile_image_url".equals(key.trim())) {
MainActivity activity = (MainActivity) MainActivity.this;
ImageLoader.getInstance().displayImage(
info.get(key).toString(),
// QQ头像
imageView,
imageLoader
.getDisplayImageOptions());
;
// QQ用户名
} else if ("screen_name".equals(key.trim())) {
textView.setText(info.get(key).toString());
}
}
}
}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
MainActivity.this.getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
package com.example.ym;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import android.app.Application;
import android.graphics.Bitmap;
public class imageLoader extends Application {
@Override
public void onCreate() {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext()).memoryCacheExtraOptions(480, 800)
// default = device screen dimensions 内存缓存文件的最大长宽
.diskCacheExtraOptions(480, 800, null)
// 本地缓存的详细信息(缓存的最大长宽),最好不要设置这个
.threadPoolSize(3)
// default 线程池内加载的数量
.threadPriority(Thread.NORM_PRIORITY - 2)
// default 设置当前线程的优先级
.tasksProcessingOrder(QueueProcessingType.FIFO)
// default
.denyCacheImageMultipleSizesInMemory()
.memoryCache(new LruMemoryCache(2 * 1024 * 1024)) // 可以通过自己的内存缓存实现
.memoryCacheSize(2 * 1024 * 1024) // 内存缓存的最大值
.memoryCacheSizePercentage(13) // default
// .diskCache(new UnlimitedDiscCache(cacheDir)) // default
// 可以自定义缓存路径
.diskCacheSize(50 * 1024 * 1024) // 50 Mb sd卡(本地)缓存的最大值
.diskCacheFileCount(100) // 可以缓存的文件数量
// default为使用HASHCODE对UIL进行加密命名, 还可以用MD5(new
// Md5FileNameGenerator())加密
.diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
// .imageDownloader(new BaseImageDownloader(context)) // default
.defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
// .discCache(new LimitedAgeDiscCache(cacheDir, 7 * 24 * 60 *
// 60))// 自定义缓存路径,7天后自动清除缓存
.writeDebugLogs() // 打印debug log
.build(); // 开始构建
// 初始化ImagerLoader
ImageLoader.getInstance().init(config);
super.onCreate();
}
public static DisplayImageOptions getDisplayImageOptions() {
DisplayImageOptions options = new DisplayImageOptions.Builder()
.cacheInMemory(true) // default
.cacheOnDisk(true) // default
.considerExifParams(false) // default
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
.bitmapConfig(Bitmap.Config.RGB_565) // default
.build();
return options;
}
}
android:name="UMENG_APPKEY"
android:value="56e8cdc267e58ea977000286" />
android:name="com.umeng.socialize.view.ShareActivity"
android:configChanges="orientation|keyboard"
android:launchMode="singleTask"
android:noHistory="true"
android:theme="@style/Theme.UMDialog"
android:windowSoftInputMode="stateVisible|adjustResize" />
android:name="com.tencent.tauth.AuthActivity"
android:launchMode="singleTask"
android:noHistory="true" >
android:name="com.tencent.connect.common.AssistActivity"
android:screenOrientation="portrait" >
android:name=".wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />