public static Prefs get(Context context) { if (singleton == null) { synchronized (Prefs.class) { singleton = new Prefs(context); } } return singleton; }
@Override public void onCheckedChanged(CompoundButton compoundButton, boolean showBounds) { prefs.setShowBounds(showBounds); } });
@Override public void run() { onLoadMore(currentPage); } };
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); final Prefs prefs = Prefs.get(this); ViewGroup showBoundsContainer = (ViewGroup) findViewById(R.id.show_bounds); SwitchCompat showBoundsSwitch = (SwitchCompat) showBoundsContainer.findViewById(R.id.the_switch); TextView showBoundsText = (TextView) showBoundsContainer.findViewById(R.id.text); ViewGroup showOffsetsContainer = (ViewGroup) findViewById(R.id.show_offsets); SwitchCompat showOffsetsSwitch = (SwitchCompat) showOffsetsContainer.findViewById(R.id.the_switch); TextView showOffsetsText = (TextView) showOffsetsContainer.findViewById(R.id.text); showBoundsSwitch.setChecked(prefs.getShowBounds()); showOffsetsSwitch.setChecked(prefs.getShowOffsets());
super.onCreate(savedInstanceState); binding = DataBindingUtil.setContentView(this, R.layout.activity_main); prefs = Prefs.get(this); recyclerView.addItemDecoration(new HeaderItemDecoration(gray, betweenPadding)); recyclerView.addItemDecoration(new InsetItemDecoration(gray, betweenPadding)); recyclerView.addItemDecoration(new DebugItemDecoration(this)); recyclerView.setAdapter(groupAdapter); recyclerView.addOnScrollListener(new InfiniteScrollListener(layoutManager) { prefs.registerListener(onSharedPrefChangeListener);
public DebugItemDecoration(Context context) { prefs = Prefs.get(context); leftColor = ContextCompat.getColor(context, R.color.red_200); topColor = ContextCompat.getColor(context, R.color.pink_200); rightColor = ContextCompat.getColor(context, R.color.purple_200); bottomColor = ContextCompat.getColor(context, R.color.indigo_200); }
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { if (!(prefs.getShowBounds() || prefs.getShowOffsets())) return; bottom = child.getBottom() + (int) child.getTranslationY(); if (prefs.getShowBounds()) { paint.setColor(Color.RED); paint.setStyle(Paint.Style.STROKE); if (prefs.getShowOffsets()) { paint.setStyle(Paint.Style.FILL);
@Override public void onCheckedChanged(CompoundButton compoundButton, boolean showOffsets) { prefs.setShowOffsets(showOffsets); } });
@Override protected void onDestroy() { prefs.unregisterListener(onSharedPrefChangeListener); super.onDestroy(); }