首先是APP的展示
代码:
后台管理:
搭建环境:
APP:Android Studio 2.3
后台管理:Myeclipse10以上
数据库:Mysql
代码
首页:
public class GoodsListActivity extends Activity {
private GridView gv_goodsList;
private Intent mIntent;
private TextView tv_actionBarTitle;
private ImageView iv_refresh;
private static final int WHAT_GET_ALL_GOODSINFO = 205;
private String menu_title[] = {
"全部", "最新发布", "热门", "拍卖", "免费送", "急售"};
private static final int WHAT_GET_ALL_GOODSINFO_FAILED = 203;
public static final int WHAT_GET_DATA_FINISHED = 200;
private RotateAnimation animation;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
animation.cancel();//停止刷新
progressDialogUtils.closeProgressDialog();
switch (msg.what) {
case WHAT_GET_ALL_GOODSINFO:
goodsList = (List<Goods>) msg.obj;
showDate();
break;
case WHAT_GET_DATA_FINISHED:
ToastUtils.showInfo(GoodsListActivity.this, "加载成功");
goodsList = (List<Goods>) msg.obj;
showDate();
break;
case WHAT_GET_ALL_GOODSINFO_FAILED:
ToastUtils.showInfo(GoodsListActivity.this, "数据加载失败");
break;
}
}
};
private EditText et_search;
private Button btn_search;
/**
* 显示数据到视图上
*/
private void showDate() {
setAdapter();
}
private ProgressDialogUtils progressDialogUtils;
private List<Goods> goodsList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SysApplication.getInstance().addActivity(this);
progressDialogUtils = new ProgressDialogUtils(this, "加载数据", "拼命加载数据中......");
initView();
updateDate();
}
// private String[] titls = {"校园代步", "手机", "电脑", "数码配件", "数码", "电器", "运动健身", "衣物伞帽", "图书教材", "校园网", "生活娱乐", "其他"};
/**
* 设置刷新按钮的动画
*/
private void setAnimation() {
animation = new RotateAnimation(0, 360f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(1000);
animation.setRepeatCount(40);
}
/**
* 更新数据
*/
private void updateDate() {
progressDialogUtils.showProgressDialog();
mIntent = getIntent();
String type = mIntent.getStringExtra("type");
if ("search".equals(type)) {
} else if ("classify".equals(type)) {
final int position = mIntent.getIntExtra("position", 0);
//开启线程读取数据
new Thread() {
@Override
public void run() {
GoodsInfoQueryHttpUtils.getNewGoodsInfoToList(GoodsListActivity.this,
getResources().getString(R.string.url_query_goods) + "?type=all&position=" + position, handler);
}
}.start();
} else if ("other".equals(type)) {
int title = mIntent.getIntExtra("title", 0);
// Log.e("mylog", "查询的是哪里的?" + title + "----");
switch (title) {
case 0:
getAllGoodsInfo();
break;
case 1:
getNewGoodsInfo();
break;
case 2:
getHotGoodsInfo();
break;
case 3:
getPaiGoodsInfo();
break;
case 4:
getFreeGoodsInfo();
break;
case 5:
getUrgentGoodsInfo();
break;
}
}
}
/**
* 获取正在拍卖的商品
*/
private void getPaiGoodsInfo() {
//开启线程读取数据
new Thread() {
@Override
public void run() {
GoodsInfoQueryHttpUtils.getNewGoodsInfoToList(GoodsListActivity.this,
getResources().getString(R.string.url_query_goods) + "?type=pai", handler);
}
}.start();
}
/**
* 获取紧急出售的商品
*/
private void getUrgentGoodsInfo() {
//开启线程读取数据
new Thread() {
@Override
public void run() {
GoodsInfoQueryHttpUtils.getNewGoodsInfoToList(GoodsListActivity.this,
getResources().getString(R.string.url_query_goods) + "?type=new&flag=urgent", handler);
}
}.start();
}
/**
* 获取免费的商品
*/
private void getFreeGoodsInfo() {
//开启线程读取数据
new Thread() {
@Override
public void run() {
GoodsInfoQueryHttpUtils.getNewGoodsInfoToList(GoodsListActivity.this,
getResources().getString(R.string.url_query_goods) + "?type=new&flag=free", handler);
}
}.start();
}
/**
* 获取最热门的
*/
private void getHotGoodsInfo() {
//开启线程读取数据
new Thread() {
@Override
public void run() {
GoodsInfoQueryHttpUtils.getNewGoodsInfoToList(GoodsListActivity.this,
getResources().getString(R.string.url_query_goods) + "?type=new&flag=hot", handler);
}
}.start();
}
/**
* 获取最新发布的商品
*/
private void getNewGoodsInfo() {
//开启线程读取数据
new Thread() {
@Override
public void run() {
GoodsInfoQueryHttpUtils.getNewGoodsInfoToList(GoodsListActivity.this,
getResources().getString(R.string.url_query_goods) + "?type=new&flag=all", handler);
}
}.start();
}
public void getAllGoodsInfo() {
//开启线程读取数据
new Thread() {
@Override
public void run() {
GoodsInfoQueryHttpUtils.getGoodsInfoToList(GoodsListActivity.this,
getResources().getString(R.string.url_query_goods) + "?type=all&position=100", handler);
}
}.start();
}
/**
* 初始化布局
*/
private void initView() {
setContentView(R.layout.activity_goodslist);
gv_goodsList = (GridView) findViewById(R.id.gv_goodslist);
tv_actionBarTitle = (TextView) findViewById(R.id.tv_goodslist_custom_actionbar_title);
iv_refresh = (ImageView) findViewById(R.id.iv_goodslist_refresh);
et_search = (EditText) findViewById(R.id.et_goodslist_search);
btn_search = (Button) findViewById(R.id.btn_goodslist_search);
setTopTitle();
// setAdapter();
setListener();
setAnimation();
}
/**
* 设置监听器
*/
private void setListener() {
btn_search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String select_after = et_search.getText().toString().trim();
try {
select_after = URLEncoder.encode(select_after, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
final String select_befor = select_after;
new Thread() {
@Override
public void run() {
GoodsInfoQueryHttpUtils.getGoodsInfoToList(GoodsListActivity.this,
getResources().getString(R.string.url_query_goods) + "?type=search&select=" + select_befor, handler);
}
}.start();
}
});
gv_goodsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
gotoPager(i);
}
});
// iv_refresh.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// updateDate();
// }
// });
}
/**
* 跳转到相应的页面
*
* @param i
*/
private void gotoPager(int i) {
Intent it = new Intent(this, GoodsDetailActivity.class);
it.putExtra("gId", goodsList.get(i).getgId());
startActivity(it);
}
/**
* 设置顶部标题栏
*/
private void setTopTitle() {
mIntent = getIntent();
String type = mIntent.getStringExtra("type");
if ("new".equals(type)) {
tv_actionBarTitle.setText("最新发布");
} else if ("pai".equals(type)) {
tv_actionBarTitle.setText("拍卖");
} else if ("urgent".equals(type)) {
tv_actionBarTitle.setText("紧急出售");
} else if ("other".equals(type)) {
int title = mIntent.getIntExtra("title", 0);
tv_actionBarTitle.setText(menu_title[title]);
} else if ("classify".equals(type)) {
String title = mIntent.getStringExtra("title");
tv_actionBarTitle.setText(title);
} else if ("search".equals(type)) {
tv_actionBarTitle.setText("搜索");
getHotGoodsInfo();
RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl_detailinfo_actionbar);
rl.setVisibility(View.GONE);
}
}
/**
* 设置适配器
*/
private void setAdapter() {
gv_goodsList.setAdapter(new BaseAdapter() {
@Override
public int getCount() {
return goodsList.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
if (view == null) {
view = View.inflate(GoodsListActivity.this, R.layout.gridview_item_main_showgoods, null);
ViewHodler vHolder = new ViewHodler(view);
view.setTag(vHolder);
}
ViewHodler vHolder = (ViewHodler) view.getTag();
vHolder.setData(i);
return view;
}
class ViewHodler {
View item_view;
ImageView iv_pic;
TextView tv_oldPrice, tv_gPinkage, tv_nickName, tv_gTime, tv_gPrice, tv_gBrowCount, tv_gClassify, tv_gTitle;
public ViewHodler(View item_view) {
this.item_view = item_view;
initViewItem();
}
/**
* 初始化视图
*/
private void initViewItem() {
iv_pic = (ImageView) item_view.findViewById(R.id.iv_home_gridview_gimg);
tv_oldPrice = (TextView) item_view.findViewById(R.id.tv_home_gridview_newgoods_oldprice);
tv_nickName = (TextView) item_view.findViewById(R.id.tv_home_gridview_nickname);
tv_gTime = (TextView) item_view.findViewById(R.id.tv_home_gridview_gtime);
tv_gPrice = (TextView) item_view.findViewById(R.id.tv_home_listview_pai_maxprice);
tv_gBrowCount = (TextView) item_view.findViewById(R.id.tv_home_listview_pai_address);
tv_gPinkage = (TextView) item_view.findViewById(R.id.tv_home_listview_pai_gpinkage);
tv_gClassify = (TextView) item_view.findViewById(R.id.tv_home_listview_pai_gclassify);
tv_gTitle = (TextView) item_view.findViewById(R.id.tv_home_listview_pai_gtitle);
}
发布商品:
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("放弃发布的商品");
builder.setMessage("您真的放弃本次商品发布吗?");
builder.setPositiveButton("放弃", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
});
builder.setNegativeButton("继续编辑发布", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
return true;
}
/**
* 完成
*
* @param view
*/
public void onFinshed(View view) {
int countImgs = 0;
if (imgPath_list != null && imgPath_list.size() > 0) {
for (String path : imgPath_list) {
if (!"deleted".equals(path)) {
countImgs++;
}
}
}
if (countImgs == 0) {
ToastUtils.showInfo(this, "还没有商品的图片喔,快去拍一个吧");
return;
}
gInfo = new GoodsPublishInfo();
gInfo.setgImgs_list(imgPath_list);//图片
String title = et_title.getText().toString().trim();
if (TextUtils.isEmpty(title)) {
ToastUtils.showInfo(this, "标题不能为空");
et_title.requestFocus();
et_title.setCursorVisible(true);
return;
}
gInfo.setgTitle(title);
String str_price = et_price.getText().toString();
if (TextUtils.isEmpty(str_price)) {
ToastUtils.showInfo(this, "要设置一个价格,免费商品可到'免费送'中发布");
et_price.requestFocus();
et_price.setCursorVisible(true);
return;
}
String desc = et_desc.getText().toString().trim();
if (TextUtils.isEmpty(desc)) {
ToastUtils.showInfo(this, "不能没有商品简介喔");
et_desc.requestFocus();
et_desc.setCursorVisible(true);
return;
}
gInfo.setgDesc(desc);
if (rg.getCheckedRadioButtonId() == R.id.rb_publish_newgoods_pinckage) {
gInfo.setPinkage(true);
} else if (rg.getCheckedRadioButtonId() == R.id.rb_publish_newgoods_unpinckage) {
gInfo.setPinkage(false);
}
gInfo.setgClassify(classify_name);
gInfo.setgAddress(address_name);
gInfo.setgPrice(Integer.parseInt(str_price));
String str_oldPrice = et_oldPrice.getText().toString().trim();
int oldPrice = 0;
if (TextUtils.isEmpty(str_oldPrice)) {
oldPrice = 0;
} else {
oldPrice = Integer.parseInt(str_oldPrice);
}
gInfo.setgOldPrice(oldPrice);
gInfo.setgPublishType("new");
gInfo.setUrgent(cb_urgent.isChecked());
Log.e("mylog", gInfo.toString());
final Map<String, Object> params = ObjectUtils.objToMap(gInfo);
params.put("username", getSharedPreferences("login", MODE_PRIVATE).getString("username", ""));
progressDialog.showProgressDialog();
new Thread() {
@Override
public void run() {
try {
HttpStreamUtils.sendHttpRequestByPost(handler, WHAT_PUBLISH_NEW_GOODS_FINISHED, getResources().getString(R.string.url_publish_goods), params);
} catch (IOException e) {
e.printStackTrace();
handler.sendEmptyMessage(WHAT_CONNECTION_FAILED);
}
}
}.start();
}
/**
* 返回主页面
*
* @param view
*/
public void onBack(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("放弃发布的商品");
builder.setMessage("您真的放弃本次商品发布吗?");
builder.setPositiveButton("放弃", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
});
builder.setNegativeButton("继续编辑发布", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
// 上传图片
public void upload(String imgPath) {
Bitmap bitmap = BitmapFactory.decodeFile(imgPath);
float wight = bitmap.getWidth();
float height = bitmap.getHeight();
Bitmap upbitmap = ZoomBitmap.zoomImage(bitmap, (wight*3) / 4, (height*3) / 4);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
upbitmap.compress(Bitmap.CompressFormat.JPEG, 80, stream);
byte[] b = stream.toByteArray();
// 将图片流以字符串形式存储下来
String file = new String(Base64Coder.encodeLines(b));
HttpClient client = new DefaultHttpClient();
// 设置上传参数
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("file", file));
formparams.add(new BasicNameValuePair("username", getSharedPreferences("login", MODE_PRIVATE).getString("username", "1")));
formparams.add(new BasicNameValuePair("gId", gId));
HttpPost post = new HttpPost(getResources().getString(R.string.url_upload_img));
UrlEncodedFormEntity entity;
try {
entity = new UrlEncodedFormEntity(formparams, "UTF-8");
post.addHeader("Accept",
"text/javascript, text/html, application/xml, text/xml");
post.addHeader("Accept-Charset", "GBK,utf-8;q=0.7,*;q=0.3");
post.addHeader("Accept-Encoding", "gzip,deflate,sdch");
post.addHeader("Connection", "Keep-Alive");
post.addHeader("Cache-Control", "no-cache");
post.addHeader("Content-Type", "application/x-www-form-urlencoded");
post.setEntity(entity);
HttpResponse response = client.execute(post);
System.out.println(response.getStatusLine().getStatusCode());
HttpEntity e = response.getEntity();
System.out.println(EntityUtils.toString(e));
if (200 == response.getStatusLine().getStatusCode()) {
System.out.println("上传完成");
} else {
System.out.println("上传失败");
}
client.getConnectionManager().shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
调用相机:
public class MyCamera extends Activity {
private CameraView cv = null;// 继承surfaceView的自定义view 用于存放照相的图片
private Camera camera; // 声明照相机
private Button cameraFolder;// 文件夹
private Button cameraPhoto; // 照相
private Button cameraOk; // 确认
private Button cameraExit; // 关闭
private LinearLayout linearLayout;//用于存放
private LinearLayout linearLayoutCamera;
private String cameraPath;
private ArrayList<String> listPath = new ArrayList<String>();// 存放路径的list
private int tag = 0; // 删除按钮tag值,从0开始
private Camera.AutoFocusCallback mAutoFocusCallback = new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean b, Camera camera) {
if (b) {
} else {
}
}
};
// 回调用的picture,实现里边的onPictureTaken方法,其中byte[]数组即为照相后获取到的图片信息
private Camera.PictureCallback picture = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String timer = format.format(date);
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File dir = new File(Environment.getExternalStorageDirectory(), "tzsc/images");
//不存在就创建
if (!dir.exists()) {
// dir.mkdir();
dir.mkdirs();
}
File img_file = new File(dir, "IMG_" + timer + ".jpg");
Log.e("mylog", img_file.getPath());
FileOutputStream fos = null;
try {
cameraPath = img_file.getPath();
fos = new FileOutputStream(cameraPath);// 获得文件输出流
fos.write(data);// 写入文件
openCamera();// 重新打开相机
getImageView(cameraPath);// 获取照片
} catch (Exception e) {
closeCamera();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} else {
ToastUtils.showInfo(MyCamera.this, "SD卡加载失败了");
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SysApplication.getInstance().addActivity(this);
Toast.makeText(this, "请横屏拍照(效果最佳),点击屏幕可对焦", Toast.LENGTH_LONG).show();
initView();
setListener();
// 打开相机
openCamera();
}
/**
* 设置自动对焦
*/
private void setAutoFoucs() {
cv.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
camera.autoFocus(mAutoFocusCallback);
return false;
}
});
}
/**
* 设置监听器
*/
private void setListener() {
// 点击确定之后调用
cameraOk.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (listPath.size() > 0) {
Intent it = null;
Bundle bundle = new Bundle();
bundle.putStringArrayList("listPath", listPath);
if (getIntent().getIntExtra("requestCode", 0) == 10) {
it = new Intent(MyCamera.this, PublishNewGoodsActivity.class);
it.putExtras(bundle);
MyCamera.this.setResult(11, it);
} else if (getIntent().getIntExtra("requestCode", 0) == 20) {
it = new Intent(MyCamera.this, PublishNewGoodsActivity.class);
it.putExtras(bundle);
MyCamera.this.setResult(22, it);
} else if (getIntent().getIntExtra("requestCode", 0) == 30) {
it = new Intent(MyCamera.this, PublishPaiGoodsActivity.class);
it.putExtras(bundle);
MyCamera.this.setResult(33, it);
} else if (getIntent().getIntExtra("requestCode", 0) == 40) {
it = new Intent(MyCamera.this, PublishPaiGoodsActivity.class);
it.putExtras(bundle);
MyCamera.this.setResult(44, it);
} else if (getIntent().getIntExtra("requestCode", 0) == 50) {
it = new Intent(MyCamera.this, PublishFeelGoodsActivity.class);
it.putExtras(bundle);
MyCamera.this.setResult(55, it);
} else if (getIntent().getIntExtra("requestCode", 0) == 60) {
it = new Intent(MyCamera.this, PublishFeelGoodsActivity.class);
it.putExtras(bundle);
MyCamera.this.setResult(66, it);
}
finish();
} else {
ToastUtils.showInfo(MyCamera.this, "没有拍照,或选择任何图片");
}
}
});
//退出的时候 将拍过的照片删除
cameraExit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(MyCamera.this);
builder.setTitle("取消拍照");
builder.setMessage("您确定要取消拍照吗?");
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
for (String path : listPath) {
removeImg(path);
}
closeCamera();//关闭照相机
finish();
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
});
cameraPhoto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
camera.takePicture(null, null, picture);
}
});
cameraFolder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 打开系统图片浏览器
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);
}
});
}
/**
* 初始化布局
*/
private void initView() {
setContentView(R.layout.custom_camera);
linearLayout = (LinearLayout) findViewById(R.id.ll_custom_camera_images_container);
linearLayoutCamera = (LinearLayout) findViewById(R.id.ll_custom_camera_preciew);
cameraFolder = (Button) findViewById(R.id.btn_custom_camera_folder);
cameraPhoto = (Button) findViewById(R.id.btn_custom_camera_photo);
cameraOk = (Button) findViewById(R.id.btn_custom_camera_ok);
cameraExit = (Button) findViewById(R.id.btn_custom_camera_exit);
}
代码会给出,大家可以自己去详细看
论文部分:
一些想说的
自己毕业没多久,也深知那些基础差的同学毕业的困难,有问题大家直接在评论问吧,也可以加QQ:672036547,或者邮箱[email protected],目前读研任务有点重但是每天晚上尽量都会上来看看解答大家的问题。
APP源码下载地址
链接:https://pan.baidu.com/s/1_8rpVHR2qyEgHOjXUK0GQw
提取码:tdrx
后台没什么东西,就是基本的JAVA的SSM框架的数据管理而已,就不放上来了。