int mCount = 0;
public View getView(int position, View convertView, ViewGroup parent) {
if (position == 0){
mCount++;
}else{
mCount = 0;
}
if (mCount > 1){
if (view == null) {
view = mInflater.inflate(R.layout.item_search_video, null);
}
return view;
}
加个标签,判断一下就好了~
View mView0;
@Override
public View getView(int position, View view, ViewGroup parent) {
GameViewHolder holder = null;
final GameInfo gameInfo = mList.get(position);
final DownloadFileInfo downloadInfo = downloadManager.getDownloadInfoOtherPage(gameInfo.getApp_name());
if (view == null) {
view = mInflater.inflate(R.layout.item_game, null);
holder = onCreateViewHolder(position, view, parent);
view.setTag(holder);
if(position==0&&mView0==null){
mView0=view;
}
}
if(position==0){
view=mView0;//保证position 0的view是一个 这样会导致其他的view 空白
}
holder = (GameViewHolder) view.getTag();
holder.update(downloadInfo);
holder.gameInfo = gameInfo;
onBindViewHolder(holder, position);
// holder.refresh();
return view;
}
if(position==0&&parent instanceof AbsListView){
AbsListView absListView= (AbsListView) parent;
absListView.setRecyclerListener(new AbsListView.RecyclerListener() {
@Override
public void onMovedToScrapHeap(View view) {
if (view==)//不知道这个能否起作用,是否能辨识出position 0中的view是否是真正在展示的view。
}
});
}
package com.gevek.appstore.adapter;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.baidu.mobstat.StatService;
import com.gevek.appstore.R;
import com.gevek.appstore.domain.DownloadVo;
import com.gevek.appstore.domain.GameInfo;
import com.gevek.appstore.domain.User;
import com.gevek.appstore.domain.VRGameContent;
import com.gevek.appstore.global.AppConfig;
import com.gevek.appstore.global.Constant;
import com.gevek.appstore.http.MyBaseHttpRequestCallback;
import com.gevek.appstore.http.MyHttpCycleContext;
import com.gevek.appstore.response.DownloadResponse;
import com.gevek.appstore.ui.activity.GameDetailInfoActivity;
import com.gevek.appstore.ui.activity.GevekVRCinemaActivity;
import com.gevek.appstore.ui.view.RoundProgressBar;
import com.gevek.appstore.utils.CustomToast;
import com.gevek.appstore.utils.DialogHelp;
import com.gevek.appstore.utils.FileUtil;
import com.gevek.appstore.utils.GevekLog;
import com.gevek.appstore.utils.GsonTools;
import com.gevek.appstore.utils.Helper;
import com.gevek.appstore.utils.LiteOrmDBUtil;
import com.gevek.appstore.utils.OpenFile;
import com.gevek.appstore.utils.PackageLocalManage;
import com.gevek.appstore.utils.UIHelper;
import com.gevek.appstore.utils.downloadtool.DownloadFileInfo;
import com.gevek.appstore.utils.downloadtool.DownloadFileManager;
import com.gevek.appstore.utils.downloadtool.DownloadState;
import com.gevek.appstore.utils.downloadtool.DownloadViewHolder;
import com.gevek.appstore.utils.statisticstool.GetPhoneInfo;
import com.gevek.appstore.utils.statisticstool.RecordAction;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import org.json.JSONException;
import org.json.JSONObject;
import org.kymjs.kjframe.KJHttp;
import org.kymjs.kjframe.http.HttpCallBack;
import org.kymjs.kjframe.http.HttpConfig;
import org.kymjs.kjframe.http.HttpParams;
import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.StringUtils;
import org.xutils.DbManager;
import org.xutils.common.Callback;
import org.xutils.common.util.LogUtil;
import org.xutils.ex.DbException;
import java.io.File;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import cn.finalteam.loadingviewfinal.GridViewSupport;
import cn.finalteam.okhttpfinal.HttpRequest;
import cn.finalteam.okhttpfinal.RequestParams;
import static com.gevek.appstore.utils.DialogHelp.getConfirmDialog;
public class GameGridAdapter extends GameCommonBaseAdapter
{
private DbManager db;
private MyHttpCycleContext mContext;
private DownloadFileManager downloadManager;
private ExecutorService pool = Executors.newFixedThreadPool(20);
private VRGameContent game;
private User user;
volatile boolean isAlive;
public void onDestroy() {//解决内存泄漏问题
isAlive = false;
pool.shutdownNow();
mContext = null;
if (downloadManager != null) {
downloadManager.clearViewHolder();
}
}
public GameGridAdapter(MyHttpCycleContext httpCycleContext, List list) {
super(httpCycleContext, list);
mContext = httpCycleContext;
downloadManager = DownloadFileManager.getInstance();
db = DownloadFileManager.getDownLoadDb();
user = UIHelper.getUser(mContext.getContext());
}
public GameViewHolder onCreateViewHolder(int position, View view, ViewGroup parent) {
final GameInfo gameInfo = mList.get(position);
final DownloadFileInfo downloadInfo = downloadManager.getDownloadInfoOtherPage(gameInfo.getApp_name());
GameViewHolder viewHolder = new GameViewHolder(view, downloadInfo, gameInfo);
return viewHolder;
}
public void onBindViewHolder(GameViewHolder holder,int position, View view, ViewGroup parent) {
final GameInfo gameInfo = mList.get(position);
final DownloadFileInfo downloadInfo = downloadManager.getDownloadInfoOtherPage(gameInfo.getApp_name());
final int mGameType = gameInfo.getType().equals("game") ? 0 : 1;
holder.previewRl.setVisibility(View.GONE);
if (downloadInfo != null) {
holder.downloadbar.setDownloadState(downloadInfo.getState());
holder.downloadbar.setProgress(downloadInfo.getProgress());
holder.download.setBackgroundResource(R.color.trans_parent);
}
ImageLoader.getInstance().displayImage(gameInfo.getIcon(), holder.gameicon, new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.game_logo_bg)
.showImageOnFail(R.drawable.game_logo_bg)
.showImageOnLoading(R.drawable.game_logo_bg)
.cacheInMemory(true)
.cacheOnDisk(true)
.build());
holder.view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext.getContext(), GameDetailInfoActivity.class);
intent.putExtra("gameinfo", gameInfo);
intent.putExtra("gametype", mGameType);
mContext.getContext().startActivity(intent);
}
});
holder.gamename.setText(gameInfo.getApp_name());
holder.gamesize.setText(FileUtil.formatFileSize(Integer.valueOf(gameInfo.getSoft_size().trim())));
holder.preview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (StringUtils.isEmpty(gameInfo.getMovieurl())) {
ViewInject.toast("该游戏暂时没有视频预览");
} else {
if (!Helper.checkConnection(mContext.getContext())) {
ViewInject.toast(mContext.getContext(), "网络未连接");
} else if (!Helper.isWifi(mContext.getContext())) {
getConfirmDialog(mContext.getContext(), "温馨提示", "当前网络是移动网络,是否继续播放?", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// playVideo(gameInfo.getMovieurl());
playVideo(gameInfo);
}
}).show();
} else {
playVideo(gameInfo);
}
}
}
});
if (Integer.valueOf(gameInfo.getAdapter_need()) == 1) {
holder.mHandle.setVisibility(View.VISIBLE);
} else {
holder.mHandle.setVisibility(View.GONE);
}
if (!gameInfo.getStar().equals("")) {
float f = Float.parseFloat(gameInfo.getStar());
holder.ratingbar.setRating(f);
}
// MyDownLoadThread down = new MyDownLoadThread(holder.downloadbar, holder.download, downloadInfo, gameInfo, holder.installflag);
holder.download.setAlpha(1);
if (gameInfo.getAllow().equals("0")) {
holder.installflag.setText("即将上线");
holder.downloadbar.setImageResource(R.drawable.btn_down_n);
holder.download.setClickable(false);
holder.download.setAlpha(0.5f);
holder.download.setBackgroundResource(R.color.trans_parent);
} else {
if (PackageLocalManage.isInstalled(mContext.getContext(), gameInfo.getPackage_name())) {
try {
holder.installflag.setText("已安装");
holder.download.setBackgroundResource(R.drawable.selector_download_success);
holder.downloadbar.setProgress(100);
holder.download.setClickable(false);
holder.downloadbar.setDownloadState(DownloadState.FINISHED);
} catch (Exception e) {
e.printStackTrace();
}
} else {
String target = AppConfig.GAMEPATH + gameInfo.getApp_name() + "."
+ gameInfo.getFormat_classify();
if (FileUtil.checkFilePathExists(target)) {
holder.installflag.setText("安装");
holder.downloadbar.setProgress(100);
holder.download.setBackgroundResource(R.drawable.btn_install);
holder.downloadbar.setApkInstallState();
} else {
if (downloadInfo != null) {
try {
holder.download.setBackgroundResource(R.color.trans_parent);
DownloadState state = downloadInfo.getState();
holder.downloadbar.setDownloadState(state);
holder.downloadbar.setProgress(downloadInfo.getProgress());
switch (state) {
case WAITING:
holder.installflag.setText("等待中");
break;
case STARTED:
holder.installflag.setText("下载中");
break;
case STOPPED:
holder.installflag.setText("暂停中");
break;
case FINISHED:
holder.installflag.setText("安装");
holder.downloadbar.setProgress(100);
holder.download.setBackgroundResource(R.drawable.btn_install);
holder.downloadbar.setApkInstallState();
break;
case ERROR:
holder.installflag.setText("重试");
break;
default:
holder.installflag.setText("暂停中");
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (downloadInfo != null) {
holder.download.setBackgroundResource(R.color.trans_parent);
DownloadState state = downloadInfo.getState();
holder.downloadbar.setDownloadState(state);
holder.downloadbar.setProgress(downloadInfo.getProgress());
} else {
if (!PackageLocalManage.isInstalled(mContext.getContext(), gameInfo.getPackage_name())) {
holder.downloadbar.setProgress(0);
holder.downloadbar.setDownloadState(DownloadState.STOPPED);
holder.downloadbar.setImageResource(R.drawable.btn_down_n);
holder.installflag.setText("下载");
holder.download.setBackgroundResource(R.drawable.btn_down_n);
holder.download.setAlpha(1);
}
}
}
}
if (position == 0){
mCount++;
}else{
mCount = 0;
}
if (mCount > 1&&view!=null){
LogUtil.e("mCount > 1 and view=="+view);
return ;
}
// // Patch for multiple getView for position 0
// if(position==0 && parent instanceof AdapterView){
// AdapterView viewGrid= (AdapterView) parent;
// LogUtil.e("FirstVisible position=="+viewGrid.getFirstVisiblePosition());//回滚时判断不准
// if(view!=null&& viewGrid.getFirstVisiblePosition()>1){
// }
// }
// if(position==0&&lastPosition!=1&&view!=null){//这个条件不对
// LogUtil.e("astPosition!=1");
// lastPosition=position;
// return view;
// }
// if(position==0&&view!=null&&view0!=view){//这样就会重复
// LogUtil.e(String.format("invalid postion 0 view==%s,\nview0==%s",view,view0));
//
//// return view;
// view=view0;
// }
// if(position==0){
// if(view0==null){
// view0 = mInflater.inflate(R.layout.item_game, null);
// view=view0;
// holder = onCreateViewHolder(position, view, parent);
// view.setTag(holder);
// }
// view=view0;
// }
/* if(position==0 && parent instanceof AdapterView){
AdapterView viewGrid= (AdapterView) parent;
LogUtil.e("FirstVisible position=="+viewGrid.getFirstVisiblePosition());//回滚时判断不准
if(parent instanceof GridViewSupport){
GridViewSupport gridViewSupport= (GridViewSupport) parent;
LogUtil.e(String.format("headview count==%s,numColums==%s",gridViewSupport.getHeaderViewCount(),gridViewSupport.getNumColumns()));
// if(view!=null){
// try {
// LogUtil.e(String.format("headview getRowHeight==%s",gridViewSupport.getRowHeight()));//stackoverflow
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
}
if(view!=null&& viewGrid.getFirstVisiblePosition()>1){
LogUtil.e("无效的 view");
return;
}
}*/
if(position==0&&){
}
if (downloadInfo != null && (downloadInfo.getState().equals(DownloadState.STARTED) || downloadInfo.getState().equals(DownloadState.WAITING))) {
try {
holder.startDownload();
} catch (Exception e) {
}
}
}
}
/**
* 正式播放视频
*
* @param gameInfo
*/
// public void playVideo(String moviePath) {
public void playVideo(GameInfo gameInfo) {
Intent intent = new Intent();
intent.putExtra("movieType", "1");
// intent.putExtra("moviePath", moviePath);
intent.putExtra("moviePath", gameInfo.getMovieurl());
intent.setClass(mContext.getContext(), GevekVRCinemaActivity.class);
intent.putExtra(GevekVRCinemaActivity.VIDEO_TITLE, gameInfo.getApp_name());
intent.putExtra(GevekVRCinemaActivity.PIC_PATH, gameInfo.getIcon());
mContext.getContext().startActivity(intent);
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
mCount=0;
}
int mCount = 0;
@Override
public View getView(int position, View view, ViewGroup parent) {
GameViewHolder holder = null;
final GameInfo gameInfo = mList.get(position);
final DownloadFileInfo downloadInfo = downloadManager.getDownloadInfoOtherPage(gameInfo.getApp_name());
LogUtil.e(String.format("gamegridadapter getView position==%s,view==%s",position,view));
if (view == null) {
view = mInflater.inflate(R.layout.item_game, null);
holder = onCreateViewHolder(position, view, parent);
view.setTag(holder);
} else {
holder = (GameViewHolder) view.getTag();
holder.update(downloadInfo);
}
holder.gameInfo = gameInfo;
onBindViewHolder(holder, position,view,parent);
if(position==0){
LogUtil.e("postion 0 view=="+view);
// holder.resetViewHolder(view,downloadInfo,gameInfo);
// view.setTag(holder);
}
return view;
}
class GameViewHolder extends DownloadViewHolder implements View.OnClickListener {
ImageView gameicon;
TextView gamename;
TextView gamesize, installflag;
ImageView mHandle;
ImageButton preview;
Button download;
RatingBar ratingbar;
RoundProgressBar downloadbar;
RelativeLayout previewRl;
View view;
GameInfo gameInfo;
public GameViewHolder(View view, DownloadFileInfo downloadFileInfo, GameInfo gameInfo) {
super(view, downloadFileInfo);
this.view = view;
this.gameInfo = gameInfo;
previewRl = (RelativeLayout) view.findViewById(R.id.rl_preview);
gameicon = (ImageView) view.findViewById(R.id.iv_gameicon);
gamename = (TextView) view.findViewById(R.id.tv_gamename);
gamesize = (TextView) view.findViewById(R.id.tv_gamesize);
mHandle = (ImageView) view.findViewById(R.id.iv_handle);
preview = (ImageButton) view.findViewById(R.id.btn_preview);
ratingbar = (RatingBar) view.findViewById(R.id.ratingbar);
download = (Button) view.findViewById(R.id.btn_download);
downloadbar = (RoundProgressBar) view.findViewById(R.id.pb_downloadbar);
installflag = (TextView) view.findViewById(R.id.tv_install_flag);
download.setOnClickListener(this);
downloadbar.setMax(100);
}
public void resetViewHolder(View view, DownloadFileInfo downloadFileInfo, GameInfo gameInfo) {
this.downloadFileInfo=downloadFileInfo;
this.view = view;
this.gameInfo = gameInfo;
previewRl = (RelativeLayout) view.findViewById(R.id.rl_preview);
gameicon = (ImageView) view.findViewById(R.id.iv_gameicon);
gamename = (TextView) view.findViewById(R.id.tv_gamename);
gamesize = (TextView) view.findViewById(R.id.tv_gamesize);
mHandle = (ImageView) view.findViewById(R.id.iv_handle);
preview = (ImageButton) view.findViewById(R.id.btn_preview);
ratingbar = (RatingBar) view.findViewById(R.id.ratingbar);
download = (Button) view.findViewById(R.id.btn_download);
downloadbar = (RoundProgressBar) view.findViewById(R.id.pb_downloadbar);
installflag = (TextView) view.findViewById(R.id.tv_install_flag);
downloadbar.setMax(100);
}
@Override
public void onWaiting() {
GevekLog.d("onWaiting");
refreshViewState();
}
@Override
public void onStarted() {
GevekLog.d("onStarted");
refreshViewState();
}
@Override
public void onLoading(long total, long current) {
GevekLog.d("onLoading");
refreshViewState();
}
@Override
public void onSuccess(File result) {
GevekLog.d("onSuccess");
refreshViewState();
}
@Override
public void onError(Throwable ex, boolean isOnCallback) {
GevekLog.d("onError");
refreshViewState();
}
@Override
public void onCancelled(Callback.CancelledException cex) {
GevekLog.d("onCancelled");
refreshViewState();
}
void refreshViewState() {
GevekLog.e("gamegrid adapter refreshViewState downloadFileInfo ==" +
(downloadFileInfo == null ? "null" : downloadFileInfo.toString())
);
LogUtil.e("refreshViewState downloadBtn=="+download);
if (downloadFileInfo == null) {
downloadFileInfo = downloadManager.getDownloadInfoOtherPage(gameInfo.getApp_name());
} else {
GameViewHolder holder = this;
try {
DownloadState state = downloadFileInfo.getState();
holder.downloadbar.setDownloadState(state);//view有时不刷新
holder.downloadbar.setProgress(downloadFileInfo.getProgress());
// holder.downloadbar.invalidate();
switch (state) {
case WAITING:
holder.installflag.setText("等待中");
break;
case STARTED:
holder.installflag.setText("下载中");
// view.invalidate();
break;
case STOPPED:
holder.installflag.setText("暂停中");
break;
case FINISHED:
downloadManager.checkDownloadInfo(downloadFileInfo);
holder.installflag.setText("安装");
holder.downloadbar.setProgress(100);
// holder.download.setBackgroundResource(R.drawable.btn_install);
holder.downloadbar.setApkInstallState();
// isStart=false;
break;
case ERROR:
holder.installflag.setText("重试");
break;
default:
holder.installflag.setText("暂停中");
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public void onClick(final View v) {
String target = AppConfig.GAMEPATH + gameInfo.getApp_name() + "."
+ gameInfo.getFormat_classify();
if (!FileUtil.checkFilePathExists(target)) {
if (!Helper.checkConnection(mContext.getContext())) {
ViewInject.toast(mContext.getContext(), "网络未连接");
} else if (!Helper.isWifi(mContext.getContext())) {
getConfirmDialog(mContext.getContext(), "温馨提示", "当前网络是移动网络,是否继续下载?", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// startDownLoad();
toggleEvent(v);
}
}).show();
} else {
toggleEvent(v);
}
} else if (!installflag.getText().toString().equals("已安装")) {
try {
Intent intent = OpenFile.openFile(target);
mContext.getContext().startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
} else if (installflag.getText().toString().equals("已安装")) {
return;
}
}
private void toggleEvent(View view) {
GevekLog.e("toggleEvent downloadFileInfo ==" +
(downloadFileInfo == null ? "null" : downloadFileInfo.toString())
);
LogUtil.e("toggleEvent downloadBtn=="+view);
// notifyDataSetChanged();//刷新ui
download.setBackgroundResource(R.color.transparent);
if (downloadFileInfo == null) {
String target = AppConfig.GAMEPATH + gameInfo.getApp_name() + "."
+ gameInfo.getFormat_classify();
installflag.setText("下载中");
try {
StatService.onEvent(mContext.getContext(), "gamedownload", gameInfo.getApp_name(), 1);
user = UIHelper.getUser(mContext.getContext());
if (user != null)
RecordAction.toRecordAction(mContext.getContext(), "gamedownload", GetPhoneInfo.getPhoneImei(mContext.getContext()), user.getId(), gameInfo.getId(), gameInfo.getType());
DownloadFileManager.getInstance().startDownload(gameInfo.getApp_name(), gameInfo.getFormat_classify(), "0", gameInfo.getPackage_name(), gameInfo.getIcon(),
gameInfo.getDownurl(), gameInfo.getApp_name(),
target, gameInfo.getId(), gameInfo.getType(),
true, false, this);
if (gameInfo.getConfig() != null) {
VRGameContent vrGameContent = gameInfo.getConfig();
vrGameContent.setIsvr("yes");
vrGameContent.setDate(new Date(System.currentTimeMillis()));
if (gameInfo.getType().equals("game")) {
vrGameContent.setStyle("ture");
vrGameContent.setIsswitch(1);
} else {
vrGameContent.setStyle("false");
vrGameContent.setIsswitch(0);
}
vrGameContent.setIsswitch(1);
vrGameContent.setDate(new Date(System.currentTimeMillis()));
LiteOrmDBUtil.savegemcontent(vrGameContent);
}
DialogHelp.showDownloadDialog(mContext.getContext());
} catch (DbException e) {
e.printStackTrace();
}
} else {
if (downloadbar.getDownloadState() == DownloadState.FINISHED) {
if (!PackageLocalManage.isInstalled(mContext.getContext(), downloadFileInfo.getPackageName())) {
try {
Intent intent = OpenFile.openFile(downloadFileInfo.getFileSavePath());
mContext.getContext().startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (downloadbar.getDownloadState() == DownloadState.WAITING
|| downloadbar.getDownloadState() == DownloadState.STARTED) {
downloadbar.setDownloadState(DownloadState.STOPPED);
downloadManager.stopDownload(downloadFileInfo);
installflag.setText("暂停中");
} else if (downloadFileInfo.getState() == DownloadState.ERROR) {
// String type=downloadFileInfo.getDownloadType();
String type = gameInfo.getType();
RequestParams params = new RequestParams(mContext);
params.addFormDataPart("id", downloadFileInfo.getGameOrVideoId());
params.addFormDataPart("type", type);
HttpRequest.post(Constant.getdownurl,
params, new MyBaseHttpRequestCallback() {
@Override
public void onStart() {
super.onStart();
downloadbar.setDownloadState(DownloadState.STARTED);
installflag.setText("下载中");
downloadbar.setProgress(0);
}
@Override
public void onLogicSuccess(DownloadResponse downloadResponse) {
super.onLogicSuccess(downloadResponse);
DownloadVo downloadVo = downloadResponse.getData();
String mNewDownloadUrl = downloadVo.getDownurl();
GevekLog.e("mNewDownloadUrl==" + mNewDownloadUrl);
if (TextUtils.isEmpty(mNewDownloadUrl)) {
mNewDownloadUrl = downloadVo.getDownurl2();
}
try {
downloadFileInfo.setUrl(mNewDownloadUrl);
db.update(downloadFileInfo);
downloadbar.setDownloadState(DownloadState.STARTED);
installflag.setText("下载中");
downloadbar.setProgress(downloadFileInfo.getProgress());
startDownload();
} catch (Exception e) {
e.printStackTrace();
onDowloadFailed();
}
}
@Override
public void onLogicFailure(DownloadResponse stringResponse) {
super.onLogicFailure(stringResponse);
onDowloadFailed();
}
@Override
public void onFailure(int errorCode, String msg) {
super.onFailure(errorCode, msg);
onDowloadFailed();
}
@Override
public void onFinish() {
super.onFinish();
}
});
} else {
downloadbar.setProgress(downloadFileInfo.getProgress());
downloadbar.setDownloadState(DownloadState.STARTED);
installflag.setText("下载中");
startDownload();
}
}
}
private void onDowloadFailed() {
CustomToast.showShortTost("下载失败");
downloadbar.setDownloadState(DownloadState.ERROR);
installflag.setText("重试");
}
private void startDownload() {
try {
downloadManager.startDownload(
downloadFileInfo.getFileName(),
downloadFileInfo.getFileType(),
downloadFileInfo.getScreenType(),
downloadFileInfo.getPackageName(),
downloadFileInfo.getIconUrl(),
downloadFileInfo.getUrl(),
downloadFileInfo.getLabel(),
downloadFileInfo.getFileSavePath(),
downloadFileInfo.getGameOrVideoId(),
downloadFileInfo.getDownloadType(),
downloadFileInfo.isAutoResume(),
downloadFileInfo.isAutoRename(),
this);
} catch (DbException ex) {
ex.printStackTrace();
onDowloadFailed();
}
}
}
private void requestPackgename(final String pakname) {
HttpConfig config = new HttpConfig();
KJHttp kjh = new KJHttp(config);
HttpParams params = new HttpParams();
params.put("package", pakname);
kjh.post(Constant.packge, params, new HttpCallBack() {
@Override
public void onSuccess(Map headers, byte[] t) {
if (t != null) {
String str = new String(t);
try {
JSONObject object = new JSONObject(str);
if (0 == object.getInt("errno")) {
String json = object.getString("data");
game = GsonTools.changeGsonToBean(json, VRGameContent.class);
game.setIsvr("yes");
if (game.getStyle().equals("false")) {
game.setIsswitch(0);
} else {
game.setIsswitch(1);
}
LiteOrmDBUtil.savegemcontent(game);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onFailure(int errorNo, String strMsg) {
}
});
}
}