-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
luobl
committed
Aug 29, 2014
0 parents
commit 5000ff4
Showing
27 changed files
with
736 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
gen/ | ||
bin/ | ||
build/ | ||
.setting/ | ||
.gradle | ||
.project | ||
.classpath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.cviewpager" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk | ||
android:minSdkVersion="14" | ||
android:targetSdkVersion="21" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" > | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# To enable ProGuard in your project, edit project.properties | ||
# to define the proguard.config property as described in that file. | ||
# | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in ${sdk.dir}/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the ProGuard | ||
# include property in project.properties. | ||
# | ||
# 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 *; | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# This file is automatically generated by Android Tools. | ||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! | ||
# | ||
# This file must be checked in Version Control Systems. | ||
# | ||
# To customize properties used by the Ant build system edit | ||
# "ant.properties", and override values to adapt the script to your | ||
# project structure. | ||
# | ||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): | ||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt | ||
|
||
# Project target. | ||
target=android-19 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="com.example.cviewpager.MainActivity" > | ||
|
||
<com.example.cviewpager.MyViewPager | ||
android:id="@+id/myViewPager1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentTop="true" > | ||
</com.example.cviewpager.MyViewPager> | ||
|
||
<Button | ||
android:id="@+id/button1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentLeft="true" | ||
android:onClick="onClick" | ||
android:text="下一个" /> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
> | ||
|
||
<ImageView | ||
android:id="@+id/imageView1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerHorizontal="true" | ||
android:layout_centerVertical="true" | ||
android:src="@drawable/ic_launcher" /> | ||
<TextView | ||
android:id="@+id/tv" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_horizontal" | ||
/> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
tools:context="com.example.cviewpager.MainActivity" > | ||
|
||
<item | ||
android:id="@+id/action_settings" | ||
android:orderInCategory="100" | ||
android:showAsAction="never" | ||
android:title="@string/action_settings"/> | ||
|
||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<resources> | ||
|
||
<!-- | ||
Base application theme for API 11+. This theme completely replaces | ||
AppBaseTheme from res/values/styles.xml on API 11+ devices. | ||
--> | ||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light"> | ||
<!-- API 11 theme customizations can go here. --> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<resources> | ||
|
||
<!-- | ||
Base application theme for API 14+. This theme completely replaces | ||
AppBaseTheme from BOTH res/values/styles.xml and | ||
res/values-v11/styles.xml on API 14+ devices. | ||
--> | ||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"> | ||
<!-- API 14 theme customizations can go here. --> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<resources> | ||
|
||
<!-- | ||
Example customization of dimensions originally defined in res/values/dimens.xml | ||
(such as screen margins) for screens with more than 820dp of available width. This | ||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). | ||
--> | ||
<dimen name="activity_horizontal_margin">64dp</dimen> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<resources> | ||
|
||
<!-- Default screen margins, per the Android Design guidelines. --> | ||
<dimen name="activity_horizontal_margin">16dp</dimen> | ||
<dimen name="activity_vertical_margin">16dp</dimen> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="app_name">CViewPager</string> | ||
<string name="hello_world">Hello world!</string> | ||
<string name="action_settings">Settings</string> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<resources> | ||
|
||
<!-- | ||
Base application theme, dependent on API level. This theme is replaced | ||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices. | ||
--> | ||
<style name="AppBaseTheme" parent="android:Theme.Light"> | ||
<!-- | ||
Theme customizations available in newer API levels can go in | ||
res/values-vXX/styles.xml, while customizations related to | ||
backward-compatibility can go here. | ||
--> | ||
</style> | ||
|
||
<!-- Application theme. --> | ||
<style name="AppTheme" parent="AppBaseTheme"> | ||
<!-- All customizations that are NOT specific to a particular API-level can go here. --> | ||
</style> | ||
|
||
</resources> |
143 changes: 143 additions & 0 deletions
143
src/com/example/cviewpager/AndroidSpringLooperFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* Copyright (c) 2013, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
|
||
package com.example.cviewpager; | ||
|
||
import android.annotation.TargetApi; | ||
import android.os.Build; | ||
import android.os.Handler; | ||
import android.os.SystemClock; | ||
import android.view.Choreographer; | ||
|
||
import com.facebook.rebound.SpringLooper; | ||
|
||
/** | ||
* Android version of the spring looper that uses the most appropriate frame callback mechanism | ||
* available. It uses Android's {@link Choreographer} when available, otherwise it uses a | ||
* {@link Handler}. | ||
*/ | ||
abstract class AndroidSpringLooperFactory { | ||
|
||
/** | ||
* Create an Android {@link com.facebook.rebound.SpringLooper} for the detected Android platform. | ||
* @return a SpringLooper | ||
*/ | ||
public static SpringLooper createSpringLooper() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | ||
return ChoreographerAndroidSpringLooper.create(); | ||
} else { | ||
return LegacyAndroidSpringLooper.create(); | ||
} | ||
} | ||
|
||
/** | ||
* The base implementation of the Android spring looper, using a {@link Handler} for the | ||
* frame callbacks. | ||
*/ | ||
private static class LegacyAndroidSpringLooper extends SpringLooper { | ||
|
||
private final Handler mHandler; | ||
private final Runnable mLooperRunnable; | ||
private boolean mStarted; | ||
private long mLastTime; | ||
|
||
/** | ||
* @return an Android spring looper using a new {@link Handler} instance | ||
*/ | ||
public static SpringLooper create() { | ||
return new LegacyAndroidSpringLooper(new Handler()); | ||
} | ||
|
||
public LegacyAndroidSpringLooper(Handler handler) { | ||
mHandler = handler; | ||
mLooperRunnable = new Runnable() { | ||
@Override | ||
public void run() { | ||
if (!mStarted || mSpringSystem == null) { | ||
return; | ||
} | ||
long currentTime = SystemClock.uptimeMillis(); | ||
mSpringSystem.loop(currentTime - mLastTime); | ||
mHandler.post(mLooperRunnable); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public void start() { | ||
if (mStarted) { | ||
return; | ||
} | ||
mStarted = true; | ||
mLastTime = SystemClock.uptimeMillis(); | ||
mHandler.removeCallbacks(mLooperRunnable); | ||
mHandler.post(mLooperRunnable); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
mStarted = false; | ||
mHandler.removeCallbacks(mLooperRunnable); | ||
} | ||
} | ||
|
||
/** | ||
* The Jelly Bean and up implementation of the spring looper that uses Android's | ||
* {@link Choreographer} instead of a {@link Handler} | ||
*/ | ||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) | ||
private static class ChoreographerAndroidSpringLooper extends SpringLooper { | ||
|
||
private final Choreographer mChoreographer; | ||
private final Choreographer.FrameCallback mFrameCallback; | ||
private boolean mStarted; | ||
private long mLastTime; | ||
|
||
/** | ||
* @return an Android spring choreographer using the system {@link Choreographer} | ||
*/ | ||
public static ChoreographerAndroidSpringLooper create() { | ||
return new ChoreographerAndroidSpringLooper(Choreographer.getInstance()); | ||
} | ||
|
||
public ChoreographerAndroidSpringLooper(Choreographer choreographer) { | ||
mChoreographer = choreographer; | ||
mFrameCallback = new Choreographer.FrameCallback() { | ||
@Override | ||
public void doFrame(long frameTimeNanos) { | ||
if (!mStarted || mSpringSystem == null) { | ||
return; | ||
} | ||
long currentTime = SystemClock.uptimeMillis(); | ||
mSpringSystem.loop(currentTime - mLastTime); | ||
mLastTime = currentTime; | ||
mChoreographer.postFrameCallback(mFrameCallback); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public void start() { | ||
if (mStarted) { | ||
return; | ||
} | ||
mStarted = true; | ||
mLastTime = SystemClock.uptimeMillis(); | ||
mChoreographer.removeFrameCallback(mFrameCallback); | ||
mChoreographer.postFrameCallback(mFrameCallback); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
mStarted = false; | ||
mChoreographer.removeFrameCallback(mFrameCallback); | ||
} | ||
} | ||
} |
Oops, something went wrong.