use the theme colors for the fastscroller

refactor-toolbar
Floens 8 years ago
parent 10155cf644
commit 48b71d83d5
  1. 26
      Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java
  2. 45
      Clover/app/src/main/java/org/floens/chan/ui/view/FastScrollerHelper.java
  3. 29
      Clover/app/src/main/res/drawable/recyclerview_fastscroll_thumb_selector.xml
  4. 29
      Clover/app/src/main/res/drawable/recyclerview_fastscroll_track_selector.xml

@ -20,12 +20,9 @@ package org.floens.chan.ui.layout;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.widget.GridLayoutManager;
@ -53,6 +50,7 @@ import org.floens.chan.ui.cell.PostCellInterface;
import org.floens.chan.ui.cell.ThreadStatusCell;
import org.floens.chan.ui.toolbar.Toolbar;
import org.floens.chan.ui.view.FastScroller;
import org.floens.chan.ui.view.FastScrollerHelper;
import org.floens.chan.ui.view.ThumbnailView;
import org.floens.chan.utils.AndroidUtils;
@ -63,7 +61,6 @@ import static org.floens.chan.utils.AndroidUtils.ROBOTO_MEDIUM;
import static org.floens.chan.utils.AndroidUtils.dp;
import static org.floens.chan.utils.AndroidUtils.getAttrColor;
import static org.floens.chan.utils.AndroidUtils.getDimen;
import static org.floens.chan.utils.AndroidUtils.getRes;
/**
* A layout that wraps around a {@link RecyclerView} and a {@link ReplyLayout} to manage showing and replying to posts.
@ -548,26 +545,7 @@ public class ThreadListLayout extends FrameLayout implements ReplyLayout.ReplyLa
}
} else {
if (fastScroller == null) {
Resources resources = getResources();
StateListDrawable verticalThumbDrawable = (StateListDrawable) resources
.getDrawable(R.drawable.recyclerview_fastscroll_thumb_selector);
Drawable verticalTrackDrawable = getRes()
.getDrawable(R.drawable.recyclerview_fastscroll_track_selector);
StateListDrawable horizontalThumbDrawable = (StateListDrawable) resources
.getDrawable(R.drawable.recyclerview_fastscroll_thumb_selector);
Drawable horizontalTrackDrawable = resources
.getDrawable(R.drawable.recyclerview_fastscroll_track_selector);
final int defaultThickness = dp(4);
final int targetWidth = dp(8);
final int minimumRange = dp(50);
final int margin = dp(0);
final int thumbMinLength = dp(23);
fastScroller = new FastScroller(recyclerView,
verticalThumbDrawable, verticalTrackDrawable,
horizontalThumbDrawable, horizontalTrackDrawable,
defaultThickness, minimumRange, margin, thumbMinLength, targetWidth);
fastScroller = FastScrollerHelper.create(recyclerView);
}
}

@ -0,0 +1,45 @@
package org.floens.chan.ui.view;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.StateListDrawable;
import android.support.v7.widget.RecyclerView;
import static org.floens.chan.ui.theme.ThemeHelper.theme;
import static org.floens.chan.utils.AndroidUtils.dp;
/**
* Helper for attaching a FastScroller with the correct theme colors and default values that
* make it look like a normal scrollbar.
*/
public class FastScrollerHelper {
public static FastScroller create(RecyclerView recyclerView) {
StateListDrawable thumb = getThumb();
StateListDrawable track = getTrack();
final int defaultThickness = dp(4);
final int targetWidth = dp(8);
final int minimumRange = dp(50);
final int margin = dp(0);
final int thumbMinLength = dp(23);
return new FastScroller(recyclerView,
thumb, track, thumb, track,
defaultThickness, minimumRange, margin, thumbMinLength, targetWidth);
}
private static StateListDrawable getThumb() {
StateListDrawable list = new StateListDrawable();
list.addState(new int[]{android.R.attr.state_pressed},
new ColorDrawable(theme().accentColor.color));
list.addState(new int[]{}, new ColorDrawable(theme().textSecondary));
return list;
}
private static StateListDrawable getTrack() {
StateListDrawable list = new StateListDrawable();
list.addState(new int[]{android.R.attr.state_pressed},
new ColorDrawable(theme().textHint));
list.addState(new int[]{}, new ColorDrawable(0));
return list;
}
}

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
Clover - 4chan browser https://github.com/Floens/Clover/
Copyright (C) 2014 Floens
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#ff009688" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#5a000000" />
</shape>
</item>
</selector>

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
Clover - 4chan browser https://github.com/Floens/Clover/
Copyright (C) 2014 Floens
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#12000000" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#00000000" />
</shape>
</item>
</selector>
Loading…
Cancel
Save