("-----", "error params");
}
itemStr = itemStr.substring(v_last);
if (itemStr.trim().startsWith("]")
|| itemStr.trim().length() <= 2) {
break;
}
}// end of while
resData.add(food);
break;
}
itemStr = sb.substring(0, a );
// decode(resData,itemStr);
food = new Food();
while (true) {
int n_last = itemStr.indexOf('=');
name = itemStr.substring(1, n_last);
System.out.println(name);
int v_first = itemStr.indexOf('=');
itemStr = itemStr.substring(v_first);
int v_last = itemStr.indexOf(';');
if (v_last == -1) {
v_last = itemStr.indexOf(']');
}
value = itemStr.substring(1, v_last);
System.out.println(value);
Log.e("name" + name, "value" + value);
if (name.equals("foodId") && name != null) {
food.foodId = Integer.parseInt(value);
} else if (name.trim().equals("foodPrice") && name != null) {
Log.e("GetNet test", "---" + name);
food.foodPrice = Float.parseFloat(value);
} else if (name.equals("foodType") && name != null) {
Log.e("GetNet test", "---" + value);
food.foodType = Integer.parseInt(value);
} else if (name.equals("foodDescri") && name != null) {
food.foodDescri = value;
} else if (name.equals("foodImage") && name != null) {
food.foodImage = value;
} else if (name.equals("foodName") && name != null) {
Log.e("GetNet test", "---" + value);
food.foodName = value;
} else {
Log.e("-----", "error params");
}
itemStr = itemStr.substring(v_last);
if (itemStr.trim().startsWith("]")
|| itemStr.trim().length() <= 2) {
break;
}
}// end of while
resData.add(food);
sb = sb.substring(a + 1);
} while (true);
return resData;
}// end of decodeResponseData()
/**
* 对图片的接收还要等等
*/
public static ArrayList
decode(ArrayList resData, String itemStr) {
String name = "";
String value = "";
Food food = new Food();
while (true) {
int n_last = itemStr.indexOf('=');
name = itemStr.substring(1, n_last);
System.out.println(name);
int v_first = itemStr.indexOf('=');
itemStr = itemStr.substring(v_first);
int v_last = itemStr.indexOf(';');
if (v_last == -1) {
v_last = itemStr.indexOf(']');
}
value = itemStr.substring(1, v_last);
System.out.println(value);
itemStr = itemStr.substring(v_last);
if (itemStr.trim().startsWith("]") || itemStr.trim().length() <= 2) {
break;
}
if (name.equals("foodId") && name != null) {
food.foodId = Integer.parseInt(value);
} else if (name.equals("foodPrice") && name != null) {
food.foodPrice = Float.parseFloat(value);
} else if (name.equals("foodType") && name != null) {
food.foodType = Integer.parseInt(value);
} else if (name.equals("foodDescri") && name != null) {
food.foodDescri = value;
} else if (name.equals("foodImage") && name != null) {
food.foodImage = value;
} else if (name.equals("foodName") && name != null) {
food.foodName = value;
} else {
Log.e("-----", "error params");
}
resData.add(food);
food = new Food();
}// end of while
return resData;
}// end of decode()
// /**
// *
// * 根据所传参数设定订餐的所有菜品的图片
// *
// * @param allImageInfo
// * 封装了所有要显示的图片信息url+foodImageView
// * url即对应服务器端资源地址(对于本方法资源即图片,同下), 可由{@link# setFoodBitmapUrl()}
// * 设定。
// * foodImageView订餐系统界面的UI元素
// */
// public static void setFoodBitMap(
// ArrayList> allImageInfo) {
//
// // 网络协议中的URL对象
// URL imageUrl = null;
// // 管理HTTP连接
// HttpURLConnection conn = null;
// try {
// if (url != null) {
//
// imageUrl = new URL(url);
// // 根据URL打开一个可以双向通信的连接
// conn = (HttpURLConnection) imageUrl.openConnection();
// // 设置连接可以输入
// conn.setDoInput(true);
// // 根据之前配置建立连接,建立后不能再设配置
// conn.connect();
// // 获取指定URL资源
// InputStream in = conn.getInputStream();
// Bitmap bitmap = BitmapFactory.decodeStream(in);
// if (foodImageView != null) {
//
// foodImageView.setImageBitmap(bitmap);
// }
// } else {
//
// Log.e("url-------", "为空");
// }
// } catch (Exception e) {
//
// e.printStackTrace();
// }
//
// }// end of setFoodBitMapByType()
/**
*
* @param foodType
* 菜品类型
* @param location
* 对应资源的位置
* @param foods
* 服务端所有的菜品信息 对应的资源名称,详细设定见{@link food.test.domain.Food}类
* @return 对应菜品类型所有资源的URL的字符串
*/
public static ArrayList getAllFoodBitmapUrl(int foodType, String location,
ArrayList foods) {
// 存储所有指定菜品的定位字符串
ArrayList urls = new ArrayList();
while (foods.iterator().hasNext()) {
// 若该菜品属于指定foodType类型
if (foodType == foods.iterator().next().foodType) {
// 暂时存一个URL
String url = "";
if (location.endsWith("/")) {
url = location + foods.iterator().next().foodImage;
} else {
url = location + "/" + foods.iterator().next().foodImage;
}
urls.add(url);
}// end of if
}
return urls;
}// end of getAllFoodBitmapUrl()
/**
* 获取指定资源的具体位置
* @param location 资源集的URL
* @param foodImage 服务端某个的菜品信息 对应的资源名称,详细设定见{@link food.test.domain.Food}类
* @return
*/
public static String getAssi
上一篇:基于IOS系统的新闻一周见手机APP设计
下一篇:试论APP广告在手机中的应用