Skip to content

Commit

Permalink
Added ability to change title and description colors and to set drawa…
Browse files Browse the repository at this point in the history
…ble resources
  • Loading branch information
Dzmitry Chyrta committed Apr 3, 2016
1 parent cebc618 commit b6fdbb3
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 30 deletions.
2 changes: 0 additions & 2 deletions onboarder/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
android:label="@string/app_name"
android:supportsRtl="true">

<activity android:name=".OnboarderActivity"/>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,56 @@
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

import java.util.ArrayList;
import java.util.List;

public class OnboarderActivity extends AppCompatActivity {
public class OnboarderActivity extends AppCompatActivity implements View.OnClickListener {

ViewPager vpOnboarderPager;
OnboarderAdapter onboarderAdapter;
ImageButton ibNext;
Button btnSkip, btnFinish;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStatusBackgroundColor();
setContentView(R.layout.activity_onboarder);
ibNext = (ImageButton) findViewById(R.id.ib_next);
btnSkip = (Button) findViewById(R.id.btn_skip);
btnFinish = (Button) findViewById(R.id.btn_finish);
vpOnboarderPager = (ViewPager) findViewById(R.id.vp_onboarder_pager);
ibNext.setOnClickListener(this);
btnSkip.setOnClickListener(this);
btnFinish.setOnClickListener(this);
}

public void setOnboardPagesReady(List<OnboarderPage> pages) {
onboarderAdapter = new OnboarderAdapter(pages, getSupportFragmentManager());
vpOnboarderPager.setAdapter(onboarderAdapter);
}

public void setStatusBackgroundColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.black_transparent));
}

setContentView(R.layout.activity_onboarder);
}

public void setOnboardPages(List<OnboarderPage> pages) {
onboarderAdapter = new OnboarderAdapter(pages, getSupportFragmentManager());
vpOnboarderPager.setAdapter(onboarderAdapter);
@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.ib_next) {
} else if (i == R.id.btn_skip) {
} else if (i == R.id.btn_finish) {
} else {
}
}


}
48 changes: 32 additions & 16 deletions onboarder/src/main/java/com/chyrta/onboarder/OnboarderFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -17,13 +22,15 @@ public class OnboarderFragment extends Fragment {
private static final String ONBOARDER_PAGE_DESCRIPTION = "onboarder_page_description";
private static final String ONBOARDER_PAGE_DESCRIPTION_RES_ID = "onboarder_page_description_res_id";
private static final String ONBOARDER_PAGE_DESCRIPTION_COLOR = "onborader_page_description_color";
private static final String ONBOARDER_PAGE_IMAGE_RES_ID = "onboarder_page_iamge_res_id";

private String onboarderTitle;
private String onboarderDescription;
private int onboarderTitleResId;
private int onboarderTitleColor;
private int onboarderDescriptionResId;
private int onboarderDescriptionColor;
@StringRes private int onboarderTitleResId;
@ColorRes private int onboarderTitleColor;
@StringRes private int onboarderDescriptionResId;
@ColorRes private int onboarderDescriptionColor;
@DrawableRes private int onboarderImageResId;

private View onboarderView;
private ImageView ivOnboarderImage;
Expand All @@ -40,6 +47,7 @@ public static OnboarderFragment newInstance(OnboarderPage page) {
args.putInt(ONBOARDER_PAGE_DESCRIPTION_RES_ID, page.getDescriptionResourceId());
args.putInt(ONBOARDER_PAGE_TITLE_COLOR, page.getTitleColor());
args.putInt(ONBOARDER_PAGE_DESCRIPTION_COLOR, page.getDescriptionColor());
args.putInt(ONBOARDER_PAGE_IMAGE_RES_ID, page.getImageResourceId());
OnboarderFragment fragment = new OnboarderFragment();
fragment.setArguments(args);
return fragment;
Expand All @@ -56,11 +64,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
Bundle bundle = getArguments();

onboarderTitle = bundle.getString(ONBOARDER_PAGE_TITLE, null);
onboarderTitleResId = bundle.getInt(ONBOARDER_PAGE_TITLE_RES_ID, -1);
onboarderTitleColor = bundle.getInt(ONBOARDER_PAGE_TITLE_COLOR, -1);
onboarderTitleResId = bundle.getInt(ONBOARDER_PAGE_TITLE_RES_ID, 0);
onboarderTitleColor = bundle.getInt(ONBOARDER_PAGE_TITLE_COLOR, 0);
onboarderDescription = bundle.getString(ONBOARDER_PAGE_DESCRIPTION, null);
onboarderDescriptionResId = bundle.getInt(ONBOARDER_PAGE_DESCRIPTION_RES_ID, -1);
onboarderDescriptionColor = bundle.getInt(ONBOARDER_PAGE_DESCRIPTION_COLOR, -1);
onboarderDescriptionResId = bundle.getInt(ONBOARDER_PAGE_DESCRIPTION_RES_ID, 0);
onboarderDescriptionColor = bundle.getInt(ONBOARDER_PAGE_DESCRIPTION_COLOR, 0);
onboarderImageResId = bundle.getInt(ONBOARDER_PAGE_IMAGE_RES_ID, 0);

onboarderView = inflater.inflate(R.layout.fragment_onboarder, container, false);
ivOnboarderImage = (ImageView) onboarderView.findViewById(R.id.iv_onboarder_image);
Expand All @@ -71,24 +80,31 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
tvOnboarderTitle.setText(onboarderTitle);
}

if (onboarderTitleResId != -1) {
tvOnboarderTitle.setText(onboarderTitleResId);
if (onboarderTitleResId != 0) {
tvOnboarderTitle.setText(getResources().getString(onboarderTitleResId));
}

if (onboarderDescription != null) {
tvOnboarderDescription.setText(onboarderDescription);
}

if (onboarderDescriptionResId != -1) {
tvOnboarderDescription.setText(onboarderDescriptionResId);
if (onboarderDescriptionResId != 0) {
tvOnboarderDescription.setText(getResources().getString(onboarderDescriptionResId));
}

if (onboarderTitleColor != -1) {
tvOnboarderTitle.setTextColor(onboarderTitleColor);
if (onboarderTitleColor != 0) {
Log.v("ONBOARD_TITLE_COLOR", String.valueOf(onboarderTitleColor));
tvOnboarderTitle.setTextColor(ContextCompat.getColor(getActivity(), onboarderTitleColor));
}

if (onboarderDescriptionColor != -1) {
tvOnboarderDescription.setTextColor(onboarderDescriptionColor);
if (onboarderDescriptionColor != 0) {
Log.v("ONBOARD_DESC_COLOR", String.valueOf(onboarderDescriptionColor));
tvOnboarderDescription.setTextColor(ContextCompat.getColor(getActivity(), onboarderDescriptionColor));
}

if (onboarderImageResId != 0) {
Log.v("ONBOARD_IMAGE", String.valueOf(onboarderImageResId));
ivOnboarderImage.setImageDrawable(ContextCompat.getDrawable(getActivity(), onboarderImageResId));
}

return onboarderView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,12 @@ public void setDescriptionColor(int color) {
this.descriptionColor = color;
}

public void setImageResourceId(int imageResourceId) {
this.imageResourceId = imageResourceId;
}

public int getImageResourceId() {
return imageResourceId;
}

}
2 changes: 2 additions & 0 deletions onboarder/src/main/res/layout/activity_onboarder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:layout_height="match_parent">

<android.support.v4.view.ViewPager
android:id="@+id/vp_onboarder_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="?attr/actionBarSize"/>
Expand All @@ -22,6 +23,7 @@
android:padding="@dimen/activity_margin">

<Button
android:id="@+id/btn_skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.Button.Borderless"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.os.Bundle;

import com.chyrta.onboarder.OnboarderActivity;
import com.chyrta.onboarder.OnboarderAdapter;
import com.chyrta.onboarder.OnboarderPage;

import java.util.ArrayList;
Expand All @@ -14,16 +15,23 @@ public class IntroActivity extends OnboarderActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

OnboarderPage onboarderPage1 = new OnboarderPage("Title 1", "Description 1");
OnboarderPage onboarderPage1 = new OnboarderPage("Title 1", "Title 2", R.drawable.ic_chevron_right);
onboarderPage1.setTitleColor(R.color.colorPrimary);
onboarderPage1.setDescriptionColor(R.color.colorAccent);
OnboarderPage onboarderPage2 = new OnboarderPage("Title 2", "Description 2");
OnboarderPage onboarderPage3 = new OnboarderPage("Title 1", "Description 3");
onboarderPage2.setTitleColor(R.color.colorPrimaryDark);
onboarderPage2.setDescriptionColor(R.color.colorAccent);
OnboarderPage onboarderPage3 = new OnboarderPage("Title 3", "Description 3");
// onboarderPage3.setTitleColor(R.color.colorPrimaryDark);
// onboarderPage3.setDescriptionColor(R.color.colorAccent);

List<OnboarderPage> pages = new ArrayList<>();

pages.add(onboarderPage1);
pages.add(onboarderPage2);
pages.add(onboarderPage3);

setOnboardPages(pages);
setOnboardPagesReady(pages);

}
}
4 changes: 2 additions & 2 deletions sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorPrimary">#732628</color>
<color name="colorPrimaryDark">#62ff00</color>
<color name="colorAccent">#FF4081</color>
</resources>
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':onboarder'
include ':onboarder', ':sample'

0 comments on commit b6fdbb3

Please sign in to comment.