Skip to content

Commit

Permalink
Fixed #31; fixed #27; fixed #22; partly fixed #20
Browse files Browse the repository at this point in the history
  • Loading branch information
janheinrichmerker committed Mar 29, 2016
1 parent e1e87e1 commit e6fe290
Show file tree
Hide file tree
Showing 15 changed files with 239 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
public class LoginFragment extends SlideFragment {

private EditText fakeUsername;

private EditText fakePassword;

private Button fakeLogin;

private boolean loggedIn = false;

private Handler loginHandler = new Handler();

private Runnable loginRunnable = new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
import com.heinrichreimersoftware.materialintro.app.OnNavigationBlockedListener;
import com.heinrichreimersoftware.materialintro.slide.FragmentSlide;
import com.heinrichreimersoftware.materialintro.slide.SimpleSlide;
import com.heinrichreimersoftware.materialintro.slide.Slide;

public class MaterialIntroActivity extends IntroActivity {

public static final String EXTRA_FULLSCREEN = "com.heinrichreimersoftware.materialintro.demo.EXTRA_FULLSCREEN";

public static final String EXTRA_SCROLLABLE = "com.heinrichreimersoftware.materialintro.demo.EXTRA_SCROLLABLE";

public static final String EXTRA_CUSTOM_FRAGMENTS = "com.heinrichreimersoftware.materialintro.demo.EXTRA_CUSTOM_FRAGMENTS";

public static final String EXTRA_PERMISSIONS = "com.heinrichreimersoftware.materialintro.demo.EXTRA_PERMISSIONS";

public static final String EXTRA_SKIP_ENABLED = "com.heinrichreimersoftware.materialintro.demo.EXTRA_SKIP_ENABLED";

public static final String EXTRA_FINISH_ENABLED = "com.heinrichreimersoftware.materialintro.demo.EXTRA_FINISH_ENABLED";

@Override
Expand All @@ -28,7 +33,7 @@ protected void onCreate(Bundle savedInstanceState) {
boolean fullscreen = intent.getBooleanExtra(EXTRA_FULLSCREEN, false);
boolean scrollable = intent.getBooleanExtra(EXTRA_SCROLLABLE, false);
boolean customFragments = intent.getBooleanExtra(EXTRA_CUSTOM_FRAGMENTS, true);
final boolean permissions = intent.getBooleanExtra(EXTRA_PERMISSIONS, true);
boolean permissions = intent.getBooleanExtra(EXTRA_PERMISSIONS, true);
boolean skipEnabled = intent.getBooleanExtra(EXTRA_SKIP_ENABLED, true);
boolean finishEnabled = intent.getBooleanExtra(EXTRA_FINISH_ENABLED, true);

Expand Down Expand Up @@ -75,30 +80,38 @@ protected void onCreate(Bundle savedInstanceState) {
.scrollable(scrollable)
.build());

final Slide permissionsSlide;
if (permissions) {
addSlide(new SimpleSlide.Builder()
permissionsSlide = new SimpleSlide.Builder()
.title(R.string.title_permissions)
.description(R.string.description_permissions)
.background(R.color.color_permissions)
.backgroundDark(R.color.color_dark_permissions)
.scrollable(scrollable)
.permissions(new String[]{Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE})
.build());
.build();
addSlide(permissionsSlide);
} else {
permissionsSlide = null;
}

if(customFragments){
addSlide(new FragmentSlide.Builder()
final Slide loginSlide;
if (customFragments) {
loginSlide = new FragmentSlide.Builder()
.background(R.color.color_custom_fragment_1)
.backgroundDark(R.color.color_dark_custom_fragment_1)
.fragment(LoginFragment.newInstance())
.build());
.build();
addSlide(loginSlide);

addSlide(new FragmentSlide.Builder()
.background(R.color.color_custom_fragment_2)
.backgroundDark(R.color.color_dark_custom_fragment_2)
.fragment(R.layout.fragment_custom, R.style.AppThemeDark)
.build());
} else {
loginSlide = null;
}

//Feel free to add a navigation policy to define when users can go forward/backward
Expand All @@ -120,9 +133,13 @@ public boolean canGoBackward(int position) {
@Override
public void onNavigationBlocked(int position, int direction) {
View contentView = findViewById(android.R.id.content);
Snackbar.make(contentView, (permissions && position == 4) ?
R.string.label_grant_permissions : R.string.label_fill_out_form,
Snackbar.LENGTH_LONG).show();
Slide slide = getSlide(position);

if (slide == permissionsSlide) {
Snackbar.make(contentView, R.string.label_grant_permissions, Snackbar.LENGTH_LONG).show();
} else if (slide == loginSlide) {
Snackbar.make(contentView, R.string.label_fill_out_form, Snackbar.LENGTH_LONG).show();
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_github.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
android:viewportWidth="24">
<path
android:fillColor="#fff"
android:pathData="M12,2A10,10 0 0,0 2,12C2,16.42 4.87,20.17 8.84,21.5C9.34,21.58 9.5,21.27 9.5,21C9.5,20.77 9.5,20.14 9.5,19.31C6.73,19.91 6.14,17.97 6.14,17.97C5.68,16.81 5.03,16.5 5.03,16.5C4.12,15.88 5.1,15.9 5.1,15.9C6.1,15.97 6.63,16.93 6.63,16.93C7.5,18.45 8.97,18 9.54,17.76C9.63,17.11 9.89,16.67 10.17,16.42C7.95,16.17 5.62,15.31 5.62,11.5C5.62,10.39 6,9.5 6.65,8.79C6.55,8.54 6.2,7.5 6.75,6.15C6.75,6.15 7.59,5.88 9.5,7.17C10.29,6.95 11.15,6.84 12,6.84C12.85,6.84 13.71,6.95 14.5,7.17C16.41,5.88 17.25,6.15 17.25,6.15C17.8,7.5 17.45,8.54 17.35,8.79C18,9.5 18.38,10.39 18.38,11.5C18.38,15.32 16.04,16.16 13.81,16.41C14.17,16.72 14.5,17.33 14.5,18.26C14.5,19.6 14.5,20.68 14.5,21C14.5,21.27 14.66,21.59 15.17,21.5C19.14,20.16 22,16.42 22,12A10,10 0 0,0 12,2Z" />
android:pathData="M12,2A10,10 0 0,0 2,12C2,16.42 4.87,20.17 8.84,21.5C9.34,21.58 9.5,21.27 9.5,21C9.5,20.77 9.5,20.14 9.5,19.31C6.73,19.91 6.14,17.97 6.14,17.97C5.68,16.81 5.03,16.5 5.03,16.5C4.12,15.88 5.1,15.9 5.1,15.9C6.1,15.97 6.63,16.93 6.63,16.93C7.5,18.45 8.97,18 9.54,17.76C9.63,17.11 9.89,16.67 10.17,16.42C7.95,16.17 5.62,15.31 5.62,11.5C5.62,10.39 6,9.5 6.65,8.79C6.55,8.54 6.2,7.5 6.75,6.15C6.75,6.15 7.59,5.88 9.5,7.17C10.29,6.95 11.15,6.84 12,6.84C12.85,6.84 13.71,6.95 14.5,7.17C16.41,5.88 17.25,6.15 17.25,6.15C17.8,7.5 17.45,8.54 17.35,8.79C18,9.5 18.38,10.39 18.38,11.5C18.38,15.32 16.04,16.16 13.81,16.41C14.17,16.72 14.5,17.33 14.5,18.26C14.5,19.6 14.5,20.68 14.5,21C14.5,21.27 14.66,21.59 15.17,21.5C19.14,20.16 22,16.42 22,12A10,10 0 0,0 12,2Z"/>
</vector>
12 changes: 6 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
android:layout_height="wrap_content"
android:gravity=""
android:text="@string/label_options"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"/>

<CheckBox
android:id="@+id/option_fullscreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/baseline"
android:checked="false"
android:text="@string/label_option_fullscreen" />
android:text="@string/label_option_fullscreen"/>

<CheckBox
android:id="@+id/option_scrollable"
Expand All @@ -66,7 +66,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/baseline"
android:checked="true"
android:text="@string/label_option_custom_fragments" />
android:text="@string/label_option_custom_fragments"/>

<CheckBox
android:id="@+id/option_permissions"
Expand All @@ -82,15 +82,15 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/baseline"
android:checked="true"
android:text="@string/label_option_skip_enabled" />
android:text="@string/label_option_skip_enabled"/>

<CheckBox
android:id="@+id/option_finish_enabled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/baseline"
android:checked="true"
android:text="@string/label_option_finish_enabled" />
android:text="@string/label_option_finish_enabled"/>

<CheckBox
android:id="@+id/option_start_new_activity"
Expand All @@ -106,7 +106,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/baseline"
android:text="@string/label_start_intro"
android:theme="@style/AppThemeDark" />
android:theme="@style/AppThemeDark"/>

</LinearLayout>

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/fragment_custom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/title_fragment_custom"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />
android:textAppearance="@style/TextAppearance.AppCompat.Headline"/>

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/baseline"
android:src="@drawable/art_plane"
tools:ignore="ContentDescription" />
tools:ignore="ContentDescription"/>

<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/baseline" />
android:layout_marginTop="@dimen/baseline"/>

<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="@dimen/mi_pager_margin_bottom" />
android:layout_height="@dimen/mi_pager_margin_bottom"/>

</LinearLayout>
10 changes: 5 additions & 5 deletions app/src/main/res/layout/fragment_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/title_fragment_login"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />
android:textAppearance="@style/TextAppearance.AppCompat.Headline"/>

<EditText
android:id="@+id/fakeUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/baseline"
android:hint="@string/hint_fake_username" />
android:hint="@string/hint_fake_username"/>

<EditText
android:id="@+id/fakePassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_fake_password"
android:inputType="textPassword" />
android:inputType="textPassword"/>

<Button
android:id="@+id/fakeLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/baseline"
android:text="@string/label_fake_login"
android:theme="@style/AppThemeDark" />
android:theme="@style/AppThemeDark"/>

<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="@dimen/mi_pager_margin_bottom" />
android:layout_height="@dimen/mi_pager_margin_bottom"/>

</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/menu/menu_activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
android:id="@+id/menu_item_github"
android:icon="@drawable/ic_github"
android:title="@string/title_menu_github"
app:showAsAction="ifRoom" />
app:showAsAction="ifRoom"/>
</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimaryDark">@color/color_primary_dark</item>
<item name="colorAccent">@color/color_accent</item>
<item name="colorButtonNormal">@color/color_accent</item>
</style>

<style name="AppThemeDark" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimaryDark">@color/color_primary_dark</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
@NonNull int[] grantResults) {
FragmentManager fragmentManager = getSupportFragmentManager();
for (Fragment fragment : fragmentManager.getFragments()) {
fragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (fragment != null) {
fragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,22 @@ public static Fragment newInstance(@LayoutRes int layoutRes, @StyleRes int theme
}

public static Fragment newInstance(@LayoutRes int layoutRes) {
return newInstance(layoutRes, -1);
return newInstance(layoutRes, 0);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Context contextThemeWrapper = new ContextThemeWrapper(getActivity(),
getArguments().getInt(ARGUMENT_THEME_RES));
int themeRes = getArguments().getInt(ARGUMENT_THEME_RES, 0);
Context contextThemeWrapper;
if (themeRes != 0) {
contextThemeWrapper = new ContextThemeWrapper(getActivity(), themeRes);
} else {
contextThemeWrapper = getActivity();
}
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);

return localInflater.inflate(getArguments().getInt(ARGUMENT_LAYOUT_RES), container, false);
return localInflater.inflate(getArguments().getInt(ARGUMENT_LAYOUT_RES, 0), container, false);
}
}
}
Loading

0 comments on commit e6fe290

Please sign in to comment.