Skip to content

Commit c7cb1ee

Browse files
committed
Merge branch 'release/v2.2.0'
2 parents 16a2a42 + 533dc79 commit c7cb1ee

File tree

10 files changed

+335
-274
lines changed

10 files changed

+335
-274
lines changed

README.md

Lines changed: 57 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Provide additional fonts for you project, or even create your custom font with j
3939
##1. Provide the gradle dependency
4040
```gradle
4141
dependencies {
42-
compile 'com.mikepenz:iconics-core:2.1.1@aar'
42+
compile 'com.mikepenz:iconics-core:2.2.0@aar'
4343
}
4444
```
4545

@@ -55,8 +55,16 @@ compile 'com.mikepenz:typeicons-typeface:2.0.7.1@aar'
5555
compile 'com.mikepenz:entypo:1.0.0.1@aar'
5656
```
5757

58-
#Usage
58+
##3. Inject into Context (optional)
59+
Wrap the `Activity` context. This will enable automatic icon detection for `TextViews`,`Buttons`, and allow you to set icons on `ImageView`'s via xml.
60+
```java
61+
@Override
62+
protected void attachBaseContext(Context newBase) {
63+
super.attachBaseContext(IconicsContextWrapper.wrap(newBase));
64+
}
65+
```
5966

67+
#Usage
6068
##Use as drawable
6169

6270
```java
@@ -72,49 +80,52 @@ If you use the Iconics library via XML provide the icon you want to use in the f
7280
available fonts and their `fontId` can be found near the end of the README.md
7381
All icon names from the default fonts can be found via the [DEMO](https://play.google.com/store/apps/details?id=com.mikepenz.iconics.sample) application.
7482

75-
###As ImageView
76-
```xml
77-
<com.mikepenz.iconics.view.IconicsImageView
78-
android:layout_width="72dp"
79-
android:layout_height="72dp"
80-
app:iiv_color="@android:color/holo_red_dark"
81-
app:iiv_icon="gmd-favorite" />
82-
```
83-
84-
###As Text
85-
86-
To use the icon within text use the `{` icon-definer `}` syntax
87-
83+
####Notation within text
84+
Use the `{` icon-definer `}` syntax
8885
```gson
8986
Some great text with a {faw-android} font awesome icon and {met-wind} meteocons icons.
9087
```
9188

92-
###Normal Views
93-
94-
####TextView / Button
95-
If you are going to use the **Android-Iconics** on normal `TextView`s or `Buttons` you will have to overwrite
96-
the `attachBaseContext` of your Activity.
97-
98-
**Note:** If you are going to use the **Android-Iconics** manually via `new Iconics.IconicsBuilder().ctx(this)....on(tv1) you should not use this.
99-
100-
```java
101-
@Override
102-
protected void attachBaseContext(Context newBase) {
103-
super.attachBaseContext(IconicsContextWrapper.wrap(newBase));
104-
}
89+
###As ImageView (only available if you inject the context)
90+
```xml
91+
<ImageView
92+
android:layout_width="48dp"
93+
android:layout_height="48dp"
94+
app:ico_color="@color/md_red_A200"
95+
app:ico_icon="gmd-plus-circle"
96+
app:ico_size="48dp" />
97+
98+
//other possible attributes
99+
//app:ico_background_color="@android:color/transparent"
100+
//app:ico_color="@color/md_red_100"
101+
//app:ico_contour_color="@android:color/transparent"
102+
//app:ico_contour_width="0dp"
103+
//app:ico_corner_radius="0dp"
104+
//app:ico_icon="gmd-plus-circle"
105+
//app:ico_offset_x="0dp"
106+
//app:ico_offset_y="0dp"
107+
//app:ico_padding="0dp"
108+
//app:ico_size="48dp"
105109
```
106-
110+
###As TextView (only available if you inject the context)
107111
```xml
108112
<TextView
109-
android:text="{gmd-chart} Chart"
110-
android:textColor="@android:color/black"
111-
android:layout_width="wrap_content"
112-
android:layout_height="56dp"
113-
android:textSize="16sp"/>
113+
android:text="{gmd-chart} Chart"
114+
android:textColor="@android:color/black"
115+
android:layout_width="wrap_content"
116+
android:layout_height="56dp"
117+
android:textSize="16sp"/>
114118
```
115119

116-
117-
###Custom Views
120+
###Custom Views (if you do NOT inject the context)
121+
####As IconicsImageView
122+
```xml
123+
<com.mikepenz.iconics.view.IconicsImageView
124+
android:layout_width="72dp"
125+
android:layout_height="72dp"
126+
app:iiv_color="@android:color/holo_red_dark"
127+
app:iiv_icon="gmd-favorite" />
128+
```
118129

119130
####As IconicsTextView
120131
```xml
@@ -209,150 +220,18 @@ Sometimes you won't like to use the icon-key ("faw-adjust") like this, but use t
209220
```
210221

211222

212-
###Create custom fonts using [Fontello](http://fontello.com) or [IcoMoon](http://icomoon.io)
213-
214-
If you plan to use an existing icon font, one provided by your design team, or if you have an svg and want to use it as drawable just follow those simple steps.
215-
216-
####1. Create the icon font (not required if you already have one)
217-
Open [Fontello](http://fontello.com) or [IcoMoon](http://icomoon.io) and select the icons you need. Add your vectors (.svg) and then just download the font.
218-
219-
####1.2. Add the font to your project
220-
- Unpack the .zip you just downloaded and add the *.ttf to your project under `src/main/assets/fonts`
221-
- In the next step you will have to know the unicode value for the icons
222-
- this information can be found in the `fontello-codes.css` (if you used fontello)
223-
- or in the style.css (if you used icomoon)
223+
##Create custom fonts
224+
This is possible with only the *.ttf and *.css mapping file. And will take you 2 minutes.
224225

225-
####2. Implement your CustomFont
226-
- Great you got your IconFont and you know which unicode character displays which icon. Now you can create your own font with it. You have to options 2.1. or 2.2.
226+
You can get these two files by downloading a web icon font, or if you want to create your
227+
own custom icon font from *.svg files then you can use following tools:
228+
* [Fontello](http://fontello.com)
229+
* [IcoMoon](http://icomoon.io)
230+
* let me know if you find other tools.
227231

228-
#####2.1. Implement as GenericFont
229-
- To implement a GenericFont just provide the mapping before you use the Iconics. (best inside a [CustomApplication](https://github.com/mikepenz/Android-Iconics/blob/develop/app/src/main/java/com/mikepenz/iconics/sample/CustomApplication.java))
230-
231-
```java
232-
//Create a new GenericFont by defining a 3 char long fontId and by defining the path to the font (starting inside src/main/assets)
233-
GenericFont gf2 = new GenericFont("gmf", "fonts/materialdrawerfont.ttf");
234-
//now register the icons which are inside the font. Just provide the unicode value and name.
235-
//the unicode value is defined as '\e800', just add the 'u' after '\' to tell java that it's an unicode char
236-
gf2.registerIcon("person", '\ue800');
237-
gf2.registerIcon("up", '\ue801');
238-
gf2.registerIcon("down", '\ue802');
239-
//now register the created GenericFont
240-
Iconics.registerFont(gf2);
241-
```
242-
- After defining the GenericFont you can use it like this
243-
```java
244-
new IconicsDrawable(this).icon("gmf-person").sizeDp(24);
245-
```
246-
247-
#####2.2. Implement as CustomFont
248-
- A more complex but easier to use / more safe implementation is to create a CustomFont.
249-
- For a QuickStart just use the [CustomFont](https://github.com/mikepenz/Android-Iconics/blob/develop/app/src/main/java/com/mikepenz/iconics/sample/typeface/CustomFont.java) used in the Sample app
250-
- A CustomFont has to implement the `ITypeface` interface, and can then be easily used as any of the provided fonts
251-
252-
```java
253-
public class CustomFont implements ITypeface {
254-
//define the font file to use
255-
private static final String TTF_FILE = "fontello.ttf";
256-
257-
private static Typeface typeface = null;
258-
private static HashMap<String, Character> mChars;
259-
260-
//return a icon by it's key
261-
@Override
262-
public IIcon getIcon(String key) {
263-
return Icon.valueOf(key);
264-
}
265-
266-
//return all possible key unicode-character mappings
267-
@Override
268-
public HashMap<String, Character> getCharacters() {
269-
if (mChars == null) {
270-
HashMap<String, Character> aChars = new HashMap<String, Character>();
271-
for (Icon v : Icon.values()) {
272-
aChars.put(v.name(), v.character);
273-
}
274-
mChars = aChars;
275-
}
276-
277-
return mChars;
278-
}
279-
280-
/**
281-
* The Mapping Prefix to identify this font (example: fon-android -> `fon` is the mappingPrefix)
282-
* must have a length of 3
283-
*
284-
* @return mappingPrefix (length = 3)
285-
*/
286-
@Override
287-
public String getMappingPrefix() {
288-
return "fon";
289-
}
290-
291-
//return all possible icon names
292-
@Override
293-
public Collection<String> getIcons() {
294-
Collection<String> icons = new LinkedList<String>();
295-
296-
for (Icon value : Icon.values()) {
297-
icons.add(value.name());
298-
}
299-
300-
return icons;
301-
}
302-
303-
//implement all additional methods from the interface
304-
//...
305-
306-
307-
//return the font from the assets (you can take this method in most cases)
308-
@Override
309-
public Typeface getTypeface(Context context) {
310-
if (typeface == null) {
311-
try {
312-
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/" + TTF_FILE);
313-
} catch (Exception e) {
314-
return null;
315-
}
316-
}
317-
return typeface;
318-
}
319-
320-
//implement the enum containing all possible icons. each icon name is like `fontId`_`iconNamE` --> `fon_test1` maps to the icon with the unicode char \e800
321-
public static enum Icon implements IIcon {
322-
//define all possible mappings here:
323-
fon_test1('\ue800'),
324-
fon_test2('\ue801');
325-
326-
//define all methods required by the IIcon interface, you can just copy and paste those
327-
char character;
328-
Icon(char character) {
329-
this.character = character;
330-
}
331-
332-
public String getFormattedName() {
333-
return "{" + name() + "}";
334-
}
335-
336-
public char getCharacter() {
337-
return character;
338-
}
339-
340-
public String getName() {
341-
return name();
342-
}
343-
344-
// remember the typeface so we can use it later
345-
private static ITypeface typeface;
346-
347-
public ITypeface getTypeface() {
348-
if (typeface == null) {
349-
typeface = new CustomFont();
350-
}
351-
return typeface;
352-
}
353-
}
354-
}
355-
```
232+
After you got those two files, head over to the icon addon creation tool [android-iconics.mikepenz.com](http://android-iconics.mikepenz.com).
233+
Enter all the information. Add the *.ttf and *.css and click the button. It will generate and download the icon font addon as
234+
zip. (this tool is local only, no files are sent to a server, you can safely use it with any icons)
356235

357236
#ProGuard
358237
Exclude `R` from ProGuard to enable the font addon auto detection

app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
defaultConfig {
1313
minSdkVersion rootProject.ext.minSdkVersion
1414
targetSdkVersion rootProject.ext.targetSdkVersion
15-
versionCode 211
16-
versionName "2.1.1"
15+
versionCode 220
16+
versionName "2.2.0"
1717
enforceUniquePackageName false
1818
}
1919

@@ -58,8 +58,8 @@ dependencies {
5858
compile 'com.android.support:recyclerview-v7:23.1.1'
5959
compile 'com.android.support:cardview-v7:23.1.1'
6060

61-
compile('com.mikepenz:aboutlibraries:5.3.2@aar')
62-
compile('com.mikepenz:materialdrawer:4.4.6@aar') {
61+
compile('com.mikepenz:aboutlibraries:5.3.3@aar')
62+
compile('com.mikepenz:materialdrawer:4.4.7@aar') {
6363
transitive = true
6464
exclude module: "iconics-core"
6565
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<activity
2222
android:name=".AutomaticActivity"
2323
android:label="@string/title_activity_playground"
24-
android:theme="@style/MaterialDrawerTheme.Light.DarkToolbar.ActionBar" />
24+
android:theme="@style/MaterialDrawerTheme.Light.DarkToolbar" />
2525
</application>
2626

2727
</manifest>

app/src/main/java/com/mikepenz/iconics/sample/AutomaticActivity.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616

1717
package com.mikepenz.iconics.sample;
1818

19-
import android.app.Activity;
2019
import android.content.Context;
2120
import android.os.Bundle;
21+
import android.support.v7.app.AppCompatActivity;
22+
import android.support.v7.widget.Toolbar;
2223
import android.widget.TextView;
2324

2425
import com.mikepenz.iconics.context.IconicsContextWrapper;
2526

2627

27-
public class AutomaticActivity extends Activity {
28+
public class AutomaticActivity extends AppCompatActivity {
2829

2930
@Override
3031
protected void attachBaseContext(Context newBase) {
@@ -36,6 +37,11 @@ protected void onCreate(Bundle savedInstanceState) {
3637
super.onCreate(savedInstanceState);
3738
setContentView(R.layout.activity_automatic);
3839

40+
// Handle Toolbar
41+
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
42+
setSupportActionBar(toolbar);
43+
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
44+
3945
//set a new text on the textView and set the icon font on it
4046
((TextView) findViewById(R.id.test4)).setText("{gmd-favorite} GIF");
4147
}

0 commit comments

Comments
 (0)