Skip to content

Commit

Permalink
New support features added. Custom calculation of text size on the vo…
Browse files Browse the repository at this point in the history
…lx-fast-scroll switched to new android autosize text
  • Loading branch information
volsahin committed Oct 8, 2017
1 parent cbeaaf2 commit 01ef149
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
Expand Up @@ -47,8 +47,8 @@ public int compare(String f1, String f2) {
model.add(userModel);
}

parentLayout = (FrameLayout) findViewById(R.id.activity_use);
mRecyclerView = (RecyclerView) findViewById(R.id.rcx);
parentLayout = findViewById(R.id.activity_use);
mRecyclerView = findViewById(R.id.rcx);

mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
Expand Down
Expand Up @@ -25,7 +25,7 @@ public static class ViewHolder extends RecyclerView.ViewHolder {
TextView txt;
public ViewHolder(View v) {
super(v);
txt = (TextView) v.findViewById(R.id.txt);
txt = v.findViewById(R.id.txt);
}
}

Expand All @@ -40,8 +40,7 @@ public UsersOwnAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_main, parent, false);

ViewHolder vh = new ViewHolder(v);
return vh;
return new ViewHolder(v);
}

@Override
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_main.xml
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_use"
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand Down
Expand Up @@ -322,7 +322,7 @@ private void onScreenCreated(int height, ViewTreeObserver.OnGlobalLayoutListener
rightBarParams.height = (int) (height * barHeightRatio);
itemHeight = (int) (height * barHeightRatio - utils.dpToPx(16)) / (charList.size());

mAdapter = new VolxAdapter(charList, utils, new VolxAdapterFeatures(itemHeight, barHeightRatio, barWidth, textSize, textColor, activeColor));
mAdapter = new VolxAdapter(charList, new VolxAdapterFeatures(itemHeight, barHeightRatio, barWidth, textSize, textColor, activeColor));
mRecyclerView.setAdapter(mAdapter);
}

Expand Down
@@ -1,7 +1,10 @@
package com.volcaniccoder.volxfastscroll;

import android.graphics.Color;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -15,12 +18,10 @@ public class VolxAdapter extends RecyclerView.Adapter<VolxAdapter.ViewHolder> {

private List<VolxCharModel> mDataset;
private VolxAdapterFeatures mFeatures;
private float defaultTextSize;

public VolxAdapter(List<VolxCharModel> mDataset, VolxUtils utils, VolxAdapterFeatures mFeatures) {
public VolxAdapter(List<VolxCharModel> mDataset, VolxAdapterFeatures mFeatures) {
this.mFeatures = mFeatures;
this.mDataset = mDataset;
this.defaultTextSize = utils.defaultTextSize(mFeatures.getParamsHeight());
}

@Override
Expand Down Expand Up @@ -77,18 +78,19 @@ public ViewHolder(View v, VolxAdapterFeatures mFeatures) {
(ViewGroup.LayoutParams.MATCH_PARENT, mFeatures.getParamsHeight());
parentParams.setMargins(4, 0, 4, 0);

itemParent = (LinearLayout) v.findViewById(R.id.item_parent);
itemParent = v.findViewById(R.id.item_parent);
itemParent.setBackgroundColor(Color.TRANSPARENT);
itemParent.setLayoutParams(parentParams);

charText = new TextView(v.getContext());
charText = new AppCompatTextView(v.getContext());
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams
(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
(ViewGroup.LayoutParams.MATCH_PARENT, mFeatures.getParamsHeight());
charText.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

if (mFeatures.getTextSize() == Volx.FIT_NICELY)
charText.setTextSize(defaultTextSize);
else
if (mFeatures.getTextSize() == Volx.FIT_NICELY) {
TextViewCompat.setAutoSizeTextTypeWithDefaults(charText, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(charText, 2, 13, 1, TypedValue.COMPLEX_UNIT_SP);
} else
charText.setTextSize(mFeatures.getTextSize());

charText.setTextColor(mFeatures.getTextColor());
Expand Down

0 comments on commit 01ef149

Please sign in to comment.