Skip to content

Commit

Permalink
upload project file
Browse files Browse the repository at this point in the history
  • Loading branch information
chenlong committed Jan 19, 2017
1 parent b16f438 commit 59f1671
Show file tree
Hide file tree
Showing 56 changed files with 7,867 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
demo/build
demo/.idea
demo/.gradle
demo/*.iml
8 changes: 8 additions & 0 deletions demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
1 change: 1 addition & 0 deletions demo/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
28 changes: 28 additions & 0 deletions demo/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "self.demo"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.2.0'
// compile 'com.github.mklimek:frame-video-view:1.3.1'
testCompile 'junit:junit:4.12'
// compile project(':library')
}
17 changes: 17 additions & 0 deletions demo/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/user/Downloads/adt-bundle-mac-x86_64-20140702/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
13 changes: 13 additions & 0 deletions demo/app/src/androidTest/java/self/demo/ApplicationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package self.demo;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
26 changes: 26 additions & 0 deletions demo/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="self.demo">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".FullScreenActivity"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
</application>

</manifest>
218 changes: 218 additions & 0 deletions demo/app/src/main/java/self/demo/AutoDirectionalViewPager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
package self.demo;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;

public class AutoDirectionalViewPager extends InfiniteViewPager {
private static final String TAG = AutoDirectionalViewPager.class.getSimpleName();
private int mTouchSlop;

public AutoDirectionalViewPager(Context context) {
super(context);
init();
}

public AutoDirectionalViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

private void init() {
ViewConfiguration vc = ViewConfiguration.get(getContext());
mTouchSlop = vc.getScaledTouchSlop();
// The majority of the magic happens here
// setPageTransformer(false, new CubeOutTransformer());
// The easiest way to get rid of the overscroll drawing that happens on the left and right
setOverScrollMode(OVER_SCROLL_NEVER);
}


/**
* Swaps the X and Y coordinates of your touch event.
*/
private MotionEvent swapXY(MotionEvent ev) {
float width = getWidth();
float height = getHeight();

float newX = (ev.getY() / height) * width;
float newY = (ev.getX() / width) * height;

ev.setLocation(newX, newY);

return ev;
}


/**
* disable left swipe when currentItem is 0, because it to be crash on some device.(the issue has been fixed)
*/
// private float initialY;
// private boolean isSwipeAllowed(MotionEvent event) {
// int currentItem = getCurrentItem();
//// Log.i(TAG, "currentItem:" + currentItem);
// if (currentItem != 0) {
// return true;
// }
//
// if (event.getAction() == MotionEvent.ACTION_DOWN) {
// initialY = event.getY();
// return true;
// }
//
// if (event.getAction() == MotionEvent.ACTION_MOVE) {
// if (event.getY() > initialY) {
// return false;
// }
// }
//
// return true;
// }

private int direction = Direction.UNKNOW;
static class Direction {
public static final int VERTICAL = 0;
public static final int HORIZONTAL = 1;
public static final int UNKNOW = -1;
}

/**
* detect swipe event and direction, once detected, start to slide(call the onInterceptTouchEvent func and reset to ACTION_DOWN of MotionEvent).
* @param ev
* @return
*/
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
int action = ev.getAction() & MotionEvent.ACTION_MASK;
Log.i(TAG, "dispatchTouchEvent-->direction:" + direction);
switch (action) {
case MotionEvent.ACTION_DOWN:
if (direction == Direction.UNKNOW) {
originalX = ev.getX();
originalY = ev.getY();
}
break;
case MotionEvent.ACTION_MOVE:
if (direction == Direction.UNKNOW) {
float absX = Math.abs(originalX - ev.getX());
float absY = Math.abs(originalY - ev.getY());
Log.i(TAG, "dispatchTouchEvent-->absX:" + absX +
" absY:" + absY + " mTouchSlop:" + mTouchSlop);
if (absX > mTouchSlop || absY > mTouchSlop) {
direction = absX > absY ? Direction.HORIZONTAL : Direction.VERTICAL;
ev.setAction(MotionEvent.ACTION_DOWN);
return onInterceptTouchEvent(ev);
}
}
break;
case MotionEvent.ACTION_UP:
direction = Direction.UNKNOW;
break;
}
return super.dispatchTouchEvent(ev);
}

/**
* set the transformer according to the swipe direction that has been detected by dispatchTouchEvent func.
* since we know the viewpager that only achieve a horizontal swipe, so we need to implement vertical swipe(
* refer to the implemention of swapXY() method for detail,it is very simple).
* @param ev
* @return
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev){
// Log.i(TAG, "onInterceptTouchEvent-->direction:" + direction);
boolean interceptHandle;
clearAnimation();
if (direction == Direction.VERTICAL) {
setPageTransformer(false, new VerticalCubeTransform());
interceptHandle = super.onInterceptTouchEvent(swapXY(ev));
swapXY(ev);
} else {
setPageTransformer(false, new HorizontalCubeTransform());
interceptHandle = super.onInterceptTouchEvent(ev);
}

return interceptHandle;
// boolean intercepted = super.onInterceptTouchEvent(
// direction == Direction.HORIZONTAL ? ev : swapXY(ev));
// Log.i(TAG, "intercepted:" + intercepted);
// if (direction == Direction.VERTICAL) {
// swapXY(ev); // return touch coordinates to original reference frame for any child views
// }
// return intercepted;
}

private float originalX;
private float originalY;

@Override
public boolean onTouchEvent(MotionEvent ev) {
// Log.i(TAG, "onTouchEvent");
// if (!isSwipeAllowed(ev)) {
// return true;
// }
// Log.i(TAG, "onTouchEvent-->direction:" + direction);
return super.onTouchEvent(direction == Direction.HORIZONTAL? ev : swapXY(ev));
}

/**
* the implemention of vertical cube transformer
*/
static class VerticalCubeTransform implements ViewPager.PageTransformer {

@Override
public void transformPage(View view, float position) {
// Log.i(TAG, "position:" + position);
final float normalizedposition = Math.abs(Math.abs(position) - 1);
view.setAlpha(normalizedposition);
view.setTranslationX(view.getWidth() * -position);
view.setTranslationY(position * view.getHeight());

view.setPivotX(view.getWidth() * 0.5f);
view.setPivotY(position < 0f ? view.getHeight() : 0f);
view.setRotationX(90f * -position);

float rotationY = view.getRotationY();
if (rotationY != 0) {
view.setRotationY(0);
}

}
}


/**
* the implemention of horizontal cube transformer
*/
private class HorizontalCubeTransform implements ViewPager.PageTransformer {

@Override
public void transformPage(View view, float position) {
final float normalizedposition = Math.abs(Math.abs(position) - 1);
view.setAlpha(normalizedposition);
view.setPivotX(position < 0f ? view.getWidth() : 0f);
view.setPivotY(view.getHeight() * 0.5f);
view.setRotationY(90f * position);
if (view.getTranslationX() != 0) {
view.setTranslationX(0);
}

if (view.getTranslationY() != 0) {
view.setTranslationY(0);
}


float rotationX = view.getRotationX();
Log.i(TAG, "horizontal --> rotationX:"+rotationX);
if (rotationX != 0) {
view.setRotationX(0);
}
}
}

}
Loading

0 comments on commit 59f1671

Please sign in to comment.