信息处理类

package com.xxxx.sns.application.space.other;


import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


import com.mobclick.android.MobclickAgent;
import com.mobclick.android.ReportPolicy;
import com.shoujifeng.sns.R;
import com.shoujifeng.sns.application.SendCommentActivity;
import com.shoujifeng.sns.application.entityui.ShareListItemEntity;
import com.shoujifeng.sns.application.pub.SmileyParser;
import com.shoujifeng.sns.application.share.ShareMsgActivity;
import com.shoujifeng.sns.application.shopinfo.MyShopActivity;
import com.shoujifeng.sns.application.space.SpaceActivity;
import com.shoujifeng.sns.beans.SendComment;
import com.shoujifeng.sns.beans.Share;
import com.shoujifeng.sns.beans.UserInfo;
import com.shoujifeng.sns.http.app.share.GetAllShare;
import com.shoujifeng.sns.http.app.share.GetAllShareByShareId;
import com.shoujifeng.sns.http.app.share.GetAllShare.onGetAllShareListener;
import com.shoujifeng.sns.http.app.share.GetAllShareByShareId.onGetAllShareByShareIdListener;
import com.shoujifeng.sns.http.logic.HttpTimeoutListener;
import com.shoujifeng.sns.http.logic.RequestType;
import com.shoujifeng.sns.http.logic.RespondType;
import com.shoujifeng.sns.manager.AllMsgListManage;
import com.shoujifeng.sns.manager.SoundManager;
import com.shoujifeng.sns.manager.UserManager;
import com.shoujifeng.sns.manager.VoiceManager;
import com.shoujifeng.sns.param.SNSParam;
import com.shoujifeng.win.winutil.AsyncImageLoader;
import com.shoujifeng.win.winutil.AsyncSoundLoader;
import com.shoujifeng.win.winutil.StringUtil;
import com.shoujifeng.win.winutil.SystemUtil;
import com.shoujifeng.win.winutil.WindOS_MediaPlay;
import com.shoujifeng.win.winutil.AsyncImageLoader.ImageCallbackByAid;
import com.shoujifeng.win.winutil.AsyncSoundLoader.SoundCallback;
import com.shoujifeng.win.winwidget.ProgressDialogHint;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;


public class SpaceShareActivity extends Activity implements OnClickListener,OnItemClickListener{
private Button backButton;
private TextView titleTextView;
private Button creatButton;// 发分享
private ListView shareListView;


private List<Share> shareList;
private ShareListAdater shareListAdater;
private AsyncImageLoader asyncImageLoader = new AsyncImageLoader();// 实例化异步加载图片
private HashMap<String, Bitmap> allImgHashMap = new HashMap<String, Bitmap>();
private AsyncSoundLoader asyncSoundLoader = new AsyncSoundLoader();
private WindOS_MediaPlay mediaPlayer;
private boolean isPlaying = false; // 是否正在播放

private static UserInfo userInfo;

private LayoutInflater mLayoutInflater;
private LinearLayout footView;// 底部
private LinearLayout footTextLayout;// 点击
private TextView footTextView;// 文字
private ProgressBar footProgressBar;// 进度条
private boolean isLoading = false;// 当前是否在加载 false 没有



public static void actionSpaceShare(Activity fromActivity,UserInfo userInfos) {
userInfo=new UserInfo();
Intent i = new Intent(fromActivity, SpaceShareActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
userInfo = userInfos;
fromActivity.startActivityForResult(i, 11);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/**
* 友盟统计分析SDK
*/
MobclickAgent.setDebugMode(SNSParam.ymDebugMode);
MobclickAgent.onError(this);
MobclickAgent.setUpdateOnlyWifi(SNSParam.ymUpdateOnlyWifi);
MobclickAgent.update(this,SNSParam.ymWaitTime);// daily
MobclickAgent.setDefaultReportPolicy(this, ReportPolicy.BATCH_AT_LAUNCH);
MobclickAgent.updateOnlineConfig(this);

shareList = new ArrayList<Share>();
mediaPlayer = new WindOS_MediaPlay(this);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.share_main_tab_my);
initViews();
}


@Override
public void onPause() {
super.onPause();
// [友盟统计分析SDK]
MobclickAgent.onPause(this);
}


@Override
protected void onResume() {


super.onResume();
// [友盟统计分析SDK]
MobclickAgent.onResume(this);
if (shareList.size() < 1) {
share_getall();
}
}


private void initViews() {
titleTextView=(TextView)findViewById(R.id.title_TextView);


backButton = (Button) findViewById(R.id.share_main_tab_my_back_Button);
backButton.setOnClickListener(this);
creatButton = (Button) findViewById(R.id.share_main_tab_my_find_Button);
creatButton.setOnClickListener(this);
creatButton.setVisibility(View.GONE);

shareListAdater = new ShareListAdater();
shareListView = (ListView) findViewById(R.id.share_main_tab_my_ListView);

mLayoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
footView = (LinearLayout) mLayoutInflater.inflate(
R.layout.all_list_item_foot, null);
footTextLayout = (LinearLayout) footView
.findViewById(R.id.btn_more_bg_default_LinearLayout);
footTextLayout.setOnClickListener(this);
footTextView = (TextView) footView
.findViewById(R.id.btn_more_bg_default_TextView);
footTextView.setOnClickListener(this);
footProgressBar = (ProgressBar) footView
.findViewById(R.id.btn_more_bg_default_ProgressBar);
shareListView.addFooterView(footView);
loadTextes(SNSParam.LIMIT);

shareListView.setAdapter(shareListAdater);
shareListView.setDivider(null);
shareListView.setOnItemClickListener(this);


StringBuffer titleBuffer=new StringBuffer();
try {
titleBuffer.append(userInfo.getUserName());
} catch (Exception e) {
e.printStackTrace();
}
titleBuffer.append("的分享");
titleTextView.setText(titleBuffer);
}





public List<Share> getShareList() {
return shareList;
}


public void setShareList(List<Share> shareLists) {
this.shareList.addAll(shareLists);
}


private class ShareListAdater extends BaseAdapter {


@Override
public int getCount() {
return getShareList().size();
}


@Override
public Object getItem(int position) {


return position;
}


@Override
public long getItemId(int position) {


return position;
}


@Override
public View getView(final int position, View convertView,ViewGroup parent) {



final ShareListItemEntity holder;
final Share shareApp = getShareList().get(position);


holder = new ShareListItemEntity();
if (shareApp.getUserId() == UserManager.GetLoginUserInfo().getUserId()) {
convertView = SpaceShareActivity.this.getLayoutInflater().inflate(R.layout.share_main_tab_all_item_right, null);
}else {
convertView = SpaceShareActivity.this.getLayoutInflater().inflate(R.layout.share_main_tab_all_item_left, null);
}
holder.iconImageView = (ImageView) convertView.findViewById(R.id.share_main_tab_icon_item_ImageView);


holder.nameTextView = (TextView) convertView.findViewById(R.id.share_main_tab_name_item_TextView);


holder.timeTextView = (TextView) convertView.findViewById(R.id.share_main_tab_time_item_TextView);


holder.summaryTextView = (TextView) convertView.findViewById(R.id.share_main_tab_summary_item_TextView);


holder.formTextView = (TextView) convertView.findViewById(R.id.share_main_tab_from_item_TextView);


holder.summaryImageView = (ImageView) convertView.findViewById(R.id.share_main_tab_summary_ImageView);


holder.playVideoButton = (Button) convertView.findViewById(R.id.share_main_tab_play_video_Button);


holder.retimeTextView = (TextView) convertView.findViewById(R.id.share_main_tab_retime_item_TextView);


holder.reIconImageView = (ImageView) convertView.findViewById(R.id.share_main_tab_reicon_ImageView);


holder.reCountTextView = (TextView) convertView.findViewById(R.id.share_main_tab_recount_item_TextView);
// convertView.setTag(holder);
// holdHashMap.put(shareApp.getId(), convertView);
//}

// *********************************设置数据*****************************************************//


holder.nameTextView.setText(shareApp.getUserName());
holder.timeTextView.setText(StringUtil.getDateString(shareApp
.getTime(), true));


CharSequence convertContent = SmileyParser.getInstance()
.addSmileySpans(shareApp.getContent());
holder.summaryTextView.setText(convertContent);


holder.formTextView
.setText(SNSParam.FROM_STRING[shareApp.getFrom()]);


holder.retimeTextView.setText(StringUtil.getDateString(shareApp
.getLastpost(), true));


holder.iconImageView.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
home_setvisitor(shareApp.getUserId());
}
});


// 发表人头像
final ImageView iconImg = holder.iconImageView;
Bitmap iconBitmap = null;
if (AllMsgListManage.getInstance().userIcon.containsKey(shareApp
.getAvatarUrl())) {
iconBitmap = AllMsgListManage.getInstance().userIcon
.get(shareApp.getAvatarUrl());
} else {


if (iconBitmap == null) {// 如果缓存没有图片,自己去下载
iconBitmap = asyncImageLoader.loadBitmap(shareApp
.getAvatarUrl(), new ImageCallbackByAid() {


@Override
public void imageLoaded(Bitmap imageBitmap,
String imageUrl, int appAid) {
if (imageBitmap != null) {
try {
// 设置控件图片
iconImg.setImageBitmap(imageBitmap);
AllMsgListManage.getInstance().userIcon
.put(imageUrl, imageBitmap);


} catch (Exception e) {
e.printStackTrace();
}
}
}
}, false, 1);


}


}
if (iconBitmap != null) {
holder.iconImageView.setImageBitmap(iconBitmap);
} else {
holder.iconImageView
.setImageResource(R.drawable.default_people_icon);// 默认图片
}


// 回复人头像
final ImageView reIconImg = holder.reIconImageView;
Bitmap reIconBitmap = null;
if (AllMsgListManage.getInstance().userIcon.containsKey(shareApp
.getRepliesavatarUrl())) {
reIconBitmap = AllMsgListManage.getInstance().userIcon
.get(shareApp.getRepliesavatarUrl());
} else {
reIconBitmap = asyncImageLoader.loadBitmap(shareApp
.getRepliesavatarUrl(), new ImageCallbackByAid() {


@Override
public void imageLoaded(Bitmap imageBitmap,
String imageUrl, int appAid) {
if (imageBitmap != null) {
try {
// 设置控件图片
reIconImg.setImageBitmap(imageBitmap);
AllMsgListManage.getInstance().userIcon.put(
imageUrl, imageBitmap);


} catch (Exception e) {


e.printStackTrace();
}
}
}
}, false, 1);


}


if (reIconBitmap != null) {
holder.reIconImageView.setImageBitmap(reIconBitmap);
} else {
holder.reIconImageView
.setImageResource(R.drawable.default_people_icon);// 默认图片
}


// 附件图片
if (shareApp.getPictures().size() > 0) {


holder.summaryImageView.setVisibility(View.VISIBLE);
final ImageView ii = holder.summaryImageView;
Bitmap bitmap = null;
final String imgUrl = shareApp.getPictures().get(0).getThumb();
if (allImgHashMap.containsKey(imgUrl)) {
bitmap = allImgHashMap.get(imgUrl);
} else {


if (bitmap == null) {// 如果缓存没有图片,自己去下载
bitmap = asyncImageLoader.loadBitmap(imgUrl,
new ImageCallbackByAid() {


@Override
public void imageLoaded(Bitmap imageBitmap,
String imageUrl, int appAid) {
Log.d("showImg", imageUrl);
if (imageBitmap != null) {
try {
// 设置控件图片
ii.setImageBitmap(imageBitmap);
allImgHashMap.put(imageUrl,
imageBitmap);


} catch (Exception e) {


e.printStackTrace();
}
}
}
}, false, 1);


}


}
if (bitmap != null) {
holder.summaryImageView.setImageBitmap(bitmap);
} else {
holder.summaryImageView
.setImageResource(R.drawable.default_pc_icon);// 默认图片
}
} else {// 附件没有图片 隐藏该图片
holder.summaryImageView.setVisibility(View.GONE);
}


// 语音附件图片
if (shareApp.getVoices().size() > 0) {
holder.playVideoButton.setVisibility(View.VISIBLE);
// 后台下载语音数据,下载完毕可以点击按钮播放
final String voiceUrl = shareApp.getVoices().get(0)
.getFilepath();
final String savePath = VoiceManager
.getSavePathFromVoiceUrl(voiceUrl);
final File sdcardVoiceFile = new File(savePath);


if (!sdcardVoiceFile.exists() // sd卡没有保存录音
&& SystemUtil.isNetworkAvailable(SpaceShareActivity.this)
&& !StringUtil.isEmpty(voiceUrl)) {
asyncSoundLoader.loadSound(voiceUrl, savePath,
new SoundCallback() {
@Override
public void soundLoaded(File soundFile,
String soundUrl) {
}
});
}
holder.playVideoButton
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 播放语音
if (sdcardVoiceFile.exists()) {
playVoice(position, savePath, false);
} else if (SystemUtil
.isNetworkAvailable(SpaceShareActivity.this)) {
playVoice(position, voiceUrl, false);
}
}
});
} else {
holder.playVideoButton.setVisibility(View.GONE);
}


holder.reCountTextView.setText(new StringBuffer().append("转发/评论(")
.append(shareApp.getReplies()).append(")"));

return convertView;
}


public void update() {
this.notifyDataSetChanged();
}
}



/**
* 点击语音消息项,开始播放处理(模仿微信的语音动画处理)
*/
public void playVoice(final int position, String path, boolean myVoice) {
if (StringUtil.isEmpty(path)) {
Log.e("message", "onVoiceButtonClick: 无效语音 " + position + ", "
+ path);
return;
}


// 暂停老的
if (isPlaying) {
mediaPlayer.PlayStop();
// voicePlayingAnimateHandler
// .removeCallbacks(voicePlayingAnimateRunnable);
// endVoiceIcon();
isPlaying = false;
} else {
isPlaying = true;
mediaPlayer.PlayFromFileWithCallback(path, voicePrepareListener,
voiceCompletionListener);
}


// 播放新的语音
// playingPos = position;
// isMyVoice = myVoice;


}


private OnPreparedListener voicePrepareListener = new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaplayer) {
if (mediaplayer == null) {
return;
}
// 启动语音按钮的播放动画
// voicePlayingAnimateHandler.postDelayed(
// voicePlayingAnimateRunnable, ANIMATE_DELAY);
}
};
private OnCompletionListener voiceCompletionListener = new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (mp == null) {
return;
}


// 停止语音按钮的播放动画, 并播放结束音
// voicePlayingAnimateHandler
// .removeCallbacks(voicePlayingAnimateRunnable);
// endVoiceIcon();
SoundManager.playSoundByIndex(
SoundManager.SOUND_INDEX_VOICE_PLAY_COMPLETED, 1.0f, 1.0f);
isPlaying = false;
}
};


// 获取全站分享
private void share_getall() {
try {
int count = getShareList().size();
// if (count <= 0) {
// count = 0;
// }
ProgressDialogHint.Show(this, "提示", "获取帖子...");
GetAllShare sendMessage = new GetAllShare();
sendMessage.Request(this,userInfo.getUserId(), SNSParam.SHARE_MY_TYPE, count);
sendMessage.SetOnResultListener(new onGetAllShareListener() {


@Override
public int OnResultHandle(List<Share> list, int code, String msg) {
ProgressDialogHint.Dismiss();
if (code != RespondType.SUCCESS) {
if (code==SNSParam.NODATA) {
loadTextes(SNSParam.NOLIMIT);
}
if (code==SNSParam.error_logo2||code==SNSParam.error_logo9) {
return 0;
}
if (msg != null && !msg.equals(""))
ToastHint(msg);
else
ToastHint("获取帖子失败");


return 0;
} else {

try {
if (list.size() > 0) {
loadTextes(list.size());
setShareList(list);
shareListAdater.update();
}else {
loadTextes(SNSParam.LIMIT);
}


} catch (Exception e) {
e.printStackTrace();
loadTextes(SNSParam.LIMIT);
}


}


return 1;
}
});
} catch (Exception e) {
e.printStackTrace();
}
}


private void ToastHint(String hint) {
Toast.makeText(this, hint, Toast.LENGTH_SHORT).show();
}


@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.share_main_tab_my_back_Button:
finish();
break;
case R.id.share_main_tab_my_find_Button:
SendComment sendcommet=new SendComment();
sendcommet.setSendCommentType(RequestType.share_publish);
SendCommentActivity.actionSendCommen(this, sendcommet) ;
break;
case R.id.btn_more_bg_default_LinearLayout:
share_getallBtn();
break;
case R.id.btn_more_bg_default_TextView:
share_getallBtn();
break;
default:
break;
}
}


@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Share shareMsgs = getShareList().get(arg2);
// ShareMsgActivity.actionFriendDialogGo(this, shareMsgs);
share_getinfo(shareMsgs.getId(),arg2);
}

// 获取单挑分享
private void share_getinfo(long shareId, final int potion) {
try {
ProgressDialogHint.Show(this, "提示", "正在加载,请稍等...");
GetAllShareByShareId sendMessage = new GetAllShareByShareId();
sendMessage.Request(this, shareId);
sendMessage
.SetOnResultListener(new onGetAllShareByShareIdListener() {


@Override
public int OnResultHandle(Share shareMsgs, int code,
String msg) {
ProgressDialogHint.Dismiss();
if (code != RespondType.SUCCESS) {
if (code==SNSParam.error_logo2||code==SNSParam.error_logo9) {
return 0;
}
if (msg != null && !msg.equals(""))
ToastHint(msg);
else
ToastHint("加载失败");


return 0;
} else {
Share shareMsg=getShareList().get(potion);

shareMsg.setLastpost(shareMsgs.getLastpost());
shareMsg.setReplies(shareMsgs.getReplies());

shareListAdater.update();

ShareMsgActivity.actionFriendDialogGo(
SpaceShareActivity.this, shareMsgs);


}


return 1;
}
});
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) {
return;
}


share_getall();
}

/**
* 添加访客记录
*/
private void home_setvisitor(long userId) {
SpaceActivity.startActivity(this, 0);
}


// 获取全站分享
private void share_getallBtn() {
try {
loadText();
GetAllShare sendMessage = new GetAllShare();
int count = getShareList().size() ;
// if (count <= 0) {
// count = 0;
// }
sendMessage.Request(this,userInfo.getUserId(), SNSParam.SHARE_MY_TYPE, count);
sendMessage.SetOnResultListener(new onGetAllShareListener() {


@Override
public int OnResultHandle(List<Share> list, int code, String msg) {

if (code != RespondType.SUCCESS) {
if (code==SNSParam.NODATA) {
loadTextes(SNSParam.NOLIMIT);
}
if (code==SNSParam.error_logo2||code==SNSParam.error_logo9) {
return 0;
}
if (msg != null && !msg.equals(""))
ToastHint(msg);
else
ToastHint("获取分享失败");


return 0;
} else {
try {
if (list.size() > 0) {
loadTextes(list.size());
setShareList(list);
shareListAdater.update();
}else {
loadTextes(SNSParam.LIMIT);
}


} catch (Exception e) {
e.printStackTrace();
loadTextes(SNSParam.LIMIT);
}


}


return 1;
}
});
sendMessage.SetOnTimeoutListener(new HttpTimeoutListener() {


@Override
public int OnTimeoutHandle() {
loadTextes(SNSParam.LIMIT);
return 0;
}
}, 40000);
} catch (Exception e) {
e.printStackTrace();
}
}

private void loadText() {
isLoading = true;
footProgressBar.setVisibility(View.VISIBLE);
footTextView.setText("正在加载信息...");
footTextLayout.setVisibility(View.VISIBLE);
}


private void loadTextes(int count) {

isLoading = false;
footProgressBar.setVisibility(View.GONE);
footTextView.setText("获取更多");

if (count<SNSParam.LIMIT) {
footTextLayout.setVisibility(View.GONE);
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值