Permalink
Browse files

首次提交代码。

  • Loading branch information...
xiangmao
xiangmao committed Oct 9, 2013
1 parent 61f6032 commit bbd084e4217c70e74f451d9a811fef000d4dbe6c
Showing with 1,282 additions and 0 deletions.
  1. +1 −0 .gradle/1.7/taskArtifacts/cache.properties
  2. +1 −0 .gradle/1.7/taskArtifacts/cache.properties.lock
  3. BIN .gradle/1.7/taskArtifacts/fileHashes.bin
  4. BIN .gradle/1.7/taskArtifacts/fileSnapshots.bin
  5. BIN .gradle/1.7/taskArtifacts/outputFileStates.bin
  6. BIN .gradle/1.7/taskArtifacts/taskArtifacts.bin
  7. +1 −0 PullScrollView/.gitignore
  8. +30 −0 PullScrollView/build.gradle
  9. +30 −0 PullScrollView/src/main/AndroidManifest.xml
  10. BIN PullScrollView/src/main/ic_launcher-web.png
  11. +19 −0 PullScrollView/src/main/java/com/markmao/pullscrollview/CustomApplication.java
  12. +45 −0 PullScrollView/src/main/java/com/markmao/pullscrollview/ui/ElasticityViewActivity.java
  13. +86 −0 PullScrollView/src/main/java/com/markmao/pullscrollview/ui/MainActivity.java
  14. +141 −0 PullScrollView/src/main/java/com/markmao/pullscrollview/ui/widget/ElasticityScrollView.java
  15. +269 −0 PullScrollView/src/main/java/com/markmao/pullscrollview/ui/widget/PullScrollView.java
  16. +123 −0 PullScrollView/src/main/java/com/markmao/pullscrollview/util/PixelUtil.java
  17. BIN PullScrollView/src/main/res/drawable-hdpi/add.png
  18. BIN PullScrollView/src/main/res/drawable-hdpi/arrow_up.png
  19. BIN PullScrollView/src/main/res/drawable-hdpi/avatar_default.png
  20. BIN PullScrollView/src/main/res/drawable-hdpi/button_bg_normal.9.png
  21. BIN PullScrollView/src/main/res/drawable-hdpi/button_bg_pressed.9.png
  22. BIN PullScrollView/src/main/res/drawable-hdpi/card_avatar_bar.9.png
  23. BIN PullScrollView/src/main/res/drawable-hdpi/card_whole.9.png
  24. BIN PullScrollView/src/main/res/drawable-hdpi/ic_launcher.png
  25. BIN PullScrollView/src/main/res/drawable-hdpi/page_cover_car_background.jpg
  26. BIN PullScrollView/src/main/res/drawable-hdpi/title_bg.png
  27. BIN PullScrollView/src/main/res/drawable-mdpi/ic_launcher.png
  28. BIN PullScrollView/src/main/res/drawable-xhdpi/ic_launcher.png
  29. BIN PullScrollView/src/main/res/drawable-xxhdpi/ic_launcher.png
  30. +7 −0 PullScrollView/src/main/res/drawable/selector_btn.xml
  31. +21 −0 PullScrollView/src/main/res/layout/act_elasticity_layout.xml
  32. +185 −0 PullScrollView/src/main/res/layout/act_main_layout.xml
  33. +11 −0 PullScrollView/src/main/res/values-v11/styles.xml
  34. +12 −0 PullScrollView/src/main/res/values-v14/styles.xml
  35. +7 −0 PullScrollView/src/main/res/values/color.xml
  36. +11 −0 PullScrollView/src/main/res/values/strings.xml
  37. +20 −0 PullScrollView/src/main/res/values/styles.xml
  38. BIN Screenshots/0.png
  39. BIN Screenshots/1.png
  40. BIN Screenshots/2.png
  41. +1 −0 build.gradle
  42. BIN gradle/wrapper/gradle-wrapper.jar
  43. +6 −0 gradle/wrapper/gradle-wrapper.properties
  44. +164 −0 gradlew
  45. +90 −0 gradlew.bat
  46. +1 −0 settings.gradle
@@ -0,0 +1 @@
#Thu Sep 12 12:50:48 CST 2013
@@ -0,0 +1 @@

View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
/build
@@ -0,0 +1,30 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 16
}
}
dependencies {
}
tasks.withType(Compile) {
options.encoding = "UTF-8"
}
@@ -0,0 +1,30 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.markmao.pullscrollview"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<application
android:name=".CustomApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme">
<activity
android:name=".ui.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>
<activity
android:name=".ui.ElasticityViewActivity"
android:label="@string/app_name" />
</application>
</manifest>
Binary file not shown.
@@ -0,0 +1,19 @@
package com.markmao.pullscrollview;
import android.app.Application;
import android.content.Context;
/**
* @author MarkMjw
* @date 13-9-17.
*/
public class CustomApplication extends Application {
public static Context gContext;
@Override
public void onCreate() {
super.onCreate();
gContext = this;
}
}
@@ -0,0 +1,45 @@
package com.markmao.pullscrollview.ui;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import com.markmao.pullscrollview.R;
/**
* 上下回弹ScrollView Demo
*
* @author MarkMjw
* @date 13-9-17.
*/
public class ElasticityViewActivity extends Activity {
private TableLayout mMainLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_elasticity_layout);
mMainLayout = (TableLayout) findViewById(R.id.table_layout);
showTable();
}
public void showTable() {
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams
.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
layoutParams.gravity = Gravity.CENTER;
for (int i = 0; i < 40; i++) {
TableRow tableRow = new TableRow(this);
TextView textView = new TextView(this);
textView.setText("Test pull scroll view " + i);
textView.setTextSize(20);
textView.setPadding(10, 10, 10, 10);
tableRow.addView(textView, layoutParams);
mMainLayout.addView(tableRow);
}
}
}
@@ -0,0 +1,86 @@
package com.markmao.pullscrollview.ui;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import com.markmao.pullscrollview.ui.widget.PullScrollView;
import com.markmao.pullscrollview.R;
/**
* Demo
*
* @author MarkMjw
* @date 13-9-17.
*/
public class MainActivity extends Activity implements PullScrollView.OnTurnListener,
View.OnClickListener {
private PullScrollView mScrollView;
private ImageView mHeadImg;
private TextView mAddAttention;
private TableLayout mMainLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_main_layout);
initView();
showTable();
}
protected void initView() {
mScrollView = (PullScrollView) findViewById(R.id.scroll_view);
mHeadImg = (ImageView) findViewById(R.id.background_img);
mAddAttention = (TextView) findViewById(R.id.attention_user);
mMainLayout = (TableLayout) findViewById(R.id.table_layout);
mAddAttention.setOnClickListener(this);
mScrollView.setOnTurnListener(this);
mScrollView.init(mHeadImg);
}
public void showTable() {
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams
.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
layoutParams.gravity = Gravity.CENTER;
for (int i = 0; i < 30; i++) {
TableRow tableRow = new TableRow(this);
TextView textView = new TextView(this);
textView.setText("Test pull scroll view " + i);
textView.setTextSize(20);
textView.setPadding(10, 10, 10, 10);
tableRow.addView(textView, layoutParams);
mMainLayout.addView(tableRow);
}
}
@Override
public void onTurn() {
Log.e("mjw", "onTurn.............");
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.attention_user:
Intent intent = new Intent(this, ElasticityViewActivity.class);
startActivity(intent);
break;
default:
break;
}
}
}
@@ -0,0 +1,141 @@
package com.markmao.pullscrollview.ui.widget;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ScrollView;
import com.markmao.pullscrollview.util.PixelUtil;
/**
* 上下回弹效果的ScrollView
*
* @author MarkMjw
* @date 13-9-12.
*/
public class ElasticityScrollView extends ScrollView {
protected Context mContext;
private View mView;
private float mTouchY;
private int mScrollY = 0;
private boolean mHandleStop = false;
private int mEachStep = 0;
/**
* 最大滑动距离
*/
private static final int MAX_SCROLL_HEIGHT = PixelUtil.dp2px(200);
/**
* 阻尼系数,越小阻力就越大
*/
private static final float SCROLL_RATIO = 0.4f;
private Handler mResetPositionHandler = new Handler() {
@Override
public void handleMessage(android.os.Message msg) {
if (mScrollY != 0 && mHandleStop) {
mScrollY -= mEachStep;
if ((mEachStep < 0 && mScrollY > 0) || (mEachStep > 0 && mScrollY < 0)) {
mScrollY = 0;
}
mView.scrollTo(0, mScrollY);
this.sendEmptyMessageDelayed(0, 20);
}
}
};
public ElasticityScrollView(Context context) {
super(context);
init(context);
}
public ElasticityScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public ElasticityScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
this.mContext = context;
// 去掉滚动到边界的效果
setOverScrollMode(OVER_SCROLL_NEVER);
}
@Override
protected void onFinishInflate() {
if (getChildCount() > 0) {
this.mView = getChildAt(0);
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
if (arg0.getAction() == MotionEvent.ACTION_DOWN) {
mTouchY = arg0.getY();
}
return super.onInterceptTouchEvent(arg0);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (mView == null) {
return super.onTouchEvent(ev);
} else {
commonOnTouchEvent(ev);
}
return super.onTouchEvent(ev);
}
private void commonOnTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_UP:
if (mView.getScrollY() != 0) {
mHandleStop = true;
animation();
}
break;
case MotionEvent.ACTION_MOVE:
float nowY = ev.getY();
int deltaY = (int) (mTouchY - nowY);
mTouchY = nowY;
if (isNeedMove()) {
int offset = mView.getScrollY();
if (offset < MAX_SCROLL_HEIGHT && offset > -MAX_SCROLL_HEIGHT) {
mView.scrollBy(0, (int) (deltaY * SCROLL_RATIO));
mHandleStop = false;
}
}
break;
default:
break;
}
}
private boolean isNeedMove() {
int viewHeight = mView.getMeasuredHeight();
int scrollHeight = getHeight();
int offset = viewHeight - scrollHeight;
int scrollY = getScrollY();
return scrollY == 0 || scrollY == offset;
}
private void animation() {
mScrollY = mView.getScrollY();
mEachStep = mScrollY / 10;
mResetPositionHandler.sendEmptyMessage(0);
}
}
Oops, something went wrong.

0 comments on commit bbd084e

Please sign in to comment.