DevStore首页 > DEV资源 > 源码下载 > 源码详情

仿糗事百科Android客户端源码

 
anitbird | 2014-09-27 17:33    浏览量(24181)    评论(118)    收藏(38)
功能分类:社交 支持平台:Android 运行环境:Eclipse
开发语言:Java 开发工具:Eclipse 源码大小:4.62MB
下载源码 4925 人下载

源码简介

仿糗事百科Android客户端

源码截图

  • 主页
  • 侧边栏
  • 登录
  • 个人中心
  • 附近的人
DevStore所有源码来自用户上传分享,版权问题及牵扯到商业纠纷均与DevStore无关。

源码片段

/**
 * 热门的fragment
 * */
public class HotFragment extends Fragment implements OnClickListener {

	private String hotUrl = Model.GANHUO;
	private int topMeunFlag = 1;
	private View view;
	private ImageView mTopImg;
	private ImageView mSendAshamed;
	private TextView mTopMenuOne, mTopMenuTwo, mTopMenuThree;
	private MyListView myListView;
	private LinearLayout mLinearLayout, load_progressBar;
	private TextView HomeNoValue;
	private HotFragmentCallBack mHotFragmentCallBack;
	private MyJson myJson = new MyJson();
	private List list = new ArrayList();
	private MyListAdapter mAdapter = null;
	private Button ListBottem = null;
	private int mStart = 0;
	private int mEnd = 5;
	private String url = null;
	private boolean flag = true;
	private boolean loadflag = false;
	private boolean listBottemFlag = true;
	private Context ctx;

	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.frame_home, null);
		ctx = view.getContext();
		myListView = new MyListView(ctx);
		initView();
		return view;
	}

	private void initView() {
		load_progressBar = (LinearLayout) view
				.findViewById(R.id.load_progressBar);
		mLinearLayout = (LinearLayout) view.findViewById(R.id.HomeGroup);
		myListView.setLayoutParams(new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.MATCH_PARENT,
				LinearLayout.LayoutParams.WRAP_CONTENT));
		myListView.setDivider(null);
		mLinearLayout.addView(myListView);
		mTopImg = (ImageView) view.findViewById(R.id.Menu);
		mSendAshamed = (ImageView) view.findViewById(R.id.SendAshamed);
		mTopMenuOne = (TextView) view.findViewById(R.id.TopMenuOne);
		mTopMenuTwo = (TextView) view.findViewById(R.id.TopMenuTwo);
		mTopMenuThree = (TextView) view.findViewById(R.id.TopMenuThree);
		HomeNoValue = (TextView) view.findViewById(R.id.HomeNoValue);
		mTopImg.setOnClickListener(this);
		mSendAshamed.setOnClickListener(this);
		mTopMenuOne.setOnClickListener(this);
		mTopMenuTwo.setOnClickListener(this);
		mTopMenuThree.setOnClickListener(this);
		createTextColor();
		switch (topMeunFlag) {
		case 1:
			mTopMenuOne.setTextColor(Color.WHITE);
			mTopMenuOne.setBackgroundResource(R.drawable.top_tab_active);
			break;
		case 2:
			mTopMenuTwo.setTextColor(Color.WHITE);
			mTopMenuTwo.setBackgroundResource(R.drawable.top_tab_active);
			break;
		case 3:
			mTopMenuThree.setTextColor(Color.WHITE);
			mTopMenuThree.setBackgroundResource(R.drawable.top_tab_active);
			break;
		}
		mAdapter = new MyListAdapter(ctx, list);
		ListBottem = new Button(ctx);
		ListBottem.setText("点击加载更多");
		ListBottem.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (flag && listBottemFlag) {
					url = hotUrl + "start=" + mStart + "&end=" + mEnd;
					ThreadPoolUtils.execute(new HttpGetThread(hand, url));
					listBottemFlag = false;
				} else if (!listBottemFlag)
					Toast.makeText(ctx, "正在加载中...", 1).show();
			}
		});
		myListView.addFooterView(ListBottem, null, false);
		ListBottem.setVisibility(View.GONE);
		myListView.setAdapter(mAdapter);
		myListView.setOnItemClickListener(new MainListOnItemClickListener());
		url = Model.GANHUO + "start=" + mStart + "&end=" + mEnd;
		ThreadPoolUtils.execute(new HttpGetThread(hand, url));
		myListView.setonRefreshListener(new OnRefreshListener() {

			@Override
			public void onRefresh() {

				if (loadflag == true) {
					mStart = 0;
					mEnd = 5;
					url = hotUrl + "start=" + mStart + "&end=" + mEnd;
					ListBottem.setVisibility(View.GONE);
					ThreadPoolUtils.execute(new HttpGetThread(hand, url));
					loadflag = false;
				} else {
					Toast.makeText(ctx, "正在加载中,请勿重复刷新", 1).show();
				}

			}
		});
	}

	@Override
	public void onClick(View arg0) {
		int mID = arg0.getId();
		switch (mID) {
		case R.id.Menu:
			mHotFragmentCallBack.callback(R.id.Menu);
			break;
		case R.id.SendAshamed:
			mHotFragmentCallBack.callback(R.id.SendAshamed);
			break;
		case R.id.TopMenuOne:
			createTextColor();
			mTopMenuOne.setTextColor(Color.WHITE);
			mTopMenuOne.setBackgroundResource(R.drawable.top_tab_active);
			if (topMeunFlag != 1) {
				hotUrl = Model.GANHUO;
				topMeunFlag = 1;
				createListModel();
			}
			break;
		case R.id.TopMenuTwo:
			createTextColor();
			mTopMenuTwo.setTextColor(Color.WHITE);
			mTopMenuTwo.setBackgroundResource(R.drawable.top_tab_active);
			if (topMeunFlag != 2) {
				hotUrl = Model.NENCAO;
				topMeunFlag = 2;
				createListModel();
			}
			break;
		case R.id.TopMenuThree:
			createTextColor();
			mTopMenuThree.setTextColor(Color.WHITE);
			mTopMenuThree.setBackgroundResource(R.drawable.top_tab_active);
			if (topMeunFlag != 3) {
				hotUrl = Model.WENZI;
				topMeunFlag = 3;
				createListModel();
			}
			break;
		default:
			break;
		}
	}

	private void createListModel() {
		ListBottem.setVisibility(View.GONE);
		mLinearLayout.setVisibility(View.GONE);
		load_progressBar.setVisibility(View.VISIBLE);
		loadflag = false;
		mStart = 0;
		mEnd = 5;
		url = hotUrl + "start=" + mStart + "&end=" + mEnd;
		ThreadPoolUtils.execute(new HttpGetThread(hand, url));
	}

	private class MainListOnItemClickListener implements OnItemClickListener {
		public void onItemClick(AdapterView arg0, View arg1, int arg2,
				long arg3) {
			Intent intent = new Intent(ctx, AshamedDetailActivity.class);
			Bundle bund = new Bundle();
			bund.putSerializable("AshamedInfo", list.get(arg2 - 1));
			intent.putExtra("value", bund);
			startActivity(intent);
		}
	}

	@SuppressWarnings("deprecation")
	private void createTextColor() {
		Drawable background = new BitmapDrawable();
		mTopMenuOne.setTextColor(Color.parseColor("#815F3D"));
		mTopMenuTwo.setTextColor(Color.parseColor("#815F3D"));
		mTopMenuThree.setTextColor(Color.parseColor("#815F3D"));
		mTopMenuOne.setBackgroundDrawable(background);
		mTopMenuTwo.setBackgroundDrawable(background);
		mTopMenuThree.setBackgroundDrawable(background);
		HomeNoValue.setVisibility(View.GONE);
	}

	public void setCallBack(HotFragmentCallBack mHotFragmentCallBack) {
		this.mHotFragmentCallBack = mHotFragmentCallBack;
	}

	public interface HotFragmentCallBack {
		public void callback(int flag);
	}

	Handler hand = new Handler() {
		public void handleMessage(android.os.Message msg) {
			super.handleMessage(msg);
			if (msg.what == 404) {
				Toast.makeText(ctx, "找不到地址", 1).show();
				listBottemFlag = true;
			} else if (msg.what == 100) {
				Toast.makeText(ctx, "传输失败", 1).show();
				listBottemFlag = true;
			} else if (msg.what == 200) {
				String result = (String) msg.obj;
				if (result != null) {
					List newList = myJson.getAshamedList(result);
					if (newList != null) {
						if (newList.size() == 5) {
							ListBottem.setVisibility(View.VISIBLE);
							mStart += 5;
							mEnd += 5;
						} else if (newList.size() == 0) {
							if (list.size() == 0)
								HomeNoValue.setVisibility(View.VISIBLE);
							ListBottem.setVisibility(View.GONE);
							Toast.makeText(ctx, "已经没有了...", 1).show();
						} else {
							ListBottem.setVisibility(View.GONE);
						}
						if (!loadflag) {
							list.removeAll(list);
						}
						for (AshamedInfo info : newList) {
							list.add(info);
						}
						listBottemFlag = true;
					} else {
						if (list.size() == 0)
							HomeNoValue.setVisibility(View.VISIBLE);
					}
				}
				mLinearLayout.setVisibility(View.VISIBLE);
				load_progressBar.setVisibility(View.GONE);
				myListView.onRefreshComplete();
				mAdapter.notifyDataSetChanged();
				loadflag = true;
			}
		};
	};

}
  •   赞(7) 赞 +1 赞(7) 已赞
  •   收藏(38) 收藏 +1 已收藏 取消
  •   下载(4925)
评论(118)
冬夜迷幻

冬夜迷幻 2018-07-08 18:37:46

不错,收藏下
回复(0) 赞(0) 赞(1)
玛丽大

玛丽大 2017-01-02 13:59:56

为什么都有错啊
回复(0) 赞(0) 赞(1)
Elijah

Elijah 2016-02-12 18:36:53

楼主,可以交个朋友么?
教教我,我新人不太会,有写地方不太明白
回复(0) 赞(0) 赞(1)
敲代码的球霸

敲代码的球霸 2015-12-15 09:07:28

不错,收藏下
回复(0) 赞(1) 赞(2)
等待11

等待11 2015-12-05 01:55:56

很不错 谢谢
回复(0) 赞(0) 赞(1)
  • 推荐
  • 审核
  • 收录
  • 获取活力值

源码上传作者

  • 32 能力值
  • 16 源码
  • 0 评测
  • 1 资料

热门源码