diff --git a/paper-onboarding-fragment-example/src/main/AndroidManifest.xml b/paper-onboarding-fragment-example/src/main/AndroidManifest.xml index c477fa9..edd8037 100644 --- a/paper-onboarding-fragment-example/src/main/AndroidManifest.xml +++ b/paper-onboarding-fragment-example/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + + + mElements = new ArrayList<>(); + private final ArrayList mElements = new ArrayList<>(); private int mActiveElementIndex = 0; // params for Pager position calculations, virtually final, but initializes in onGlobalLayoutListener @@ -80,10 +83,10 @@ public PaperOnboardingEngine(View rootLayout, ArrayList con this.mAppContext = appContext.getApplicationContext(); mRootLayout = (RelativeLayout) rootLayout; - mContentTextContainer = (FrameLayout) rootLayout.findViewById(R.id.onboardingContentTextContainer); - mContentIconContainer = (FrameLayout) rootLayout.findViewById(R.id.onboardingContentIconContainer); - mBackgroundContainer = (FrameLayout) rootLayout.findViewById(R.id.onboardingBackgroundContainer); - mPagerIconsContainer = (LinearLayout) rootLayout.findViewById(R.id.onboardingPagerIconsContainer); + mContentTextContainer = rootLayout.findViewById(R.id.onboardingContentTextContainer); + mContentIconContainer = rootLayout.findViewById(R.id.onboardingContentIconContainer); + mBackgroundContainer = rootLayout.findViewById(R.id.onboardingBackgroundContainer); + mPagerIconsContainer = rootLayout.findViewById(R.id.onboardingPagerIconsContainer); mContentRootLayout = (RelativeLayout) mRootLayout.getChildAt(1); mContentCenteredContainer = (LinearLayout) mContentRootLayout.getChildAt(0); @@ -102,7 +105,6 @@ public void onSwipeLeft() { public void onSwipeRight() { toggleContent(true); } - }); mRootLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @@ -124,7 +126,7 @@ public void onGlobalLayout() { mPagerElementRightMargin = layoutParams.rightMargin; mPagerIconsContainer.setX(calculateNewPagerPosition(0)); - mContentCenteredContainer.setY((mContentRootLayout.getHeight() - mContentCenteredContainer.getHeight()) / 2); + mContentCenteredContainer.setY((mContentRootLayout.getHeight() - mContentCenteredContainer.getHeight()) >> 1); } }); @@ -468,8 +470,63 @@ protected ViewGroup createContentTextView(PaperOnboardingPage PaperOnboardingPag ViewGroup contentTextView = (ViewGroup) vi.inflate(R.layout.onboarding_text_content_layout, mContentTextContainer, false); TextView contentTitle = (TextView) contentTextView.getChildAt(0); contentTitle.setText(PaperOnboardingPage.getTitleText()); + + if (PaperOnboardingPage.getTitleTextColor() != 0) { + contentTitle.setTextColor(PaperOnboardingPage.getTitleTextColor()); + } + + if (PaperOnboardingPage.getTitleTextSize() != 0) { + contentTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, PaperOnboardingPage.getTitleTextSize()); + } + + if (PaperOnboardingPage.getTitleTextStyle() != null) { + switch (PaperOnboardingPage.getTitleTextStyle()) { + case NORMAL: + contentTitle.setTypeface(contentTitle.getTypeface(), Typeface.NORMAL); + break; + case ITALIC: + contentTitle.setTypeface(contentTitle.getTypeface(), Typeface.ITALIC); + break; + case BOLD_ITALIC: + contentTitle.setTypeface(contentTitle.getTypeface(), Typeface.BOLD_ITALIC); + break; + case BOLD: + default: + contentTitle.setTypeface(contentTitle.getTypeface(), Typeface.BOLD); + } + } else { + contentTitle.setTypeface(contentTitle.getTypeface(), Typeface.BOLD); + } + TextView contentText = (TextView) contentTextView.getChildAt(1); contentText.setText(PaperOnboardingPage.getDescriptionText()); + + if (PaperOnboardingPage.getDescriptionTextColor() != 0) { + contentText.setTextColor(PaperOnboardingPage.getDescriptionTextColor()); + } + + if (PaperOnboardingPage.getDescriptionTextSize() != 0) { + contentText.setTextSize(TypedValue.COMPLEX_UNIT_SP, PaperOnboardingPage.getDescriptionTextSize()); + } + + if (PaperOnboardingPage.getDescriptionTextStyle() != null) { + switch (PaperOnboardingPage.getDescriptionTextStyle()) { + case NORMAL: + contentText.setTypeface(contentTitle.getTypeface(), Typeface.NORMAL); + break; + case ITALIC: + contentText.setTypeface(contentTitle.getTypeface(), Typeface.ITALIC); + break; + case BOLD_ITALIC: + contentText.setTypeface(contentTitle.getTypeface(), Typeface.BOLD_ITALIC); + break; + case BOLD: + default: + contentText.setTypeface(contentTitle.getTypeface(), Typeface.BOLD); + } + } else { + contentText.setTypeface(contentTitle.getTypeface(), Typeface.BOLD); + } return contentTextView; } @@ -479,7 +536,26 @@ protected ViewGroup createContentTextView(PaperOnboardingPage PaperOnboardingPag */ protected ImageView createContentIconView(PaperOnboardingPage PaperOnboardingPage) { ImageView contentIcon = new ImageView(mAppContext); - contentIcon.setImageResource(PaperOnboardingPage.getContentIconRes()); + + if (PaperOnboardingPage.getImageUrl() != null) { + if (PaperOnboardingPage.getImageUrl().startsWith("http")) { + if (PaperOnboardingPage.getImageHeight() != 0 && PaperOnboardingPage.getImageWidth() != 0) { + Picasso.get() + .load(PaperOnboardingPage.getImageUrl()) + .resize(dpToPixels(PaperOnboardingPage.getImageWidth()), dpToPixels(PaperOnboardingPage.getImageHeight())) + .into(contentIcon); + } else { + Picasso.get().load(PaperOnboardingPage.getImageUrl()).into(contentIcon); + } + } + } else { + if (PaperOnboardingPage.getImageHeight() != 0 && PaperOnboardingPage.getImageWidth() != 0) { + contentIcon.setMinimumHeight(dpToPixels(PaperOnboardingPage.getImageHeight())); + contentIcon.setMinimumWidth(dpToPixels(PaperOnboardingPage.getImageWidth())); + } + contentIcon.setImageResource(PaperOnboardingPage.getContentIconRes()); + } + FrameLayout.LayoutParams iconLP = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); iconLP.gravity = Gravity.CENTER; contentIcon.setLayoutParams(iconLP); diff --git a/paper-onboarding/src/main/java/com/ramotion/paperonboarding/PaperOnboardingPage.java b/paper-onboarding/src/main/java/com/ramotion/paperonboarding/PaperOnboardingPage.java index d90beba..25eeb1a 100644 --- a/paper-onboarding/src/main/java/com/ramotion/paperonboarding/PaperOnboardingPage.java +++ b/paper-onboarding/src/main/java/com/ramotion/paperonboarding/PaperOnboardingPage.java @@ -1,5 +1,7 @@ package com.ramotion.paperonboarding; +import com.ramotion.paperonboarding.utils.TextStyle; + import java.io.Serializable; /** @@ -13,6 +15,17 @@ public class PaperOnboardingPage implements Serializable { private int contentIconRes; private int bottomBarIconRes; + private String imageUrl; + private int imageHeight; + private int imageWidth; + + private int titleTextColor; + private int titleTextSize; + private int descriptionTextColor; + private int descriptionTextSize; + private TextStyle titleTextStyle; + private TextStyle descriptionTextStyle; + public PaperOnboardingPage() { } @@ -24,6 +37,86 @@ public PaperOnboardingPage(String titleText, String descriptionText, int bgColor this.titleText = titleText; } + public PaperOnboardingPage(String titleText, String descriptionText, String imageUrl, int bgColor, int bottomBarIconRes) { + this.titleText = titleText; + this.descriptionText = descriptionText; + this.bgColor = bgColor; + this.bottomBarIconRes = bottomBarIconRes; + this.imageUrl = imageUrl; + } + + public TextStyle getTitleTextStyle() { + return titleTextStyle; + } + + public void setTitleTextStyle(TextStyle titleTextStyle) { + this.titleTextStyle = titleTextStyle; + } + + public TextStyle getDescriptionTextStyle() { + return descriptionTextStyle; + } + + public void setDescriptionTextStyle(TextStyle descriptionTextStyle) { + this.descriptionTextStyle = descriptionTextStyle; + } + + public int getTitleTextSize() { + return titleTextSize; + } + + public void setTitleTextSize(int titleTextSize) { + this.titleTextSize = titleTextSize; + } + + public int getDescriptionTextSize() { + return descriptionTextSize; + } + + public void setDescriptionTextSize(int descriptionTextSize) { + this.descriptionTextSize = descriptionTextSize; + } + + public int getTitleTextColor() { + return titleTextColor; + } + + public void setTitleTextColor(int titleTextColor) { + this.titleTextColor = titleTextColor; + } + + public int getDescriptionTextColor() { + return descriptionTextColor; + } + + public void setDescriptionTextColor(int descriptionTextColor) { + this.descriptionTextColor = descriptionTextColor; + } + + public int getImageHeight() { + return imageHeight; + } + + public void setImageHeight(int imageHeight) { + this.imageHeight = imageHeight; + } + + public int getImageWidth() { + return imageWidth; + } + + public void setImageWidth(int imageWidth) { + this.imageWidth = imageWidth; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + public String getTitleText() { return titleText; } diff --git a/paper-onboarding/src/main/java/com/ramotion/paperonboarding/utils/TextStyle.java b/paper-onboarding/src/main/java/com/ramotion/paperonboarding/utils/TextStyle.java new file mode 100644 index 0000000..f9d134f --- /dev/null +++ b/paper-onboarding/src/main/java/com/ramotion/paperonboarding/utils/TextStyle.java @@ -0,0 +1,18 @@ +package com.ramotion.paperonboarding.utils; + +/** + * TextView Text style values + */ +public enum TextStyle { + + NORMAL(0), + BOLD(1), + ITALIC(2), + BOLD_ITALIC(3); + + public int value; + + TextStyle(int value) { + this.value = value; + } +} \ No newline at end of file