Compare commits
34 Commits
master
...
a5d952a5f7
| Author | SHA1 | Date | |
|---|---|---|---|
| a5d952a5f7 | |||
| 682c87e27d | |||
| 84883cd7a8 | |||
| e519adfb02 | |||
| 4bbdcd9a63 | |||
| fafc03993d | |||
| 42854c9555 | |||
| 4ae70fd9ef | |||
| 53dbef8f48 | |||
| 59783d89e3 | |||
| 260ff0825b | |||
| a14f3c6561 | |||
| 0cd4779419 | |||
| 2a5dfbd73b | |||
| 753ef290eb | |||
| 25c77aad68 | |||
| 27457cf8ce | |||
| 494d7e63ff | |||
| b8b8989166 | |||
| 0acf5066b0 | |||
| e10fe43759 | |||
| 9fdeb528cc | |||
| 540e24d5eb | |||
| 81e5f90ab8 | |||
| c8fb7a5d93 | |||
| 824c5fed37 | |||
| 7df8c91156 | |||
| 3311bda502 | |||
| ab21451616 | |||
| ecdbb788f5 | |||
| 7c9a2c44fd | |||
| fd76fa3a2f | |||
| 632000cb56 | |||
| 646719c3fb |
@@ -11,8 +11,8 @@ android {
|
|||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 34
|
targetSdkVersion 34
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
versionCode 568888804
|
versionCode 568888806
|
||||||
versionName "SNFLauncher-5.6.4"
|
versionName "SNFLauncher-5.6.6"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
buildConfigField "String", "MANUFACTURER", '"allwinner"'
|
buildConfigField "String", "MANUFACTURER", '"allwinner"'
|
||||||
buildConfigField "boolean", "LOG_ENABLED", "false"
|
buildConfigField "boolean", "LOG_ENABLED", "false"
|
||||||
@@ -99,7 +99,7 @@ dependencies {
|
|||||||
//消息组件
|
//消息组件
|
||||||
implementation 'org.greenrobot:eventbus:3.1.1'
|
implementation 'org.greenrobot:eventbus:3.1.1'
|
||||||
|
|
||||||
implementation 'com.google.android.gms:play-services-ads:20.3.0'
|
// implementation 'com.google.android.gms:play-services-ads:20.3.0'
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -48,7 +48,7 @@ public class SystemService extends Service implements AppnetCallback, NetStateCh
|
|||||||
private static final int WHAT_PERIODIC_REQUEST = 4;
|
private static final int WHAT_PERIODIC_REQUEST = 4;
|
||||||
|
|
||||||
// 请求间隔(8小时,正式环境)
|
// 请求间隔(8小时,正式环境)
|
||||||
// private static final long REQUEST_INTERVAL = 8 * 60 * 60 * 1000;
|
// private static final long REQUEST_INTERVAL = 8 * 60 * 60 * 1000;
|
||||||
// 测试用短间隔
|
// 测试用短间隔
|
||||||
private static final long REQUEST_INTERVAL = 5 * 60 * 1000; // 5分钟
|
private static final long REQUEST_INTERVAL = 5 * 60 * 1000; // 5分钟
|
||||||
//持久化存储成功请求时间
|
//持久化存储成功请求时间
|
||||||
@@ -167,6 +167,10 @@ public class SystemService extends Service implements AppnetCallback, NetStateCh
|
|||||||
handler.sendEmptyMessageDelayed(WHAT_PERIODIC_REQUEST, 60 * 60 * 1000);
|
handler.sendEmptyMessageDelayed(WHAT_PERIODIC_REQUEST, 60 * 60 * 1000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(currentTime<lastSuccessTime){
|
||||||
|
handler.sendEmptyMessage(WHAT_PERIODIC_REQUEST);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
long nextRequestTime = lastSuccessTime + REQUEST_INTERVAL;
|
long nextRequestTime = lastSuccessTime + REQUEST_INTERVAL;
|
||||||
long delay = Math.max(0, nextRequestTime - currentTime);
|
long delay = Math.max(0, nextRequestTime - currentTime);
|
||||||
@@ -312,12 +316,19 @@ public class SystemService extends Service implements AppnetCallback, NetStateCh
|
|||||||
// handleRequestFailure();
|
// handleRequestFailure();
|
||||||
// 仅保留首次请求完成标记(必须保留,避免无限重复首次请求)
|
// 仅保留首次请求完成标记(必须保留,避免无限重复首次请求)
|
||||||
if (!isFirstRequestDone) {
|
if (!isFirstRequestDone) {
|
||||||
|
scheduleNextPeriodicRequest();
|
||||||
markFirstRequestDone();
|
markFirstRequestDone();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
boolean isTimeout = code==0 || message.contains("The server is busy");
|
boolean isTimeout = code==0 || message.contains("The server is busy");
|
||||||
if (isTimeout) {
|
if (isTimeout) {
|
||||||
handler.removeMessages(WHAT_PERIODIC_REQUEST);
|
long lastSuccessTime = getLastSuccessTime();
|
||||||
handler.sendEmptyMessageDelayed(WHAT_PERIODIC_REQUEST, REQUEST_INTERVAL);
|
if (lastSuccessTime == 0) {
|
||||||
|
scheduleNextPeriodicRequest();
|
||||||
|
} else {
|
||||||
|
handler.removeMessages(WHAT_PERIODIC_REQUEST);
|
||||||
|
handler.sendEmptyMessageDelayed(WHAT_PERIODIC_REQUEST, REQUEST_INTERVAL);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//保留原逻辑
|
//保留原逻辑
|
||||||
scheduleNextPeriodicRequest();
|
scheduleNextPeriodicRequest();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.ik.mboxlauncher.ui;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
import androidx.media3.common.Player;
|
import androidx.media3.common.Player;
|
||||||
|
|
||||||
@@ -11,10 +12,8 @@ import com.android.monitor.DataBeeObserver;
|
|||||||
import com.android.monitor.impl.EventFactory;
|
import com.android.monitor.impl.EventFactory;
|
||||||
import com.android.nebulasdk.ADManager;
|
import com.android.nebulasdk.ADManager;
|
||||||
import com.android.util.LogUtils;
|
import com.android.util.LogUtils;
|
||||||
import com.ik.mboxlauncher.view.AdMultiView;
|
|
||||||
import com.ik.mboxlauncher.view.MultiView;
|
import com.ik.mboxlauncher.view.MultiView;
|
||||||
import com.ik.mboxlauncher.view.HomeMultiView;
|
import com.ik.mboxlauncher.view.HomeMultiView;
|
||||||
import com.seraphic.ad.AdStateListener;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -27,18 +26,19 @@ public class ADSWindowManager implements HomeMultiView.MultiViewListener{
|
|||||||
private int currentADIndex=0;
|
private int currentADIndex=0;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private static ADSWindowManager mInstance = null;
|
private static ADSWindowManager mInstance = null;
|
||||||
private Handler mHandler= new Handler();
|
private MyHandler mHandler;
|
||||||
|
|
||||||
/**广告延迟播放时间*/
|
/**广告延迟播放时间*/
|
||||||
// private static final long DELAYED_TIME=1000*60*5;
|
private static final long DELAYED_TIME=1000*60*5;
|
||||||
private static final long DELAYED_TIME=1000*60*1;
|
// private static final long DELAYED_TIME=1000*60*1;
|
||||||
|
|
||||||
/**是否开启播放模式*/
|
/**是否开启播放模式*/
|
||||||
private boolean isPlayMode=false;
|
private boolean isPlayMode=false;
|
||||||
|
//防止所有视频广告位都无法播放 进入startVideo()死循环
|
||||||
|
private boolean hasOncePlayOk;
|
||||||
private ADSWindowManager(Context context){
|
private ADSWindowManager(Context context){
|
||||||
this.mContext =context;
|
this.mContext =context;
|
||||||
|
mHandler=new MyHandler(Looper.getMainLooper());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(Context context){
|
public static void init(Context context){
|
||||||
@@ -64,7 +64,7 @@ public class ADSWindowManager implements HomeMultiView.MultiViewListener{
|
|||||||
for (MultiView multiView:mMultiViewList){
|
for (MultiView multiView:mMultiViewList){
|
||||||
multiView.setMultiViewListener(this);
|
multiView.setMultiViewListener(this);
|
||||||
}
|
}
|
||||||
|
if(hasOncePlayOk) hasOncePlayOk=false;
|
||||||
}
|
}
|
||||||
public void startVideo(){
|
public void startVideo(){
|
||||||
isPlayMode =true;
|
isPlayMode =true;
|
||||||
@@ -99,9 +99,6 @@ public class ADSWindowManager implements HomeMultiView.MultiViewListener{
|
|||||||
if(mMultiViewList!=null&¤tADIndex<mMultiViewList.size()) {
|
if(mMultiViewList!=null&¤tADIndex<mMultiViewList.size()) {
|
||||||
if(mMultiViewList.get(currentADIndex) instanceof HomeMultiView) {
|
if(mMultiViewList.get(currentADIndex) instanceof HomeMultiView) {
|
||||||
mMultiViewList.get(currentADIndex).resetView();
|
mMultiViewList.get(currentADIndex).resetView();
|
||||||
} else if (mMultiViewList.get(currentADIndex) instanceof AdMultiView
|
|
||||||
&& mMultiViewList.get(currentADIndex).isAdPlaying()) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LogUtils.loge("按键事件触发停止播放,wait ad play "+DELAYED_TIME+" , index is "+currentADIndex);
|
LogUtils.loge("按键事件触发停止播放,wait ad play "+DELAYED_TIME+" , index is "+currentADIndex);
|
||||||
@@ -116,22 +113,21 @@ public class ADSWindowManager implements HomeMultiView.MultiViewListener{
|
|||||||
if(adInfo!=null){
|
if(adInfo!=null){
|
||||||
try {
|
try {
|
||||||
if (adInfo.getState() == 1) {
|
if (adInfo.getState() == 1) {
|
||||||
if(multiView instanceof AdMultiView){
|
|
||||||
LogUtils.loge(" ad playing id:" + adInfo.getId());
|
|
||||||
multiView.onVideoRestart(adInfo.getLocalFilePath());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file = new File(adInfo.getLocalFilePath());
|
File file = new File(adInfo.getLocalFilePath());
|
||||||
if (file.isFile() && file.exists()) {
|
if (file.isFile() && file.exists()) {
|
||||||
LogUtils.loge(" ad playing id:" + adInfo.getId());
|
LogUtils.loge(" ad playing id:" + adInfo.getId());
|
||||||
multiView.onVideoRestart(adInfo.getLocalFilePath());
|
multiView.onVideoRestart(adInfo.getLocalFilePath());
|
||||||
|
hasOncePlayOk=true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
LogUtils.loge("error file is not exists:"+adInfo.getLocalFilePath());
|
LogUtils.loge("error file is not exists:"+adInfo.getLocalFilePath());
|
||||||
|
if(mMultiViewList.size()-1==currentADIndex&&!hasOncePlayOk){
|
||||||
|
hasOncePlayOk=false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
currentADIndex++;
|
currentADIndex++;
|
||||||
if (currentADIndex >= mMultiViewList.size()) { //所有文件都不存在,跳出循环,都不播放
|
if (currentADIndex >= mMultiViewList.size()) { //所有文件都不存在,跳出循环,都不播放
|
||||||
@@ -156,7 +152,7 @@ public class ADSWindowManager implements HomeMultiView.MultiViewListener{
|
|||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
if(playbackState== Player.STATE_ENDED||playbackState==Player.STATE_IDLE|| playbackState==AdStateListener.AD_ERROR) {
|
if(playbackState== Player.STATE_ENDED||playbackState==Player.STATE_IDLE|| playbackState==0) {
|
||||||
// if(playbackState== Player.STATE_ENDED){
|
// if(playbackState== Player.STATE_ENDED){
|
||||||
// if(currentADIndex<mAdsInfoBeanList.size()) {
|
// if(currentADIndex<mAdsInfoBeanList.size()) {
|
||||||
// DataBeeObserver.getInstance().recordEventMsg(
|
// DataBeeObserver.getInstance().recordEventMsg(
|
||||||
@@ -195,6 +191,10 @@ public class ADSWindowManager implements HomeMultiView.MultiViewListener{
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
private static class MyHandler extends Handler{
|
||||||
|
private MyHandler(Looper looper){
|
||||||
|
super(looper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,4 +84,11 @@ public class FragmentManager {
|
|||||||
public void destory(){
|
public void destory(){
|
||||||
mInstance = null;
|
mInstance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPackageName(){
|
||||||
|
if(mContext!=null){
|
||||||
|
return mContext.getPackageName();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,12 @@ import android.widget.GridView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.media3.common.Player;
|
import androidx.media3.common.Player;
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||||
|
|
||||||
import com.android.MXQConfig;
|
import com.android.MXQConfig;
|
||||||
|
import com.android.SharePreUtils;
|
||||||
import com.android.api.encrytion.UtilEncrypt;
|
import com.android.api.encrytion.UtilEncrypt;
|
||||||
import com.android.database.lib.AdsInfoBean;
|
import com.android.database.lib.AdsInfoBean;
|
||||||
import com.android.database.lib.AppBean;
|
import com.android.database.lib.AppBean;
|
||||||
@@ -41,9 +43,13 @@ import com.android.monitor.DataBeeObserver;
|
|||||||
import com.android.nebulasdk.ADManager;
|
import com.android.nebulasdk.ADManager;
|
||||||
import com.android.nebulasdk.AppManager;
|
import com.android.nebulasdk.AppManager;
|
||||||
import com.android.nebulasdk.bean.FavNaviBean;
|
import com.android.nebulasdk.bean.FavNaviBean;
|
||||||
|
import com.android.nebulasdk.bean.UploadADBean;
|
||||||
|
import com.android.nebulasdk.presenter.DownLoadAdPresenter;
|
||||||
|
import com.android.nebulasdk.presenter.callback.AppnetCallback;
|
||||||
import com.android.util.GsonUtil;
|
import com.android.util.GsonUtil;
|
||||||
import com.android.util.IntentUtil;
|
import com.android.util.IntentUtil;
|
||||||
import com.android.util.LogUtils;
|
import com.android.util.LogUtils;
|
||||||
|
import com.android.util.NetUtil;
|
||||||
import com.android.util.PakageInstallUtil;
|
import com.android.util.PakageInstallUtil;
|
||||||
import com.ik.mboxlauncher.R;
|
import com.ik.mboxlauncher.R;
|
||||||
import com.ik.mboxlauncher.ui.adapter.CustomAppAdapter;
|
import com.ik.mboxlauncher.ui.adapter.CustomAppAdapter;
|
||||||
@@ -56,10 +62,10 @@ import com.ik.mboxlauncher.ui.fragment.MusicFragment;
|
|||||||
import com.ik.mboxlauncher.ui.fragment.RecommendFragment;
|
import com.ik.mboxlauncher.ui.fragment.RecommendFragment;
|
||||||
import com.ik.mboxlauncher.ui.fragment.VideoFragment;
|
import com.ik.mboxlauncher.ui.fragment.VideoFragment;
|
||||||
import com.ik.mboxlauncher.view.MultiView;
|
import com.ik.mboxlauncher.view.MultiView;
|
||||||
import com.ik.mboxlauncher.view.AdMultiView;
|
|
||||||
import com.ik.mboxlauncher.view.CustomRecyclerView;
|
import com.ik.mboxlauncher.view.CustomRecyclerView;
|
||||||
import com.ik.mboxlauncher.view.SplashView;
|
import com.ik.mboxlauncher.view.SplashView;
|
||||||
import com.ik.mboxlauncher.view.TimeTextView;
|
import com.ik.mboxlauncher.view.TimeTextView;
|
||||||
|
import com.ik.mboxlauncher.view.TvRecyclerView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -72,9 +78,10 @@ import java.util.Map;
|
|||||||
public class Launcher extends FragmentActivity implements SplashView.SplashAdListener {
|
public class Launcher extends FragmentActivity implements SplashView.SplashAdListener {
|
||||||
public static final String TAG="com.ik.mboxlauncher.ui.fragment.MainFragment";
|
public static final String TAG="com.ik.mboxlauncher.ui.fragment.MainFragment";
|
||||||
private MultiView layout_video,layout_music,layout_primevideo,layout_filemanager,layout_hbomax,layout_setting,layout_youtube,layout_recommend,layout_netflix,layout_chrome;
|
private MultiView layout_video,layout_music,layout_primevideo,layout_filemanager,layout_hbomax,layout_setting,layout_youtube,layout_recommend,layout_netflix,layout_chrome;
|
||||||
private AdMultiView layout_miracastreceive;
|
private MultiView layout_miracastreceive;
|
||||||
private int[] imageResIds={R.drawable.img_video,R.drawable.img_miracastreceive,R.drawable.img_youtube,R.drawable.img_recommend,R.drawable.img_music,R.drawable.img_netflix,R.drawable.img_primevideo,R.drawable.img_filemanager,R.drawable.img_chrome,R.drawable.img_hbomax,R.drawable.img_setting};
|
private int[] imageResIds={R.drawable.img_video,R.drawable.img_miracastreceive,R.drawable.img_youtube,R.drawable.img_recommend,R.drawable.img_music,R.drawable.img_netflix,R.drawable.img_primevideo,R.drawable.img_filemanager,R.drawable.img_chrome,R.drawable.img_hbomax,R.drawable.img_setting};
|
||||||
private CustomRecyclerView gv_shortcut,grid_coustom_apps;
|
private CustomRecyclerView gv_shortcut;
|
||||||
|
private TvRecyclerView grid_coustom_apps;
|
||||||
private StatusLoader mStatusLoader;
|
private StatusLoader mStatusLoader;
|
||||||
private ShortAppInfoAdapter mShortAppInfoAdapter=null;
|
private ShortAppInfoAdapter mShortAppInfoAdapter=null;
|
||||||
private CustomAppAdapter mCustomAppAdapter=null;
|
private CustomAppAdapter mCustomAppAdapter=null;
|
||||||
@@ -101,6 +108,7 @@ public class Launcher extends FragmentActivity implements SplashView.SplashAdLi
|
|||||||
/**闪屏界面是否结束*/
|
/**闪屏界面是否结束*/
|
||||||
private boolean isSplashEnd=false;
|
private boolean isSplashEnd=false;
|
||||||
private SplashView mSplashView;
|
private SplashView mSplashView;
|
||||||
|
private DownLoadAdPresenter downLoadAdPresenter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -150,7 +158,7 @@ public class Launcher extends FragmentActivity implements SplashView.SplashAdLi
|
|||||||
ad_full_root = findViewById(R.id.ad_full_root);
|
ad_full_root = findViewById(R.id.ad_full_root);
|
||||||
layout_miracastreceive = findViewById(R.id.layout_miracastreceive);
|
layout_miracastreceive = findViewById(R.id.layout_miracastreceive);
|
||||||
layout_miracastreceive.setOnClickListener(onClickListener);
|
layout_miracastreceive.setOnClickListener(onClickListener);
|
||||||
layout_miracastreceive.setFullRooView(ad_full_root);
|
// layout_miracastreceive.setFullRooView(ad_full_root);
|
||||||
multiViewArray[1]=layout_miracastreceive;
|
multiViewArray[1]=layout_miracastreceive;
|
||||||
layout_youtube = findViewById(R.id.layout_youtube);
|
layout_youtube = findViewById(R.id.layout_youtube);
|
||||||
layout_youtube.setOnClickListener(onClickListener);
|
layout_youtube.setOnClickListener(onClickListener);
|
||||||
@@ -261,28 +269,27 @@ public class Launcher extends FragmentActivity implements SplashView.SplashAdLi
|
|||||||
gv_shortcut.setCanFocusOutHorizontal(false);
|
gv_shortcut.setCanFocusOutHorizontal(false);
|
||||||
gv_shortcut.setCanFocusOutVertical(true);
|
gv_shortcut.setCanFocusOutVertical(true);
|
||||||
|
|
||||||
StaggeredGridLayoutManager customLayoutManager = new StaggeredGridLayoutManager(9, StaggeredGridLayoutManager.VERTICAL);
|
GridLayoutManager customLayoutManager = new GridLayoutManager(Launcher.this,9);
|
||||||
grid_coustom_apps.setLayoutManager(customLayoutManager);
|
grid_coustom_apps.setLayoutManager(customLayoutManager);
|
||||||
grid_coustom_apps.setAdapter(mCustomAppAdapter);
|
grid_coustom_apps.setAdapter(mCustomAppAdapter);
|
||||||
|
// grid_coustom_apps.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
grid_coustom_apps.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
// int childViewPosition=0;
|
||||||
int childViewPosition=0;
|
// @Override
|
||||||
@Override
|
// public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
// if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
// View childView = recyclerView.getFocusedChild();
|
||||||
View childView = recyclerView.getFocusedChild();
|
// childViewPosition= recyclerView.getChildAdapterPosition(childView);
|
||||||
childViewPosition= recyclerView.getChildAdapterPosition(childView);
|
// LogUtils.loge("childView|childViewPosition==>"+childViewPosition);
|
||||||
LogUtils.loge("childView|childViewPosition==>"+childViewPosition);
|
// if(childViewPosition==-1){//当焦点错乱是,强制修正找到目标位置(例如第一个可见项)
|
||||||
if(childViewPosition==-1){//当焦点错乱是,强制修正找到目标位置(例如第一个可见项)
|
// int[] rows=new int[8];
|
||||||
int[] rows=new int[8];
|
// ((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPositions(rows);
|
||||||
((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPositions(rows);
|
// View targetView = recyclerView.findViewHolderForAdapterPosition(rows[0]).itemView;
|
||||||
View targetView = recyclerView.findViewHolderForAdapterPosition(rows[0]).itemView;
|
// targetView.post(() -> targetView.requestFocus());
|
||||||
targetView.post(() -> targetView.requestFocus());
|
// }
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// });
|
||||||
});
|
|
||||||
|
|
||||||
ADSWindowManager.init(this);
|
ADSWindowManager.init(this);
|
||||||
bindAdsWindowMultiView();
|
bindAdsWindowMultiView();
|
||||||
@@ -322,7 +329,12 @@ public class Launcher extends FragmentActivity implements SplashView.SplashAdLi
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private boolean isNetworkAvailable() {
|
||||||
|
int netState = NetUtil.getNetWorkState(this);
|
||||||
|
return netState == NetUtil.NETWORK_MOBILE
|
||||||
|
|| netState == NetUtil.NETWORK_WIFI
|
||||||
|
|| netState == NetUtil.NETWORK_ETHERNET;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
protected int getFramlayoutId() {
|
protected int getFramlayoutId() {
|
||||||
return R.layout.main;
|
return R.layout.main;
|
||||||
@@ -504,7 +516,29 @@ private void loadShortAppList(){
|
|||||||
}
|
}
|
||||||
sortAppList(filteredList);
|
sortAppList(filteredList);
|
||||||
mCustomAppAdapter.addDatas(filteredList);
|
mCustomAppAdapter.addDatas(filteredList);
|
||||||
grid_coustom_apps.setAdapter(mCustomAppAdapter);
|
// grid_coustom_apps.setAdapter(mCustomAppAdapter);
|
||||||
|
// if(filteredList.size()>0){
|
||||||
|
// if(Build.VERSION.SDK_INT<29){
|
||||||
|
// grid_coustom_apps.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
// @Override
|
||||||
|
// public void onGlobalLayout() {
|
||||||
|
// grid_coustom_apps.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
|
// grid_coustom_apps.scrollToPosition(0);
|
||||||
|
// grid_coustom_apps.post(()->{
|
||||||
|
// int[] rows = new int[9];
|
||||||
|
// ((StaggeredGridLayoutManager) grid_coustom_apps.getLayoutManager()).findFirstVisibleItemPositions(rows);
|
||||||
|
// View targetView = grid_coustom_apps.findViewHolderForAdapterPosition(rows[0]).itemView;
|
||||||
|
// if(targetView!=null){
|
||||||
|
// targetView.post(() -> targetView.requestFocus());
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }else {
|
||||||
|
// grid_coustom_apps.setSelectedPosition(0);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -631,6 +665,45 @@ public boolean onGenericMotionEvent(MotionEvent event) {
|
|||||||
LogUtils.loge("onMessageEvent===>"+event.action);
|
LogUtils.loge("onMessageEvent===>"+event.action);
|
||||||
if(MessageEvent.ACTION_UPADATE_DATA_SOURCE.equals(event.action)) {
|
if(MessageEvent.ACTION_UPADATE_DATA_SOURCE.equals(event.action)) {
|
||||||
ADManager.getInstance().updateDownloadTaskBeanTable();
|
ADManager.getInstance().updateDownloadTaskBeanTable();
|
||||||
|
if(isNetworkAvailable()){
|
||||||
|
ArrayList<UploadADBean.RecordsBean> uploadAds = ADManager.getInstance().getUploadAds();
|
||||||
|
if(uploadAds.size()>0){
|
||||||
|
if(downLoadAdPresenter==null){
|
||||||
|
downLoadAdPresenter = new DownLoadAdPresenter(new AppnetCallback() {
|
||||||
|
@Override
|
||||||
|
public void onResult(Object data) {
|
||||||
|
LogUtils.loge("DownLoadAdPresenter result="+String.valueOf(data));
|
||||||
|
SharePreUtils.savePreference();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewFailureString(int code, String message) {
|
||||||
|
LogUtils.loge("DownLoadAdPresenter onViewFailureString="+message);
|
||||||
|
SharePreUtils.resetDataList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExceptionFailure(String message) {
|
||||||
|
LogUtils.loge("DownLoadAdPresenter onExceptionFailure="+message);
|
||||||
|
SharePreUtils.resetDataList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServerFailure(int code, String message) {
|
||||||
|
LogUtils.loge("DownLoadAdPresenter onServerFailure="+message+"code="+code);
|
||||||
|
SharePreUtils.resetDataList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
downLoadAdPresenter.postDownLoadAds(Launcher.this,uploadAds);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.loge("downLoadAdPresenter net request error"+e.getMessage());
|
||||||
|
SharePreUtils.resetDataList();
|
||||||
|
//throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
handler.removeCallbacks(runnable);
|
handler.removeCallbacks(runnable);
|
||||||
handler.postDelayed(runnable,1000*5);
|
handler.postDelayed(runnable,1000*5);
|
||||||
|
|
||||||
@@ -807,7 +880,7 @@ public boolean onGenericMotionEvent(MotionEvent event) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
translateAnimation.setDuration(300);
|
translateAnimation.setDuration(380);
|
||||||
translateAnimation.setFillAfter(true);
|
translateAnimation.setFillAfter(true);
|
||||||
content_view.startAnimation(translateAnimation);
|
content_view.startAnimation(translateAnimation);
|
||||||
|
|
||||||
@@ -824,7 +897,7 @@ public boolean onGenericMotionEvent(MotionEvent event) {
|
|||||||
cuttentModel = MODEL_NORMAL;
|
cuttentModel = MODEL_NORMAL;
|
||||||
LogUtils.loge("coustom_view.getHeight():"+coustom_view.getLayoutParams().height);
|
LogUtils.loge("coustom_view.getHeight():"+coustom_view.getLayoutParams().height);
|
||||||
TranslateAnimation translateAnimation = new TranslateAnimation(0.0f, 0.0f,(float)(0 - coustom_view.getLayoutParams().height - gv_shortcut.getHeight()),0.0f);
|
TranslateAnimation translateAnimation = new TranslateAnimation(0.0f, 0.0f,(float)(0 - coustom_view.getLayoutParams().height - gv_shortcut.getHeight()),0.0f);
|
||||||
translateAnimation.setDuration(300);
|
translateAnimation.setDuration(380);
|
||||||
translateAnimation.setAnimationListener(new Animation.AnimationListener() {
|
translateAnimation.setAnimationListener(new Animation.AnimationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationStart(Animation animation) {
|
public void onAnimationStart(Animation animation) {
|
||||||
@@ -835,6 +908,7 @@ public boolean onGenericMotionEvent(MotionEvent event) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationEnd(Animation animation) {
|
public void onAnimationEnd(Animation animation) {
|
||||||
|
LogUtils.loge("dismissCustomApp onAnimationEnd()");
|
||||||
coustom_view.setVisibility(View.GONE);
|
coustom_view.setVisibility(View.GONE);
|
||||||
gv_shortcut.requestFocus();
|
gv_shortcut.requestFocus();
|
||||||
|
|
||||||
@@ -949,7 +1023,10 @@ public boolean onGenericMotionEvent(MotionEvent event) {
|
|||||||
if(isSplashEnd) {
|
if(isSplashEnd) {
|
||||||
ADSWindowManager.getInstance().startVideo();
|
ADSWindowManager.getInstance().startVideo();
|
||||||
}
|
}
|
||||||
ADManager.getInstance().clearTaskInteruptQueueAndRestart();
|
if(isNetworkAvailable()){
|
||||||
|
ADManager.getInstance().clearTaskInteruptQueueAndRestart();
|
||||||
|
ADManager.getInstance().clearApkFileByPowerDown();
|
||||||
|
}
|
||||||
setImageViewData();
|
setImageViewData();
|
||||||
loadShortAppList();
|
loadShortAppList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.SharePreUtils;
|
||||||
import com.android.monitor.DataBeeObserver;
|
import com.android.monitor.DataBeeObserver;
|
||||||
import com.android.nebulasdk.ADManager;
|
import com.android.nebulasdk.ADManager;
|
||||||
import com.android.nebulasdk.AppManager;
|
import com.android.nebulasdk.AppManager;
|
||||||
@@ -12,8 +13,6 @@ import com.android.util.LogManager;
|
|||||||
import com.android.util.LogUtils;
|
import com.android.util.LogUtils;
|
||||||
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
|
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
|
||||||
import com.ik.mboxlauncher.SystemService;
|
import com.ik.mboxlauncher.SystemService;
|
||||||
import com.seraphic.ad.AdConfig;
|
|
||||||
import com.seraphic.ad.AdManager;
|
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
@@ -27,16 +26,7 @@ public class MyApplication extends Application {
|
|||||||
DataBeeObserver.init(getApplicationContext());
|
DataBeeObserver.init(getApplicationContext());
|
||||||
AppManager.init(getApplicationContext());
|
AppManager.init(getApplicationContext());
|
||||||
ADManager.init(getApplicationContext());
|
ADManager.init(getApplicationContext());
|
||||||
|
SharePreUtils.getInstance(getApplicationContext());
|
||||||
AdConfig config = new AdConfig.Builder()
|
|
||||||
.isDebug(false)//是否开始 debug 模式,开启会打印更多log,供开发调试
|
|
||||||
.productName("aike")//正式发版时使用正式的PN
|
|
||||||
.productTag("launcher")//正式发版时使用正式的PT
|
|
||||||
// .productName("test")//仅限开发测试使用
|
|
||||||
// .productTag("test")//仅限开发测试使用
|
|
||||||
.adId(getAdId(this))
|
|
||||||
.build();
|
|
||||||
AdManager.getInstance().init(MyApplication.this, config);
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void uncaughtException(Thread thread, Throwable throwable) {
|
public void uncaughtException(Thread thread, Throwable throwable) {
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class CustomAppAdapter extends RecyclerView.Adapter<CustomAppAdapter.View
|
|||||||
if(hasFocus){
|
if(hasFocus){
|
||||||
viewHolder.item_name.setSelected(true);
|
viewHolder.item_name.setSelected(true);
|
||||||
viewHolder.itemView.setBackgroundResource(R.drawable.app_item_select);
|
viewHolder.itemView.setBackgroundResource(R.drawable.app_item_select);
|
||||||
viewHolder.itemView.requestFocus();
|
// viewHolder.itemView.requestFocus();
|
||||||
scaleView(viewHolder.itemView, 1.07f);
|
scaleView(viewHolder.itemView, 1.07f);
|
||||||
// viewHolder.itemView.post(() -> viewHolder.itemView.requestFocus());
|
// viewHolder.itemView.post(() -> viewHolder.itemView.requestFocus());
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package com.ik.mboxlauncher.ui.fragment;
|
package com.ik.mboxlauncher.ui.fragment;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.android.database.lib.AppBean;
|
import com.android.database.lib.AppBean;
|
||||||
import com.android.eventbaus.MessageEvent;
|
import com.android.eventbaus.MessageEvent;
|
||||||
@@ -13,6 +16,7 @@ import com.android.nebulasdk.AppManager;
|
|||||||
import com.android.util.IntentUtil;
|
import com.android.util.IntentUtil;
|
||||||
import com.android.util.LogUtils;
|
import com.android.util.LogUtils;
|
||||||
import com.ik.mboxlauncher.R;
|
import com.ik.mboxlauncher.R;
|
||||||
|
import com.ik.mboxlauncher.ui.FragmentManager;
|
||||||
import com.ik.mboxlauncher.ui.adapter.MyAppInfoAdapter;
|
import com.ik.mboxlauncher.ui.adapter.MyAppInfoAdapter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -21,6 +25,7 @@ import java.util.List;
|
|||||||
public class AppsFragment extends CategoryFragment {
|
public class AppsFragment extends CategoryFragment {
|
||||||
public static final String ACTION="com.ik.mboxlauncher.ui.fragment.AppsFragment";
|
public static final String ACTION="com.ik.mboxlauncher.ui.fragment.AppsFragment";
|
||||||
private MyAppInfoAdapter mMyAppInfoAdapter = null;
|
private MyAppInfoAdapter mMyAppInfoAdapter = null;
|
||||||
|
private final int SCROLLPOSITION=17;
|
||||||
@Override
|
@Override
|
||||||
protected void initView(View view) {
|
protected void initView(View view) {
|
||||||
super.initView(view);
|
super.initView(view);
|
||||||
@@ -56,10 +61,25 @@ public class AppsFragment extends CategoryFragment {
|
|||||||
LogUtils.loge("hasFocus===>"+hasFocus);
|
LogUtils.loge("hasFocus===>"+hasFocus);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
gv_category_apps.setOnScrollChangeListener(new View.OnScrollChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||||
|
lastFocusPositon=gv_category_apps.getmCurrentFocusPosition();
|
||||||
|
LogUtils.loge("onScrollChange()AppsFragment pos="+lastFocusPositon);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// h3翻页后gv_category_apps失去焦点处理
|
||||||
|
if(Build.VERSION.SDK_INT<29&&disableFreshData){
|
||||||
|
gv_category_apps.requestFocus();
|
||||||
|
}
|
||||||
|
LogUtils.loge("AppsFragment initView==>"+disableFreshData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initData() {
|
protected void initData() {
|
||||||
|
LogUtils.loge("initData===>AppsFragment");
|
||||||
loadAppInfoByCategory(AppManager.CATEGORY_MYAPPS);
|
loadAppInfoByCategory(AppManager.CATEGORY_MYAPPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,11 +88,13 @@ public class AppsFragment extends CategoryFragment {
|
|||||||
runUiThread(new Runnable() {
|
runUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if(disableFreshData) return;
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
disableFreshData=true;
|
||||||
List<AppBean> appBeanList = (List<AppBean>) data;
|
List<AppBean> appBeanList = (List<AppBean>) data;
|
||||||
// 创建过滤后的列表
|
// 创建过滤后的列表
|
||||||
List<AppBean> filteredList = new ArrayList<>();
|
List<AppBean> filteredList = new ArrayList<>();
|
||||||
String selfPackageName = getActivity().getPackageName();
|
String selfPackageName = FragmentManager.getInstance().getPackageName();;
|
||||||
|
|
||||||
for (AppBean appBean : appBeanList) {
|
for (AppBean appBean : appBeanList) {
|
||||||
// 跳过自身应用
|
// 跳过自身应用
|
||||||
@@ -87,6 +109,21 @@ public class AppsFragment extends CategoryFragment {
|
|||||||
// 使用过滤后的列表更新适配器
|
// 使用过滤后的列表更新适配器
|
||||||
mMyAppInfoAdapter.addDatas(filteredList);
|
mMyAppInfoAdapter.addDatas(filteredList);
|
||||||
}
|
}
|
||||||
|
gv_category_apps.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
@Override
|
||||||
|
public void onGlobalLayout() {
|
||||||
|
gv_category_apps.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
|
gv_category_apps.scrollToPosition(0);
|
||||||
|
gv_category_apps.post(()->{
|
||||||
|
int firstVisibleItemPosition = ((GridLayoutManager) gv_category_apps.getLayoutManager()).findFirstVisibleItemPosition();
|
||||||
|
RecyclerView.ViewHolder holderview = gv_category_apps.findViewHolderForAdapterPosition(firstVisibleItemPosition);
|
||||||
|
if(holderview !=null){
|
||||||
|
View targetView = holderview.itemView;
|
||||||
|
targetView.post(() -> targetView.requestFocus());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
// if(data!=null){
|
// if(data!=null){
|
||||||
// List<AppBean> appBeanList = (List<AppBean>) data;
|
// List<AppBean> appBeanList = (List<AppBean>) data;
|
||||||
// mMyAppInfoAdapter.addDatas(appBeanList);
|
// mMyAppInfoAdapter.addDatas(appBeanList);
|
||||||
@@ -100,8 +137,9 @@ public class AppsFragment extends CategoryFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onResumeFragment(MessageEvent event) {
|
public void onResumeFragment(MessageEvent event) {
|
||||||
super.onResumeFragment(event);
|
super.onResumeFragment(event);
|
||||||
|
disableFreshData=false;
|
||||||
loadAppInfoByCategory(AppManager.CATEGORY_MYAPPS);//重新加载数据
|
loadAppInfoByCategory(AppManager.CATEGORY_MYAPPS);//重新加载数据
|
||||||
|
LogUtils.loge("onResumeFragment===>AppsFragment");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,11 +163,17 @@ public class AppsFragment extends CategoryFragment {
|
|||||||
@Override
|
@Override
|
||||||
protected void toNextPage() {
|
protected void toNextPage() {
|
||||||
doneEvents(new MessageEvent(MusicFragment.ACTION));
|
doneEvents(new MessageEvent(MusicFragment.ACTION));
|
||||||
|
if(lastFocusPositon>SCROLLPOSITION){
|
||||||
|
disableFreshData=false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void toPreviousPage() {
|
protected void toPreviousPage() {
|
||||||
doneEvents(new MessageEvent(RecommendFragment.ACTION));
|
doneEvents(new MessageEvent(RecommendFragment.ACTION));
|
||||||
|
if(lastFocusPositon>SCROLLPOSITION){
|
||||||
|
disableFreshData=false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ package com.ik.mboxlauncher.ui.fragment;
|
|||||||
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.animation.TranslateAnimation;
|
import android.view.animation.TranslateAnimation;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||||
|
|
||||||
@@ -18,11 +20,13 @@ import com.android.nebulasdk.presenter.callback.AppnetCallback;
|
|||||||
import com.android.util.GsonUtil;
|
import com.android.util.GsonUtil;
|
||||||
import com.android.util.LogUtils;
|
import com.android.util.LogUtils;
|
||||||
import com.ik.mboxlauncher.R;
|
import com.ik.mboxlauncher.R;
|
||||||
|
import com.ik.mboxlauncher.ui.Launcher;
|
||||||
import com.ik.mboxlauncher.ui.adapter.CustomAppAdapter;
|
import com.ik.mboxlauncher.ui.adapter.CustomAppAdapter;
|
||||||
import com.ik.mboxlauncher.ui.adapter.VideoAppAdapter;
|
import com.ik.mboxlauncher.ui.adapter.VideoAppAdapter;
|
||||||
import com.ik.mboxlauncher.ui.adapter.MyAppInfoAdapter;
|
import com.ik.mboxlauncher.ui.adapter.MyAppInfoAdapter;
|
||||||
import com.ik.mboxlauncher.ui.base.BaseFragment;
|
import com.ik.mboxlauncher.ui.base.BaseFragment;
|
||||||
import com.ik.mboxlauncher.view.CustomRecyclerViewer;
|
import com.ik.mboxlauncher.view.CustomRecyclerViewer;
|
||||||
|
import com.ik.mboxlauncher.view.TvRecyclerView;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -32,7 +36,7 @@ public abstract class CategoryFragment extends BaseFragment implements AppnetCal
|
|||||||
|
|
||||||
private CategoryAppPresenter mCategoryAppPresenter =null;
|
private CategoryAppPresenter mCategoryAppPresenter =null;
|
||||||
// private MyAppInfoAdapter mMyAppInfoAdapter = null;
|
// private MyAppInfoAdapter mMyAppInfoAdapter = null;
|
||||||
protected RecyclerView grid_coustom_apps;
|
protected TvRecyclerView grid_coustom_apps;
|
||||||
protected CustomRecyclerViewer gv_category_apps;
|
protected CustomRecyclerViewer gv_category_apps;
|
||||||
protected ImageView img_logo,img_tab_video, img_tab_recommend, img_tab_apps, img_tab_music, img_tab_local;
|
protected ImageView img_logo,img_tab_video, img_tab_recommend, img_tab_apps, img_tab_music, img_tab_local;
|
||||||
protected TextView tv_title;
|
protected TextView tv_title;
|
||||||
@@ -40,7 +44,8 @@ public abstract class CategoryFragment extends BaseFragment implements AppnetCal
|
|||||||
protected CustomAppAdapter mCustomAppAdapter=null;
|
protected CustomAppAdapter mCustomAppAdapter=null;
|
||||||
protected int mCategory=-1;
|
protected int mCategory=-1;
|
||||||
|
|
||||||
|
protected boolean disableFreshData;//禁止再次刷新数据
|
||||||
|
protected int lastFocusPositon;//记录焦点位置
|
||||||
protected static final int VIDEO_CATEGORY=0;
|
protected static final int VIDEO_CATEGORY=0;
|
||||||
protected static final int RECOMMEND_CATEGORY=1;
|
protected static final int RECOMMEND_CATEGORY=1;
|
||||||
|
|
||||||
@@ -48,6 +53,8 @@ public abstract class CategoryFragment extends BaseFragment implements AppnetCal
|
|||||||
protected static final int LOCAL_CATEGORY=3;
|
protected static final int LOCAL_CATEGORY=3;
|
||||||
protected static final int APPS_CATEGORY=4;
|
protected static final int APPS_CATEGORY=4;
|
||||||
protected Map<String,String> collectAppMap=new HashMap();
|
protected Map<String,String> collectAppMap=new HashMap();
|
||||||
|
private Runnable customFocusRunnable;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getLayoutResourceId() {
|
protected int getLayoutResourceId() {
|
||||||
return R.layout.layout_category_app;
|
return R.layout.layout_category_app;
|
||||||
@@ -100,28 +107,28 @@ public abstract class CategoryFragment extends BaseFragment implements AppnetCal
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
StaggeredGridLayoutManager customLayoutManager = new StaggeredGridLayoutManager(8, StaggeredGridLayoutManager.VERTICAL);
|
GridLayoutManager customLayoutManager = new GridLayoutManager(getActivity(),8);
|
||||||
grid_coustom_apps.setLayoutManager(customLayoutManager);
|
grid_coustom_apps.setLayoutManager(customLayoutManager);
|
||||||
grid_coustom_apps.setAdapter(mCustomAppAdapter);
|
grid_coustom_apps.setAdapter(mCustomAppAdapter);
|
||||||
grid_coustom_apps.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
// grid_coustom_apps.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
int childViewPosition=0;
|
// int childViewPosition=0;
|
||||||
@Override
|
// @Override
|
||||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
// public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
// if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||||
// 找到目标位置(例如第一个可见项)
|
// // 找到目标位置(例如第一个可见项)
|
||||||
View childView = recyclerView.getFocusedChild();
|
// View childView = recyclerView.getFocusedChild();
|
||||||
childViewPosition= recyclerView.getChildAdapterPosition(childView);
|
// childViewPosition= recyclerView.getChildAdapterPosition(childView);
|
||||||
LogUtils.loge("childView|childViewPosition==>"+childViewPosition);
|
// LogUtils.loge("childView|childViewPosition==>"+childViewPosition);
|
||||||
if(childViewPosition==-1){ //当焦点错乱是,强制修正找到目标位置(例如第一个可见项)
|
// if(childViewPosition==-1){ //当焦点错乱是,强制修正找到目标位置(例如第一个可见项)
|
||||||
int[] rows=new int[8];
|
// int[] rows=new int[8];
|
||||||
((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPositions(rows);
|
// ((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPositions(rows);
|
||||||
View targetView = recyclerView.findViewHolderForAdapterPosition(rows[0]).itemView;
|
// View targetView = recyclerView.findViewHolderForAdapterPosition(rows[0]).itemView;
|
||||||
targetView.post(() -> targetView.requestFocus());
|
// targetView.post(() -> targetView.requestFocus());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
loadCustomAppList();
|
loadCustomAppList();
|
||||||
|
|
||||||
gv_category_apps.setmFocusOnBoundaryListener(new CustomRecyclerViewer.FocusOnBoundaryListener() {
|
gv_category_apps.setmFocusOnBoundaryListener(new CustomRecyclerViewer.FocusOnBoundaryListener() {
|
||||||
@@ -231,19 +238,24 @@ public abstract class CategoryFragment extends BaseFragment implements AppnetCal
|
|||||||
translateAnimation.setDuration(300);
|
translateAnimation.setDuration(300);
|
||||||
translateAnimation.setFillAfter(true);
|
translateAnimation.setFillAfter(true);
|
||||||
content_view.startAnimation(translateAnimation);
|
content_view.startAnimation(translateAnimation);
|
||||||
handler.postDelayed(new Runnable() {
|
if(customFocusRunnable==null){
|
||||||
@Override
|
customFocusRunnable = new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
coustom_view.requestFocus();
|
public void run() {
|
||||||
}
|
coustom_view.requestFocus();
|
||||||
},800);
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
handler.postDelayed(customFocusRunnable,800);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void dismissCustomApp(){
|
private void dismissCustomApp(){
|
||||||
|
handler.removeCallbacks(customFocusRunnable);
|
||||||
cuttentModel = MODEL_NORMAL;
|
cuttentModel = MODEL_NORMAL;
|
||||||
|
disableFreshData=false;
|
||||||
LogUtils.loge("coustom_view.getHeight():"+coustom_view.getLayoutParams().height);
|
LogUtils.loge("coustom_view.getHeight():"+coustom_view.getLayoutParams().height);
|
||||||
|
|
||||||
TranslateAnimation exitTransAnim = new TranslateAnimation(0.0f, 0.0f, 0,(float)(0 - coustom_view.getLayoutParams().height));
|
TranslateAnimation exitTransAnim = new TranslateAnimation(0.0f, 0.0f, 0,(float)(0 - coustom_view.getLayoutParams().height));
|
||||||
@@ -286,7 +298,21 @@ public abstract class CategoryFragment extends BaseFragment implements AppnetCal
|
|||||||
|
|
||||||
LogUtils.loge("data size is "+shortcutInfoBeanList.size());
|
LogUtils.loge("data size is "+shortcutInfoBeanList.size());
|
||||||
mCustomAppAdapter.addDatas(shortcutInfoBeanList);
|
mCustomAppAdapter.addDatas(shortcutInfoBeanList);
|
||||||
|
grid_coustom_apps.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
@Override
|
||||||
|
public void onGlobalLayout() {
|
||||||
|
grid_coustom_apps.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
|
grid_coustom_apps.scrollToPosition(0);
|
||||||
|
grid_coustom_apps.post(()->{
|
||||||
|
int firstVisibleItemPosition = ((GridLayoutManager) grid_coustom_apps.getLayoutManager()).findFirstVisibleItemPosition();
|
||||||
|
RecyclerView.ViewHolder holderview = grid_coustom_apps.findViewHolderForAdapterPosition(firstVisibleItemPosition);
|
||||||
|
if(holderview !=null){
|
||||||
|
View targetView = holderview.itemView;
|
||||||
|
targetView.post(() -> targetView.requestFocus());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}else {
|
}else {
|
||||||
LogUtils.loge("no data");
|
LogUtils.loge("no data");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package com.ik.mboxlauncher.ui.fragment;
|
package com.ik.mboxlauncher.ui.fragment;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.android.database.lib.AppBean;
|
import com.android.database.lib.AppBean;
|
||||||
import com.android.database.lib.LocalAppBean;
|
import com.android.database.lib.LocalAppBean;
|
||||||
@@ -23,6 +26,8 @@ public class LocalFragment extends CategoryFragment {
|
|||||||
|
|
||||||
public static final String ACTION="com.ik.mboxlauncher.ui.fragment.LocalFragment";
|
public static final String ACTION="com.ik.mboxlauncher.ui.fragment.LocalFragment";
|
||||||
private LocalAppAdapter mLocalAppAdapter =null;
|
private LocalAppAdapter mLocalAppAdapter =null;
|
||||||
|
|
||||||
|
private final int SCROLLPOSITION=17;
|
||||||
@Override
|
@Override
|
||||||
protected void initView(View view) {
|
protected void initView(View view) {
|
||||||
mCategory=AppManager.CATEGORY_LOCAL;
|
mCategory=AppManager.CATEGORY_LOCAL;
|
||||||
@@ -51,6 +56,20 @@ public class LocalFragment extends CategoryFragment {
|
|||||||
GridLayoutManager customLayoutManager = new GridLayoutManager(view.getContext(), 6);
|
GridLayoutManager customLayoutManager = new GridLayoutManager(view.getContext(), 6);
|
||||||
gv_category_apps.setLayoutManager(customLayoutManager);
|
gv_category_apps.setLayoutManager(customLayoutManager);
|
||||||
gv_category_apps.setAdapter(mLocalAppAdapter);
|
gv_category_apps.setAdapter(mLocalAppAdapter);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
gv_category_apps.setOnScrollChangeListener(new View.OnScrollChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||||
|
lastFocusPositon=gv_category_apps.getmCurrentFocusPosition();
|
||||||
|
LogUtils.loge("onScrollChange()LocalFragment pos="+lastFocusPositon);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// h3翻页后gv_category_apps失去焦点处理
|
||||||
|
if(Build.VERSION.SDK_INT<29&&disableFreshData){
|
||||||
|
gv_category_apps.requestFocus();
|
||||||
|
}
|
||||||
|
LogUtils.loge("LocalFragment initView==>"+disableFreshData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -58,7 +77,9 @@ public class LocalFragment extends CategoryFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResult(Object data) {
|
public void onResult(Object data) {
|
||||||
|
if(disableFreshData) return;
|
||||||
if(data!=null){
|
if(data!=null){
|
||||||
|
disableFreshData=true;//禁用再次刷新数据
|
||||||
collectAppMap.clear();
|
collectAppMap.clear();
|
||||||
List<LocalAppBean> appBeanList = (List<LocalAppBean>) data;
|
List<LocalAppBean> appBeanList = (List<LocalAppBean>) data;
|
||||||
|
|
||||||
@@ -69,6 +90,23 @@ public class LocalFragment extends CategoryFragment {
|
|||||||
appBeanList.add(new LocalAppBean());
|
appBeanList.add(new LocalAppBean());
|
||||||
mLocalAppAdapter.addDatas(appBeanList);
|
mLocalAppAdapter.addDatas(appBeanList);
|
||||||
}
|
}
|
||||||
|
if(!isShowCustomApp()){
|
||||||
|
gv_category_apps.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
@Override
|
||||||
|
public void onGlobalLayout() {
|
||||||
|
gv_category_apps.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
|
gv_category_apps.scrollToPosition(0);
|
||||||
|
gv_category_apps.post(()->{
|
||||||
|
int firstVisibleItemPosition = ((GridLayoutManager) gv_category_apps.getLayoutManager()).findFirstVisibleItemPosition();
|
||||||
|
RecyclerView.ViewHolder holderview = gv_category_apps.findViewHolderForAdapterPosition(firstVisibleItemPosition);
|
||||||
|
if(holderview !=null){
|
||||||
|
View targetView = holderview.itemView;
|
||||||
|
targetView.post(() -> targetView.requestFocus());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
super.onResult(data);
|
super.onResult(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,13 +146,16 @@ public class LocalFragment extends CategoryFragment {
|
|||||||
@Override
|
@Override
|
||||||
protected void toPreviousPage() {
|
protected void toPreviousPage() {
|
||||||
doneEvents(new MessageEvent(MusicFragment.ACTION));
|
doneEvents(new MessageEvent(MusicFragment.ACTION));
|
||||||
|
if(lastFocusPositon>SCROLLPOSITION){
|
||||||
|
disableFreshData=false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResumeFragment(MessageEvent event) {
|
public void onResumeFragment(MessageEvent event) {
|
||||||
super.onResumeFragment(event);
|
super.onResumeFragment(event);
|
||||||
|
disableFreshData=false;
|
||||||
loadAppInfoByCategory(AppManager.CATEGORY_LOCAL);//重新加载数据
|
loadAppInfoByCategory(AppManager.CATEGORY_LOCAL);//重新加载数据
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package com.ik.mboxlauncher.ui.fragment;
|
package com.ik.mboxlauncher.ui.fragment;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.android.database.lib.AppBean;
|
import com.android.database.lib.AppBean;
|
||||||
import com.android.database.lib.MusicAppBean;
|
import com.android.database.lib.MusicAppBean;
|
||||||
@@ -23,6 +26,7 @@ public class MusicFragment extends CategoryFragment {
|
|||||||
public static final String ACTION="com.ik.mboxlauncher.ui.fragment.MusicFragment";
|
public static final String ACTION="com.ik.mboxlauncher.ui.fragment.MusicFragment";
|
||||||
|
|
||||||
private MusicAppAdapter mMusicAppAdapter;
|
private MusicAppAdapter mMusicAppAdapter;
|
||||||
|
private final int SCROLLPOSITION=17;
|
||||||
@Override
|
@Override
|
||||||
protected void initView(View view) {
|
protected void initView(View view) {
|
||||||
super.initView(view);
|
super.initView(view);
|
||||||
@@ -51,6 +55,20 @@ public class MusicFragment extends CategoryFragment {
|
|||||||
GridLayoutManager customLayoutManager = new GridLayoutManager(view.getContext(), 6);
|
GridLayoutManager customLayoutManager = new GridLayoutManager(view.getContext(), 6);
|
||||||
gv_category_apps.setLayoutManager(customLayoutManager);
|
gv_category_apps.setLayoutManager(customLayoutManager);
|
||||||
gv_category_apps.setAdapter(mMusicAppAdapter);
|
gv_category_apps.setAdapter(mMusicAppAdapter);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
gv_category_apps.setOnScrollChangeListener(new View.OnScrollChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||||
|
lastFocusPositon=gv_category_apps.getmCurrentFocusPosition();
|
||||||
|
LogUtils.loge("onScrollChange()MusicFragment pos="+lastFocusPositon);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// h3翻页后gv_category_apps失去焦点处理
|
||||||
|
if(Build.VERSION.SDK_INT<29&&disableFreshData){
|
||||||
|
gv_category_apps.requestFocus();
|
||||||
|
}
|
||||||
|
LogUtils.loge("MusicFragment initView==>"+disableFreshData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -67,6 +85,23 @@ public class MusicFragment extends CategoryFragment {
|
|||||||
appBeanList.add(new MusicAppBean());
|
appBeanList.add(new MusicAppBean());
|
||||||
mMusicAppAdapter.addDatas(appBeanList);
|
mMusicAppAdapter.addDatas(appBeanList);
|
||||||
}
|
}
|
||||||
|
if(!isShowCustomApp()){
|
||||||
|
gv_category_apps.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
@Override
|
||||||
|
public void onGlobalLayout() {
|
||||||
|
gv_category_apps.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
|
gv_category_apps.scrollToPosition(0);
|
||||||
|
gv_category_apps.post(()->{
|
||||||
|
int firstVisibleItemPosition = ((GridLayoutManager) gv_category_apps.getLayoutManager()).findFirstVisibleItemPosition();
|
||||||
|
RecyclerView.ViewHolder holderview = gv_category_apps.findViewHolderForAdapterPosition(firstVisibleItemPosition);
|
||||||
|
if(holderview !=null){
|
||||||
|
View targetView = holderview.itemView;
|
||||||
|
targetView.post(() -> targetView.requestFocus());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
super.onResult(data);
|
super.onResult(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,18 +143,24 @@ public class MusicFragment extends CategoryFragment {
|
|||||||
@Override
|
@Override
|
||||||
protected void toNextPage() {
|
protected void toNextPage() {
|
||||||
doneEvents(new MessageEvent(LocalFragment.ACTION));
|
doneEvents(new MessageEvent(LocalFragment.ACTION));
|
||||||
|
if(lastFocusPositon>SCROLLPOSITION){
|
||||||
|
disableFreshData=false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void toPreviousPage() {
|
protected void toPreviousPage() {
|
||||||
doneEvents(new MessageEvent(AppsFragment.ACTION));
|
doneEvents(new MessageEvent(AppsFragment.ACTION));
|
||||||
|
if(lastFocusPositon>SCROLLPOSITION){
|
||||||
|
disableFreshData=false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResumeFragment(MessageEvent event) {
|
public void onResumeFragment(MessageEvent event) {
|
||||||
super.onResumeFragment(event);
|
super.onResumeFragment(event);
|
||||||
|
disableFreshData=false;
|
||||||
loadAppInfoByCategory(AppManager.CATEGORY_MUSIC);//重新加载数据
|
loadAppInfoByCategory(AppManager.CATEGORY_MUSIC);//重新加载数据
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
package com.ik.mboxlauncher.ui.fragment;
|
package com.ik.mboxlauncher.ui.fragment;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.android.database.lib.AppBean;
|
import com.android.database.lib.AppBean;
|
||||||
import com.android.database.lib.RecommendAppBean;
|
import com.android.database.lib.RecommendAppBean;
|
||||||
import com.android.eventbaus.MessageEvent;
|
import com.android.eventbaus.MessageEvent;
|
||||||
import com.android.nebulasdk.AppManager;
|
import com.android.nebulasdk.AppManager;
|
||||||
|
import com.android.util.GsonUtil;
|
||||||
import com.android.util.IntentUtil;
|
import com.android.util.IntentUtil;
|
||||||
import com.android.util.LogUtils;
|
import com.android.util.LogUtils;
|
||||||
import com.ik.mboxlauncher.R;
|
import com.ik.mboxlauncher.R;
|
||||||
@@ -22,6 +26,7 @@ public class RecommendFragment extends CategoryFragment {
|
|||||||
|
|
||||||
public static final String ACTION="com.ik.mboxlauncher.ui.fragment.RecommendFragment";
|
public static final String ACTION="com.ik.mboxlauncher.ui.fragment.RecommendFragment";
|
||||||
private RecommendAppAdapter mRecommendAppAdapter;
|
private RecommendAppAdapter mRecommendAppAdapter;
|
||||||
|
private final int SCROLLPOSITION=17;
|
||||||
@Override
|
@Override
|
||||||
protected void initView(View view) {
|
protected void initView(View view) {
|
||||||
mCategory=AppManager.CATEGORY_RECOMMEND;
|
mCategory=AppManager.CATEGORY_RECOMMEND;
|
||||||
@@ -51,12 +56,28 @@ public class RecommendFragment extends CategoryFragment {
|
|||||||
GridLayoutManager customLayoutManager = new GridLayoutManager(view.getContext(), 6);
|
GridLayoutManager customLayoutManager = new GridLayoutManager(view.getContext(), 6);
|
||||||
gv_category_apps.setLayoutManager(customLayoutManager);
|
gv_category_apps.setLayoutManager(customLayoutManager);
|
||||||
gv_category_apps.setAdapter(mRecommendAppAdapter);
|
gv_category_apps.setAdapter(mRecommendAppAdapter);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
gv_category_apps.setOnScrollChangeListener(new View.OnScrollChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||||
|
lastFocusPositon=gv_category_apps.getmCurrentFocusPosition();
|
||||||
|
LogUtils.loge("onScrollChange()RecommendFragment pos="+lastFocusPositon);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// h3翻页后gv_category_apps失去焦点处理
|
||||||
|
if(Build.VERSION.SDK_INT<29&&disableFreshData){
|
||||||
|
gv_category_apps.requestFocus();
|
||||||
|
}
|
||||||
|
LogUtils.loge("RecommendFragment initView==>"+disableFreshData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResult(Object data) {
|
public void onResult(Object data) {
|
||||||
|
if(disableFreshData) return;
|
||||||
if(data!=null){
|
if(data!=null){
|
||||||
|
disableFreshData=true;
|
||||||
collectAppMap.clear();
|
collectAppMap.clear();
|
||||||
List<RecommendAppBean> appBeanList = (List<RecommendAppBean>) data;
|
List<RecommendAppBean> appBeanList = (List<RecommendAppBean>) data;
|
||||||
for (RecommendAppBean recommendAppBean:appBeanList){
|
for (RecommendAppBean recommendAppBean:appBeanList){
|
||||||
@@ -66,6 +87,24 @@ public class RecommendFragment extends CategoryFragment {
|
|||||||
appBeanList.add(new RecommendAppBean());
|
appBeanList.add(new RecommendAppBean());
|
||||||
mRecommendAppAdapter.addDatas(appBeanList);
|
mRecommendAppAdapter.addDatas(appBeanList);
|
||||||
}
|
}
|
||||||
|
if(!isShowCustomApp()){
|
||||||
|
gv_category_apps.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
@Override
|
||||||
|
public void onGlobalLayout() {
|
||||||
|
gv_category_apps.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
|
LogUtils.loge("onGlobalLayout===>RecommendFragment"+ GsonUtil.GsonString(data));
|
||||||
|
gv_category_apps.scrollToPosition(0);
|
||||||
|
gv_category_apps.post(()->{
|
||||||
|
int firstVisibleItemPosition = ((GridLayoutManager) gv_category_apps.getLayoutManager()).findFirstVisibleItemPosition();
|
||||||
|
RecyclerView.ViewHolder holderview = gv_category_apps.findViewHolderForAdapterPosition(firstVisibleItemPosition);
|
||||||
|
if(holderview !=null){
|
||||||
|
View targetView = holderview.itemView;
|
||||||
|
targetView.post(() -> targetView.requestFocus());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
super.onResult(data);
|
super.onResult(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,11 +144,17 @@ public class RecommendFragment extends CategoryFragment {
|
|||||||
@Override
|
@Override
|
||||||
protected void toNextPage() {
|
protected void toNextPage() {
|
||||||
doneEvents(new MessageEvent(AppsFragment.ACTION));
|
doneEvents(new MessageEvent(AppsFragment.ACTION));
|
||||||
|
if(lastFocusPositon>SCROLLPOSITION){
|
||||||
|
disableFreshData=false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void toPreviousPage() {
|
protected void toPreviousPage() {
|
||||||
doneEvents(new MessageEvent(VideoFragment.ACTION));
|
doneEvents(new MessageEvent(VideoFragment.ACTION));
|
||||||
|
if(lastFocusPositon>SCROLLPOSITION){
|
||||||
|
disableFreshData=false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package com.ik.mboxlauncher.ui.fragment;
|
package com.ik.mboxlauncher.ui.fragment;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.android.database.lib.AppBean;
|
import com.android.database.lib.AppBean;
|
||||||
import com.android.database.lib.VideoAppBean;
|
import com.android.database.lib.VideoAppBean;
|
||||||
@@ -22,6 +25,7 @@ public class VideoFragment extends CategoryFragment {
|
|||||||
|
|
||||||
public static final String ACTION="com.ik.mboxlauncher.ui.fragment.VideoFragment";
|
public static final String ACTION="com.ik.mboxlauncher.ui.fragment.VideoFragment";
|
||||||
private VideoAppAdapter mVideoAppAdapter = null;
|
private VideoAppAdapter mVideoAppAdapter = null;
|
||||||
|
private final int SCROLLPOSITION=17;
|
||||||
@Override
|
@Override
|
||||||
protected void initView(View view) {
|
protected void initView(View view) {
|
||||||
mCategory=AppManager.CATEGORY_VIDEO;
|
mCategory=AppManager.CATEGORY_VIDEO;
|
||||||
@@ -51,12 +55,28 @@ public class VideoFragment extends CategoryFragment {
|
|||||||
GridLayoutManager layoutManager = new GridLayoutManager(view.getContext(), 6);
|
GridLayoutManager layoutManager = new GridLayoutManager(view.getContext(), 6);
|
||||||
gv_category_apps.setLayoutManager(layoutManager);
|
gv_category_apps.setLayoutManager(layoutManager);
|
||||||
gv_category_apps.setAdapter(mVideoAppAdapter);
|
gv_category_apps.setAdapter(mVideoAppAdapter);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
gv_category_apps.setOnScrollChangeListener(new View.OnScrollChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||||
|
lastFocusPositon=gv_category_apps.getmCurrentFocusPosition();
|
||||||
|
LogUtils.loge("onScrollChange()VideoFragment pos="+lastFocusPositon);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// h3翻页后gv_category_apps失去焦点处理
|
||||||
|
if(Build.VERSION.SDK_INT<29&&disableFreshData){
|
||||||
|
gv_category_apps.requestFocus();
|
||||||
|
}
|
||||||
|
LogUtils.loge("VideoFragment initView==>"+disableFreshData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResult(Object data) {
|
public void onResult(Object data) {
|
||||||
|
if(disableFreshData) return;
|
||||||
if(data!=null){
|
if(data!=null){
|
||||||
|
disableFreshData=true;
|
||||||
collectAppMap.clear();
|
collectAppMap.clear();
|
||||||
List<VideoAppBean> appBeanList = (List<VideoAppBean>) data;
|
List<VideoAppBean> appBeanList = (List<VideoAppBean>) data;
|
||||||
for (VideoAppBean videoAppBean:appBeanList){
|
for (VideoAppBean videoAppBean:appBeanList){
|
||||||
@@ -67,6 +87,24 @@ public class VideoFragment extends CategoryFragment {
|
|||||||
appBeanList.add(new VideoAppBean());
|
appBeanList.add(new VideoAppBean());
|
||||||
mVideoAppAdapter.addDatas(appBeanList);
|
mVideoAppAdapter.addDatas(appBeanList);
|
||||||
}
|
}
|
||||||
|
if(!isShowCustomApp()){
|
||||||
|
gv_category_apps.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGlobalLayout() {
|
||||||
|
gv_category_apps.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
|
gv_category_apps.scrollToPosition(0);
|
||||||
|
gv_category_apps.post(()->{
|
||||||
|
int firstVisibleItemPosition = ((GridLayoutManager) gv_category_apps.getLayoutManager()).findFirstVisibleItemPosition();
|
||||||
|
RecyclerView.ViewHolder holderview = gv_category_apps.findViewHolderForAdapterPosition(firstVisibleItemPosition);
|
||||||
|
if(holderview !=null){
|
||||||
|
View targetView = holderview.itemView;
|
||||||
|
targetView.post(() -> targetView.requestFocus());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
super.onResult(data);
|
super.onResult(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +146,9 @@ public class VideoFragment extends CategoryFragment {
|
|||||||
@Override
|
@Override
|
||||||
protected void toNextPage() {
|
protected void toNextPage() {
|
||||||
doneEvents(new MessageEvent(RecommendFragment.ACTION));
|
doneEvents(new MessageEvent(RecommendFragment.ACTION));
|
||||||
|
if(lastFocusPositon>SCROLLPOSITION){
|
||||||
|
disableFreshData=false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -119,6 +160,7 @@ public class VideoFragment extends CategoryFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onResumeFragment(MessageEvent event) {
|
public void onResumeFragment(MessageEvent event) {
|
||||||
super.onResumeFragment(event);
|
super.onResumeFragment(event);
|
||||||
|
disableFreshData=false;
|
||||||
loadAppInfoByCategory(AppManager.CATEGORY_VIDEO);//重新加载数据
|
loadAppInfoByCategory(AppManager.CATEGORY_VIDEO);//重新加载数据
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,484 +0,0 @@
|
|||||||
package com.ik.mboxlauncher.view;
|
|
||||||
|
|
||||||
import android.animation.ValueAnimator;
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.graphics.Outline;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.ViewOutlineProvider;
|
|
||||||
import android.view.animation.Animation;
|
|
||||||
import android.view.animation.ScaleAnimation;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.media3.common.Player;
|
|
||||||
|
|
||||||
import com.android.util.LogUtils;
|
|
||||||
import com.bumptech.glide.Glide;
|
|
||||||
import com.ik.mboxlauncher.R;
|
|
||||||
import com.seraphic.ad.AdPlayManager;
|
|
||||||
import com.seraphic.ad.AdStateListener;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public class AdMultiView extends MultiView {
|
|
||||||
private Context mContext;
|
|
||||||
private View mView;
|
|
||||||
private ImageView img_view;
|
|
||||||
private TextView tx_view;
|
|
||||||
private long animDuration = 50;
|
|
||||||
private View mMultiInsideLayout;
|
|
||||||
private ViewGroup mAdRootView;
|
|
||||||
private AdPlayManager mAdPlayManager;
|
|
||||||
private ViewGroup mFullRootView;
|
|
||||||
private boolean isFullAdShow;
|
|
||||||
private int mWidth = 0;
|
|
||||||
private int mHeight = 0;
|
|
||||||
|
|
||||||
private int oldMarginstart=0;
|
|
||||||
private int oldMargintop=0;
|
|
||||||
|
|
||||||
private int mAdState = -1;
|
|
||||||
|
|
||||||
public AdMultiView(@NonNull Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdMultiView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdMultiView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdMultiView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initView(Context context, AttributeSet attrs){
|
|
||||||
mContext = context;
|
|
||||||
LayoutInflater inflater = LayoutInflater.from(context);
|
|
||||||
mView = inflater.inflate(R.layout.ad_multi_layout,this);
|
|
||||||
tx_view = mView.findViewById(R.id.tx_view);
|
|
||||||
mMultiInsideLayout = mView.findViewById(R.id.multi_inside);
|
|
||||||
mAdRootView = mView.findViewById(R.id.ad_root);
|
|
||||||
img_view = mView.findViewById(R.id.img_view);
|
|
||||||
mView.findViewById(R.id.tx_view).setVisibility(View.INVISIBLE);
|
|
||||||
if(attrs!=null){
|
|
||||||
TypedArray a= context.getTheme().obtainStyledAttributes(attrs,R.styleable.AdMultiView,0,0);
|
|
||||||
try {
|
|
||||||
|
|
||||||
int titleResId = a.getResourceId(R.styleable.AdMultiView_adMultiViewTitle,-1);
|
|
||||||
int imageResId = a.getResourceId(R.styleable.AdMultiView_adMultiViewImage,-1);
|
|
||||||
|
|
||||||
if(titleResId!=-1){
|
|
||||||
tx_view.setText(titleResId);
|
|
||||||
tx_view.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
tx_view.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
if(imageResId!=-1){
|
|
||||||
img_view.setImageResource(imageResId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mMultiInsideLayout.setOutlineProvider(new ViewOutlineProvider() {
|
|
||||||
@Override
|
|
||||||
public void getOutline(View view, Outline outline) {
|
|
||||||
outline.setRoundRect(4, 4, view.getWidth()-4, view.getHeight()-4, 20);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mMultiInsideLayout.setClipToOutline(true);
|
|
||||||
hookWebView();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onVideoRestart(String uri) {
|
|
||||||
startAd();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onImageRestart(String uri) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onImageRestartLocal(String path) {
|
|
||||||
if(path==null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
img_view.setVisibility(VISIBLE);
|
|
||||||
File tmpfile= new File(path);
|
|
||||||
LogUtils.loge("AdMultiView tmpfile===>"+tmpfile.exists());
|
|
||||||
if(tmpfile.exists()) {
|
|
||||||
Glide.with(mContext).load(tmpfile).into(img_view);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadIamgeRes(String uri, int defaultImageId) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadDefaultImage(int resId) {
|
|
||||||
img_view.setImageResource(resId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resetView() {
|
|
||||||
//TODO 如果无需响应用户操作取消广告(即:广告可点击),删掉下方一行代码
|
|
||||||
// stopAd();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stopView() {
|
|
||||||
LogUtils.loge( "stopView=====>");
|
|
||||||
stopAd();
|
|
||||||
if(mFullRootView.getVisibility()==VISIBLE){
|
|
||||||
mFullRootView.setVisibility(GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void releaseView() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pauseView() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAdPlaying() {
|
|
||||||
return mAdState == AdStateListener.AD_PLAYING
|
|
||||||
|| mAdState == AdStateListener.AD_LOADING
|
|
||||||
|| mAdState == AdStateListener.AD_LOADED;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setFullRooView(ViewGroup fullRooView){
|
|
||||||
mFullRootView = fullRooView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
||||||
super.onLayout(changed, left, top, right, bottom);
|
|
||||||
if(mWidth == 0 || mHeight == 0) {
|
|
||||||
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
|
|
||||||
mWidth = getWidth();
|
|
||||||
mHeight = getHeight();
|
|
||||||
oldMarginstart =layoutParams.leftMargin;
|
|
||||||
oldMargintop =layoutParams.topMargin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDetachedFromWindow() {
|
|
||||||
super.onDetachedFromWindow();
|
|
||||||
stopAd();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("SoonBlockedPrivateApi")
|
|
||||||
private void hookWebView() {
|
|
||||||
int sdkInt = Build.VERSION.SDK_INT;
|
|
||||||
try {
|
|
||||||
Class factoryClass = Class.forName("android.webkit.WebViewFactory");
|
|
||||||
Field field = factoryClass.getDeclaredField("sProviderInstance");
|
|
||||||
field.setAccessible(true);
|
|
||||||
Object sProviderInstance = field.get(null);
|
|
||||||
if (sProviderInstance != null) {
|
|
||||||
LogUtils.logi("sProviderInstance isn't null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Method getProviderClassMethod = null;
|
|
||||||
if (sdkInt > 22) {
|
|
||||||
getProviderClassMethod = factoryClass.getDeclaredMethod("getProviderClass");
|
|
||||||
} else if (sdkInt == 22) {
|
|
||||||
getProviderClassMethod = factoryClass.getDeclaredMethod("getFactoryClass");
|
|
||||||
} else {
|
|
||||||
LogUtils.logi("Don't need to Hook WebView");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getProviderClassMethod.setAccessible(true);
|
|
||||||
Class factoryProviderClass = (Class) getProviderClassMethod.invoke(factoryClass);
|
|
||||||
Class delegateClass = Class.forName("android.webkit.WebViewDelegate");
|
|
||||||
Constructor delegateConstructor = delegateClass.getDeclaredConstructor();
|
|
||||||
delegateConstructor.setAccessible(true);
|
|
||||||
if (sdkInt < 26) { //低于Android O版本
|
|
||||||
Constructor providerConstructor = factoryProviderClass.getConstructor(delegateClass);
|
|
||||||
if (providerConstructor != null) {
|
|
||||||
providerConstructor.setAccessible(true);
|
|
||||||
sProviderInstance = providerConstructor.newInstance(delegateConstructor.newInstance());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Field chromiumMethodName = factoryClass.getDeclaredField("CHROMIUM_WEBVIEW_FACTORY_METHOD");
|
|
||||||
chromiumMethodName.setAccessible(true);
|
|
||||||
String chromiumMethodNameStr = (String) chromiumMethodName.get(null);
|
|
||||||
if (chromiumMethodNameStr == null) {
|
|
||||||
chromiumMethodNameStr = "create";
|
|
||||||
}
|
|
||||||
Method staticFactory = factoryProviderClass.getMethod(chromiumMethodNameStr, delegateClass);
|
|
||||||
if (staticFactory != null) {
|
|
||||||
sProviderInstance = staticFactory.invoke(null, delegateConstructor.newInstance());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sProviderInstance != null) {
|
|
||||||
field.set("sProviderInstance", sProviderInstance);
|
|
||||||
LogUtils.logi("can use webview");
|
|
||||||
} else {
|
|
||||||
LogUtils.logi("can not use webview");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startAd(){
|
|
||||||
if(mAdPlayManager != null){
|
|
||||||
stopAd();
|
|
||||||
}
|
|
||||||
mAdPlayManager = new AdPlayManager(mContext, AdPlayManager.TYPE_WITH_CONTAINER,
|
|
||||||
0, adstate -> {
|
|
||||||
if(mMultiViewListener != null) {
|
|
||||||
int playState = Player.STATE_IDLE;
|
|
||||||
switch (adstate){
|
|
||||||
case AdStateListener.AD_LOADING:
|
|
||||||
playState = Player.STATE_BUFFERING;
|
|
||||||
break;
|
|
||||||
case AdStateListener.AD_LOADED:
|
|
||||||
case AdStateListener.AD_PLAYING:
|
|
||||||
playState = Player.STATE_READY;
|
|
||||||
break;
|
|
||||||
case AdStateListener.AD_ERROR:
|
|
||||||
playState = adstate;
|
|
||||||
break;
|
|
||||||
case AdStateListener.AD_COMPLETE_ALL:
|
|
||||||
playState = Player.STATE_ENDED;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
LogUtils.loge("AdMultiView adstate ===>"+adstate);
|
|
||||||
if((mAdState == -1 || mAdState != adstate) && playState != Player.STATE_IDLE) {
|
|
||||||
mMultiViewListener.onPlaybackStateChanged(getId(), playState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mAdState = adstate;
|
|
||||||
|
|
||||||
if(adstate == AdStateListener.AD_COMPLETE_ALL||adstate == AdStateListener.AD_ERROR){
|
|
||||||
if(isFullAdShow){
|
|
||||||
isFullAdShow = false;
|
|
||||||
requestFocus();
|
|
||||||
}
|
|
||||||
stopAd();
|
|
||||||
}
|
|
||||||
}); //position 必填
|
|
||||||
mAdPlayManager.setAdFullRootView(mFullRootView);//设置全屏的 ad root
|
|
||||||
if(isFocused()) {//焦点在当前view时,显示back提示
|
|
||||||
mAdPlayManager.setNeedCancelTips(true);
|
|
||||||
}
|
|
||||||
mAdPlayManager.startAd(mAdRootView,0);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void stopAd() {
|
|
||||||
LogUtils.loge( "stopAd=====>");
|
|
||||||
if (mAdPlayManager != null) {
|
|
||||||
mAdPlayManager.stopAd();
|
|
||||||
mAdPlayManager = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onAdViewClick(){
|
|
||||||
boolean isNeed = false;
|
|
||||||
if (mAdPlayManager != null) {
|
|
||||||
isNeed = mAdPlayManager.onAdViewClick();
|
|
||||||
}
|
|
||||||
isFullAdShow = isNeed;
|
|
||||||
return isNeed;
|
|
||||||
}
|
|
||||||
public boolean onAdBackClick(){
|
|
||||||
boolean isNeed = false;
|
|
||||||
//NOTE: 如果希望全局按back键取消广告,可以移除焦点判断
|
|
||||||
if (isFocused() && mAdPlayManager != null) {
|
|
||||||
isNeed = mAdPlayManager.onAdBackClick();
|
|
||||||
}
|
|
||||||
return isNeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean mGainFocus=false;
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) {
|
|
||||||
// super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
|
|
||||||
// mGainFocus = gainFocus;
|
|
||||||
//
|
|
||||||
// if (gainFocus) {
|
|
||||||
// if(mAdPlayManager != null) {
|
|
||||||
// mAdPlayManager.setNeedCancelTips(true);
|
|
||||||
// }
|
|
||||||
// setBackgroundResource(R.drawable.app_item_border);
|
|
||||||
// setTranslationZ(10);
|
|
||||||
// setElevation(10);
|
|
||||||
//
|
|
||||||
// scaleView(1.05f);
|
|
||||||
//
|
|
||||||
//// ScaleAnimation anim = new ScaleAnimation(1f, 1.1f, 1f, 1.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
|
|
||||||
//// anim.setZAdjustment(Animation.ZORDER_TOP);
|
|
||||||
//// anim.setDuration(animDuration);
|
|
||||||
//// anim.setFillAfter(true);
|
|
||||||
//// this.startAnimation(anim);
|
|
||||||
// this.bringToFront();
|
|
||||||
// } else {
|
|
||||||
// if(mAdPlayManager != null) {
|
|
||||||
// mAdPlayManager.setNeedCancelTips(false);
|
|
||||||
// }
|
|
||||||
// setBackgroundResource(R.color.transparent_background);
|
|
||||||
// setTranslationZ(0);
|
|
||||||
// setElevation(0);
|
|
||||||
// scaleView(1.0f);
|
|
||||||
//// ScaleAnimation anim = new ScaleAnimation(1.1f, 1f, 1.1f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
|
|
||||||
//// anim.setZAdjustment(Animation.ZORDER_TOP);
|
|
||||||
//// anim.setDuration(animDuration);
|
|
||||||
//// anim.setFillAfter(true);
|
|
||||||
//// this.startAnimation(anim);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) {
|
|
||||||
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
|
|
||||||
// int width = getWidth();
|
|
||||||
// int height = getHeight();
|
|
||||||
mGainFocus = gainFocus;
|
|
||||||
if(gainFocus){
|
|
||||||
if(mAdPlayManager != null) {
|
|
||||||
mAdPlayManager.setNeedCancelTips(true);
|
|
||||||
}
|
|
||||||
setBackgroundResource(R.drawable.app_item_border);
|
|
||||||
setTranslationZ(8);
|
|
||||||
setElevation(8);
|
|
||||||
ValueAnimator animator = ValueAnimator.ofFloat(1f,1.1f);
|
|
||||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationUpdate(@NonNull ValueAnimator valueAnimator) {
|
|
||||||
float scale = (float) valueAnimator.getAnimatedValue();
|
|
||||||
// RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
|
|
||||||
// layoutParams.height = (int) (height*scale);
|
|
||||||
// layoutParams.width = (int) (width*scale);
|
|
||||||
// setLayoutParams(layoutParams);
|
|
||||||
// setScaleWithLayoutd(scale);
|
|
||||||
setScaleWithLayoutd(scale);
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
animator.setDuration(animDuration);
|
|
||||||
animator.start();
|
|
||||||
this.bringToFront();
|
|
||||||
}else {
|
|
||||||
if(mAdPlayManager != null) {
|
|
||||||
mAdPlayManager.setNeedCancelTips(false);
|
|
||||||
}
|
|
||||||
setBackgroundResource(R.color.transparent_background);
|
|
||||||
setTranslationZ(0);
|
|
||||||
setElevation(0);
|
|
||||||
ValueAnimator animator = ValueAnimator.ofFloat(1.1f, 1f);
|
|
||||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationUpdate(@NonNull ValueAnimator valueAnimator) {
|
|
||||||
float scale = (float) valueAnimator.getAnimatedValue();
|
|
||||||
// RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
|
|
||||||
// layoutParams.height = (int) (height*scale);
|
|
||||||
// layoutParams.width = (int) (width*scale);
|
|
||||||
// if(layoutParams.height < mHeight || layoutParams.width < mWidth){
|
|
||||||
// layoutParams.height = mHeight;
|
|
||||||
// layoutParams.width = mWidth;
|
|
||||||
// }
|
|
||||||
// setLayoutParams(layoutParams);
|
|
||||||
// setScaleWithLayoutd(scale);
|
|
||||||
setScaleWithLayoutd(scale);
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
animator.setDuration(animDuration);
|
|
||||||
animator.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 缩放方法
|
|
||||||
public void scaleView(float scale) {
|
|
||||||
setScaleX(scale);
|
|
||||||
setScaleY(scale);
|
|
||||||
setScaleWithLayoutd(scale);
|
|
||||||
invalidate(); // 可选,通常不需要
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 或者如果需要同时改变布局大小
|
|
||||||
public void setScaleWithLayoutd(float scale) {
|
|
||||||
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) getLayoutParams();
|
|
||||||
int newWidth = (int) (mWidth * scale);
|
|
||||||
int newHeight = (int) (mHeight * scale);
|
|
||||||
|
|
||||||
// 调整margin保持中心位置
|
|
||||||
lp.leftMargin -= (newWidth - lp.width) / 2;
|
|
||||||
lp.topMargin -= (newHeight - lp.height) / 2;
|
|
||||||
|
|
||||||
lp.width = newWidth;
|
|
||||||
lp.height = newHeight;
|
|
||||||
setLayoutParams(lp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// public void setScaleWithLayouts(float scale) {
|
|
||||||
// RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) getLayoutParams();
|
|
||||||
// // 调整margin保持中心位置
|
|
||||||
// lp.leftMargin -= (mWidth - lp.width) / 2;
|
|
||||||
// lp.topMargin -= (mWidth - lp.height) / 2;
|
|
||||||
// lp.width = mWidth;
|
|
||||||
// lp.height = mWidth;
|
|
||||||
// setLayoutParams(lp);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
||||||
LogUtils.loge("AdMultiView onKeyDown==>"+keyCode);
|
|
||||||
switch (keyCode){
|
|
||||||
case KeyEvent.KEYCODE_BACK:
|
|
||||||
if(mGainFocus){
|
|
||||||
onAdBackClick();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onKeyDown(keyCode, event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -166,6 +166,10 @@ public class CustomRecyclerViewer extends RecyclerView {
|
|||||||
super.requestChildFocus(child, focused);//执行过super.requestChildFocus之后hasFocus会变成true
|
super.requestChildFocus(child, focused);//执行过super.requestChildFocus之后hasFocus会变成true
|
||||||
mCurrentFocusPosition = getChildViewHolder(child).getAdapterPosition();
|
mCurrentFocusPosition = getChildViewHolder(child).getAdapterPosition();
|
||||||
}
|
}
|
||||||
|
//获取当前焦点位置
|
||||||
|
public int getmCurrentFocusPosition() {
|
||||||
|
return mCurrentFocusPosition;
|
||||||
|
}
|
||||||
|
|
||||||
//实现焦点记忆的关键代码
|
//实现焦点记忆的关键代码
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ public class HomeMultiView extends MultiView {
|
|||||||
private int animDuration=50;
|
private int animDuration=50;
|
||||||
|
|
||||||
private View mMultiInsideLayout;
|
private View mMultiInsideLayout;
|
||||||
|
private int imageResId;
|
||||||
|
|
||||||
|
|
||||||
public HomeMultiView(@NonNull Context context) {
|
public HomeMultiView(@NonNull Context context) {
|
||||||
@@ -98,7 +99,7 @@ public class HomeMultiView extends MultiView {
|
|||||||
TypedArray a= context.getTheme().obtainStyledAttributes(attrs,R.styleable.MultiView,0,0);
|
TypedArray a= context.getTheme().obtainStyledAttributes(attrs,R.styleable.MultiView,0,0);
|
||||||
try {
|
try {
|
||||||
int titleResId = a.getResourceId(R.styleable.MultiView_multiViewTitle,-1);
|
int titleResId = a.getResourceId(R.styleable.MultiView_multiViewTitle,-1);
|
||||||
int imageResId = a.getResourceId(R.styleable.MultiView_multiViewImage,-1);
|
imageResId = a.getResourceId(R.styleable.MultiView_multiViewImage,-1);
|
||||||
boolean adsSwitch = a.getBoolean(R.styleable.MultiView_adsSwitch,false);
|
boolean adsSwitch = a.getBoolean(R.styleable.MultiView_adsSwitch,false);
|
||||||
if(titleResId!=-1){
|
if(titleResId!=-1){
|
||||||
tx_view.setText(titleResId);
|
tx_view.setText(titleResId);
|
||||||
@@ -107,7 +108,7 @@ public class HomeMultiView extends MultiView {
|
|||||||
tx_view.setVisibility(View.INVISIBLE);
|
tx_view.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(imageResId!=-1){
|
if(imageResId !=-1){
|
||||||
img_view.setImageResource(imageResId);
|
img_view.setImageResource(imageResId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +185,7 @@ public class HomeMultiView extends MultiView {
|
|||||||
@Override
|
@Override
|
||||||
public void onImageRestartLocal(String path){
|
public void onImageRestartLocal(String path){
|
||||||
LogUtils.loge("onImageRestartLocal==>"+path);
|
LogUtils.loge("onImageRestartLocal==>"+path);
|
||||||
if(path==null){
|
if(TextUtils.isEmpty(path)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
img_view.setVisibility(VISIBLE);
|
img_view.setVisibility(VISIBLE);
|
||||||
@@ -196,7 +197,7 @@ public class HomeMultiView extends MultiView {
|
|||||||
File tmpfile= new File(path);
|
File tmpfile= new File(path);
|
||||||
LogUtils.loge("tmpfile===>"+tmpfile.exists());
|
LogUtils.loge("tmpfile===>"+tmpfile.exists());
|
||||||
if(tmpfile.exists()) {
|
if(tmpfile.exists()) {
|
||||||
Glide.with(mContext).load(tmpfile).into(img_view);
|
Glide.with(mContext).load(tmpfile).placeholder(imageResId).into(img_view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,26 +147,33 @@ public class SplashView {
|
|||||||
|
|
||||||
if(adsInfoBeanInfo==null){
|
if(adsInfoBeanInfo==null){
|
||||||
LogUtils.loge("adsInfoBeanInfo is null===>");
|
LogUtils.loge("adsInfoBeanInfo is null===>");
|
||||||
mHandler.sendEmptyMessageDelayed(2,10000);
|
mHandler.sendEmptyMessage(2);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(adsInfoBeanInfo.getLocalFilePath()==null){
|
if(adsInfoBeanInfo.getLocalFilePath()==null){
|
||||||
LogUtils.loge("getLocalFilePath is null===>");
|
LogUtils.loge("getLocalFilePath is null===>");
|
||||||
mHandler.sendEmptyMessageDelayed(2,10000);
|
mHandler.sendEmptyMessage(2);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
File file = new File(adsInfoBeanInfo.getLocalFilePath());
|
File file = new File(adsInfoBeanInfo.getLocalFilePath());
|
||||||
if(!file.exists()){
|
if(!file.exists()){
|
||||||
LogUtils.loge("file is not exits===>");
|
File tempFile=new File(adsInfoBeanInfo.getLocalFilePath()+"-tmp");
|
||||||
mHandler.sendEmptyMessageDelayed(2,10000);
|
if(tempFile.exists()&&tempFile.length()==adsInfoBeanInfo.getAdSize()){
|
||||||
return ;
|
tempFile.renameTo(file);
|
||||||
|
tempFile.delete();
|
||||||
|
LogUtils.loge("下载大小完成但重命名失败同时下载任务已清除图片至始至终未显示优化处理 system rename file file bug compose");
|
||||||
|
}else {
|
||||||
|
LogUtils.loge("file is not exits===>");
|
||||||
|
mHandler.sendEmptyMessage(2);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(adsInfoBeanInfo.getState()==0){
|
if(adsInfoBeanInfo.getState()==0){
|
||||||
LogUtils.loge("splash task is closd ");
|
LogUtils.loge("splash task is closd ");
|
||||||
mHandler.sendEmptyMessageDelayed(2,5000);
|
mHandler.sendEmptyMessage(2);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
688
app/src/main/java/com/ik/mboxlauncher/view/TvRecyclerView.java
Normal file
688
app/src/main/java/com/ik/mboxlauncher/view/TvRecyclerView.java
Normal file
@@ -0,0 +1,688 @@
|
|||||||
|
package com.ik.mboxlauncher.view;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.FocusFinder;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.core.view.ViewCompat;
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||||
|
|
||||||
|
import com.android.util.LogUtils;
|
||||||
|
import com.ik.mboxlauncher.R;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ksl on 2026/1/9.
|
||||||
|
*/
|
||||||
|
public class TvRecyclerView extends RecyclerView {
|
||||||
|
private static final String TAG = "TvRecyclerView";
|
||||||
|
|
||||||
|
private int position;
|
||||||
|
private int lastFocusPosition;
|
||||||
|
//焦点是否居中
|
||||||
|
private boolean mSelectedItemCentered;
|
||||||
|
|
||||||
|
private boolean hasResetFocus;//自控焦点
|
||||||
|
|
||||||
|
private boolean mScrollDirecitonUp;//默认向下滚
|
||||||
|
|
||||||
|
private int mSelectedItemOffsetStart;
|
||||||
|
|
||||||
|
private int mSelectedItemOffsetEnd;
|
||||||
|
|
||||||
|
//分页的时候使用
|
||||||
|
private int mLoadMoreBeforehandCount = 0;
|
||||||
|
private PressBackListenner mPressbackLister;
|
||||||
|
|
||||||
|
public TvRecyclerView(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TvRecyclerView(Context context, AttributeSet attrs) {
|
||||||
|
this(context, attrs, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TvRecyclerView(Context context, AttributeSet attrs, int defStyle) {
|
||||||
|
super(context, attrs, defStyle);
|
||||||
|
init(context, attrs, defStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(Context context, AttributeSet attrs, int defStyle) {
|
||||||
|
initView();
|
||||||
|
initAttr(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initView() {
|
||||||
|
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
|
||||||
|
setHasFixedSize(true);
|
||||||
|
setWillNotDraw(true);
|
||||||
|
setOverScrollMode(View.OVER_SCROLL_NEVER);
|
||||||
|
setChildrenDrawingOrderEnabled(true);
|
||||||
|
|
||||||
|
setClipChildren(false);
|
||||||
|
setClipToPadding(false);
|
||||||
|
|
||||||
|
setClickable(false);
|
||||||
|
setFocusable(true);
|
||||||
|
setFocusableInTouchMode(true);
|
||||||
|
/**
|
||||||
|
防止RecyclerView刷新时焦点不错乱bug的步骤如下:
|
||||||
|
(1)adapter执行setHasStableIds(true)方法
|
||||||
|
(2)重写getItemId()方法,让每个view都有各自的id
|
||||||
|
(3)RecyclerView的动画必须去掉
|
||||||
|
*/
|
||||||
|
setItemAnimator(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initAttr(Context context, AttributeSet attrs) {
|
||||||
|
if (attrs != null) {
|
||||||
|
final TypedArray a = context.obtainStyledAttributes(attrs,
|
||||||
|
R.styleable.TvRecyclerView);
|
||||||
|
/**
|
||||||
|
* 如果是towWayView的layoutManager
|
||||||
|
*/
|
||||||
|
final String name = a.getString(R.styleable.TvRecyclerView_tv_layoutManager);
|
||||||
|
|
||||||
|
|
||||||
|
mSelectedItemCentered = a.getBoolean(R.styleable.TvRecyclerView_tv_selectedItemCentered, false);
|
||||||
|
|
||||||
|
mLoadMoreBeforehandCount = a.getInteger(R.styleable.TvRecyclerView_tv_loadMoreBeforehandCount, 0);
|
||||||
|
|
||||||
|
mSelectedItemOffsetStart = a.getDimensionPixelSize(R.styleable.TvRecyclerView_tv_selectedItemOffsetStart, 0);
|
||||||
|
|
||||||
|
mSelectedItemOffsetEnd = a.getDimensionPixelSize(R.styleable.TvRecyclerView_tv_selectedItemOffsetEnd, 0);
|
||||||
|
|
||||||
|
a.recycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private int getFreeWidth() {
|
||||||
|
return getWidth() - getPaddingLeft() - getPaddingRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getFreeHeight() {
|
||||||
|
return getHeight() - getPaddingTop() - getPaddingBottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
|
||||||
|
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
|
||||||
|
// View lastFocusedView = getLayoutManager().findViewByPosition(lastFocusPosition);
|
||||||
|
// if(lastFocusedView!=null){
|
||||||
|
// lastFocusedView.requestFocus();
|
||||||
|
// }
|
||||||
|
if(!gainFocus){
|
||||||
|
hasResetFocus=false;
|
||||||
|
LogUtils.loge("TvRecyclerView gainFocus="+gainFocus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasFocus() {
|
||||||
|
return super.hasFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInTouchMode() {
|
||||||
|
// 解决4.4版本抢焦点的问题
|
||||||
|
if (Build.VERSION.SDK_INT == 19) {
|
||||||
|
return !(hasFocus() && !super.isInTouchMode());
|
||||||
|
} else {
|
||||||
|
return super.isInTouchMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
//return super.isInTouchMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestChildFocus(View child, View focused) {
|
||||||
|
|
||||||
|
if (null != child) {
|
||||||
|
if (mSelectedItemCentered) {
|
||||||
|
mSelectedItemOffsetStart = !isVertical() ? (getFreeWidth() - child.getWidth()) : (getFreeHeight() - child.getHeight());
|
||||||
|
mSelectedItemOffsetStart /= 2;
|
||||||
|
mSelectedItemOffsetEnd = mSelectedItemOffsetStart;
|
||||||
|
}
|
||||||
|
lastFocusPosition=getChildViewHolder(child).getAdapterPosition();
|
||||||
|
Log.e(TAG,"lastFocusPosition="+lastFocusPosition);
|
||||||
|
}
|
||||||
|
super.requestChildFocus(child, focused);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
|
||||||
|
final int parentLeft = getPaddingLeft();
|
||||||
|
final int parentRight = getWidth() - getPaddingRight();
|
||||||
|
|
||||||
|
final int parentTop = getPaddingTop();
|
||||||
|
final int parentBottom = getHeight() - getPaddingBottom();
|
||||||
|
|
||||||
|
final int childLeft = child.getLeft() + rect.left;
|
||||||
|
final int childTop = child.getTop() + rect.top;
|
||||||
|
|
||||||
|
final int childRight = childLeft + rect.width();
|
||||||
|
final int childBottom = childTop + rect.height();
|
||||||
|
|
||||||
|
final int offScreenLeft = Math.min(0, childLeft - parentLeft - mSelectedItemOffsetStart);
|
||||||
|
final int offScreenRight = Math.max(0, childRight - parentRight + mSelectedItemOffsetEnd);
|
||||||
|
|
||||||
|
final int offScreenTop = Math.min(0, childTop - parentTop - mSelectedItemOffsetStart);
|
||||||
|
final int offScreenBottom = Math.max(0, childBottom - parentBottom + mSelectedItemOffsetEnd);
|
||||||
|
|
||||||
|
|
||||||
|
final boolean canScrollHorizontal = getLayoutManager().canScrollHorizontally();
|
||||||
|
final boolean canScrollVertical = getLayoutManager().canScrollVertically();
|
||||||
|
|
||||||
|
// Favor the "start" layout direction over the end when bringing one side or the other
|
||||||
|
// of a large rect into view. If we decide to bring in end because start is already
|
||||||
|
// visible, limit the scroll such that start won't go out of bounds.
|
||||||
|
final int dx;
|
||||||
|
if (canScrollHorizontal) {
|
||||||
|
if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL) {
|
||||||
|
dx = offScreenRight != 0 ? offScreenRight
|
||||||
|
: Math.max(offScreenLeft, childRight - parentRight);
|
||||||
|
} else {
|
||||||
|
dx = offScreenLeft != 0 ? offScreenLeft
|
||||||
|
: Math.min(childLeft - parentLeft, offScreenRight);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Favor bringing the top into view over the bottom. If top is already visible and
|
||||||
|
// we should scroll to make bottom visible, make sure top does not go out of bounds.
|
||||||
|
final int dy;
|
||||||
|
if (canScrollVertical) {
|
||||||
|
dy = offScreenTop != 0 ? offScreenTop : Math.min(childTop - parentTop, offScreenBottom);
|
||||||
|
} else {
|
||||||
|
dy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (dx != 0 || dy != 0) {
|
||||||
|
if (immediate) {
|
||||||
|
scrollBy(dx, dy);
|
||||||
|
} else {
|
||||||
|
smoothScrollBy(dx, dy);
|
||||||
|
}
|
||||||
|
// 重绘是为了选中item置顶,具体请参考getChildDrawingOrder方法
|
||||||
|
postInvalidate();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBaseline() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getSelectedItemOffsetStart() {
|
||||||
|
return mSelectedItemOffsetStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSelectedItemOffsetEnd() {
|
||||||
|
return mSelectedItemOffsetEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLayoutManager(LayoutManager layout) {
|
||||||
|
super.setLayoutManager(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是垂直,还是横向.
|
||||||
|
*/
|
||||||
|
private boolean isVertical() {
|
||||||
|
LayoutManager manager = getLayoutManager();
|
||||||
|
if (manager != null) {
|
||||||
|
LinearLayoutManager layout = (LinearLayoutManager) getLayoutManager();
|
||||||
|
return layout.getOrientation() == LinearLayoutManager.VERTICAL;
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置选中的Item距离开始或结束的偏移量;
|
||||||
|
* 与滚动方向有关;
|
||||||
|
* 与setSelectedItemAtCentered()方法二选一
|
||||||
|
*
|
||||||
|
* @param offsetStart
|
||||||
|
* @param offsetEnd 从结尾到你移动的位置.
|
||||||
|
*/
|
||||||
|
public void setSelectedItemOffset(int offsetStart, int offsetEnd) {
|
||||||
|
setSelectedItemAtCentered(false);
|
||||||
|
mSelectedItemOffsetStart = offsetStart;
|
||||||
|
mSelectedItemOffsetEnd = offsetEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置选中的Item居中;
|
||||||
|
* 与setSelectedItemOffset()方法二选一
|
||||||
|
*
|
||||||
|
* @param isCentered
|
||||||
|
*/
|
||||||
|
public void setSelectedItemAtCentered(boolean isCentered) {
|
||||||
|
this.mSelectedItemCentered = isCentered;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getChildDrawingOrder(int childCount, int i) {
|
||||||
|
View view = getFocusedChild();
|
||||||
|
if (null != view) {
|
||||||
|
|
||||||
|
position = getChildAdapterPosition(view) - getFirstVisiblePosition();
|
||||||
|
if (position < 0) {
|
||||||
|
return i;
|
||||||
|
} else {
|
||||||
|
if (i == childCount - 1) {//这是最后一个需要刷新的item
|
||||||
|
if (position > i) {
|
||||||
|
position = i;
|
||||||
|
}
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
if (i == position) {//这是原本要在最后一个刷新的item
|
||||||
|
return childCount - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFirstVisiblePosition() {
|
||||||
|
if (getChildCount() == 0)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return getChildAdapterPosition(getChildAt(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastVisiblePosition() {
|
||||||
|
final int childCount = getChildCount();
|
||||||
|
if (childCount == 0)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return getChildAdapterPosition(getChildAt(childCount - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***********
|
||||||
|
* 按键加载更多 start
|
||||||
|
**********/
|
||||||
|
|
||||||
|
private OnLoadMoreListener mOnLoadMoreListener;
|
||||||
|
|
||||||
|
public interface OnLoadMoreListener {
|
||||||
|
void onLoadMore();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) {
|
||||||
|
this.mOnLoadMoreListener = onLoadMoreListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// private PressBackListenner mPressbackLister;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public void setOnPressBackListener(PressBackListenner listener) {
|
||||||
|
// this.mPressbackLister = listener;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置为0,这样可以防止View获取焦点的时候,ScrollView自动滚动到焦点View的位置
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onScrollStateChanged(int state) {
|
||||||
|
if (state == SCROLL_STATE_IDLE) {
|
||||||
|
// 加载更多回调
|
||||||
|
if (null != mOnLoadMoreListener) {
|
||||||
|
if (getLastVisiblePosition() >= getAdapter().getItemCount() - (1 + mLoadMoreBeforehandCount)) {
|
||||||
|
mOnLoadMoreListener.onLoadMore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LayoutManager layoutManager = getLayoutManager();
|
||||||
|
GridLayoutManager staggeredGridLayoutManager = (GridLayoutManager) layoutManager;
|
||||||
|
int spanCount = staggeredGridLayoutManager.getSpanCount();
|
||||||
|
int itemCount = staggeredGridLayoutManager.getItemCount();
|
||||||
|
Log.i(TAG,"onScrollStateChanged() spanCount="+spanCount+"itemCount="+itemCount);
|
||||||
|
if(hasResetFocus&&mScrollDirecitonUp&&lastFocusPosition>=spanCount){
|
||||||
|
Log.i(TAG,"onScrollStateChanged() hasResetFocus1="+hasResetFocus);
|
||||||
|
hasResetFocus=false;
|
||||||
|
setSelectedPosition(lastFocusPosition-spanCount);
|
||||||
|
View view = layoutManager.findViewByPosition(lastFocusPosition-spanCount);
|
||||||
|
if (view != null) {
|
||||||
|
view.requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(hasResetFocus&&!mScrollDirecitonUp&&lastFocusPosition<itemCount-spanCount){
|
||||||
|
Log.i(TAG,"onScrollStateChanged() hasResetFocus2="+hasResetFocus);
|
||||||
|
hasResetFocus=false;
|
||||||
|
View view = layoutManager.findViewByPosition(lastFocusPosition+spanCount);
|
||||||
|
if (view != null) {
|
||||||
|
view.requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(hasResetFocus&&!mScrollDirecitonUp&&lastFocusPosition>=itemCount-spanCount&&lastFocusPosition<spanCount*(itemCount/spanCount)&&itemCount%spanCount!=0){
|
||||||
|
hasResetFocus=false;
|
||||||
|
Log.i(TAG,"onScrollStateChanged() hasResetFocus3="+hasResetFocus);
|
||||||
|
View view = layoutManager.findViewByPosition(itemCount-1);
|
||||||
|
if (view != null) {
|
||||||
|
view.requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onScrollStateChanged(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
|
|
||||||
|
boolean result = super.dispatchKeyEvent(event);
|
||||||
|
View focusView = this.getFocusedChild();
|
||||||
|
if (focusView == null) {
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
int dy = 0;
|
||||||
|
int dx = 0;
|
||||||
|
if (getChildCount() > 0) {
|
||||||
|
View firstView = this.getChildAt(0);
|
||||||
|
dy = firstView.getHeight();
|
||||||
|
dx = firstView.getWidth();
|
||||||
|
}
|
||||||
|
if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
switch (event.getKeyCode()) {
|
||||||
|
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||||
|
View rightView = FocusFinder.getInstance().findNextFocus(this, focusView, View.FOCUS_RIGHT);
|
||||||
|
Log.i(TAG, "rightView is null:" + (rightView == null));
|
||||||
|
if (rightView != null) {
|
||||||
|
rightView.requestFocus();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.smoothScrollBy(dx, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||||
|
View leftView = FocusFinder.getInstance().findNextFocus(this, focusView, View.FOCUS_LEFT);
|
||||||
|
Log.i(TAG, "leftView is null:" + (leftView == null));
|
||||||
|
if (leftView != null) {
|
||||||
|
leftView.requestFocus();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.smoothScrollBy(-dx, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case KeyEvent.KEYCODE_DPAD_DOWN:
|
||||||
|
mScrollDirecitonUp=false;
|
||||||
|
View downView = FocusFinder.getInstance().findNextFocus(this, focusView, View.FOCUS_DOWN);
|
||||||
|
Log.i(TAG, " downView is null:" + (downView == null));
|
||||||
|
if (downView != null) {
|
||||||
|
hasResetFocus=false;
|
||||||
|
downView.requestFocus();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.smoothScrollBy(0, dy);
|
||||||
|
hasResetFocus=true;
|
||||||
|
return true;// true解决item滚动滑向中间item
|
||||||
|
}
|
||||||
|
case KeyEvent.KEYCODE_DPAD_UP:
|
||||||
|
mScrollDirecitonUp=true;
|
||||||
|
View upView = FocusFinder.getInstance().findNextFocus(this, focusView, View.FOCUS_UP);
|
||||||
|
Log.i(TAG, "upView is null:" + (upView == null));
|
||||||
|
if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (upView != null) {
|
||||||
|
hasResetFocus=false;
|
||||||
|
upView.requestFocus();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
hasResetFocus=true;
|
||||||
|
this.smoothScrollBy(0, -dy);
|
||||||
|
Log.e(TAG,"KEYCODE_DPAD_UP");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(event.getKeyCode()== KeyEvent.KEYCODE_BACK){
|
||||||
|
if(mPressbackLister!=null){
|
||||||
|
mPressbackLister.hasPressback(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Log.e(TAG,"dispatchKeyEvent()="+result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onInterceptTouchEvent(MotionEvent e) {
|
||||||
|
return super.onInterceptTouchEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置默认选中.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void setSelectedPosition(int pos) {
|
||||||
|
this.smoothScrollToPosition(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
//防止Activity时,RecyclerView崩溃
|
||||||
|
@Override
|
||||||
|
protected void onDetachedFromWindow() {
|
||||||
|
if (getLayoutManager() != null) {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是最右边的item,如果是竖向,表示右边,如果是横向表示下边
|
||||||
|
*
|
||||||
|
* @param childPosition
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isRightEdge(int childPosition) {
|
||||||
|
LayoutManager layoutManager = getLayoutManager();
|
||||||
|
|
||||||
|
if (layoutManager instanceof GridLayoutManager) {
|
||||||
|
|
||||||
|
GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
|
||||||
|
GridLayoutManager.SpanSizeLookup spanSizeLookUp = gridLayoutManager.getSpanSizeLookup();
|
||||||
|
|
||||||
|
int totalSpanCount = gridLayoutManager.getSpanCount();
|
||||||
|
int totalItemCount = gridLayoutManager.getItemCount();
|
||||||
|
int childSpanCount = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i <= childPosition; i++) {
|
||||||
|
childSpanCount += spanSizeLookUp.getSpanSize(i);
|
||||||
|
}
|
||||||
|
if (isVertical()) {
|
||||||
|
if (childSpanCount % gridLayoutManager.getSpanCount() == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int lastColumnSize = totalItemCount % totalSpanCount;
|
||||||
|
if (lastColumnSize == 0) {
|
||||||
|
lastColumnSize = totalSpanCount;
|
||||||
|
}
|
||||||
|
if (childSpanCount > totalItemCount - lastColumnSize) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (layoutManager instanceof LinearLayoutManager) {
|
||||||
|
if (isVertical()) {
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return childPosition == getLayoutManager().getItemCount() - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是最左边的item,如果是竖向,表示左方,如果是横向,表示上边
|
||||||
|
*
|
||||||
|
* @param childPosition
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isLeftEdge(int childPosition) {
|
||||||
|
LayoutManager layoutManager = getLayoutManager();
|
||||||
|
if (layoutManager instanceof GridLayoutManager) {
|
||||||
|
GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
|
||||||
|
GridLayoutManager.SpanSizeLookup spanSizeLookUp = gridLayoutManager.getSpanSizeLookup();
|
||||||
|
|
||||||
|
int totalSpanCount = gridLayoutManager.getSpanCount();
|
||||||
|
int childSpanCount = 0;
|
||||||
|
for (int i = 0; i <= childPosition; i++) {
|
||||||
|
childSpanCount += spanSizeLookUp.getSpanSize(i);
|
||||||
|
}
|
||||||
|
if (isVertical()) {
|
||||||
|
if (childSpanCount % gridLayoutManager.getSpanCount() == 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (childSpanCount <= totalSpanCount) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (layoutManager instanceof LinearLayoutManager) {
|
||||||
|
if (isVertical()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return childPosition == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是最上边的item,以recyclerview的方向做参考
|
||||||
|
*
|
||||||
|
* @param childPosition
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isTopEdge(int childPosition) {
|
||||||
|
LayoutManager layoutManager = getLayoutManager();
|
||||||
|
if (layoutManager instanceof GridLayoutManager) {
|
||||||
|
GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
|
||||||
|
GridLayoutManager.SpanSizeLookup spanSizeLookUp = gridLayoutManager.getSpanSizeLookup();
|
||||||
|
|
||||||
|
int totalSpanCount = gridLayoutManager.getSpanCount();
|
||||||
|
|
||||||
|
int childSpanCount = 0;
|
||||||
|
for (int i = 0; i <= childPosition; i++) {
|
||||||
|
childSpanCount += spanSizeLookUp.getSpanSize(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isVertical()) {
|
||||||
|
if (childSpanCount <= totalSpanCount) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (childSpanCount % totalSpanCount == 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else if (layoutManager instanceof LinearLayoutManager) {
|
||||||
|
if (isVertical()) {
|
||||||
|
return childPosition == 0;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是最下边的item,以recyclerview的方向做参考
|
||||||
|
*
|
||||||
|
* @param childPosition
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isBottomEdge(int childPosition) {
|
||||||
|
LayoutManager layoutManager = getLayoutManager();
|
||||||
|
if (layoutManager instanceof GridLayoutManager) {
|
||||||
|
GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
|
||||||
|
GridLayoutManager.SpanSizeLookup spanSizeLookUp = gridLayoutManager.getSpanSizeLookup();
|
||||||
|
int itemCount = gridLayoutManager.getItemCount();
|
||||||
|
int childSpanCount = 0;
|
||||||
|
int totalSpanCount = gridLayoutManager.getSpanCount();
|
||||||
|
for (int i = 0; i <= childPosition; i++) {
|
||||||
|
childSpanCount += spanSizeLookUp.getSpanSize(i);
|
||||||
|
}
|
||||||
|
if (isVertical()) {
|
||||||
|
//最后一行item的个数
|
||||||
|
int lastRowCount = itemCount % totalSpanCount;
|
||||||
|
if (lastRowCount == 0) {
|
||||||
|
lastRowCount = gridLayoutManager.getSpanCount();
|
||||||
|
}
|
||||||
|
if (childSpanCount > itemCount - lastRowCount) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (childSpanCount % totalSpanCount == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (layoutManager instanceof LinearLayoutManager) {
|
||||||
|
if (isVertical()) {
|
||||||
|
return childPosition == getLayoutManager().getItemCount() - 1;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public interface PressBackListenner {
|
||||||
|
void hasPressback(TvRecyclerView tvRecyclerViewer);
|
||||||
|
}
|
||||||
|
public void setOnPressBackListener(PressBackListenner listener) {
|
||||||
|
this.mPressbackLister = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -4,9 +4,11 @@
|
|||||||
android:layout_height="100dp"
|
android:layout_height="100dp"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:padding="5dp"
|
android:padding="5dp"
|
||||||
|
android:clipChildren="false"
|
||||||
android:descendantFocusability="beforeDescendants">
|
android:descendantFocusability="beforeDescendants">
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/item_bg"
|
android:id="@+id/item_bg"
|
||||||
|
android:clipChildren="false"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@@ -22,13 +24,14 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="10dp"
|
android:paddingStart="10dp"
|
||||||
android:paddingEnd="10dp"
|
android:paddingEnd="10dp"
|
||||||
|
android:includeFontPadding="false"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:marqueeRepeatLimit="marquee_forever"
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
android:ellipsize="marquee"
|
android:ellipsize="marquee"
|
||||||
android:textSize="13dp"
|
android:textSize="11sp"
|
||||||
android:layout_marginVertical="5dp"
|
android:layout_marginVertical="2dp"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:textColor="@color/item_text_color"
|
android:textColor="@color/item_text_color"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
tools:ignore="MissingDefaultResource">
|
tools:ignore="MissingDefaultResource">
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/item_bg"
|
android:id="@+id/item_bg"
|
||||||
|
android:clipChildren="false"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@
|
|||||||
android:paddingEnd="6dp"
|
android:paddingEnd="6dp"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:includeFontPadding="false"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:marqueeRepeatLimit="marquee_forever"
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
android:ellipsize="marquee"
|
android:ellipsize="marquee"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
android:layout_width="93dp"
|
android:layout_width="93dp"
|
||||||
android:layout_height="98dp"
|
android:layout_height="98dp"
|
||||||
android:id="@+id/item_bg"
|
android:id="@+id/item_bg"
|
||||||
|
android:clipChildren="false"
|
||||||
android:background="@drawable/app_info_bg"
|
android:background="@drawable/app_info_bg"
|
||||||
android:descendantFocusability="beforeDescendants"
|
android:descendantFocusability="beforeDescendants"
|
||||||
android:focusable="true">
|
android:focusable="true">
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
android:background="@drawable/bg">
|
android:background="@drawable/bg">
|
||||||
|
|
||||||
|
|
||||||
<com.ik.mboxlauncher.view.CustomRecyclerView
|
<com.ik.mboxlauncher.view.TvRecyclerView
|
||||||
android:id="@+id/grid_coustom_apps"
|
android:id="@+id/grid_coustom_apps"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|||||||
@@ -98,13 +98,13 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
<com.ik.mboxlauncher.view.AdMultiView
|
<com.ik.mboxlauncher.view.HomeMultiView
|
||||||
android:id="@+id/layout_miracastreceive"
|
android:id="@+id/layout_miracastreceive"
|
||||||
android:layout_width="285dp"
|
android:layout_width="285dp"
|
||||||
android:layout_height="117dp"
|
android:layout_height="117dp"
|
||||||
android:layout_marginStart="64dp"
|
android:layout_marginStart="64dp"
|
||||||
android:layout_marginTop="302dp"
|
android:layout_marginTop="302dp"
|
||||||
app:adMultiViewImage="@drawable/img_miracastreceive"
|
app:multiViewImage="@drawable/img_miracastreceive"
|
||||||
android:focusableInTouchMode="true"
|
android:focusableInTouchMode="true"
|
||||||
android:descendantFocusability="beforeDescendants"
|
android:descendantFocusability="beforeDescendants"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -4,9 +4,11 @@
|
|||||||
android:layout_height="99dp"
|
android:layout_height="99dp"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:clipChildren="false"
|
||||||
android:focusableInTouchMode="true">
|
android:focusableInTouchMode="true">
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/item_bg"
|
android:id="@+id/item_bg"
|
||||||
|
android:clipChildren="false"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@@ -22,12 +24,13 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="7dp"
|
android:paddingStart="7dp"
|
||||||
android:paddingEnd="7dp"
|
android:paddingEnd="7dp"
|
||||||
|
android:includeFontPadding="false"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:marqueeRepeatLimit="marquee_forever"
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
android:ellipsize="marquee"
|
android:ellipsize="marquee"
|
||||||
android:textSize="11sp"
|
android:textSize="13sp"
|
||||||
android:layout_marginVertical="2dp"
|
android:layout_marginVertical="2dp"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:textColor="@color/item_text_color"
|
android:textColor="@color/item_text_color"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
tools:ignore="MissingDefaultResource">
|
tools:ignore="MissingDefaultResource">
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/item_bg"
|
android:id="@+id/item_bg"
|
||||||
|
android:clipChildren="false"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@
|
|||||||
android:marqueeRepeatLimit="marquee_forever"
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
android:ellipsize="marquee"
|
android:ellipsize="marquee"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
|
android:includeFontPadding="false"
|
||||||
android:layout_marginVertical="10dp"
|
android:layout_marginVertical="10dp"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:textColor="@color/item_text_color"
|
android:textColor="@color/item_text_color"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
android:layout_height="110dp"
|
android:layout_height="110dp"
|
||||||
android:id="@+id/item_bg"
|
android:id="@+id/item_bg"
|
||||||
android:background="@drawable/app_info_bg"
|
android:background="@drawable/app_info_bg"
|
||||||
|
android:clipChildren="false"
|
||||||
android:descendantFocusability="beforeDescendants"
|
android:descendantFocusability="beforeDescendants"
|
||||||
android:focusable="true">
|
android:focusable="true">
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/app_info_add_bg">
|
android:background="@color/app_info_add_bg">
|
||||||
<com.ik.mboxlauncher.view.CustomRecyclerView
|
<com.ik.mboxlauncher.view.TvRecyclerView
|
||||||
android:id="@+id/grid_coustom_apps"
|
android:id="@+id/grid_coustom_apps"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|||||||
@@ -98,13 +98,13 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
<com.ik.mboxlauncher.view.AdMultiView
|
<com.ik.mboxlauncher.view.HomeMultiView
|
||||||
android:id="@+id/layout_miracastreceive"
|
android:id="@+id/layout_miracastreceive"
|
||||||
android:layout_width="321dp"
|
android:layout_width="321dp"
|
||||||
android:layout_height="131dp"
|
android:layout_height="131dp"
|
||||||
android:layout_marginStart="72dp"
|
android:layout_marginStart="72dp"
|
||||||
android:layout_marginTop="339dp"
|
android:layout_marginTop="339dp"
|
||||||
app:adMultiViewImage="@drawable/img_miracastreceive"
|
app:multiViewImage="@drawable/img_miracastreceive"
|
||||||
android:focusableInTouchMode="true"
|
android:focusableInTouchMode="true"
|
||||||
android:descendantFocusability="beforeDescendants"
|
android:descendantFocusability="beforeDescendants"
|
||||||
/>
|
/>
|
||||||
@@ -117,7 +117,7 @@
|
|||||||
android:layout_marginTop="339dp"
|
android:layout_marginTop="339dp"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:focusableInTouchMode="true"
|
android:focusableInTouchMode="true"
|
||||||
app:adMultiViewImage="@drawable/img_chrome"
|
app:multiViewImage="@drawable/img_chrome"
|
||||||
android:descendantFocusability="beforeDescendants"
|
android:descendantFocusability="beforeDescendants"
|
||||||
/>
|
/>
|
||||||
<com.ik.mboxlauncher.view.HomeMultiView
|
<com.ik.mboxlauncher.view.HomeMultiView
|
||||||
|
|||||||
@@ -4,9 +4,11 @@
|
|||||||
android:layout_height="132dp"
|
android:layout_height="132dp"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:clipChildren="false"
|
||||||
android:focusableInTouchMode="true">
|
android:focusableInTouchMode="true">
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/item_bg"
|
android:id="@+id/item_bg"
|
||||||
|
android:clipChildren="false"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@@ -22,6 +24,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="10dp"
|
android:paddingStart="10dp"
|
||||||
android:paddingEnd="10dp"
|
android:paddingEnd="10dp"
|
||||||
|
android:includeFontPadding="false"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
tools:ignore="MissingDefaultResource">
|
tools:ignore="MissingDefaultResource">
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/item_bg"
|
android:id="@+id/item_bg"
|
||||||
|
android:clipChildren="false"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@
|
|||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
|
android:includeFontPadding="false"
|
||||||
android:marqueeRepeatLimit="marquee_forever"
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
android:ellipsize="marquee"
|
android:ellipsize="marquee"
|
||||||
android:textSize="21sp"
|
android:textSize="21sp"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
android:layout_height="147dp"
|
android:layout_height="147dp"
|
||||||
android:id="@+id/item_bg"
|
android:id="@+id/item_bg"
|
||||||
android:background="@drawable/app_info_bg"
|
android:background="@drawable/app_info_bg"
|
||||||
|
android:clipChildren="false"
|
||||||
android:descendantFocusability="beforeDescendants"
|
android:descendantFocusability="beforeDescendants"
|
||||||
android:focusable="true">
|
android:focusable="true">
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/app_info_add_bg">
|
android:background="@color/app_info_add_bg">
|
||||||
<com.ik.mboxlauncher.view.CustomRecyclerView
|
<com.ik.mboxlauncher.view.TvRecyclerView
|
||||||
android:id="@+id/grid_coustom_apps"
|
android:id="@+id/grid_coustom_apps"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|||||||
@@ -98,13 +98,13 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
<com.ik.mboxlauncher.view.AdMultiView
|
<com.ik.mboxlauncher.view.HomeMultiView
|
||||||
android:id="@+id/layout_miracastreceive"
|
android:id="@+id/layout_miracastreceive"
|
||||||
android:layout_width="428dp"
|
android:layout_width="428dp"
|
||||||
android:layout_height="175dp"
|
android:layout_height="175dp"
|
||||||
android:layout_marginStart="96dp"
|
android:layout_marginStart="96dp"
|
||||||
android:layout_marginTop="453dp"
|
android:layout_marginTop="453dp"
|
||||||
app:adMultiViewImage="@drawable/img_miracastreceive"
|
app:multiViewImage="@drawable/img_miracastreceive"
|
||||||
android:focusableInTouchMode="true"
|
android:focusableInTouchMode="true"
|
||||||
android:descendantFocusability="beforeDescendants"
|
android:descendantFocusability="beforeDescendants"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:background="@color/bg"
|
android:background="@color/bg"
|
||||||
tools:context=".ui.SplashscreenActivity"
|
tools:context=".ui.Launcher"
|
||||||
tools:ignore="MergeRootFrame">
|
tools:ignore="MergeRootFrame">
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
35
app/src/main/res/layout/ad_multi_layout.xml
Normal file
35
app/src/main/res/layout/ad_multi_layout.xml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/layout_rect_group"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:ignore="MissingDefaultResource">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/multi_inside"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
>
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/img_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_centerInParent="true"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tx_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="53dp"
|
||||||
|
android:background="@drawable/item_text_bg"
|
||||||
|
android:textSize="15sp"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingTop="12dp"
|
||||||
|
android:paddingBottom="19dp"
|
||||||
|
android:gravity="left"
|
||||||
|
android:textColor="@color/btn_text_color"/>
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/ad_root"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
</RelativeLayout>
|
||||||
|
</RelativeLayout>
|
||||||
@@ -4,9 +4,11 @@
|
|||||||
android:layout_height="150dp"
|
android:layout_height="150dp"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:padding="5dp"
|
android:padding="5dp"
|
||||||
|
android:clipChildren="false"
|
||||||
android:descendantFocusability="beforeDescendants">
|
android:descendantFocusability="beforeDescendants">
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/item_bg"
|
android:id="@+id/item_bg"
|
||||||
|
android:clipChildren="false"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@@ -22,13 +24,14 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="10dp"
|
android:paddingStart="10dp"
|
||||||
android:paddingEnd="10dp"
|
android:paddingEnd="10dp"
|
||||||
|
android:includeFontPadding="false"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:marqueeRepeatLimit="marquee_forever"
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
android:ellipsize="marquee"
|
android:ellipsize="marquee"
|
||||||
android:textSize="18sp"
|
android:textSize="15sp"
|
||||||
android:layout_marginVertical="5dp"
|
android:layout_marginVertical="3dp"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:textColor="@color/item_text_color"
|
android:textColor="@color/item_text_color"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
android:id="@+id/item_bg"
|
android:id="@+id/item_bg"
|
||||||
android:layout_margin="5dp"
|
android:layout_margin="5dp"
|
||||||
android:descendantFocusability="beforeDescendants"
|
android:descendantFocusability="beforeDescendants"
|
||||||
|
android:clipChildren="false"
|
||||||
android:focusable="true">
|
android:focusable="true">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
@@ -24,6 +25,6 @@
|
|||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:textColor="@color/btn_text_color"
|
android:textColor="@color/btn_text_color"
|
||||||
android:textSize="20dp"/>
|
android:textSize="20sp"/>
|
||||||
|
|
||||||
</com.ik.mboxlauncher.view.MyRelativeLayout>
|
</com.ik.mboxlauncher.view.MyRelativeLayout>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
android:background="@drawable/bg">
|
android:background="@drawable/bg">
|
||||||
|
|
||||||
|
|
||||||
<com.ik.mboxlauncher.view.CustomRecyclerView
|
<com.ik.mboxlauncher.view.TvRecyclerView
|
||||||
android:id="@+id/grid_coustom_apps"
|
android:id="@+id/grid_coustom_apps"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|||||||
@@ -97,13 +97,13 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
<com.ik.mboxlauncher.view.AdMultiView
|
<com.ik.mboxlauncher.view.HomeMultiView
|
||||||
android:id="@+id/layout_miracastreceive"
|
android:id="@+id/layout_miracastreceive"
|
||||||
android:layout_width="321dp"
|
android:layout_width="321dp"
|
||||||
android:layout_height="131dp"
|
android:layout_height="131dp"
|
||||||
android:layout_marginStart="72dp"
|
android:layout_marginStart="72dp"
|
||||||
android:layout_marginTop="339dp"
|
android:layout_marginTop="339dp"
|
||||||
app:adMultiViewImage="@drawable/img_miracastreceive"
|
app:multiViewImage="@drawable/img_miracastreceive"
|
||||||
android:focusableInTouchMode="true"
|
android:focusableInTouchMode="true"
|
||||||
android:descendantFocusability="beforeDescendants"
|
android:descendantFocusability="beforeDescendants"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
<declare-styleable name="MultiView">
|
<declare-styleable name="MultiView">
|
||||||
<attr name="multiViewTitle" format="reference"/>
|
<attr name="multiViewTitle" format="reference"/>
|
||||||
<attr name="multiViewImage" format="reference"/>
|
<attr name="multiViewImage" format="reference"/>
|
||||||
@@ -12,4 +12,16 @@
|
|||||||
<attr name="adMultiViewTitle" format="reference"/>
|
<attr name="adMultiViewTitle" format="reference"/>
|
||||||
<attr name="adMultiViewImage" format="reference"/>
|
<attr name="adMultiViewImage" format="reference"/>
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
<declare-styleable name="TvRecyclerView">
|
||||||
|
<attr name="android:orientation" tools:ignore="ResourceName"/>
|
||||||
|
<attr name="tv_layoutManager" format="string"/>
|
||||||
|
<attr name="tv_numColumns" format="integer"/>
|
||||||
|
<attr name="tv_numRows" format="integer"/>
|
||||||
|
|
||||||
|
<attr name="tv_selectedItemCentered" format="boolean" />
|
||||||
|
<attr name="tv_loadMoreBeforehandCount" format="integer" />
|
||||||
|
<attr name="tv_selectedItemOffsetStart" format="dimension" />
|
||||||
|
<attr name="tv_selectedItemOffsetEnd" format="dimension" />
|
||||||
|
|
||||||
|
</declare-styleable>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
103
mylibrary/src/main/java/com/android/SharePreUtils.java
Normal file
103
mylibrary/src/main/java/com/android/SharePreUtils.java
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package com.android;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.android.util.GsonUtil;
|
||||||
|
import com.android.util.LogUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SharePreUtils {
|
||||||
|
public static final String SHARERE_NAME="upload_ads_droid";
|
||||||
|
private static SharePreUtils mInstance;
|
||||||
|
private static List<Map<String, Object>> dataList;//处理一对多的关系 key为AdSourceId value 为任务类型值
|
||||||
|
private static SharedPreferences.Editor editor;
|
||||||
|
|
||||||
|
private static SharedPreferences sharedPreferences;
|
||||||
|
public SharePreUtils(Context context) {
|
||||||
|
sharedPreferences=context.getSharedPreferences(SHARERE_NAME,Context.MODE_PRIVATE);
|
||||||
|
editor=sharedPreferences.edit();
|
||||||
|
dataList=getDataList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized static SharePreUtils getInstance(Context context){
|
||||||
|
if(mInstance==null){
|
||||||
|
mInstance=new SharePreUtils(context);
|
||||||
|
}
|
||||||
|
return mInstance;
|
||||||
|
}
|
||||||
|
public synchronized static List<Map<String, Object>> getDataList(){
|
||||||
|
if(dataList==null){
|
||||||
|
String adsHasUpload = sharedPreferences.getString("ads_has_upload", "");
|
||||||
|
if(!TextUtils.isEmpty(adsHasUpload)){
|
||||||
|
List<Map<String, Object>> mapList = GsonUtil.GsonToListMaps(adsHasUpload);
|
||||||
|
dataList=mapList;
|
||||||
|
}else{
|
||||||
|
dataList=new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized static void addRelation(String key, Object value) {
|
||||||
|
if(dataList!=null){
|
||||||
|
Map<String, Object> record = new HashMap<>();
|
||||||
|
record.put("relation_key", key);
|
||||||
|
record.put("relation_value", value);
|
||||||
|
dataList.add(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean filterByKeyValue(String key, Object value) {
|
||||||
|
List<Map<String, Object>> filtered = new ArrayList<>();
|
||||||
|
if(dataList!=null){
|
||||||
|
for (Map<String, Object> record : dataList) {
|
||||||
|
if (key.equals(record.get("relation_key")) &&(value == null ? record.get("relation_value") == null :value.equals(record.get("relation_value")))) {
|
||||||
|
filtered.add(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LogUtils.loge("filterByKeyValue() size"+filtered.size()+"dataList() size"+dataList.size());
|
||||||
|
return filtered.size()==1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized static void savePreference(){
|
||||||
|
if(dataList!=null&&dataList.size()>=0){
|
||||||
|
String commitJson = GsonUtil.GsonString(dataList);
|
||||||
|
editor.putString("ads_has_upload",commitJson).apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeKeyFromAllMaps(String keyToRemove) {
|
||||||
|
if (dataList == null || keyToRemove == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> current=new ArrayList<>();
|
||||||
|
// 遍历列表中的每个Map
|
||||||
|
for (Map<String, Object> map : dataList) {
|
||||||
|
if (map != null) {
|
||||||
|
// 使用remove方法删除指定键
|
||||||
|
if(!map.containsValue(keyToRemove)){
|
||||||
|
current.add(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataList=current;
|
||||||
|
//LogUtils.loge("removeKeyFromAllMaps current()"+current.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void resetDataList(){
|
||||||
|
String adsHasUpload = sharedPreferences.getString("ads_has_upload", "");
|
||||||
|
if(!TextUtils.isEmpty(adsHasUpload)&& GsonUtil.isJson(adsHasUpload)){
|
||||||
|
List<Map<String, Object>> mapList = GsonUtil.GsonToListMaps(adsHasUpload);
|
||||||
|
dataList=mapList;
|
||||||
|
}else{
|
||||||
|
dataList=new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,4 +27,8 @@ public interface ServerApi {
|
|||||||
@POST(ServerInterface.POST_LAUNCHER_ADS)
|
@POST(ServerInterface.POST_LAUNCHER_ADS)
|
||||||
Call<String> postLauncherAds(@Body RequestBody requestBody);
|
Call<String> postLauncherAds(@Body RequestBody requestBody);
|
||||||
|
|
||||||
|
@Headers({"Content-type:application/json;charset=UTF-8"})
|
||||||
|
@POST(ServerInterface.POST_DOWNLOAD_ADS)
|
||||||
|
Call<String> postDownLoadAds(@Body RequestBody requestBody);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public class ServerInterface {
|
|||||||
/**上传事件信息*/
|
/**上传事件信息*/
|
||||||
public static final String POST_EVENTINFO_DEVICE="/app-api/third/launcher/ad/play/callback";
|
public static final String POST_EVENTINFO_DEVICE="/app-api/third/launcher/ad/play/callback";
|
||||||
|
|
||||||
|
public static final String POST_DOWNLOAD_ADS="/app-api/launcher/ad/cb";
|
||||||
|
|
||||||
private static final boolean USER_DEBUG=false;
|
private static final boolean USER_DEBUG=false;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package com.android.api.biz;
|
|||||||
import com.android.api.biz.OnBaseListener;
|
import com.android.api.biz.OnBaseListener;
|
||||||
import com.android.database.lib.RecordEventBean;
|
import com.android.database.lib.RecordEventBean;
|
||||||
import com.android.nebulasdk.bean.EventDataInfo;
|
import com.android.nebulasdk.bean.EventDataInfo;
|
||||||
|
import com.android.nebulasdk.bean.UploadADBean;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -19,8 +20,8 @@ public interface Biz {
|
|||||||
void postLauncherAds(Map<String ,String > map, OnBaseListener listener);
|
void postLauncherAds(Map<String ,String > map, OnBaseListener listener);
|
||||||
//记录设备事件的接口
|
//记录设备事件的接口
|
||||||
void postEventData(List<EventDataInfo> recordEventBeans, OnBaseListener listener);
|
void postEventData(List<EventDataInfo> recordEventBeans, OnBaseListener listener);
|
||||||
|
//上传各个广告位下载状态
|
||||||
|
void postDownloadAd(UploadADBean uploadADBean, OnBaseListener listener);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.android.api.biz.bizimpl;
|
|||||||
|
|
||||||
import com.android.api.biz.Biz;
|
import com.android.api.biz.Biz;
|
||||||
import com.android.nebulasdk.bean.EventDataInfo;
|
import com.android.nebulasdk.bean.EventDataInfo;
|
||||||
|
import com.android.nebulasdk.bean.UploadADBean;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.android.api.ServerApi;
|
import com.android.api.ServerApi;
|
||||||
import com.android.api.biz.BaseBiz;
|
import com.android.api.biz.BaseBiz;
|
||||||
@@ -110,5 +111,38 @@ public class BizImpl extends BaseBiz implements Biz {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postDownloadAd(UploadADBean uploadADBean, OnBaseListener listener) {
|
||||||
|
RequestBody requestBody = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), GsonUtil.GsonString(uploadADBean));
|
||||||
|
getStringRetrofit().create(ServerApi.class).postDownLoadAds(requestBody).enqueue(new Callback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<String> call, Response<String> response) {
|
||||||
|
if(call != null){
|
||||||
|
if (response.body() != null) {
|
||||||
|
LogUtils.loge("postLauncherAds response==>" + GsonUtil.GsonString(response.body()));
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
listener.onResponse(response.body());
|
||||||
|
} else {
|
||||||
|
listener.onFailure(response.message(), response.raw().code());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
listener.onFailure("The server is busy, please try again later", response.raw().code());
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
LogUtils.loge("postDownloadAd Biz>>>>>>>>>>>>>>>>>>call == null<<<<<<<<<<<<<<<<<<");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<String> call, Throwable t) {
|
||||||
|
if (call.isExecuted()) {
|
||||||
|
call.cancel();
|
||||||
|
}
|
||||||
|
LogUtils.loge("recoedDeviceEvent Biz服务器未响应请求失败==>" + GsonUtil.GsonString(t.getMessage()));
|
||||||
|
listener.onFailure("The server is busy, please try again later", 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.android.util.GsonUtil;
|
|||||||
import com.android.util.LogUtils;
|
import com.android.util.LogUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DownLoadManeger {
|
public class DownLoadManeger {
|
||||||
@@ -132,9 +133,23 @@ public class DownLoadManeger {
|
|||||||
for (DownLoadTaskBean downLoadTaskBean:list) {
|
for (DownLoadTaskBean downLoadTaskBean:list) {
|
||||||
if(!TextUtils.isEmpty(downLoadTaskBean.getUrl())&&!TextUtils.isEmpty(downLoadTaskBean.getFileName())&&!TextUtils.isEmpty(downLoadTaskBean.getPath())){
|
if(!TextUtils.isEmpty(downLoadTaskBean.getUrl())&&!TextUtils.isEmpty(downLoadTaskBean.getFileName())&&!TextUtils.isEmpty(downLoadTaskBean.getPath())){
|
||||||
File file = new File(downLoadTaskBean.getPath()+downLoadTaskBean.getFileName()+"-tmp");
|
File file = new File(downLoadTaskBean.getPath()+downLoadTaskBean.getFileName()+"-tmp");
|
||||||
if(file.exists()&&downLoadTaskBean.getCurrentProgress()==file.length()&&file.length()<=downLoadTaskBean.getTotal()){
|
if(file.exists()&&downLoadTaskBean.getCurrentProgress()==file.length()&&file.length()<=downLoadTaskBean.getTotal()){
|
||||||
TaskQueue.getInstance().remove(downLoadTaskBean);
|
TaskQueue.getInstance().remove(downLoadTaskBean);
|
||||||
TaskQueue.getInstance().add(new DownLoadTaskThread(downLoadTaskBean, observer));
|
TaskQueue.getInstance().add(new DownLoadTaskThread(downLoadTaskBean, observer));
|
||||||
|
}else if(downLoadTaskBean.getTaskType()==1){//apk 下载完成未安装断电重新启动下载任务 因为需要安装apk
|
||||||
|
File apkFile = new File(downLoadTaskBean.getPath()+downLoadTaskBean.getFileName());
|
||||||
|
if(apkFile.exists()&&apkFile.length()==downLoadTaskBean.getTotal()&&downLoadTaskBean.getCurrentProgress()<downLoadTaskBean.getTotal()){
|
||||||
|
TaskQueue.getInstance().remove(downLoadTaskBean);
|
||||||
|
TaskQueue.getInstance().add(new DownLoadTaskThread(downLoadTaskBean, observer));
|
||||||
|
}
|
||||||
|
}else if(downLoadTaskBean.getTaskType()==0){//图片文件下载完成 删除downloadtaskbean表数据脏数据
|
||||||
|
File imgFile = new File(downLoadTaskBean.getPath()+downLoadTaskBean.getFileName());
|
||||||
|
if(imgFile.exists()&&imgFile.length()==downLoadTaskBean.getTotal()){
|
||||||
|
DaoManager.getInstance().delete(DownLoadTaskBean.class,downLoadTaskBean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!file.exists()&&downLoadTaskBean.getCurrentProgress()==0){
|
||||||
|
LogUtils.loge("power down but downloadstaskbean table remain task");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -274,4 +289,9 @@ public class DownLoadManeger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public boolean checkTaskQueueClear(){
|
||||||
|
LogUtils.loge("checkTaskQueueClear() size="+TaskQueue.getInstance().getAllTask().size());
|
||||||
|
return TaskQueue.getInstance().size()==0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ public class DownLoadTaskThread implements Runnable {
|
|||||||
|
|
||||||
File dataFile = new File(bean.getPath(), bean.getFileName());
|
File dataFile = new File(bean.getPath(), bean.getFileName());
|
||||||
if(dataFile.exists()&&dataFile.length()==bean.getTotal()){ //判断该文件已下载无需再下载
|
if(dataFile.exists()&&dataFile.length()==bean.getTotal()){ //判断该文件已下载无需再下载
|
||||||
|
LogUtils.loge("dont need download "+bean.getFileName());
|
||||||
observer.onFinish(bean, bean.getTaskId(), dataFile.length());
|
observer.onFinish(bean, bean.getTaskId(), dataFile.length());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -63,9 +64,9 @@ public class DownLoadTaskThread implements Runnable {
|
|||||||
if(currentTotal==bean.getTotal()){
|
if(currentTotal==bean.getTotal()){
|
||||||
File targFile = new File(bean.getPath(), bean.getFileName());
|
File targFile = new File(bean.getPath(), bean.getFileName());
|
||||||
file.renameTo(targFile);//重命名
|
file.renameTo(targFile);//重命名
|
||||||
file.delete();//删除临时文件
|
Thread.sleep(3000);
|
||||||
Thread.sleep(5000);
|
|
||||||
observer.onFinish(bean, bean.getTaskId(), currentTotal);
|
observer.onFinish(bean, bean.getTaskId(), currentTotal);
|
||||||
|
file.delete();//删除临时文件
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//设置下载位置
|
//设置下载位置
|
||||||
@@ -114,10 +115,10 @@ public class DownLoadTaskThread implements Runnable {
|
|||||||
LogUtils.loge("download Exception===>sleeping before");
|
LogUtils.loge("download Exception===>sleeping before");
|
||||||
File targFile = new File(bean.getPath(), bean.getFileName());
|
File targFile = new File(bean.getPath(), bean.getFileName());
|
||||||
file.renameTo(targFile);//重命名
|
file.renameTo(targFile);//重命名
|
||||||
file.delete();//删除临时文件
|
Thread.sleep(3000);
|
||||||
Thread.sleep(5000);
|
|
||||||
LogUtils.loge("download Exception===>sleeping after");
|
LogUtils.loge("download Exception===>sleeping after");
|
||||||
observer.onFinish(bean, bean.getTaskId(), currentTotal);
|
observer.onFinish(bean, bean.getTaskId(), currentTotal);
|
||||||
|
file.delete();//删除临时文件
|
||||||
}else {
|
}else {
|
||||||
LogUtils.loge("下载失败");
|
LogUtils.loge("下载失败");
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
@@ -128,6 +129,15 @@ public class DownLoadTaskThread implements Runnable {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
LogUtils.loge("download Exception===>"+e.getMessage());
|
LogUtils.loge("download Exception===>"+e.getMessage());
|
||||||
|
// TODO: 2025/12/17 异常检验-tmp是否存在,不存在再建一个0KB临时空文件可保证 文件以后一定能下载下来
|
||||||
|
File file = new File(bean.getPath(), bean.getFileName()+"-tmp");
|
||||||
|
if(!file.exists()){
|
||||||
|
try {
|
||||||
|
file.createNewFile();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
LogUtils.loge("exception happen before file create,must create tmp file");
|
||||||
|
}
|
||||||
|
}
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
observer.onError(bean, bean.getTaskId(), e.getMessage());
|
observer.onError(bean, bean.getTaskId(), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import android.content.Context;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.android.SharePreUtils;
|
||||||
import com.android.database.AdsInfoBeanDao;
|
import com.android.database.AdsInfoBeanDao;
|
||||||
import com.android.database.DaoManager;
|
import com.android.database.DaoManager;
|
||||||
import com.android.database.lib.AdsInfoBean;
|
import com.android.database.lib.AdsInfoBean;
|
||||||
|
import com.android.database.lib.AppBean;
|
||||||
import com.android.database.lib.DownLoadTaskBean;
|
import com.android.database.lib.DownLoadTaskBean;
|
||||||
import com.android.database.lib.NetShortAppBean;
|
import com.android.database.lib.NetShortAppBean;
|
||||||
import com.android.database.lib.ShortAppBean;
|
import com.android.database.lib.ShortAppBean;
|
||||||
@@ -14,10 +16,12 @@ import com.android.download.DownLoadManeger;
|
|||||||
import com.android.eventbaus.EventBusUtils;
|
import com.android.eventbaus.EventBusUtils;
|
||||||
import com.android.eventbaus.MessageEvent;
|
import com.android.eventbaus.MessageEvent;
|
||||||
import com.android.nebulasdk.bean.ADInfo;
|
import com.android.nebulasdk.bean.ADInfo;
|
||||||
|
import com.android.nebulasdk.bean.UploadADBean;
|
||||||
import com.android.util.FileUtil;
|
import com.android.util.FileUtil;
|
||||||
import com.android.util.GsonUtil;
|
import com.android.util.GsonUtil;
|
||||||
import com.android.util.LogUtils;
|
import com.android.util.LogUtils;
|
||||||
import com.android.util.PakageInstallUtil;
|
import com.android.util.PakageInstallUtil;
|
||||||
|
import com.android.util.SharedPreferencesUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -89,6 +93,7 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
if(adsInfoBean.getId()==12){ //删除收藏数据
|
if(adsInfoBean.getId()==12){ //删除收藏数据
|
||||||
|
configUtilSaveNetEmptyApp();
|
||||||
DaoManager.getInstance().delete(AdsInfoBean.class,adsInfoBean);
|
DaoManager.getInstance().delete(AdsInfoBean.class,adsInfoBean);
|
||||||
DaoManager.getInstance().deleteAll(NetShortAppBean.class);
|
DaoManager.getInstance().deleteAll(NetShortAppBean.class);
|
||||||
List<NetShortAppBean> netShortAppBeanList = DaoManager.getInstance().queryList(NetShortAppBean.class);
|
List<NetShortAppBean> netShortAppBeanList = DaoManager.getInstance().queryList(NetShortAppBean.class);
|
||||||
@@ -115,18 +120,20 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
// if(adsInfoBean.getAdId()==aDInfo.getAdId()){ //是同一个任务,根据版本号更新新资源
|
// if(adsInfoBean.getAdId()==aDInfo.getAdId()){ //是同一个任务,根据版本号更新新资源
|
||||||
LogUtils.loge("aDInfo.getAdVersion()|adsInfoBean.getAdVersion():"+aDInfo.getAdVersion()+"|"+adsInfoBean.getAdVersion());
|
LogUtils.loge("aDInfo.getAdVersion()|adsInfoBean.getAdVersion():"+aDInfo.getAdVersion()+"|"+adsInfoBean.getAdVersion());
|
||||||
if(Long.valueOf(aDInfo.getAdVersion())!=adsInfoBean.getAdVersion()){ //更新新资源
|
if(Long.valueOf(aDInfo.getAdVersion())!=adsInfoBean.getAdVersion()){ //更新新资源
|
||||||
|
SharePreUtils.removeKeyFromAllMaps(String.valueOf(adsInfoBean.getAdResourceId()));
|
||||||
LogUtils.loge("广告位"+adsInfoBean.getId()+"已存在,是同一个任务同步资源,需要删除缓存文件:"+GsonUtil.GsonString(adsInfoBean));//先删除旧任务的缓存文件,再更新数据
|
LogUtils.loge("广告位"+adsInfoBean.getId()+"已存在,是同一个任务同步资源,需要删除缓存文件:"+GsonUtil.GsonString(adsInfoBean));//先删除旧任务的缓存文件,再更新数据
|
||||||
String dbLocalFilePath=adsInfoBean.getLocalFilePath();
|
String dbLocalFilePath=adsInfoBean.getLocalFilePath();
|
||||||
if(!TextUtils.isEmpty(dbLocalFilePath)) {
|
if(!TextUtils.isEmpty(dbLocalFilePath)) {
|
||||||
int lastIndex = dbLocalFilePath.lastIndexOf("/");
|
int lastIndex = dbLocalFilePath.lastIndexOf("/");
|
||||||
String fileName=lastIndex==-1?dbLocalFilePath:dbLocalFilePath.substring(lastIndex+1);
|
String fileName=lastIndex==-1?dbLocalFilePath:dbLocalFilePath.substring(lastIndex+1);
|
||||||
if(!aDInfo.getAdUri().contains(fileName)){
|
if(TextUtils.isEmpty(aDInfo.getAdUri())||!aDInfo.getAdUri().contains(fileName)){
|
||||||
File oldfile = new File(dbLocalFilePath);
|
File oldfile = new File(dbLocalFilePath);
|
||||||
List<AdsInfoBean> adSInfoBeanList =DaoManager.getInstance().queryByKeyList(AdsInfoBean.class,"localFilePath",dbLocalFilePath);
|
List<AdsInfoBean> adSInfoBeanList =DaoManager.getInstance().queryByKeyList(AdsInfoBean.class,"localFilePath",dbLocalFilePath);
|
||||||
if (oldfile.exists()&& adSInfoBeanList.size()==1) {
|
if (oldfile.exists()&& adSInfoBeanList.size()==1) {
|
||||||
oldfile.delete();
|
oldfile.delete();
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
|
//todo SharePreUtils.addRelation(String.valueOf(aDInfo.getAdResourceId()),String.valueOf(0));
|
||||||
LogUtils.loge("广告位仅换apk不换图 fresh apk not fresh img,dont delete img but download");
|
LogUtils.loge("广告位仅换apk不换图 fresh apk not fresh img,dont delete img but download");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,7 +158,9 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
if(aDInfo.getState()!=null) {
|
if(aDInfo.getState()!=null) {
|
||||||
adsInfoBean.setState(aDInfo.getState());
|
adsInfoBean.setState(aDInfo.getState());
|
||||||
}
|
}
|
||||||
|
if(adsInfoBean.getId()==12){
|
||||||
|
configUtilSaveNetEmptyApp();//任务更新必须移除 隔离收藏夹记录
|
||||||
|
}
|
||||||
if(aDInfo.getState()==0){ //任务已关闭,需要删除数据
|
if(aDInfo.getState()==0){ //任务已关闭,需要删除数据
|
||||||
LogUtils.loge(aDInfo.getId()+"任务已关闭,暂不删除本地缓存");
|
LogUtils.loge(aDInfo.getId()+"任务已关闭,暂不删除本地缓存");
|
||||||
adsInfoBean.setState(0);
|
adsInfoBean.setState(0);
|
||||||
@@ -177,6 +186,7 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
DaoManager.getInstance().update(AdsInfoBean.class,adsInfoBean);
|
DaoManager.getInstance().update(AdsInfoBean.class,adsInfoBean);
|
||||||
|
SharePreUtils.savePreference();
|
||||||
analysisResInfo(aDInfo,adsInfoBean);
|
analysisResInfo(aDInfo,adsInfoBean);
|
||||||
}else {
|
}else {
|
||||||
LogUtils.loge(aDInfo.getId()+"广告任务已存在");
|
LogUtils.loge(aDInfo.getId()+"广告任务已存在");
|
||||||
@@ -191,7 +201,7 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
// }
|
// }
|
||||||
if(aDInfo.getId()==12){ //删除收藏数据
|
if(aDInfo.getId()==12){ //删除收藏数据
|
||||||
LogUtils.loge(aDInfo.getId()+"任务已关闭,删除本地缓存");
|
LogUtils.loge(aDInfo.getId()+"任务已关闭,删除本地缓存");
|
||||||
DaoManager.getInstance().delete(AdsInfoBean.class,adsInfoBean);
|
//DaoManager.getInstance().delete(AdsInfoBean.class,adsInfoBean);
|
||||||
DaoManager.getInstance().deleteAll(NetShortAppBean.class);
|
DaoManager.getInstance().deleteAll(NetShortAppBean.class);
|
||||||
List<NetShortAppBean> netShortAppBeanList = DaoManager.getInstance().queryList(NetShortAppBean.class);
|
List<NetShortAppBean> netShortAppBeanList = DaoManager.getInstance().queryList(NetShortAppBean.class);
|
||||||
if(netShortAppBeanList==null){
|
if(netShortAppBeanList==null){
|
||||||
@@ -205,7 +215,9 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
//打开任务
|
//打开任务
|
||||||
adsInfoBean.setState(1); //任务已存在只需要改变数据,不需要重新下载
|
adsInfoBean.setState(1); //任务已存在只需要改变数据,不需要重新下载
|
||||||
DaoManager.getInstance().update(AdsInfoBean.class,adsInfoBean);
|
DaoManager.getInstance().update(AdsInfoBean.class,adsInfoBean);
|
||||||
|
if(adsInfoBean.getId()==12){
|
||||||
|
analysisResInfo(aDInfo,adsInfoBean);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// if(aDInfo.getState()==0){ //任务已关闭,需要删除数据
|
// if(aDInfo.getState()==0){ //任务已关闭,需要删除数据
|
||||||
// LogUtils.loge("任务已关闭,删除本地缓存"+adsInfoBean.getLocalFilePath());
|
// LogUtils.loge("任务已关闭,删除本地缓存"+adsInfoBean.getLocalFilePath());
|
||||||
@@ -278,7 +290,16 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
EventBusUtils.postMsg(new MessageEvent(MessageEvent.ACTION_UPADATE_DATA_SOURCE));
|
EventBusUtils.postMsg(new MessageEvent(MessageEvent.ACTION_UPADATE_DATA_SOURCE));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private void configUtilSaveNetEmptyApp() {
|
||||||
|
String sharePrefrencesString = SharedPreferencesUtil.getSharePrefrencesString(mContext, SharedPreferencesUtil.CONFIG_NET_DEFEND_BOOKMARK_APP);
|
||||||
|
List<AppBean> saveList=new ArrayList<>();
|
||||||
|
if(TextUtils.isEmpty(sharePrefrencesString)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String saveConfig = GsonUtil.GsonString(saveList);
|
||||||
|
SharedPreferencesUtil.setSharePrefrencesString(mContext,SharedPreferencesUtil.CONFIG_NET_DEFEND_BOOKMARK_APP,saveConfig);
|
||||||
|
|
||||||
|
}
|
||||||
/***
|
/***
|
||||||
* 根据id来查询广告展位信息
|
* 根据id来查询广告展位信息
|
||||||
*/
|
*/
|
||||||
@@ -335,7 +356,7 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
|
|
||||||
}else {
|
}else {
|
||||||
LogUtils.loge("app已安装");
|
LogUtils.loge("app已安装");
|
||||||
|
SharePreUtils.addRelation(String.valueOf(adinfo.getAdResourceId()),String.valueOf(3));
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
LogUtils.loge("没有app任务");
|
LogUtils.loge("没有app任务");
|
||||||
@@ -343,9 +364,9 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
|
|
||||||
LogUtils.loge("analysisResInfo AdType===>"+adinfo.getAdType());
|
LogUtils.loge("analysisResInfo AdType===>"+adinfo.getAdType());
|
||||||
if(ADTYPE_VIDEO.equals(adinfo.getAdType())){
|
if(ADTYPE_VIDEO.equals(adinfo.getAdType())){
|
||||||
if(adinfo.getAdUri()!=null&&adinfo.getAdSize()!=null) {
|
// if(adinfo.getAdUri()!=null&&adinfo.getAdSize()!=null) {
|
||||||
addDownloadTask(adsInfoBean, adinfo.getAdUri(), 0, adinfo.getAdSize());
|
// addDownloadTask(adsInfoBean, adinfo.getAdUri(), 0, adinfo.getAdSize());
|
||||||
}
|
// }
|
||||||
}else if(ADTYPE_FAV.equals(adinfo.getAdType())){
|
}else if(ADTYPE_FAV.equals(adinfo.getAdType())){
|
||||||
if( adinfo.getInfo()!=null){
|
if( adinfo.getInfo()!=null){
|
||||||
String[] packageArray =adinfo.getInfo().split(",");
|
String[] packageArray =adinfo.getInfo().split(",");
|
||||||
@@ -396,17 +417,28 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
LogUtils.loge("onFinish filePath==>" + bean.getTaskType()+"||"+appInstallPath);
|
LogUtils.loge("onFinish filePath==>" + bean.getTaskType()+"||"+appInstallPath);
|
||||||
if(bean.getTaskType()==1){
|
if(bean.getTaskType()==1){
|
||||||
boolean flag = PakageInstallUtil.silentInstall(mContext, appInstallPath);
|
boolean flag = PakageInstallUtil.silentInstall(mContext, appInstallPath);
|
||||||
|
List<AdsInfoBean> list = DaoManager.getInstance().queryByKeyList(AdsInfoBean.class, "appUrl", bean.getUrl());
|
||||||
|
AdsInfoBean adsInfoBean=null;
|
||||||
|
if(list!=null&&list.size()>0){
|
||||||
|
adsInfoBean=list.get(0);
|
||||||
|
}else {
|
||||||
|
LogUtils.loge("onFinish: adsInfoBean table no apk url data");
|
||||||
|
}
|
||||||
|
AdsInfoBean finalAdsInfoBean = adsInfoBean;
|
||||||
handler.postDelayed(new Runnable() {
|
handler.postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (flag) {
|
if (flag&&finalAdsInfoBean!=null&&PakageInstallUtil.checkAppInstall(mContext, finalAdsInfoBean.getInfo())) {
|
||||||
FileUtil.deleteFile(appInstallPath); //安装成功后删除文件
|
if(PakageInstallUtil.checkAppInstall(mContext, finalAdsInfoBean.getInfo(), (int) finalAdsInfoBean.getAppVersion())){
|
||||||
|
//升级apk 不删apk文件 交给clearApkFileByPowerDown 去删除文件
|
||||||
|
FileUtil.deleteFile(appInstallPath); //安装成功后删除文件
|
||||||
|
}
|
||||||
LogUtils.loge("executeAppInstall==>" + flag + "||" + appInstallPath);
|
LogUtils.loge("executeAppInstall==>" + flag + "||" + appInstallPath);
|
||||||
}
|
}
|
||||||
EventBusUtils.postMsg(new MessageEvent(MessageEvent.ACTION_UPADATE_DATA_SOURCE));
|
EventBusUtils.postMsg(new MessageEvent(MessageEvent.ACTION_UPADATE_DATA_SOURCE));
|
||||||
}
|
}
|
||||||
},1000*5);
|
},1000*5);
|
||||||
|
// EventBusUtils.postMsg(new MessageEvent(MessageEvent.ACTION_UPADATE_DATA_SOURCE));
|
||||||
}else{
|
}else{
|
||||||
EventBusUtils.postMsg(new MessageEvent(MessageEvent.ACTION_UPADATE_DATA_SOURCE));
|
EventBusUtils.postMsg(new MessageEvent(MessageEvent.ACTION_UPADATE_DATA_SOURCE));
|
||||||
}
|
}
|
||||||
@@ -454,7 +486,117 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
|||||||
DownLoadManeger.getInstance().updateDownloadTaskBeanTable();
|
DownLoadManeger.getInstance().updateDownloadTaskBeanTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearApkFileByPowerDown(){
|
||||||
|
List<DownLoadTaskBean> list = DaoManager.getInstance().queryList(DownLoadTaskBean.class);
|
||||||
|
if(list==null||list.size()==0){
|
||||||
|
String apkDir = FileUtil.getBakPath(mContext, 1);
|
||||||
|
File apkFile = new File(apkDir);
|
||||||
|
if(apkFile.exists()){
|
||||||
|
File[] files = apkFile.listFiles();
|
||||||
|
for (int i = 0; i < files.length; i++) {
|
||||||
|
boolean isApk = files[i].getAbsolutePath().endsWith("apk");
|
||||||
|
if(isApk){
|
||||||
|
String apkFileName = files[i].getName();
|
||||||
|
int apkFileContainIndex=-1;
|
||||||
|
List<AdsInfoBean> adsInfoBeanList = DaoManager.getInstance().queryList(AdsInfoBean.class);
|
||||||
|
for (int j = 0; j < adsInfoBeanList.size(); j++) {
|
||||||
|
if(!TextUtils.isEmpty(adsInfoBeanList.get(j).getAppUrl())&&adsInfoBeanList.get(j).getAppUrl().contains(apkFileName)){
|
||||||
|
apkFileContainIndex=j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(apkFileContainIndex==-1){
|
||||||
|
files[i].delete();
|
||||||
|
LogUtils.loge("apk data rm need delete app");
|
||||||
|
}else {
|
||||||
|
AdsInfoBean adsInfoBean = adsInfoBeanList.get(apkFileContainIndex);
|
||||||
|
if(!(PakageInstallUtil.checkAppInstall(mContext,adsInfoBean.getInfo()))||PakageInstallUtil.checkAppUpdate(mContext,adsInfoBean.getInfo(),(int) adsInfoBean.getAppVersion())){ //需要跟新app
|
||||||
|
LogUtils.loge("need reinstall app");
|
||||||
|
addDownloadTask(adsInfoBean,adsInfoBean.getAppUrl(),1,adsInfoBean.getAppSize());
|
||||||
|
}else {
|
||||||
|
LogUtils.loge("need delete app");
|
||||||
|
files[i].delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void hasDownloadButLostFile(AdsInfoBean adsInfoBean,String url, int taskType,long fileSize){
|
||||||
|
addDownloadTask(adsInfoBean,url,taskType,fileSize);
|
||||||
|
}
|
||||||
|
public boolean checkTaskQueueClear(){
|
||||||
|
return DownLoadManeger.getInstance().checkTaskQueueClear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<UploadADBean.RecordsBean> getUploadAds(){
|
||||||
|
List<AdsInfoBean> adsInfoBeanList = DaoManager.getInstance().queryByKeyList(AdsInfoBean.class, "state", "1");
|
||||||
|
ArrayList<UploadADBean.RecordsBean> uploadAdList=new ArrayList<>();
|
||||||
|
for (int i = 0; i < adsInfoBeanList.size(); i++) {
|
||||||
|
AdsInfoBean adsInfoBean = adsInfoBeanList.get(i);
|
||||||
|
String appUrl=adsInfoBean.getAppUrl();
|
||||||
|
if(!TextUtils.isEmpty(adsInfoBean.getAppUrl())){
|
||||||
|
// int lastIndex = appUrl.lastIndexOf("/");
|
||||||
|
// String fileName=lastIndex==-1?appUrl:appUrl.substring(lastIndex+1);
|
||||||
|
// String filePath = FileUtil.getBakPath(mContext,1)+"/"+fileName;
|
||||||
|
// String tmpFilePath = FileUtil.getBakPath(mContext, 1) + "/" + fileName + "-tmp";
|
||||||
|
// File tmpFile=new File(tmpFilePath);
|
||||||
|
// File file =new File(filePath);
|
||||||
|
if((PakageInstallUtil.checkAppInstall(mContext,adsInfoBean.getInfo()))&& !PakageInstallUtil.checkAppUpdate(mContext,adsInfoBean.getInfo(),(int) adsInfoBean.getAppVersion())) {
|
||||||
|
if (!SharePreUtils.filterByKeyValue(String.valueOf(adsInfoBean.getAdResourceId()), String.valueOf(2))) {
|
||||||
|
SharePreUtils.addRelation(String.valueOf(adsInfoBean.getAdResourceId()), String.valueOf(2));
|
||||||
|
UploadADBean.RecordsBean recordsBean = new UploadADBean.RecordsBean();
|
||||||
|
recordsBean.setAdResourceId(adsInfoBean.getAdResourceId());
|
||||||
|
if (SharePreUtils.filterByKeyValue(String.valueOf(adsInfoBean.getAdResourceId()), String.valueOf(3))) {//考虑到3为app已安装 analysisResInfo
|
||||||
|
recordsBean.setType(3);
|
||||||
|
} else {
|
||||||
|
recordsBean.setType(2);
|
||||||
|
}
|
||||||
|
uploadAdList.add(recordsBean);
|
||||||
|
}
|
||||||
|
LogUtils.loge("==============resid" + adsInfoBean.getAdResourceId());
|
||||||
|
}
|
||||||
|
// }else if(file.exists()||(tmpFile.exists()&&tmpFile.length()==adsInfoBean.getAppSize())){
|
||||||
|
// if(!SharePreUtils.filterByKeyValue(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(1))){
|
||||||
|
// SharePreUtils.addRelation(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(1));
|
||||||
|
// UploadADBean.RecordsBean recordsBean = new UploadADBean.RecordsBean();
|
||||||
|
// recordsBean.setAdResourceId(adsInfoBean.getAdResourceId());
|
||||||
|
// recordsBean.setType(1);
|
||||||
|
// uploadAdList.add(recordsBean);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
if(!TextUtils.isEmpty(adsInfoBean.getLocalFilePath())){
|
||||||
|
File file = new File(adsInfoBean.getLocalFilePath());
|
||||||
|
File tmpFile=new File(adsInfoBean.getLocalFilePath()+"-tmp");
|
||||||
|
if(file.exists()||(tmpFile.exists()&&tmpFile.length()==adsInfoBean.getAdSize())){
|
||||||
|
if(ADTYPE_IMAGE.equalsIgnoreCase(adsInfoBean.getAdType())){
|
||||||
|
if(!SharePreUtils.filterByKeyValue(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(0))){
|
||||||
|
SharePreUtils.addRelation(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(0));
|
||||||
|
UploadADBean.RecordsBean recordsBean = new UploadADBean.RecordsBean();
|
||||||
|
recordsBean.setAdResourceId(adsInfoBean.getAdResourceId());
|
||||||
|
recordsBean.setType(0);
|
||||||
|
uploadAdList.add(recordsBean);
|
||||||
|
}
|
||||||
|
}else if(ADTYPE_VIDEO.equalsIgnoreCase(adsInfoBean.getAdType())){
|
||||||
|
if(!SharePreUtils.filterByKeyValue(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(1))){
|
||||||
|
SharePreUtils.addRelation(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(1));
|
||||||
|
UploadADBean.RecordsBean recordsBean = new UploadADBean.RecordsBean();
|
||||||
|
recordsBean.setAdResourceId(adsInfoBean.getAdResourceId());
|
||||||
|
recordsBean.setType(1);
|
||||||
|
uploadAdList.add(recordsBean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LogUtils.loge("==============resid"+adsInfoBean.getAdResourceId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(uploadAdList.size()>0){
|
||||||
|
LogUtils.loge(GsonUtil.GsonString(uploadAdList));
|
||||||
|
}
|
||||||
|
return uploadAdList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,23 @@ import android.content.Intent;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.android.SharePreUtils;
|
||||||
import com.android.database.DaoManager;
|
import com.android.database.DaoManager;
|
||||||
import com.android.database.lib.AdsInfoBean;
|
import com.android.database.lib.AdsInfoBean;
|
||||||
import com.android.database.lib.AppBean;
|
import com.android.database.lib.AppBean;
|
||||||
|
import com.android.database.lib.DownLoadTaskBean;
|
||||||
import com.android.database.lib.LocalAppBean;
|
import com.android.database.lib.LocalAppBean;
|
||||||
import com.android.database.lib.MusicAppBean;
|
import com.android.database.lib.MusicAppBean;
|
||||||
import com.android.database.lib.NetShortAppBean;
|
import com.android.database.lib.NetShortAppBean;
|
||||||
import com.android.database.lib.RecommendAppBean;
|
import com.android.database.lib.RecommendAppBean;
|
||||||
import com.android.database.lib.ShortAppBean;
|
import com.android.database.lib.ShortAppBean;
|
||||||
import com.android.database.lib.VideoAppBean;
|
import com.android.database.lib.VideoAppBean;
|
||||||
|
import com.android.eventbaus.EventBusUtils;
|
||||||
|
import com.android.eventbaus.MessageEvent;
|
||||||
import com.android.nebulasdk.bean.FavNaviBean;
|
import com.android.nebulasdk.bean.FavNaviBean;
|
||||||
|
import com.android.util.FileUtil;
|
||||||
import com.android.util.GsonUtil;
|
import com.android.util.GsonUtil;
|
||||||
import com.android.util.LogUtils;
|
import com.android.util.LogUtils;
|
||||||
import com.android.util.PakageInstallUtil;
|
import com.android.util.PakageInstallUtil;
|
||||||
@@ -67,7 +73,8 @@ public class AppManager {
|
|||||||
|
|
||||||
/**主界面推荐数据*/
|
/**主界面推荐数据*/
|
||||||
private Map<Integer, FavNaviBean> favRecommendCacheData = new HashMap<>();
|
private Map<Integer, FavNaviBean> favRecommendCacheData = new HashMap<>();
|
||||||
|
//包名-应用名
|
||||||
|
private Map<String, String> appNameCacheData = new HashMap<>();
|
||||||
|
|
||||||
private AppManager(Context context){
|
private AppManager(Context context){
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
@@ -119,7 +126,7 @@ public class AppManager {
|
|||||||
for (NetShortAppBean netShortAppBean:netShortAppBeanList){
|
for (NetShortAppBean netShortAppBean:netShortAppBeanList){
|
||||||
if(filterAppBeanMap.size()<SHORT_COUNT) {
|
if(filterAppBeanMap.size()<SHORT_COUNT) {
|
||||||
|
|
||||||
if(PakageInstallUtil.checkAppInstall(mContext, netShortAppBean.getPackageName())){
|
if(PakageInstallUtil.checkAppInstall(mContext, netShortAppBean.getPackageName())&&!configUtilContainNetApp(netShortAppBean.getPackageName())){
|
||||||
ShortAppBean shortAppBean = new ShortAppBean();
|
ShortAppBean shortAppBean = new ShortAppBean();
|
||||||
shortAppBean.setCategory(netShortAppBean.getCategory());
|
shortAppBean.setCategory(netShortAppBean.getCategory());
|
||||||
shortAppBean.setAppName(netShortAppBean.getAppName());
|
shortAppBean.setAppName(netShortAppBean.getAppName());
|
||||||
@@ -137,19 +144,40 @@ public class AppManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ShortAppBean shortAppBean:shortAppBeanList){
|
// for (ShortAppBean shortAppBean:shortAppBeanList){
|
||||||
if(filterAppBeanMap.size()<SHORT_COUNT) {
|
// if(filterAppBeanMap.size()<SHORT_COUNT) {
|
||||||
if(PakageInstallUtil.checkAppInstall(mContext, shortAppBean.getPackageName())) {
|
// if(PakageInstallUtil.checkAppInstall(mContext, shortAppBean.getPackageName())) {
|
||||||
shortAppBean.setIndex(netShortStartIndex);
|
// shortAppBean.setIndex(netShortStartIndex);
|
||||||
filterAppBeanMap.put(shortAppBean.getPackageName(), shortAppBean);
|
// filterAppBeanMap.put(shortAppBean.getPackageName(), shortAppBean);
|
||||||
netShortStartIndex++;
|
// netShortStartIndex++;
|
||||||
|
// }
|
||||||
|
// }else {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
String sharePrefrencesString = SharedPreferencesUtil.getSharePrefrencesString(mContext, SharedPreferencesUtil.CONFIG_LOCAL_BOOKMARK_APP);
|
||||||
|
LogUtils.loge("SNFLauncher--->getSharePrefrencesStringList4444 :" + GsonUtil.GsonString(netShortAppBeanList));
|
||||||
|
if(!TextUtils.isEmpty(sharePrefrencesString)){
|
||||||
|
List<AppBean> appBeans = GsonUtil.GsonToList(sharePrefrencesString, AppBean.class);
|
||||||
|
for (AppBean bean : appBeans) {
|
||||||
|
if(filterAppBeanMap.size() < SHORT_COUNT){
|
||||||
|
if (PakageInstallUtil.checkAppInstall(mContext, bean.getPackageName())) {
|
||||||
|
ShortAppBean shortAppBean = new ShortAppBean();
|
||||||
|
shortAppBean.setCategory(bean.getCategory());
|
||||||
|
shortAppBean.setAppName(bean.getAppName());
|
||||||
|
shortAppBean.setId(bean.getId());
|
||||||
|
shortAppBean.setIndex(netShortStartIndex);
|
||||||
|
shortAppBean.setItemType(bean.getItemType());
|
||||||
|
shortAppBean.setPackageName(bean.getPackageName());
|
||||||
|
filterAppBeanMap.put(bean.getPackageName(), shortAppBean);
|
||||||
|
netShortStartIndex++;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}else {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
List<ShortAppBean> newShortAppBeanList = new ArrayList<>();
|
List<ShortAppBean> newShortAppBeanList = new ArrayList<>();
|
||||||
Iterator it= filterAppBeanMap.keySet().iterator();
|
Iterator it= filterAppBeanMap.keySet().iterator();
|
||||||
while (it.hasNext()){
|
while (it.hasNext()){
|
||||||
@@ -252,7 +280,12 @@ public class AppManager {
|
|||||||
shortAppBean.setCategory(CATEGORY_SHORT);
|
shortAppBean.setCategory(CATEGORY_SHORT);
|
||||||
shortAppBean.setItemType(1);
|
shortAppBean.setItemType(1);
|
||||||
DaoManager.getInstance().insert(ShortAppBean.class,shortAppBean);
|
DaoManager.getInstance().insert(ShortAppBean.class,shortAppBean);
|
||||||
|
// 存 本地收藏夹config.xml 与 网络配置隔离收藏夹分开 book compose
|
||||||
|
if(!configUtilContainNetApp(appBean.getPackageName())){
|
||||||
|
configUtilSaveLocalApp(appBean);
|
||||||
|
}else {
|
||||||
|
configUtilRmNetApp(appBean.getPackageName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
@@ -263,8 +296,10 @@ public class AppManager {
|
|||||||
}
|
}
|
||||||
List<NetShortAppBean> netShortAppBeanList = DaoManager.getInstance().queryByKeyList(NetShortAppBean.class,"packageName",appBean.getPackageName());
|
List<NetShortAppBean> netShortAppBeanList = DaoManager.getInstance().queryByKeyList(NetShortAppBean.class,"packageName",appBean.getPackageName());
|
||||||
if(netShortAppBeanList!=null&&netShortAppBeanList.size()>0){
|
if(netShortAppBeanList!=null&&netShortAppBeanList.size()>0){
|
||||||
DaoManager.getInstance().deleteByList(NetShortAppBean.class,netShortAppBeanList);
|
configUtilSaveNetApp(appBean);
|
||||||
|
//DaoManager.getInstance().deleteByList(NetShortAppBean.class,netShortAppBeanList);
|
||||||
}
|
}
|
||||||
|
configUtilRmLocalApp(appBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(appBeanList!=null&&appBeanList.size()>0){
|
// if(appBeanList!=null&&appBeanList.size()>0){
|
||||||
@@ -286,7 +321,89 @@ public class AppManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void configUtilSaveLocalApp(AppBean appBean) {
|
||||||
|
String sharePrefrencesString = SharedPreferencesUtil.getSharePrefrencesString(mContext, SharedPreferencesUtil.CONFIG_LOCAL_BOOKMARK_APP);
|
||||||
|
List<AppBean> saveList=null;
|
||||||
|
if(TextUtils.isEmpty(sharePrefrencesString)){
|
||||||
|
saveList=new ArrayList<>();
|
||||||
|
}
|
||||||
|
if(!TextUtils.isEmpty(sharePrefrencesString)){
|
||||||
|
saveList= GsonUtil.GsonToList(sharePrefrencesString ,AppBean.class);
|
||||||
|
}
|
||||||
|
if(saveList!=null){
|
||||||
|
saveList.add(appBean);
|
||||||
|
String saveConfig = GsonUtil.GsonString(saveList);
|
||||||
|
SharedPreferencesUtil.setSharePrefrencesString(mContext,SharedPreferencesUtil.CONFIG_LOCAL_BOOKMARK_APP,saveConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configUtilRmLocalApp(AppBean appBean) {
|
||||||
|
String sharePrefrencesString = SharedPreferencesUtil.getSharePrefrencesString(mContext, SharedPreferencesUtil.CONFIG_LOCAL_BOOKMARK_APP);
|
||||||
|
if(!TextUtils.isEmpty(sharePrefrencesString)){
|
||||||
|
List<AppBean> appBeans = GsonUtil.GsonToList(sharePrefrencesString, AppBean.class);
|
||||||
|
List<AppBean> appNewBeans=new ArrayList<>();
|
||||||
|
for (AppBean bean :appBeans) {
|
||||||
|
if(!bean.getPackageName().equalsIgnoreCase(appBean.getPackageName())){
|
||||||
|
appNewBeans.add(bean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String saveConfig = GsonUtil.GsonString(appNewBeans);
|
||||||
|
LogUtils.loge("SNFLauncher--->configUtilRmLocalApp() List:"+saveConfig);
|
||||||
|
SharedPreferencesUtil.setSharePrefrencesString(mContext,SharedPreferencesUtil.CONFIG_LOCAL_BOOKMARK_APP,saveConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configUtilSaveNetApp(AppBean appBean) {
|
||||||
|
String sharePrefrencesString = SharedPreferencesUtil.getSharePrefrencesString(mContext, SharedPreferencesUtil.CONFIG_NET_DEFEND_BOOKMARK_APP);
|
||||||
|
List<AppBean> saveList=null;
|
||||||
|
if(TextUtils.isEmpty(sharePrefrencesString)){
|
||||||
|
saveList=new ArrayList<>();
|
||||||
|
}
|
||||||
|
if(!TextUtils.isEmpty(sharePrefrencesString)){
|
||||||
|
saveList= GsonUtil.GsonToList(sharePrefrencesString ,AppBean.class);
|
||||||
|
}
|
||||||
|
if(saveList!=null){
|
||||||
|
saveList.add(appBean);
|
||||||
|
String saveConfig = GsonUtil.GsonString(saveList);
|
||||||
|
SharedPreferencesUtil.setSharePrefrencesString(mContext,SharedPreferencesUtil.CONFIG_NET_DEFEND_BOOKMARK_APP,saveConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configUtilRmNetApp(String name) {
|
||||||
|
String sharePrefrencesString = SharedPreferencesUtil.getSharePrefrencesString(mContext, SharedPreferencesUtil.CONFIG_NET_DEFEND_BOOKMARK_APP);
|
||||||
|
if(!TextUtils.isEmpty(sharePrefrencesString)){
|
||||||
|
List<AppBean> appBeans = GsonUtil.GsonToList(sharePrefrencesString, AppBean.class);
|
||||||
|
List<AppBean> appNewBeans=new ArrayList<>();
|
||||||
|
for (AppBean bean :appBeans) {
|
||||||
|
if(!bean.getPackageName().equalsIgnoreCase(name)){
|
||||||
|
appNewBeans.add(bean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String saveConfig = GsonUtil.GsonString(appNewBeans);
|
||||||
|
LogUtils.loge("SNFLauncher--->configUtilRmNetApp() List:"+saveConfig);
|
||||||
|
SharedPreferencesUtil.setSharePrefrencesString(mContext,SharedPreferencesUtil.CONFIG_NET_DEFEND_BOOKMARK_APP,saveConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean configUtilContainNetApp(String name) {
|
||||||
|
boolean isContain = false;
|
||||||
|
String sharePrefrencesString = SharedPreferencesUtil.getSharePrefrencesString(mContext, SharedPreferencesUtil.CONFIG_NET_DEFEND_BOOKMARK_APP);
|
||||||
|
if(!TextUtils.isEmpty(sharePrefrencesString)){
|
||||||
|
List<AppBean> appBeans = GsonUtil.GsonToList(sharePrefrencesString, AppBean.class);
|
||||||
|
for (AppBean bean :appBeans) {
|
||||||
|
if(bean.getPackageName().equalsIgnoreCase(name)){
|
||||||
|
isContain = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return isContain;
|
||||||
|
}
|
||||||
public void addShortcutInfo(String packageName,String apName,int index){
|
public void addShortcutInfo(String packageName,String apName,int index){
|
||||||
|
|
||||||
List<AppBean> shortcutInfoBeanList =DaoManager.getInstance().queryByKeyList(AppBean.class,"packageName",packageName);
|
List<AppBean> shortcutInfoBeanList =DaoManager.getInstance().queryByKeyList(AppBean.class,"packageName",packageName);
|
||||||
@@ -348,6 +465,7 @@ public class AppManager {
|
|||||||
favNaviBean.setAppName(jsonobjectTmp.getString("name"));
|
favNaviBean.setAppName(jsonobjectTmp.getString("name"));
|
||||||
favRecommendCacheData.put(favNaviBean.getIndex(), favNaviBean);
|
favRecommendCacheData.put(favNaviBean.getIndex(), favNaviBean);
|
||||||
}
|
}
|
||||||
|
appNameCacheData.put(packageName,jsonobjectTmp.getString("name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -367,26 +485,40 @@ public class AppManager {
|
|||||||
// DaoManager.getInstance().update(ShortAppBean.class,tmpapp);
|
// DaoManager.getInstance().update(ShortAppBean.class,tmpapp);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
String sharePrefrencesString = SharedPreferencesUtil.getSharePrefrencesString(mContext, SharedPreferencesUtil.CONFIG_LOCAL_BOOKMARK_APP);
|
||||||
int flag =SharedPreferencesUtil.getSharePrefrencesInteger(mContext,SharedPreferencesUtil.CONFIG_INIOR);
|
int flag =SharedPreferencesUtil.getSharePrefrencesInteger(mContext,SharedPreferencesUtil.CONFIG_INIOR);
|
||||||
if(flag==1){//数据已初始化完成
|
if(flag==1&&!TextUtils.isEmpty(sharePrefrencesString)){//数据已初始化完成
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] shortcutArray =appStr.split(",");
|
String[] shortcutArray =appStr.split(",");
|
||||||
List<ShortAppBean> appBeanList = new ArrayList<>();
|
List<ShortAppBean> appBeanList = new ArrayList<>();
|
||||||
|
List<AppBean> appBeans =new ArrayList<>();
|
||||||
for (int i = 0; i < shortcutArray.length; i++) {
|
for (int i = 0; i < shortcutArray.length; i++) {
|
||||||
String packageName= shortcutArray[i];
|
String packageName= shortcutArray[i];
|
||||||
if(PakageInstallUtil.checkAppInstall(mContext,packageName)) {
|
// if(PakageInstallUtil.checkAppInstall(mContext,packageName)) {
|
||||||
ShortAppBean appBean = new ShortAppBean();
|
ShortAppBean appBean = new ShortAppBean();
|
||||||
|
AppBean bean =new AppBean();
|
||||||
appBean.setPackageName(packageName);
|
appBean.setPackageName(packageName);
|
||||||
|
bean.setPackageName(packageName);
|
||||||
appBean.setIndex(i);
|
appBean.setIndex(i);
|
||||||
|
bean.setIndex(i);
|
||||||
|
bean.setId(5L);
|
||||||
appBean.setItemType(1);
|
appBean.setItemType(1);
|
||||||
|
bean.setItemType(1);
|
||||||
|
bean.setCategory(0);
|
||||||
|
bean.setAppName(appNameCacheData.get(packageName));
|
||||||
|
bean.setSelect(1);
|
||||||
appBeanList.add(appBean);
|
appBeanList.add(appBean);
|
||||||
}
|
appBeans.add(bean);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(appBeans.size()>0){
|
||||||
|
String saveConfig = GsonUtil.GsonString(appBeans);
|
||||||
|
SharedPreferencesUtil.setSharePrefrencesString(mContext,SharedPreferencesUtil.CONFIG_LOCAL_BOOKMARK_APP,saveConfig);
|
||||||
|
}
|
||||||
if(appBeanList.size()>0){
|
if(appBeanList.size()>0){
|
||||||
DaoManager.getInstance().insert(ShortAppBean.class, appBeanList);
|
DaoManager.getInstance().insert(ShortAppBean.class, appBeanList);
|
||||||
SharedPreferencesUtil.setSharePrefrencesInteger(mContext, SharedPreferencesUtil.CONFIG_INIOR, 1);
|
SharedPreferencesUtil.setSharePrefrencesInteger(mContext, SharedPreferencesUtil.CONFIG_INIOR, 1);
|
||||||
@@ -586,12 +718,55 @@ public class AppManager {
|
|||||||
File file = new File(adsInfoBean.getLocalFilePath());
|
File file = new File(adsInfoBean.getLocalFilePath());
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
favNaviBean = new FavNaviBean(index, adsInfoBean.getLocalFilePath(), adsInfoBean.getInfo(), null);
|
favNaviBean = new FavNaviBean(index, adsInfoBean.getLocalFilePath(), adsInfoBean.getInfo(), null);
|
||||||
}else {
|
}else {//考虑下载好图片重启后变回 -tmp文件的情况
|
||||||
|
File tempFile=new File(adsInfoBean.getLocalFilePath()+"-tmp");
|
||||||
|
//对已上报的图片文件 系统丢失文件情况 重新下载
|
||||||
|
if(!tempFile.exists()&& SharePreUtils.filterByKeyValue(String.valueOf(adsInfoBean.getAdResourceId()),String.valueOf(0))){
|
||||||
|
LogUtils.loge("sys lost file which has upload,redownload it but not notify");
|
||||||
|
ADManager.getInstance().hasDownloadButLostFile(adsInfoBean,adsInfoBean.getAdUri(),0,adsInfoBean.getAdSize());
|
||||||
|
}
|
||||||
|
if(tempFile.exists()&&tempFile.length()==adsInfoBean.getAdSize()){
|
||||||
|
tempFile.renameTo(file);
|
||||||
|
tempFile.delete();
|
||||||
|
EventBusUtils.postMsg(new MessageEvent(MessageEvent.ACTION_UPADATE_DATA_SOURCE));
|
||||||
|
LogUtils.loge("下载大小完成但重命名失败同时下载任务已清除图片至始至终未显示处理 sys rename failed bug solved");
|
||||||
|
}
|
||||||
LogUtils.loge(file.getPath()+" is not exit");
|
LogUtils.loge(file.getPath()+" is not exit");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
LogUtils.loge(adsInfoBean.getInfo()+" is not exit");
|
LogUtils.loge(adsInfoBean.getInfo()+" is not exit");//考虑下载好APK重启后变回 -tmp文件的情况 补充clearApkFileByPowerDown 下载任务有脏数据情况下
|
||||||
|
String appUrl = adsInfoBean.getAppUrl();
|
||||||
|
boolean taskTableHasIt=false;
|
||||||
|
List<DownLoadTaskBean> list = DaoManager.getInstance().queryList(DownLoadTaskBean.class);
|
||||||
|
for (int i = 0; i <list.size() ; i++) {
|
||||||
|
if(list.get(i).getUrl().equalsIgnoreCase(appUrl)){
|
||||||
|
taskTableHasIt=true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!TextUtils.isEmpty(appUrl)&&!taskTableHasIt){
|
||||||
|
int lastIndex = appUrl.lastIndexOf("/");
|
||||||
|
String fileName=lastIndex==-1?appUrl:appUrl.substring(lastIndex+1);
|
||||||
|
String filePath = FileUtil.getBakPath(mContext,1)+"/"+fileName;
|
||||||
|
String tmpFilePath = FileUtil.getBakPath(mContext, 1) + "/" + fileName + "-tmp";
|
||||||
|
File tmpFile=new File(tmpFilePath);
|
||||||
|
File file =new File(filePath);
|
||||||
|
if(tmpFile.exists()&&tmpFile.length()==adsInfoBean.getAppSize()){
|
||||||
|
LogUtils.loge(adsInfoBean.getInfo()+" but apk tmpfile is exit");
|
||||||
|
tmpFile.renameTo(file);
|
||||||
|
//tmpFile.delete();
|
||||||
|
if(list!=null&&list.size()>0){
|
||||||
|
boolean flag = PakageInstallUtil.silentInstall(mContext, file.getAbsolutePath());
|
||||||
|
LogUtils.loge("no task and restart sys apk back to tmp install result="+flag);
|
||||||
|
}
|
||||||
|
}else if(file.exists()&&file.length()==adsInfoBean.getAppSize()){
|
||||||
|
if(list!=null&&list.size()>0){
|
||||||
|
boolean flag = PakageInstallUtil.silentInstall(mContext, file.getAbsolutePath());
|
||||||
|
LogUtils.loge("no task and restart sys apk not install result="+flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package com.android.nebulasdk.bean;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UploadADBean {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mac : 9C:00:D3:86:31:DF
|
||||||
|
* cpu : 1747248796593488611d7d3114575b9
|
||||||
|
* records : [{"adId":494,"type":0,"ts":1763450525769},{"adId":494,"type":2,"ts":1763450525769},{"adId":494,"type":0,"ts":1763450925769},{"adId":396,"type":0,"ts":1763450525769}]
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String mac;
|
||||||
|
private String cpu;
|
||||||
|
private List<RecordsBean> records;
|
||||||
|
|
||||||
|
public String getMac() {
|
||||||
|
return mac;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMac(String mac) {
|
||||||
|
this.mac = mac;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCpu() {
|
||||||
|
return cpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCpu(String cpu) {
|
||||||
|
this.cpu = cpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RecordsBean> getRecords() {
|
||||||
|
return records;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRecords(List<RecordsBean> records) {
|
||||||
|
this.records = records;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class RecordsBean {
|
||||||
|
/**
|
||||||
|
* adId : 494
|
||||||
|
* type : 0
|
||||||
|
* ts : 1763450525769
|
||||||
|
*/
|
||||||
|
|
||||||
|
private long adResourceId;
|
||||||
|
private int type;
|
||||||
|
//private long ts;
|
||||||
|
|
||||||
|
public long getAdResourceId() {
|
||||||
|
return adResourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAdResourceId(long adId) {
|
||||||
|
this.adResourceId = adId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(int type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public long getTs() {
|
||||||
|
// return ts;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setTs(long ts) {
|
||||||
|
// this.ts = ts;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,7 +36,7 @@ public class CategoryAppPresenter {
|
|||||||
|
|
||||||
public CategoryAppPresenter(Context context,AppnetCallback appnetCallback) {
|
public CategoryAppPresenter(Context context,AppnetCallback appnetCallback) {
|
||||||
this.mAppnetCallback = appnetCallback;
|
this.mAppnetCallback = appnetCallback;
|
||||||
AppManager.init(context);
|
//AppManager.init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package com.android.nebulasdk.presenter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.MXQConfig;
|
||||||
|
import com.android.api.ServerInterface;
|
||||||
|
import com.android.api.biz.Biz;
|
||||||
|
import com.android.api.biz.OnBaseListener;
|
||||||
|
import com.android.api.biz.bizimpl.BizImpl;
|
||||||
|
import com.android.api.response.EventResponse;
|
||||||
|
import com.android.nebulasdk.bean.ADInfoResponse;
|
||||||
|
import com.android.nebulasdk.bean.UploadADBean;
|
||||||
|
import com.android.nebulasdk.presenter.callback.AppnetCallback;
|
||||||
|
import com.android.util.DeviceUtil;
|
||||||
|
import com.android.util.GsonUtil;
|
||||||
|
import com.android.util.LogUtils;
|
||||||
|
import com.android.util.RKDeviceUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class DownLoadAdPresenter {
|
||||||
|
private Biz biz;
|
||||||
|
private AppnetCallback mAppnetCallback;
|
||||||
|
|
||||||
|
public DownLoadAdPresenter(AppnetCallback mAppnetCallback) {
|
||||||
|
this.mAppnetCallback = mAppnetCallback;
|
||||||
|
biz = new BizImpl(ServerInterface.createHttpUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void postDownLoadAds(Context context,ArrayList<UploadADBean.RecordsBean> recordsBeans){
|
||||||
|
UploadADBean uploadADBean=new UploadADBean();
|
||||||
|
String cpuId ="";
|
||||||
|
if(MXQConfig.ALLWINNER_PLATFORM.equalsIgnoreCase(MXQConfig.getManufacturer())) {
|
||||||
|
cpuId = DeviceUtil.getCpu();
|
||||||
|
}else if(MXQConfig.RK_PLATFORM.equalsIgnoreCase(MXQConfig.getManufacturer())){
|
||||||
|
cpuId = RKDeviceUtil.getCpu();
|
||||||
|
}
|
||||||
|
uploadADBean.setCpu(cpuId);
|
||||||
|
uploadADBean.setMac(DeviceUtil.getEthernetMac());
|
||||||
|
uploadADBean.setRecords(recordsBeans);
|
||||||
|
biz.postDownloadAd(uploadADBean, new OnBaseListener() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(String result) {
|
||||||
|
LogUtils.loge(GsonUtil.GsonString(result));
|
||||||
|
if(GsonUtil.isJson(result)){
|
||||||
|
try {
|
||||||
|
EventResponse eventResponse = GsonUtil.GsonToBean(result, EventResponse.class);
|
||||||
|
if (eventResponse.getCode() == ServerInterface.SUCCESS) {
|
||||||
|
mAppnetCallback.onResult(eventResponse.getData());
|
||||||
|
} else {
|
||||||
|
mAppnetCallback.onViewFailureString(eventResponse.getCode(), eventResponse.getMsg());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
mAppnetCallback.onExceptionFailure("json 解析异常:"+e.getMessage());
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
mAppnetCallback.onServerFailure(0,"获取签到信息,服务器繁忙··");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(String e, int code) {
|
||||||
|
mAppnetCallback.onServerFailure(code,e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ public class IntentUtil {
|
|||||||
intent = context.getPackageManager().getLeanbackLaunchIntentForPackage(packageName);
|
intent = context.getPackageManager().getLeanbackLaunchIntentForPackage(packageName);
|
||||||
}
|
}
|
||||||
if(intent!=null){
|
if(intent!=null){
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}else {
|
}else {
|
||||||
Toast.makeText( context, tipmsg, Toast.LENGTH_SHORT).show();
|
Toast.makeText( context, tipmsg, Toast.LENGTH_SHORT).show();
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class PakageInstallUtil {
|
|||||||
private static final String TAG= "INSTALL";
|
private static final String TAG= "INSTALL";
|
||||||
|
|
||||||
/**检测app是否安装*/
|
/**检测app是否安装*/
|
||||||
public static boolean checkAppUpdate(Context context,String packageName,int versionCode){
|
public static boolean checkAppUpdate(Context context,String packageName,int versionCode){
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packageName,0);
|
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packageName,0);
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ public class SharedPreferencesUtil {
|
|||||||
/**是否要更新app信息到服务器*/
|
/**是否要更新app信息到服务器*/
|
||||||
public static final String CONFIG_INIOR="CONFIG_INIOR";
|
public static final String CONFIG_INIOR="CONFIG_INIOR";
|
||||||
|
|
||||||
|
public static final String CONFIG_LOCAL_BOOKMARK_APP="config_local_bookmark_app";//本地配置 收藏夹
|
||||||
|
public static final String CONFIG_NET_DEFEND_BOOKMARK_APP="config_net_defend_bookmark_app";//网络隔离 收藏夹
|
||||||
|
|
||||||
public static String getSharePrefrencesString(Context context,String key){
|
public static String getSharePrefrencesString(Context context,String key){
|
||||||
SharedPreferences sharedPreferences=context.getSharedPreferences(SHARE_NAME,0);
|
SharedPreferences sharedPreferences=context.getSharedPreferences(SHARE_NAME,0);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user