package com.da.lon.wang.xlg.activity;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import com.appkefu.lib.interfaces.KFAPIs;
import com.bumptech.glide.Glide;
import com.da.lon.wang.xlg.MyApplication;
import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.bean.CartNubBean;
import com.da.lon.wang.xlg.bean.DetailBean;
import com.da.lon.wang.xlg.bean.DetailBean.NomeList.Value;
import com.da.lon.wang.xlg.bean.DetailListBean;
import com.da.lon.wang.xlg.bean.IdsBean;
import com.da.lon.wang.xlg.bean.OrderListBean;
import com.da.lon.wang.xlg.bean.ZanBean;
import com.da.lon.wang.xlg.constants.PreferencesConfig;
import com.da.lon.wang.xlg.fragment.OneFragment;
import com.da.lon.wang.xlg.fragment.ThreeFragment;
import com.da.lon.wang.xlg.fragment.TwoFragment;
import com.da.lon.wang.xlg.http.HttpLoader;
import com.da.lon.wang.xlg.http.HttpLoader.OnWebLoadListener;
import com.da.lon.wang.xlg.util.BuyUtil;
import com.da.lon.wang.xlg.util.DialogUtil;
import com.da.lon.wang.xlg.util.PreferenceUtils;
import com.da.lon.wang.xlg.util.SingleManager;
import com.da.lon.wang.xlg.util.XLGDataUtils;
import com.da.lon.wang.xlg.view.CancelPopWindow;
import com.da.lon.wang.xlg.view.McoyProductContentPage;
import com.da.lon.wang.xlg.view.McoyProductDetailInfoPage;
import com.da.lon.wang.xlg.view.McoySnapPageLayout;
import com.da.lon.wang.xlg.view.MyViewPager;
import com.da.lon.wang.xlg.view.ProductsPopupWindow;
import com.da.lon.wang.xlg.view.QuestionPopupWindow;
import com.jauker.widget.BadgeView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.squareup.picasso.Picasso;
import com.umeng.analytics.MobclickAgent;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.TextUtils;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import net.tsz.afinal.http.AjaxParams;
public class ProductsActivity extends BaseActivity implements OnClickListener {
private HttpLoader<DetailListBean> loader;
private HttpLoader<OrderListBean> loader3;
private DetailBean bean = new DetailBean();
// private ImageLoader loader2;
private HttpLoader<ZanBean> loader4;
private HttpLoader<CartNubBean> loader5;
private HttpLoader<IdsBean> loader6;
private McoySnapPageLayout mcoySnapPageLayout = null;
private McoyProductContentPage bottomPage = null;
private McoyProductDetailInfoPage topPage = null;
private LinearLayout popupwindowLayout;
private ProductsPopupWindow contentWindow;
private QuestionPopupWindow questionWindow;
private CancelPopWindow cancelPopWindow;
private Button bottomLayout;
private View view;
private Context context;
private String product_number;
private List<Fragment> fragmentList;
private MyViewPager detailPager;
private TextView detailView1, detailView2, detailView3;
private ImageView img_line;
private int screenWidth;
private int currenttab = 0;
private MyViewPager pager;
private ImageView[] tips;
private TextView nameView;
private Button buyButton;
private LinearLayout topLayout;
private ImageButton backButton, smileButton, ringButton, shareButton;
private TextView collectBox;
private TextView cartView;
private Button addcartButton;
// 滑動條顏色
private int select_color;
private int unselect_color;
private int mScreen1_4;
/** 當前視圖寬度 **/
private Integer viewPagerW = 0;
private static int width = 0;
private OneFragment oneFragment;
private TwoFragment twoFragment;
private ThreeFragment threeFragment;
private DialogUtil dialogUtil;
String user_id = PreferenceUtils.getInstance().getSettingStr(PreferencesConfig.USER_ID, "");
String device_id = PreferenceUtils.getInstance().getSettingStr(PreferencesConfig.DEVICE_ID, "");
private String ids;
private ImageView imageView;
private boolean BackState =false;
private ArrayList<Fragment> arrayList;
public int index =1;
private FragmentTransaction ft;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.ouka_products_main);
buyButton = (Button) findViewById(R.id.ouka_products_bottom);
backButton = (ImageButton) findViewById(R.id.detail_back);
smileButton = (ImageButton) findViewById(R.id.detail_smile);
ringButton = (ImageButton) findViewById(R.id.detail_ring);
shareButton = (ImageButton) findViewById(R.id.detail_share);
collectBox = (TextView) findViewById(R.id.ouka_products_collect);
cartView = (TextView) findViewById(R.id.ouka_products_cart);
addcartButton = (Button) findViewById(R.id.ouka_products_addcart);
cartView.setOnClickListener(this);
addcartButton.setOnClickListener(this);
collectBox.setOnClickListener(this);
buyButton.setOnClickListener(this);
backButton.setOnClickListener(this);
smileButton.setOnClickListener(this);
ringButton.setOnClickListener(this);
shareButton.setOnClickListener(this);
topLayout = (LinearLayout) findViewById(R.id.detail_top);
topLayout.bringToFront();
context = this;
PreferenceUtils.getInstance().SetSettingString(PreferencesConfig.COUNT_NUMBER, "1");
String is_collect = PreferenceUtils.getInstance().getSettingStr(PreferencesConfig.IS_COLLECT, "");
if (is_collect.equals("")) {
Drawable drawable = getResources().getDrawable(R.drawable.ocoffee_collect_normal);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
collectBox.setCompoundDrawables(null, drawable, null, null);
} else {
if (is_collect.equals("1")) {
Drawable drawable = getResources().getDrawable(R.drawable.ocoffee_collect_pressed);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
collectBox.setCompoundDrawables(null, drawable, null, null);
} else {
Drawable drawable = getResources().getDrawable(R.drawable.ocoffee_collect_normal);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
collectBox.setCompoundDrawables(null, drawable, null, null);
}
}
dialogUtil = new DialogUtil(context);
initCart();
init();
}
private void initCart() {
// TODO Auto-generated method stub
loader5 = new HttpLoader<CartNubBean>(context, "http://api.ocoffee.cn/Cart-cartcount", CartNubBean.class,
60 * 1000);
AjaxParams params = new AjaxParams();
params.put("id", user_id);
params.put("deviceId", device_id);
params.put("token", XLGDataUtils.encrypt2MD5("Cart" + "2015#$%" + "cartcount"));
loader5.setManagerListener(new OnWebLoadListener<CartNubBean>() {
@Override
public void OnStart() {
// TODO Auto-generated method stub
dialogUtil.showDialog();
System.out.println("請求開始!");
}
@Override
public void OnError(String error) {
// TODO Auto-generated method stub
dialogUtil.dismissDialog();
System.out.println("請求錯誤!" + error);
}
@Override
public void onSuccess(CartNubBean t) {
// TODO Auto-generated method stub
dialogUtil.dismissDialog();
System.out.println("請求成功!");
if (t != null && t.getCode().equals("000000")) {
if (t.getResult().equals("0")) {
} else {
BadgeView badgeView = new BadgeView(context);
badgeView.setTargetView(cartView);
badgeView.setBadgeCount(Integer.parseInt(t.getResult()));
}
}
}
});
loader5.loadData(params);
}
@Override
protected void onResume() {
super.onResume();
MobclickAgent.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
MobclickAgent.onPause(this);
// Glide.clear(imageView);
// Glide.get(this).clearMemory();
// MyApplication.getWith().shutdown();
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
dialogUtil.dismissDialog();
this.setContentView(R.layout.empty_ll);
loader =null;
loader3=null;
loader4 =null;
loader5=null;
loader6=null;
topPage=null;
bottomPage =null;
view=null;
arrayList =null;
// System.gc();
}
private void init() {
// TODO Auto-generated method stub
product_number = PreferenceUtils.getInstance().getSettingStr(PreferencesConfig.PRODUCT_NUMBER, "");
loader = new HttpLoader<DetailListBean>(context, "http://api.ocoffee.cn/Product-details", DetailListBean.class,
60 * 1000);
AjaxParams params = new AjaxParams();
params.put("product_number", product_number);
params.put("token", XLGDataUtils.encrypt2MD5("Product" + "2015#$%" + "details"));
System.out.println("商品詳情介面請求:" + params);
loader.setManagerListener(new OnWebLoadListener<DetailListBean>() {
@Override
public void OnStart() {
// TODO Auto-generated method stub
dialogUtil.showDialog();
System.out.println("請求開始!");
}
uj5u.com熱心網友回復:
看代碼看不出來,把錯誤日志貼出來。uj5u.com熱心網友回復:
就是記憶體一直增加!uj5u.com熱心網友回復:
你這是圖片又多有大,導致加載時還沒有顯示就oom了,對圖片進行一次壓縮,優化一下,其他占用記憶體大的地方uj5u.com熱心網友回復:
最好把log發上來看一下,建議使用MAT工具分析下記憶體占用情況。涉及到加載drawable中圖片導致oom的話,可以看下這個http://blog.csdn.net/chniccs/article/details/51373623
uj5u.com熱心網友回復:
先把activity設定成singleTop不要每次啟動都重新創建,看能否解決這個問題。當然這個方法治標不治本,根本的問題還是要MAT分析下看是什么地方記憶體泄漏的把所有的清理回收資源的地方都注銷了是什么鬼?
// Glide.clear(imageView);
// Glide.get(this).clearMemory();
// MyApplication.getWith().shutdown();
// System.gc();
uj5u.com熱心網友回復:
貼 錯誤日志! 不貼日志 看不出!uj5u.com熱心網友回復:
MobclickAgentuj5u.com熱心網友回復:
首先成員變數在Destroy時置null是沒有任何作用的,垃圾回收正常情況一定會回收這些東西,無論你有沒有置null。垃圾回收無法回收的情況:靜態參考、無限handler、一些第三方sdk、網路請求一直等待不回傳、application類強參考。新手博客常見問題3有具體描述:https://blog.csdn.net/weimingjue/article/details/87921494
看你的成員變數里的東西,基本上是HttpLoader里面有問題,你貼一下這里的代碼。
還有寫這么多成員變數不累嗎,Destroy的時候setView不怕崩潰嗎
uj5u.com熱心網友回復:
還有命名、system.out等等就不多吐槽了轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/129098.html
標籤:Android
