商场源码 [复制链接]

2017-5-16 11:50
wy313622821 阅读:1631 评论:7 赞:5
基于安卓的京东商城高仿应用最新版项目源码,实现了首页、搜索页、商品分类页、购物页、个人中心的登录注册、应用设置页面的UI布局模仿。
UI仿照度可以达到80%.翻了翻源码看了一下实现了摇一摇抽奖,二维码扫描购物等功能。
其他功能暂时没有实现,只是纯布局。首页有可以手指拖动的3D商品轮播模块,翻转效果非常漂亮。
项目中的资源文件是扒的京东安卓客户端的皮。二维码用的zxing,最新的源码加入了二维码、登录效验、和启动页。
所用到的Activity比较多,这里只列出mainactivity的源码:

[代码]xml代码:

package com.baidayi.activity;

import java.util.Timer;
import java.util.TimerTask;

import com.baidayi.config.ConstantS;
import com.baidayi.fragment.FragmentIndicator;
import com.baidayi.fragment.FragmentIndicator.OnIndicateListener;
import com.baidayi.slidmenu.lib.SlidingMenu;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

/**
 * 主页面
 * 
 * @author: wll
 */
public class MainActivity extends FragmentActivity implements OnClickListener {

	public static Fragment[] mFragments;
	private boolean isExit = false;//是否退出
	private TimerTask timeTask = null;
	private SharedPreferences settings = null;
	private Timer timer = null;
	private SlidingMenu slidingMenu = null;
	private Intent intent;
	private View view;
	private RelativeLayout food_layout, clean_layout, day_layout,
			mother_layout, beauty_layout, life_layout, service_layout;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);

		// 创建一个新的非守护进程定时器
		timer = new Timer();

		slidingMenu = new SlidingMenu(this);
		slidingMenu.setMode(SlidingMenu.LEFT);// 侧滑菜单在左边
		slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); // 触摸边界拖出菜单
		slidingMenu.setClickable(true);
		slidingMenu.setMenu(R.layout.menu_sliding_left);// 侧滑菜单布局
		// 菜单,打开时,将留在屏幕的右侧该宽度余量。
		slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
		// 将抽屉菜单与主页面关联起来
		slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
		view = slidingMenu.getMenu();

		initview();

		// 保存用户名
		settings = getSharedPreferences(ConstantS.PREFS_NAME, 0);
		String UserName = settings.getString("UserName", null);
		if (UserName == null) {
			ImageView usericon = (ImageView) findViewById(R.id.fragment_dsx_pic);
			usericon.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent intent = new Intent();
					intent.setClass(getApplicationContext(),
							LoginActivity.class);
					startActivity(intent);
				}
			});
		}
		setFragmentIndicator(0);
	}

	/**
	 * 设置Fragment的指引器
	 * 
	 * @param whichIsDefault
	 */
	private void setFragmentIndicator(int whichIsDefault) {
		mFragments = new Fragment[4];
		mFragments[0] = getSupportFragmentManager().findFragmentById(
				R.id.fragment_home);
		mFragments[1] = getSupportFragmentManager().findFragmentById(
				R.id.fragment_buy);
		mFragments[2] = getSupportFragmentManager().findFragmentById(
				R.id.fragment_shopping);
		mFragments[3] = getSupportFragmentManager().findFragmentById(
				R.id.fragment_user);

		getSupportFragmentManager().beginTransaction().hide(mFragments[0])
				.hide(mFragments[1]).hide(mFragments[2]).hide(mFragments[3])
				.show(mFragments[whichIsDefault]).commit();

		FragmentIndicator mIndicator = (FragmentIndicator) findViewById(R.id.indicator);
		FragmentIndicator.setIndicator(whichIsDefault);
		mIndicator.setOnIndicateListener(new OnIndicateListener() {
			@Override
			public void onIndicate(View v, int which) {
				getSupportFragmentManager().beginTransaction()
						.hide(mFragments[0]).hide(mFragments[1])
						.hide(mFragments[2]).hide(mFragments[3])
						.show(mFragments[which]).commit();
			}
		});
	}

	@Override
	public void onBackPressed() {
		if (isExit) {
			finish();
		} else {
			isExit = true;
			Toast.makeText(MainActivity.this, "再按一次退出百大易商城", Toast.LENGTH_SHORT)
					.show();
			timeTask = new TimerTask() {

				@Override
				public void run() {
					isExit = false;
				}
			};
			timer.schedule(timeTask, 2000);
		}
	}

	// 初始化Fragment
	private void initview() {

		food_layout = (RelativeLayout) view.findViewById(R.id.food_layout);
		food_layout.setOnClickListener(this);

		clean_layout = (RelativeLayout) view.findViewById(R.id.clean_layout);
		clean_layout.setOnClickListener(this);

		day_layout = (RelativeLayout) view.findViewById(R.id.day_layout);
		day_layout.setOnClickListener(this);

		mother_layout = (RelativeLayout) view.findViewById(R.id.mother_layout);
		mother_layout.setOnClickListener(this);

		beauty_layout = (RelativeLayout) view.findViewById(R.id.beauty_layout);
		beauty_layout.setOnClickListener(this);

		life_layout = (RelativeLayout) view.findViewById(R.id.life_layout);
		life_layout.setOnClickListener(this);

		service_layout = (RelativeLayout) view
				.findViewById(R.id.service_layout);
		service_layout.setOnClickListener(this);

	}

	/**
	 * 侧滑菜单的点击事件
	 */
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.food_layout:
			intent = new Intent();
			intent.setClass(MainActivity.this, MenuFoodActivity.class);
			startActivity(intent);
			break;
		case R.id.clean_layout:
			intent = new Intent();
			intent.setClass(MainActivity.this, MenuCleanActivity.class);
			startActivity(intent);
			break;
		case R.id.day_layout:
			intent = new Intent();
			intent.setClass(MainActivity.this, MenuDayActivity.class);
			startActivity(intent);
			break;
		case R.id.mother_layout:
			intent = new Intent();
			intent.setClass(MainActivity.this, MenuMotherActivity.class);
			startActivity(intent);
			break;
		case R.id.beauty_layout:
			intent = new Intent();
			intent.setClass(MainActivity.this, MenuBeautyActivity.class);
			startActivity(intent);
			break;
		case R.id.life_layout:
			intent = new Intent();
			intent.setClass(MainActivity.this, MenuLifeActivity.class);
			startActivity(intent);
			break;
		case R.id.service_layout:
			intent = new Intent();
			intent.setClass(MainActivity.this, MenuServiceActivity.class);
			startActivity(intent);
			break;
		}
	}

}

下面来看看效果图:




我来说两句
您需要登录后才可以评论 登录 | 立即注册
facelist
所有评论(7)
九霄逆鳞 2017-5-16 18:14
不错,感谢分享商场源码。  楼主也可以去 精品源码区直接上传代码哟。
回复
zeki_10 2017-5-16 19:06
感谢分享
回复
到处是狼 2017-5-17 09:26
没有下载链接地址,差评
回复
花漫旧城夏天2 2017-5-17 11:54
源码呢。亲。
回复
0号凯迪 2017-5-18 10:10
可以可以,很详细.
回复
pawnluo 2017-5-20 10:26
geili
回复
ericshao 2017-5-29 08:57
感谢分享
回复
领先的中文移动开发者社区
18620764416
7*24全天服务
意见反馈:1294855032@qq.com

扫一扫关注我们

Powered by X3.2© 2001-2019 ( )

上海11选5 千禧彩票是真的吗 山东11选5 山东11选5走势 大乐购彩票计划群 山东11选5走势 山东11选5走势 上海11选5 北京极速赛车规律 北京极速赛车软件