Skip to content

Commit

Permalink
version 2.0.0-BETA-3
Browse files Browse the repository at this point in the history
- add support RTL
  • Loading branch information
raphaelbussa committed Jan 24, 2017
1 parent 1be15f9 commit 2d6cbec
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public void run() {
headerView.setDialogTitle("Choose account");
//headerView.setShowArrow(false);
headerView.setFragmentManager(getFragmentManager());

headerView.setCallback(new HeaderCallback() {

@Override
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/header_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/header_view"
app:hv_add_status_bar_height="true"
app:hv_style="normal"
app:hv_style="compact"
app:hv_theme="light"
app:hv_highlight_color="@color/colorAccent"
app:hv_dialog_title="@string/account"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ buildscript {
buildTools: "25.0.2",
minSdk : 11,
targetSdk : 25,
version : "2.0.0-BETA-2",
version : "2.0.0-BETA-3",
supportLib: "25.1.0"
]
}
Expand Down
131 changes: 91 additions & 40 deletions library/src/main/java/rebus/header/view/HeaderView.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package rebus.header.view;

import android.annotation.SuppressLint;
import android.app.FragmentManager;
import android.content.Context;
import android.content.res.TypedArray;
Expand Down Expand Up @@ -102,6 +103,7 @@ public class HeaderView extends ViewGroup implements ProfileChooserCallback {
@DrawableRes
private int hvAddIconDrawable;
private String hvDialogTitle;
private boolean hvIsRTL;

private SparseArray<Profile> profileSparseArray = new SparseArray<>();
private ArrayList<Item> itemArrayList = new ArrayList<>();
Expand Down Expand Up @@ -535,6 +537,7 @@ private void setupAttributeSet(AttributeSet attrs, int defStyle) {
}

private void setupResources() {
hvIsRTL = getResources().getBoolean(R.bool.is_right_to_left);
statusBarHeight = Utils.getStatusBarHeight(getContext());
hvAvatarDimen = getResources().getDimensionPixelSize(R.dimen.hv_avatar);
hvAvatarMiniDimen = getResources().getDimensionPixelSize(R.dimen.hv_avatar_mini);
Expand Down Expand Up @@ -576,20 +579,22 @@ private void addAvatar() {
addView(avatar, 3, layoutParams);
}

@SuppressLint("RtlHardcoded")
private void addUsername() {
username = new TextView(getContext());
username.setTextColor(hvTextColor);
username.setTypeface(Typeface.DEFAULT_BOLD);
username.setGravity(Gravity.CENTER_VERTICAL);
username.setGravity(Gravity.CENTER_VERTICAL | (hvIsRTL ? Gravity.RIGHT : Gravity.LEFT));
username.setMaxLines(1);
username.setEllipsize(TextUtils.TruncateAt.END);
addView(username, 4);
}

@SuppressLint("RtlHardcoded")
private void addEmail() {
email = new TextView(getContext());
email.setTextColor(hvTextColor);
email.setGravity(Gravity.CENTER_VERTICAL);
email.setGravity(Gravity.CENTER_VERTICAL | (hvIsRTL ? Gravity.RIGHT : Gravity.LEFT));
email.setMaxLines(1);
email.setEllipsize(TextUtils.TruncateAt.END);
addView(email, 5);
Expand Down Expand Up @@ -636,53 +641,99 @@ private void addAvatar3() {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
Log.d(TAG, "onLayout changed [" + changed + "]");
Log.d(TAG, "is_right_to_left [" + getResources().getBoolean(R.bool.is_right_to_left) + "]");
if (!changed) return;
background.layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
if (hvShowGradient) {
gradient.layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
}
selector.layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
avatar.layout(hvMarginDimen,
getDimensionFix(hvMarginDimen),
hvMarginDimen + hvAvatarDimen,
getDimensionFix(hvAvatarDimen + hvMarginDimen));
if (hvStyle == STYLE_NORMAL) {
avatar2.layout(getMeasuredWidth() - hvMarginDimen - hvAvatarMiniDimen,
if (hvIsRTL) {
avatar.layout(getMeasuredWidth() - hvMarginDimen - hvAvatarDimen,
getDimensionFix(hvMarginDimen),
getMeasuredWidth() - hvMarginDimen,
getDimensionFix(hvAvatarMiniDimen + hvMarginDimen));
avatar3.layout(avatar2.getLeft() - hvMarginDimen - hvAvatarMiniDimen,
getDimensionFix(hvAvatarDimen + hvMarginDimen));
if (hvStyle == STYLE_NORMAL) {
avatar2.layout(hvMarginDimen,
getDimensionFix(hvMarginDimen),
hvAvatarMiniDimen + hvMarginDimen,
getDimensionFix(hvAvatarMiniDimen + hvMarginDimen));
avatar3.layout(avatar2.getRight() + hvMarginDimen,
getDimensionFix(hvMarginDimen),
avatar2.getRight() + hvAvatarMiniDimen + hvMarginDimen,
getDimensionFix(hvAvatarMiniDimen + hvMarginDimen));
arrow.layout(0,
getMeasuredHeight() - hvArrowDimen,
hvArrowDimen,
getMeasuredHeight());
username.layout(arrow.getRight(),
avatar.getBottom() + hvMarginDimen,
getMeasuredWidth() - hvMarginDimen,
avatar.getBottom() + hvMarginDimen + hvTextDimen);
email.layout(arrow.getRight(),
username.getBottom(),
getMeasuredWidth() - hvMarginDimen,
username.getBottom() + hvTextDimen);
}
if (hvStyle == STYLE_COMPACT) {
avatar3.layout(0, 0, 0, 0);
avatar2.layout(0, 0, 0, 0);
arrow.layout(0,
getDimensionFix(getMeasuredHeight()) / 2 - hvArrowDimen / 2,
hvArrowDimen,
getDimensionFix(getMeasuredHeight()) / 2 + hvArrowDimen / 2);
username.layout(arrow.getRight(),
getDimensionFix(getMeasuredHeight()) / 2 - hvTextDimen,
avatar.getLeft() - hvMarginDimen,
getDimensionFix(getMeasuredHeight()) / 2);
email.layout(arrow.getRight(),
getDimensionFix(getMeasuredHeight()) / 2,
avatar.getLeft() - hvMarginDimen,
getDimensionFix(getMeasuredHeight()) / 2 + hvTextDimen);
}
} else {
avatar.layout(hvMarginDimen,
getDimensionFix(hvMarginDimen),
avatar2.getLeft() - hvMarginDimen,
getDimensionFix(hvAvatarMiniDimen + hvMarginDimen));
arrow.layout(getMeasuredWidth() - hvArrowDimen,
getMeasuredHeight() - hvArrowDimen,
getMeasuredWidth(),
getMeasuredHeight());
username.layout(hvMarginDimen,
avatar.getBottom() + hvMarginDimen,
arrow.getLeft(),
avatar.getBottom() + hvMarginDimen + hvTextDimen);
email.layout(hvMarginDimen,
username.getBottom(),
arrow.getLeft(),
username.getBottom() + hvTextDimen);
}
if (hvStyle == STYLE_COMPACT) {
avatar3.layout(0, 0, 0, 0);
avatar2.layout(0, 0, 0, 0);
arrow.layout(getMeasuredWidth() - hvArrowDimen,
getDimensionFix(getMeasuredHeight()) / 2 - hvArrowDimen / 2,
getMeasuredWidth(),
getDimensionFix(getMeasuredHeight()) / 2 + hvArrowDimen / 2);
username.layout(avatar.getRight() + hvMarginDimen,
getDimensionFix(getMeasuredHeight()) / 2 - hvTextDimen,
arrow.getLeft(),
getDimensionFix(getMeasuredHeight()) / 2);
email.layout(avatar.getRight() + hvMarginDimen,
getDimensionFix(getMeasuredHeight()) / 2,
arrow.getLeft(),
getDimensionFix(getMeasuredHeight()) / 2 + hvTextDimen);
hvMarginDimen + hvAvatarDimen,
getDimensionFix(hvAvatarDimen + hvMarginDimen));
if (hvStyle == STYLE_NORMAL) {
avatar2.layout(getMeasuredWidth() - hvMarginDimen - hvAvatarMiniDimen,
getDimensionFix(hvMarginDimen),
getMeasuredWidth() - hvMarginDimen,
getDimensionFix(hvAvatarMiniDimen + hvMarginDimen));
avatar3.layout(avatar2.getLeft() - hvMarginDimen - hvAvatarMiniDimen,
getDimensionFix(hvMarginDimen),
avatar2.getLeft() - hvMarginDimen,
getDimensionFix(hvAvatarMiniDimen + hvMarginDimen));
arrow.layout(getMeasuredWidth() - hvArrowDimen,
getMeasuredHeight() - hvArrowDimen,
getMeasuredWidth(),
getMeasuredHeight());
username.layout(hvMarginDimen,
avatar.getBottom() + hvMarginDimen,
arrow.getLeft(),
avatar.getBottom() + hvMarginDimen + hvTextDimen);
email.layout(hvMarginDimen,
username.getBottom(),
arrow.getLeft(),
username.getBottom() + hvTextDimen);
}
if (hvStyle == STYLE_COMPACT) {
avatar3.layout(0, 0, 0, 0);
avatar2.layout(0, 0, 0, 0);
arrow.layout(getMeasuredWidth() - hvArrowDimen,
getDimensionFix(getMeasuredHeight()) / 2 - hvArrowDimen / 2,
getMeasuredWidth(),
getDimensionFix(getMeasuredHeight()) / 2 + hvArrowDimen / 2);
username.layout(avatar.getRight() + hvMarginDimen,
getDimensionFix(getMeasuredHeight()) / 2 - hvTextDimen,
arrow.getLeft(),
getDimensionFix(getMeasuredHeight()) / 2);
email.layout(avatar.getRight() + hvMarginDimen,
getDimensionFix(getMeasuredHeight()) / 2,
arrow.getLeft(),
getDimensionFix(getMeasuredHeight()) / 2 + hvTextDimen);
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion library/src/main/java/rebus/header/view/ProfileChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package rebus.header.view;


import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.util.SparseArray;
Expand All @@ -46,17 +47,20 @@ class ProfileChooser extends Dialog {

private ProfileChooserCallback callback;

@SuppressLint("RtlHardcoded")
ProfileChooser(Context context, SparseArray<Profile> profileSparseArray, ArrayList<Item> items, int accent, boolean showAdd, String titleValue, int icon) {
super(context);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.hw_account_chooser);
boolean hvIsRTL = context.getResources().getBoolean(R.bool.is_right_to_left);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.hw_profile_container);
LinearLayout linearLayout1 = (LinearLayout) findViewById(R.id.hw_action_container);
TextView title = (TextView) findViewById(R.id.hw_dialog_title);
ImageView add = (ImageView) findViewById(R.id.hv_add_profile);
add.setImageResource(icon);
title.setTextColor(Utils.getTextColorPrimary(context));
title.setText(titleValue);
title.setGravity(Gravity.CENTER_VERTICAL | (hvIsRTL ? Gravity.RIGHT : Gravity.LEFT));
add.setVisibility(showAdd ? View.VISIBLE : View.INVISIBLE);
add.setColorFilter(Utils.getTextColorPrimary(context));
add.setBackgroundResource(Utils.selectableItemBackgroundBorderless(context));
Expand Down Expand Up @@ -96,7 +100,7 @@ public void onClick(View v) {
textView.setBackgroundResource(Utils.selectableItemBackground(context));
textView.setPadding(padding, padding / 2, padding, padding / 2);
textView.setTextColor(Utils.getTextColorSecondary(context));
textView.setGravity(Gravity.CENTER_VERTICAL);
textView.setGravity(Gravity.CENTER_VERTICAL | (hvIsRTL ? Gravity.RIGHT : Gravity.LEFT));
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package rebus.header.view;

import android.annotation.SuppressLint;
import android.app.DialogFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class ProfileChooserFragment extends DialogFragment {
private ImageView add;

private ProfileChooserCallback callback;
private boolean hvIsRTL;

public static ProfileChooserFragment newInstance(SparseArray<Profile> profileSparseArray, ArrayList<Item> items, int accent, boolean showAdd, String titleValue, int icon) {
Bundle bundle = new Bundle();
Expand All @@ -75,9 +77,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
linearLayout1 = (LinearLayout) rootView.findViewById(R.id.hw_action_container);
title = (TextView) rootView.findViewById(R.id.hw_dialog_title);
add = (ImageView) rootView.findViewById(R.id.hv_add_profile);
hvIsRTL = getResources().getBoolean(R.bool.is_right_to_left);
return rootView;
}

@SuppressLint("RtlHardcoded")
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Expand All @@ -92,6 +96,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
add.setImageResource(icon);
title.setTextColor(Utils.getTextColorPrimary(getActivity()));
title.setText(titleValue);
title.setGravity(Gravity.CENTER_VERTICAL | (hvIsRTL ? Gravity.RIGHT : Gravity.LEFT));
add.setVisibility(showAdd ? View.VISIBLE : View.INVISIBLE);
add.setColorFilter(Utils.getTextColorPrimary(getActivity()));
add.setBackgroundResource(Utils.selectableItemBackgroundBorderless(getActivity()));
Expand Down Expand Up @@ -134,7 +139,7 @@ public void onClick(View v) {
textView.setBackgroundResource(Utils.selectableItemBackground(getActivity()));
textView.setPadding(padding, padding / 2, padding, padding / 2);
textView.setTextColor(Utils.getTextColorSecondary(getActivity()));
textView.setGravity(Gravity.CENTER_VERTICAL);
textView.setGravity(Gravity.CENTER_VERTICAL | (hvIsRTL ? Gravity.RIGHT : Gravity.LEFT));
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Loading

0 comments on commit 2d6cbec

Please sign in to comment.