Conflicts:
	app/src/main/java/com/gh/gamecenter/download/GameUpdateFragmentAdapter.java
This commit is contained in:
huangzhuanghua
2017-01-20 17:14:07 +08:00
25 changed files with 168 additions and 106 deletions

View File

@ -11,6 +11,7 @@ import android.text.Spanned;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gh.gamecenter.R;
@ -99,10 +100,10 @@ public class DialogUtils {
// 标题
TextView alertdialog_title = (TextView) view.findViewById(R.id.installhint_title);
alertdialog_title.setText("重要提示");
Spanned content = Html.fromHtml("如果您使用的是"+ "<font color=\"#ff0000\">华为</font>" +"手机"+
Spanned content = Html.fromHtml("如果您使用的是"+ "<font color=\"#ff0000\">华为</font>" +""+
"<font color=\"#ff0000\">OPPO</font>" +"手机,安装游戏时请选择“" +
"<font color=\"#ff0000\">继续安装</font>" +
"”(记住不要选择“官方推荐”或“软件商店安装”)");
"”(记住不要选择“官方推荐”或“软件商店安装”)");
// 内容
TextView alertdialog_content = (TextView) view.findViewById(R.id.installhint_content);
alertdialog_content.setText(content);
@ -115,8 +116,9 @@ public class DialogUtils {
final ImageView installhint_select = (ImageView) view.findViewById(R.id.installhint_select);
TextView installhint_cancel = (TextView) view.findViewById(R.id.installhint_cancel);
LinearLayout installhint_unselect_ll = (LinearLayout) view.findViewById(R.id.installhint_unselect_ll);
installhint_cancel.setOnClickListener(new View.OnClickListener() {
installhint_unselect_ll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (installhint_unselect.getVisibility() == View.GONE) {

View File

@ -1,5 +1,6 @@
package com.gh.common.util;
import android.content.Context;
import android.graphics.Bitmap;
import com.google.zxing.BarcodeFormat;
@ -9,6 +10,7 @@ import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
@ -27,7 +29,7 @@ public class QRCodeUtils {
* @param filePath 用于存储二维码图片的文件路径
* @return 生成二维码及保存文件是否成功
*/
public static boolean createQRImage(String content, int widthPix, int heightPix, String filePath) {
public static boolean createQRImage(String content, int widthPix, int heightPix, String filePath, Context context) {
try {
if (content == null || "".equals(content)) {
return false;
@ -60,6 +62,12 @@ public class QRCodeUtils {
Bitmap bitmap = Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix);
//检查上级路径
File file = new File(context.getExternalCacheDir().getPath() + "/ShareImg");
if (!file.exists()) {
file.mkdirs();
}
FileOutputStream fileOutputStream = new FileOutputStream(filePath);
//必须使用compress方法将bitmap保存到文件中再进行读取。直接返回的bitmap是没有任何压缩的内存消耗巨大
return bitmap != null && bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(filePath));

View File

@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -559,17 +560,17 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
// 获取已安装游戏
private void getInstalledListFromServer() {
ArrayList<String> list = PackageUtils.getAllPackageName(getApplicationContext());
if (list.isEmpty()) {
if (isNewFirstLaunch) { // 延迟0.3s,防止页面未注册eventbus接收消息失败
handler.postDelayed(new Runnable() {
@Override
public void run() {
EventBus.getDefault().post(new EBUISwitch("NewsFragment", -1)); //通知更新推荐关注小版块
}
}, 300);
}
return;
}
// if (list.isEmpty()) {
// if (isNewFirstLaunch) { // 延迟0.3s,防止页面未注册eventbus接收消息失败
// handler.postDelayed(new Runnable() {
// @Override
// public void run() {
// EventBus.getDefault().post(new EBUISwitch("NewsFragment", -1)); //通知更新推荐关注小版块
// }
// }, 300);
// }
// return;
// }
PackageManager.init(list);
@ -653,9 +654,9 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
* 更新关注列表数据
*/
private void update() {
if (isNewFirstLaunch) {
EventBus.getDefault().post(new EBUISwitch("NewsFragment", -1)); //通知更新推荐关注小版块
}
// if (isNewFirstLaunch) {
// EventBus.getDefault().post(new EBUISwitch("NewsFragment", -1)); //通知更新推荐关注小版块
// }
new Thread(){
@Override
public void run() {
@ -1069,9 +1070,9 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
ivGame.setImageResource(R.drawable.ic_game_unselect);
ivNews.setImageResource(R.drawable.ic_news_unselect);
ivPersonal.setImageResource(R.drawable.ic_user_unselect);
tvGame.setTextColor(getResources().getColor(R.color.title));
tvNews.setTextColor(getResources().getColor(R.color.title));
tvPersonal.setTextColor(getResources().getColor(R.color.title));
tvGame.setTextColor(Color.parseColor("#a7a8b2"));
tvNews.setTextColor(Color.parseColor("#a7a8b2"));
tvPersonal.setTextColor(Color.parseColor("#a7a8b2"));
}
// 将所有的Fragment都置为隐藏状态。

View File

@ -105,7 +105,8 @@ public class ShareCardActivity extends BaseActivity {
@Override
public void run() {
final String filePath = getExternalCacheDir().getPath() + "/ShareImg/ShareQRCode.jpg";
boolean success = QRCodeUtils.createQRImage("http://www.ghzhushou.com/article/" + newsId+ ".html?source=appshare200", 200, 200, filePath);
boolean success = QRCodeUtils.createQRImage("http://www.ghzhushou.com/article/" + newsId+ ".html?source=appshare200"
, 200, 200, filePath, ShareCardActivity.this);
if (success) {
runOnUiThread(new Runnable() {
@Override

View File

@ -149,7 +149,8 @@ public class ShareCardPicActivity extends BaseActivity {
@Override
public void run() {
final String filePath = getExternalCacheDir().getPath() + "/ShareImg/ShareQRCode.jpg";
boolean success = QRCodeUtils.createQRImage("http://www.ghzhushou.com/article/" + newsId+ ".html?source=appshare200", 200, 200, filePath);
boolean success = QRCodeUtils.createQRImage("http://www.ghzhushou.com/article/" + newsId+ ".html?source=appshare200"
, 200, 200, filePath, ShareCardPicActivity.this);
if (success) {
runOnUiThread(new Runnable() {
@Override

View File

@ -116,13 +116,15 @@ public class LibaoDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
public int getItemCount() {
int index = 0;
if (mLibaoEntity != null) {
index = 2;
}
if (mLibaoDetailEntity != null) {
if (mLibaoEntity != null) {
index = 2;
}
if (mLibaoDetailEntity.getTime() != null || mLibaoDetailEntity.getInstallRequired()) {
index ++;
}
if (mLibaoDetailEntity.getDes() != null) {
index ++;
}

View File

@ -549,6 +549,11 @@ class GameUpdateFragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
downloadEntity.setIcon(updateEntity.getIcon());
downloadEntity.setPlatform(updateEntity.getPlatform());
downloadEntity.setPackageName(updateEntity.getPackageName());
String platform = PlatformUtils.getInstance(context)
.getPlatformName(updateEntity.getPlatform());
if (platform != null || !"官方版".equals(platform)) {
downloadEntity.setPlugin(true);
}
if (updateEntity.isPluggable()) {
downloadEntity.setPluggable(true);
} else {

View File

@ -5,7 +5,6 @@ import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
@ -107,36 +106,36 @@ public class GameFragment extends HomeFragment implements SwipeRefreshLayout.OnR
}
});
// 计算顶部下拉偏移量
fm_game_swipe_refresh.setOnTouchListener(new View.OnTouchListener() {
float y = -1;
float y1 = -1;
float offset = -1;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
y = event.getY();
break;
case MotionEvent.ACTION_MOVE:
y1 = event.getY();
offset = y - y1;
y = y1;
if ((adapterPosition == -1 || adapterPosition == 0) && Math.abs(offset) < 50) {
float d = (offset) * adapter.getDragPercent();
adapter.stretchTop(-Math.round(d), false);
}
break;
case MotionEvent.ACTION_UP:
adapter.stretchTop(-Math.round(offset), true);
break;
}
return false;
}
});
// TODO 计算顶部下拉偏移量
// fm_game_swipe_refresh.setOnTouchListener(new View.OnTouchListener() {
// float y = -1;
// float y1 = -1;
// float offset = -1;
//
// @Override
// public boolean onTouch(View v, MotionEvent event) {
// switch (event.getAction()) {
// case MotionEvent.ACTION_DOWN:
// y = event.getY();
// break;
// case MotionEvent.ACTION_MOVE:
// y1 = event.getY();
// offset = y - y1;
// y = y1;
// if ((adapterPosition == -1 || adapterPosition == 0) && Math.abs(offset) < 50) {
//
// float d = (offset) * adapter.getDragPercent();
//
// adapter.stretchTop(-Math.round(d), false);
// }
// break;
// case MotionEvent.ACTION_UP:
// adapter.stretchTop(-Math.round(offset), true);
// break;
// }
// return false;
// }
// });
}

View File

@ -145,8 +145,10 @@ class GameFragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
DisplayMetrics outMetrics = new DisplayMetrics();
fragment.getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
topHeight = (int) (outMetrics.widthPixels / 16f * 10f);
topHeightOld = (int) (outMetrics.widthPixels / 16f * 10f);
// topHeight = (int) (outMetrics.widthPixels / 16f * 10f); //TODO 盖住轮播图比例
topHeightOld = (int) (outMetrics.widthPixels / 16f * 10f); // 盖住轮播图比例时,记录初始大小
topHeight = (int) (outMetrics.widthPixels / 16f * 11.4f); //TODO 不盖住轮播图比例
cardMargin = (int) context.getResources().getDimension(R.dimen.cardview_margin);
@ -542,8 +544,9 @@ class GameFragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
LinearLayout hint = (LinearLayout) view.findViewById(R.id.viewpager_ll_hint);
RelativeLayout.LayoutParams hintParams = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
hintParams.setMargins(0, (int) (outMetrics.widthPixels / 16f * 5.3f), 0, 0);
hintParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
// hintParams.setMargins(0, (int) (outMetrics.widthPixels / 16f * 5.3f), 0, 0); // TODO 盖住轮播图点 比例
hintParams.setMargins(0, (int) (outMetrics.widthPixels / 16f * 6.5f), DisplayUtils.dip2px(context, 010), 0);
hintParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
hint.setLayoutParams(hintParams);
return new GameViewPagerViewHolder(view);

View File

@ -22,6 +22,7 @@ import rx.schedulers.Schedulers;
/**
* Created by khy on 2017/1/12.
* 验证码工具类
*/
public class GeetestUtils {
private static Context context;

View File

@ -224,7 +224,7 @@ public class GtDialog extends Dialog {
TextView textView = new TextView(getContext());
textView.setBackgroundColor(Color.WHITE);
textView.setGravity(Gravity.CENTER);
textView.setText("完成验证领取礼包");
textView.setText("完成验证即可领取礼包");
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(getDeviceWidth(), (int)((float)getDeviceWidth()/7.5));
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
contentView.addView(textView, params);

View File

@ -381,7 +381,7 @@ class InstallFragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
} else {
holder.gameNameAndSize.setText(String.format("%s - %s", gameEntity.getName(),
PlatformUtils.getInstance(context).getPlatformName(gameEntity.getApk().get(0).getPlatform())));
holder.gameDes.setText(String.format("V%s", gameEntity.getApk().get(0).getVersion()));
holder.gameDes.setText(gameEntity.getBrief());
}
GameViewUtils.setLabelList(context, holder.labelList, gameEntity.getTag());

View File

@ -72,7 +72,7 @@ public interface ApiService {
@GET("update/package/{package_name}")
Observable<GameUpdateEntity> getGameUpdate(@Path("package_name") String package_name);// 获取游戏更新
@GET("update/game/{gh_id}/package{package_name}")
@GET("update/game/{gh_id}/package/{package_name}")
Observable<GameUpdateEntity> getGameUpdate(@Path("gh_id") String gh_id,
@Path("package_name") String package_name);// 获取游戏更新

View File

@ -4,6 +4,8 @@ import android.app.ActivityManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.os.IBinder;
import android.os.PowerManager;
import android.support.annotation.Nullable;
@ -11,6 +13,7 @@ import android.support.annotation.Nullable;
import com.gh.common.util.Utils;
import com.gh.gamecenter.db.AppRunTimeDao;
import java.util.ArrayList;
import java.util.List;
import static java.lang.Thread.sleep;
@ -29,7 +32,9 @@ public class AppStaticService extends Service {
private String mPrePackageName; // 切换app前的应用包名
private String mNextPackageName; // 切换app后的应用包名
private String homePackage = "com.huawei.android.launcher"; //桌面包名 以华为为例
// private String homePackage = "com.huawei.android.launcher"; //桌面包名 以华为为例
private ArrayList<String> homePackage;
private int mRunTime;
AppRunTimeDao runTimeDao;
@ -48,6 +53,17 @@ public class AppStaticService extends Service {
mNextPackageName = getPackageName();
runTimeDao = new AppRunTimeDao(getApplicationContext());
homePackage = new ArrayList<>();
List<PackageInfo> packages = getPackageManager()
.getInstalledPackages(0);
for (PackageInfo aPackage : packages) {
if ((aPackage.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) > 0) {
Utils.log("============系统应用" + aPackage.packageName);
homePackage.add(aPackage.packageName);
}
}
// PackageManager packageManager = getApplication().getPackageManager();
// Intent intent = new Intent(Intent.ACTION_MAIN);
// intent.addCategory(Intent.CATEGORY_HOME);
@ -69,9 +85,9 @@ public class AppStaticService extends Service {
mTopTaskInfo = mTaskInfo.get(0);
mNextPackageName = mTopTaskInfo.topActivity.getPackageName();
if (homePackage.equals(mNextPackageName)) { // 跳转至桌面
if (homePackage.equals(mPrePackageName)) { // 桌面跳转至桌面 不统计
Utils.log("============ 桌面跳转至桌面 不统计");
if (homePackage.contains(mNextPackageName)) { // 跳转至桌面
if (homePackage.contains(mPrePackageName)) { // 桌面跳转至桌面 不统计
Utils.log("============ 桌面跳转至桌面 不统计" + mNextPackageName);
} else { // 非桌面跳转至桌面
// TODO 计时结束 存储数据
writeToStorage();
@ -79,16 +95,24 @@ public class AppStaticService extends Service {
}
} else { // 跳转至非桌面
if (mNextPackageName.equals(mPrePackageName)) { //如果nextPackageName和prePackageName相同(无跳转操作),那么计时增加
if (homePackage.contains(mPrePackageName)) {
// mNextPackageName不是桌面 mPrePackageName是桌面从桌面到非桌面计时开始
// TODO 计时开始
mRunTime = mRunTime + 1;
mPrePackageName = mNextPackageName; //身份转换
Utils.log("============ 跳转至非桌面 计时开始");
} else {
Utils.log("============ 计时开始");
} else { // 非桌面跳转至非桌面 mPrePackageName的计时结束mNextPackageName的计时开始
// TODO 计时结束 存储数据
Utils.log("============ 非桌面跳转至非桌面 计时结束 存储数据22"+ mRunTime);
writeToStorage();
if (mPrePackageName.equals(mNextPackageName)) {
//如果mNextPackageName和mPrePackageName相同(无跳转操作),那么计时增加
mRunTime = mRunTime + 1;
Utils.log("============ 无跳转操作");
} else {
// TODO 计时结束 存储数据
// 非桌面跳转至非桌面 mPrePackageName的计时结束mNextPackageName的计时开始
Utils.log("============ 非桌面跳转至非桌面 计时结束 存储数据22"+ mRunTime);
writeToStorage();
}
}
}
} else {

View File

@ -13,7 +13,7 @@ public class StatisticsUtils {
if (runTimeDao.isExist(packageName)) {
Utils.log("存在记录=================" + (runTimeCount + runTimeDao.getRunTimeCount(packageName)));
Utils.log("存在记录=================" + (runTimeCount + runTimeDao.getRunTimeCount(packageName)) + "==" + "本次增加:" + runTimeCount);
runTimeDao.update(new AppRunTimeInfo(packageName, (runTimeCount + runTimeDao.getRunTimeCount(packageName))));
} else {
Utils.log("不存在记录=================" + runTimeCount);

View File

@ -1,19 +1,30 @@
package com.gh.gamecenter.statistics;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.TrafficStats;
import com.gh.common.util.Utils;
import java.util.List;
/**
* Created by khy on 2017/1/3.
*/
public class TrafficUtils {
//
// PackageManager pm = getPackageManager();
// List<PackageInfo> installedPackages = (List<PackageInfo>) pm.getInstalledPackages(0);
// TrafficStats trafficStats = new TrafficStats();
//
// for (PackageInfo installedPackage : installedPackages) {
// int uid = installedPackage.applicationInfo.uid;
// long uidRxBytes = trafficStats.getUidRxBytes(uid);
// long KB = uidRxBytes / 1024;
// Utils.log(installedPackage.applicationInfo.loadLabel(pm).toString() + "===========" + KB);
// }
public static void getAppTraffic(Context context) {
PackageManager pm = context.getPackageManager();
List<PackageInfo> installedPackages = pm.getInstalledPackages(0);
TrafficStats trafficStats = new TrafficStats();
for (PackageInfo installedPackage : installedPackages) {
if ((installedPackage.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
int uid = installedPackage.applicationInfo.uid;
long uidRxBytes = trafficStats.getUidRxBytes(uid);
long KB = uidRxBytes / 1024;
Utils.log(installedPackage.applicationInfo.loadLabel(pm).toString() + "=====" + uid + "===========" + KB);
}
}
}
}