Skip to content

Commit

Permalink
You can give default text size which renders text nicely on several d…
Browse files Browse the repository at this point in the history
…evices

The right frame can be stay without disappearing
  • Loading branch information
vsahin committed May 9, 2017
1 parent 817c436 commit 7046e95
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public int compare(String f1, String f2) {
.setTextColor(Color.WHITE) // the color of right bar letters
.setBarWidth(24) // the width of right bar in dp
.setBarHeightRatio(1f) // the height of right bar between 0 and 1 according to screen height
.setTextSize(0) // the size of the letters in right bar , default zero handles it nicely , specific values are also ok
.setTextSize(0) // the size of the letters in right bar , default zero handles it nicely , specific values are optional
.setMiddleTextSize(16) // the size of the letter in center circle
.setMiddleLayoutSize(48) // the size of the center circle in dp
.setMiddleBackgroundColor(Color.rgb(67, 67, 67)) // the color of the center circle
Expand All @@ -86,7 +86,7 @@ public int compare(String f1, String f2) {
.setRightStrokeWidth(3) // the width of right bar stroke in dp
.setRightStrokeColor(Color.rgb(204, 204, 204)) // the color of middle circle stroke
.setMinItem(0) // the min amount of item required to show right bar
.setDelayMillis(3000) // the amount of time in ms that closes right bar if there are no interaction
.setDelayMillis(3000) // the amount of time in ms that closes right bar if there are no interaction , if negative it never closes
.build();
*/

Expand All @@ -97,3 +97,6 @@ public int compare(String f1, String f2) {
}

}



Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.lang.reflect.Field;
import java.util.ArrayList;
Expand Down Expand Up @@ -119,7 +118,6 @@ public void execute() {
utils = new VolxUtils(context);

if (!(userRecyclerView.getAdapter() instanceof IVolxAdapter)) {
Toast.makeText(context, "Please implement IVolxAdapter in your own adapter", Toast.LENGTH_SHORT).show();
Log.w("VOLX", "Please implement IVolxAdapter in your own adapter , you need to initialize the adapter before initializing Volx");
return;
}
Expand Down Expand Up @@ -261,14 +259,17 @@ public boolean onTouch(View v, MotionEvent event) {
}

private void removeViewsWithDelay() {
mRecyclerView.postDelayed(Volx.this, delayMillis);
if (delayMillis > 0)
mRecyclerView.postDelayed(Volx.this, delayMillis);
}

public void setViewsVisibility(boolean isShow) {

if (!isShow) {
rightIndicatorLayout.setVisibility(View.GONE);
middleText.setVisibility(View.GONE);
if (delayMillis < 0)
return;
rightIndicatorLayout.setVisibility(View.GONE);
isTouched = false;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public ViewHolder(View v, VolxAdapterFeatures mFeatures) {

charText = new TextView(v.getContext());
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams
(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);//81
charText.setGravity(Gravity.CENTER);
(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
charText.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

if (mFeatures.getTextSize() == 0)
charText.setTextSize(defaultTextSize);
Expand All @@ -54,7 +54,7 @@ public ViewHolder(View v, VolxAdapterFeatures mFeatures) {
public VolxAdapter(List<VolxCharModel> mDataset, VolxUtils utils, VolxAdapterFeatures mFeatures) {
this.mFeatures = mFeatures;
this.mDataset = mDataset;
this.defaultTextSize = (float)(utils.pxToDp(utils.dpToPx(mFeatures.getBarWidth()) - utils.dpToPx(8)))* mFeatures.getScale();
this.defaultTextSize = utils.defaultTextSize(mFeatures.getParamsHeight());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,17 @@ public int pxToDp(int px) {
return Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
}

public void changeDrawableColor(View v , int backgroundColor, int strokeColor, int strokeWidthDp){
GradientDrawable drawable = ((GradientDrawable)v.getBackground());
public float defaultTextSize(int px) {
int maxTextSize = 11;
DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
float textSize = ((float) px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)) - displayMetrics.density + 1;
if (textSize < maxTextSize)
return textSize;
return maxTextSize;
}

public void changeDrawableColor(View v, int backgroundColor, int strokeColor, int strokeWidthDp) {
GradientDrawable drawable = ((GradientDrawable) v.getBackground());
drawable.setColor(backgroundColor);
drawable.setStroke(dpToPx(strokeWidthDp), strokeColor);
}
Expand Down

0 comments on commit 7046e95

Please sign in to comment.