Optimized IconicsImageView
Small refactoring
MODIFY
iconics-view-library/src/main/java/com/mikepenz/iconics/internal/CheckedCompoundIconicsDrawables.java
iconics-view-library/src/main/java/com/mikepenz/iconics/internal/CheckedCompoundIconicsDrawables.java
@@ -24,10 +24,11 @@ import com.mikepenz.iconics.IconicsDrawable;
import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP;
/**
- * @author zTrap (09.07.2017)
+ * @author pa.gulko zTrap (09.07.2017)
*/
@RestrictTo(LIBRARY_GROUP)
public interface CheckedCompoundIconicsDrawables {
+
IconicsDrawable getCheckedIconicsDrawableStart();
IconicsDrawable getCheckedIconicsDrawableTop();

MODIFY
iconics-view-library/src/main/java/com/mikepenz/iconics/internal/CompoundIconicsDrawables.java
iconics-view-library/src/main/java/com/mikepenz/iconics/internal/CompoundIconicsDrawables.java
@@ -28,6 +28,7 @@ import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP;
*/
@RestrictTo(LIBRARY_GROUP)
public interface CompoundIconicsDrawables {
+
IconicsDrawable getIconicsDrawableStart();
IconicsDrawable getIconicsDrawableTop();

MODIFY
iconics-view-library/src/main/java/com/mikepenz/iconics/internal/IconicsView.java
iconics-view-library/src/main/java/com/mikepenz/iconics/internal/IconicsView.java
@@ -23,7 +23,7 @@ import android.util.AttributeSet;
import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP;
/**
- * @author zTrap (09.07.2017)
+ * @author pa.gulko zTrap (09.07.2017)
*/
@RestrictTo(LIBRARY_GROUP)
public interface IconicsView {

MODIFY
iconics-view-library/src/main/java/com/mikepenz/iconics/internal/IconicsViewsAttrsReader.java
iconics-view-library/src/main/java/com/mikepenz/iconics/internal/IconicsViewsAttrsReader.java
@@ -19,8 +19,10 @@ package com.mikepenz.iconics.internal;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
+import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;
import android.text.TextUtils;
+import android.util.AttributeSet;
import com.mikepenz.iconics.IconicsDrawable;
import com.mikepenz.iconics.context.IconicsAttrsReader;
@@ -78,10 +80,24 @@ public class IconicsViewsAttrsReader extends IconicsAttrsReader {
icon.backgroundContourWidthPx(backgroundContourWidth);
}
}
+
+ @Nullable
+ public static IconicsDrawable getIconicsImageViewDrawable(Context context, AttributeSet attrs){
+ IconicsDrawable drawable = null;
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IconicsImageView);
+
+ String icon = a.getString(R.styleable.IconicsImageView_iiv_icon);
+ if (!TextUtils.isEmpty(icon)) {
+ drawable = new IconicsDrawable(context, icon);
+ readIconicsImageView(a, drawable);
+ }
+
+ a.recycle();
+ return drawable;
+ }
//endregion
//region IconicsTextView
-
/**
* Attributes priority:
* <p>
@@ -471,7 +487,6 @@ public class IconicsViewsAttrsReader extends IconicsAttrsReader {
//endregion
//region IconicsCheckableTextView
-
/**
* Attributes priority:
* <p>

MODIFY
iconics-view-library/src/main/java/com/mikepenz/iconics/utils/IconicsMenuInflaterUtil.java
iconics-view-library/src/main/java/com/mikepenz/iconics/utils/IconicsMenuInflaterUtil.java
package com.mikepenz.iconics.utils;
import android.content.Context;
-import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.AttributeSet;
import android.util.Xml;
import android.view.Menu;
import android.view.MenuInflater;
-import android.view.MenuItem;
import com.mikepenz.iconics.IconicsDrawable;
import com.mikepenz.iconics.internal.IconicsViewsAttrsReader;
-import com.mikepenz.iconics.view.R;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -88,7 +85,7 @@ public class IconicsMenuInflaterUtil {
do {
if (eventType == XmlPullParser.START_TAG) {
tagName = parser.getName();
- if (tagName.equals(XML_MENU)) {
+ if (XML_MENU.equals(tagName)) {
// Go to next tag
eventType = parser.next();
break;
@@ -109,29 +106,24 @@ public class IconicsMenuInflaterUtil {
tagName = parser.getName();
switch (tagName) {
case XML_ITEM:
- HashMap<String, String> attr = new HashMap<>();
+ HashMap<String, String> attrsMap = new HashMap<>();
for (int i = 0; i < parser.getAttributeCount(); i++) {
- attr.put(parser.getAttributeName(i), parser.getAttributeValue(i));
+ attrsMap.put(parser.getAttributeName(i), parser.getAttributeValue(i));
+ }
+ IconicsDrawable icon = IconicsViewsAttrsReader.getIconicsImageViewDrawable(context, attrs);
+ if (icon != null) {
+ int id = Integer.parseInt(attrsMap.get("id").replace("@", ""));
+ menu.findItem(id).setIcon(icon);
}
- //region trying to set normal icon
- TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IconicsImageView);
- IconicsDrawable icon = new IconicsDrawable(context);
-
- IconicsViewsAttrsReader.readIconicsImageView(a, icon);
-
- int id = Integer.parseInt(attr.get("id").replace("@", ""));
- MenuItem item = menu.findItem(id);
- item.setIcon(icon);
- a.recycle();
- //endregion
break;
- case XML_MENU:
+ case XML_MENU:
// TODO: maybe we must pass in the sub menu in this case, not sure if the function menu.findItem(id) will search through sub items
if (checkSubMenus) {
parseMenu(context, attrs, parser, menu, checkSubMenus);
}
break;
+
default:
lookingForEndOfUnknownTag = true;
unknownTagName = tagName;
@@ -144,7 +136,7 @@ public class IconicsMenuInflaterUtil {
if (lookingForEndOfUnknownTag && tagName.equals(unknownTagName)) {
lookingForEndOfUnknownTag = false;
unknownTagName = null;
- } else if (tagName.equals(XML_MENU)) {
+ } else if (XML_MENU.equals(tagName)) {
reachedEndOfMenu = true;
}
break;
@@ -152,7 +144,6 @@ public class IconicsMenuInflaterUtil {
case XmlPullParser.END_DOCUMENT:
throw new RuntimeException("Unexpected end of document");
}
-
eventType = parser.next();
}
}

MODIFY
iconics-view-library/src/main/java/com/mikepenz/iconics/view/IconicsCheckableTextView.java
iconics-view-library/src/main/java/com/mikepenz/iconics/view/IconicsCheckableTextView.java
@@ -140,7 +140,6 @@ public class IconicsCheckableTextView extends IconicsTextView implements Checkab
}
mBroadcasting = false;
}
-
}
public void setOnCheckedChangeListener(OnCheckedChangeListener listener) {

MODIFY
iconics-view-library/src/main/java/com/mikepenz/iconics/view/IconicsImageView.java
iconics-view-library/src/main/java/com/mikepenz/iconics/view/IconicsImageView.java
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package com.mikepenz.iconics.view;
import android.content.Context;
-import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;
import android.support.v7.widget.AppCompatImageView;
@@ -29,7 +29,6 @@ import com.mikepenz.iconics.internal.IconicsViewsAttrsReader;
import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP;
public class IconicsImageView extends AppCompatImageView implements IconicsView {
- private IconicsDrawable mIcon;
public IconicsImageView(Context context) {
this(context, null);
@@ -49,25 +48,20 @@ public class IconicsImageView extends AppCompatImageView implements IconicsView
@Override
@RestrictTo(LIBRARY_GROUP)
public void initialize(Context context, AttributeSet attrs, int defStyle) {
- mIcon = new IconicsDrawable(context);
- applyAttr(context, attrs, defStyle);
//set the scale type for this view
setScaleType(ScaleType.CENTER_INSIDE);
- //set our values for this view
- setImageDrawable(mIcon);
+
+ applyAttr(context, attrs, defStyle);
}
@Override
@RestrictTo(LIBRARY_GROUP)
public void applyAttr(Context context, AttributeSet attrs, int defStyle) {
- TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IconicsImageView, defStyle, 0);
- IconicsViewsAttrsReader.readIconicsImageView(a, mIcon);
- a.recycle();
+ setIcon(IconicsViewsAttrsReader.getIconicsImageViewDrawable(context, attrs));
}
public void setIcon(@Nullable IconicsDrawable icon) {
- //set the imageDrawable
- setImageDrawable(mIcon = icon);
+ setImageDrawable(icon);
}
public IconicsDrawable getIcon() {

MODIFY
iconics-view-library/src/main/res/values/attrs.xml
iconics-view-library/src/main/res/values/attrs.xml
</declare-styleable>
<declare-styleable name="IconicsTextView">
+ <!--region start icon-->
<attr name="iiv_start_icon" format="string" />
<attr name="iiv_start_color" format="color|reference" />
<attr name="iiv_start_size" format="dimension|reference" />
<attr name="iiv_start_corner_radius" format="dimension|reference" />
<attr name="iiv_start_background_contour_color" format="color|reference" />
<attr name="iiv_start_background_contour_width" format="dimension|reference" />
+ <!--endregion-->
+ <!--region top icon-->
<attr name="iiv_top_icon" format="string" />
<attr name="iiv_top_color" format="color|reference" />
<attr name="iiv_top_size" format="dimension|reference" />
<attr name="iiv_top_corner_radius" format="dimension|reference" />
<attr name="iiv_top_background_contour_color" format="color|reference" />
<attr name="iiv_top_background_contour_width" format="dimension|reference" />
+ <!--endregion-->
+ <!--region end icon-->
<attr name="iiv_end_icon" format="string" />
<attr name="iiv_end_color" format="color|reference" />
<attr name="iiv_end_size" format="dimension|reference" />
<attr name="iiv_end_corner_radius" format="dimension|reference" />
<attr name="iiv_end_background_contour_color" format="color|reference" />
<attr name="iiv_end_background_contour_width" format="dimension|reference" />
+ <!--endregion-->
+ <!--region bottom icon-->
<attr name="iiv_bottom_icon" format="string" />
<attr name="iiv_bottom_color" format="color|reference" />
<attr name="iiv_bottom_size" format="dimension|reference" />
<attr name="iiv_bottom_corner_radius" format="dimension|reference" />
<attr name="iiv_bottom_background_contour_color" format="color|reference" />
<attr name="iiv_bottom_background_contour_width" format="dimension|reference" />
+ <!--endregion-->
+ <!--region all icons-->
<attr name="iiv_all_icon" format="string" />
<attr name="iiv_all_color" format="color|reference" />
<attr name="iiv_all_size" format="dimension|reference" />
<attr name="iiv_all_corner_radius" format="dimension|reference" />
<attr name="iiv_all_background_contour_color" format="color|reference" />
<attr name="iiv_all_background_contour_width" format="dimension|reference" />
+ <!--endregion-->
</declare-styleable>
<declare-styleable name="IconicsCompoundButton">
+ <!--region checked icons-->
<attr name="iiv_checked_icon" format="string" />
<attr name="iiv_checked_color" format="color|reference" />
<attr name="iiv_checked_size" format="dimension|reference" />
<attr name="iiv_checked_corner_radius" format="dimension|reference" />
<attr name="iiv_checked_background_contour_color" format="color|reference" />
<attr name="iiv_checked_background_contour_width" format="dimension|reference" />
+ <!--endregion-->
+ <!--region unchecked icons-->
<attr name="iiv_unchecked_icon" format="string" />
<attr name="iiv_unchecked_color" format="color|reference" />
<attr name="iiv_unchecked_size" format="dimension|reference" />
<attr name="iiv_unchecked_corner_radius" format="dimension|reference" />
<attr name="iiv_unchecked_background_contour_color" format="color|reference" />
<attr name="iiv_unchecked_background_contour_width" format="dimension|reference" />
+ <!--endregion-->
</declare-styleable>
<declare-styleable name="IconicsCheckableTextView">
-
- <!--region all icons-->
- <attr name="iiv_all_checked_icon" format="string" />
- <attr name="iiv_all_checked_color" format="color|reference" />
- <attr name="iiv_all_checked_size" format="dimension|reference" />
- <attr name="iiv_all_checked_padding" format="dimension|reference" />
- <attr name="iiv_all_checked_contour_color" format="color|reference" />
- <attr name="iiv_all_checked_contour_width" format="dimension|reference" />
- <attr name="iiv_all_checked_background_color" format="color|reference" />
- <attr name="iiv_all_checked_corner_radius" format="dimension|reference" />
- <attr name="iiv_all_checked_background_contour_color" format="color|reference" />
- <attr name="iiv_all_checked_background_contour_width" format="dimension|reference" />
- <!--endregion-->
-
<!--region start icon-->
<attr name="iiv_start_checked_icon" format="string" />
<attr name="iiv_start_checked_color" format="color|reference" />
<attr name="iiv_bottom_checked_background_contour_color" format="color|reference" />
<attr name="iiv_bottom_checked_background_contour_width" format="dimension|reference" />
<!--endregion-->
+
+ <!--region all icons-->
+ <attr name="iiv_all_checked_icon" format="string" />
+ <attr name="iiv_all_checked_color" format="color|reference" />
+ <attr name="iiv_all_checked_size" format="dimension|reference" />
+ <attr name="iiv_all_checked_padding" format="dimension|reference" />
+ <attr name="iiv_all_checked_contour_color" format="color|reference" />
+ <attr name="iiv_all_checked_contour_width" format="dimension|reference" />
+ <attr name="iiv_all_checked_background_color" format="color|reference" />
+ <attr name="iiv_all_checked_corner_radius" format="dimension|reference" />
+ <attr name="iiv_all_checked_background_contour_color" format="color|reference" />
+ <attr name="iiv_all_checked_background_contour_width" format="dimension|reference" />
+ <!--endregion-->
</declare-styleable>
</resources>
\ No newline at end of file

MODIFY
library-core/src/main/java/com/mikepenz/iconics/context/IconicsAttrsReader.java
library-core/src/main/java/com/mikepenz/iconics/context/IconicsAttrsReader.java
@@ -38,7 +38,7 @@ public class IconicsAttrsReader {
protected final static int DEF_SIZE = -1;
@Nullable
- public static IconicsDrawable readIconics(Context context, AttributeSet attrs) {
+ public static IconicsDrawable getIconicsDrawable(Context context, AttributeSet attrs) {
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Iconics);
IconicsDrawable icon;

MODIFY
library-core/src/main/java/com/mikepenz/iconics/context/IconicsFactory.java
library-core/src/main/java/com/mikepenz/iconics/context/IconicsFactory.java
@@ -41,7 +41,7 @@ class IconicsFactory {
}
if (view instanceof ActionMenuItemView) {
- IconicsDrawable drawable = IconicsAttrsReader.readIconics(context, attrs);
+ IconicsDrawable drawable = IconicsAttrsReader.getIconicsDrawable(context, attrs);
if (drawable != null) {
((ActionMenuItemView) view).setIcon(drawable);
}
@@ -71,7 +71,7 @@ class IconicsFactory {
}
});
} else if (view instanceof ImageView) {
- IconicsDrawable drawable = IconicsAttrsReader.readIconics(context, attrs);
+ IconicsDrawable drawable = IconicsAttrsReader.getIconicsDrawable(context, attrs);
if (drawable != null) {
((ImageView) view).setImageDrawable(drawable);
}

- Optimized IconicsImageView
- Small refactoring