Skip to content

Commit 94c9dd1

Browse files
committed
General cleanup
- Removed unused resources - Cleaned up styles (mostly removing default stuff) - Improved and corrected method documentation - Minor refactoring of min method
1 parent d7fd49c commit 94c9dd1

File tree

21 files changed

+81
-130
lines changed

21 files changed

+81
-130
lines changed

ViewPagerTransformsExample/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
android:allowBackup="true"
1313
android:icon="@drawable/ic_launcher"
1414
android:label="@string/app_name"
15-
android:theme="@style/AppTheme" >
15+
android:theme="@style/AppBaseTheme" >
1616
<activity
1717
android:name="com.ToxicBakery.viewpager.transforms.example.MainActivity"
1818
android:label="@string/app_name" >
Binary file not shown.
Binary file not shown.
Binary file not shown.

ViewPagerTransformsExample/res/layout/fragment_main.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
55
android:gravity="center"
6-
android:paddingBottom="@dimen/activity_vertical_margin"
7-
android:paddingLeft="@dimen/activity_horizontal_margin"
8-
android:paddingRight="@dimen/activity_horizontal_margin"
9-
android:paddingTop="@dimen/activity_vertical_margin"
106
android:text="@string/app_name"
11-
android:textColor="?android:attr/colorBackground"
7+
android:textColor="@android:color/white"
128
android:textSize="72sp"
139
tools:context="com.ToxicBakery.viewpager.transforms.example.MainActivity$PlaceholderFragment" />

ViewPagerTransformsExample/res/values-w820dp/dimens.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

ViewPagerTransformsExample/res/values/dimens.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<style name="AppBaseTheme" parent="android:Theme.Holo">
5+
<item name="android:windowBackground">@android:color/background_light</item>
6+
<item name="android:actionBarStyle">@style/DarkActionBar</item>
7+
</style>
8+
9+
<style name="DarkActionBar" parent="@android:style/Widget.Holo.ActionBar">
10+
<item name="android:background">@android:color/background_dark</item>
11+
</style>
12+
13+
</resources>

ViewPagerTransformsExample/res/values/styles.xml

Lines changed: 0 additions & 20 deletions
This file was deleted.

ViewPagerTransformsExample/src/com/ToxicBakery/viewpager/transforms/example/MainActivity.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ public class MainActivity extends Activity implements OnNavigationListener {
4141
private static final ArrayList<TransformerItem> TRANSFORM_CLASSES;
4242

4343
static {
44-
TRANSFORM_CLASSES = new ArrayList<>();
44+
TRANSFORM_CLASSES = new ArrayList<TransformerItem>();
4545
TRANSFORM_CLASSES.add(new TransformerItem(DefaultTransformer.class));
4646
TRANSFORM_CLASSES.add(new TransformerItem(AccordionTransformer.class));
4747
TRANSFORM_CLASSES.add(new TransformerItem(BackgroundToForegroundTransformer.class));
48-
TRANSFORM_CLASSES.add(new TransformerItem(DepthPageTransformer.class));
49-
TRANSFORM_CLASSES.add(new TransformerItem(ForegroundToBackgroundTransformer.class));
5048
TRANSFORM_CLASSES.add(new TransformerItem(CubeInTransformer.class));
5149
TRANSFORM_CLASSES.add(new TransformerItem(CubeOutTransformer.class));
50+
TRANSFORM_CLASSES.add(new TransformerItem(DepthPageTransformer.class));
5251
TRANSFORM_CLASSES.add(new TransformerItem(FlipHorizontalTransformer.class));
5352
TRANSFORM_CLASSES.add(new TransformerItem(FlipVerticalTransformer.class));
53+
TRANSFORM_CLASSES.add(new TransformerItem(ForegroundToBackgroundTransformer.class));
5454
TRANSFORM_CLASSES.add(new TransformerItem(RotateDownTransformer.class));
5555
TRANSFORM_CLASSES.add(new TransformerItem(RotateUpTransformer.class));
5656
TRANSFORM_CLASSES.add(new TransformerItem(StackTransformer.class));
5757
TRANSFORM_CLASSES.add(new TransformerItem(TabletTransformer.class));
5858
TRANSFORM_CLASSES.add(new TransformerItem(ZoomInTransformer.class));
59-
TRANSFORM_CLASSES.add(new TransformerItem(ZoomOutTranformer.class));
6059
TRANSFORM_CLASSES.add(new TransformerItem(ZoomOutSlideTransformer.class));
60+
TRANSFORM_CLASSES.add(new TransformerItem(ZoomOutTranformer.class));
6161
}
6262

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

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

8080
final ActionBar actionBar = getActionBar();
8181
actionBar.setListNavigationCallbacks(actionBarAdapter, this);

ViewPagerTransformsLibrary/res/.gitignore

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.

ViewPagerTransformsLibrary/res/values-v11/styles.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

ViewPagerTransformsLibrary/res/values-v14/styles.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

ViewPagerTransformsLibrary/res/values/strings.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

ViewPagerTransformsLibrary/res/values/styles.xml

Lines changed: 0 additions & 20 deletions
This file was deleted.

ViewPagerTransformsLibrary/src/com/ToxicBakery/viewpager/transforms/ABaseTransformer.java

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,34 @@ public abstract class ABaseTransformer implements PageTransformer {
88
/**
99
* Called each {@link #transformPage(View, float)}.
1010
*
11-
* @param view
11+
* @param page
12+
* Apply the transformation to this page
1213
* @param position
14+
* Position of page relative to the current front-and-center position of the pager. 0 is front and
15+
* center. 1 is one full page position to the right, and -1 is one page position to the left.
1316
*/
14-
protected abstract void onTransform(View view, float position);
17+
protected abstract void onTransform(View page, float position);
1518

19+
/**
20+
* Apply a property transformation to the given page. For most use cases, this method should not be overridden.
21+
* Instead use {@link #transformPage(View, float)} to perform typical transformations.
22+
*
23+
* @param page
24+
* Apply the transformation to this page
25+
* @param position
26+
* Position of page relative to the current front-and-center position of the pager. 0 is front and
27+
* center. 1 is one full page position to the right, and -1 is one page position to the left.
28+
*/
1629
@Override
17-
public void transformPage(View view, float position) {
18-
onPreTransform(view, position);
19-
onTransform(view, position);
20-
onPostTransform(view, position);
30+
public void transformPage(View page, float position) {
31+
onPreTransform(page, position);
32+
onTransform(page, position);
33+
onPostTransform(page, position);
2134
}
2235

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

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

51-
view.setRotationX(0);
52-
view.setRotationY(0);
53-
view.setRotation(0);
54-
view.setScaleX(1);
55-
view.setScaleY(1);
56-
view.setPivotX(0);
57-
view.setPivotY(0);
58-
view.setTranslationY(0);
59-
view.setTranslationX(isPagingEnabled() ? 0f : -width * position);
72+
page.setRotationX(0);
73+
page.setRotationY(0);
74+
page.setRotation(0);
75+
page.setScaleX(1);
76+
page.setScaleY(1);
77+
page.setPivotX(0);
78+
page.setPivotY(0);
79+
page.setTranslationY(0);
80+
page.setTranslationX(isPagingEnabled() ? 0f : -width * position);
6081

6182
if (hideOffscreenPages()) {
62-
view.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
83+
page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
6384
} else {
64-
view.setAlpha(1f);
85+
page.setAlpha(1f);
6586
}
6687
}
6788

6889
/**
69-
* Called each {@link #transformPage(View, float)} call after {@link #onTransform(View, float)} is finished.
90+
* Called each {@link #transformPage(View, float)} after {@link #onTransform(View, float)}.
7091
*
71-
* @param view
92+
* @param page
93+
* Apply the transformation to this page
7294
* @param position
95+
* Position of page relative to the current front-and-center position of the pager. 0 is front and
96+
* center. 1 is one full page position to the right, and -1 is one page position to the left.
97+
*/
98+
protected void onPostTransform(View page, float position) {
99+
}
100+
101+
/**
102+
* Same as {@link Math#min(double, double)} without double casting, zero closest to infinity handling, or NaN support.
103+
*
104+
* @param val
105+
* @param min
106+
* @return
73107
*/
74-
protected void onPostTransform(View view, float position) {
108+
protected static final float min(float val, float min) {
109+
return val < min ? min : val;
75110
}
76111

77112
}

ViewPagerTransformsLibrary/src/com/ToxicBakery/viewpager/transforms/BackgroundToForegroundTransformer.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,4 @@ protected void onTransform(View view, float position) {
1717
view.setTranslationX(position < 0 ? width * position : -width * position * 0.25f);
1818
}
1919

20-
private static final float min(float val, float min) {
21-
return val < min ? min : val;
22-
}
23-
2420
}

ViewPagerTransformsLibrary/src/com/ToxicBakery/viewpager/transforms/ForegroundToBackgroundTransformer.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,4 @@ protected void onTransform(View view, float position) {
1717
view.setTranslationX(position > 0 ? width * position : -width * position * 0.25f);
1818
}
1919

20-
private static final float min(float val, float min) {
21-
return val < min ? min : val;
22-
}
23-
2420
}

0 commit comments

Comments
 (0)