Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public MUButton(Context context, AttributeSet attrs) {
// Label
mLabel = attributes.getString(R.styleable.MUButton_android_text);
mLabelColor = attributes.getColor(R.styleable.MUButton_android_textColor, mLabelColor);
// mLabelFontSize = attributes.getDimensionPixelSize(R.styleable.MUButton_android_textSize, (int) mLabelFontSize);
mLabelFontSize = attributes.getDimensionPixelSize(R.styleable.MUButton_android_textSize, (int) mLabelFontSize);
mLabelFontWeight = attributes.getInt(R.styleable.MUButton_android_textStyle, mLabelFontWeight);
mLabelAlignment = attributes.getInt(R.styleable.MUButton_alignment, mLabelAlignment);
mLabelHighLightedColor = attributes.getColor(R.styleable.MUButton_pressed_color, mLabelHighLightedColor);
Expand All @@ -185,6 +185,63 @@ public MUButton(Context context, AttributeSet attrs) {
* @param context the view context
* @param attributes the XML attributes of the super view
*/

public void applyAttributes(Context context, TypedArray attributes) {
if(null != attributes){

mDisabledAlpha = attributes.hasValue(R.styleable.MUNavigationBar_disable_alpha) ?
attributes.getFloat(R.styleable.MUNavigationBar_disable_alpha, mDisabledAlpha)
: mDisabledAlpha;
mBkgColor = attributes.hasValue(R.styleable.MUNavigationBar_bkg_color) ?
attributes.getColor(R.styleable.MUNavigationBar_bkg_color, mBkgColor)
: mBkgColor;
mLabel = attributes.hasValue(R.styleable.MUNavigationBar_android_text) ?
attributes.getString(R.styleable.MUNavigationBar_android_text)
: mLabel;
mLabelColor = attributes.hasValue(R.styleable.MUNavigationBar_android_textColor) ?
attributes.getColor(R.styleable.MUNavigationBar_android_textColor, mLabelColor)
: mLabelColor;
mLabelFontSize = attributes.hasValue(R.styleable.MUNavigationBar_android_textSize) ?
attributes.getDimensionPixelSize(R.styleable.MUNavigationBar_android_textSize, (int) mLabelFontSize)
: mLabelFontSize;
mLabelFontWeight = attributes.hasValue(R.styleable.MUNavigationBar_android_textStyle) ?
attributes.getColor(R.styleable.MUNavigationBar_android_textStyle, mLabelFontWeight)
: mLabelFontWeight;
mLabelAlignment = attributes.hasValue(R.styleable.MUNavigationBar_alignment) ?
attributes.getInt(R.styleable.MUNavigationBar_alignment, mLabelAlignment)
: mLabelAlignment;
mLabelHighLightedColor = attributes.hasValue(R.styleable.MUNavigationBar_pressed_color) ?
attributes.getInt(R.styleable.MUNavigationBar_pressed_color, mLabelHighLightedColor)
: mLabelHighLightedColor;
mProgressingColor = attributes.hasValue(R.styleable.MUNavigationBar_progressing_color) ?
attributes.getInt(R.styleable.MUNavigationBar_progressing_color, mProgressingColor)
: mProgressingColor;
mBorderWidth = attributes.hasValue(R.styleable.MUNavigationBar_border_width) ?
attributes.getDimensionPixelSize(R.styleable.MUNavigationBar_border_width, 0)
: mBorderWidth;
mBorderColor = attributes.hasValue(R.styleable.MUNavigationBar_border_color) ?
attributes.getColor(R.styleable.MUNavigationBar_border_color, mBorderColor)
: mBorderColor;
mCornerRadius = attributes.hasValue(R.styleable.MUNavigationBar_corner_radius) ?
attributes.getDimensionPixelSize(R.styleable.MUNavigationBar_corner_radius, mCornerRadius)
: mBorderColor;
mIsLoading = attributes.hasValue(R.styleable.MUNavigationBar_is_loading) ?
attributes.getBoolean(R.styleable.MUNavigationBar_is_loading, false)
: mIsLoading;
mHorizontalPadding = attributes.hasValue(R.styleable.MUNavigationBar_android_paddingHorizontal) ?
attributes.getDimensionPixelSize(R.styleable.MUNavigationBar_android_paddingHorizontal, mHorizontalPadding)
: mHorizontalPadding;
mVerticalPadding = attributes.hasValue(R.styleable.MUNavigationBar_android_paddingVertical) ?
attributes.getDimensionPixelSize(R.styleable.MUNavigationBar_android_paddingVertical, mVerticalPadding)
: mVerticalPadding;
mFontStyle = attributes.hasValue(R.styleable.MUNavigationBar_font_style) ?
attributes.getResourceId(R.styleable.MUNavigationBar_font_style, mFontStyle)
: mFontStyle;
}

init(context);
}

public MUButton(Context context, TypedArray attributes) {
super(context);

Expand Down Expand Up @@ -246,20 +303,19 @@ public MUButton(Context context, TypedArray attributes) {
private void init(Context context){

mButton = new MaterialButton(context);
mButton.setGravity(Gravity.CENTER);
mButton.setAllCaps(false);
mButton.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mButton.setId(View.generateViewId());
mButton.setAllCaps(false);
addView(mButton);

mProgressBar = new ProgressBar(context);
mProgressBar.setIndeterminate(true);

LayoutParams lp2 = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp2.addRule(RelativeLayout.ALIGN_END, mButton.getId());
lp2.addRule(RelativeLayout.ALIGN_START, mButton.getId());
lp2.addRule(RelativeLayout.ALIGN_TOP, mButton.getId());
lp2.addRule(RelativeLayout.ALIGN_BOTTOM, mButton.getId());
addView(mProgressBar, lp2);
RelativeLayout.LayoutParams progress = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
progress.addRule(RelativeLayout.ALIGN_LEFT, mButton.getId());
progress.addRule(RelativeLayout.ALIGN_RIGHT, mButton.getId());
progress.addRule(RelativeLayout.ALIGN_TOP, mButton.getId());
progress.addRule(RelativeLayout.ALIGN_BOTTOM, mButton.getId());
mProgressBar.setLayoutParams(progress);
addView(mProgressBar);

// Background
setBkgColor(mBkgColor);
Expand All @@ -271,10 +327,10 @@ private void init(Context context){
setLabel(mLabel);
setLabelFontWeight(mLabelFontWeight);
setLabelAlignment(mLabelAlignment);
// setLabelFontSize(mLabelFontSize);
setLabelFontSize(mLabelFontSize);
setProgressingColor(mProgressingColor);
// Style
// setFontStyle(mFontStyle);
setFontStyle(mFontStyle);
// Border
setBorderWidth(mBorderWidth);
setCornerRadius(mCornerRadius);
Expand All @@ -287,18 +343,15 @@ private void init(Context context){
setFontColors();
setBackgroundColors();
//Padding
// setVerticalPadding(mVerticalPadding);
// setHorizontalPadding(mHorizontalPadding);
mButton.setPadding(mHorizontalPadding, mVerticalPadding, mHorizontalPadding, mVerticalPadding);
mProgressBar.setPadding(mHorizontalPadding, mVerticalPadding, mHorizontalPadding, mVerticalPadding);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
mButton.setWidth(getMeasuredWidth());
mButton.setHeight(getMeasuredHeight());

mButton.setPadding(mHorizontalPadding, mVerticalPadding, mHorizontalPadding, mVerticalPadding);
mProgressBar.setPadding(mHorizontalPadding, mVerticalPadding, mHorizontalPadding, mVerticalPadding);
}

/**
Expand Down Expand Up @@ -538,6 +591,8 @@ public void setLoading(boolean loading) {
mProgressBar.setVisibility(mIsLoading ? VISIBLE : GONE)
);
mButton.setTextColor(mIsLoading ? Color.TRANSPARENT : mLabelColor);
mButton.setClickable(!mIsLoading);
mButton.setEnabled(!mIsLoading);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void init(Context context, TypedArray attributeSet) {
if(isInEditMode()){
TextView tv = new TextView(context);
tv.setText(context.getResources().getString(R.string.app_name));
tv.setBackgroundColor(context.getResources().getColor(R.color.primary));
tv.setBackgroundColor(context.getResources().getColor(R.color.sejima_primary));
addContentView(tv);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MUPageControl extends LinearLayout implements MUViewHelper {
/**
* The unactive element color
*/
private int mElementColor = getResources().getColor(R.color.primary);
private int mElementColor = getResources().getColor(R.color.sejima_primary);
/**
* The active element width
*/
Expand All @@ -49,7 +49,7 @@ public class MUPageControl extends LinearLayout implements MUViewHelper {
/**
* The unactive element color
*/
private int mActiveElementColor = getResources().getColor(R.color.accent);
private int mActiveElementColor = getResources().getColor(R.color.sejima_accent);
/**
* The unactive element border color
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class MUTextField extends RelativeLayout implements MUViewHelper {
/**
* Keyboard type
*/
private int mKeyboardType = InputType.TYPE_NULL;
private int mKeyboardType = InputType.TYPE_CLASS_TEXT;
/**
* Enable/disable auto-correction
*/
Expand Down Expand Up @@ -156,6 +156,7 @@ public MUTextField(Context context, AttributeSet attrs) {
mIsEditable = attributes.getBoolean(R.styleable.MUTextField_android_editable, true);
mAutoCorrection = attributes.getBoolean(R.styleable.MUTextField_auto_correct, true);
mKeyboardType = attributes.getInt(R.styleable.MUTextField_android_inputType, mKeyboardType);
mUnderlineColor = attributes.getColor(R.styleable.MUTextField_underline_color, mUnderlineColor);

s = attributes.getString(R.styleable.MUTextField_android_hint);
mPlaceHolderText = TextUtils.isEmpty(s) ? mPlaceHolderText : s;
Expand All @@ -171,9 +172,8 @@ private void init(Context context){
setLayoutParams(lpRoot);

// Field's label
LayoutParams lpTVLabel = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LayoutParams lpTVLabel = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lpTVLabel.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
lpTVLabel.addRule(mAlignment, RelativeLayout.TRUE);
mTVLabel = new TextView(context);
mTVLabel.setLayoutParams(lpTVLabel);
mTVLabel.setId(View.generateViewId());
Expand All @@ -186,7 +186,6 @@ private void init(Context context){

// Input field
LayoutParams lpEVInput = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lpEVInput.addRule(mAlignment, RelativeLayout.TRUE);
lpEVInput.addRule(RelativeLayout.BELOW, mTVLabel.getId());
mETInput = new AppCompatEditText(context){
@Override
Expand Down Expand Up @@ -329,17 +328,15 @@ public int getAlignment() {
* </ul>
*/
public void setAlignment(int alignment) {
RelativeLayout.LayoutParams ll = (LayoutParams) mTVLabel.getLayoutParams();
ll.removeRule(mAlignment);
ll.addRule(alignment, RelativeLayout.TRUE);
mTVLabel.setLayoutParams(ll);

if(Gravity.END == alignment){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like mETInput.setGravity(alignment); mTVLabel.setGravity(alignment); do the same thing?

mETInput.setGravity(Gravity.END);
mETInput.setGravity(alignment);
mTVLabel.setGravity(alignment);
} else if(Gravity.CENTER == alignment){
mETInput.setGravity(Gravity.CENTER);
mETInput.setGravity(alignment);
mTVLabel.setGravity(alignment);
} else {
mETInput.setGravity(Gravity.START);
mTVLabel.setGravity(Gravity.START);
}
mAlignment = alignment;
}
Expand Down Expand Up @@ -472,6 +469,14 @@ public int getKeyboardType() {
*/
public void setKeyboardType(int keyboardType) {
mKeyboardType = keyboardType;



if((keyboardType & InputType.TYPE_MASK_VARIATION) == InputType.TYPE_TEXT_VARIATION_PASSWORD
|| (keyboardType & InputType.TYPE_MASK_VARIATION) == InputType.TYPE_NUMBER_VARIATION_PASSWORD) {
setSecure(true);
}

mETInput.setInputType(mKeyboardType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

Expand All @@ -37,7 +37,7 @@ public class MUTopBar extends RelativeLayout implements MUViewHelper {
/**
* The left image button
*/
private ImageButton mIBLeftButton;
private ImageView mIBLeftButton;

/**
* The current title
Expand Down Expand Up @@ -67,9 +67,17 @@ public class MUTopBar extends RelativeLayout implements MUViewHelper {
*/
private int mButtonImage = R.drawable.ic_launcher_background;
/**
* The left padding
* The left btn padding
*/
private float mLeftButtonLeading = 0;
private float mLeftButtonPadding = 0;
/**
* The right btn padding
*/
private float mRightButtonPadding = 0;
/**
* The right btn padding
*/
private float mLeading = 0;
/**
* The left button width
*/
Expand Down Expand Up @@ -113,7 +121,9 @@ public MUTopBar(Context context, AttributeSet attrs) {
mTitleAlignment = attributes.getInt(R.styleable.MUTopBar_topbar_title_alignment, mTitleAlignment);

mLeftButtonWidth = attributes.getDimensionPixelSize(R.styleable.MUTopBar_topbar_img_width, 0);
mLeftButtonLeading = attributes.getDimensionPixelSize(R.styleable.MUTopBar_topbar_btn_leading, 0);
mLeftButtonPadding = attributes.getDimensionPixelSize(R.styleable.MUTopBar_topbar_btn_left_padding, 0);
mRightButtonPadding = attributes.getDimensionPixelSize(R.styleable.MUTopBar_topbar_btn_right_padding, 0);
mLeading = attributes.getDimensionPixelSize(R.styleable.MUTopBar_topbar_btn_leading, 0);
mButtonImage = attributes.getResourceId(R.styleable.MUTopBar_topbar_btn_img, mButtonImage);
// Font Style
mFontStyle = attributes.getResourceId(R.styleable.MUTopBar_font_style, mFontStyle);
Expand All @@ -131,9 +141,9 @@ private void init(Context context) {
setLayoutParams(lpRoot);

mLeftButtonWidth = mLeftButtonWidth != 0 ? mLeftButtonWidth : DEFAULT_BUTTON_WIDTH_IN_SP;
mIBLeftButton = new ImageButton(context);
mIBLeftButton = new ImageView(context);
mIBLeftButton.setId(View.generateViewId());
mIBLeftButton.setLayoutParams(getLeftBtnLayoutParams(mLeftButtonWidth));
mIBLeftButton.setLayoutParams(getImgLayoutParams(mLeftButtonWidth));
setButtonImage(mButtonImage);
addView(mIBLeftButton);

Expand All @@ -159,17 +169,22 @@ private void init(Context context) {
* Get the left padding of ImageButton
* @return the left padding of image button in dp.
*/
public float getLeftButtonLeading() {
return mLeftButtonLeading;
public float getLeftButtonPadding() {
return mLeftButtonPadding;
}

/**
* Set the left padding of ImageButton
* @param leftButtonLeading the left padding of ImageButton in dp.
* @param leftButtonPadding the left padding of ImageButton in dp.
*/
public void setLeftButtonLeading(float leftButtonLeading) {
mLeftButtonLeading = normalizeFloatValue(0, leftButtonLeading, leftButtonLeading);
mIBLeftButton.setLayoutParams(getLeftBtnLayoutParams(mLeftButtonWidth));
public void setLeftButtonPadding(float leftButtonPadding) {
mLeftButtonPadding = normalizeFloatValue(0, leftButtonPadding, leftButtonPadding);
mIBLeftButton.setLayoutParams(getImgLayoutParams(mLeftButtonWidth));
}

public void setRightButtonPadding(float rightButtonPadding) {
mRightButtonPadding = normalizeFloatValue(0, rightButtonPadding, rightButtonPadding);
mIBLeftButton.setLayoutParams(getImgLayoutParams(mLeftButtonWidth));
}

/**
Expand Down Expand Up @@ -375,24 +390,43 @@ public void setFontStyle(int fontStyle) {
}
}

/**
* Hide left button image
*/
public void hideImage() {
setImageVisibility(false);
}

/**
* Show left button image
*/
public void showImage() {
setImageVisibility(true);
}

private void setImageVisibility(boolean visible) {
mIBLeftButton.setVisibility(visible ? VISIBLE : GONE);
}


/**
* Apply the given width on the left image button
* @param width the width in dp.
*/
private void updateImageWidth(float width){
mIBLeftButton.setLayoutParams(getLeftBtnLayoutParams(width));
mIBLeftButton.setLayoutParams(getImgLayoutParams(width));
}

/**
* Get the params to update width and padding of the left ImageButton
* @param width the width in dp.
* @return the layout params of the left image button.
*/
private RelativeLayout.LayoutParams getLeftBtnLayoutParams(float width){
private RelativeLayout.LayoutParams getImgLayoutParams(float width){
LayoutParams lpImBtn = new LayoutParams((int) width, (int) width);
lpImBtn.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
lpImBtn.addRule(RelativeLayout.ALIGN_PARENT_START, RelativeLayout.TRUE);
lpImBtn.setMargins((int) mLeftButtonLeading, (int) mLeftButtonLeading, (int) mLeftButtonLeading, (int) mLeftButtonLeading);
lpImBtn.setMargins((int) mLeftButtonPadding, (int) mLeading, (int) mRightButtonPadding, (int) mLeading);
return lpImBtn;
}

Expand Down
2 changes: 2 additions & 0 deletions sejima-library/app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<attr name="topbar_btn_img" format="reference"/>
<attr name="topbar_img_width" format="dimension"/>
<attr name="topbar_btn_left_padding" format="dimension"/>
<attr name="topbar_btn_right_padding" format="dimension"/>
<attr name="topbar_btn_leading" format="dimension"/>
</declare-styleable>

Expand All @@ -85,6 +86,7 @@
<attr name="field" format="string"/>
<attr name="field_size" format="dimension"/>
<attr name="field_color" format="color"/>
<attr name="underline_color" format="color"/>
<attr name="field_weight" format="enum">
<enum name="normal" value="0"/>
<enum name="bold" value="1"/>
Expand Down
Loading