修复了代码中存在的很多问题。

This commit is contained in:
qinjiaming_branch 2016-08-24 09:18:54 +08:00
parent daa82f6230
commit a761faf5b7
30 changed files with 70 additions and 86 deletions

View File

@ -1,6 +1,6 @@
package com.stone.shop.adapter;
//import android.R.integer;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

View File

@ -81,7 +81,6 @@ public class LoginActivity extends Activity implements OnClickListener {
mUserInfo.setVisibility(android.view.View.VISIBLE);
mUserInfo.setText(response.getString("nickname"));
} catch (JSONException e) {
//e.printStackTrace();
logger.log(Level.SEVERE, "something may be wrong", e);
}
}
@ -105,7 +104,6 @@ public class LoginActivity extends Activity implements OnClickListener {
// QQ登陆, 获取实例
// mQQAuth = QQAuth.createInstance(APP_ID,
// this.getApplicationContext());
mTencent = Tencent.createInstance(APP_ID, this.getApplicationContext());
btnLogin = (Button) findViewById(R.id.btn_login);
@ -128,11 +126,19 @@ public class LoginActivity extends Activity implements OnClickListener {
getUserInfo();
}
public String getusername()
{
return username;
}
public String getpassword()
{
return password;
}
private void getUserInfo() {
SharedPreferences sp = getSharedPreferences("UserInfo", 0);
etUsername.setText(sp.getString("username", null));
etPassword.setText(sp.getString("password", null));
//etUsername.setText(sp.getString("username", null));
etUsername.setText(sp.getString(getusername(), null));
etPassword.setText(sp.getString(getpassword(), null));
}
// 保存用户的登陆记录
@ -165,7 +171,6 @@ public class LoginActivity extends Activity implements OnClickListener {
if (!Util.isNetworkConnected(this)) {
toast("木有网络 ( ⊙ o ⊙ ) ");
// } else if (username.equals("") || password.equals("")) {
} else if ("".equals(username) || "".equals(password)) {
toast("请输入账号和密码");
break;
@ -233,12 +238,11 @@ public class LoginActivity extends Activity implements OnClickListener {
return;
}
JSONObject jsonResponse = (JSONObject) response;
if (jsonResponse!=null && jsonResponse.length() == 0)
if (jsonResponse.length() == 0)
{
Util.showResultDialog(LoginActivity.this, "返回为空", "登录失败");
return;
}
// Util.showResultDialog(LoginActivity.this, response.toString(), "登录成功");
doComplete((JSONObject) response);
Logger logger = Logger.getLogger("lavasoft");
try
@ -248,7 +252,6 @@ public class LoginActivity extends Activity implements OnClickListener {
catch (JSONException e)
{
// TODO
//e.printStackTrace();
logger.log(Level.SEVERE, "something may be wrong", e);
}

View File

@ -6,7 +6,6 @@ import android.app.Activity;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
//import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@ -22,7 +21,6 @@ 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.ui.DialogOrder;
import com.stone.util.Util;
/**
@ -112,7 +110,7 @@ public class OrderActivity extends Activity implements OnClickListener{
if (count == 4) {
toast("每份订单数量不能超过 4");
} else {
tvOrderCount.setText( (count+1)+"");
tvOrderCount.setText(Integer.toString(count+1));
}
break;
case R.id.btn_order_count_less:
@ -120,7 +118,6 @@ public class OrderActivity extends Activity implements OnClickListener{
if (count == 1) {
toast("每份订单数量至少为 1 ");
} else {
//tvOrderCount.setText( (count-1)+"");
tvOrderCount.setText(Integer.toString(count-1));
}
break;
@ -134,6 +131,7 @@ public class OrderActivity extends Activity implements OnClickListener{
case R.id.btn_dlg_ok:
time = tpOrderTime.getCurrentHour()+ " : " + tpOrderTime.getCurrentMinute();
dlgSetOrderTime.dismiss();
break; //by qinjiaming
case R.id.btn_order_submit:
postOrder();
finish();

View File

@ -23,7 +23,6 @@ import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import cn.bmob.v3.BmobQuery;
//import cn.bmob.v3.listener.DeleteListener;
import cn.bmob.v3.listener.FindListener;
import cn.bmob.v3.listener.SaveListener;
@ -74,7 +73,6 @@ public class ReservationActivity extends Activity {
}
} catch (ParseException e) {
// TODO
//e.printStackTrace();
logger.log(Level.SEVERE, "something may be wrong", e);
}

View File

@ -52,7 +52,6 @@ public class ShopItemActivity extends Activity implements OnClickListener, OnIte
// 店铺商品列表
private ListView lvGoodsList;
private GoodsListAdapter goodsListAdapter;
// private Button btnBuyGood;
// 店铺简介页中的控件
private TextView tvShopName; // 店铺名
@ -142,7 +141,6 @@ public class ShopItemActivity extends Activity implements OnClickListener, OnIte
@Override
public void onSuccess(List<Good> goods) {
// toast("查询商品成功, 共" + goods.size());
if (goods.size() == 0) {
toast("该店还没有添加商品");
}
@ -205,49 +203,16 @@ public class ShopItemActivity extends Activity implements OnClickListener, OnIte
tvUser.setText(user);
tvContent.setText(content);
llCommitParent.addView(view);
tvUser = null;
tvContent = null;
}
// public void clickBuyGood(View v) {
// Intent toOrderActivity = new Intent(ShopItemActivity.this, OrderActivity.class);
// Bundle bundle = new Bundle();
// bundle.putSerializable("shop", shop );
// bundle.putString("shopID", shopID); //商铺的ID需要单独传递,否则获取到的是null
// toOrderActivity.putExtras(bundle);
// startActivity(toOrderActivity);
// //-------------------------------------------------------------------
// toast("亲, 记得在弹出的对话框中选择数量哦");
// Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
// lvGoodsList.startAnimation(shake);
//
// // 显示订单对话框
// orderDlg = new DialogOrder(this, R.style.MyDialog);
// orderDlg.show();
// // 得到订单对话框的View
// LayoutInflater factory = LayoutInflater.from(this);
// dlgOrderView = factory.inflate(R.layout.dlg_order, null);
// tvOrderCount = (TextView) dlgOrderView
// .findViewById(R.id.tv_order_count);
// etOrderPhone = (EditText) dlgOrderView
// .findViewById(R.id.et_order_phone);
// etOrderWords = (EditText) dlgOrderView
// .findViewById(R.id.et_order_phone);
// ;
// btnOrderCount = (Button) dlgOrderView
// .findViewById(R.id.btn_order_count);
// btnOrderSubmit = (Button) dlgOrderView
// .findViewById(R.id.btn_order_submit);
// btnOrderCount.setOnClickListener(this);
// btnOrderSubmit.setOnClickListener(this);
// //-------------------------------------------------------------------
// }
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_commit:
if (etCommit.getText().toString().equals("")) {
if ("".equals(etCommit.getText().toString())) {
toast("亲,先写一句吧");
} else {
SimpleDateFormat formatter = new SimpleDateFormat(
@ -286,17 +251,7 @@ public class ShopItemActivity extends Activity implements OnClickListener, OnIte
bundle.putString("shopID", shopID); //商铺的ID需要单独传递,否则获取到的是null
toOrderActivity.putExtras(bundle);
startActivity(toOrderActivity);
//toast("点击了Position " + position);
// if(view.getId() == R.id.btn_buy_good) {
// toast("点击了购买按钮");
// Intent toOrderActivity = new Intent(ShopItemActivity.this, OrderActivity.class);
// Bundle bundle = new Bundle();
// bundle.putSerializable("shop", shop );
// bundle.putSerializable("good", selectGood);
// bundle.putString("shopID", shopID); //商铺的ID需要单独传递,否则获取到的是null
// toOrderActivity.putExtras(bundle);
// startActivity(toOrderActivity);
// }
break;
case 1:
break;

View File

@ -1,7 +1,8 @@
package com.stone.ui;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
@ -130,8 +131,10 @@ public class AutoScrollViewPager extends ViewPager {
scroller = new CustomDurationScroller(getContext(), (Interpolator)interpolatorField.get(null));
scrollerField.set(this, scroller);
} catch (Exception e) {
e.printStackTrace();
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
}
}
@ -218,6 +221,7 @@ public class AutoScrollViewPager extends ViewPager {
case SCROLL_WHAT:
scrollOnce();
sendScrollMessage(interval);
break; //by qinjiaming
default:
break;
}

View File

@ -1,5 +1,8 @@
package com.stone.ui;
import java.util.logging.Level;
import java.util.logging.Logger;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
@ -46,6 +49,8 @@ public class ViewPagerCompat extends ViewPager {
try {
return super.onTouchEvent(ev);
} catch (Exception e) {
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
return false;
}
}

View File

@ -12,6 +12,8 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -112,8 +114,9 @@ private static final String TAG = "SDK_Sample.Util";
* @return byte[]
*/
public static byte[] hexStringToBytes(String hexString) {
if (hexString == null || hexString.equals("")) {
return null;
if (hexString == null || "".equals(hexString)) {
byte[] forreturn = new byte[0];
return forreturn;
}
hexString = hexString.toUpperCase();
int length = hexString.length() / 2;
@ -148,7 +151,8 @@ private static final String TAG = "SDK_Sample.Util";
try {
bytes = str.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
}
if (bytes == null) return null;
StringBuilder sb=new StringBuilder(bytes.length*2);
@ -156,7 +160,7 @@ private static final String TAG = "SDK_Sample.Util";
for(int i=0;i<bytes.length;i++)
{
sb.append(hexString.charAt((bytes[i]&0xf0)>>4));
sb.append(hexString.charAt((bytes[i]&0x0f)>>0));
sb.append(hexString.charAt((bytes[i]&0x0f)));
}
return sb.toString();
}
@ -177,7 +181,8 @@ private static final String TAG = "SDK_Sample.Util";
}
catch(Exception e)
{
e.printStackTrace();
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
}
}
@ -187,7 +192,8 @@ private static final String TAG = "SDK_Sample.Util";
}
catch (Exception e1)
{
e1.printStackTrace();
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e1);
}
return s;
}
@ -203,7 +209,8 @@ private static final String TAG = "SDK_Sample.Util";
try {
output.close();
} catch (Exception e) {
e.printStackTrace();
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
}
return result;
@ -221,9 +228,11 @@ private static final String TAG = "SDK_Sample.Util";
inStream = httpConnection.getInputStream();
}
} catch (MalformedURLException e) {
e.printStackTrace();
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
} catch (IOException e) {
e.printStackTrace();
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
}
byte[] data = inputStreamToByte(inStream);
@ -241,21 +250,25 @@ private static final String TAG = "SDK_Sample.Util";
bytestream.close();
return imgdata;
}catch(Exception e){
e.printStackTrace();
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
}
return null;
byte[] forreturn = new byte[0];
return forreturn;
}
public static byte[] readFromFile(String fileName, int offset, int len) {
byte[] forreturn = new byte[0];
if (fileName == null) {
return null;
return forreturn;
}
File file = new File(fileName);
if (!file.exists()) {
Log.i(TAG, "readFromFile: file not found");
return null;
return forreturn;
}
if (len == -1) {
@ -266,15 +279,15 @@ private static final String TAG = "SDK_Sample.Util";
if(offset <0){
Log.e(TAG, "readFromFile invalid offset:" + offset);
return null;
return forreturn;
}
if(len <=0 ){
Log.e(TAG, "readFromFile invalid len:" + len);
return null;
return forreturn;
}
if(offset + len > (int) file.length()){
Log.e(TAG, "readFromFile invalid file len:" + file.length());
return null;
return forreturn;
}
byte[] b = null;
@ -377,15 +390,19 @@ private static final String TAG = "SDK_Sample.Util";
Bitmap bitmap = BitmapFactory.decodeStream(stream , null, opts);
return bitmap;
} catch (OutOfMemoryError e) {
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
return null;
} catch (Exception e) {
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
return null;
}
}
private static final int MAX_DECODE_PICTURE_SIZE = 1920 * 1440;
public static Bitmap extractThumbNail(final String path, final int height, final int width, final boolean crop) {
Assert.assertTrue(path != null && !path.equals("") && height > 0 && width > 0);
Assert.assertTrue(path != null && !"".equals(path) && height > 0 && width > 0);
BitmapFactory.Options options = new BitmapFactory.Options();
@ -457,6 +474,8 @@ private static final String TAG = "SDK_Sample.Util";
} catch (final OutOfMemoryError e) {
Log.e(TAG, "decode bitmap failed: " + e.getMessage());
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
options = null;
}
@ -569,10 +588,12 @@ private static final String TAG = "SDK_Sample.Util";
Log.v(TAG, "image download finished." + imageUri);
} catch (OutOfMemoryError e) {
e.printStackTrace();
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
bitmap = null;
} catch (IOException e) {
e.printStackTrace();
Logger logger = Logger.getLogger("lavasoft");
logger.log(Level.SEVERE, "something may be wrong", e);
Log.v(TAG, "getbitmap bmp fail---");
bitmap = null;
}