Skip to content

Commit

Permalink
Update dependencies, lock orientation while intro is running, add pos…
Browse files Browse the repository at this point in the history
…ition navigation blocked listener, clean up SlideFragment
  • Loading branch information
janheinrichmerker committed Mar 21, 2017
1 parent 615fdf3 commit dbae320
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 24 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ android {
dependencies {
compile project(':library')
//Support
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:support-v4:25.3.0'
compile 'com.android.support:design:25.3.0'
//Firebase
compile 'com.google.firebase:firebase-core:10.2.0'
compile 'com.google.firebase:firebase-crash:10.2.0'
Expand Down
12 changes: 6 additions & 6 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Mar 09 14:27:07 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
#Thu Mar 09 14:27:07 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:appcompat-v7:25.3.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
Expand Down Expand Up @@ -142,6 +144,8 @@ public class IntroActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

lockOrientation();

pageScrollInterpolator = AnimationUtils.loadInterpolator(this, android.R.interpolator.accelerate_decelerate);
pageScrollDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);

Expand Down Expand Up @@ -240,6 +244,8 @@ public Intent onSendActivityResult(int result) {
protected void onDestroy() {
if (isAutoplaying())
cancelAutoplay();

unlockOrientation();
super.onDestroy();
}

Expand Down Expand Up @@ -885,6 +891,26 @@ private void updateButtonBackDrawable() {
}
}

private void lockOrientation() {
int orientation;
int rotation = getResources().getConfiguration().orientation;
switch (rotation) {
case Configuration.ORIENTATION_LANDSCAPE:
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
break;
case Configuration.ORIENTATION_PORTRAIT:
default:
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
break;
}

setRequestedOrientation(orientation);
}

private void unlockOrientation() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}

@SuppressWarnings("unused")
public void autoplay(@IntRange(from = 1) long delay, @IntRange(from = -1) int repeatCount) {
autoplayCounter = repeatCount;
Expand Down Expand Up @@ -1223,6 +1249,11 @@ public Slide getSlide(int location) {
return adapter.getSlide(location);
}

@SuppressWarnings("unused")
public int getSlidePosition(Slide slide) {
return adapter.getItemPosition(slide);
}

@SuppressWarnings("unused")
public Fragment getItem(int position) {
return adapter.getItem(position);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.heinrichreimersoftware.materialintro.app;

public abstract class OnPositionNavigationBlockedListener implements OnNavigationBlockedListener {
private final int position;

public OnPositionNavigationBlockedListener(int position) {
this.position = position;
}

public int getPosition() {
return position;
}

protected abstract void onNavigationBlocked(@Direction int direction);

@Override
public void onNavigationBlocked(int position, @Direction int direction) {
if (this.position == position) {
onNavigationBlocked(direction);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,37 @@ public boolean canGoBackward() {
return true;
}

public void updateNavigation() {
public IntroActivity getIntroActivity() {
if (getActivity() instanceof IntroActivity) {
((IntroActivity) getActivity()).lockSwipeIfNeeded();
return (IntroActivity) getActivity();
} else {
throw new IllegalStateException("SlideFragment's must be attached to an IntroActivity.");
}
}

public void updateNavigation() {
getIntroActivity().lockSwipeIfNeeded();
}

public void addOnNavigationBlockedListener(OnNavigationBlockedListener listener) {
if (getActivity() instanceof IntroActivity) {
((IntroActivity) getActivity()).addOnNavigationBlockedListener(listener);
}
getIntroActivity().addOnNavigationBlockedListener(listener);
}

public void removeOnNavigationBlockedListener(OnNavigationBlockedListener listener) {
if (getActivity() instanceof IntroActivity) {
((IntroActivity) getActivity()).removeOnNavigationBlockedListener(listener);
}
getIntroActivity().removeOnNavigationBlockedListener(listener);
}

protected void nextSlide() {
if (getActivity() instanceof IntroActivity) {
((IntroActivity) getActivity()).nextSlide();
}
getIntroActivity().nextSlide();
}

protected void previousSlide() {
if (getActivity() instanceof IntroActivity) {
((IntroActivity) getActivity()).previousSlide();
}
getIntroActivity().previousSlide();
}

/**
* @deprecated
*/
public View getContentView() {
return getActivity().findViewById(android.R.id.content);
}
Expand Down

0 comments on commit dbae320

Please sign in to comment.