报错。

This commit is contained in:
qinjiaming_branch 2016-08-30 09:02:07 +08:00
parent e929b22f5e
commit 424ec44904
203 changed files with 2 additions and 9953 deletions

View File

@ -3,8 +3,8 @@
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -1,75 +0,0 @@
package com.stone.shop.adapter;
import java.util.Iterator;
import java.util.List;
import com.stone.shop.R;
import com.stone.shop.model.BXTNews;
import com.stone.shop.model.Good;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
/**
* 教学类-博学堂-讲座列表适配器
*
* @date 2014-5-10
* @author Stone
*/
public class BXTListAdapter extends BaseAdapter {
private Context mContext;
private List<BXTNews> mNewsList; // 商品列表信息
private LayoutInflater mInflater = null;
public BXTListAdapter(Context context, List<BXTNews> newsList) {
mContext = context;
mNewsList = newsList;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mNewsList.size();
}
@Override
public Object getItem(int position) {
return mNewsList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
// 刷新列表中的数据
public void refresh(List<BXTNews> list) {
Log.i("BXTNewsAdapter", "Adapter刷新数据");
mNewsList = list;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
BXTNewsHolder newsHolder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.bxt_list_item, null);
newsHolder = new BXTNewsHolder();
newsHolder.tvBXTNewsTitle = (TextView) convertView
.findViewById(R.id.tv_bxt_news_item_title);
convertView.setTag(newsHolder);
} else {
newsHolder = (BXTNewsHolder) convertView.getTag();
}
newsHolder.tvBXTNewsTitle.setText(mNewsList.get(position).getTitle());
return convertView;
}
}

View File

@ -1,69 +0,0 @@
package com.stone.shop.adapter;
import java.util.List;
import com.stone.shop.R;
import com.stone.shop.model.Classroom;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class ClassroomAdapter extends BaseAdapter {
private Context mContext;
private List<Classroom> mNewsList; // 商品列表信息
private LayoutInflater mInflater = null;
public ClassroomAdapter(Context context, List<Classroom> newsList) {
mContext = context;
mNewsList = newsList;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mNewsList.size();
}
@Override
public Object getItem(int position) {
return mNewsList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
// 刷新列表中的数据
public void refresh(List<Classroom> list) {
mNewsList = list;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.gv_item_classroom, null);
viewHolder = new ViewHolder();
viewHolder.tv_chooseText = (TextView) convertView.findViewById(R.id.tv_chooseText);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.tv_chooseText.setText(mNewsList.get(position).getName());
return convertView;
}
class ViewHolder {
public TextView tv_chooseText; // 博学堂讲座标题
}
}

View File

@ -1,70 +0,0 @@
package com.stone.shop.adapter;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import com.stone.shop.R;
import com.stone.shop.model.Good;
public class GoodsListAdapter extends BaseAdapter {
private Context mContext;
private List<Good> mGoodsList; // 商品列表信息
private LayoutInflater mInflater = null;
public GoodsListAdapter(Context context, List<Good> goodsList) {
mContext = context;
mGoodsList = goodsList;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mGoodsList.size();
}
@Override
public Object getItem(int position) {
return mGoodsList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
// 刷新列表中的数据
public void refresh(List<Good> list) {
mGoodsList = list;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
GoodsHolder goodHolder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.goods_list_item, null);
goodHolder = new GoodsHolder();
goodHolder.tvName = (TextView) convertView
.findViewById(R.id.tv_good_name);
goodHolder.tvPrice = (TextView) convertView
.findViewById(R.id.tv_good_price);
goodHolder.btnBuyGood = (TextView) convertView
.findViewById(R.id.btn_buy_good);
convertView.setTag(goodHolder);
} else {
goodHolder = (GoodsHolder) convertView.getTag();
}
goodHolder.tvName.setText(mGoodsList.get(position).getName());
goodHolder.tvPrice.setText("¥"+mGoodsList.get(position).getPrice());
return convertView;
}
}

View File

@ -1,114 +0,0 @@
package com.stone.shop.adapter;
import android.R.integer;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.stone.date.TypeDef;
import com.stone.shop.R;
/**
* 生活-- 网格布局(ImageView+TextView)适配器
*
* @date 2014-4-24
* @author Stone
*/
public class GridAdapter extends BaseAdapter {
private Context mContext;
private int mIndex = 0; // 代表当前需要适配页面中第几个GridView
//学习小菜
public static String[] mSchoolTexts = TypeDef.typeSonList1;
private int[] mSchoolImages = { R.drawable.ic_81, R.drawable.ic_82, R.drawable.ic_8 };
//吃饭小菜
public static String[] mFoodTexts = TypeDef.typeSonList2;
private int[] mFoodImages = { R.drawable.ic_41, R.drawable.ic_42};
//购物小菜
public static String[] mGiftTexts = TypeDef.typeSonList3;
private int[] mGiftImages = { R.drawable.ic_71, R.drawable.ic_72,
R.drawable.ic_73, R.drawable.ic_74, R.drawable.ic_75,
R.drawable.ic_76, R.drawable.ic_77};
//疯狂小菜
public static String[] mOutTexts = TypeDef.typeSonList4;
private int[] mOutImages = { R.drawable.ic_3, R.drawable.ic_3,
R.drawable.ic_3, R.drawable.ic_3, R.drawable.ic_3,
R.drawable.ic_3, R.drawable.ic_3 };
public GridAdapter(Context context, int index) {
mContext = context;
mIndex = index;
}
@Override
public int getCount() {
int count = 0;
switch (mIndex) {
case 0:
count = mFoodImages.length;
break;
case 1:
count = mGiftImages.length;
break;
case 2:
count = mOutImages.length;
break;
case 3:
count = mSchoolImages.length;
break;
default:
break;
}
return count;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = View.inflate(mContext, R.layout.shop_grid_item, null);
// RelativeLayout rl = (RelativeLayout)
// view.findViewById(R.id.relaGrid);
ImageView image = (ImageView) view.findViewById(R.id.img_chooseImage);
TextView text = (TextView) view.findViewById(R.id.tv_chooseText);
switch (mIndex) {
case 0:
image.setImageResource(mFoodImages[position]);
text.setText(mFoodTexts[position]);
break;
case 1:
image.setImageResource(mGiftImages[position]);
text.setText(mGiftTexts[position]);
break;
case 2:
image.setImageResource(mOutImages[position]);
text.setText(mOutTexts[position]);
break;
case 3:
image.setImageResource(mSchoolImages[position]);
text.setText(mSchoolTexts[position]);
break;
default:
break;
}
return view;
}
}

View File

@ -1,67 +0,0 @@
package com.stone.shop.adapter;
import java.util.List;
import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
/**
* 首页--图片轮播AutoScrollViewPager适配器
* @author Stone
*/
public class ImagePagerAdapter extends PagerAdapter {
private List<View> mImgViews;
public ImagePagerAdapter(Context context, List<View> imgViews) {
this.mImgViews = imgViews;
}
@Override
public int getCount() {
if(mImgViews != null){
return mImgViews.size();
}
return 0;
}
@Override
public Object instantiateItem(View arg0, int arg1) {
((ViewPager) arg0).addView(mImgViews.get(arg1));
return mImgViews.get(arg1);
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView(mImgViews.get(arg1));
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View arg0) {
}
@Override
public void finishUpdate(View arg0) {
}
}

View File

@ -1,69 +0,0 @@
package com.stone.shop.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.stone.shop.R;
/**
* MineActivity 项目列表适配器
* @date 2014-5-10
* @author Stone
*/
public class MineListAdapter extends BaseAdapter {
private Context mContext;
private String[] mItemNames; // 项目列表名称
private String[] mItemContents; //项目列表的备注值
private int[] mItemImgIds; // 项目列表Icon
private LayoutInflater mInflater = null;
public MineListAdapter(Context context, String[] names, String[] contents, int[] imgIds) {
mContext = context;
mItemNames = names;
mItemContents = contents;
mItemImgIds = imgIds;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mItemNames.length;
}
@Override
public Object getItem(int position) {
return mItemNames[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MineListHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.mine_list_item, null);
holder = new MineListHolder();
holder.imgItem = (ImageView) convertView.findViewById(R.id.img_item);
holder.tvItemName = (TextView) convertView
.findViewById(R.id.tv_item_name);
holder.tvItemContent = (TextView) convertView.findViewById(R.id.tv_item_content);
convertView.setTag(holder);
} else {
holder = (MineListHolder) convertView.getTag();
}
holder.imgItem.setBackgroundResource(mItemImgIds[position]);
holder.tvItemName.setText(mItemNames[position]);
holder.tvItemContent.setText(mItemContents[position]);
return convertView;
}
}

View File

@ -1,65 +0,0 @@
package com.stone.shop.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.stone.shop.R;
/**
* MineActivity 项目列表适配器
* @date 2014-5-10
* @author Stone
*/
public class MineSoftAdapter extends BaseAdapter {
private Context mContext;
private String[] mItemNames; // 项目列表名称
private String[] mItemContents; //项目列表的备注值
private LayoutInflater mInflater = null;
public MineSoftAdapter(Context context, String[] names, String[] contents) {
mContext = context;
mItemNames = names;
mItemContents = contents;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mItemNames.length;
}
@Override
public Object getItem(int position) {
return mItemNames[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MineListHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.mine_soft_list_item, null);
holder = new MineListHolder();
holder.tvItemName = (TextView) convertView
.findViewById(R.id.tv_item_name);
holder.tvItemContent = (TextView) convertView.findViewById(R.id.tv_item_content);
convertView.setTag(holder);
} else {
holder = (MineListHolder) convertView.getTag();
}
holder.tvItemName.setText(mItemNames[position]);
holder.tvItemContent.setText(mItemContents[position]);
return convertView;
}
}

View File

@ -1,82 +0,0 @@
package com.stone.shop.adapter;
import java.util.ArrayList;
import java.util.List;
import com.stone.shop.R;
import com.stone.shop.model.News;
import android.R.integer;
import android.content.Context;
import android.graphics.pdf.PdfDocument.Page;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
* 新闻列表适配器
*
* @date 2014-5-3
* @author Stone
*/
public class NewsListAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater = null;
private List<News> mNewsList = null; // 所选分类下的所有店铺列表
public NewsListAdapter(Context context, List<News> newsList) {
mContext = context;
mNewsList = newsList;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mNewsList.size();
}
@Override
public Object getItem(int position) {
return mNewsList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
// 刷新列表中的数据
public void refresh(ArrayList<News> list) {
mNewsList = list;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
NewsHolder newsHolder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.news_list_item, null);
newsHolder = new NewsHolder();
newsHolder.tvNewsType = (TextView) convertView
.findViewById(R.id.tv_news_type);
newsHolder.tvNewsTitle = (TextView) convertView
.findViewById(R.id.tv_news_title);
newsHolder.tvNewsDate = (TextView) convertView
.findViewById(R.id.tv_news_date);
convertView.setTag(newsHolder);
} else {
newsHolder = (NewsHolder) convertView.getTag();
}
//拆分字符串,只取年月日
String[] ss = new String[2];
ss = mNewsList.get(position).getCreatedAt().split(" ");
newsHolder.tvNewsType.setText(mNewsList.get(position).getType()); //新闻类型
newsHolder.tvNewsTitle.setText(mNewsList.get(position).getTitle()); //新闻标题
newsHolder.tvNewsDate.setText(ss[0]); //新闻发布日期
return convertView;
}
}

View File

@ -1,81 +0,0 @@
package com.stone.shop.adapter;
import java.util.ArrayList;
import java.util.List;
import com.stone.shop.R;
import com.stone.shop.model.News;
import android.R.integer;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
* 新闻列表适配器
*
* @date 2014-5-3
* @author Stone
*/
public class NewsListAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater = null;
private List<News> mNewsList = null; // 所选分类下的所有店铺列表
public NewsListAdapter(Context context, List<News> newsList) {
mContext = context;
mNewsList = newsList;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mNewsList.size();
}
@Override
public Object getItem(int position) {
return mNewsList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
// 刷新列表中的数据
public void refresh(ArrayList<News> list) {
mNewsList = list;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
NewsHolder newsHolder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.news_list_item, null);
newsHolder = new NewsHolder();
newsHolder.tvNewsType = (TextView) convertView
.findViewById(R.id.tv_news_type);
newsHolder.tvNewsTitle = (TextView) convertView
.findViewById(R.id.tv_news_title);
newsHolder.tvNewsDate = (TextView) convertView
.findViewById(R.id.tv_news_date);
convertView.setTag(newsHolder);
} else {
newsHolder = (NewsHolder) convertView.getTag();
}
//拆分字符串,只取年月日
String[] ss = new String[2];
ss = mNewsList.get(position).getCreatedAt().split(" ");
newsHolder.tvNewsType.setText(mNewsList.get(position).getType()); //新闻类型
newsHolder.tvNewsTitle.setText(mNewsList.get(position).getTitle()); //新闻标题
newsHolder.tvNewsDate.setText(ss[0]); //新闻发布日期
return convertView;
}
}

View File

@ -1,82 +0,0 @@
package com.stone.shop.adapter;
import java.util.ArrayList;
import java.util.List;
import com.stone.shop.R;
import com.stone.shop.model.News;
import android.R.integer;
import android.content.Context;
import android.graphics.pdf.PdfDocument.Page;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
* 新闻列表适配器
*
* @date 2014-5-3
* @author Stone
*/
public class NewsListAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater = null;
private List<News> mNewsList = null; // 所选分类下的所有店铺列表
public NewsListAdapter(Context context, List<News> newsList) {
mContext = context;
mNewsList = newsList;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mNewsList.size();
}
@Override
public Object getItem(int position) {
return mNewsList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
// 刷新列表中的数据
public void refresh(ArrayList<News> list) {
mNewsList = list;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
NewsHolder newsHolder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.news_list_item, null);
newsHolder = new NewsHolder();
newsHolder.tvNewsType = (TextView) convertView
.findViewById(R.id.tv_news_type);
newsHolder.tvNewsTitle = (TextView) convertView
.findViewById(R.id.tv_news_title);
newsHolder.tvNewsDate = (TextView) convertView
.findViewById(R.id.tv_news_date);
convertView.setTag(newsHolder);
} else {
newsHolder = (NewsHolder) convertView.getTag();
}
//拆分字符串,只取年月日
String[] ss = new String[2];
ss = mNewsList.get(position).getCreatedAt().split(" ");
newsHolder.tvNewsType.setText(mNewsList.get(position).getType()); //新闻类型
newsHolder.tvNewsTitle.setText(mNewsList.get(position).getTitle()); //新闻标题
newsHolder.tvNewsDate.setText(ss[0]); //新闻发布日期
return convertView;
}
}

View File

@ -1,88 +0,0 @@
package com.stone.shop.adapter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.GetListener;
import com.stone.date.TypeDef;
import com.stone.shop.R;
import com.stone.shop.model.Good;
import com.stone.shop.model.Order;
import com.stone.shop.model.Shop;
import com.stone.shop.view.OrderInfoActivity;
/**
* 适配器--适配订单列表中的数据
*
* @date 2014-5-27
* @author Stone
*/
public class OrderInfoListAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater = null;
private List<Order> mOrderList = null; // 所选分类下的所有店铺列表
private String mType; // 商店的分类
public OrderInfoListAdapter(Context context, List<Order> orderList) {
mContext = context;
mOrderList = orderList;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mOrderList.size();
}
@Override
public Object getItem(int position) {
return mOrderList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public void refresh(List<Order> list) {
mOrderList = list;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
OrderInfoHolder orderInfoHolder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.order_info_list_item, null);
orderInfoHolder = new OrderInfoHolder();
orderInfoHolder.tvOrderInfoGoodName = (TextView) convertView
.findViewById(R.id.tv_order_info_good_name);
orderInfoHolder.tvOrderInfoShopName = (TextView) convertView
.findViewById(R.id.tv_order_info_shop_name);
orderInfoHolder.tvOrderInfoPrice = (TextView) convertView
.findViewById(R.id.tv_order_info_price);
orderInfoHolder.tvOrderInfoState = (TextView) convertView
.findViewById(R.id.tv_order_info_state);
convertView.setTag(orderInfoHolder);
} else {
orderInfoHolder = (OrderInfoHolder) convertView.getTag();
}
orderInfoHolder.tvOrderInfoGoodName.setText(mOrderList.get(position).getGoodName());
orderInfoHolder.tvOrderInfoShopName.setText(mOrderList.get(position).getShopName());
orderInfoHolder.tvOrderInfoPrice.setText("¥" + mOrderList.get(position).getPrice());
orderInfoHolder.tvOrderInfoState.setText(mOrderList.get(position).getState());
return convertView;
}
}

View File

@ -1,66 +0,0 @@
package com.stone.shop.adapter;
import java.util.List;
import com.stone.shop.R;
import com.stone.shop.model.SComment;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
* 店铺评论列表适配器
* @date 2014-5-3
* @author Stone
*/
public class SCommentAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater = null;
private List<SComment> mSComList = null; // 所选分类下的所有店铺列表
public SCommentAdapter(Context context, List<SComment> list) {
mContext = context;
mSComList = list;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mSComList.size();
}
@Override
public Object getItem(int position) {
return mSComList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
SComHolder scomHolder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.scom_list_item, null);
scomHolder = new SComHolder();
scomHolder.tvComUser = (TextView) convertView
.findViewById(R.id.tv_commit_user);
scomHolder.tvComContent = (TextView) convertView
.findViewById(R.id.tv_commit_content);
convertView.setTag(scomHolder);
} else {
scomHolder = (SComHolder) convertView.getTag();
}
scomHolder.tvComUser.setText(mSComList.get(position).getUserName());
scomHolder.tvComContent.setText(mSComList.get(position).getContent());
return convertView;
}
}

View File

@ -1,126 +0,0 @@
package com.stone.shop.adapter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.stone.date.TypeDef;
import com.stone.shop.R;
import com.stone.shop.model.Shop;
/**
* 适配器--适配某一分类下的店铺列表数据
*
* @date 2014-4-29
* @author Stone
*/
public class ShopListAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater = null;
private ArrayList<Shop> mShopList = null; // 所选分类下的所有店铺列表
private String mType; // 商店的分类
public ShopListAdapter(Context context, ArrayList<Shop> shopList,
String type) {
mContext = context;
mShopList = shopList;
mType = type;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mShopList.size();
}
@Override
public Object getItem(int position) {
return mShopList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
// 刷新列表中的数据
public void refresh(ArrayList<Shop> list) {
mShopList = list;
//将数字的类型编号转换为文字
exchangeType(mType);
notifyDataSetChanged();
}
/**
* 根据当前的type类型, 转换成相应的文字
* @date 2014-4-29
* @param typeString
*/
private void exchangeType(String typeString) {
int type = Integer.parseInt(typeString);
int fatherType = type / 10; //父类型编号
int sonType = type % 10; //子类型编号
Iterator<Shop> iterator = mShopList.iterator();
while (iterator.hasNext()) {
switch (fatherType) {
case 1:
iterator.next().setType(
TypeDef.typeDadList[fatherType-1] + "/"
+ TypeDef.typeSonList1[sonType-1]);
break;
case 2:
iterator.next().setType(
TypeDef.typeDadList[fatherType-1] + "/"
+ TypeDef.typeSonList2[sonType-1]);
break;
case 3:
iterator.next().setType(
TypeDef.typeDadList[fatherType-1] + "/"
+ TypeDef.typeSonList3[sonType-1]);
break;
case 4:
iterator.next().setType(
TypeDef.typeDadList[fatherType-1] + "/"
+ TypeDef.typeSonList4[sonType-1]);
break;
default:
break;
}
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ShopHolder shopHodler;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.shop_all_list_item, null);
shopHodler = new ShopHolder();
shopHodler.tvShopName = (TextView) convertView
.findViewById(R.id.tv_shop_name);
shopHodler.tvShopType = (TextView) convertView
.findViewById(R.id.tv_shop_type);
shopHodler.tvShopLoc = (TextView) convertView
.findViewById(R.id.tv_shop_loc);
convertView.setTag(shopHodler);
} else {
shopHodler = (ShopHolder) convertView.getTag();
}
shopHodler.tvShopName.setText(mShopList.get(position).getName());
// 商店的类型需要单独处理
shopHodler.tvShopType.setText(mShopList.get(position).getType());
shopHodler.tvShopLoc.setText("二食堂");
return convertView;
}
}

View File

@ -1,100 +0,0 @@
package com.stone.shop.view;
import java.util.ArrayList;
import java.util.List;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.FindListener;
import com.stone.shop.R;
import com.stone.shop.adapter.BXTListAdapter;
import com.stone.shop.model.BXTNews;
import com.stone.shop.model.Classroom;
import com.stone.shop.model.BXTNews;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.renderscript.Element;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;
/**
* 教学类-博学堂界面
* @date 2014-5-10
* @author Stone
*/
public class BXTActivity extends Activity implements OnItemClickListener{
private static final String TAG = "BXTActivity";
private ListView lvBXTNews;
private BXTListAdapter mBxtListAdapter;
private List<BXTNews> mBXTNewsList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bxt);
initView();
initData();
}
private void initView() {
lvBXTNews = (ListView) findViewById(R.id.lv_bxt_news);
mBXTNewsList = new ArrayList<BXTNews>();
mBxtListAdapter = new BXTListAdapter(this, mBXTNewsList);
lvBXTNews.setAdapter(mBxtListAdapter);
lvBXTNews.setOnItemClickListener(this);
}
private void initData() {
BmobQuery<BXTNews> query = new BmobQuery<BXTNews>();
query.findObjects(this, new FindListener<BXTNews>() {
@Override
public void onSuccess(List<BXTNews> newsList) {
//toast("查询商品成功, 共" + newsList.size());
if(newsList.size()==0)
toast("亲, 暂时还木有讲座哦");
else {
mBXTNewsList = newsList;
mBxtListAdapter.refresh(newsList);
mBxtListAdapter.notifyDataSetChanged();
}
}
@Override
public void onError(int arg0, String arg1) {
toast("查询失败");
}
});
}
private void toast(String toast) {
Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Intent toBXTNewsActivity = new Intent(BXTActivity.this, BXTNewsActivity.class);
toBXTNewsActivity.putExtra("title", mBXTNewsList.get(position).getTitle());
toBXTNewsActivity.putExtra("topic", mBXTNewsList.get(position).getTopic());
toBXTNewsActivity.putExtra("speaker", mBXTNewsList.get(position).getSpeaker());
toBXTNewsActivity.putExtra("time", mBXTNewsList.get(position).getTime());
toBXTNewsActivity.putExtra("location", mBXTNewsList.get(position).getLocation());
toBXTNewsActivity.putExtra("holder1", mBXTNewsList.get(position).getHolder1());
toBXTNewsActivity.putExtra("holder2", mBXTNewsList.get(position).getHolder2());
toBXTNewsActivity.putExtra("points", mBXTNewsList.get(position).getPoints());
toBXTNewsActivity.putExtra("speakerinfo", mBXTNewsList.get(position).getSpeakerinfo());
startActivity(toBXTNewsActivity);
}
}

View File

@ -1,65 +0,0 @@
package com.stone.shop.view;
import com.stone.shop.R;
import com.stone.shop.model.BXTNews;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
/**
* 教学类-博学堂-讲座详情界面
* @date 2014-5-10
* @author Stone
*/
public class BXTNewsActivity extends Activity {
private static final String TAG = "BXTNewsActivity";
private BXTNews news;
private TextView tvBXTNewsTitle;
private TextView tvBXTNewsTopic;
private TextView tvBXTNewsSpeaker;
private TextView tvBXTNewsTime;
private TextView tvBXTNewsLoc;
private TextView tvBXTNewsHolder1;
private TextView tvBXTNewsHolder2;
private TextView tvBXTNewsPoints;
private TextView tvBXTNewsSpeakerInfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bxt_news);
initView();
}
private void initView() {
tvBXTNewsTitle = (TextView) findViewById(R.id.tv_bxt_news_title);
tvBXTNewsTopic = (TextView) findViewById(R.id.tv_bxt_news_topic);
tvBXTNewsSpeaker = (TextView) findViewById(R.id.tv_bxt_news_speaker);
tvBXTNewsTime = (TextView) findViewById(R.id.tv_bxt_news_time);
tvBXTNewsLoc = (TextView) findViewById(R.id.tv_bxt_news_loc);
tvBXTNewsHolder1 = (TextView) findViewById(R.id.tv_bxt_news_holder1);
tvBXTNewsHolder2 = (TextView) findViewById(R.id.tv_bxt_news_holder2);
tvBXTNewsPoints = (TextView) findViewById(R.id.tv_bxt_news_point);
tvBXTNewsSpeakerInfo = (TextView) findViewById(R.id.tv_bxt_news_speaker_info);
tvBXTNewsTitle.setText(getIntent().getStringExtra("title"));
tvBXTNewsTopic.setText(getIntent().getStringExtra("topic"));
tvBXTNewsSpeaker.setText(getIntent().getStringExtra("speaker"));
tvBXTNewsTime.setText(getIntent().getStringExtra("time"));
tvBXTNewsLoc.setText(getIntent().getStringExtra("location"));
tvBXTNewsHolder1.setText(getIntent().getStringExtra("holder1"));
tvBXTNewsHolder2.setText(getIntent().getStringExtra("holder2"));
tvBXTNewsPoints.setText(getIntent().getStringExtra("points"));
tvBXTNewsSpeakerInfo.setText(getIntent().getStringExtra("speakerinfo"));
}
}

View File

@ -1,104 +0,0 @@
package com.stone.shop.view;
import cn.bmob.v3.Bmob;
import com.stone.shop.R;
import com.stone.shop.view.old.OldMineActivity;
import android.os.Bundle;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.Space;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
/**
* 应用主界面
* @date 2014-4-24
* @author Stone
*/
@SuppressWarnings("deprecation")
public class BaseActivity extends TabActivity {
private static final String TAG = "BaseActivity";
private TabHost tabHost;
private LayoutInflater layoutInflater;
String[] mTitle = new String[] { "周边", "讨论区", "我的"};
int[] mIcon = new int[] { R.drawable.ic_shop2, R.drawable.ic_sale2,
R.drawable.ic_car2, R.drawable.ic_mine };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base);
initTabView();
}
public View getTabItemView(int i) {
// TODO Auto-generated method stub
View view = layoutInflater.inflate(R.layout.tab_widget_item, null);
ImageView imageView = (ImageView) view.findViewById(R.id.imageview);
imageView.setImageResource(mIcon[i]);
TextView textView = (TextView) view.findViewById(R.id.textview);
textView.setText(mTitle[i]);
return view;
}
public void initTabView() {
/**
* tabHost.newTabSpec("artist")创建一个标签项其中artist为它的标签标识符相当于jsp页面标签的name属性
* setIndicator("艺术标签",resources.getDrawable(R.drawable.ic_tab))设置标签显示文本以及标签上的图标该图标并不是一个图片而是一个xml文件哦
* setContent(intent)为当前标签指定一个意图
* tabHost.addTab(spec); 将标签项添加到标签中
*/
tabHost = getTabHost();
layoutInflater = LayoutInflater.from(this);
TabHost.TabSpec spec;
Intent intent1 = new Intent(this, ShopActivity.class);
spec = tabHost.newTabSpec(mTitle[0]).setIndicator( getTabItemView(0) ).setContent(intent1);
tabHost.addTab(spec);
Intent intent2 = new Intent(this, AwardActivity.class);
spec = tabHost.newTabSpec(mTitle[1]).setIndicator( getTabItemView(1) ).setContent(intent2);
tabHost.addTab(spec);
Intent intent3 = new Intent(this, MineActivity.class);
spec = tabHost.newTabSpec(mTitle[2]).setIndicator( getTabItemView(2) ).setContent(intent3);
tabHost.addTab(spec);
/*
Intent intent3 = new Intent(this, WsqActivity.class);
spec = tabHost.newTabSpec(mTitle[2]).setIndicator( getTabItemView(2) ).setContent(intent3);
tabHost.addTab(spec);
Intent intent4 = new Intent(this, OldMineActivity.class);
spec = tabHost.newTabSpec(mTitle[3]).setIndicator( getTabItemView(3) ).setContent(intent4);
tabHost.addTab(spec); */
tabHost.setCurrentTab(0);
}
@Override
public void onBackPressed() {
Toast.makeText(this, "确定要退出在这里么?", Toast.LENGTH_LONG).show();
//super.onBackPressed();
}
}

View File

@ -1,94 +0,0 @@
package com.stone.shop.view;
import java.util.ArrayList;
import java.util.List;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.FindListener;
import com.stone.shop.R;
import com.stone.shop.adapter.BXTListAdapter;
import com.stone.shop.adapter.ClassroomAdapter;
import com.stone.shop.model.Classroom;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class ClassroomActivity extends Activity implements OnItemClickListener {
private static final String TAG = "BXTActivity";
private GridView lvBXTNews;
private ClassroomAdapter mBxtListAdapter;
private List<Classroom> mBXTNewsList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_classroom);
initView();
initData();
}
private void initView() {
lvBXTNews = (GridView) findViewById(R.id.gv_classroom);
mBXTNewsList = new ArrayList<Classroom>();
mBxtListAdapter = new ClassroomAdapter(this, mBXTNewsList);
lvBXTNews.setAdapter(mBxtListAdapter);
lvBXTNews.setOnItemClickListener(this);
TextView tv_title = (TextView) findViewById(R.id.tv_title);
tv_title.setText("教室");
}
private void initData() {
BmobQuery<Classroom> query = new BmobQuery<Classroom>();
query.addWhereEqualTo("type", "教室");
query.findObjects(this, new FindListener<Classroom>() {
@Override
public void onSuccess(List<Classroom> newsList) {
// toast("查询商品成功, 共" + newsList.size());
if (newsList.size() == 0)
toast("亲, 暂时还木有教室哦");
else {
mBXTNewsList = newsList;
mBxtListAdapter.refresh(newsList);
mBxtListAdapter.notifyDataSetChanged();
}
}
@Override
public void onError(int arg0, String arg1) {
toast("查询失败");
}
});
}
private void toast(String toast) {
Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(ClassroomActivity.this, ReservationActivity.class);
Classroom classroom = mBXTNewsList.get(position);
intent.putExtra("roomId", classroom.getObjectId());
intent.putExtra("roomName", classroom.getName());
startActivity(intent);
}
}

View File

@ -1,103 +0,0 @@
package com.stone.shop.view;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.listener.SaveListener;
import com.stone.shop.R;
import com.stone.shop.model.FeedBack;
import com.stone.shop.model.User;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
/**
* 意见反馈界面
*
* @date 2014-5-27
* @author Stone
*/
public class FeedBackActivity extends Activity implements OnClickListener {
private static final String TAG = "FeedBackActivity";
private EditText etContent;
private Button btnSubmit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feedback);
initView();
}
private void initView() {
etContent = (EditText) findViewById(R.id.et_feedback_content);
btnSubmit = (Button) findViewById(R.id.btn_feedback_submit);
btnSubmit.setOnClickListener(this);
}
/**
* 提交用户的反馈信息
*/
private void submit() {
String content = etContent.getText().toString();
if (content.equals("")) {
toast("亲,请先写点东西吧");
} else {
BmobUser user = BmobUser.getCurrentUser(this);
FeedBack fb = new FeedBack();
fb.setUsername(user.getUsername());
fb.setEmail(user.getEmail());
fb.setContent(content);
fb.save(this, new SaveListener() {
@Override
public void onSuccess() {
// TODO Auto-generated method stub
toast("提交成功, 在这里会尽快回复");
back();
}
@Override
public void onFailure(int arg0, String arg1) {
// TODO Auto-generated method stub
toast("提交失败");
}
});
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_feedback_submit:
submit();
break;
default:
break;
}
}
private void back() {
finish();
}
public void clickFeedBack(View v) {
finish();
}
private void toast(String toast) {
Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
}
}

View File

@ -1,195 +0,0 @@
package com.stone.shop.view;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.opengl.Visibility;
import android.os.Bundle;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;
import android.widget.Toast;
import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.FindListener;
import cn.bmob.v3.listener.GetServerTimeListener;
import com.stone.date.TypeDef;
import com.stone.shop.R;
import com.stone.shop.adapter.ImagePagerAdapter;
import com.stone.shop.adapter.NewsListAdapter;
import com.stone.shop.model.News;
import com.stone.shop.model.Shop;
import com.stone.ui.AutoScrollViewPager;
import com.stone.ui.ListScrollView;
/**
* 主界面
*
* @date 2014-4-24
* @author Stone
*/
public class HomeActivity extends Activity implements OnClickListener,
OnItemClickListener {
private static final String TAG = "HomeActivity";
private ListScrollView listScrollView;
// 校历
private TextView tvWeek; // 周次和星期
private TextView tvDay; // 年月日
// 图片轮播
private FrameLayout flImageAds;
private AutoScrollViewPager viewPager;
private List<View> mImgViews;
private ImageButton btnHideAds;
private int[] mImgResId = { R.drawable.ic_banner1, R.drawable.ic_banner1,
R.drawable.ic_banner1, R.drawable.ic_banner1 };
// 校园新闻
private ListView lvNewsList;
private List<News> newsList = new ArrayList<News>();
private NewsListAdapter newsListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
// 解决ScrollView和ListView之间的冲突
listScrollView = (ListScrollView) findViewById(R.id.listScrollView);
lvNewsList = (ListView) findViewById(R.id.lv_news);
listScrollView.setListView(lvNewsList);
flImageAds = (FrameLayout) findViewById(R.id.fl_image_ads);
viewPager = (AutoScrollViewPager) findViewById(R.id.view_pager);
btnHideAds = (ImageButton) findViewById(R.id.btn_hide_ads);
mImgViews = new ArrayList<View>();
for (int i = 0; i < mImgResId.length; i++) {
ImageView imageView = new ImageView(this);
imageView.setImageResource(mImgResId[i]);
imageView.setScaleType(ScaleType.CENTER_CROP);
mImgViews.add(imageView);
}
btnHideAds.setOnClickListener(this);
viewPager.setAdapter(new ImagePagerAdapter(this, mImgViews));
viewPager.setInterval(3000); // 设置自动滚动的间隔时间,单位为毫秒
viewPager.setDirection(AutoScrollViewPager.RIGHT); // 设置自动滚动的方向,默认向右
viewPager.setCycle(true); // 是否自动循环轮播默认为true
viewPager.setScrollDurationFactor(3); // 设置ViewPager滑动动画间隔时间的倍率达到减慢动画或改变动画速度的效果
viewPager.setStopScrollWhenTouch(true); // 当手指碰到ViewPager时是否停止自动滚动默认为true
viewPager.setBorderAnimation(true); // 设置循环滚动时滑动到从边缘滚动到下一个是否需要动画默认为true
viewPager
.setSlideBorderMode(AutoScrollViewPager.SLIDE_BORDER_MODE_NONE);// 滑动到第一个或最后一个Item的处理方式支持没有任何操作、轮播以及传递到父View三种模式
viewPager.startAutoScroll();
// 校历
tvWeek = (TextView) findViewById(R.id.tv_week);
tvDay = (TextView) findViewById(R.id.tv_day);
setTime();
// 新闻
newsListAdapter = new NewsListAdapter(this, newsList);
lvNewsList.setAdapter(newsListAdapter);
lvNewsList.setOnItemClickListener(this);
getNewsData();
}
/**
* 设置校历中日期的时间
*/
public void setTime() {
Calendar calendar = Calendar.getInstance();
String year = calendar.get(Calendar.YEAR)+"";
String month = calendar.get(Calendar.MONTH)+1+"";
String day = calendar.get(Calendar.DAY_OF_MONTH)+"";
String week = calendar.get(Calendar.WEEK_OF_YEAR)-9+"";
String dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)+"";
String chDayOfWeek = TypeDef.chDayOfWeek[Integer.parseInt(dayOfWeek)-1];
toast(year+"-"+month+"-"+day+" "+" 第 "+week+" 周 "+" "+" 星期 "+chDayOfWeek);
tvWeek.setText(" 第 "+week+" 周 "+" "+" 星期 "+chDayOfWeek);
tvDay.setText(year+" 年 "+month+" 月 "+day+" 日");
}
/**
* 初始化新闻列表数据
* @date 2014-5-3
* @author Stone
*/
public void getNewsData() {
BmobQuery<News> query = new BmobQuery<News>();
query.order("-updatedAt");
query.findObjects(this, new FindListener<News>() {
@Override
public void onSuccess(List<News> object) {
newsList = object;
// 通知Adapter数据更新
newsListAdapter.refresh((ArrayList<News>) newsList);
newsListAdapter.notifyDataSetChanged();
}
@Override
public void onError(int arg0, String arg1) {
toast("对不起, 获取数据失败了");
}
});
}
@Override
protected void onResume() {
super.onResume();
// start auto scroll when onResume
viewPager.startAutoScroll();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_hide_ads:
flImageAds.setVisibility(View.GONE);
break;
default:
break;
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Intent toNewsDetail = new Intent(HomeActivity.this, NewsActivity.class);
toNewsDetail.putExtra("NewsTitle", newsList.get(position).getTitle());
toNewsDetail.putExtra("NewsAuthor", newsList.get(position).getAuthor());
toNewsDetail.putExtra("NewsTime", newsList.get(position).getCreatedAt());
toNewsDetail.putExtra("NewsContent", newsList.get(position).getContent());
startActivity(toNewsDetail);
}
public void toast(String toast) {
Toast.makeText(this, toast, Toast.LENGTH_SHORT);
}
}

View File

@ -1,346 +0,0 @@
package com.stone.shop.view;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import cn.bmob.v3.Bmob;
import cn.bmob.v3.listener.SaveListener;
import com.stone.shop.R;
import com.stone.shop.model.User;
import com.stone.util.Util;
import com.tencent.connect.UserInfo;
import com.tencent.connect.auth.QQAuth;
import com.tencent.connect.common.Constants;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;
/**
* 登陆界面
*
* @date 2014-4-24
* @author Stone
*/
public class LoginActivity extends Activity implements OnClickListener {
private static final String TAG = "LoginActicity";
private Button btnLogin;
private Button btnReg;
private EditText etUsername;
private EditText etPassword;
private String username;
private String password;
private static final String APP_ID = "222222";
private UserInfo mInfo;
private TextView mUserInfo;
private ImageView mUserLogo;
private ImageView mNewLoginButton;
private TextView backInfo;
// QQ登陆
private static Tencent mTencent;
// private QQAuth mQQAuth;
Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == 0) {
JSONObject response = (JSONObject) msg.obj;
if (response.has("nickname")) {
try {
mUserInfo.setVisibility(android.view.View.VISIBLE);
mUserInfo.setText(response.getString("nickname"));
} catch (JSONException e) {
e.printStackTrace();
}
}
} else if (msg.what == 1) {
Bitmap bitmap = (Bitmap) msg.obj;
mUserLogo.setImageBitmap(bitmap);
mUserLogo.setVisibility(android.view.View.VISIBLE);
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 初始化 Bmob SDK
// 使用时请将第二个参数Application ID替换成你在Bmob服务器端创建的Application ID
Bmob.initialize(this, "252a2c58d0dc9a78a5411501c62ce0de");
setContentView(R.layout.activity_login);
// QQ登陆, 获取实例
// mQQAuth = QQAuth.createInstance(APP_ID,
// this.getApplicationContext());
mTencent = Tencent.createInstance(APP_ID, this.getApplicationContext());
btnLogin = (Button) findViewById(R.id.btn_login);
btnReg = (Button) findViewById(R.id.btn_register);
etUsername = (EditText) findViewById(R.id.et_username);
etPassword = (EditText) findViewById(R.id.et_password);
btnLogin.setOnClickListener(this);
btnReg.setOnClickListener(this);
findViewById(R.id.btn_qq).setOnClickListener(this);
mUserInfo = (TextView) findViewById(R.id.user_nickname);
mUserLogo = (ImageView) findViewById(R.id.user_logo);
mNewLoginButton = (ImageView) findViewById(R.id.new_login_btn);
mNewLoginButton.setOnClickListener(this);
backInfo = (TextView) findViewById(R.id.user_callback);
getUserInfo();
}
private void getUserInfo() {
SharedPreferences sp = getSharedPreferences("UserInfo", 0);
etUsername.setText(sp.getString("username", null));
etPassword.setText(sp.getString("password", null));
}
// 保存用户的登陆记录
private void saveUserInfo(String username, String password) {
SharedPreferences sp = getSharedPreferences("UserInfo", 0);
Editor editor = sp.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.commit();
}
public void onClickLogin() {
if (!mTencent.isSessionValid()) {
mTencent.login(this, "all", loginListener);
Log.d("SDKQQAgentPref", "FirstLaunch_SDK:" + SystemClock.elapsedRealtime());
} else {
mTencent.logout(this);
updateUserInfo();
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
// 登陆
case R.id.btn_login:
username = etUsername.getText().toString();
password = etPassword.getText().toString();
if (!Util.isNetworkConnected(this)) {
toast("木有网络 ( ⊙ o ⊙ ) ");
} else if (username.equals("") || password.equals("")) {
toast("请输入账号和密码");
break;
} else {
final User bu2 = new User();
bu2.setUsername(username);
bu2.setPassword(password);
bu2.login(this, new SaveListener() {
@Override
public void onSuccess() {
// TODO Auto-generated method stub
toast("欢迎进入 在这里 服务系统");
// 保存用户信息
saveUserInfo(username, password);
// 跳转到主页
User.userId = bu2.getObjectId();
Intent toHome = new Intent(LoginActivity.this, BaseActivity.class);
startActivity(toHome);
finish();
}
@Override
public void onFailure(int arg0, String arg1) {
// TODO Auto-generated method stub
toast("用户名或密码错误");
}
});
}
break;
case R.id.btn_register:
Intent toReg = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(toReg);
break;
case R.id.btn_qq:
onClickLogin();
break;
default:
break;
}
}
public void toast(String toast) {
Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
}
IUiListener loginListener = new BaseUiListener() {
@Override
protected void doComplete(JSONObject values) {
Log.d("SDKQQAgentPref", "AuthorSwitch_SDK:" + SystemClock.elapsedRealtime());
initOpenidAndToken(values);
updateUserInfo();
}
};
private class BaseUiListener implements IUiListener {
@Override
public void onComplete(Object response) {
if (null == response) {
Util.showResultDialog(LoginActivity.this, "返回为空", "登录失败");
return;
}
JSONObject jsonResponse = (JSONObject) response;
if (null != jsonResponse && jsonResponse.length() == 0) {
Util.showResultDialog(LoginActivity.this, "返回为空", "登录失败");
return;
}
// Util.showResultDialog(LoginActivity.this, response.toString(),
// "登录成功");
doComplete((JSONObject) response);
try {
User.userId = jsonResponse.getString("openid");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent toHome = new Intent(LoginActivity.this, BaseActivity.class);
startActivity(toHome);
finish();
}
protected void doComplete(JSONObject values) {
}
@Override
public void onError(UiError e) {
Util.toastMessage(LoginActivity.this, "onError: " + e.errorDetail);
Util.dismissDialog();
}
@Override
public void onCancel() {
Util.toastMessage(LoginActivity.this, "onCancel: ");
Util.dismissDialog();
}
}
private void updateUserInfo() {
if (mTencent != null && mTencent.isSessionValid()) {
IUiListener listener = new IUiListener() {
@Override
public void onError(UiError e) {
}
@Override
public void onComplete(final Object response) {
Message msg = new Message();
msg.obj = response;
msg.what = 0;
mHandler.sendMessage(msg);
new Thread() {
@Override
public void run() {
JSONObject json = (JSONObject) response;
if (json.has("figureurl")) {
Bitmap bitmap = null;
try {
bitmap = Util.getbitmap(json.getString("figureurl_qq_2"));
} catch (JSONException e) {
}
Message msg = new Message();
msg.obj = bitmap;
msg.what = 1;
mHandler.sendMessage(msg);
}
}
}.start();
}
@Override
public void onCancel() {
}
};
mInfo = new UserInfo(this, mTencent.getQQToken());
mInfo.getUserInfo(listener);
} else {
mUserInfo.setText("");
mUserInfo.setVisibility(android.view.View.GONE);
mUserLogo.setVisibility(android.view.View.GONE);
}
}
public static void initOpenidAndToken(JSONObject jsonObject) {
try {
String token = jsonObject.getString(Constants.PARAM_ACCESS_TOKEN);
String expires = jsonObject.getString(Constants.PARAM_EXPIRES_IN);
String openId = jsonObject.getString(Constants.PARAM_OPEN_ID);
if (!TextUtils.isEmpty(token) && !TextUtils.isEmpty(expires) && !TextUtils.isEmpty(openId)) {
mTencent.setAccessToken(token, expires);
mTencent.setOpenId(openId);
}
} catch (Exception e) {
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "-->onActivityResult " + requestCode + " resultCode=" + resultCode);
if (requestCode == Constants.REQUEST_LOGIN || requestCode == Constants.REQUEST_APPBAR) {
Tencent.onActivityResultData(requestCode, resultCode, data, loginListener);
}
super.onActivityResult(requestCode, resultCode, data);
}
}

Some files were not shown because too many files have changed in this diff Show More