|
| 1 | +# Header View |
| 2 | + |
| 3 | +[](https://gitter.im/rebus007/HeaderView?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
| 4 | +[  ](https://bintray.com/raphaelbussa/maven/header-view/_latestVersion) [](http://android-arsenal.com/details/1/2123) |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +This is a view for NavigationView in android.support.design library |
| 9 | + |
| 10 | +### Import |
| 11 | +At the moment the library is in my personal maven repo |
| 12 | +```Gradle |
| 13 | +repositories { |
| 14 | + maven { |
| 15 | + url 'http://dl.bintray.com/raphaelbussa/maven' |
| 16 | + } |
| 17 | +} |
| 18 | +``` |
| 19 | +```Gradle |
| 20 | +dependencies { |
| 21 | + compile 'rebus:header-view:2.0.7' |
| 22 | +} |
| 23 | +``` |
| 24 | +### How to use |
| 25 | +#### Via XML |
| 26 | +Create a layout named like this header_drawer.xml |
| 27 | +```XML |
| 28 | +<rebus.header.view.HeaderView xmlns:android="http://schemas.android.com/apk/res/android" |
| 29 | + xmlns:app="http://schemas.android.com/apk/res-auto" |
| 30 | + android:id="@+id/header_view" |
| 31 | + android:layout_width="match_parent" |
| 32 | + android:layout_height="wrap_content" |
| 33 | + app:hv_add_icon="@drawable/ic_action_settings" |
| 34 | + app:hv_add_status_bar_height="true" |
| 35 | + app:hv_background_color="@color/colorPrimaryDark" |
| 36 | + app:hv_dialog_title="@string/account" |
| 37 | + app:hv_highlight_color="@color/colorAccent" |
| 38 | + app:hv_profile_avatar="@drawable/ic_placeholder" |
| 39 | + app:hv_profile_background="@drawable/ic_placeholder_bg" |
| 40 | + app:hv_profile_email="batman@gotham.city" |
| 41 | + app:hv_profile_username="Bruce Wayne" |
| 42 | + app:hv_show_add_button="true" |
| 43 | + app:hv_show_arrow="true" |
| 44 | + app:hv_show_gradient="true" |
| 45 | + app:hv_style="normal" |
| 46 | + app:hv_theme="light" /> |
| 47 | +``` |
| 48 | +And in your NavigationView |
| 49 | + |
| 50 | +```XML |
| 51 | +<android.support.design.widget.NavigationView |
| 52 | + android:id="@+id/nav_view" |
| 53 | + android:layout_width="wrap_content" |
| 54 | + android:layout_height="match_parent" |
| 55 | + android:layout_gravity="start" |
| 56 | + app:headerLayout="@layout/header_drawer" |
| 57 | + app:menu="@menu/drawer" /> |
| 58 | +``` |
| 59 | +#### Manage Profiles |
| 60 | +The new HeaderView manage different profile and a new profile chooser inspired from YouTube android app |
| 61 | +- Create a profile |
| 62 | +```Java |
| 63 | +Profile profile = new Profile.Builder() |
| 64 | + .setId(2) |
| 65 | + .setUsername("Raphaël Bussa") |
| 66 | + .setEmail("raphaelbussa@gmail.com") |
| 67 | + .setAvatar("https://github.com/rebus007.png?size=512") |
| 68 | + .setBackground("https://images.unsplash.com/photo-1473220464492-452fb02e6221?dpr=2&auto=format&fit=crop&w=767&h=512&q=80&cs=tinysrgb&crop=") |
| 69 | + .build(); |
| 70 | +``` |
| 71 | +- Add a profile |
| 72 | +```Java |
| 73 | +headerView.addProfile(profile); |
| 74 | +``` |
| 75 | +- Set a profile active |
| 76 | +```Java |
| 77 | +headerView.setProfileActive(2); |
| 78 | +``` |
| 79 | +- Remove a profile |
| 80 | +```Java |
| 81 | +headerView.removeProfile(2); |
| 82 | +``` |
| 83 | +- Get actual active profile |
| 84 | +```Java |
| 85 | +int activeProfileId = headerView.getProfileActive(); |
| 86 | +``` |
| 87 | + |
| 88 | +#### Customize Profile Chooser |
| 89 | +You can also customize the profile chooser |
| 90 | +- Add bottom items |
| 91 | +```Java |
| 92 | +Item item = new Item.Builder() |
| 93 | + .setId(1) |
| 94 | + .setTitle("Remove all profile") |
| 95 | + .build(); |
| 96 | + |
| 97 | +headerView.addDialogItem(item); |
| 98 | +``` |
| 99 | +- HighlightColor in dialog |
| 100 | +``` |
| 101 | +headerView.setHighlightColor(ContextCompat.getColor(this, R.color.colorAccent)); |
| 102 | +app:hv_highlight_color="@color/colorAccent" |
| 103 | +``` |
| 104 | +- Change dialog title |
| 105 | +``` |
| 106 | +headerView.setDialogTitle("Choose account"); |
| 107 | +app:hv_dialog_title="Dialog title" |
| 108 | +``` |
| 109 | +- Change dialog top icon |
| 110 | +``` |
| 111 | +headerView.setAddIconDrawable(R.drawable.ic_action_settings); |
| 112 | +app:hv_add_icon="@drawable/ic_action_settings" |
| 113 | +``` |
| 114 | +- Or hide dialog top icon |
| 115 | +``` |
| 116 | +headerView.setShowAddButton(true); |
| 117 | +app:hv_show_add_button="true" |
| 118 | +``` |
| 119 | +- Dismiss profile chooser dialog |
| 120 | +```Java |
| 121 | +headerView.dismissProfileChooser(); |
| 122 | +``` |
| 123 | +#### Callback |
| 124 | +```Java |
| 125 | +headerView.setCallback(new HeaderCallback() { |
| 126 | + |
| 127 | + @Override |
| 128 | + public boolean onSelect(int id, boolean isActive) { |
| 129 | + //return profile id selected and if is the active profile |
| 130 | + return true; //true for close the dialog, false for do nothing |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public boolean onItem(int id) { |
| 135 | + //return witch buttom item is selected |
| 136 | + return true; //true for close the dialog, false for do nothing |
| 137 | + } |
| 138 | + |
| 139 | + @Override |
| 140 | + public boolean onAdd() { |
| 141 | + return true; //true for close the dialog, false for do nothing |
| 142 | + } |
| 143 | +}); |
| 144 | +``` |
| 145 | +#### Loading image from network |
| 146 | +Just add this in your class Application (of course you can use your preferred libs for load images) |
| 147 | +```Java |
| 148 | +ImageLoader.init(new ImageLoader.ImageLoaderInterface() { |
| 149 | + @Override |
| 150 | + public void loadImage(Uri url, ImageView imageView, @ImageLoader.Type int type) { |
| 151 | + switch (type) { |
| 152 | + case ImageLoader.AVATAR: |
| 153 | + Glide.with(imageView.getContext()) |
| 154 | + .load(url) |
| 155 | + .asBitmap() |
| 156 | + .placeholder(R.drawable.ic_placeholder) |
| 157 | + .error(R.drawable.ic_placeholder) |
| 158 | + .into(imageView); |
| 159 | + break; |
| 160 | + case ImageLoader.HEADER: |
| 161 | + Glide.with(imageView.getContext()) |
| 162 | + .load(url) |
| 163 | + .asBitmap() |
| 164 | + .placeholder(R.drawable.ic_placeholder_bg) |
| 165 | + .error(R.drawable.ic_placeholder_bg) |
| 166 | + .into(imageView); |
| 167 | + break; |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | +}); |
| 172 | +``` |
| 173 | +#### Use custom font with Calligraphy |
| 174 | +You can set a custom font with [Calligraphy](https://github.com/chrisjenx/Calligraphy) just add a CustomViewTypeface with HeaderView.class in CalligraphyConfig |
| 175 | +```Java |
| 176 | +CalligraphyConfig.initDefault(new CalligraphyConfig.Builder() |
| 177 | + .setDefaultFontPath("Oswald-Stencbab.ttf") |
| 178 | + .setFontAttrId(R.attr.fontPath) |
| 179 | + .addCustomViewWithSetTypeface(HeaderView.class) |
| 180 | + .build() |
| 181 | +); |
| 182 | +``` |
| 183 | +### Screen |
| 184 | + |
| 185 | + |
| 186 | +### Sample |
| 187 | +Browse the sample code [here](https://github.com/rebus007/HeaderView/tree/master/sample) or download sample app from the [Play Store](https://play.google.com/store/apps/details?id=rebus.header.view.sample) |
| 188 | + |
| 189 | +### Javadoc |
| 190 | +Browse Javadoc [here](https://rebus007.github.io/HeaderView/javadoc/) |
| 191 | + |
| 192 | +### App using Header View |
| 193 | +If you use this lib [contact me](mailto:raphaelbussa@gmail.com) and I will add it to the list below: |
| 194 | +- [Mister Gadget](https://play.google.com/store/apps/details?id=rebus.mister.gadget) |
| 195 | +- [Git Chat](https://github.com/rebus007/Git-Chat) |
| 196 | +- [The Coding Love](https://play.google.com/store/apps/details?id=rebus.thecodinglove) |
| 197 | +- [Romanews.eu](https://play.google.com/store/apps/details?id=it.daigan.romanews) |
| 198 | +- [Mob@rt](https://play.google.com/store/apps/details?id=it.artigiancassa.mobile.android.mobart) |
| 199 | + |
| 200 | +### Developed By |
| 201 | +Raphaël Bussa - [raphaelbussa@gmail.com](mailto:raphaelbussa@gmail.com) |
| 202 | + |
| 203 | +[  ](https://twitter.com/rebus_007)[  ](https://plus.google.com/+RaphaelBussa/posts)[  ](https://www.linkedin.com/in/rebus007) |
| 204 | + |
| 205 | +### License |
| 206 | +``` |
| 207 | +The MIT License (MIT) |
| 208 | +
|
| 209 | +Copyright (c) 2017 Raphaël Bussa <raphaelbussa@gmail.com> |
| 210 | +
|
| 211 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 212 | +of this software and associated documentation files (the "Software"), to deal |
| 213 | +in the Software without restriction, including without limitation the rights |
| 214 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 215 | +copies of the Software, and to permit persons to whom the Software is |
| 216 | +furnished to do so, subject to the following conditions: |
| 217 | +
|
| 218 | +The above copyright notice and this permission notice shall be included in all |
| 219 | +copies or substantial portions of the Software. |
| 220 | +
|
| 221 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 222 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 223 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 224 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 225 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 226 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 227 | +SOFTWARE. |
| 228 | +``` |
0 commit comments