1.二级菜单翻页自动获取首个item焦点
This commit is contained in:
@@ -3,9 +3,11 @@ package com.ik.mboxlauncher.ui.fragment;
|
||||
import android.content.Intent;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.database.lib.AppBean;
|
||||
import com.android.eventbaus.MessageEvent;
|
||||
@@ -61,6 +63,7 @@ public class AppsFragment extends CategoryFragment {
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
LogUtils.loge("initData===>AppsFragment");
|
||||
loadAppInfoByCategory(AppManager.CATEGORY_MYAPPS);
|
||||
}
|
||||
|
||||
@@ -88,6 +91,21 @@ public class AppsFragment extends CategoryFragment {
|
||||
// 使用过滤后的列表更新适配器
|
||||
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){
|
||||
// List<AppBean> appBeanList = (List<AppBean>) data;
|
||||
// mMyAppInfoAdapter.addDatas(appBeanList);
|
||||
@@ -102,7 +120,7 @@ public class AppsFragment extends CategoryFragment {
|
||||
public void onResumeFragment(MessageEvent event) {
|
||||
super.onResumeFragment(event);
|
||||
loadAppInfoByCategory(AppManager.CATEGORY_MYAPPS);//重新加载数据
|
||||
|
||||
LogUtils.loge("onResumeFragment===>AppsFragment");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.ik.mboxlauncher.ui.fragment;
|
||||
import android.content.Intent;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.database.lib.AppBean;
|
||||
import com.android.database.lib.LocalAppBean;
|
||||
@@ -69,6 +71,21 @@ public class LocalFragment extends CategoryFragment {
|
||||
appBeanList.add(new LocalAppBean());
|
||||
mLocalAppAdapter.addDatas(appBeanList);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.ik.mboxlauncher.ui.fragment;
|
||||
import android.content.Intent;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.database.lib.AppBean;
|
||||
import com.android.database.lib.MusicAppBean;
|
||||
@@ -67,6 +69,21 @@ public class MusicFragment extends CategoryFragment {
|
||||
appBeanList.add(new MusicAppBean());
|
||||
mMusicAppAdapter.addDatas(appBeanList);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,17 @@ package com.ik.mboxlauncher.ui.fragment;
|
||||
import android.content.Intent;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.database.lib.AppBean;
|
||||
import com.android.database.lib.RecommendAppBean;
|
||||
import com.android.eventbaus.MessageEvent;
|
||||
import com.android.nebulasdk.AppManager;
|
||||
import com.android.util.GsonUtil;
|
||||
import com.android.util.IntentUtil;
|
||||
import com.android.util.LogUtils;
|
||||
import com.ik.mboxlauncher.R;
|
||||
@@ -66,6 +69,22 @@ public class RecommendFragment extends CategoryFragment {
|
||||
appBeanList.add(new RecommendAppBean());
|
||||
mRecommendAppAdapter.addDatas(appBeanList);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.ik.mboxlauncher.ui.fragment;
|
||||
import android.content.Intent;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.database.lib.AppBean;
|
||||
import com.android.database.lib.VideoAppBean;
|
||||
@@ -67,6 +69,22 @@ public class VideoFragment extends CategoryFragment {
|
||||
appBeanList.add(new VideoAppBean());
|
||||
mVideoAppAdapter.addDatas(appBeanList);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user