Skip to content

Commit ca74f8d

Browse files
committed
分享基本完成
1 parent 737fe1a commit ca74f8d

9 files changed

Lines changed: 186 additions & 55 deletions

File tree

.swp

-48 KB
Binary file not shown.

app/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ apply plugin: 'com.android.application'
22
apply plugin: 'android-apt'
33

44
android {
5-
compileSdkVersion 22
6-
buildToolsVersion "22.0.1"
5+
compileSdkVersion 23
6+
useLibrary 'org.apache.http.legacy' // 因为 sdk23 去掉了 apache
7+
buildToolsVersion "23.0.1"
78

89
defaultConfig {
910
applicationId "net.coding.program"
1011
renderscriptTargetApi 19
1112
multiDexEnabled true
12-
1313
}
1414

1515
buildTypes {
@@ -26,6 +26,7 @@ dependencies {
2626
compile 'com.android.support:appcompat-v7:21.0.+'
2727
compile 'com.skyfishjy.ripplebackground:library:1.0.1'
2828
compile 'com.loopj.android:android-async-http:1.4.6'
29+
// compile 'com.loopj.android:android-async-http:1.9.31'
2930
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
3031
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
3132
compile 'se.emilsjolander:stickylistheaders:2.7.0'

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@
6969
android:largeHeap="true"
7070
android:theme="@style/ActionbarNoIcon" >
7171

72+
<!-- ###################注册SDK使用的Activity###################### -->
73+
<!--分享编辑页-->
74+
<activity
75+
android:name="com.umeng.socialize.view.ShareActivity"
76+
android:configChanges="orientation|keyboard"
77+
android:launchMode="singleTask"
78+
android:noHistory="true"
79+
android:theme="@style/Theme.UMDialog"
80+
android:windowSoftInputMode="stateVisible|adjustResize" />
7281
<!-- ############ QQ空间和QQ SSO授权的Activity注册 ############ -->
7382
<activity
7483
android:name="com.tencent.tauth.AuthActivity"

app/src/main/java/net/coding/program/AllThirdKeys.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
/**
44
* Created by chenchao on 15/9/7.
5+
* 第三方的 key,需要自己申请添加
56
*/
67
public class AllThirdKeys {
78

89
// 分享到qq的key
9-
public static final String APP_ID = "";
10-
public static final String APP_KEY = "";
10+
public static final String QQ_APP_ID = "";
11+
public static final String QQ_APP_KEY = "";
12+
13+
// 分享到weixin的key
14+
public static final String WX_APP_ID = "";
15+
public static final String WX_APP_KEY = "";
1116

1217
// 百度地图key
1318
public static final String geotable = "";
1419
public static final String ak = "";
1520
public static final String sk = "";
21+
1622
}

app/src/main/java/net/coding/program/common/AmrUtils.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,7 @@ public class AmrUtils {
1313

1414
/**
1515
* Created by Carlos2015 on 2015/8/28.
16-
* <p/>
1716
* converts 16 bit PCM to AMR
18-
*
19-
* @param inputStream
20-
* @return
21-
* @throws ClassNotFoundException
22-
* @throws NoSuchMethodException
23-
* @throws InvocationTargetException
24-
* @throws IllegalAccessException
25-
* @throws InstantiationException
26-
* @throws IllegalArgumentException
27-
* @throws IOException
2817
*/
2918
public static byte[] convertToAmr(InputStream inputStream, boolean isAddAmrFileHead) throws ClassNotFoundException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, IOException {
3019
Class<?> cls = Class.forName("android.media.AmrInputStream");
@@ -51,7 +40,7 @@ public static byte[] convertToAmr(InputStream inputStream, boolean isAddAmrFileH
5140
}
5241
Method close = cls.getMethod("close");
5342
close.setAccessible(true);
54-
close.invoke(amrInputStream, null);
43+
close.invoke(amrInputStream);
5544
buf = bos.toByteArray();
5645
bos.close();
5746
return buf;

app/src/main/java/net/coding/program/maopao/share/CustomShareBoard.java

Lines changed: 98 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,31 @@
99
import android.graphics.drawable.BitmapDrawable;
1010
import android.os.Parcel;
1111
import android.os.Parcelable;
12+
import android.util.Log;
1213
import android.view.LayoutInflater;
1314
import android.view.View;
1415
import android.view.View.OnClickListener;
1516
import android.view.ViewGroup.LayoutParams;
1617
import android.widget.PopupWindow;
18+
import android.widget.Toast;
1719

1820
import com.umeng.socialize.bean.SHARE_MEDIA;
1921
import com.umeng.socialize.bean.SocializeEntity;
22+
import com.umeng.socialize.bean.StatusCode;
23+
import com.umeng.socialize.controller.UMEvernoteHandler;
2024
import com.umeng.socialize.controller.UMServiceFactory;
2125
import com.umeng.socialize.controller.UMSocialService;
2226
import com.umeng.socialize.controller.listener.SocializeListeners;
27+
import com.umeng.socialize.media.SinaShareContent;
2328
import com.umeng.socialize.media.UMImage;
2429
import com.umeng.socialize.sso.QZoneSsoHandler;
30+
import com.umeng.socialize.sso.SinaSsoHandler;
2531
import com.umeng.socialize.sso.UMQQSsoHandler;
32+
import com.umeng.socialize.weixin.controller.UMWXHandler;
2633

2734
import net.coding.program.AllThirdKeys;
2835
import net.coding.program.R;
36+
import net.coding.program.common.Global;
2937

3038
/**
3139
*
@@ -45,19 +53,52 @@ public CustomShareBoard(Activity activity, ShareData shareData) {
4553
}
4654

4755
private void addQQ() {
48-
UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(mActivity, AllThirdKeys.APP_ID, AllThirdKeys.APP_KEY);
56+
UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(mActivity, AllThirdKeys.QQ_APP_ID, AllThirdKeys.QQ_APP_KEY);
4957
qqSsoHandler.setTargetUrl(mShareData.link);
5058
qqSsoHandler.setTitle(mShareData.name);
5159
qqSsoHandler.addToSocialSDK();
5260
}
5361

62+
private void addWX() {
63+
UMWXHandler wxHandler = new UMWXHandler(mActivity, AllThirdKeys.WX_APP_ID, AllThirdKeys.WX_APP_KEY);
64+
wxHandler.setTargetUrl(mShareData.link);
65+
wxHandler.setTitle(mShareData.name);
66+
wxHandler.addToSocialSDK();
67+
}
68+
69+
private void addWXCircle() {
70+
UMWXHandler wxCircleHandler = new UMWXHandler(mActivity, AllThirdKeys.WX_APP_ID, AllThirdKeys.WX_APP_KEY);
71+
wxCircleHandler.setTargetUrl(mShareData.link);
72+
wxCircleHandler.setTitle(mShareData.name);
73+
wxCircleHandler.setToCircle(true);
74+
wxCircleHandler.addToSocialSDK();
75+
}
76+
5477
private void addQQZone() {
5578
// 添加QZone平台
56-
QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(mActivity, AllThirdKeys.APP_ID, AllThirdKeys.APP_KEY);
79+
QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(mActivity, AllThirdKeys.QQ_APP_ID, AllThirdKeys.QQ_APP_KEY);
5780
qZoneSsoHandler.setTargetUrl(mShareData.link);
5881
qZoneSsoHandler.addToSocialSDK();
5982
}
6083

84+
private void addSinaWeibo() {
85+
// SinaSsoHandler sinaSsoHandler = new SinaSsoHandler();
86+
// sinaSsoHandler.setTargetUrl(mShareData.link);
87+
// sinaSsoHandler.addToSocialSDK();
88+
mController.getConfig().setSsoHandler(new SinaSsoHandler());
89+
}
90+
91+
private void addEvernote() {
92+
UMEvernoteHandler evernoteHandler = new UMEvernoteHandler(mActivity);
93+
evernoteHandler.addToSocialSDK();
94+
95+
// 设置evernote的分享内容
96+
// EvernoteShareContent shareContent = new EvernoteShareContent(
97+
// "来自友盟社会化组件(SDK)让移动应用快速整合社交分享功能-EverNote。http://www.umeng.com/social");
98+
// shareContent.setShareMedia(new UMImage(getActivity(), R.drawable.test));
99+
// mController.setShareMedia(shareContent);
100+
}
101+
61102
public static class ShareData implements Parcelable {
62103
public String name = "";
63104
public String link = "";
@@ -127,10 +168,20 @@ public ShareData[] newArray(int size) {
127168
@SuppressWarnings("deprecation")
128169
private void initView(Context context) {
129170
View rootView = LayoutInflater.from(context).inflate(R.layout.share_custom_board, null);
130-
rootView.findViewById(R.id.wechat).setOnClickListener(this);
131-
rootView.findViewById(R.id.wechat_circle).setOnClickListener(this);
132-
rootView.findViewById(R.id.qq).setOnClickListener(this);
133-
rootView.findViewById(R.id.qzone).setOnClickListener(this);
171+
final int[] buttns = new int[]{
172+
R.id.wechat,
173+
R.id.wechat_circle,
174+
R.id.qq,
175+
R.id.qzone,
176+
R.id.sinaWeibo,
177+
R.id.evernote,
178+
R.id.codingFriend,
179+
R.id.linkCopy
180+
};
181+
for (int id : buttns) {
182+
rootView.findViewById(id).setOnClickListener(this);
183+
}
184+
134185
setContentView(rootView);
135186
setWidth(LayoutParams.MATCH_PARENT);
136187
setHeight(LayoutParams.WRAP_CONTENT);
@@ -144,9 +195,11 @@ public void onClick(View v) {
144195
int id = v.getId();
145196
switch (id) {
146197
case R.id.wechat:
198+
addWX();
147199
performShare(SHARE_MEDIA.WEIXIN);
148200
break;
149201
case R.id.wechat_circle:
202+
addWXCircle();
150203
performShare(SHARE_MEDIA.WEIXIN_CIRCLE);
151204
break;
152205
case R.id.qq:
@@ -157,6 +210,25 @@ public void onClick(View v) {
157210
addQQZone();
158211
performShare(SHARE_MEDIA.QZONE);
159212
break;
213+
214+
case R.id.sinaWeibo:
215+
addSinaWeibo();
216+
performShare(SHARE_MEDIA.SINA);
217+
break;
218+
219+
case R.id.evernote:
220+
addEvernote();
221+
performShare(SHARE_MEDIA.EVERNOTE);
222+
break;
223+
224+
case R.id.codingFriend:
225+
break;
226+
227+
case R.id.linkCopy:
228+
Global.copy(mActivity, mShareData.link);
229+
Toast.makeText(mActivity, "链接已复制 " + mShareData.link, Toast.LENGTH_SHORT).show();
230+
break;
231+
160232
default:
161233
break;
162234
}
@@ -169,6 +241,17 @@ private void performShare(SHARE_MEDIA platform) {
169241
mController.setShareImage(umImage);
170242
}
171243

244+
if (platform == SHARE_MEDIA.SINA) {
245+
SinaShareContent sinaContent = new SinaShareContent();
246+
sinaContent.setShareContent(mShareData.des + " " + mShareData.link);
247+
sinaContent.setTargetUrl(mShareData.link);
248+
UMImage umImage = new UMImage(mActivity, mShareData.img);
249+
sinaContent.setShareImage(umImage);
250+
sinaContent.setTitle(mShareData.name);
251+
sinaContent.setAppWebSite(mShareData.link);
252+
mController.setShareMedia(sinaContent);
253+
}
254+
172255
mController.postShare(mActivity, platform, new SocializeListeners.SnsPostListener() {
173256

174257
@Override
@@ -178,14 +261,15 @@ public void onStart() {
178261

179262
@Override
180263
public void onComplete(SHARE_MEDIA platform, int eCode, SocializeEntity entity) {
181-
// String showText = platform.toString();
182-
// if (eCode == StatusCode.ST_CODE_SUCCESSED) {
183-
// showText += "平台分享成功";
184-
// } else {
185-
// showText += "平台分享失败";
186-
// }
187-
// Toast.makeText(mActivity, showText, Toast.LENGTH_SHORT).show();
188-
// dismiss();
264+
String showText = platform.toString();
265+
if (eCode == StatusCode.ST_CODE_SUCCESSED) {
266+
showText += "平台分享成功";
267+
} else {
268+
showText += "平台分享失败";
269+
}
270+
Log.d("", "umengshare " + eCode);
271+
Toast.makeText(mActivity, showText, Toast.LENGTH_SHORT).show();
272+
dismiss();
189273
}
190274
}
191275

app/src/main/java/net/coding/program/user/AddFollowActivity.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public class AddFollowActivity extends BackActivity implements Handler.Callback
4444
public static final int RESULT_USER_DETAIL = 1000;
4545

4646
String HOST_SEARCH_USER = Global.HOST_API + "/user/search?key=%s";
47-
4847
String urlAddUser = "";
49-
5048
ArrayList<UserObject> mData = new ArrayList<>();
5149

5250
boolean mNeedUpdate = false;

app/src/main/res/layout/share_custom_board.xml

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
5+
android:orientation="vertical"
56
android:background="#d3d3d3" >
67

7-
<TextView
8-
android:id="@+id/share_text"
9-
android:layout_width="wrap_content"
10-
android:layout_height="wrap_content"
11-
android:layout_centerHorizontal="true"
12-
android:layout_marginBottom="6dp"
13-
android:layout_marginTop="16dp"
14-
android:text="分享"
15-
android:textSize="14sp" />
16-
17-
<!--<View-->
18-
<!--android:id="@+id/divider_line"-->
19-
<!--android:layout_width="match_parent"-->
20-
<!--android:layout_height="1dp"-->
21-
<!--android:layout_below="@id/share_text"-->
22-
<!--android:background="@drawable/divider" />-->
23-
248
<LinearLayout
259
android:layout_width="match_parent"
2610
android:layout_height="70dp"
@@ -81,4 +65,64 @@
8165
</RelativeLayout>
8266
</LinearLayout>
8367

84-
</RelativeLayout>
68+
<LinearLayout
69+
android:layout_width="match_parent"
70+
android:layout_height="70dp"
71+
android:orientation="horizontal"
72+
android:layout_marginTop="12dp"
73+
android:layoutAnimation="@anim/share_layout_animation" >
74+
75+
<RelativeLayout
76+
android:layout_width="0dp"
77+
android:layout_height="wrap_content"
78+
android:layout_weight="1" >
79+
80+
<ImageButton
81+
android:id="@+id/sinaWeibo"
82+
android:layout_width="50dp"
83+
android:layout_height="50dp"
84+
android:layout_centerInParent="true"
85+
android:background="@drawable/umeng_socialize_sina_on" />
86+
</RelativeLayout>
87+
88+
<RelativeLayout
89+
android:layout_width="0dp"
90+
android:layout_height="wrap_content"
91+
android:layout_weight="1" >
92+
93+
<ImageButton
94+
android:id="@+id/evernote"
95+
android:layout_width="50dp"
96+
android:layout_height="50dp"
97+
android:background="@drawable/umeng_socialize_wxcircle"
98+
android:layout_centerInParent="true" />
99+
</RelativeLayout>
100+
101+
<RelativeLayout
102+
android:layout_width="0dp"
103+
android:layout_height="wrap_content"
104+
android:layout_weight="1" >
105+
106+
<ImageButton
107+
android:id="@+id/codingFriend"
108+
android:layout_width="50dp"
109+
android:layout_height="50dp"
110+
android:background="@drawable/umeng_socialize_qq_on"
111+
android:layout_centerInParent="true" />
112+
</RelativeLayout>
113+
114+
<RelativeLayout
115+
android:layout_width="0dp"
116+
android:layout_height="wrap_content"
117+
android:layout_weight="1" >
118+
119+
<ImageButton
120+
android:id="@+id/linkCopy"
121+
android:layout_width="50dp"
122+
android:layout_height="50dp"
123+
android:background="@drawable/umeng_socialize_qzone_on"
124+
android:layout_centerInParent="true" />
125+
</RelativeLayout>
126+
</LinearLayout>
127+
128+
</LinearLayout>

0 commit comments

Comments
 (0)