Skip to content

Commit

Permalink
Merge pull request #16 from Maxr1998/master
Browse files Browse the repository at this point in the history
Don't require setting all values in SimpleSlide.Builder, fixes #5
  • Loading branch information
janheinrichmerker committed Mar 7, 2016
2 parents 9584372 + dcac485 commit 3701e97
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ public Builder scrollable(boolean scrollable) {
}

public SimpleSlide build(){
if (title == 0 || description == 0 || image == 0 || background == 0)
throw new IllegalArgumentException("You must set at least a title, description, image, and background.");
return new SimpleSlide(this);
}
}
Expand Down Expand Up @@ -145,28 +143,31 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
TextView description = (TextView) fragment.findViewById(R.id.mi_description);
ImageView image = (ImageView) fragment.findViewById(R.id.mi_image);

int titleRes = arguments.getInt(ARGUMENT_TITLE_RES);
int descRes = arguments.getInt(ARGUMENT_DESCRIPTION_RES);
int imgRes = arguments.getInt(ARGUMENT_IMAGE_RES);
int backgroundRes = arguments.getInt(ARGUMENT_BACKGROUND_RES);

title.setText(arguments.getInt(ARGUMENT_TITLE_RES));
description.setText(arguments.getInt(ARGUMENT_DESCRIPTION_RES));
image.setImageResource(arguments.getInt(ARGUMENT_IMAGE_RES));
if (titleRes != 0)
title.setText(titleRes);
if (descRes != 0)
description.setText(descRes);
if (imgRes != 0)
image.setImageResource(imgRes);

int background = ContextCompat.getColor(getContext(),
arguments.getInt(ARGUMENT_BACKGROUND_RES));
if(ColorUtils.calculateLuminance(background) > 0.6){
if (backgroundRes != 0 && ColorUtils.calculateLuminance(ContextCompat.getColor(getContext(), backgroundRes)) > 0.6) {
//Use dark text color
title.setTextColor(ContextCompat.getColor(getContext(),
R.color.mi_text_color_primary_light));
description.setTextColor(ContextCompat.getColor(getContext(),
R.color.mi_text_color_secondary_light));
}
else {
} else {
//Use light text color
title.setTextColor(ContextCompat.getColor(getContext(),
R.color.mi_text_color_primary_dark));
description.setTextColor(ContextCompat.getColor(getContext(),
R.color.mi_text_color_secondary_dark));
}

return fragment;
}
}
Expand Down

0 comments on commit 3701e97

Please sign in to comment.