reformat code & optimize import & reorder entries
This commit is contained in:
@ -8,19 +8,13 @@ import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
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 java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-14
|
||||
@ -29,100 +23,100 @@ import java.util.TimeZone;
|
||||
*/
|
||||
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, "官方版", 0));
|
||||
} else {
|
||||
for (int i = 0, size = tag.size(); i < size; i++) {
|
||||
View view;
|
||||
if (i == size - 1) {
|
||||
view = getGameTagView(context, tag.get(i), 0);
|
||||
} else {
|
||||
view = getGameTagView(context, tag.get(i), DisplayUtils.dip2px(context, 6));
|
||||
}
|
||||
if (view != null) {
|
||||
labelLayout.addView(view);
|
||||
}
|
||||
if (labelLayout.getChildCount() == 3) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void setLabelList(Context context, LinearLayout labelLayout, List<String> tag) {
|
||||
labelLayout.removeAllViews();
|
||||
if (tag == null || tag.isEmpty()) {
|
||||
labelLayout.addView(getGameTagView(context, "官方版", 0));
|
||||
} else {
|
||||
for (int i = 0, size = tag.size(); i < size; i++) {
|
||||
View view;
|
||||
if (i == size - 1) {
|
||||
view = getGameTagView(context, tag.get(i), 0);
|
||||
} else {
|
||||
view = getGameTagView(context, tag.get(i), DisplayUtils.dip2px(context, 6));
|
||||
}
|
||||
if (view != null) {
|
||||
labelLayout.addView(view);
|
||||
}
|
||||
if (labelLayout.getChildCount() == 3) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static TextView getGameTagView(Context context, String tagStr, int rightMargin) {
|
||||
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
||||
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
lparams.rightMargin = rightMargin;
|
||||
TextView tag = new TextView(context);
|
||||
tag.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
|
||||
tag.setSingleLine(true);
|
||||
tag.setText(tagStr);
|
||||
if ("官方版".equals(tagStr) || "已关注".equals(tagStr)) {
|
||||
tag.setBackgroundResource(R.drawable.border_green_bg);
|
||||
tag.setTextColor(context.getResources().getColor(R.color.tag_green));
|
||||
} else {
|
||||
String colorStr = TagUtils.getInstance(context).getColor(tagStr);
|
||||
if (colorStr == null) {
|
||||
return null;
|
||||
}
|
||||
int color = Color.parseColor(colorStr);
|
||||
GradientDrawable gradientDrawable = new GradientDrawable();
|
||||
gradientDrawable.setColor(Color.TRANSPARENT);
|
||||
gradientDrawable.setStroke(DisplayUtils.dip2px(context, 0.6f), color);
|
||||
tag.setBackgroundDrawable(gradientDrawable);
|
||||
private static TextView getGameTagView(Context context, String tagStr, int rightMargin) {
|
||||
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
||||
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
lparams.rightMargin = rightMargin;
|
||||
TextView tag = new TextView(context);
|
||||
tag.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
|
||||
tag.setSingleLine(true);
|
||||
tag.setText(tagStr);
|
||||
if ("官方版".equals(tagStr) || "已关注".equals(tagStr)) {
|
||||
tag.setBackgroundResource(R.drawable.border_green_bg);
|
||||
tag.setTextColor(context.getResources().getColor(R.color.tag_green));
|
||||
} else {
|
||||
String colorStr = TagUtils.getInstance(context).getColor(tagStr);
|
||||
if (colorStr == null) {
|
||||
return null;
|
||||
}
|
||||
int color = Color.parseColor(colorStr);
|
||||
GradientDrawable gradientDrawable = new GradientDrawable();
|
||||
gradientDrawable.setColor(Color.TRANSPARENT);
|
||||
gradientDrawable.setStroke(DisplayUtils.dip2px(context, 0.6f), color);
|
||||
tag.setBackgroundDrawable(gradientDrawable);
|
||||
// tag.setBackgroundResource(R.drawable.border_blue_bg);
|
||||
tag.setTextColor(color);
|
||||
}
|
||||
tag.setLayoutParams(lparams);
|
||||
tag.setPadding(DisplayUtils.dip2px(context, 3),
|
||||
0,
|
||||
DisplayUtils.dip2px(context, 3),
|
||||
DisplayUtils.dip2px(context, 1));
|
||||
return tag;
|
||||
}
|
||||
tag.setTextColor(color);
|
||||
}
|
||||
tag.setLayoutParams(lparams);
|
||||
tag.setPadding(DisplayUtils.dip2px(context, 3),
|
||||
0,
|
||||
DisplayUtils.dip2px(context, 3),
|
||||
DisplayUtils.dip2px(context, 1));
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static String getGameTestDate(long testTime) {
|
||||
public static String getGameTestDate(long testTime) {
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
|
||||
format.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user