Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #58 #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ramotion.paperonboarding.examples.fragment">

<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import android.graphics.Color;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.ramotion.paperonboarding.PaperOnboardingFragment;
import com.ramotion.paperonboarding.PaperOnboardingPage;
import com.ramotion.paperonboarding.listeners.PaperOnboardingOnRightOutListener;

import java.util.ArrayList;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

public class FragmentsActivity extends AppCompatActivity {

private FragmentManager fragmentManager;
Expand Down
2 changes: 2 additions & 0 deletions paper-onboarding-simple-example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ramotion.paperonboarding.examples.simple">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
1 change: 1 addition & 0 deletions paper-onboarding/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.squareup.picasso:picasso:2.71828'
testImplementation 'junit:junit:4.12'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Build;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -26,6 +28,7 @@
import com.ramotion.paperonboarding.listeners.PaperOnboardingOnLeftOutListener;
import com.ramotion.paperonboarding.listeners.PaperOnboardingOnRightOutListener;
import com.ramotion.paperonboarding.utils.PaperOnboardingEngineDefaults;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

Expand All @@ -51,7 +54,7 @@ public class PaperOnboardingEngine implements PaperOnboardingEngineDefaults {
private final Context mAppContext;

// state variables
private ArrayList<PaperOnboardingPage> mElements = new ArrayList<>();
private final ArrayList<PaperOnboardingPage> mElements = new ArrayList<>();
private int mActiveElementIndex = 0;

// params for Pager position calculations, virtually final, but initializes in onGlobalLayoutListener
Expand Down Expand Up @@ -80,10 +83,10 @@ public PaperOnboardingEngine(View rootLayout, ArrayList<PaperOnboardingPage> 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);
Expand All @@ -102,7 +105,6 @@ public void onSwipeLeft() {
public void onSwipeRight() {
toggleContent(true);
}

});

mRootLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
Expand All @@ -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);

}
});
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ramotion.paperonboarding;

import com.ramotion.paperonboarding.utils.TextStyle;

import java.io.Serializable;

/**
Expand All @@ -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() {
}

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}