Skip to content

Commit

Permalink
#62 Add translatable permissions strings for Slides
Browse files Browse the repository at this point in the history
 * Update README.md
 * Add example to app module
  • Loading branch information
bezmian committed Apr 3, 2017
1 parent db289f7 commit b6e9565
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 12 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
<string name="error_message">Please accept terms and conditions first.</string>
<string name="launch_intro_activity">Launch intro activity</string>
<string name="lorem_ipsum">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</string>
<string name="txt_pls_grant_permission">Please grant all permissions</string>
<string name="txt_grant_permission_error">Error! Please grant permissions!</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

public class MessageButtonBehaviourOnPageSelected implements IPageSelectedListener {

private Button messageButton;
private SlidesAdapter adapter;
private SparseArray<MessageButtonBehaviour> messageButtonBehaviours;
private final Button messageButton;
private final SlidesAdapter adapter;
private final SparseArray<MessageButtonBehaviour> messageButtonBehaviours;

public MessageButtonBehaviourOnPageSelected(Button messageButton, SlidesAdapter adapter,
SparseArray<MessageButtonBehaviour> messageButtonBehaviours) {
SparseArray<MessageButtonBehaviour> messageButtonBehaviours) {
this.messageButton = messageButton;
this.adapter = adapter;
this.messageButtonBehaviours = messageButtonBehaviours;
Expand All @@ -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) {
Expand Down

0 comments on commit b6e9565

Please sign in to comment.