领取1888钻石.最近坐骑礼包地址:http luding1888.net://p.t.qq.com/longweibo/in

/ sinaandtencentweibo
项目语言:JAVA
权限:read-only(如需更高权限请先加入项目)
sinaandtencentweibo/
Index: GeneralDataShowActivity.java
===================================================================
--- GeneralDataShowActivity.java (revision 0)
+++ GeneralDataShowActivity.java (revision 7)
@@ -0,0 +1,30 @@
+package com.tencent.weibo.
+import android.app.A
+import android.content.I
+import android.os.B
+import android.text.method.ScrollingMovementM
+import android.util.L
+import android.widget.TextV
+ * 展示获取访问常用接口返回json数据
+public class GeneralDataShowActivity extends Activity{
+ private TextV
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
tv = new TextView(this);
Intent i = getIntent();
Bundle bundle = i.getExtras();
String data
= bundle.getString(&data&);
tv.setText(data);
//Log.i(&data&,data);
//tv.setScrollbarFadingEnabled(true);
tv.setMovementMethod(ScrollingMovementMethod.getInstance());
setContentView(tv);
Index: LetterListView.java
===================================================================
--- LetterListView.java (revision 0)
+++ LetterListView.java (revision 7)
@@ -0,0 +1,133 @@
+package com.tencent.weibo.
+import java.util.L
+import android.content.C
+import android.graphics.C
+import android.graphics.C
+import android.graphics.P
+import android.graphics.T
+import android.util.AttributeS
+import android.util.L
+import android.view.MotionE
+import android.view.V
+ * 自定义控件显示好友昵称首字母列表
+public class LetterListView extends View {
+ OnTouchingLetterChangedListener onTouchingLetterChangedL
+ List&String&
+ int choose = -1;
+ Paint paint = new Paint();
+ boolean showBkg =
+ public LetterListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
+ public LetterListView(Context context, AttributeSet attrs) {
super(context, attrs);
+ public LetterListView(Context context,List&String& b) {
super(context);
+ * 设置好友昵称首字母列表数据
+ public void setB(List&String& b) {
invalidate();
+ @Override
+ protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (showBkg) {
canvas.drawColor(Color.parseColor(&#&));
int height = getHeight();
int width = getWidth()-30;
if (b.size()&0) {
int singleHeight = height / b.size();
for (int i = 0; i & b.size(); i++) {
paint.setColor(Color.parseColor(&#2796c4&));
paint.setTextSize(17);
paint.setTypeface(Typeface.DEFAULT_BOLD);
paint.setAntiAlias(true);
if (i == choose) {
paint.setColor(Color.GRAY);
paint.setFakeBoldText(true);
float xPos = width / 2 - paint.measureText(b.get(i)) / 2;
float yPos = singleHeight * i + singleH
canvas.drawText(b.get(i).toUpperCase(), xPos, yPos, paint);
paint.reset();
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent event) {
final int action = event.getAction();
final float y = event.getY();
final int oldChoose =
final OnTouchingLetterChangedListener listener = onTouchingLetterChangedL
final int c = (int) (y / getHeight() * b.size());
switch (action) {
case MotionEvent.ACTION_DOWN:
if (oldChoose != c && listener != null) {
if (c &= 0 && c & b.size()) {
listener.onTouchingLetterChanged(c);
invalidate();
case MotionEvent.ACTION_MOVE:
if (oldChoose != c && listener != null) {
if (c &=0 && c & b.size()) {
listener.onTouchingLetterChanged(c);
invalidate();
case MotionEvent.ACTION_UP:
choose = -1;
invalidate();
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
+ public void setOnTouchingLetterChangedListener(
OnTouchingLetterChangedListener onTouchingLetterChangedListener) {
this.onTouchingLetterChangedListener = onTouchingLetterChangedL
* 点击好友昵称首字母列表监听接口
+ public interface OnTouchingLetterChangedListener {
public void onTouchingLetterChanged(int c);
Index: ConversationActivity.java
===================================================================
--- ConversationActivity.java (revision 0)
+++ ConversationActivity.java (revision 7)
@@ -0,0 +1,224 @@
+package com.tencent.weibo.
+import java.util.ArrayL
+import java.util.L
+import org.json.JSONA
+import org.json.JSONE
+import org.json.JSONO
+import com.tencent.weibo.sdk.android.api.PublishWeiBoAPI;
+import com.tencent.weibo.sdk.android.api.adapter.ConversationA
+import com.tencent.weibo.sdk.android.api.util.BackGroudS
+import com.tencent.weibo.sdk.android.api.util.U
+import com.tencent.weibo.sdk.android.model.AccountM
+import com.tencent.weibo.sdk.android.model.ModelR
+import com.tencent.weibo.sdk.android.network.HttpC
+import android.app.A
+import android.app.ProgressD
+import android.content.I
+import android.graphics.C
+import android.os.B
+import android.text.E
+import android.text.TextW
+import android.util.L
+import android.view.G
+import android.view.V
+import android.view.View.OnClickL
+import android.view.ViewG
+import android.view.W
+import android.widget.AdapterV
+import android.widget.AdapterView.OnItemClickL
+import android.widget.B
+import android.widget.EditT
+import android.widget.LinearL
+import android.widget.ListV
+import android.widget.T
+ * 话题类表组件
+public class ConversationActivity extends Activity implements HttpCallback{
+ private ListView listV
+ private List&String&
+ private EditText editT
+ private ConversationA
+ private ProgressD
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
LinearLayout layout=(LinearLayout) initview();
setContentView(layout);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView&?& arg0, View arg1, int arg2,
long arg3) {
Toast.makeText(ConversationActivity.this, arg2+&&, 100).show();
if (dialog==null) {
dialog=new ProgressDialog(ConversationActivity.this);
dialog.setMessage(&请稍后...&);
dialog.setCancelable(false);
dialog.show();
new PublishWeiBoAPI(new AccountModel(Util.getSharePersistent(getApplicationContext(), &ACCESS_TOKEN&))).recent_used(ConversationActivity.this, ConversationActivity.this, null, 15, 1, 0);
* 初始化界面使用控件,并设置相应监听
+ private View initview(){
LinearLayout viewroot=new LinearLayout(ConversationActivity.this);
LinearLayout.LayoutParams params_viewroot=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
viewroot.setLayoutParams(params_viewroot);
viewroot.setOrientation(LinearLayout.VERTICAL);
LinearLayout layout_title=new LinearLayout(ConversationActivity.this);
LinearLayout.LayoutParams params_title=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layout_title.setLayoutParams(params_title);
layout_title.setOrientation(LinearLayout.HORIZONTAL);
layout_title.setBackgroundDrawable(BackGroudSeletor.getdrawble(&up_bg2x&, ConversationActivity.this));
layout_title.setPadding(20, 0, 20, 0);
layout_title.setGravity(Gravity.CENTER_VERTICAL);
LinearLayout layout_editext=new LinearLayout(ConversationActivity.this);
LinearLayout.LayoutParams params_editext=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1);
layout_editext.setLayoutParams(params_editext);
layout_editext.setPadding(0, 0, 12, 0);
editText=new EditText(ConversationActivity.this);
editText.setSingleLine(true);
editText.setLines(1);
editText.setTextSize(18f);
editText.setHint(&搜索话题&);
editText.setPadding(20, 0, 10, 0);
editText.setBackgroundDrawable(BackGroudSeletor.getdrawble(&huati_input2x&, ConversationActivity.this));
editText.setCompoundDrawablesWithIntrinsicBounds(BackGroudSeletor.getdrawble(&huati_icon_hover2x&, ConversationActivity.this), null, null, null);
editText.setLayoutParams(params_viewroot);
Button button_esc=new Button(ConversationActivity.this);
String string_esc[] = { &sent_btn_22x&, &sent_btn_hover& };
button_esc.setBackgroundDrawable(BackGroudSeletor.createBgByImageIds(string_esc, ConversationActivity.this));
button_esc.setTextColor(Color.WHITE);
button_esc.setText(&取消&);
layout_editext.addView(editText);
layout_title.addView(layout_editext);
layout_title.addView(button_esc);
viewroot.addView(layout_title);
LinearLayout layout_list=new LinearLayout(ConversationActivity.this);
LinearLayout.LayoutParams params_list=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT,1);
layout_list.setLayoutParams(params_list);
listView=new ListView(ConversationActivity.this);
listView.setDivider(BackGroudSeletor.getdrawble(&table_lie_&,
ConversationActivity.this));
listView.setLayoutParams(params_viewroot);
editText.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
public void afterTextChanged(Editable s) {
List&String& lists=new ArrayList&String&();
for (int i = 0; i & list.size(); i++) {
if (list.get(i).contains(s.toString())) {
lists.add(list.get(i));
adapter.setCvlist(lists);
adapter.notifyDataSetChanged();
click(lists);
LinearLayout layout_foot=new LinearLayout(ConversationActivity.this);
Button button=new Button(ConversationActivity.this);
layout_foot.setGravity(Gravity.CENTER);
button.setLayoutParams(params_title);
button.setText(&abc&);
button.setTextColor(Color.BLACK);
button_esc.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
layout_foot.addView(button);
//listView.addFooterView(layout_foot);
layout_list.addView(listView);
viewroot.addView(layout_list);
* 解析获取的话题数据
+ private List&String& initData(JSONObject jsonObject){
List&String& list=new ArrayList&String&();
JSONArray array=jsonObject.getJSONObject(&data&).getJSONArray(&info&);
for (int i = 0; i & array.length(); i++) {
list.add(&#&+array.getJSONObject(i).getString(&text&)+&#&);
+ } catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
* 设置话题列表每条的点击事件
+ private void click(final List&String& li){
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView&?& arg0, View arg1, int arg2,
long arg3) {
Intent intent =new Intent();
intent.setClass(ConversationActivity.this, PublishActivity.class);
intent.putExtra(&conversation&, li.get(arg2));
setResult(RESULT_OK, intent);
+@Override
+protected void onStop() {
+ super.onStop();
+ if (dialog!=null&& dialog.isShowing()) {
dialog.dismiss();
+@Override
+public void onResult(Object object) {
+ if (dialog!=null&& dialog.isShowing()) {
dialog.dismiss();
+ if (object!=null&&((ModelResult)object).isSuccess()) {
Log.d(&发送成功&, ((ModelResult)object).getObj().toString());
JSONObject jsonObject=(JSONObject) ((ModelResult) object).getObj();
list=initData(jsonObject);
adapter=new ConversationAdapter(ConversationActivity.this, list);
listView.setAdapter(adapter);
click(list);
Index: GeneralInterfaceActivity.java
===================================================================
--- GeneralInterfaceActivity.java (revision 0)
+++ GeneralInterfaceActivity.java (revision 7)
@@ -0,0 +1,372 @@
+package com.tencent.weibo.
+import java.io.F
+import com.tencent.weibo.sdk.android.api.FriendAPI;
+import com.tencent.weibo.sdk.android.api.LbsAPI;
+import com.tencent.weibo.sdk.android.api.TimeLineAPI;
+import com.tencent.weibo.sdk.android.api.UserAPI;
+import com.tencent.weibo.sdk.android.api.WeiboAPI;
+import com.tencent.weibo.sdk.android.api.util.U
+import com.tencent.weibo.sdk.android.model.AccountM
+import com.tencent.weibo.sdk.android.model.BaseVO;
+import com.tencent.weibo.sdk.android.model.ModelR
+import com.tencent.weibo.sdk.android.network.HttpC
+import android.app.A
+import android.content.C
+import android.content.I
+import android.graphics.B
+import android.graphics.BitmapF
+import android.location.L
+import android.os.B
+import android.os.E
+import android.os.L
+import android.os.MessageQueue.IdleH
+import android.util.L
+import android.view.G
+import android.view.V
+import android.widget.B
+import android.widget.LinearL
+import android.widget.PopupW
+import android.widget.ProgressB
+import android.widget.ScrollV
+import android.widget.TableL
+import android.widget.TableR
+import android.widget.T
常用数据接口访问实例组件
+public class GeneralInterfaceActivity extends Activity implements View.OnClickListener {
+ private Button homeTimeL// 主人页时间线
+ private Button userTimeL// 客人页时间线
+ private Button addW// 普通发表接口
+ private Button addP// 发表带图微博
+ private Button addPicU// 发表带网络图片微博
+ private Button htTimeL// 话题时间线
+ private Button userI// 获取用户信息
+ private Button userOtherI// 获取他人信息
+ private Button userI// 获取一批人信息
+ private Button friendA// 收听某个用户
+ private Button friendIdolL// 获取偶像列表
+ private Button friendFunsL// 获取粉丝列表
+ private Button friendMutualL// 获取互听列表
+ private Button friendC// 验证好友关系
+ private Button tReL// 转播获取转播列表
+ private Button friendGetIntimateF// 获取最近联系人
+ private Button lbsGetAroundP// 获取附近的人
+ private Button lbsGetAroundN// 获取身边最新的微博
+ private Button deviceS// 终端状况
+ private Button errorR// 错误反馈
+ private String accessT// 用户访问令牌
+ private FriendAPI friendAPI;//好友相关API
+ private TimeLineAPI timeLineAPI;//时间线API
+ private WeiboAPI weiboAPI;//微博相关API
+ private UserAPI userAPI;//帐户相关API
+ private LbsAPI lbsAPI;//LBS相关API
+ private HttpCallback mCallB//回调函数
+ private PopupWindow loadingWindow =
+ private ProgressBar progressBar =
+ private ScrollView scrollView =
+ private Context context=
+ private String requestFormat = &json&;
+ private double longitude = 0d;
+ private double latitude = 0d;
+ private Location mL
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
accessToken = Util.getSharePersistent(getApplicationContext(), &ACCESS_TOKEN&);
if (accessToken == null || &&.equals(accessToken)) {
Toast.makeText(GeneralInterfaceActivity.this, &请先授权&, Toast.LENGTH_SHORT).show();
this.finish();
AccountModel account = new AccountModel(accessToken);
friendAPI = new FriendAPI(account);
timeLineAPI = new TimeLineAPI(account);
weiboAPI = new WeiboAPI(account);
userAPI = new UserAPI(account);
lbsAPI = new LbsAPI(account);
mCallBack = new HttpCallback() {
public void onResult(Object object) {
ModelResult result = (ModelResult)
if(loadingWindow!=null && loadingWindow.isShowing()){
loadingWindow.dismiss();
if(result!=null){
System.out.println(&返回的结果是:& + result.getObj().toString());
Toast.makeText(GeneralInterfaceActivity.this,&成功&, Toast.LENGTH_SHORT).show();
Intent i = new Intent(GeneralInterfaceActivity.this,GeneralDataShowActivity.class);
i.putExtra(&data&, result.getObj().toString());
startActivity(i);
Toast.makeText(GeneralInterfaceActivity.this,&发生异常&, Toast.LENGTH_SHORT).show();
progressBar = new ProgressBar(this);
loadingWindow = new PopupWindow(progressBar,100,100);
context = getApplicationContext();
mLocation = Util.getLocation(context);
if(mLocation !=null){
longitude = mLocation.getLongitude();
latitude = mLocation.getLatitude();
this.initInterface();
* 初始化界面使用控件
+ public void initInterface() {
scrollView = new ScrollView(this);
TableLayout table = new TableLayout(this);
TableLayout.LayoutParams paramsTable = new TableLayout.LayoutParams(
TableLayout.LayoutParams.FILL_PARENT,
TableLayout.LayoutParams.FILL_PARENT);
table.setLayoutParams(paramsTable);
TableRow row1 = new TableRow(this);
homeTimeLine = new Button(this);
homeTimeLine.setText(&主人页时间线&);
homeTimeLine.setId(1001);
homeTimeLine.setOnClickListener(this);
row1.addView(homeTimeLine);
userTimeLine = new Button(this);
userTimeLine.setText(&客人页时间线&);
userTimeLine.setId(1002);
userTimeLine.setOnClickListener(this);
row1.addView(userTimeLine);
table.addView(row1);
TableRow row2 = new TableRow(this);
addWeibo = new Button(this);
addWeibo.setText(&普通发表接口&);
addWeibo.setId(1003);
addWeibo.setOnClickListener(this);
row2.addView(addWeibo);
addPic = new Button(this);
addPic.setText(&发表带图微博&);
addPic.setId(1004);
addPic.setOnClickListener(this);
row2.addView(addPic);
table.addView(row2);
TableRow row3 = new TableRow(this);
addPicUrl = new Button(this);
addPicUrl.setText(&发表带网络图片微博&);
addPicUrl.setId(1005);
addPicUrl.setOnClickListener(this);
row3.addView(addPicUrl);
htTimeLine = new Button(this);
htTimeLine.setText(&话题时间线&);
htTimeLine.setId(1006);
htTimeLine.setOnClickListener(this);
row3.addView(htTimeLine);
table.addView(row3);
TableRow row4 = new TableRow(this);
userInfo = new Button(this);
userInfo.setText(&获取用户信息&);
userInfo.setId(1007);
userInfo.setOnClickListener(this);
row4.addView(userInfo);
userOtherInfo = new Button(this);
userOtherInfo.setText(&获取他人信息&);
userOtherInfo.setId(1008);
userOtherInfo.setOnClickListener(this);
row4.addView(userOtherInfo);
table.addView(row4);
TableRow row5 = new TableRow(this);
userInfos = new Button(this);
userInfos.setText(&获取一批人信息&);
userInfos.setId(1009);
userInfos.setOnClickListener(this);
row5.addView(userInfos);
friendAdd = new Button(this);
friendAdd.setText(&收听某个用户&);
friendAdd.setId(1010);
friendAdd.setOnClickListener(this);
row5.addView(friendAdd);
table.addView(row5);
TableRow row6 = new TableRow(this);
friendIdolList = new Button(this);
friendIdolList.setText(&获取偶像列表&);
friendIdolList.setId(1011);
friendIdolList.setOnClickListener(this);
row6.addView(friendIdolList);
friendFunsList = new Button(this);
friendFunsList.setText(&获取粉丝列表&);
friendFunsList.setId(1012);
friendFunsList.setOnClickListener(this);
row6.addView(friendFunsList);
table.addView(row6);
TableRow row7 = new TableRow(this);
friendMutualList = new Button(this);
friendMutualList.setText(&获取互听列表&);
friendMutualList.setId(1013);
friendMutualList.setOnClickListener(this);
row7.addView(friendMutualList);
friendCheck = new Button(this);
friendCheck.setText(&验证好友关系&);
friendCheck.setId(1014);
friendCheck.setOnClickListener(this);
row7.addView(friendCheck);
table.addView(row7);
TableRow row8 = new TableRow(this);
tReList = new Button(this);
tReList.setText(&转播获取转播列表&);
tReList.setId(1015);
tReList.setOnClickListener(this);
row8.addView(tReList);
friendGetIntimateFriend = new Button(this);
friendGetIntimateFriend.setText(&获取最近联系人&);
friendGetIntimateFriend.setId(1016);
friendGetIntimateFriend.setOnClickListener(this);
row8.addView(friendGetIntimateFriend);
table.addView(row8);
TableRow row9 = new TableRow(this);
lbsGetAroundPeople = new Button(this);
lbsGetAroundPeople.setText(&获取附近的人&);
lbsGetAroundPeople.setId(1017);
lbsGetAroundPeople.setOnClickListener(this);
row9.addView(lbsGetAroundPeople);
lbsGetAroundNew = new Button(this);
lbsGetAroundNew.setText(&获取身边最新的微博&);
lbsGetAroundNew.setId(1018);
lbsGetAroundNew.setOnClickListener(this);
row9.addView(lbsGetAroundNew);
table.addView(row9);
TableRow row10 = new TableRow(this);
deviceStatus = new Button(this);
deviceStatus.setText(&终端状况&);
deviceStatus.setId(1019);
row10.addView(deviceStatus);
errorReport = new Button(this);
errorReport.setText(&错误反馈&);
errorReport.setId(1020);
row10.addView(errorReport);
table.addView(row10);
scrollView.addView(table);
this.setContentView(scrollView);
+ @Override
+ public void onClick(View v) {
Looper.myQueue().addIdleHandler(new IdleHandler(){
public boolean queueIdle() {
loadingWindow.showAtLocation(scrollView, Gravity.CENTER, 0, 80);
switch (v.getId()) {
case 1001:
timeLineAPI.getHomeTimeLine(context, 0, 0, 30, 0, 0, requestFormat, mCallBack, null, BaseVO.TYPE_JSON);
case 1002:
Log.e(&generalinterface&, &开始请求&);
timeLineAPI.getWeiboByName(context, 0, 0, 30, 0, &sc-travel&, 0, 0, mCallBack, null, BaseVO.TYPE_JSON);
timeLineAPI.getUserTimeLine(context, 0, 0, 30, 0, &api_weibo&, null, 0, 0, requestFormat, mCallBack, null, BaseVO.TYPE_JSON);
case 1003:
weiboAPI.addWeibo(context, &hello world !&, requestFormat, longitude, latitude, 0, 0, mCallBack, null, BaseVO.TYPE_JSON);
case 1004:
Bitmap bm = BitmapFactory.decodeStream(context.getAssets().open(&logo&));//BitmapFactory.decodeFile(pic);
weiboAPI.addPic(context, &call telephone OKK&, requestFormat, longitude, latitude, bm, 0, 0, mCallBack, null, BaseVO.TYPE_JSON);
}catch(Exception e){
case 1005:
String picUrl = &/mblogpic/9c7ea696/2000&;
weiboAPI.addPicUrl(context, &y phone &, requestFormat, longitude, latitude, picUrl, 0, 0, mCallBack, null, BaseVO.TYPE_JSON);
case 1006:
timeLineAPI.getHTTimeLine(context, requestFormat, 30, &0&, &0&, 0, 0, &加油&, &0&, 1, 0x80, mCallBack, null, BaseVO.TYPE_JSON);
case 1007://获取用户信息
userAPI.getUserInfo(context, requestFormat, mCallBack, null, BaseVO.TYPE_JSON);
case 1008://获取他人信息
userAPI.getUserOtherInfo(context, requestFormat, &api_weibo&,null, mCallBack, null, BaseVO.TYPE_JSON);
case 1009://获取一批人信息
userAPI.getUserInfos(context, requestFormat, &api_weibo&, null, mCallBack, null, BaseVO.TYPE_JSON);
case 1010://收听某个用户
friendAPI.addFriend(context, requestFormat, &api_weibo&, null, mCallBack, null, BaseVO.TYPE_JSON);
case 1011://获取偶像列表
friendAPI.friendIDolList(context, requestFormat, 30, 0, 1, 0, mCallBack,null, BaseVO.TYPE_JSON);
case 1012://获取粉丝列表
friendAPI.friendFansList(context, requestFormat, 30, 0, 1, 0, 0, mCallBack, null, BaseVO.TYPE_JSON);
case 1013:
friendAPI.getMutualList(context, requestFormat, &api_weibo&, null, 0, 30, 0, mCallBack, null, BaseVO.TYPE_JSON);
case 1014://验证好友关系
friendAPI.friendCheck(context, requestFormat, &api_weibo&, null, 2, mCallBack, null, BaseVO.TYPE_JSON);
case 1015://转播获取转播列表
weiboAPI.reList(context, requestFormat, 2, &346&, 0, &0&, 30, &0&, mCallBack, null, BaseVO.TYPE_JSON);
case 1016://获取最近联系人
friendAPI.getIntimateFriends(context, requestFormat, 30, mCallBack, null, BaseVO.TYPE_JSON);
case 1017://获取附近的人
lbsAPI.getAroundPeople(context, requestFormat, longitude, latitude, &&, 20, 0, mCallBack, null, BaseVO.TYPE_JSON);
case 1018://获取身边最新的微博
lbsAPI.getAroundNew(context, requestFormat, longitude, latitude, &&, 20, mCallBack, null, BaseVO.TYPE_JSON);
case 1019:
case 1020:
Index: ReAddActivity.java
===================================================================
--- ReAddActivity.java (revision 0)
+++ ReAddActivity.java (revision 7)
@@ -0,0 +1,351 @@
+package com.tencent.weibo.
+import java.util.ArrayL
+import java.util.L
+import org.json.JSONO
+import com.tencent.weibo.sdk.android.api.WeiboAPI;
+import com.tencent.weibo.sdk.android.api.adapter.GalleryA
+import com.tencent.weibo.sdk.android.api.util.BackGroudS
+import com.tencent.weibo.sdk.android.api.util.U
+import com.tencent.weibo.sdk.android.model.AccountM
+import com.tencent.weibo.sdk.android.model.BaseVO;
+import com.tencent.weibo.sdk.android.model.ImageI
+import com.tencent.weibo.sdk.android.model.ModelR
+import com.tencent.weibo.sdk.android.network.HttpC
+import android.app.A
+import android.content.I
+import android.graphics.C
+import android.os.B
+import android.os.H
+import android.os.L
+import android.os.M
+import android.os.MessageQueue.IdleH
+import android.text.E
+import android.text.TextW
+import android.text.method.ScrollingMovementM
+import android.util.DisplayM
+import android.view.G
+import android.view.V
+import android.view.W
+import android.view.WindowM
+import android.widget.B
+import android.widget.EditT
+import android.widget.G
+import android.widget.LinearL
+import android.widget.PopupW
+import android.widget.ProgressB
+import android.widget.RelativeL
+import android.widget.TextV
+import android.widget.T
+ * 一键转播组件
+public class ReAddActivity extends Activity {
+ private LinearLayout layout =//整体布局
+ private EditText content =//转播内容输入框
+ private TextView textView_//显示文本剩余字数
+ private String contentStr = &&;//转播内容
+ private String videoPath = &&;//视频地址
+ private String picPath = &&;//图片地址
+ private String musicPath = &&;//音乐地址
+ private String musicTitle = &&;//音乐标题
+ private String musicAuthor = &&;//音乐演唱者
+ private Handler mHandler =//处理消息
+ private G//显示图片或者
+ private WeiboAPI//添加weiboAPI
+ private String accessT//用户访问令牌
+ private ArrayList&ImageInfo& imageList = new ArrayList&ImageInfo&();
+ private PopupWindow loadingWindow =
+ private ProgressBar progressBar =
+ private RelativeLayout galleryLayout =//添加
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
DisplayMetrics displaysMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics( displaysMetrics );
String pix=displaysMetrics.widthPixels+&x&+displaysMetrics.heightP
BackGroudSeletor.setPix(pix);
accessToken = Util.getSharePersistent(getApplicationContext(), &ACCESS_TOKEN&);
if(accessToken==null || &&.equals(accessToken)){
Toast.makeText(ReAddActivity.this,&请先授权&, Toast.LENGTH_SHORT)
this.finish();
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
if(bundle!=null){
contentStr = bundle.getString(&content&);
videoPath = bundle.getString(&video_url&);
picPath = bundle.getString(&pic_url&);
musicPath = bundle.getString(&music_url&);
musicTitle = bundle.getString(&music_title&);
musicAuthor = bundle.getString(&music_author&);
AccountModel account = new AccountModel(accessToken);
api = new WeiboAPI(account);
this.setContentView(initLayout());
* 初始化界面并设置监听
+ public View initLayout(){
RelativeLayout.LayoutParams fillParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
RelativeLayout.LayoutParams fillWrapParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams wrapParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layout = new LinearLayout(this);
layout.setLayoutParams(fillParams);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setBackgroundDrawable(BackGroudSeletor.getdrawble(&readd_bg&, getApplication()));
RelativeLayout cannelLayout = new RelativeLayout(this);
cannelLayout.setLayoutParams(fillWrapParams);
cannelLayout.setBackgroundDrawable(BackGroudSeletor.getdrawble(&up_bg2x&, getApplication()));
cannelLayout.setGravity(LinearLayout.HORIZONTAL);
Button returnBtn = new Button(this);
String[] pngArray = new String[]{&quxiao_btn2x&,&quxiao_btn_hover&};
returnBtn.setBackgroundDrawable(BackGroudSeletor.createBgByImageIds(pngArray, getApplication()));
returnBtn.setText(&取消&);
wrapParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
wrapParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
wrapParams.topMargin=10;
wrapParams.leftMargin=10;
wrapParams.bottomMargin=10;
returnBtn.setLayoutParams(wrapParams);
returnBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
ReAddActivity.this.finish();
cannelLayout.addView(returnBtn);
TextView title = new TextView(this);
title.setText(&转播&);
title.setTextColor(Color.WHITE);
title.setTextSize(24f);
RelativeLayout.LayoutParams titleParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
titleParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
title.setLayoutParams(titleParams);
cannelLayout.addView(title);
Button reAddBtn = new Button(this);
pngArray = new String[]{&sent_btn2x&,&sent_btn_hover&};
reAddBtn.setBackgroundDrawable(BackGroudSeletor.createBgByImageIds(pngArray, getApplication()));
reAddBtn.setText(&转播&);
RelativeLayout.LayoutParams wrapParamsRight = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
wrapParamsRight.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
wrapParamsRight.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
wrapParamsRight.topMargin=10;
wrapParamsRight.rightMargin=10;
wrapParamsRight.bottomMargin=10;
reAddBtn.setLayoutParams(wrapParamsRight);
reAddBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
reAddWeibo();
cannelLayout.addView(reAddBtn);
RelativeLayout reAddLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams readdParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, 240);
reAddLayout.setLayoutParams(readdParams);
RelativeLayout contentLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams contentParams = new RelativeLayout.LayoutParams(440, RelativeLayout.LayoutParams.FILL_PARENT);
contentParams.addRule(RelativeLayout.CENTER_IN_PARENT);
contentParams.topMargin=50;
+ // contentLayout.setBackgroundColor(Color.GRAY);//修改此处 设置背景
contentLayout.setLayoutParams(contentParams);
contentLayout.setBackgroundDrawable(BackGroudSeletor.getdrawble(&input_bg&, getApplication()));
textView_num = new TextView(this);
textView_num.setText(contentStr==null?&140&:String.valueOf(140-contentStr.length()));
textView_num.setTextColor(Color.parseColor(&#999999&));
textView_num.setGravity(Gravity.RIGHT);
textView_num.setTextSize(18f);
RelativeLayout.LayoutParams params_space = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params_space.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
params_space.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
params_space.rightMargin=10;
textView_num.setLayoutParams(params_space);
contentLayout.addView(textView_num);
//设置输入框
content = new EditText(this);
contentParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
contentParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
contentParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
content.setLayoutParams(contentParams);
//content.setBackgroundColor(Color.WHITE);
content.setMaxLines(4);
content.setMinLines(4);
//content.setMinEms(4);
//content.setMaxEms(4);
content.setScrollbarFadingEnabled(true);
content.setGravity(Gravity.TOP);
content.setMovementMethod(ScrollingMovementMethod.getInstance());
content.setText(contentStr);
content.setSelection(contentStr.length());
content.setBackgroundDrawable(null);
//content.setBackgroundColor(Color.CYAN);
content.addTextChangedListener(new TextWatcher(){
private CharS
private int selectionS
private int selectionE
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
selectionStart = content.getSelectionStart();
selectionEnd = content.getSelectionEnd();
if(temp.length()&140){
Toast.makeText(ReAddActivity.this,&最多可输入140字符&, Toast.LENGTH_SHORT)
arg0.delete(selectionStart-1, selectionEnd);
int tempSelection = selectionS
content.setText(arg0);
content.setSelection(tempSelection);
//temp = arg0.toString();
//int textLen = arg0.length();
textView_num.setText(String.valueOf(140-arg0.length()));
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
contentLayout.addView(content);
reAddLayout.addView(contentLayout);
galleryLayout = new RelativeLayout(this);
galleryLayout.setLayoutParams(fillParams);
gallery = new Gallery(this);
RelativeLayout.LayoutParams galleryParams = new RelativeLayout.LayoutParams(303,203);
galleryParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
galleryParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
galleryParams.topMargin=50;
gallery.setLayoutParams(galleryParams);
gallery.setBackgroundDrawable(BackGroudSeletor.getdrawble(&pic_biankuang2x&, getApplication()));
requestForGallery();
galleryLayout.addView(gallery);
layout.addView(cannelLayout);
layout.addView(reAddLayout);
if(picPath!=null && !&&.equals(picPath) && videoPath!=null && !&&.equals(videoPath)){
//progressBar = new ProgressBar(this);
//loadingWindow = new PopupWindow(progressBar,80,80);
layout.addView(galleryLayout);
Looper.myQueue().addIdleHandler(new IdleHandler(){
public boolean queueIdle() {
// TODO Auto-generated method stub
if( gallery.isShown()){
loadingWindow.showAtLocation(gallery, Gravity.CENTER, 0, 80);
* 发送多类型微博
+ protected void reAddWeibo(){
contentStr = content.getText().toString();
api.reAddWeibo(getApplicationContext(),contentStr,picPath,videoPath,musicPath,musicTitle,musicAuthor, mCallBack, null, BaseVO.TYPE_JSON);
+ private HttpCallback mCallBack = new HttpCallback() {
public void onResult(Object object) {
ModelResult result = (ModelResult)
if(result.isExpires()){
Toast.makeText(ReAddActivity.this, result.getError_message(), Toast.LENGTH_SHORT).show();
if(result.isSuccess()){
Toast.makeText(ReAddActivity.this, &转播成功&, Toast.LENGTH_SHORT).show();
ReAddActivity.this.finish();
Toast.makeText(ReAddActivity.this, result.getError_message(), Toast.LENGTH_SHORT).show();
ReAddActivity.this.finish();
* 获取一键转播组件中用于显示的图片信息
+ public ArrayList&ImageInfo& requestForGallery(){
if(picPath!=null){
ImageInfo info2 = new ImageInfo();
info2.setImagePath(picPath);
imageList.add(info2);
if(videoPath!=null){
ImageInfo info1 = new ImageInfo();
api.getVideoInfo(getApplicationContext(), videoPath, videoCallBack,null, BaseVO.TYPE_JSON);
return imageL
+ private HttpCallback videoCallBack = new HttpCallback() {
public void onResult(Object object) {
ModelResult result = (ModelResult)
if(result!=null){
if(!result.isExpires()){
if(result.isSuccess()){
JSONObject json = (JSONObject)result.getObj();
JSONObject data = json.getJSONObject(&data&);
ImageInfo info1 = new ImageInfo();
info1.setImagePath(data.getString(&minipic&));
info1.setImageName(data.getString(&title&));
info1.setPlayPath(data.getString(&real&));
imageList.add(info1);
GalleryAdapter adapter = new GalleryAdapter(getApplicationContext(),loadingWindow,imageList);
gallery.setAdapter(adapter);
}catch(Exception e){
e.printStackTrace();
if(loadingWindow!=null && loadingWindow.isShowing()){
loadingWindow.dismiss();
Index: PublishActivity.java
===================================================================
--- PublishActivity.java (revision 0)
+++ PublishActivity.java (revision 7)
@@ -0,0 +1,978 @@
+package com.tencent.weibo.
+import java.io.ByteArrayOutputS
+import java.io.FileInputS
+import java.io.FileNotFoundE
+import java.io.IOE
+import java.io.UnsupportedEncodingE
+import java.util.M
+import java.util.T
+import java.util.TimerT
+import com.tencent.weibo.sdk.android.api.WeiboAPI;
+import com.tencent.weibo.sdk.android.api.util.BackGroudS
+import com.tencent.weibo.sdk.android.api.util.U
+import com.tencent.weibo.sdk.android.model.AccountM
+import com.tencent.weibo.sdk.android.model.BaseVO;
+import com.tencent.weibo.sdk.android.model.ModelR
+import com.tencent.weibo.sdk.android.network.HttpC
+import android.app.A
+import android.app.ProgressD
+import android.content.C
+import android.content.I
+import android.database.C
+import android.graphics.B
+import android.graphics.BitmapF
+import android.graphics.C
+import android.graphics.M
+import android.graphics.drawable.BitmapD
+import android.location.L
+import android.net.U
+import android.os.B
+import android.os.E
+import android.os.H
+import android.os.L
+import android.os.M
+import android.provider.MediaS
+import android.text.E
+import android.text.TextW
+import android.text.method.ScrollingMovementM
+import android.util.L
+import android.view.G
+import android.view.V
+import android.view.W
+import android.view.View.OnClickL
+import android.view.inputmethod.InputMethodM
+import android.widget.B
+import android.widget.EditT
+import android.widget.FrameL
+import android.widget.ImageB
+import android.widget.ImageV
+import android.widget.LinearL
+import android.widget.RelativeL
+import android.widget.LinearLayout.LayoutP
+import android.widget.PopupW
+import android.widget.TextV
+import android.widget.T
+import android.graphics.BitmapFactory.O
+ * 微博发表组件
+public class PublishActivity extends Activity implements OnClickListener,
HttpCallback {
+ private Button button_ // 取消按钮5001
+ private Button button_ // 发送按钮5002
+ private EditText editText_// 编辑文本内容5003
+ private ImageView imageView_// 图片小图标5004
+ private ImageView imageView_// 小图标边框5005
+ private ImageView imageView_ // 图片大图
+ private ImageView imageView_// 大图删除按钮5013
+ private ImageButton button_ // 查看收听的人列表功能按钮5006
+ private ImageButton button_// 查看话题功能按钮5007
+ private ImageButton button_// 启动照相机按钮5008
+ private ImageButton button_// 获取地理位置按钮5009
+ private TextView textView_// 显示文本剩余字数
+ private LinearLayout layout_
+ private LinearLayout layout_
+ private LinearL
+ private LinearLayout layout_big_
+ private FrameLayout frameLayout_
+ private FrameLayout frameLayout_
+ private PopupWindow popupW
+ // private byte[]
+ private int lyout[] = new int[2];
+ private String edstring = &&;
+ private Map&String, String&
+ private Location mL
+ private ProgressD
+ private String accessT// 用户访问令牌
+ private Bitmap mBitmap =
+ private WeiboAPI weiboAPI;// 微博相关API
+ private C
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
accessToken = Util.getSharePersistent(getApplicationContext(),
&ACCESS_TOKEN&);
if (accessToken == null || &&.equals(accessToken)) {
Toast.makeText(PublishActivity.this, &请先授权&, Toast.LENGTH_SHORT)
this.finish();
context = getApplicationContext();
AccountModel account = new AccountModel(accessToken);
weiboAPI = new WeiboAPI(account);
lyout[0] = (BackGroudSeletor.getdrawble(&test2x&, PublishActivity.this))
.getMinimumWidth();
lyout[1] = BackGroudSeletor.getdrawble(&test2x&, PublishActivity.this)
.getMinimumHeight();
LinearLayout layout = (LinearLayout) initview();
dialog = new ProgressDialog(PublishActivity.this);
dialog.setMessage(&正在发送请稍后......&);
setContentView(layout);
setonclick();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
InputMethodManager imm = (InputMethodManager) PublishActivity.this
.getSystemService(INPUT_METHOD_SERVICE);
// imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
imm.showSoftInput(editText_text, InputMethodManager.SHOW_FORCED);
+ @Override
+ protected void onResume() {
super.onResume();
final InputMethodManager imm = (InputMethodManager) PublishActivity.this
.getSystemService(INPUT_METHOD_SERVICE);
// frameLayout_icon.setVisibility(View.INVISIBLE);
// frameLayout_big.setVisibility(View.GONE);
if (popupWindow != null && popupWindow.isShowing()) {
Log.d(&mkl&, imm.isActive() + &&);
// imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
// imm.showSoftInput(editText_text,InputMethodManager.SHOW_FORCED);
imm.hideSoftInputFromWindow(editText_text.getWindowToken(), 0);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
imm.showSoftInput(editText_text,
InputMethodManager.SHOW_FORCED);
if (location != null) {
button_location.setBackgroundDrawable(BackGroudSeletor.getdrawble(
&dingwei_icon_hover2x&, PublishActivity.this));
button_location.setBackgroundDrawable(BackGroudSeletor.getdrawble(
&dingwei_icon2x&, PublishActivity.this));
+ * 初始化界面使用控件,并设置相应属性,
+ private View initview() {
viewroot = new LinearLayout(PublishActivity.this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT);
FrameLayout.LayoutParams layoutParams_frame = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams wrapParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
viewroot.setLayoutParams(params);
viewroot.setOrientation(LinearLayout.VERTICAL);
// viewroot.setBackgroundColor(Color.parseColor(&#888888&));
LinearLayout.LayoutParams params_layout = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
// LinearLayout layout_title = new LinearLayout(PublishActivity.this);
// layout_title.setLayoutParams(params_layout);
// layout_title.setOrientation(LinearLayout.HORIZONTAL);
// layout_title.setGravity(Gravity.CENTER_VERTICAL);
// layout_title.setBackgroundDrawable(BackGroudSeletor.getdrawble(
// &up_bg2x&, PublishActivity.this));
// layout_title.setPadding(10, 10, 10, 10);
RelativeLayout.LayoutParams fillWrapParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
RelativeLayout layout_title = new RelativeLayout(this);
layout_title.setLayoutParams(fillWrapParams);
layout_title.setBackgroundDrawable(BackGroudSeletor.getdrawble(
&up_bg2x&, getApplication()));
layout_title.setGravity(LinearLayout.HORIZONTAL);
button_esc = new Button(PublishActivity.this);// 取消按钮
wrapParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
wrapParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
wrapParams.topMargin=10;
wrapParams.leftMargin=10;
wrapParams.bottomMargin=10;
button_esc.setLayoutParams(wrapParams);
button_esc.setText(&取消&);
button_esc.setClickable(true);
button_esc.setId(5001);
String string_esc[] = { &quxiao_btn2x&, &quxiao_btn_hover& };
button_esc.setBackgroundDrawable(BackGroudSeletor.createBgByImageIds(
string_esc, PublishActivity.this));
button_send = new Button(PublishActivity.this);// 发送按钮
RelativeLayout.LayoutParams wrapParamsRight = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
wrapParamsRight.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
wrapParamsRight.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
wrapParamsRight.topMargin=10;
wrapParamsRight.rightMargin=10;
wrapParamsRight.bottomMargin=10;
button_send.setLayoutParams(wrapParamsRight);
LinearLayout layout_space = new LinearLayout(PublishActivity.this);
LinearLayout.LayoutParams params_space = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT, 1);
layout_space.setLayoutParams(params_space);
button_send.setText(&发送&);
button_send.setClickable(true);
button_send.setId(5002);
String string_send[] = { &sent_btn_22x&, &sent_btn_hover& };
button_send.setBackgroundDrawable(BackGroudSeletor.createBgByImageIds(
string_send, PublishActivity.this));
layout_title.addView(button_esc);
layout_title.addView(button_send);
LinearLayout layout_content = new LinearLayout(PublishActivity.this);
layout_content.setLayoutParams(params_layout);
layout_content.setLayoutParams(params_layout);
layout_content.setOrientation(LinearLayout.VERTICAL);
layout_content.setBackgroundColor(Color.WHITE);
layout_content.requestFocus();
editText_text = new EditText(PublishActivity.this);
editText_text.setBackgroundColor(Color.WHITE);
editText_text.setMaxLines(4);
editText_text.setMinLines(4);
editText_text.setMinEms(4);
editText_text.setMaxEms(4);
editText_text.setFocusable(true);
editText_text.requestFocus();
editText_text.setText(edstring);
editText_text.setSelection(edstring.length());
editText_text.setScrollbarFadingEnabled(true);
editText_text.setGravity(Gravity.TOP);
editText_text.setMovementMethod(ScrollingMovementMethod.getInstance());
editText_text.setId(5003);
frameLayout_icon = new FrameLayout(PublishActivity.this);
frameLayout_icon.setLayoutParams(layoutParams_frame);
LinearLayout layout_icon = new LinearLayout(PublishActivity.this);
layout_icon.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
layout_icon.setLayoutParams(new LinearLayout.LayoutParams(54, 45));
layout_icon.setPadding(0, 0, 2, 0);
imageView_icon = new ImageView(PublishActivity.this);
imageView_icon.setId(5004);
imageView_bound = new ImageView(PublishActivity.this);
imageView_bound.setId(5005);
imageView_bound.setLayoutParams(new LinearLayout.LayoutParams(54, 45));
// imageView_icon.setImageDrawable(BackGroudSeletor.getdrawble(
// &test2x&, PublishActivity.this));
imageView_icon.setLayoutParams(new LinearLayout.LayoutParams(33, 33));
imageView_bound.setImageDrawable(BackGroudSeletor.getdrawble(
&composeimageframe&, PublishActivity.this));
frameLayout_icon.setVisibility(View.GONE);
// imageView_bound.setLayoutParams(layoutParams_frame);
layout_icon.addView(imageView_icon);
frameLayout_icon.addView(layout_icon);
frameLayout_icon.addView(imageView_bound);
layout_content.addView(editText_text);
layout_content.addView(frameLayout_icon);
layout_set = new LinearLayout(PublishActivity.this);
layout_set.setLayoutParams(params_layout);
layout_set.setBackgroundDrawable(BackGroudSeletor.getdrawble(
&icon_bg2x&, PublishActivity.this));
layout_set.setOrientation(LinearLayout.HORIZONTAL);
layout_set.setGravity(Gravity.CENTER_VERTICAL);
layout_set.setPadding(10, 0, 30, 0);
LinearLayout layout_function = new LinearLayout(PublishActivity.this);
layout_function.setOrientation(LinearLayout.HORIZONTAL);
layout_function.setLayoutParams(params_space);
LinearLayout layout_friend = new LinearLayout(PublishActivity.this);
layout_friend.setGravity(Gravity.CENTER_HORIZONTAL);
layout_friend.setLayoutParams(params_space);
LinearLayout layout_conversation = new LinearLayout(
PublishActivity.this);
layout_conversation.setGravity(Gravity.CENTER_HORIZONTAL);
layout_conversation.setLayoutParams(params_space);
LinearLayout layout_camera = new LinearLayout(PublishActivity.this);
layout_camera.setGravity(Gravity.CENTER_HORIZONTAL);
layout_camera.setLayoutParams(params_space);
LinearLayout layout_location = new LinearLayout(PublishActivity.this);
layout_location.setGravity(Gravity.CENTER_HORIZONTAL);
layout_location.setLayoutParams(params_space);
button_friend = new ImageButton(PublishActivity.this);
button_friend.setLayoutParams(layoutParams_frame);
button_friend.setId(5006);
button_conversation = new ImageButton(PublishActivity.this);
button_conversation.setLayoutParams(layoutParams_frame);
button_conversation.setId(5007);
button_camera = new ImageButton(PublishActivity.this);
button_camera.setLayoutParams(layoutParams_frame);
button_camera.setId(5008);
button_location = new ImageButton(PublishActivity.this);
button_location.setLayoutParams(layoutParams_frame);
button_location.setId(5009);
// String string_friend[] = { &haoyou_icon2x&, &haoyou_icon_hover2x& };
button_friend.setBackgroundDrawable(BackGroudSeletor.getdrawble(
&haoyou_icon2x&, PublishActivity.this));
String string_conversation[] = { &huati_icon2x&, &huati_icon_hover2x& };
button_conversation.setBackgroundDrawable(BackGroudSeletor
.createBgByImageIds(string_conversation, PublishActivity.this));
String string_camera[] = { &pic_icon2x&, &pic_icon_hover2x& };
button_camera.setBackgroundDrawable(BackGroudSeletor
.createBgByImageIds(string_camera, PublishActivity.this));
String string_location[] = { &dingwei_icon2x&, &dingwei_icon_hover2x& };
button_location.setBackgroundDrawable(BackGroudSeletor
.createBgByImageIds(string_location, PublishActivity.this));
layout_friend.addView(button_friend);
layout_function.addView(layout_friend);
layout_conversation.addView(button_conversation);
layout_function.addView(layout_conversation);
layout_camera.addView(button_camera);
layout_function.addView(layout_camera);
layout_location.addView(button_location);
layout_function.addView(layout_location);
textView_num = new TextView(PublishActivity.this);
textView_num.setText(&140&);
textView_num.setTextColor(Color.parseColor(&#999999&));
textView_num.setGravity(Gravity.RIGHT);
textView_num.setLayoutParams(params_space);
textView_num.setId(5010);
textView_num.setWidth(40);
LinearLayout layout_textnum = new LinearLayout(PublishActivity.this);
layout_textnum.setLayoutParams(params_space);
layout_textnum.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
layout_textnum.addView(textView_num);
layout_set.addView(layout_function);
layout_set.addView(layout_textnum);
LinearLayout layout_image = new LinearLayout(PublishActivity.this);
LinearLayout.LayoutParams params_image = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT, 1);
layout_image.setLayoutParams(params_image);
layout_image.setGravity(Gravity.CENTER);
layout_image.setBackgroundDrawable(BackGroudSeletor.getdrawble(&bg&,
PublishActivity.this));
frameLayout_big = new FrameLayout(PublishActivity.this);
FrameLayout.LayoutParams framelayout_Params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
frameLayout_big.setLayoutParams(framelayout_Params);
frameLayout_big.setPadding(10, 10, 0, 0);
layout_imagebound = new LinearLayout(PublishActivity.this);
layout_imagebound.setPadding(2, 2, 2, 2);
layout_imagebound.setBackgroundDrawable(BackGroudSeletor.getdrawble(
&pic_biankuang2x&, PublishActivity.this));
layout_big_delete = new LinearLayout(PublishActivity.this);
LinearLayout.LayoutParams image_layout_params = new LinearLayout.LayoutParams(
getarea(lyout)[0] + 10, getarea(lyout)[1] + 10);
layout_big_delete.setLayoutParams(image_layout_params);
layout_imagebound.setGravity(Gravity.CENTER);
layout_imagebound.setId(5011);
layout_imagebound.setLayoutParams(new LayoutParams(getarea(lyout)[0],
getarea(lyout)[1]));
imageView_big = new ImageView(PublishActivity.this);
imageView_big.setId(5012);
// imageView_big.setImageDrawable(BackGroudSeletor.getdrawble(
// &test2x&, PublishActivity.this));
layout_imagebound.addView(imageView_big);
// layout_imagebound.setVisibility(View.GONE);
imageView_delete = new ImageView(PublishActivity.this);
imageView_delete.setId(5013);
imageView_delete.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
imageView_delete.setImageDrawable(BackGroudSeletor.getdrawble(&close&,
PublishActivity.this));
layout_big_delete.addView(imageView_delete);
frameLayout_big.addView(layout_imagebound);
frameLayout_big.addView(layout_big_delete);
frameLayout_big.setVisibility(View.GONE);
layout_image.addView(frameLayout_big);
viewroot.addView(layout_title);
viewroot.addView(layout_content);
viewroot.addView(layout_set);
viewroot.addView(layout_image);
+ * 对个空间设置监听
+ private void setonclick() {
button_esc.setOnClickListener(PublishActivity.this);
button_send.setOnClickListener(PublishActivity.this);
editText_text.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before,
int count) {
Log.d(&contentafter&, s.toString().getBytes(&gbk&).length
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
public void afterTextChanged(Editable s) {
edstring = s.toString();
String num = (140 - s.toString().getBytes(&gbk&).length / 2)
Log.d(&contentafter&, num);
textView_num.setText(num);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
imageView_bound.setOnClickListener(PublishActivity.this);
imageView_delete.setOnClickListener(PublishActivity.this);
button_friend.setOnClickListener(PublishActivity.this);
button_conversation.setOnClickListener(PublishActivity.this);
button_camera.setOnClickListener(PublishActivity.this);
button_location.setOnClickListener(PublishActivity.this);
+ @Override
+ public void onClick(View v) {
final InputMethodManager imm = (InputMethodManager) PublishActivity.this
.getSystemService(INPUT_METHOD_SERVICE);
switch (v.getId()) {
case 5001:
imm.hideSoftInputFromWindow(editText_text.getWindowToken(), 0);
case 5002:
String content = editText_text.getText().toString();
if (&&.equals(content)
&& frameLayout_icon.getVisibility() == View.GONE) {
Toast.makeText(PublishActivity.this, &无内容发送&,
Toast.LENGTH_SHORT).show();
if (dialog != null && !dialog.isShowing()) {
dialog.show();
if (Integer.parseInt(textView_num.getText().toString()) & 0) {
Toast.makeText(PublishActivity.this, &请重新输入少于140个字的内容&,
Toast.LENGTH_SHORT).show();
double longitude = 0d;
double latitude = 0d;
if (mLocation != null) {
longitude = mLocation.getLongitude();
latitude = mLocation.getLatitude();
if (!frameLayout_icon.isShown()) {
weiboAPI.addWeibo(context, content, &json&, longitude,
latitude, 0, 0, this, null, BaseVO.TYPE_JSON);
} else if (frameLayout_icon.getVisibility() == View.VISIBLE) {
weiboAPI.addPic(context, content, &json&, longitude,
latitude, mBitmap, 0, 0, this, null,
BaseVO.TYPE_JSON);
case 5005:
// Toast.makeText(PublishActivity.this, &5005&, 1000).show();
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
// imm.showSoftInput(editText_text,InputMethodManager.SHOW_FORCED);
case 5006:
imm.hideSoftInputFromWindow(editText_text.getWindowToken(), 0);
Intent intent_friend = new Intent();
intent_friend.setClass(PublishActivity.this, FriendActivity.class);
startActivityForResult(intent_friend, 5006);
case 5007:
imm.hideSoftInputFromWindow(editText_text.getWindowToken(), 0);
Intent intent_conversation = new Intent();
intent_conversation.setClass(PublishActivity.this,
ConversationActivity.class);
startActivityForResult(intent_conversation, 5007);
case 5008:
if (popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
if (imm.isActive()) {
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
// m.showSoftInput(editText_text,InputMethodManager.SHOW_FORCED);
popupWindow = new PopupWindow(showView(),
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
// popupWindow.setFocusable(true);
popupWindow.setTouchable(true);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
Message msg = handler.obtainMessage();
msg.what = 0;
handler.sendMessage(msg);
case 5009:
new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
Looper.prepare();
Message msg = handler.obtainMessage();
// if (location == null) {
// LocationAction la = new LocationAction(context);
// location = la.getLocation();
// if (location != null) {
// msg.what = 10;
// handler.sendMessage(msg);
// } else {
// msg.what = 15;
// handler.sendMessage(msg);
// } else {
// msg.what = 15;
msg.what = 15;
if (mLocation == null) {
mLocation = Util.getLocation(context);
if (mLocation != null) {
msg.what = 10;
handler.sendMessage(msg);
Looper.loop();
}).start();
case 5010:
case 5013:
frameLayout_icon.setVisibility(View.INVISIBLE);
frameLayout_big.setVisibility(View.GONE);
case 5014:
edstring = editText_text.getText().toString();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 2000);
case 5015:
edstring = editText_text.getText().toString();
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, 1000);
case 5016:
if (popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
editText_text.requestFocus();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
if (imm.isActive()) {
imm.toggleSoftInput(0,
InputMethodManager.HIDE_NOT_ALWAYS);
// m.showSoftInput(editText_text,InputMethodManager.SHOW_FORCED);
+ private Handler handler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
int flag = msg.
if (flag == 5) {
frameLayout_big.setVisibility(View.VISIBLE);
frameLayout_icon.setVisibility(View.VISIBLE);
if (flag == 0) {
popupWindow.showAsDropDown(layout_set);
InputMethodManager imm = (InputMethodManager) PublishActivity.this
.getSystemService(INPUT_METHOD_SERVICE);
Log.d(&alive&, imm.isActive() + &&);
if (imm.isActive()) {
imm.hideSoftInputFromWindow(editText_text.getWindowToken(),
Log.d(&alive&, imm.isActive() + &&);
if (flag == 10) {
button_location.setBackgroundDrawable(BackGroudSeletor
.getdrawble(&dingwei_icon_hover2x&,
PublishActivity.this));
if (flag == 15) {
Toast.makeText(PublishActivity.this, &定位失败&, Toast.LENGTH_SHORT)
button_location.setBackgroundDrawable(BackGroudSeletor
.getdrawble(&dingwei_icon2x&, PublishActivity.this));
* 点击相机按钮弹出选择框,来选择本地图片来源,可以是系统图库,也可以是拍照
+ private View showView() {
LinearLayout camera = new LinearLayout(PublishActivity.this);
camera.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
camera.setBackgroundDrawable(BackGroudSeletor.getdrawble(&bg&,
PublishActivity.this));
camera.setOrientation(LinearLayout.VERTICAL);
camera.setPadding(50, 50, 50, 50);
camera.setGravity(Gravity.CENTER);
camera.requestFocus();
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout camera_layout = new LinearLayout(PublishActivity.this);
camera_layout.setLayoutParams(params);
camera_layout.setPadding(0, 0, 0, 0);
LinearLayout pic_layout = new LinearLayout(PublishActivity.this);
pic_layout.setLayoutParams(params);
pic_layout.setPadding(0, 10, 0, 30);
LinearLayout esc_layout = new LinearLayout(PublishActivity.this);
LinearLayout.LayoutParams button_Params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
Button camera_button = new Button(PublishActivity.this);
camera_button.setId(5014);
camera_button.setOnClickListener(PublishActivity.this);
camera_button.setLayoutParams(button_Params);
camera_button.setText(&拍照&);
String camera_string[] = { &btn1_&, &btn1_hover_& };
camera_button.setBackgroundDrawable(BackGroudSeletor
.createBgByImageIds(camera_string, PublishActivity.this));
Button pic_button = new Button(PublishActivity.this);
pic_button.setId(5015);
pic_button.setOnClickListener(PublishActivity.this);
pic_button.setLayoutParams(button_Params);
pic_button.setText(&相册&);
pic_button.setBackgroundDrawable(BackGroudSeletor.createBgByImageIds(
camera_string, PublishActivity.this));
Button esc_bButton = new Button(PublishActivity.this);
esc_bButton.setId(5016);
esc_bButton.setOnClickListener(PublishActivity.this);
esc_bButton.setLayoutParams(button_Params);
esc_bButton.setText(&取消&);
String esc_string[] = { &btn2_&, &btn1_hover_& };
esc_bButton.setBackgroundDrawable(BackGroudSeletor.createBgByImageIds(
esc_string, PublishActivity.this));
pic_layout.addView(pic_button);
camera.addView(camera_button);
camera.addView(pic_layout);
camera.addView(esc_bButton);
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1000 && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
Log.d(&path&, picturePath + &&);
final int[] in = new int[2];
FileInputStream fileInputStream = new FileInputStream(
picturePath);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds =
options.inSampleSize = 6;// 宽度和高度设置为原来的1/10
Bitmap bitmap = BitmapFactory.decodeStream(fileInputStream,
null, options);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pressFormat.JPEG, 100, baos);
lyout[0] = bitmap.getWidth();
lyout[1] = bitmap.getHeight();
setContentView(initview());
setonclick();
imageView_icon.setImageDrawable(new BitmapDrawable(bitmap));
imageView_big.setImageDrawable(new BitmapDrawable(bitmap));
frameLayout_icon.setVisibility(View.VISIBLE);
frameLayout_big.setVisibility(View.VISIBLE);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
cursor.close();
if (popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
InputMethodManager i = (InputMethodManager) PublishActivity.this
.getSystemService(INPUT_METHOD_SERVICE);
Log.d(&mks&, i.isActive() + &&);
i.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
Message msg = handler.obtainMessage();
msg.what = 5;
handler.sendMessage(msg);
// i.hideSoftInputFromWindow(PublishActivity.this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
} else if (requestCode == 2000 && resultCode == RESULT_OK
&& null != data) {
if (popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
Bundle bundle = data.getExtras();
Bitmap bitmap = (Bitmap) bundle.get(&data&);
// MediaStore.Images.Media.insertImage(getContentResolver(), bitmap,
// &myPhoto&, &&);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse(&file://&
+ Environment.getExternalStorageDirectory())));
// frameLayout_big.setVisibility(View.VISIBLE);
// frameLayout_icon.setVisibility(View.VISIBLE);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pressFormat.PNG, 100, baos);
lyout[0] = bitmap.getWidth();
lyout[1] = bitmap.getHeight();
setContentView(initview());
setonclick();
imageView_icon.setImageDrawable(new BitmapDrawable(bitmap));
imageView_big.setImageDrawable(new BitmapDrawable(bitmap));
frameLayout_icon.setVisibility(View.VISIBLE);
frameLayout_big.setVisibility(View.VISIBLE);
} else if (requestCode == 5007 && resultCode == RESULT_OK
&& null != data) {
edstring = edstring + data.getStringExtra(&conversation&);
editText_text.setText(edstring);
editText_text.setSelection(edstring.length());
} else if (requestCode == 5006 && resultCode == RESULT_OK
&& null != data) {
edstring = edstring + &@& + data.getStringExtra(&firend&);
editText_text.setText(edstring);
editText_text.setSelection(edstring.length());
+ @Override
+ public void onResult(Object object) {
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
if (object != null) {
ModelResult result = (ModelResult)
if (result.isExpires()) {
Toast.makeText(PublishActivity.this,
result.getError_message(), Toast.LENGTH_SHORT)
if (result.isSuccess()) {
Toast.makeText(PublishActivity.this, &发送成功&, 4000)
Log.d(&发送成功&, object.toString());
Toast.makeText(PublishActivity.this,
((ModelResult) object).getError_message(), 4000)
* 计算图片大图显示时的伸缩后的宽高
+ private int[] getarea(int area[]) {
int myarea[] = new int[2];
float temp = 0.0f;
if (area != null) {
if (area[0] & area[1] && area[0] &= 300) {
myarea[0] = 300;
temp = (float) area[1] / area[0];
myarea[1] = (int) (temp * 300);
} else if (area[0] & area[1] && area[0] & 300) {
myarea[0] = area[0];
myarea[1] = area[1];
} else if (area[0] & area[1] && area[1] &= 300) {
temp = (float) area[0] / area[1];
myarea[0] = (int) (temp * 300);
myarea[1] = 300;
} else if (area[0] & area[1] && area[0] & 300) {
myarea[0] = area[0];
myarea[1] = area[1];
} else if (area[0] == area[1] && area[0] &= 300) {
myarea[0] = 300;
myarea[1] = 300;
} else if (area[0] == area[1] && area[0] & 300) {
myarea[0] = area[0];
myarea[1] = area[1];
Log.d(&myarea&, myarea[0] + &.....& + myarea[1]);
* 图片的缩放方法
* @param bgimage
:源图片资源
* @param newWidth
:缩放后宽度
* @param newHeight
:缩放后高度
可用的图片 bitmap对象
+ public Bitmap zoomImage(Bitmap bm, double newWidth, double newHeight) {
// 获取这个图片的宽和高
float width = bm.getWidth();
float height = bm.getHeight();
// 创建操作图片用的matrix对象
Matrix matrix = new Matrix();
// 计算宽高缩放率
float scaleWidth = ((float) newWidth) /
float scaleHeight = ((float) newHeight) /
// 缩放图片动作
matrix.postScale(scaleWidth, scaleHeight);
Bitmap bitmap = Bitmap.createBitmap(bm, 0, 0, (int) width,
(int) height, matrix, true);
// Options op = new Options();
// op.inSampleSize=(int)maxS
// Bitmap bitmap = BitmapFactory.decodeFile(op);
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// bm.pressFormat.JPEG, 100, baos);
// InputStream temp = new
// ByteArrayInputStream(baos.toByteArray());//this.getAssets().open(path);
// BitmapFactory.Options options = new BitmapFactory.Options();
// // 这个参数代表,不为bitmap分配内存空间,只记录一些该图片的信息(例如图片大小),说白了就是为了内存优化
// options.inJustDecodeBounds =
// // 通过创建图片的方式,取得options的内容(这里就是利用了java的地址传递来赋值)
// BitmapFactory.decodeStream(temp, null, options);
// // 关闭流
// temp.close();
// // 生成压缩的图片
// int i = 0;
// Bitmap bitmap =
// while (true) {
// // 这一步是根据要设置的大小,使宽和高都能满足
// if ((options.outWidth && i &= maxSize)
// && (options.outHeight && i &= maxSize)) {
// // 重新取得流,注意:这里一定要再次加载,不能二次使用之前的流!
// temp = new
// ByteArrayInputStream(baos.toByteArray());//this.getAssets().open(path);
// // 这个参数表示 新生成的图片为原始图片的几分之一。
// options.inSampleSize = (int)maxS//(int) Math.pow(2.0D, i);
// // 这里之前设置为了true,所以要改为false,否则就创建不出图片
// options.inJustDecodeBounds =
// bitmap = BitmapFactory.decodeStream(temp, null, options);
// i += 1;
// }catch(Exception e){
// e.printStackT}

我要回帖

更多关于 天天酷跑领取1888钻石 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信