diff --git a/app/src/main/java/rebus/header/view/sample/MainActivity.java b/app/src/main/java/rebus/header/view/sample/MainActivity.java index f4f9e8b..a7a3c38 100644 --- a/app/src/main/java/rebus/header/view/sample/MainActivity.java +++ b/app/src/main/java/rebus/header/view/sample/MainActivity.java @@ -33,6 +33,7 @@ import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.util.Log; +import android.view.View; import android.widget.Toast; import rebus.header.view.HeaderCallback; @@ -122,6 +123,7 @@ public void run() { headerView.setDialogTitle("Choose account"); //headerView.setShowArrow(false); headerView.setFragmentManager(getFragmentManager()); + headerView.setCallback(new HeaderCallback() { @Override diff --git a/app/src/main/res/layout/header_drawer.xml b/app/src/main/res/layout/header_drawer.xml index 8e3dbc2..658e520 100644 --- a/app/src/main/res/layout/header_drawer.xml +++ b/app/src/main/res/layout/header_drawer.xml @@ -26,7 +26,7 @@ profiles) { for (Profile profile : profiles) { profileSparseArray.put(profile.getId(), profile); @@ -171,6 +186,20 @@ public void addProfile(List profiles) { Log.d(TAG, profileSparseArray.toString()); } + /** + * @param profiles add a ArrayList of profiles + */ + public void addProfile(ArrayList profiles) { + for (Profile profile : profiles) { + profileSparseArray.put(profile.getId(), profile); + } + populateAvatar(); + Log.d(TAG, profileSparseArray.toString()); + } + + /** + * @param profiles add Profiles + */ public void addProfile(Profile... profiles) { for (Profile profile : profiles) { profileSparseArray.put(profile.getId(), profile); @@ -179,16 +208,33 @@ public void addProfile(Profile... profiles) { Log.d(TAG, profileSparseArray.toString()); } + /** + * @param item add profile chooser bottom items + */ public void addDialogItem(Item... item) { itemArrayList.clear(); Collections.addAll(itemArrayList, item); } + /** + * @param items add a List of items for profile chooser + */ public void addDialogItem(List items) { itemArrayList.clear(); itemArrayList.addAll(items); } + /** + * @param items add a ArrayList of items for profile chooser + */ + public void addDialogItem(ArrayList items) { + itemArrayList.clear(); + itemArrayList.addAll(items); + } + + /** + * @param id remove profile from id + */ public void removeProfile(int id) { for (int i = 0; i < profileSparseArray.size(); i++) { Profile profile = profileSparseArray.valueAt(i); @@ -200,10 +246,16 @@ public void removeProfile(int id) { } } + /** + * @return get active id profile + */ public int getProfileActive() { return profileSparseArray.valueAt(0).getId(); } + /** + * @param id set active profile from id + */ public void setProfileActive(int id) { for (int i = 0; i < profileSparseArray.size(); i++) { Profile profile = profileSparseArray.valueAt(i); @@ -214,11 +266,17 @@ public void setProfileActive(int id) { } } + /** + * @param showArrow set if arrow is visible + */ public void setShowArrow(boolean showArrow) { hvShowArrow = showArrow; addArrow(); } + /** + * @param showGradient set if background gradient is visible + */ public void setShowGradient(boolean showGradient) { hvShowGradient = showGradient; addGradient(); @@ -231,42 +289,86 @@ public void setAddIconDrawable(@DrawableRes int addIconDrawable) { hvAddIconDrawable = addIconDrawable; } + /** + * @param fragmentManager set FragmentManager for use a DialogFragment for profile chooser and prevent dismiss in activity rotation + */ public void setFragmentManager(FragmentManager fragmentManager) { hvFragmentManager = fragmentManager; } + /** + * @param showAddButton show button in the upper right in profile chooser + */ public void setShowAddButton(boolean showAddButton) { hvShowAddButton = showAddButton; } + /** + * @param color set HeaderView background color as color int + */ public void setBackgroundColor(@ColorInt int color) { background.setBackgroundColor(color); } + /** + * @param color set HeaderView background color as color res + */ public void setBackgroundColorRes(@ColorRes int color) { background.setBackgroundColor(Utils.getColor(getContext(), color)); } + /** + * @param onClickListener set onClickListener for avatar in HeaderView + */ public void setOnAvatarClickListener(View.OnClickListener onClickListener) { avatar.setOnClickListener(onClickListener); } + /** + * @param onLongClickListener set onLongClickListener for avatar in HeaderView + */ public void setOnLongAvatarClickListener(View.OnLongClickListener onLongClickListener) { avatar.setOnLongClickListener(onLongClickListener); } + /** + * @param onClickListener set onClickListener for background in HeaderView + */ public void setOnHeaderClickListener(OnClickListener onClickListener) { selector.setOnClickListener(onClickListener); } + /** + * @param onLongClickListener set onLongClickListener for background in HeaderView + */ public void setOnLongHeaderClickListener(View.OnLongClickListener onLongClickListener) { selector.setOnLongClickListener(onLongClickListener); } - public void setHighlightColor(int highlightColor) { + /** + * @param onClickListener replace default on onClickListener for arrow and replace default action (open profile chooser dialog) + */ + public void setOnArrowClickListener(OnClickListener onClickListener) { + arrow.setOnClickListener(onClickListener); + } + + /** + * @param onLongClickListener set onLongClickListener for arrow in HeaderView + */ + public void setOnLongArrowClickListener(View.OnLongClickListener onLongClickListener) { + arrow.setOnLongClickListener(onLongClickListener); + } + + /** + * @param highlightColor set color for circle border in avatar view in profile chooser + */ + public void setHighlightColor(@ColorInt int highlightColor) { hvHighlightColor = highlightColor; } + /** + * @param dialogTitle set profile chooser dialog title + */ public void setDialogTitle(String dialogTitle) { hvDialogTitle = dialogTitle; } @@ -388,7 +490,7 @@ private void setupAttributeSet(AttributeSet attrs, int defStyle) { hvBackgroundColor = Color.TRANSPARENT; hvHighlightColor = Color.BLACK; - hvBelowToolbar = false; + hvAddStatusBarHeight = true; hvStyle = STYLE_NORMAL; hvTheme = THEME_LIGHT; hvShowGradient = true; @@ -406,7 +508,7 @@ private void setupAttributeSet(AttributeSet attrs, int defStyle) { hvBackgroundColor = typedArray.getColor(R.styleable.HeaderView_hv_background_color, Color.TRANSPARENT); hvHighlightColor = typedArray.getColor(R.styleable.HeaderView_hv_highlight_color, Color.BLACK); - hvBelowToolbar = typedArray.getBoolean(R.styleable.HeaderView_hv_below_toolbar, false); + hvAddStatusBarHeight = typedArray.getBoolean(R.styleable.HeaderView_hv_add_status_bar_height, true); hvStyle = typedArray.getInt(R.styleable.HeaderView_hv_style, STYLE_NORMAL); hvTheme = typedArray.getInt(R.styleable.HeaderView_hv_theme, THEME_LIGHT); hvShowGradient = typedArray.getBoolean(R.styleable.HeaderView_hv_show_gradient, true); @@ -503,7 +605,7 @@ public void onClick(View v) { if (hvFragmentManager != null) { ProfileChooserFragment profileChooserFragment = ProfileChooserFragment.newInstance(profileSparseArray, itemArrayList, hvHighlightColor, hvShowAddButton, hvDialogTitle, hvAddIconDrawable); profileChooserFragment.setCallback(HeaderView.this); - profileChooserFragment.show(hvFragmentManager, "ProfileChooserFragment"); + profileChooserFragment.show(hvFragmentManager, ProfileChooserFragment.FRAGMENT_TAG); } else { ProfileChooser profileChooser = new ProfileChooser(getContext(), profileSparseArray, itemArrayList, hvHighlightColor, hvShowAddButton, hvDialogTitle, hvAddIconDrawable); profileChooser.setCallback(HeaderView.this); @@ -591,7 +693,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { } private int getDimensionFix(int dimen) { - if (hvBelowToolbar) { + if (!hvAddStatusBarHeight) { return dimen; } else { return dimen + statusBarHeight; @@ -600,14 +702,14 @@ private int getDimensionFix(int dimen) { private int getHeaderHeight(int heightMeasureSpec) { if (hvStyle == STYLE_NORMAL) { - if (hvBelowToolbar) { + if (!hvAddStatusBarHeight) { return getResources().getDimensionPixelSize(R.dimen.hv_normal); } else { return getResources().getDimensionPixelSize(R.dimen.hv_normal) + statusBarHeight; } } if (hvStyle == STYLE_COMPACT) { - if (hvBelowToolbar) { + if (!hvAddStatusBarHeight) { return getResources().getDimensionPixelSize(R.dimen.hv_compact); } else { return getResources().getDimensionPixelSize(R.dimen.hv_compact) + statusBarHeight; @@ -622,7 +724,7 @@ protected Parcelable onSaveInstanceState() { Bundle bundle = new Bundle(); bundle.putParcelable("superState", super.onSaveInstanceState()); //STORE CUSTOM VALUES - bundle.putSparseParcelableArray("PROFILE_LIST", profileSparseArray); + bundle.putSparseParcelableArray(PROFILE_LIST, profileSparseArray); return bundle; } @@ -633,11 +735,11 @@ protected void onRestoreInstanceState(Parcelable state) { Bundle bundle = (Bundle) state; state = bundle.getParcelable("superState"); //RESTORE CUSTOM VALUES - profileSparseArray = bundle.getSparseParcelableArray("PROFILE_LIST"); + profileSparseArray = bundle.getSparseParcelableArray(PROFILE_LIST); populateAvatar(); } if (hvFragmentManager != null) { - ProfileChooserFragment profileChooserFragment = (ProfileChooserFragment) hvFragmentManager.findFragmentByTag("ProfileChooserFragment"); + ProfileChooserFragment profileChooserFragment = (ProfileChooserFragment) hvFragmentManager.findFragmentByTag(ProfileChooserFragment.FRAGMENT_TAG); if (profileChooserFragment != null) { profileChooserFragment.setCallback(HeaderView.this); } diff --git a/library/src/main/java/rebus/header/view/ImageLoader.java b/library/src/main/java/rebus/header/view/ImageLoader.java index 1d7468a..76eb3a7 100644 --- a/library/src/main/java/rebus/header/view/ImageLoader.java +++ b/library/src/main/java/rebus/header/view/ImageLoader.java @@ -46,12 +46,15 @@ public class ImageLoader { private static ImageLoader instance; private ImageLoaderInterface imageLoaderInterface; - public static ImageLoader init(ImageLoaderInterface imageLoaderInterface) { + + /** + * @param imageLoaderInterface set ImageLoaderInterface for image loading from Uri + */ + public static void init(ImageLoaderInterface imageLoaderInterface) { if (instance == null) { instance = new ImageLoader(); } instance.setImageLoaderInterface(imageLoaderInterface); - return instance; } static void loadImage(Uri url, ImageView imageView, @Type int type) { @@ -66,6 +69,11 @@ private void setImageLoaderInterface(ImageLoaderInterface imageLoaderInterface) } public interface ImageLoaderInterface { + /** + * @param url uri of image + * @param imageView reference of ImageView + * @param type type of image to load AVATAR or HEADER + */ void loadImage(Uri url, ImageView imageView, @Type int type); } diff --git a/library/src/main/java/rebus/header/view/Item.java b/library/src/main/java/rebus/header/view/Item.java index a3a94b7..4d592e6 100644 --- a/library/src/main/java/rebus/header/view/Item.java +++ b/library/src/main/java/rebus/header/view/Item.java @@ -52,7 +52,7 @@ private Item(int id, String title) { this.title = title; } - protected Item(Parcel in) { + private Item(Parcel in) { id = in.readInt(); title = in.readString(); } @@ -84,21 +84,31 @@ public static class Builder { public Builder() { } + /** + * @param id set id of item for match onClick result + * @return current builder instance + */ public Builder setId(int id) { this.id = id; return this; } + /** + * @param title set title of item + * @return current builder instance + */ public Builder setTitle(String title) { this.title = title; return this; } + /** + * @return build Item and return it + */ public Item build() { return new Item(id, title); } } - } diff --git a/library/src/main/java/rebus/header/view/Profile.java b/library/src/main/java/rebus/header/view/Profile.java index cbd7ba2..6e103ba 100644 --- a/library/src/main/java/rebus/header/view/Profile.java +++ b/library/src/main/java/rebus/header/view/Profile.java @@ -161,72 +161,118 @@ public static class Builder { public Builder() { } + /** + * @param id set id of profile for match onClick result + * @return current builder instance + */ public Builder setId(@IdValue int id) { this.id = id; return this; } - public Builder setAvatar(Uri avatar) { + /** + * @param avatar set avatar Uri (for use this function you must implement ImageLoader) + * @return current builder instance + */ + public Builder setAvatar(@NonNull Uri avatar) { this.avatarUri = avatar; this.avatarDrawable = null; return this; } + /** + * @param avatar set avatar url as String (for use this function you must implement ImageLoader) + * @return current builder instance + */ public Builder setAvatar(@NonNull String avatar) { this.avatarUri = Uri.parse(avatar); this.avatarDrawable = null; return this; } + /** + * @param avatar set avatar drawable + * @return current builder instance + */ public Builder setAvatar(Drawable avatar) { this.avatarDrawable = avatar; this.avatarUri = null; return this; } - public Builder setBackground(Uri background) { + /** + * @param background set background Uri (for use this function you must implement ImageLoader) + * @return current builder instance + */ + public Builder setBackground(@NonNull Uri background) { this.backgroundUri = background; this.backgroundDrawable = null; return this; } + /** + * @param background set background url as String (for use this function you must implement ImageLoader) + * @return current builder instance + */ public Builder setBackground(@NonNull String background) { this.backgroundUri = Uri.parse(background); this.backgroundDrawable = null; return this; } + /** + * @param background set background drawable + * @return current builder instance + */ public Builder setBackground(Drawable background) { this.backgroundDrawable = background; this.backgroundUri = null; return this; } + /** + * @param username set profile username + * @return current builder instance + */ public Builder setUsername(Spanned username) { this.username = username; return this; } + /** + * @param email set profile email + * @return current builder instance + */ public Builder setEmail(Spanned email) { this.email = email; return this; } + /** + * @param username set profile username + * @return current builder instance + */ public Builder setUsername(String username) { this.username = Utils.fromHtml(username); return this; } + /** + * @param email set profile email + * @return current builder instance + */ public Builder setEmail(String email) { this.email = Utils.fromHtml(email); return this; } + /** + * @return build Profile and return it + */ public Profile build() { return new Profile(id, avatarUri, avatarDrawable, backgroundUri, backgroundDrawable, username, email); } } - } diff --git a/library/src/main/java/rebus/header/view/ProfileChooserFragment.java b/library/src/main/java/rebus/header/view/ProfileChooserFragment.java index 24ea85d..7c324db 100644 --- a/library/src/main/java/rebus/header/view/ProfileChooserFragment.java +++ b/library/src/main/java/rebus/header/view/ProfileChooserFragment.java @@ -45,6 +45,8 @@ public class ProfileChooserFragment extends DialogFragment { + public static final String FRAGMENT_TAG = "HV_PROFILE_CHOOSER_FRAGMENT"; + private LinearLayout linearLayout; private LinearLayout linearLayout1; private TextView title; diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index d464257..b68046d 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -31,7 +31,7 @@ - +