diff --git a/README.md b/README.md index 8cfddb0..c422cdd 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ public class IntroActivity extends MaterialIntroActivity .possiblePermissions(new String[]{Manifest.permission.CALL_PHONE, Manifest.permission.READ_SMS}) .neededPermissions(new String[]{Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}) .image(agency.tango.materialintroscreen.R.drawable.ic_next) + .grantPermissionMessage(R.string.txt_pls_grant_permission) + .grantPermissionError(R.string.txt_grant_permission_error) .title("title 3") .description("Description 3") .build(), @@ -100,7 +102,9 @@ getBackButtonTranslationWrapper() - ```cantMoveFurtherErrorMessage()``` (as above) - ```neededPermissions()``` - ```possiblePermissions()``` - + - ```grantPermissionStringRes()``` + - ```grantPermissionErrorStringRes()``` + #### If you want to use parallax in a fragment please use one of the below views: - [```ParallaxFrameLayout```][ParallaxFrame] - [```ParallaxLinearLayout```][ParallaxLinear] diff --git a/app/src/main/java/agency/tango/materialintro/IntroActivity.java b/app/src/main/java/agency/tango/materialintro/IntroActivity.java index 6b9b991..13fc35c 100644 --- a/app/src/main/java/agency/tango/materialintro/IntroActivity.java +++ b/app/src/main/java/agency/tango/materialintro/IntroActivity.java @@ -61,6 +61,8 @@ public void onClick(View v) { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}) .image(R.drawable.img_equipment) + .grantPermissionMessage(R.string.txt_pls_grant_permission) + .grantPermissionError(R.string.txt_grant_permission_error) .title("We provide best tools") .description("ever") .build(), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3d330c6..32bc9d6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,4 +4,6 @@ Please accept terms and conditions first. Launch intro activity Lorem ipsum \n\ndolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure + Please grant all permissions + Error! Please grant permissions! diff --git a/build.gradle b/build.gradle index 3908003..8a312c7 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.3' + classpath 'com.android.tools.build:gradle:2.3.0' classpath 'com.novoda:bintray-release:0.3.4' classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1' classpath 'com.palantir:jacoco-coverage:0.4.0' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 04e285f..556bfea 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 10:00:20 PST 2015 +#Mon Apr 03 12:02:18 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/material-intro-screen/src/main/java/agency/tango/materialintroscreen/MaterialIntroActivity.java b/material-intro-screen/src/main/java/agency/tango/materialintroscreen/MaterialIntroActivity.java index 595844f..dd3fb3c 100644 --- a/material-intro-screen/src/main/java/agency/tango/materialintroscreen/MaterialIntroActivity.java +++ b/material-intro-screen/src/main/java/agency/tango/materialintroscreen/MaterialIntroActivity.java @@ -173,7 +173,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { } public void showPermissionsNotGrantedError() { - showError(getString(R.string.mis_please_grant_permissions)); + showError(getString(adapter.getItem(viewPager.getCurrentItem()).grantPermissionErrorStringRes())); } /** diff --git a/material-intro-screen/src/main/java/agency/tango/materialintroscreen/fragments/SlideFragment.java b/material-intro-screen/src/main/java/agency/tango/materialintroscreen/fragments/SlideFragment.java index 40bd55f..4f1d47b 100644 --- a/material-intro-screen/src/main/java/agency/tango/materialintroscreen/fragments/SlideFragment.java +++ b/material-intro-screen/src/main/java/agency/tango/materialintroscreen/fragments/SlideFragment.java @@ -4,6 +4,7 @@ import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; +import android.support.annotation.StringRes; import android.support.v4.content.ContextCompat; import android.view.LayoutInflater; import android.view.View; @@ -22,6 +23,8 @@ public class SlideFragment extends SlideFragmentBase { public static final String NEEDED_PERMISSIONS = "needed_permission"; public static final String POSSIBLE_PERMISSIONS = "possible_permission"; public static final String IMAGE = "image"; + public static final String GRANT_PERMISSION_MESSAGE = "grant_permission_message"; + public static final String GRANT_PERMISSION_ERROR = "grant_permission_error"; @ColorRes private int backgroundColor; @@ -32,6 +35,12 @@ public class SlideFragment extends SlideFragmentBase { @DrawableRes private int image; + @StringRes + private int grantPermissionStringRes; + + @StringRes + private int grantPermissionErrorStringRes; + private String title; private String description; private String[] neededPermissions; @@ -50,7 +59,7 @@ public static SlideFragment createInstance(Bundle bundle) { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) { + @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.mis_fragment_slide, container, false); titleTextView = (TextView) view.findViewById(R.id.txt_title_slide); descriptionTextView = (TextView) view.findViewById(R.id.txt_description_slide); @@ -91,6 +100,16 @@ public String cantMoveFurtherErrorMessage() { return getString(R.string.mis_impassable_slide); } + @Override + public int grantPermissionStringRes() { + return grantPermissionStringRes; + } + + @Override + public int grantPermissionErrorStringRes() { + return grantPermissionErrorStringRes; + } + private void initializeView() { Bundle bundle = getArguments(); backgroundColor = bundle.getInt(BACKGROUND_COLOR); @@ -100,6 +119,8 @@ private void initializeView() { description = bundle.getString(DESCRIPTION); neededPermissions = bundle.getStringArray(NEEDED_PERMISSIONS); possiblePermissions = bundle.getStringArray(POSSIBLE_PERMISSIONS); + grantPermissionStringRes = bundle.getInt(GRANT_PERMISSION_MESSAGE); + grantPermissionErrorStringRes = bundle.getInt(GRANT_PERMISSION_ERROR); updateViewWithValues(); } @@ -112,5 +133,13 @@ private void updateViewWithValues() { imageView.setImageDrawable(ContextCompat.getDrawable(getActivity(), image)); imageView.setVisibility(View.VISIBLE); } + + if (grantPermissionStringRes == 0) { + grantPermissionStringRes = R.string.mis_grant_permissions; + } + + if (grantPermissionErrorStringRes == 0) { + grantPermissionErrorStringRes = R.string.mis_please_grant_permissions; + } } } \ No newline at end of file diff --git a/material-intro-screen/src/main/java/agency/tango/materialintroscreen/fragments/SlideFragmentBase.java b/material-intro-screen/src/main/java/agency/tango/materialintroscreen/fragments/SlideFragmentBase.java index d770c54..dc0eca0 100644 --- a/material-intro-screen/src/main/java/agency/tango/materialintroscreen/fragments/SlideFragmentBase.java +++ b/material-intro-screen/src/main/java/agency/tango/materialintroscreen/fragments/SlideFragmentBase.java @@ -2,6 +2,7 @@ import android.content.pm.PackageManager; import android.support.annotation.ColorRes; +import android.support.annotation.StringRes; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; @@ -42,6 +43,16 @@ public String[] neededPermissions() { return new String[0]; } + @StringRes + public int grantPermissionStringRes() { + return R.string.mis_grant_permissions; + } + + @StringRes + public int grantPermissionErrorStringRes() { + return R.string.mis_please_grant_permissions; + } + public boolean hasAnyPermissionsToGrant() { boolean hasPermissionToGrant = hasPermissionsToGrant(neededPermissions()); if (!hasPermissionToGrant) { diff --git a/material-intro-screen/src/main/java/agency/tango/materialintroscreen/fragments/SlideFragmentBuilder.java b/material-intro-screen/src/main/java/agency/tango/materialintroscreen/fragments/SlideFragmentBuilder.java index 90fe1a2..51d5660 100644 --- a/material-intro-screen/src/main/java/agency/tango/materialintroscreen/fragments/SlideFragmentBuilder.java +++ b/material-intro-screen/src/main/java/agency/tango/materialintroscreen/fragments/SlideFragmentBuilder.java @@ -3,10 +3,13 @@ import android.os.Bundle; import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; +import android.support.annotation.StringRes; import static agency.tango.materialintroscreen.fragments.SlideFragment.BACKGROUND_COLOR; import static agency.tango.materialintroscreen.fragments.SlideFragment.BUTTONS_COLOR; import static agency.tango.materialintroscreen.fragments.SlideFragment.DESCRIPTION; +import static agency.tango.materialintroscreen.fragments.SlideFragment.GRANT_PERMISSION_ERROR; +import static agency.tango.materialintroscreen.fragments.SlideFragment.GRANT_PERMISSION_MESSAGE; import static agency.tango.materialintroscreen.fragments.SlideFragment.IMAGE; import static agency.tango.materialintroscreen.fragments.SlideFragment.NEEDED_PERMISSIONS; import static agency.tango.materialintroscreen.fragments.SlideFragment.POSSIBLE_PERMISSIONS; @@ -24,6 +27,12 @@ public class SlideFragmentBuilder { @DrawableRes private int image; + @StringRes + private int grantPermissionMessage; + + @StringRes + private int grantPermissionError; + private String title; private String description; private String[] neededPermissions; @@ -64,6 +73,17 @@ public SlideFragmentBuilder image(@DrawableRes int image) { return this; } + public SlideFragmentBuilder grantPermissionMessage(@StringRes int grantPermissionMessage) { + this.grantPermissionMessage = grantPermissionMessage; + return this; + } + + public SlideFragmentBuilder grantPermissionError(int grantPermissionError) { + this.grantPermissionError = grantPermissionError; + return this; + } + + public SlideFragment build() { String missing = ""; if (backgroundColor == 0) { @@ -85,6 +105,8 @@ public SlideFragment build() { bundle.putString(DESCRIPTION, description); bundle.putStringArray(NEEDED_PERMISSIONS, neededPermissions); bundle.putStringArray(POSSIBLE_PERMISSIONS, possiblePermissions); + bundle.putInt(GRANT_PERMISSION_MESSAGE, grantPermissionMessage); + bundle.putInt(GRANT_PERMISSION_ERROR, grantPermissionError); return SlideFragment.createInstance(bundle); } diff --git a/material-intro-screen/src/main/java/agency/tango/materialintroscreen/listeners/MessageButtonBehaviourOnPageSelected.java b/material-intro-screen/src/main/java/agency/tango/materialintroscreen/listeners/MessageButtonBehaviourOnPageSelected.java index 9402b49..be89b13 100644 --- a/material-intro-screen/src/main/java/agency/tango/materialintroscreen/listeners/MessageButtonBehaviourOnPageSelected.java +++ b/material-intro-screen/src/main/java/agency/tango/materialintroscreen/listeners/MessageButtonBehaviourOnPageSelected.java @@ -15,12 +15,12 @@ public class MessageButtonBehaviourOnPageSelected implements IPageSelectedListener { - private Button messageButton; - private SlidesAdapter adapter; - private SparseArray messageButtonBehaviours; + private final Button messageButton; + private final SlidesAdapter adapter; + private final SparseArray messageButtonBehaviours; public MessageButtonBehaviourOnPageSelected(Button messageButton, SlidesAdapter adapter, - SparseArray messageButtonBehaviours) { + SparseArray messageButtonBehaviours) { this.messageButton = messageButton; this.adapter = adapter; this.messageButtonBehaviours = messageButtonBehaviours; @@ -32,8 +32,8 @@ public void pageSelected(int position) { if (slideFragment.hasAnyPermissionsToGrant()) { showMessageButton(slideFragment); - messageButton - .setText(slideFragment.getActivity().getString(R.string.mis_grant_permissions)); + messageButton.setText( + slideFragment.getString(adapter.getItem(position).grantPermissionStringRes())); messageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) {