商場源碼 [復制鏈接]

2017-5-16 11:50
wy313622821 閱讀:1685 評論: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全天服務
意見反饋:[email protected]

掃一掃關注我們

Powered by Discuz! X3.2© 2001-2019 Comsenz Inc.( 粵ICP備15117877號 )

白沟网供网包牛牛 快乐8官网 广西快3是合法彩票吗 欢乐生肖超强计划 合买江西时时彩 广东11选五走势图开奖结果 河北11选5当天走势图 快中彩开奖号码 腾讯分分彩技巧栈泛云dx速12捷 云南11选5近100期开奖走势图 三分彩开奖