Skip to content

Commit 1be15f9

Browse files
committed
version 2.0.0-BETA-2
- rename "hv_below_toolbar" as "hv_add_status_bar_height" - add javadoc
1 parent 4f849d4 commit 1be15f9

9 files changed

Lines changed: 192 additions & 22 deletions

File tree

app/src/main/java/rebus/header/view/sample/MainActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.os.Bundle;
3434
import android.support.v7.widget.Toolbar;
3535
import android.util.Log;
36+
import android.view.View;
3637
import android.widget.Toast;
3738

3839
import rebus.header.view.HeaderCallback;
@@ -122,6 +123,7 @@ public void run() {
122123
headerView.setDialogTitle("Choose account");
123124
//headerView.setShowArrow(false);
124125
headerView.setFragmentManager(getFragmentManager());
126+
125127
headerView.setCallback(new HeaderCallback() {
126128

127129
@Override

app/src/main/res/layout/header_drawer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<rebus.header.view.HeaderView xmlns:android="http://schemas.android.com/apk/res/android"
2727
xmlns:app="http://schemas.android.com/apk/res-auto"
2828
android:id="@+id/header_view"
29-
app:hv_below_toolbar="false"
29+
app:hv_add_status_bar_height="true"
3030
app:hv_style="normal"
3131
app:hv_theme="light"
3232
app:hv_highlight_color="@color/colorAccent"

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ buildscript {
3030
buildTools: "25.0.2",
3131
minSdk : 11,
3232
targetSdk : 25,
33-
version : "2.0.0-BETA-1",
33+
version : "2.0.0-BETA-2",
3434
supportLib: "25.1.0"
3535
]
3636
}

library/src/main/java/rebus/header/view/HeaderView.java

Lines changed: 114 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@
6363

6464
public class HeaderView extends ViewGroup implements ProfileChooserCallback {
6565

66+
private static final String TAG = HeaderView.class.getName();
67+
private static final String PROFILE_LIST = "PROFILE_LIST";
68+
6669
public static final int STYLE_NORMAL = 1;
6770
public static final int STYLE_COMPACT = 2;
6871
public static final int THEME_LIGHT = 1;
6972
public static final int THEME_DARK = 2;
70-
private static final String TAG = HeaderView.class.getName();
73+
7174
private int statusBarHeight;
7275

7376
private CircleImageView avatar;
@@ -92,7 +95,7 @@ public class HeaderView extends ViewGroup implements ProfileChooserCallback {
9295
private int hvBackgroundColor;
9396
@ColorInt
9497
private int hvHighlightColor;
95-
private boolean hvBelowToolbar;
98+
private boolean hvAddStatusBarHeight;
9699
private boolean hvShowGradient;
97100
private boolean hvShowAddButton;
98101
private boolean hvShowArrow;
@@ -137,10 +140,16 @@ private void init(AttributeSet attrs, int defStyle) {
137140
setDefaultValues();
138141
}
139142

143+
/**
144+
* @param style set style of HeaderView: STYLE_NORMAL or STYLE_COMPACT
145+
*/
140146
public void setStyle(@Style int style) {
141147
hvStyle = style;
142148
}
143149

150+
/**
151+
* @param theme set theme of HeaderView: THEME_LIGHT or THEME_DARK
152+
*/
144153
public void setTheme(@Theme int theme) {
145154
hvTheme = theme;
146155
if (hvTheme == THEME_LIGHT) {
@@ -154,6 +163,9 @@ public void setTheme(@Theme int theme) {
154163
arrow.setColorFilter(hvTextColor);
155164
}
156165

166+
/**
167+
* @param headerCallback set callback for HeaderView actions, onAdd (from profile chooser), onItem (from profile chooser) and onSelect when a profile is clicked
168+
*/
157169
public void setCallback(HeaderCallback headerCallback) {
158170
this.headerCallback = headerCallback;
159171
}
@@ -163,6 +175,9 @@ public void clearProfile() {
163175
populateAvatar();
164176
}
165177

178+
/**
179+
* @param profiles add a List of profiles
180+
*/
166181
public void addProfile(List<Profile> profiles) {
167182
for (Profile profile : profiles) {
168183
profileSparseArray.put(profile.getId(), profile);
@@ -171,6 +186,20 @@ public void addProfile(List<Profile> profiles) {
171186
Log.d(TAG, profileSparseArray.toString());
172187
}
173188

189+
/**
190+
* @param profiles add a ArrayList of profiles
191+
*/
192+
public void addProfile(ArrayList<Profile> profiles) {
193+
for (Profile profile : profiles) {
194+
profileSparseArray.put(profile.getId(), profile);
195+
}
196+
populateAvatar();
197+
Log.d(TAG, profileSparseArray.toString());
198+
}
199+
200+
/**
201+
* @param profiles add Profiles
202+
*/
174203
public void addProfile(Profile... profiles) {
175204
for (Profile profile : profiles) {
176205
profileSparseArray.put(profile.getId(), profile);
@@ -179,16 +208,33 @@ public void addProfile(Profile... profiles) {
179208
Log.d(TAG, profileSparseArray.toString());
180209
}
181210

211+
/**
212+
* @param item add profile chooser bottom items
213+
*/
182214
public void addDialogItem(Item... item) {
183215
itemArrayList.clear();
184216
Collections.addAll(itemArrayList, item);
185217
}
186218

219+
/**
220+
* @param items add a List of items for profile chooser
221+
*/
187222
public void addDialogItem(List<Item> items) {
188223
itemArrayList.clear();
189224
itemArrayList.addAll(items);
190225
}
191226

227+
/**
228+
* @param items add a ArrayList of items for profile chooser
229+
*/
230+
public void addDialogItem(ArrayList<Item> items) {
231+
itemArrayList.clear();
232+
itemArrayList.addAll(items);
233+
}
234+
235+
/**
236+
* @param id remove profile from id
237+
*/
192238
public void removeProfile(int id) {
193239
for (int i = 0; i < profileSparseArray.size(); i++) {
194240
Profile profile = profileSparseArray.valueAt(i);
@@ -200,10 +246,16 @@ public void removeProfile(int id) {
200246
}
201247
}
202248

249+
/**
250+
* @return get active id profile
251+
*/
203252
public int getProfileActive() {
204253
return profileSparseArray.valueAt(0).getId();
205254
}
206255

256+
/**
257+
* @param id set active profile from id
258+
*/
207259
public void setProfileActive(int id) {
208260
for (int i = 0; i < profileSparseArray.size(); i++) {
209261
Profile profile = profileSparseArray.valueAt(i);
@@ -214,11 +266,17 @@ public void setProfileActive(int id) {
214266
}
215267
}
216268

269+
/**
270+
* @param showArrow set if arrow is visible
271+
*/
217272
public void setShowArrow(boolean showArrow) {
218273
hvShowArrow = showArrow;
219274
addArrow();
220275
}
221276

277+
/**
278+
* @param showGradient set if background gradient is visible
279+
*/
222280
public void setShowGradient(boolean showGradient) {
223281
hvShowGradient = showGradient;
224282
addGradient();
@@ -231,42 +289,86 @@ public void setAddIconDrawable(@DrawableRes int addIconDrawable) {
231289
hvAddIconDrawable = addIconDrawable;
232290
}
233291

292+
/**
293+
* @param fragmentManager set FragmentManager for use a DialogFragment for profile chooser and prevent dismiss in activity rotation
294+
*/
234295
public void setFragmentManager(FragmentManager fragmentManager) {
235296
hvFragmentManager = fragmentManager;
236297
}
237298

299+
/**
300+
* @param showAddButton show button in the upper right in profile chooser
301+
*/
238302
public void setShowAddButton(boolean showAddButton) {
239303
hvShowAddButton = showAddButton;
240304
}
241305

306+
/**
307+
* @param color set HeaderView background color as color int
308+
*/
242309
public void setBackgroundColor(@ColorInt int color) {
243310
background.setBackgroundColor(color);
244311
}
245312

313+
/**
314+
* @param color set HeaderView background color as color res
315+
*/
246316
public void setBackgroundColorRes(@ColorRes int color) {
247317
background.setBackgroundColor(Utils.getColor(getContext(), color));
248318
}
249319

320+
/**
321+
* @param onClickListener set onClickListener for avatar in HeaderView
322+
*/
250323
public void setOnAvatarClickListener(View.OnClickListener onClickListener) {
251324
avatar.setOnClickListener(onClickListener);
252325
}
253326

327+
/**
328+
* @param onLongClickListener set onLongClickListener for avatar in HeaderView
329+
*/
254330
public void setOnLongAvatarClickListener(View.OnLongClickListener onLongClickListener) {
255331
avatar.setOnLongClickListener(onLongClickListener);
256332
}
257333

334+
/**
335+
* @param onClickListener set onClickListener for background in HeaderView
336+
*/
258337
public void setOnHeaderClickListener(OnClickListener onClickListener) {
259338
selector.setOnClickListener(onClickListener);
260339
}
261340

341+
/**
342+
* @param onLongClickListener set onLongClickListener for background in HeaderView
343+
*/
262344
public void setOnLongHeaderClickListener(View.OnLongClickListener onLongClickListener) {
263345
selector.setOnLongClickListener(onLongClickListener);
264346
}
265347

266-
public void setHighlightColor(int highlightColor) {
348+
/**
349+
* @param onClickListener replace default on onClickListener for arrow and replace default action (open profile chooser dialog)
350+
*/
351+
public void setOnArrowClickListener(OnClickListener onClickListener) {
352+
arrow.setOnClickListener(onClickListener);
353+
}
354+
355+
/**
356+
* @param onLongClickListener set onLongClickListener for arrow in HeaderView
357+
*/
358+
public void setOnLongArrowClickListener(View.OnLongClickListener onLongClickListener) {
359+
arrow.setOnLongClickListener(onLongClickListener);
360+
}
361+
362+
/**
363+
* @param highlightColor set color for circle border in avatar view in profile chooser
364+
*/
365+
public void setHighlightColor(@ColorInt int highlightColor) {
267366
hvHighlightColor = highlightColor;
268367
}
269368

369+
/**
370+
* @param dialogTitle set profile chooser dialog title
371+
*/
270372
public void setDialogTitle(String dialogTitle) {
271373
hvDialogTitle = dialogTitle;
272374
}
@@ -388,7 +490,7 @@ private void setupAttributeSet(AttributeSet attrs, int defStyle) {
388490

389491
hvBackgroundColor = Color.TRANSPARENT;
390492
hvHighlightColor = Color.BLACK;
391-
hvBelowToolbar = false;
493+
hvAddStatusBarHeight = true;
392494
hvStyle = STYLE_NORMAL;
393495
hvTheme = THEME_LIGHT;
394496
hvShowGradient = true;
@@ -406,7 +508,7 @@ private void setupAttributeSet(AttributeSet attrs, int defStyle) {
406508

407509
hvBackgroundColor = typedArray.getColor(R.styleable.HeaderView_hv_background_color, Color.TRANSPARENT);
408510
hvHighlightColor = typedArray.getColor(R.styleable.HeaderView_hv_highlight_color, Color.BLACK);
409-
hvBelowToolbar = typedArray.getBoolean(R.styleable.HeaderView_hv_below_toolbar, false);
511+
hvAddStatusBarHeight = typedArray.getBoolean(R.styleable.HeaderView_hv_add_status_bar_height, true);
410512
hvStyle = typedArray.getInt(R.styleable.HeaderView_hv_style, STYLE_NORMAL);
411513
hvTheme = typedArray.getInt(R.styleable.HeaderView_hv_theme, THEME_LIGHT);
412514
hvShowGradient = typedArray.getBoolean(R.styleable.HeaderView_hv_show_gradient, true);
@@ -503,7 +605,7 @@ public void onClick(View v) {
503605
if (hvFragmentManager != null) {
504606
ProfileChooserFragment profileChooserFragment = ProfileChooserFragment.newInstance(profileSparseArray, itemArrayList, hvHighlightColor, hvShowAddButton, hvDialogTitle, hvAddIconDrawable);
505607
profileChooserFragment.setCallback(HeaderView.this);
506-
profileChooserFragment.show(hvFragmentManager, "ProfileChooserFragment");
608+
profileChooserFragment.show(hvFragmentManager, ProfileChooserFragment.FRAGMENT_TAG);
507609
} else {
508610
ProfileChooser profileChooser = new ProfileChooser(getContext(), profileSparseArray, itemArrayList, hvHighlightColor, hvShowAddButton, hvDialogTitle, hvAddIconDrawable);
509611
profileChooser.setCallback(HeaderView.this);
@@ -591,7 +693,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
591693
}
592694

593695
private int getDimensionFix(int dimen) {
594-
if (hvBelowToolbar) {
696+
if (!hvAddStatusBarHeight) {
595697
return dimen;
596698
} else {
597699
return dimen + statusBarHeight;
@@ -600,14 +702,14 @@ private int getDimensionFix(int dimen) {
600702

601703
private int getHeaderHeight(int heightMeasureSpec) {
602704
if (hvStyle == STYLE_NORMAL) {
603-
if (hvBelowToolbar) {
705+
if (!hvAddStatusBarHeight) {
604706
return getResources().getDimensionPixelSize(R.dimen.hv_normal);
605707
} else {
606708
return getResources().getDimensionPixelSize(R.dimen.hv_normal) + statusBarHeight;
607709
}
608710
}
609711
if (hvStyle == STYLE_COMPACT) {
610-
if (hvBelowToolbar) {
712+
if (!hvAddStatusBarHeight) {
611713
return getResources().getDimensionPixelSize(R.dimen.hv_compact);
612714
} else {
613715
return getResources().getDimensionPixelSize(R.dimen.hv_compact) + statusBarHeight;
@@ -622,7 +724,7 @@ protected Parcelable onSaveInstanceState() {
622724
Bundle bundle = new Bundle();
623725
bundle.putParcelable("superState", super.onSaveInstanceState());
624726
//STORE CUSTOM VALUES
625-
bundle.putSparseParcelableArray("PROFILE_LIST", profileSparseArray);
727+
bundle.putSparseParcelableArray(PROFILE_LIST, profileSparseArray);
626728
return bundle;
627729
}
628730

@@ -633,11 +735,11 @@ protected void onRestoreInstanceState(Parcelable state) {
633735
Bundle bundle = (Bundle) state;
634736
state = bundle.getParcelable("superState");
635737
//RESTORE CUSTOM VALUES
636-
profileSparseArray = bundle.getSparseParcelableArray("PROFILE_LIST");
738+
profileSparseArray = bundle.getSparseParcelableArray(PROFILE_LIST);
637739
populateAvatar();
638740
}
639741
if (hvFragmentManager != null) {
640-
ProfileChooserFragment profileChooserFragment = (ProfileChooserFragment) hvFragmentManager.findFragmentByTag("ProfileChooserFragment");
742+
ProfileChooserFragment profileChooserFragment = (ProfileChooserFragment) hvFragmentManager.findFragmentByTag(ProfileChooserFragment.FRAGMENT_TAG);
641743
if (profileChooserFragment != null) {
642744
profileChooserFragment.setCallback(HeaderView.this);
643745
}

library/src/main/java/rebus/header/view/ImageLoader.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ public class ImageLoader {
4646
private static ImageLoader instance;
4747
private ImageLoaderInterface imageLoaderInterface;
4848

49-
public static ImageLoader init(ImageLoaderInterface imageLoaderInterface) {
49+
50+
/**
51+
* @param imageLoaderInterface set ImageLoaderInterface for image loading from Uri
52+
*/
53+
public static void init(ImageLoaderInterface imageLoaderInterface) {
5054
if (instance == null) {
5155
instance = new ImageLoader();
5256
}
5357
instance.setImageLoaderInterface(imageLoaderInterface);
54-
return instance;
5558
}
5659

5760
static void loadImage(Uri url, ImageView imageView, @Type int type) {
@@ -66,6 +69,11 @@ private void setImageLoaderInterface(ImageLoaderInterface imageLoaderInterface)
6669
}
6770

6871
public interface ImageLoaderInterface {
72+
/**
73+
* @param url uri of image
74+
* @param imageView reference of ImageView
75+
* @param type type of image to load AVATAR or HEADER
76+
*/
6977
void loadImage(Uri url, ImageView imageView, @Type int type);
7078
}
7179

0 commit comments

Comments
 (0)