提交项目

This commit is contained in:
huangzhuanghua
2016-04-25 11:18:59 +08:00
commit 3f29f7b39a
660 changed files with 68059 additions and 0 deletions

View File

@ -0,0 +1,127 @@
package com.gh.common.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import android.content.Context;
import android.util.TypedValue;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import com.gh.gamecenter.R;
/**
*
* @author 温冠超
* @email 294299195@qq.com
* @date 2015-8-14
* @update 2015-8-14
* @des 设置列表中game item视图上的工具类
*/
public class GameViewUtils {
public static void setLabelList(Context context, LinearLayout labelLayout,
List<String> tag) {
labelLayout.removeAllViews();
if (tag == null || tag.isEmpty()) {
labelLayout.addView(getGameTagView(context, "官方版"));
} else {
for (int i = 0, size = tag.size() > 3 ? 3 : tag.size(); i < size; i++) {
labelLayout.addView(getGameTagView(context, tag.get(i)));
}
}
}
// 获取游戏标签列表视图
public static void setLabelList(Context context, LinearLayout labelLayout,
String tag) {
labelLayout.removeAllViews();
// 添加tag标签
if (tag != null && !tag.isEmpty()) {
String[] tags = tag.split(",");
if (tags != null && tags.length > 0) {
for (int i = 0; i < tags.length; i++) {
labelLayout.addView(getGameTagView(context, tags[i]));
}
}
}
}
public static TextView getGameTagView(Context context, String tagStr) {
LayoutParams lp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.setMargins(0, 0, DisplayUtils.dip2px(context, 5), 0);
TextView tag = new TextView(context);
tag.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
tag.setSingleLine(true);
tag.setText(tagStr);
if ("官方版".equals(tagStr) || "已关注".equals(tagStr)) {
tag.setBackgroundResource(R.drawable.border_red_bg);
tag.setTextColor(0xffbc2132);
} else if ("已安装".equals(tagStr)) {
tag.setBackgroundResource(R.drawable.border_blue_bg);
tag.setTextColor(0xff1BA4FC);
} else {
tag.setBackgroundResource(R.drawable.border_green_bg);
tag.setTextColor(0xff2ec991);
}
tag.setLayoutParams(lp);
tag.setPadding(DisplayUtils.dip2px(context, 4),
DisplayUtils.dip2px(context, 2),
DisplayUtils.dip2px(context, 4),
DisplayUtils.dip2px(context, 2));
return tag;
}
public static String getGameTestDate(long testTime) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
Locale.CHINA);
format.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
String testDate;
try {
long today = format.parse(format.format(new Date())).getTime();
long day = Long.parseLong(testTime + "000");
Calendar calendar = Calendar.getInstance(TimeZone
.getTimeZone("Asia/Shanghai"));
calendar.setTimeInMillis(day);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
if (day >= today && day < today + 86400 * 1000) {
testDate = "今天" + hour + "";
} else if (day >= today + 86400 * 1000
&& day < today + 86400 * 1000 * 2) {
testDate = "明天" + hour + "";
} else if (day >= today + 86400 * 1000 * 2
&& day < today + 86400 * 1000 * 3) {
testDate = "后天" + hour + "";
} else if (day >= today - 86400 * 1000 && day < today) {
testDate = "昨天" + hour + "";
} else {
format = new SimpleDateFormat("MM-dd", Locale.CHINA);
testDate = format.format(day) + " " + hour + "";
}
return testDate;
} catch (ParseException e) {
e.printStackTrace();
long day = Long.parseLong(testTime + "000");
Calendar calendar = Calendar.getInstance(TimeZone
.getTimeZone("Asia/Shanghai"));
calendar.setTimeInMillis(day);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
format = new SimpleDateFormat("MM-dd", Locale.CHINA);
testDate = format.format(day) + " " + hour + "";
return testDate;
}
}
}