From 024caa8c5175282c7d9de3b2ec9d027cdad7444d Mon Sep 17 00:00:00 2001 From: "David W. Berry" Date: Mon, 24 Oct 2016 12:37:44 -0500 Subject: [PATCH 1/3] Allow for better subclassing by passing defStyleAttr and defStyleRes all the way through to obtainStyledAttributes --- .../github/clans/fab/FloatingActionButton.java | 10 +++++++--- .../com/github/clans/fab/FloatingActionMenu.java | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/library/src/main/java/com/github/clans/fab/FloatingActionButton.java b/library/src/main/java/com/github/clans/fab/FloatingActionButton.java index e9c98df..5620dcb 100755 --- a/library/src/main/java/com/github/clans/fab/FloatingActionButton.java +++ b/library/src/main/java/com/github/clans/fab/FloatingActionButton.java @@ -112,11 +112,15 @@ public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAtt @TargetApi(Build.VERSION_CODES.LOLLIPOP) public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); - init(context, attrs, defStyleAttr); + init(context, attrs, defStyleAttr, defStyleRes); + } + + protected void init(Context context, AttributeSet attrs, int defStyleAttr) { + init(context, attrs, defStyleAttr, 0); } - private void init(Context context, AttributeSet attrs, int defStyleAttr) { - TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, 0); + protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, defStyleRes); mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, 0xFFDA4336); mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, 0xFFE75043); mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, 0xFFAAAAAA); diff --git a/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java b/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java index 0b80e4c..d82e6df 100755 --- a/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java +++ b/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java @@ -120,11 +120,21 @@ public FloatingActionMenu(Context context, AttributeSet attrs) { public FloatingActionMenu(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - init(context, attrs); + init(context, attrs, defStyleAttr); } - private void init(Context context, AttributeSet attrs) { - TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionMenu, 0, 0); + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public FloatingActionMenu(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + init(context, attrs, defStyleAttr, defStyleRes); + } + + protected void init(Context context, AttributeSet attrs, int defStyleAttr) { + init(context, attrs, defStyleAttr, 0); + } + + protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionMenu, defStyleAttr, defStyleRes); mButtonSpacing = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_buttonSpacing, mButtonSpacing); mLabelsMargin = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_margin, mLabelsMargin); mLabelsPosition = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_position, LABELS_POSITION_LEFT); From 92c34fc1f16763b91f7b85456ac16dcb0e173a50 Mon Sep 17 00:00:00 2001 From: "David W. Berry" Date: Mon, 24 Oct 2016 12:44:42 -0500 Subject: [PATCH 2/3] Revert "Allow for better subclassing by passing defStyleAttr and defStyleRes all the way through to obtainStyledAttributes" This reverts commit 024caa8c5175282c7d9de3b2ec9d027cdad7444d. --- .../github/clans/fab/FloatingActionButton.java | 10 +++------- .../com/github/clans/fab/FloatingActionMenu.java | 16 +++------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/library/src/main/java/com/github/clans/fab/FloatingActionButton.java b/library/src/main/java/com/github/clans/fab/FloatingActionButton.java index 5620dcb..e9c98df 100755 --- a/library/src/main/java/com/github/clans/fab/FloatingActionButton.java +++ b/library/src/main/java/com/github/clans/fab/FloatingActionButton.java @@ -112,15 +112,11 @@ public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAtt @TargetApi(Build.VERSION_CODES.LOLLIPOP) public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); - init(context, attrs, defStyleAttr, defStyleRes); - } - - protected void init(Context context, AttributeSet attrs, int defStyleAttr) { - init(context, attrs, defStyleAttr, 0); + init(context, attrs, defStyleAttr); } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, defStyleRes); + private void init(Context context, AttributeSet attrs, int defStyleAttr) { + TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, 0); mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, 0xFFDA4336); mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, 0xFFE75043); mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, 0xFFAAAAAA); diff --git a/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java b/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java index d82e6df..0b80e4c 100755 --- a/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java +++ b/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java @@ -120,21 +120,11 @@ public FloatingActionMenu(Context context, AttributeSet attrs) { public FloatingActionMenu(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - init(context, attrs, defStyleAttr); + init(context, attrs); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public FloatingActionMenu(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - init(context, attrs, defStyleAttr, defStyleRes); - } - - protected void init(Context context, AttributeSet attrs, int defStyleAttr) { - init(context, attrs, defStyleAttr, 0); - } - - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionMenu, defStyleAttr, defStyleRes); + private void init(Context context, AttributeSet attrs) { + TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionMenu, 0, 0); mButtonSpacing = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_buttonSpacing, mButtonSpacing); mLabelsMargin = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_margin, mLabelsMargin); mLabelsPosition = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_position, LABELS_POSITION_LEFT); From e9ac8ee2ad0723139a2df3af3dbc18728e7fcf60 Mon Sep 17 00:00:00 2001 From: "David W. Berry" Date: Mon, 24 Oct 2016 12:37:44 -0500 Subject: [PATCH 3/3] Allow for better subclassing by passing defStyleAttr and defStyleRes all the way through to obtainStyledAttributes --- .../github/clans/fab/FloatingActionButton.java | 10 +++++++--- .../com/github/clans/fab/FloatingActionMenu.java | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/library/src/main/java/com/github/clans/fab/FloatingActionButton.java b/library/src/main/java/com/github/clans/fab/FloatingActionButton.java index e9c98df..5620dcb 100755 --- a/library/src/main/java/com/github/clans/fab/FloatingActionButton.java +++ b/library/src/main/java/com/github/clans/fab/FloatingActionButton.java @@ -112,11 +112,15 @@ public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAtt @TargetApi(Build.VERSION_CODES.LOLLIPOP) public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); - init(context, attrs, defStyleAttr); + init(context, attrs, defStyleAttr, defStyleRes); + } + + protected void init(Context context, AttributeSet attrs, int defStyleAttr) { + init(context, attrs, defStyleAttr, 0); } - private void init(Context context, AttributeSet attrs, int defStyleAttr) { - TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, 0); + protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, defStyleRes); mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, 0xFFDA4336); mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, 0xFFE75043); mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, 0xFFAAAAAA); diff --git a/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java b/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java index 0b80e4c..d82e6df 100755 --- a/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java +++ b/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java @@ -120,11 +120,21 @@ public FloatingActionMenu(Context context, AttributeSet attrs) { public FloatingActionMenu(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - init(context, attrs); + init(context, attrs, defStyleAttr); } - private void init(Context context, AttributeSet attrs) { - TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionMenu, 0, 0); + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public FloatingActionMenu(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + init(context, attrs, defStyleAttr, defStyleRes); + } + + protected void init(Context context, AttributeSet attrs, int defStyleAttr) { + init(context, attrs, defStyleAttr, 0); + } + + protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionMenu, defStyleAttr, defStyleRes); mButtonSpacing = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_buttonSpacing, mButtonSpacing); mLabelsMargin = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_margin, mLabelsMargin); mLabelsPosition = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_position, LABELS_POSITION_LEFT);