Code cleanup
Used more pretty way for spacing items in RecyclerView
MODIFY
app/build.gradle
app/build.gradle
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
//wrap with try and catch so the build is working even if the signing stuff is missing
try {
apply from: '../../../signing.gradle'
-} catch (ex) {
+} catch (ignored) {
}
android {
@@ -14,8 +14,6 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 29301
versionName "2.9.3"
-
- multiDexEnabled true
}
buildTypes {
@@ -24,14 +22,14 @@ android {
versionNameSuffix = "-DEBUG"
try {
signingConfig signingConfigs.debug
- } catch (ex) {
+ } catch (ignored) {
}
minifyEnabled false
}
release {
try {
signingConfig signingConfigs.release
- } catch (ex) {
+ } catch (ignored) {
}
zipAlignEnabled true
minifyEnabled false

MODIFY
app/src/main/java/com/mikepenz/iconics/sample/CustomApplication.java
app/src/main/java/com/mikepenz/iconics/sample/CustomApplication.java
package com.mikepenz.iconics.sample;
-import android.support.multidex.MultiDexApplication;
+import android.app.Application;
import com.mikepenz.iconics.Iconics;
import com.mikepenz.iconics.sample.typeface.CustomFont;
import com.mikepenz.iconics.typeface.GenericFont;
-public class CustomApplication extends MultiDexApplication {
+public class CustomApplication extends Application {
@Override
public void onCreate() {

MODIFY
app/src/main/java/com/mikepenz/iconics/sample/IconsFragment.java
app/src/main/java/com/mikepenz/iconics/sample/IconsFragment.java
package com.mikepenz.iconics.sample;
+import android.content.ClipData;
+import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Color;
-import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
@@ -38,12 +40,12 @@ import java.util.Random;
public class IconsFragment extends Fragment {
private static final String FONT_NAME = "FONT_NAME";
- private ArrayList<IconItem> icons = new ArrayList<>();
+ private ArrayList<IconItem> mIcons = new ArrayList<>();
private FastItemAdapter<IconItem> mAdapter;
- private boolean randomize;
- private String search;
- private PopupWindow popup;
- private Random random = new Random();
+ private boolean mRandomize;
+ private String mSearch;
+ private PopupWindow mPopup;
+ private Random mRandom = new Random();
public static IconsFragment newInstance(String fontName) {
Bundle bundle = new Bundle();
@@ -56,24 +58,25 @@ public class IconsFragment extends Fragment {
}
public void randomize(boolean randomize) {
- this.randomize = randomize;
- if (this.mAdapter != null) {
- this.mAdapter.notifyAdapterDataSetChanged();
+ mRandomize = randomize;
+ if (mAdapter != null) {
+ mAdapter.notifyAdapterDataSetChanged();
}
}
@Override
- public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.icons_fragment, null, false);
}
@Override
- public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Init and Setup RecyclerView
- RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
+ RecyclerView recyclerView = view.findViewById(R.id.list);
recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
+ recyclerView.addItemDecoration(new SpaceItemDecoration());
//animator not yet working
recyclerView.setItemAnimator(new DefaultItemAnimator());
mAdapter = new FastItemAdapter<>();
@@ -87,16 +90,16 @@ public class IconsFragment extends Fragment {
if (iTypeface.getFontName().equalsIgnoreCase(fontName)) {
if (iTypeface.getIcons() != null) {
for (String icon : iTypeface.getIcons()) {
- icons.add(new IconItem(icon));
+ mIcons.add(new IconItem(icon));
}
- mAdapter.set(icons);
+ mAdapter.set(mIcons);
break;
}
}
}
}
//filter if a search param was provided
- onSearch(search);
+ onSearch(mSearch);
}
private void configAdapter() {
@@ -106,8 +109,8 @@ public class IconsFragment extends Fragment {
public boolean onTouch(View v, MotionEvent motionEvent, IAdapter<IconItem> adapter, IconItem item, int position) {
int a = motionEvent.getAction();
if (a == MotionEvent.ACTION_DOWN) {
- if (popup != null && popup.isShowing()) {
- popup.dismiss();
+ if (mPopup != null && mPopup.isShowing()) {
+ mPopup.dismiss();
}
IconicsDrawable icon = new IconicsDrawable(v.getContext()).icon(item.getIcon()).sizeDp(144).paddingDp(8).backgroundColor(Color.parseColor("#DDFFFFFF")).roundedCornersDp(12);
ImageView imageView = new ImageView(v.getContext());
@@ -115,21 +118,16 @@ public class IconsFragment extends Fragment {
icon
);
int size = (int) UIUtils.convertDpToPixel(144, v.getContext());
- popup = new PopupWindow(imageView, size, size);
- popup.showAsDropDown(v);
+ mPopup = new PopupWindow(imageView, size, size);
+ mPopup.showAsDropDown(v);
//copy to clipboard
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
- android.text.ClipboardManager clipboard = (android.text.ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
- clipboard.setText(icon.getIcon().getFormattedName());
- } else {
- android.content.ClipboardManager clipboard = (android.content.ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
- android.content.ClipData clip = android.content.ClipData.newPlainText("Android-Iconics icon", icon.getIcon().getFormattedName());
+ ClipboardManager clipboard = (ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
+ ClipData clip = ClipData.newPlainText("Android-Iconics icon", icon.getIcon().getFormattedName());
clipboard.setPrimaryClip(clip);
- }
} else if (a == MotionEvent.ACTION_UP || a == MotionEvent.ACTION_CANCEL || a == MotionEvent.ACTION_OUTSIDE) {
- if (popup != null && popup.isShowing()) {
- popup.dismiss();
+ if (mPopup != null && mPopup.isShowing()) {
+ mPopup.dismiss();
}
}
return false;
@@ -150,18 +148,18 @@ public class IconsFragment extends Fragment {
//as we overwrite the default listener
item.bindView(holder, payloads);
- if (randomize) {
+ if (mRandomize) {
holder.image.getIcon().colorRes(getRandomColor(position));
- holder.image.getIcon().paddingDp(random.nextInt(12));
+ holder.image.getIcon().paddingDp(mRandom.nextInt(12));
- holder.image.getIcon().contourWidthDp(random.nextInt(2));
+ holder.image.getIcon().contourWidthDp(mRandom.nextInt(2));
holder.image.getIcon().contourColor(getRandomColor(position - 2));
- int y = random.nextInt(10);
+ int y = mRandom.nextInt(10);
if (y % 4 == 0) {
holder.image.getIcon().backgroundColorRes(getRandomColor(position - 4));
- holder.image.getIcon().roundedCornersDp(2 + random.nextInt(10));
+ holder.image.getIcon().roundedCornersDp(2 + mRandom.nextInt(10));
}
}
}
@@ -198,15 +196,15 @@ public class IconsFragment extends Fragment {
}
void onSearch(String s) {
- search = s;
+ mSearch = s;
if (mAdapter != null) {
if (TextUtils.isEmpty(s)) {
mAdapter.clear();
- mAdapter.setNewList(icons);
+ mAdapter.setNewList(mIcons);
} else {
AbstractList<IconItem> tmpList = new ArrayList<>();
- for (IconItem icon : icons) {
+ for (IconItem icon : mIcons) {
if (icon.getIcon().toLowerCase().contains(s.toLowerCase())) {
tmpList.add(icon);
}

ADD
app/src/main/java/com/mikepenz/iconics/sample/SpaceItemDecoration.java
+package com.mikepenz.iconics.sample;
+
+import android.content.res.Resources;
+import android.graphics.Rect;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+
+/**
+ * @author pa.gulko zTrap (28.10.2017)
+ */
+public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
+
+ @Override
+ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
+ int space = (int) Math.ceil(8 * Resources.getSystem().getDisplayMetrics().density); // 8 dp
+ int position = parent.getChildAdapterPosition(view);
+ if (position < 2) {
+ outRect.top = space;
+ }
+ if ((position + 1) % 2 == 0) {
+ outRect.right = space;
+ }
+ outRect.bottom = outRect.left = space;
+ }
+}

MODIFY
app/src/main/java/com/mikepenz/iconics/sample/item/IconItem.java
app/src/main/java/com/mikepenz/iconics/sample/item/IconItem.java
@@ -71,8 +71,8 @@ public class IconItem extends AbstractItem<IconItem, IconItem.ViewHolder> {
ViewHolder(final View itemView) {
super(itemView);
- name = (TextView) itemView.findViewById(R.id.name);
- image = (IconicsImageView) itemView.findViewById(R.id.icon);
+ name = itemView.findViewById(R.id.name);
+ image = itemView.findViewById(R.id.icon);
}
}
}

MODIFY
app/src/main/java/com/mikepenz/iconics/sample/typeface/CustomFont.java
app/src/main/java/com/mikepenz/iconics/sample/typeface/CustomFont.java
@@ -107,7 +107,7 @@ public class CustomFont implements ITypeface {
return typeface;
}
- public static enum Icon implements IIcon {
+ public enum Icon implements IIcon {
fon_test1('\ue800'),
fon_test2('\ue801');

MODIFY
app/src/main/res/layout/activity_main.xml
app/src/main/res/layout/activity_main.xml
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MyActivity">
+ android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"

MODIFY
app/src/main/res/layout/activity_playground.xml
app/src/main/res/layout/activity_playground.xml
android:layout_width="72dp"
android:layout_height="72dp"
android:padding="24dp"
- app:iiv_icon="@string/faw_android"/>
+ app:iiv_icon="faw_android"/>
<com.mikepenz.iconics.view.IconicsImageView
android:layout_width="72dp"
android:layout_height="72dp"
app:iiv_color="@color/md_red_200"
- app:iiv_icon="@string/gmd_favorite"
+ app:iiv_icon="gmd_favorite"
app:iiv_background_color="@android:color/black"
app:iiv_background_contour_color="@android:color/holo_red_light"
android:layout_height="72dp"
android:background="#ffcccc"
app:iiv_color="#666666"
- app:iiv_icon="@string/faw_android"/>
+ app:iiv_icon="faw_android"/>
<!-- android:iiv_size -->
<com.mikepenz.iconics.view.IconicsImageView
android:layout_height="72dp"
android:background="#ccffcc"
app:iiv_color="#666666"
- app:iiv_icon="@string/faw_android"
+ app:iiv_icon="faw_android"
app:iiv_size="16dp"/>
<!-- android:iiv_padding -->
android:layout_height="72dp"
android:background="#ccccff"
app:iiv_color="#666666"
- app:iiv_icon="@string/faw_android"
+ app:iiv_icon="faw_android"
app:iiv_padding="16dp"/>
<!-- android:padding -->
android:background="#ffffcc"
android:padding="16dp"
app:iiv_color="#666666"
- app:iiv_icon="@string/faw_android"/>
+ app:iiv_icon="faw_android"/>
</LinearLayout>
<!--endregion-->
android:textColor="@android:color/black"
app:iiv_all_color="@color/md_amber_300"
- app:iiv_all_icon="@string/gmd_account_circle"
+ app:iiv_all_icon="gmd_account_circle"
app:iiv_all_size="24dp"/>
<com.mikepenz.iconics.view.IconicsTextView
android:textColor="@android:color/black"
app:iiv_all_color="@color/md_amber_300"
- app:iiv_all_icon="@string/gmd_account_circle"
+ app:iiv_all_icon="gmd_account_circle"
app:iiv_all_size="24dp"/>
<com.mikepenz.iconics.view.IconicsTextView
android:layout_height="wrap_content"
android:text="IconicsButton with side-drawables"
app:iiv_all_color="@color/md_red_600"
- app:iiv_all_icon="@string/faw_android"
+ app:iiv_all_icon="faw_android"
app:iiv_all_size="24dp"/>
<!--endregion-->
android:layout_width="48dp"
android:layout_height="48dp"
app:iiv_color="@color/md_red_200"
- app:iiv_icon="@string/gmd_favorite"/>
+ app:iiv_icon="gmd_favorite"/>
</LinearLayout>
<!--endregion-->
android:padding="5dp"
app:iiv_checked_color="@color/primary"
- app:iiv_checked_icon="@string/gmd_star"
+ app:iiv_checked_icon="gmd_star"
app:iiv_checked_size="24dp"
app:iiv_unchecked_color="@color/primary"
- app:iiv_unchecked_icon="@string/gmd_star_border"
+ app:iiv_unchecked_icon="gmd_star_border"
app:iiv_unchecked_size="24dp"/>
<com.mikepenz.iconics.view.IconicsCheckBox
android:padding="5dp"
app:iiv_checked_color="@color/primary"
- app:iiv_checked_icon="@string/gmd_check_box"
+ app:iiv_checked_icon="gmd_check_box"
app:iiv_checked_size="24dp"
app:iiv_unchecked_color="@color/primary"
- app:iiv_unchecked_icon="@string/gmd_check_box_outline_blank"
+ app:iiv_unchecked_icon="gmd_check_box_outline_blank"
app:iiv_unchecked_size="24dp"/>
<com.mikepenz.iconics.view.IconicsCheckBox
android:padding="5dp"
app:iiv_checked_color="@color/primary"
- app:iiv_checked_icon="@string/gmd_play_circle_filled"
+ app:iiv_checked_icon="gmd_play_circle_filled"
app:iiv_checked_size="24dp"
app:iiv_unchecked_color="@color/primary"
- app:iiv_unchecked_icon="@string/gmd_play_circle_outline"
+ app:iiv_unchecked_icon="gmd_play_circle_outline"
app:iiv_unchecked_size="24dp"/>
</LinearLayout>
<!--endregion-->
android:textColor="@android:color/black"
android:padding="5dp"
- app:iiv_start_icon="@string/gmd_error_outline"
+ app:iiv_start_icon="gmd_error_outline"
app:iiv_start_color="@color/colorAccent"
app:iiv_start_size="24dp"
- app:iiv_start_checked_icon="@string/gmd_error"
+ app:iiv_start_checked_icon="gmd_error"
app:iiv_start_checked_color="@color/colorAccent"
app:iiv_start_checked_size="24dp"/>
android:textColor="@android:color/black"
android:padding="5dp"
- app:iiv_top_icon="@string/gmd_help_outline"
+ app:iiv_top_icon="gmd_help_outline"
app:iiv_top_color="@color/md_deep_orange_400"
app:iiv_top_size="24dp"
- app:iiv_top_checked_icon="@string/gmd_help"
+ app:iiv_top_checked_icon="gmd_help"
app:iiv_top_checked_color="@color/md_deep_orange_400"
app:iiv_top_checked_size="24dp"/>
android:textColor="@android:color/black"
android:padding="5dp"
- app:iiv_end_icon="@string/gmd_info_outline"
+ app:iiv_end_icon="gmd_info_outline"
app:iiv_end_color="@color/md_cyan_800"
app:iiv_end_size="24dp"
- app:iiv_end_checked_icon="@string/gmd_info"
+ app:iiv_end_checked_icon="gmd_info"
app:iiv_end_checked_color="@color/md_cyan_800"
app:iiv_end_checked_size="24dp"/>
android:textColor="@android:color/black"
android:padding="5dp"
- app:iiv_bottom_icon="@string/gmd_add_circle_outline"
+ app:iiv_bottom_icon="gmd_add_circle_outline"
app:iiv_bottom_color="@color/md_blue_grey_300"
app:iiv_bottom_size="24dp"
- app:iiv_bottom_checked_icon="@string/gmd_add_circle"
+ app:iiv_bottom_checked_icon="gmd_add_circle"
app:iiv_bottom_checked_color="@color/md_blue_grey_300"
app:iiv_bottom_checked_size="24dp"/>
app:iiv_all_size="24dp"
app:iiv_all_checked_size="24dp"
- app:iiv_start_icon="@string/gmd_error_outline"
+ app:iiv_start_icon="gmd_error_outline"
app:iiv_start_color="@color/colorAccent"
- app:iiv_start_checked_icon="@string/gmd_error"
+ app:iiv_start_checked_icon="gmd_error"
app:iiv_start_checked_color="@color/colorAccent"
- app:iiv_top_icon="@string/gmd_help_outline"
+ app:iiv_top_icon="gmd_help_outline"
app:iiv_top_color="@color/md_deep_orange_400"
- app:iiv_top_checked_icon="@string/gmd_help"
+ app:iiv_top_checked_icon="gmd_help"
app:iiv_top_checked_color="@color/md_deep_orange_400"
- app:iiv_end_icon="@string/gmd_info_outline"
+ app:iiv_end_icon="gmd_info_outline"
app:iiv_end_color="@color/md_cyan_800"
- app:iiv_end_checked_icon="@string/gmd_info"
+ app:iiv_end_checked_icon="gmd_info"
app:iiv_end_checked_color="@color/md_cyan_800"
- app:iiv_bottom_icon="@string/gmd_add_circle_outline"
+ app:iiv_bottom_icon="gmd_add_circle_outline"
app:iiv_bottom_color="@color/md_blue_grey_300"
- app:iiv_bottom_checked_icon="@string/gmd_add_circle"
+ app:iiv_bottom_checked_icon="gmd_add_circle"
app:iiv_bottom_checked_color="@color/md_blue_grey_300"/>
</LinearLayout>
<!--endregion-->

MODIFY
app/src/main/res/layout/icons_fragment.xml
app/src/main/res/layout/icons_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
-<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
+<android.support.v7.widget.RecyclerView
+ xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
- android:padding="8dp" />
\ No newline at end of file
+ android:scrollbars="vertical"/>
\ No newline at end of file

MODIFY
app/src/main/res/menu/menu_playground.xml
app/src/main/res/menu/menu_playground.xml
android:title="Item 1"
app:showAsAction="always"
app:iiv_color="@android:color/white"
- app:iiv_icon="@string/gmd_favorite"
+ app:iiv_icon="gmd_favorite"
app:iiv_size="24dp"/>
<item
android:title="Item 2"
app:showAsAction="always"
app:iiv_color="@android:color/white"
- app:iiv_icon="@string/gmd_star"
+ app:iiv_icon="gmd_star"
app:iiv_size="24dp"/>
</menu>

MODIFY
fontawesome-typeface-library/src/main/java/com/mikepenz/fontawesome_typeface_library/FontAwesome.java
fontawesome-typeface-library/src/main/java/com/mikepenz/fontawesome_typeface_library/FontAwesome.java
@@ -126,7 +126,7 @@ public class FontAwesome implements ITypeface {
return typeface;
}
- public static enum Icon implements IIcon {
+ public enum Icon implements IIcon {
faw_glass('\uf000'),
faw_music('\uf001'),
faw_search('\uf002'),

MODIFY
library-core/src/main/java/com/mikepenz/iconics/typeface/IIcon.java
library-core/src/main/java/com/mikepenz/iconics/typeface/IIcon.java
@@ -20,11 +20,11 @@ package com.mikepenz.iconics.typeface;
* Created by mikepenz on 06.11.14.
*/
public interface IIcon {
- public String getFormattedName();
+ String getFormattedName();
- public String getName();
+ String getName();
- public char getCharacter();
+ char getCharacter();
- public ITypeface getTypeface();
+ ITypeface getTypeface();
}

MODIFY
library-core/src/main/java/com/mikepenz/iconics/typeface/ITypeface.java
library-core/src/main/java/com/mikepenz/iconics/typeface/ITypeface.java
@@ -27,9 +27,9 @@ import java.util.HashMap;
*/
public interface ITypeface {
- public IIcon getIcon(String key);
+ IIcon getIcon(String key);
- public HashMap<String, Character> getCharacters();
+ HashMap<String, Character> getCharacters();
/**
* The Mapping Prefix to identify this font
@@ -37,26 +37,26 @@ public interface ITypeface {
*
* @return mappingPrefix (length = 3)
*/
- public String getMappingPrefix();
+ String getMappingPrefix();
- public String getFontName();
+ String getFontName();
- public String getVersion();
+ String getVersion();
- public int getIconCount();
+ int getIconCount();
- public Collection<String> getIcons();
+ Collection<String> getIcons();
- public String getAuthor();
+ String getAuthor();
- public String getUrl();
+ String getUrl();
- public String getDescription();
+ String getDescription();
- public String getLicense();
+ String getLicense();
- public String getLicenseUrl();
+ String getLicenseUrl();
- public Typeface getTypeface(Context ctx);
+ Typeface getTypeface(Context ctx);
}

MODIFY
material-design-iconic-typeface-library/src/main/java/com/mikepenz/material_design_iconic_typeface_library/MaterialDesignIconic.java
material-design-iconic-typeface-library/src/main/java/com/mikepenz/material_design_iconic_typeface_library/MaterialDesignIconic.java
@@ -120,7 +120,7 @@ public class MaterialDesignIconic implements ITypeface {
return typeface;
}
- public static enum Icon implements IIcon {
+ public enum Icon implements IIcon {
//Google material design
gmi_3d_rotation('\uf101'),
gmi_airplane_off('\uf102'),

- Code cleanup
- Used more pretty way for spacing items in RecyclerView