Skip to content

Commit 25f9005

Browse files
committed
Can now set max image height
1 parent ea171f7 commit 25f9005

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

onboarder/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 15
99
targetSdkVersion 23
10-
versionCode 2
11-
versionName "1.01"
10+
versionCode 3
11+
versionName "1.02"
1212
}
1313
buildTypes {
1414
release {

onboarder/src/main/java/com/jrejaud/onboarder/OnboardingFragment.java

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class OnboardingFragment extends Fragment implements Serializable {
2525
private static final String IMAGE_RESOURCE_ID = "IMAGE_RESOURCE_ID";
2626
private static final String POSITION = "POSITION";
2727
private static final String BUTTON_TEXT = "BUTTON_TEXT";
28+
private static final String MAX_IMAGE_HEIGHT = "MAX_IMAGE_HEIGHT";
2829

2930
public OnboardingFragment() {
3031
// Required empty public constructor
@@ -40,6 +41,7 @@ public static OnboardingFragment newInstance(OnboardingPage onboardingPage, int
4041
args.putString(BUTTON_TEXT, onboardingPage.getButtonText());
4142
args.putInt(TITLE_TEXT_COLOR, onboardingPage.getTitleTextColor());
4243
args.putInt(BODY_TEXT_COLOR,onboardingPage.getBodyTextColor());
44+
args.putInt(MAX_IMAGE_HEIGHT, onboardingPage.getMaxImageHeight());
4345
fragment.setArguments(args);
4446
return fragment;
4547
}
@@ -62,6 +64,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
6264
final int position = bundle.getInt(POSITION, 0);
6365
/* The button text (if the user set any) */
6466
String buttonText = bundle.getString(BUTTON_TEXT, null);
67+
/* Max height for the image (if not, it just scales it up) */
68+
int maxImageHeight = bundle.getInt(MAX_IMAGE_HEIGHT,-1);
6569

6670
@ColorRes int titleTextColor = bundle.getInt(TITLE_TEXT_COLOR, -1);
6771
@ColorRes int bodyTextColor = bundle.getInt(BODY_TEXT_COLOR,-1);
@@ -96,6 +100,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
96100
//Set the image
97101
if (imageResId !=-1) {
98102
imageView.setImageResource(imageResId);
103+
//Set the max image height (if it was set)
104+
if (maxImageHeight !=-1) {
105+
imageView.setMaxHeight(maxImageHeight);
106+
}
99107
} else {
100108
imageView.setVisibility(View.GONE);
101109
}

onboarder/src/main/java/com/jrejaud/onboarder/OnboardingPage.java

+17-6
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,35 @@ public class OnboardingPage implements Serializable {
1717
private @DrawableRes
1818
int imageResId = -1;
1919

20+
int maxImageHeight = -1;
21+
2022
private String buttonText = null;
2123

22-
public String getTitle() {
24+
protected String getTitle() {
2325
return title;
2426
}
2527

26-
public String getBodyText() {
28+
protected String getBodyText() {
2729
return bodyText;
2830
}
2931

30-
public int getImageResId() {
32+
protected int getImageResId() {
3133
return imageResId;
3234
}
3335

34-
public String getButtonText() {
36+
protected String getButtonText() {
3537
return buttonText;
3638
}
3739

38-
public int getTitleTextColor() {
40+
protected int getTitleTextColor() {
3941
return titleTextColor;
4042
}
4143

4244
public void setTitleTextColor(int titleTextColor) {
4345
this.titleTextColor = titleTextColor;
4446
}
4547

46-
public int getBodyTextColor() {
48+
protected int getBodyTextColor() {
4749
return bodyTextColor;
4850
}
4951

@@ -81,5 +83,14 @@ public OnboardingPage(@Nullable String title,@Nullable String bodyText, @Nullabl
8183
this.buttonText = buttonText;
8284
}
8385

86+
protected int getMaxImageHeight() {
87+
return maxImageHeight;
88+
}
89+
90+
public void setMaxImageHeight(int maxImageHeight) {
91+
this.maxImageHeight = maxImageHeight;
92+
}
93+
94+
8495

8596
}

0 commit comments

Comments
 (0)