Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch.andeo.dev.tvplayground;
- import android.graphics.drawable.Drawable;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Looper;
- import android.util.Log;
- import androidx.annotation.NonNull;
- import androidx.leanback.app.GuidedStepSupportFragment;
- import androidx.leanback.widget.GuidanceStylist;
- import androidx.leanback.widget.GuidedAction;
- import androidx.recyclerview.widget.RecyclerView;
- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Method;
- import java.util.List;
- public class SampleStepFragment extends GuidedStepSupportFragment {
- private static final String TAG = "SampleStepFragment";
- @NonNull
- @Override
- public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
- String title = "Title";
- String breadcrumb = "Breadcrumb";
- String description = "Description";
- Drawable icon = getActivity().getDrawable(R.drawable.app_icon_your_company);
- return new GuidanceStylist.Guidance(title, description, breadcrumb, icon);
- }
- @Override
- public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
- addAction(actions, GuidedAction.ACTION_ID_CONTINUE, "Action1");
- addAction(actions, GuidedAction.ACTION_ID_CANCEL, "Action2");
- // Run code delayed on mainThread (any other/better method can/should be used)
- // It's delayed because if focus scroll is disabled, the list will stick to the top of the layout
- new Handler(Looper.getMainLooper()).postDelayed(this::disableFocusScroll, 500);
- }
- private void disableFocusScroll() {
- RecyclerView.LayoutManager layoutManager = SampleStepFragment.this.getGuidedActionsStylist().getActionsGridView().getLayoutManager();
- try {
- Method method = layoutManager.getClass().getMethod("setFocusScrollStrategy", int.class);
- method.invoke(layoutManager, 1 /* FOCUS_SCROLL_ITEM */);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- Log.e(TAG, "disableFocusScroll: ", e);
- }
- }
- private void addAction(List<GuidedAction> actions, long id, String text) {
- actions.add(new GuidedAction.Builder(this.getContext()).title(text).clickAction(id).build());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement