Skip to content

Commit

Permalink
Fix Direction with input
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza Amuzadeh committed Mar 10, 2019
1 parent fa24c5a commit c5975d6
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 65 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ext {
minSdkVersion = 17
targetSdkVersion = 28
versionCode = 10
versionName = "0.2.5"
versionCode = 11
versionName = "0.2.6"
}

buildscript {
Expand Down
1 change: 1 addition & 0 deletions demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
android:id="@+id/breadcrumbs_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:isRtl="true"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:textColorSelected="@color/colorSelected"
app:textColorUnSelected="@color/colorUnSelected"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class ArrowIconHolder extends ItemHolder<IBreadcrumbItem> {

ArrowIconHolder(View itemView) {
super(itemView);
Drawable normalDrawable = getContext().getResources().getDrawable(R.drawable.ic_chevron_right_black_24dp);
Drawable normalDrawable = getContext().getResources().getDrawable(R.drawable.ic_fiber_manual_record_black_24dp);
Drawable wrapDrawable = DrawableCompat.wrap(normalDrawable);
if (mtextColorUnSelected != -1)
DrawableCompat.setTint(wrapDrawable, mtextColorUnSelected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public class BreadcrumbsView extends FrameLayout {
*/
private int mPopupThemeId = -1;
private int mTextColorSelected = -1;
private int mtextColorUnSelected = -1;
private int mTextColorUnSelected = -1;
private int mTextSizeCustom = -1;
private boolean isRtl = false;

private static final String KEY_SUPER_STATES = BuildConfig.APPLICATION_ID + ".superStates";
private static final String KEY_BREADCRUMBS = BuildConfig.APPLICATION_ID + ".breadcrumbs";
Expand All @@ -51,8 +52,9 @@ public BreadcrumbsView(Context context, AttributeSet attrs, int defStyleAttr) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BreadcrumbsView, defStyleAttr, 0);
mPopupThemeId = a.getResourceId(R.styleable.BreadcrumbsView_popupTheme, -1);
mTextColorSelected = a.getColor(R.styleable.BreadcrumbsView_textColorSelected, -1);
mtextColorUnSelected = a.getColor(R.styleable.BreadcrumbsView_textColorUnSelected, -1);
mTextColorUnSelected = a.getColor(R.styleable.BreadcrumbsView_textColorUnSelected, -1);
mTextSizeCustom = a.getDimensionPixelSize(R.styleable.BreadcrumbsView_textSizeCustom, -1);
isRtl = a.getBoolean(R.styleable.BreadcrumbsView_isRtl, false);
a.recycle();
}

Expand All @@ -70,8 +72,7 @@ private void init() {
mRecyclerView = new RecyclerView(getContext());

// Create Horizontal LinearLayoutManager
LinearLayoutManager layoutManager = new LinearLayoutManager(
getContext(), LinearLayoutManager.HORIZONTAL, ViewUtils.isRtlLayout(getContext()));
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, isRtl);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setOverScrollMode(OVER_SCROLL_NEVER);

Expand All @@ -80,7 +81,7 @@ private void init() {
}
// Init Adapter
if (mAdapter == null) {
mAdapter = new BreadcrumbsAdapter(this, mTextColorSelected, mtextColorUnSelected, mTextSizeCustom);
mAdapter = new BreadcrumbsAdapter(this, mTextColorSelected, mTextColorUnSelected, mTextSizeCustom);
if (mPopupThemeId != -1) {
mAdapter.setPopupThemeId(mPopupThemeId);
}
Expand Down
114 changes: 57 additions & 57 deletions library/src/main/java/moe/feng/common/view/breadcrumbs/ViewUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,70 @@

class ViewUtils {

/**
* Check if the current language is RTL
*
* @param context Context
* @return Result
*/
static boolean isRtlLayout(Context context) {
return context.getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
}
/**
* Check if the current language is RTL
*
* @param context Context
* @return Result
*/
static boolean isRtlLayout(Context context) {
return context.getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
}

/**
* Get color attribute from current theme
*
* @param context Themed context
* @param attr The resource id of color attribute
* @return Result
*/
@ColorInt
static int getColorFromAttr(Context context, @AttrRes int attr) {
TypedArray array = context.getTheme().obtainStyledAttributes(new int[]{attr});
int color = array.getColor(0, Color.TRANSPARENT);
array.recycle();
return color;
}
/**
* Get color attribute from current theme
*
* @param context Themed context
* @param attr The resource id of color attribute
* @return Result
*/
@ColorInt
static int getColorFromAttr(Context context, @AttrRes int attr) {
TypedArray array = context.getTheme().obtainStyledAttributes(new int[]{attr});
int color = array.getColor(0, Color.TRANSPARENT);
array.recycle();
return color;
}

/**
* Measure content width from ListAdapter
*
* @param context Context
* @param listAdapter The adapter that should be measured
* @return Recommend popup window width
*/
static int measureContentWidth(Context context, ListAdapter listAdapter) {
ViewGroup mMeasureParent = null;
int maxWidth = 0;
View itemView = null;
int itemType = 0;
/**
* Measure content width from ListAdapter
*
* @param context Context
* @param listAdapter The adapter that should be measured
* @return Recommend popup window width
*/
static int measureContentWidth(Context context, ListAdapter listAdapter) {
ViewGroup mMeasureParent = null;
int maxWidth = 0;
View itemView = null;
int itemType = 0;

final ListAdapter adapter = listAdapter;
final int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int count = adapter.getCount();
for (int i = 0; i < count; i++) {
final int positionType = adapter.getItemViewType(i);
if (positionType != itemType) {
itemType = positionType;
itemView = null;
}
final ListAdapter adapter = listAdapter;
final int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int count = adapter.getCount();
for (int i = 0; i < count; i++) {
final int positionType = adapter.getItemViewType(i);
if (positionType != itemType) {
itemType = positionType;
itemView = null;
}

if (mMeasureParent == null) {
mMeasureParent = new FrameLayout(context);
}
if (mMeasureParent == null) {
mMeasureParent = new FrameLayout(context);
}

itemView = adapter.getView(i, itemView, mMeasureParent);
itemView.measure(widthMeasureSpec, heightMeasureSpec);
itemView = adapter.getView(i, itemView, mMeasureParent);
itemView.measure(widthMeasureSpec, heightMeasureSpec);

final int itemWidth = itemView.getMeasuredWidth();
final int itemWidth = itemView.getMeasuredWidth();

if (itemWidth > maxWidth) {
maxWidth = itemWidth;
}
}
if (itemWidth > maxWidth) {
maxWidth = itemWidth;
}
}

return maxWidth;
}
return maxWidth;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="14dp"
android:height="14dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M12,12m-8,0a8,8 0,1 1,16 0a8,8 0,1 1,-16 0"
android:fillColor="#010101"/>
</vector>
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<attr name="textColorSelected" format="reference|integer" />
<attr name="textColorUnSelected" format="reference|integer" />
<attr name="textSizeCustom" format="dimension" />
<attr name="isRtl" format="boolean" />
</declare-styleable>

</resources>

0 comments on commit c5975d6

Please sign in to comment.