Skip to content

Commit e38e72c

Browse files
committed
Make decorators use the new decor style
1 parent af5bf7d commit e38e72c

11 files changed

+116
-34
lines changed

decorators/src/main/java/com/mounacheikhna/decorators/AutofitDecorator.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import android.content.Context;
88
import android.content.res.Resources;
9+
import android.content.res.TypedArray;
910
import android.text.Layout;
1011
import android.text.StaticLayout;
1112
import android.text.TextPaint;
@@ -45,6 +46,11 @@ public class AutofitDecorator extends AttrsDecorator<TextView> {
4546
private TextPaint mPaint;
4647

4748

49+
@Override
50+
protected int[] styleable() {
51+
return R.styleable.AutofitDecorator;
52+
}
53+
4854
@Override
4955
protected int[] attrs() {
5056
return new int[]{ R.attr.decorAutofitText,
@@ -59,9 +65,9 @@ protected Class<TextView> clazz() {
5965
}
6066

6167
@Override
62-
protected void apply(TextView view, DecorValue decorValue) {
68+
protected void apply(TextView view, TypedArray typedArray) {
6369
mTextView = view;
64-
boolean isAutofit = decorValue.getBoolean(R.attr.decorAutofitText);
70+
boolean isAutofit = typedArray.getBoolean(R.styleable.AutofitDecorator_decorAutofitText, false);
6571
if(!isAutofit) return;
6672

6773
float scaledDensity = mTextView.getContext().getResources().getDisplayMetrics().scaledDensity;
@@ -71,11 +77,11 @@ protected void apply(TextView view, DecorValue decorValue) {
7177

7278
//TODO: deal with case when one of these values is absent
7379

74-
sizeToFit = decorValue.getBoolean(R.attr.decorSizeToFit, sizeToFit);
80+
sizeToFit = typedArray.getBoolean(R.styleable.AutofitDecorator_decorSizeToFit, sizeToFit);
7581

76-
minTextSize = decorValue.getDimensionPixelSize(R.attr.decorMinTextSize, minTextSize);
82+
minTextSize = typedArray.getDimensionPixelSize(R.styleable.AutofitDecorator_decorMinTextSize, minTextSize);
7783

78-
precision = decorValue.getFloat(R.attr.decorPrecision, precision);
84+
precision = typedArray.getFloat(R.styleable.AutofitDecorator_decorPrecision, precision);
7985

8086
mPaint = new TextPaint();
8187
setSizeToFit(sizeToFit);

decorators/src/main/java/com/mounacheikhna/decorators/BlurDecorator.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mounacheikhna.decorators;
22

3+
import android.content.res.TypedArray;
34
import android.os.Build;
45
import android.view.View;
56
import android.view.ViewGroup;
@@ -15,6 +16,10 @@
1516
*/
1617
public class BlurDecorator extends AttrsDecorator<View> {
1718

19+
@Override
20+
protected int[] styleable() {
21+
return R.styleable.BlurDecorator;
22+
}
1823

1924
@Override
2025
protected int[] attrs() {
@@ -28,8 +33,8 @@ protected Class<View> clazz() {
2833
}
2934

3035
@Override
31-
protected void apply(View view, DecorValue decorValue) {
32-
boolean isBlur = decorValue.getBoolean(R.attr.decorBlur);
36+
protected void apply(View view, TypedArray typedArray) {
37+
boolean isBlur = typedArray.getBoolean(R.styleable.BlurDecorator_decorBlur, false);
3338
if(!isBlur || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) return;
3439

3540
//i'm guessing this part here doesnt work because i'm using the same blur as ngAndroid and they are

decorators/src/main/java/com/mounacheikhna/decorators/ColorFilterDecorator.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mounacheikhna.decorators;
22

3+
import android.content.res.TypedArray;
34
import android.widget.ImageView;
45

56
import com.mounacheikhna.decor.AttrsDecorator;
@@ -11,6 +12,11 @@
1112
*/
1213
public class ColorFilterDecorator extends AttrsDecorator<ImageView> {
1314

15+
@Override
16+
protected int[] styleable() {
17+
return R.styleable.ColorFilterDecorator;
18+
}
19+
1420
@Override
1521
protected int[] attrs() {
1622
return new int[]{R.attr.decorColorFilter};
@@ -23,8 +29,8 @@ protected Class<ImageView> clazz() {
2329
}
2430

2531
@Override
26-
protected void apply(ImageView view, DecorValue decorValue) {
27-
int color = decorValue.getColor(R.attr.decorColorFilter);
32+
protected void apply(ImageView view, TypedArray typedArray) {
33+
int color = typedArray.getColor(R.styleable.ColorFilterDecorator_decorColorFilter, 0);
2834
if (color != 0) {
2935
view.setColorFilter(color);
3036
}

decorators/src/main/java/com/mounacheikhna/decorators/ErrorDecorator.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mounacheikhna.decorators;
22

3+
import android.content.res.TypedArray;
34
import android.graphics.drawable.Drawable;
45
import android.widget.EditText;
56

@@ -11,6 +12,11 @@
1112
*/
1213
public class ErrorDecorator extends AttrsDecorator<EditText> {
1314

15+
@Override
16+
protected int[] styleable() {
17+
return R.styleable.ErrorDecorator;
18+
}
19+
1420
@Override
1521
protected int[] attrs() {
1622
return new int[] { R.attr.decorErrorIcon, R.attr.decorErrorText};
@@ -22,9 +28,9 @@ protected Class<EditText> clazz() {
2228
}
2329

2430
@Override
25-
protected void apply(EditText view, DecorValue decorValue) {
26-
Drawable errorIcon = decorValue.getDrawable(R.attr.decorErrorIcon);
27-
CharSequence errorText = decorValue.getString(R.attr.decorErrorText);
31+
protected void apply(EditText view, TypedArray typedArray) {
32+
Drawable errorIcon = typedArray.getDrawable(R.styleable.ErrorDecorator_decorErrorIcon);
33+
CharSequence errorText = typedArray.getString(R.styleable.ErrorDecorator_decorErrorText);
2834
view.setError(errorText, errorIcon);
2935
}
3036

decorators/src/main/java/com/mounacheikhna/decorators/FontDecorator.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mounacheikhna.decorators;
22

3+
import android.content.res.TypedArray;
34
import android.graphics.Typeface;
45
import android.widget.TextView;
56

@@ -9,6 +10,11 @@
910

1011
public class FontDecorator extends AttrsDecorator<TextView> {
1112

13+
@Override
14+
protected int[] styleable() {
15+
return R.styleable.FontDecorator;
16+
}
17+
1218
@Override
1319
protected int[] attrs() {
1420
return new int[] { R.attr.decorTypefaceAsset};
@@ -21,8 +27,8 @@ protected Class<TextView> clazz() {
2127
}
2228

2329
@Override
24-
protected void apply(TextView view, DecorValue decorValue) {
25-
String typefacePath = decorValue.getString(R.attr.decorTypefaceAsset);
30+
protected void apply(TextView view, TypedArray typedArray) {
31+
String typefacePath = typedArray.getString(R.styleable.FontDecorator_decorTypefaceAsset);
2632
if(typefacePath == null) return;
2733
view.setTypeface(Typeface.createFromAsset(
2834
view.getResources().getAssets(), typefacePath));

decorators/src/main/java/com/mounacheikhna/decorators/OnLongClickDecorator.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mounacheikhna.decorators;
22

33
import android.app.Activity;
4+
import android.content.res.TypedArray;
45
import android.view.View;
56
import android.view.View.OnLongClickListener;
67

@@ -15,18 +16,22 @@ public OnLongClickDecorator(Activity activity) {
1516
super(activity);
1617
}
1718

19+
@Override
20+
protected int[] styleable() {
21+
return R.styleable.OnLongClickDecorator;
22+
}
1823

1924
@Override
2025
protected int[] attrs() {
2126
return new int[]{R.attr.decorOnLongClick};
2227
}
2328

2429
@Override
25-
protected void apply(View view, final DecorValue decorValue) {
30+
protected void apply(View view, final TypedArray typedArray) {
2631
view.setOnLongClickListener(new OnLongClickListener() {
2732
@Override
2833
public boolean onLongClick(View v) {
29-
onAction(decorValue.getString(R.attr.decorOnLongClick));
34+
onAction(typedArray.getString(R.styleable.OnLongClickDecorator_decorOnLongClick));
3035
return true;
3136
}
3237
});

decorators/src/main/java/com/mounacheikhna/decorators/OnTouchDecorator.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mounacheikhna.decorators;
22

33
import android.app.Activity;
4+
import android.content.res.TypedArray;
45
import android.view.MotionEvent;
56
import android.view.View;
67
import android.view.View.OnTouchListener;
@@ -17,17 +18,22 @@ public OnTouchDecorator(Activity activity) {
1718
}
1819

1920

21+
@Override
22+
protected int[] styleable() {
23+
return R.styleable.OnTouchDecorator;
24+
}
25+
2026
@Override
2127
protected int[] attrs() {
2228
return new int[]{R.attr.decorOnTouch};
2329
}
2430

2531
@Override
26-
protected void apply(View view, final DecorValue decorValue) {
32+
protected void apply(View view, final TypedArray typedArray) {
2733
view.setOnTouchListener(new OnTouchListener() {
2834
@Override
2935
public boolean onTouch(View v, MotionEvent event) {
30-
return onAction(decorValue.getString(R.attr.decorOnTouch));
36+
return onAction(typedArray.getString(R.styleable.OnTouchDecorator_decorOnTouch));
3137
}
3238
});
3339
}

decorators/src/main/java/com/mounacheikhna/decorators/SearchAnimateDecorator.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mounacheikhna.decorators;
22

33
import android.annotation.TargetApi;
4+
import android.content.res.TypedArray;
45
import android.graphics.drawable.AnimatedVectorDrawable;
56
import android.os.Build;
67
import android.view.View;
@@ -26,6 +27,11 @@ public class SearchAnimateDecorator extends AttrsDecorator<ImageView> {
2627
private float mOffset;
2728

2829

30+
@Override
31+
protected int[] styleable() {
32+
return R.styleable.SearchAnimateDecorator;
33+
}
34+
2935
@Override
3036
protected int[] attrs() {
3137
return new int[]{R.attr.decorAnimateSearch};
@@ -38,8 +44,8 @@ protected Class<ImageView> clazz() {
3844
}
3945

4046
@Override
41-
protected void apply(ImageView view, DecorValue decorValue) {
42-
boolean shouldAnimate = decorValue.getBoolean(R.attr.decorAnimateSearch);
47+
protected void apply(ImageView view, TypedArray typedArray) {
48+
boolean shouldAnimate = typedArray.getBoolean(R.styleable.SearchAnimateDecorator_decorAnimateSearch, false);
4349
if(!shouldAnimate) return;
4450

4551
mIv = view;

decorators/src/main/java/com/mounacheikhna/decorators/ShimmerDecorator.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mounacheikhna.decorators;
22

3+
import android.content.res.TypedArray;
34
import android.widget.TextView;
45

56
import com.mounacheikhna.decor.AttrsDecorator;
@@ -10,6 +11,11 @@
1011
*/
1112
public class ShimmerDecorator extends AttrsDecorator<TextView> {
1213

14+
@Override
15+
protected int[] styleable() {
16+
return R.styleable.SearchAnimateDecorator;
17+
}
18+
1319
@Override
1420
protected int[] attrs() {
1521
return new int[] {R.attr.decorShimmer};
@@ -21,7 +27,7 @@ protected Class<TextView> clazz() {
2127
}
2228

2329
@Override
24-
protected void apply(TextView view, DecorValue decorValue) {
30+
protected void apply(TextView view, TypedArray typedArray) {
2531
//TODO: implement
2632
}
2733
}

decorators/src/main/res/values/attrs.xml

+42-12
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,54 @@
33

44
<!-- all attributes here prefixed with decor to avoid conflicts with other apps & lib attributes -->
55

6-
<attr name="decorTypefaceAsset" format="string" />
7-
<attr name="decorErrorText" format="string" />
8-
<attr name="decorErrorIcon" format="reference" />
6+
<declare-styleable name="FontDecorator">
7+
<attr name="decorTypefaceAsset" format="string" />
8+
</declare-styleable>
9+
10+
<declare-styleable name="ErrorDecorator">
11+
<attr name="decorErrorText" format="string" />
12+
<attr name="decorErrorIcon" format="reference" />
13+
</declare-styleable>
14+
915
<attr name="decorRound" format="reference" />
1016
<attr name="decorCornerRadius" format="dimension" />
11-
<attr name="decorOnTouch" />
12-
<attr name="decorColorFilter" format="color" />
17+
18+
<declare-styleable name="OnTouchDecorator">
19+
<attr name="decorOnTouch" format="string"/>
20+
</declare-styleable>
21+
22+
<declare-styleable name="ColorFilterDecorator">
23+
<attr name="decorColorFilter" format="color" />
24+
</declare-styleable>
25+
1326
<attr name="decorCircular" format="boolean" />
14-
<attr name="decorOnLongClick" />
15-
<attr name="decorLayoutManager" />
16-
<attr name="decorLayoutManagerOrientation" />
17-
<attr name="decorBlur" format="boolean" />
27+
28+
<declare-styleable name="OnLongClickDecorator">
29+
<attr name="decorOnLongClick" format="string" />
30+
</declare-styleable>
31+
32+
<declare-styleable name="LayoutManagerDecorator">
33+
<attr name="decorLayoutManager" format="string"/>
34+
<attr name="decorLayoutManagerOrientation" format="string" />
35+
</declare-styleable>
36+
37+
<declare-styleable name="BlurDecorator">
38+
<attr name="decorBlur" format="boolean" />
39+
</declare-styleable>
40+
1841
<attr name="decorColorDescendents" format="boolean|reference" />
19-
<attr name="decorAnimateSearch" format="boolean|reference" />
42+
43+
<declare-styleable name="SearchAnimateDecorator">
44+
<attr name="decorAnimateSearch" format="boolean|reference" />
45+
</declare-styleable>
46+
2047
<attr name="decorOptimise" format="boolean" />
21-
<attr name="decorShimmer" format="boolean" />
2248

23-
<declare-styleable name="DecorAutofit">
49+
<declare-styleable name="ShimmerDecorator">
50+
<attr name="decorShimmer" format="boolean" />
51+
</declare-styleable>
52+
53+
<declare-styleable name="AutofitDecorator">
2454
<attr name="decorAutofitText" format="boolean|reference" />
2555
<attr name="decorSizeToFit" format="float|reference" />
2656
<attr name="decorMinTextSize" format="reference" />

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':decor' /*, ':decorators', ':samples' */
1+
include ':decor' , ':decorators', ':samples'

0 commit comments

Comments
 (0)