Skip to content

Commit

Permalink
version 2.0.0-BETA-6
Browse files Browse the repository at this point in the history
- update support libs
- add font calligraphy support
  • Loading branch information
raphaelbussa committed May 18, 2017
1 parent 6d9783a commit 74c4f86
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 55 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
```
```Gradle
dependencies {
compile 'rebus:header-view:2.0.0-BETA-5'
compile 'rebus:header-view:2.0.0-BETA-6'
}
```
### How to use
Expand Down Expand Up @@ -170,6 +170,16 @@ ImageLoader.init(new ImageLoader.ImageLoaderInterface() {

});
```
#### Use custom font with Calligraphy
You can set a custom font with [Calligraphy](https://github.com/chrisjenx/Calligraphy) just add a CustomViewTypeface with HeaderView.class in CalligraphyConfig
```Java
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("Oswald-Stencbab.ttf")
.setFontAttrId(R.attr.fontPath)
.addCustomViewWithSetTypeface(HeaderView.class)
.build()
);
```
### Screen
![Screen](https://raw.githubusercontent.com/rebus007/HeaderView/master/img/screen.png)

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ dependencies {
compile project(':library')
compile "com.android.support:appcompat-v7:${var.supportLib}"
compile "com.android.support:design:${var.supportLib}"

compile 'uk.co.chrisjenx:calligraphy:2.3.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
}
Binary file added app/src/main/assets/Oswald-Stencbab.ttf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

import com.bumptech.glide.Glide;

import rebus.header.view.HeaderView;
import rebus.header.view.ImageLoader;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;

/**
* Created by raphaelbussa on 13/01/17.
Expand Down Expand Up @@ -65,6 +67,11 @@ public void loadImage(Uri url, ImageView imageView, @ImageLoader.Type int type)
}

});

CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("Oswald-Stencbab.ttf")
.setFontAttrId(R.attr.fontPath)
.addCustomViewWithSetTypeface(HeaderView.class)
.build()
);
}
}
9 changes: 8 additions & 1 deletion app/src/main/java/rebus/header/view/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package rebus.header.view.sample;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.content.ContextCompat;
Expand All @@ -40,6 +41,7 @@
import rebus.header.view.HeaderView;
import rebus.header.view.Item;
import rebus.header.view.Profile;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;

public class MainActivity extends AppCompatActivity {

Expand Down Expand Up @@ -119,7 +121,7 @@ public void run() {
headerView.addProfile(profile, profile2, profile3, profile4);
headerView.addDialogItem(item, item2);
headerView.setShowAddButton(true);
headerView.setAddIconDrawable(R.drawable.ic_action_settings);
//headerView.setAddIconDrawable(R.drawable.ic_action_settings);
headerView.setDialogTitle("Choose account");
headerView.setShowArrow(true);
headerView.setOnHeaderClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -174,4 +176,9 @@ public boolean onAdd() {

}

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}

}
15 changes: 9 additions & 6 deletions app/src/main/res/layout/header_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@
android:id="@+id/header_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hv_add_icon="@drawable/ic_action_settings"
app:hv_add_status_bar_height="true"
app:hv_background_color="@color/colorPrimaryDark"
app:hv_dialog_title="@string/account"
app:hv_highlight_color="@color/colorAccent"
app:hv_profile_avatar="@drawable/ic_avatar_batman"
app:hv_profile_background="@drawable/ic_bg_batman"
app:hv_profile_email="[email protected]"
app:hv_profile_username="Bruce Wayne"
app:hv_show_add_button="true"
app:hv_show_arrow="true"
app:hv_show_gradient="true"
app:hv_style="normal"
app:hv_theme="light" />
app:hv_theme="light" />

<!--
app:hv_add_icon="@drawable/ic_action_settings"
app:hv_profile_avatar="@drawable/ic_avatar_batman"
app:hv_profile_background="@drawable/ic_bg_batman"
app:hv_profile_email="[email protected]"
app:hv_profile_username="Bruce Wayne"
-->
54 changes: 18 additions & 36 deletions app/src/main/res/menu/drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,40 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
<item
android:icon="@android:drawable/ic_menu_search"
android:title="@string/nav_search" />
android:title="@string/nav_settings" />
</group>
</menu>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">Header View</string>
<string name="nav_search">Search</string>
<string name="nav_settings">Settings</string>
<string name="account">Account</string>
</resources>
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ buildscript {
ext {
var = [
compileSdk: 25,
buildTools: "25.0.2",
buildTools: "25.0.3",
minSdk : 11,
targetSdk : 25,
version : "2.0.0-BETA-5",
supportLib: "25.1.1"
version : "2.0.0-BETA-6",
supportLib: "25.3.1"
]
}

repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.novoda:bintray-release:0.4.0'
}
}
Expand Down
14 changes: 13 additions & 1 deletion library/src/main/java/rebus/header/view/HeaderView.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public class HeaderView extends ViewGroup implements ProfileChooserCallback {
private FragmentManager hvFragmentManager;
private ProfileChooser profileChooser;

private Typeface typeface;

public HeaderView(Context context) {
super(context);
init(null, 0);
Expand Down Expand Up @@ -626,9 +628,10 @@ public void onClick(View v) {
if (hvFragmentManager != null) {
ProfileChooserFragment profileChooserFragment = ProfileChooserFragment.newInstance(profileSparseArray, itemArrayList, hvHighlightColor, hvShowAddButton, hvDialogTitle, hvAddIconDrawable);
profileChooserFragment.setCallback(HeaderView.this);
profileChooserFragment.setTypeface(typeface);
profileChooserFragment.show(hvFragmentManager, ProfileChooserFragment.FRAGMENT_TAG);
} else {
profileChooser = new ProfileChooser(getContext(), profileSparseArray, itemArrayList, hvHighlightColor, hvShowAddButton, hvDialogTitle, hvAddIconDrawable);
profileChooser = new ProfileChooser(getContext(), profileSparseArray, itemArrayList, hvHighlightColor, hvShowAddButton, hvDialogTitle, hvAddIconDrawable, typeface);
profileChooser.setCallback(HeaderView.this);
profileChooser.show();
}
Expand Down Expand Up @@ -809,6 +812,7 @@ protected void onRestoreInstanceState(Parcelable state) {
ProfileChooserFragment profileChooserFragment = (ProfileChooserFragment) hvFragmentManager.findFragmentByTag(ProfileChooserFragment.FRAGMENT_TAG);
if (profileChooserFragment != null) {
profileChooserFragment.setCallback(HeaderView.this);
profileChooserFragment.updateTypeface(typeface);
}
}
super.onRestoreInstanceState(state);
Expand Down Expand Up @@ -844,4 +848,12 @@ public boolean onAdd() {
public @interface Theme {
}

@SuppressWarnings("unused")
public void setTypeface(Typeface tf) {
typeface = tf;
username.setTypeface(tf);
email.setTypeface(tf);
invalidate();
}

}
6 changes: 5 additions & 1 deletion library/src/main/java/rebus/header/view/ProfileChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Typeface;
import android.util.SparseArray;
import android.view.Gravity;
import android.view.View;
Expand All @@ -48,7 +49,7 @@ class ProfileChooser extends Dialog {
private ProfileChooserCallback callback;

@SuppressLint("RtlHardcoded")
ProfileChooser(Context context, SparseArray<Profile> profileSparseArray, ArrayList<Item> items, int accent, boolean showAdd, String titleValue, int icon) {
ProfileChooser(Context context, SparseArray<Profile> profileSparseArray, ArrayList<Item> items, int accent, boolean showAdd, String titleValue, int icon, Typeface tf) {
super(context);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.hw_account_chooser);
Expand All @@ -61,6 +62,7 @@ class ProfileChooser extends Dialog {
title.setTextColor(Utils.getTextColorPrimary(context));
title.setText(titleValue);
title.setGravity(Gravity.CENTER_VERTICAL | (hvIsRTL ? Gravity.RIGHT : Gravity.LEFT));
if (tf != null) title.setTypeface(tf);
add.setVisibility(showAdd ? View.VISIBLE : View.INVISIBLE);
add.setColorFilter(Utils.getTextColorPrimary(context));
add.setBackgroundResource(Utils.selectableItemBackgroundBorderless(context));
Expand All @@ -78,6 +80,7 @@ public void onClick(View v) {
Profile profile = profileSparseArray.valueAt(i);
if (profile.getId() != 1) {
RowProfileView profileView = new RowProfileView(context);
profileView.setTypeface(tf);
profileView.setProfile(profile, i == 0);
profileView.setAccent(accent);
profileView.setOnClickListener(new View.OnClickListener() {
Expand All @@ -99,6 +102,7 @@ public void onClick(View v) {
for (Item item : items) {
TextView textView = new TextView(context);
textView.setText(item.getTitle());
if (tf != null) textView.setTypeface(tf);
textView.setTag(item.getId());
textView.setBackgroundResource(Utils.selectableItemBackground(context));
textView.setPadding(padding, padding / 2, padding, padding / 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import android.annotation.SuppressLint;
import android.app.DialogFragment;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.SparseArray;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class ProfileChooserFragment extends DialogFragment {
private ImageView add;

private ProfileChooserCallback callback;
private Typeface typeface;
private boolean hvIsRTL;

public static ProfileChooserFragment newInstance(SparseArray<Profile> profileSparseArray, ArrayList<Item> items, int accent, boolean showAdd, String titleValue, int icon) {
Expand Down Expand Up @@ -97,6 +99,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
title.setTextColor(Utils.getTextColorPrimary(getActivity()));
title.setText(titleValue);
title.setGravity(Gravity.CENTER_VERTICAL | (hvIsRTL ? Gravity.RIGHT : Gravity.LEFT));
if (typeface != null) title.setTypeface(typeface);
add.setVisibility(showAdd ? View.VISIBLE : View.INVISIBLE);
add.setColorFilter(Utils.getTextColorPrimary(getActivity()));
add.setBackgroundResource(Utils.selectableItemBackgroundBorderless(getActivity()));
Expand All @@ -115,6 +118,7 @@ public void onClick(View v) {
Profile profile = profileSparseArray.valueAt(i);
if (profile.getId() != 1) {
RowProfileView profileView = new RowProfileView(getActivity());
profileView.setTypeface(typeface);
profileView.setProfile(profile, i == 0);
profileView.setAccent(accent);
profileView.setOnClickListener(new View.OnClickListener() {
Expand All @@ -138,6 +142,7 @@ public void onClick(View v) {
for (Item item : items) {
TextView textView = new TextView(getActivity());
textView.setText(item.getTitle());
if (typeface != null) textView.setTypeface(typeface);
textView.setTag(item.getId());
textView.setBackgroundResource(Utils.selectableItemBackground(getActivity()));
textView.setPadding(padding, padding / 2, padding, padding / 2);
Expand All @@ -163,4 +168,27 @@ public void setCallback(ProfileChooserCallback callback) {
this.callback = callback;
}

public void updateTypeface(Typeface tf) {
if (tf == null) return;
setTypeface(tf);
for (int i = 0; i < linearLayout.getChildCount(); i++) {
View view = linearLayout.getChildAt(i);
if (view instanceof RowProfileView) {
((RowProfileView) view).setTypeface(typeface);
}
}
for (int i = 0; i < linearLayout1.getChildCount(); i++) {
View view = linearLayout1.getChildAt(i);
if (view instanceof TextView) {
((TextView) view).setTypeface(typeface);
}
}
title.setTypeface(typeface);
}

public void setTypeface(Typeface tf) {
if (tf == null) return;
typeface = tf;
}

}
Loading

0 comments on commit 74c4f86

Please sign in to comment.