From 517fcfa0eadf026879520e4bc31e450d85d3cdbc Mon Sep 17 00:00:00 2001 From: odeyfox Date: Thu, 7 Oct 2021 22:35:27 +0300 Subject: [PATCH 1/2] - added functionality to load image from URL using Picasso. - added functionality to change "title text color", "description text color", "title text style", "description text style", "title text size", "description text size". - added TextStyle.java Enum. - added internet permission to the fragment example. - added Picasso dependency. --- .../src/main/AndroidManifest.xml | 1 + .../examples/fragment/FragmentsActivity.java | 10 +- .../src/main/AndroidManifest.xml | 2 + paper-onboarding/build.gradle | 1 + .../PaperOnboardingEngine.java | 68 +++++++++++++- .../paperonboarding/PaperOnboardingPage.java | 93 +++++++++++++++++++ .../paperonboarding/utils/TextStyle.java | 18 ++++ 7 files changed, 187 insertions(+), 6 deletions(-) create mode 100644 paper-onboarding/src/main/java/com/ramotion/paperonboarding/utils/TextStyle.java 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 @@ + + + Date: Tue, 30 Nov 2021 15:32:33 +0200 Subject: [PATCH 2/2] - bug fix when text style is not set for title and description. - applied user set height and width for local icon resources. --- .../PaperOnboardingEngine.java | 78 +++++++++++-------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/paper-onboarding/src/main/java/com/ramotion/paperonboarding/PaperOnboardingEngine.java b/paper-onboarding/src/main/java/com/ramotion/paperonboarding/PaperOnboardingEngine.java index ee9bb87..9305538 100644 --- a/paper-onboarding/src/main/java/com/ramotion/paperonboarding/PaperOnboardingEngine.java +++ b/paper-onboarding/src/main/java/com/ramotion/paperonboarding/PaperOnboardingEngine.java @@ -54,7 +54,7 @@ public class PaperOnboardingEngine implements PaperOnboardingEngineDefaults { private final Context mAppContext; // state variables - private ArrayList mElements = new ArrayList<>(); + private final ArrayList mElements = new ArrayList<>(); private int mActiveElementIndex = 0; // params for Pager position calculations, virtually final, but initializes in onGlobalLayoutListener @@ -83,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); @@ -105,7 +105,6 @@ public void onSwipeLeft() { public void onSwipeRight() { toggleContent(true); } - }); mRootLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @@ -127,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); } }); @@ -480,19 +479,23 @@ protected ViewGroup createContentTextView(PaperOnboardingPage PaperOnboardingPag contentTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, PaperOnboardingPage.getTitleTextSize()); } - 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); + 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); @@ -506,21 +509,24 @@ protected ViewGroup createContentTextView(PaperOnboardingPage PaperOnboardingPag contentText.setTextSize(TypedValue.COMPLEX_UNIT_SP, PaperOnboardingPage.getDescriptionTextSize()); } - 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); + 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; } @@ -543,6 +549,10 @@ protected ImageView createContentIconView(PaperOnboardingPage PaperOnboardingPag } } } else { + if (PaperOnboardingPage.getImageHeight() != 0 && PaperOnboardingPage.getImageWidth() != 0) { + contentIcon.setMinimumHeight(dpToPixels(PaperOnboardingPage.getImageHeight())); + contentIcon.setMinimumWidth(dpToPixels(PaperOnboardingPage.getImageWidth())); + } contentIcon.setImageResource(PaperOnboardingPage.getContentIconRes()); }