Skip to content

Commit

Permalink
General cleanup
Browse files Browse the repository at this point in the history
- Removed unused resources
- Cleaned up styles (mostly removing default stuff)
- Improved and corrected method documentation
- Minor refactoring of min method
  • Loading branch information
ToxicBakery committed Sep 4, 2014
1 parent d7fd49c commit 94c9dd1
Show file tree
Hide file tree
Showing 21 changed files with 81 additions and 130 deletions.
2 changes: 1 addition & 1 deletion ViewPagerTransformsExample/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppBaseTheme" >
<activity
android:name="com.ToxicBakery.viewpager.transforms.example.MainActivity"
android:label="@string/app_name" >
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 1 addition & 5 deletions ViewPagerTransformsExample/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:text="@string/app_name"
android:textColor="?android:attr/colorBackground"
android:textColor="@android:color/white"
android:textSize="72sp"
tools:context="com.ToxicBakery.viewpager.transforms.example.MainActivity$PlaceholderFragment" />
10 changes: 0 additions & 10 deletions ViewPagerTransformsExample/res/values-w820dp/dimens.xml

This file was deleted.

7 changes: 0 additions & 7 deletions ViewPagerTransformsExample/res/values/dimens.xml

This file was deleted.

13 changes: 13 additions & 0 deletions ViewPagerTransformsExample/res/values/style.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="AppBaseTheme" parent="android:Theme.Holo">
<item name="android:windowBackground">@android:color/background_light</item>
<item name="android:actionBarStyle">@style/DarkActionBar</item>
</style>

<style name="DarkActionBar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@android:color/background_dark</item>
</style>

</resources>
20 changes: 0 additions & 20 deletions ViewPagerTransformsExample/res/values/styles.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ public class MainActivity extends Activity implements OnNavigationListener {
private static final ArrayList<TransformerItem> TRANSFORM_CLASSES;

static {
TRANSFORM_CLASSES = new ArrayList<>();
TRANSFORM_CLASSES = new ArrayList<TransformerItem>();
TRANSFORM_CLASSES.add(new TransformerItem(DefaultTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(AccordionTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(BackgroundToForegroundTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(DepthPageTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(ForegroundToBackgroundTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(CubeInTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(CubeOutTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(DepthPageTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(FlipHorizontalTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(FlipVerticalTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(ForegroundToBackgroundTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(RotateDownTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(RotateUpTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(StackTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(TabletTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(ZoomInTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(ZoomOutTranformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(ZoomOutSlideTransformer.class));
TRANSFORM_CLASSES.add(new TransformerItem(ZoomOutTranformer.class));
}

private int mSelectedItem;
Expand All @@ -74,8 +74,8 @@ protected void onCreate(Bundle savedInstanceState) {
selectedPage = savedInstanceState.getInt(KEY_SELECTED_PAGE);
}

final ArrayAdapter<TransformerItem> actionBarAdapter = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_list_item_1, android.R.id.text1, TRANSFORM_CLASSES);
final ArrayAdapter<TransformerItem> actionBarAdapter = new ArrayAdapter<TransformerItem>(
getApplicationContext(), android.R.layout.simple_list_item_1, android.R.id.text1, TRANSFORM_CLASSES);

final ActionBar actionBar = getActionBar();
actionBar.setListNavigationCallbacks(actionBarAdapter, this);
Expand Down
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 0 additions & 11 deletions ViewPagerTransformsLibrary/res/values-v11/styles.xml

This file was deleted.

12 changes: 0 additions & 12 deletions ViewPagerTransformsLibrary/res/values-v14/styles.xml

This file was deleted.

5 changes: 0 additions & 5 deletions ViewPagerTransformsLibrary/res/values/strings.xml

This file was deleted.

20 changes: 0 additions & 20 deletions ViewPagerTransformsLibrary/res/values/styles.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,34 @@ public abstract class ABaseTransformer implements PageTransformer {
/**
* Called each {@link #transformPage(View, float)}.
*
* @param view
* @param page
* Apply the transformation to this page
* @param position
* Position of page relative to the current front-and-center position of the pager. 0 is front and
* center. 1 is one full page position to the right, and -1 is one page position to the left.
*/
protected abstract void onTransform(View view, float position);
protected abstract void onTransform(View page, float position);

/**
* Apply a property transformation to the given page. For most use cases, this method should not be overridden.
* Instead use {@link #transformPage(View, float)} to perform typical transformations.
*
* @param page
* Apply the transformation to this page
* @param position
* Position of page relative to the current front-and-center position of the pager. 0 is front and
* center. 1 is one full page position to the right, and -1 is one page position to the left.
*/
@Override
public void transformPage(View view, float position) {
onPreTransform(view, position);
onTransform(view, position);
onPostTransform(view, position);
public void transformPage(View page, float position) {
onPreTransform(page, position);
onTransform(page, position);
onPostTransform(page, position);
}

/**
* If the position offset of a fragment is less than negative one or greater than one, returning true will set the
* visibility of the fragment to {@link View#GONE}. Returning false will force the fragment to {@link View#VISIBLE}.
* fragment alpha to 0f. Otherwise fragment alpha is always defaulted to 1f.
*
* @return
*/
Expand All @@ -40,38 +53,60 @@ protected boolean isPagingEnabled() {
}

/**
* Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)} is called.
* Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)}.
* <p>
* The default implementation attempts to reset all view properties. This is useful when toggling transforms that do
* not modify the same page properties. For instance changing from a transformation that applies rotation to a
* transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied
* alpha.
*
* @param view
* @param page
* Apply the transformation to this page
* @param position
* Position of page relative to the current front-and-center position of the pager. 0 is front and
* center. 1 is one full page position to the right, and -1 is one page position to the left.
*/
protected void onPreTransform(View view, float position) {
final float width = view.getWidth();
protected void onPreTransform(View page, float position) {
final float width = page.getWidth();

view.setRotationX(0);
view.setRotationY(0);
view.setRotation(0);
view.setScaleX(1);
view.setScaleY(1);
view.setPivotX(0);
view.setPivotY(0);
view.setTranslationY(0);
view.setTranslationX(isPagingEnabled() ? 0f : -width * position);
page.setRotationX(0);
page.setRotationY(0);
page.setRotation(0);
page.setScaleX(1);
page.setScaleY(1);
page.setPivotX(0);
page.setPivotY(0);
page.setTranslationY(0);
page.setTranslationX(isPagingEnabled() ? 0f : -width * position);

if (hideOffscreenPages()) {
view.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
} else {
view.setAlpha(1f);
page.setAlpha(1f);
}
}

/**
* Called each {@link #transformPage(View, float)} call after {@link #onTransform(View, float)} is finished.
* Called each {@link #transformPage(View, float)} after {@link #onTransform(View, float)}.
*
* @param view
* @param page
* Apply the transformation to this page
* @param position
* Position of page relative to the current front-and-center position of the pager. 0 is front and
* center. 1 is one full page position to the right, and -1 is one page position to the left.
*/
protected void onPostTransform(View page, float position) {
}

/**
* Same as {@link Math#min(double, double)} without double casting, zero closest to infinity handling, or NaN support.
*
* @param val
* @param min
* @return
*/
protected void onPostTransform(View view, float position) {
protected static final float min(float val, float min) {
return val < min ? min : val;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@ protected void onTransform(View view, float position) {
view.setTranslationX(position < 0 ? width * position : -width * position * 0.25f);
}

private static final float min(float val, float min) {
return val < min ? min : val;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@ protected void onTransform(View view, float position) {
view.setTranslationX(position > 0 ? width * position : -width * position * 0.25f);
}

private static final float min(float val, float min) {
return val < min ? min : val;
}

}

0 comments on commit 94c9dd1

Please sign in to comment.