Skip to content

Commit

Permalink
User can now set the Fragment title and body text colors
Browse files Browse the repository at this point in the history
  • Loading branch information
jrejaud committed Mar 12, 2016
1 parent d634fbb commit d9eaba8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ public class OnboardingFragment extends Fragment implements Serializable {

// the fragment initialization parameters
private static final String TITLE = "TITLE";
private final static String TITLE_TEXT_COLOR = "TITLE_TEXT_COLOR";
private static final String BODY_TEXT = "BODY_TEXT";
private final static String BODY_TEXT_COLOR = "TITLE_TEXT_COLOR";
private static final String IMAGE_RESOURCE_ID = "IMAGE_RESOURCE_ID";
private static final String POSITION = "POSITION";
private static final String BUTTON_TEXT = "BUTTON_TEXT";
public final static String BUTTON_BACKGROUND_COLOR = "BUTTON_BACKGROUND_COLOR";

public OnboardingFragment() {
// Required empty public constructor
Expand All @@ -37,6 +38,8 @@ public static OnboardingFragment newInstance(OnboardingPage onboardingPage, int
args.putInt(IMAGE_RESOURCE_ID, onboardingPage.getImageResId());
args.putInt(POSITION, position);
args.putString(BUTTON_TEXT, onboardingPage.getButtonText());
args.putInt(TITLE_TEXT_COLOR, onboardingPage.getTitleTextColor());
args.putInt(BODY_TEXT_COLOR,onboardingPage.getBodyTextColor());
fragment.setArguments(args);
return fragment;
}
Expand All @@ -60,6 +63,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
/* The button text (if the user set any) */
String buttonText = bundle.getString(BUTTON_TEXT, null);

@ColorRes int titleTextColor = bundle.getInt(TITLE_TEXT_COLOR, -1);
@ColorRes int bodyTextColor = bundle.getInt(BODY_TEXT_COLOR,-1);

TextView titleTextView = (TextView) view.findViewById(R.id.onboarding_fragment_title);
TextView bodyTextView = (TextView) view.findViewById(R.id.onboarding_fragment_body_text);
ImageView imageView = (ImageView) view.findViewById(R.id.onboarding_fragment_image);
Expand All @@ -68,13 +74,21 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
//Set the title
if (title !=null) {
titleTextView.setText(title);
//Set the body text color
if (titleTextColor!=-1) {
titleTextView.setTextColor(getResources().getColor(titleTextColor));
}
} else {
titleTextView.setVisibility(View.GONE);
}

//Set the body text
if (bodyText !=null) {
bodyTextView.setText(bodyText);
//Set the body text color
if (bodyTextColor!=-1) {
bodyTextView.setTextColor(getResources().getColor(bodyTextColor));
}
} else {
bodyTextView.setVisibility(View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
*/
public class OnboardingPage implements Serializable {
private String title;
private @ColorRes int titleTextColor = -1;
private String bodyText;
private @ColorRes int bodyTextColor = -1;
private @DrawableRes
int imageResId = -1;

private String buttonText = null;


public String getTitle() {
return title;
}
Expand All @@ -34,6 +35,23 @@ public String getButtonText() {
return buttonText;
}

public int getTitleTextColor() {
return titleTextColor;
}

public void setTitleTextColor(int titleTextColor) {
this.titleTextColor = titleTextColor;
}

public int getBodyTextColor() {
return bodyTextColor;
}

public void setBodyTextColor(int bodyTextColor) {
this.bodyTextColor = bodyTextColor;
}



public OnboardingPage(@Nullable String title,@Nullable String bodyText) {
this.title = title;
Expand Down

0 comments on commit d9eaba8

Please sign in to comment.