Skip to content

Commit

Permalink
use default WRAP_CONTENT if no layoutparams are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
medyo committed Dec 8, 2016
1 parent 0a385a9 commit 2dcbc42
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- Added ability to use android:text, android:textSize, android:testAllCaps attributes
- Fixed preview issues with android:* attrs
- Added opportunity to use android:* attrs in styles
- Added ability to use custom LayoutParams instead of the default one
- Minor optimization & refactoring

- 1.8.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class FancyButton extends LinearLayout{

private boolean mGhost = false ; // Default is a solid button !
private boolean mUseSystemFont = false; // Default is using robotoregular.ttf
private boolean useRippleEffect = true;
private boolean mUseRippleEffect = true;

/**
* Default constructor
Expand Down Expand Up @@ -308,6 +308,7 @@ private void initAttributesArray(TypedArray attrsArray){
mUseSystemFont = attrsArray.getBoolean(R.styleable.FancyButtonsAttrs_fb_useSystemFont, mUseSystemFont);

String text = attrsArray.getString(R.styleable.FancyButtonsAttrs_fb_text);

if (text == null) { //no fb_text attribute
text = attrsArray.getString(R.styleable.FancyButtonsAttrs_android_text);
}
Expand All @@ -330,8 +331,8 @@ private void initAttributesArray(TypedArray attrsArray){
if(fontIcon!=null)
mFontIcon = fontIcon;

if(text!=null)
mText = mTextAllCaps ? text.toUpperCase():text;
if(text != null)
mText = mTextAllCaps ? text.toUpperCase() : text;

if(!isInEditMode()){
if(iconFontFamily!=null){
Expand Down Expand Up @@ -397,7 +398,7 @@ private void setupBackground(){
}


if (useRippleEffect && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (mUseRippleEffect && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

this.setBackground(getRippleDrawable(defaultDrawable, focusDrawable, disabledDrawable));

Expand Down Expand Up @@ -464,8 +465,12 @@ private void initializeButtonContainer(){
}else{
this.setOrientation(LinearLayout.HORIZONTAL);
}
LayoutParams containerParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
this.setLayoutParams(containerParams);

if (this.getLayoutParams() == null){
LayoutParams containerParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
this.setLayoutParams(containerParams);
}

this.setGravity(Gravity.CENTER);
this.setClickable(true);
this.setFocusable(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mehdi.sakout.fancybuttons.samples;

import android.graphics.Color;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
Expand Down Expand Up @@ -49,6 +50,7 @@ protected void onCreate(Bundle savedInstanceState) {
installBtn.setIconPadding(0,30,0,0);

FancyButton signupBtn = new FancyButton(this);
signupBtn.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
signupBtn.setText("Repost the song");
signupBtn.setIconResource(R.drawable.soundcloud);
signupBtn.setBackgroundColor(Color.parseColor("#ff8800"));
Expand All @@ -64,7 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
container.addView(facebookLoginBtn,layoutParams);
container.addView(foursquareBtn,layoutParams);
container.addView(installBtn,layoutParams);
container.addView(signupBtn,layoutParams);
container.addView(signupBtn);

}

Expand Down

0 comments on commit 2dcbc42

Please sign in to comment.