Skip to content
Permalink
Browse files

Initial commit

  • Loading branch information...
razerdp committed Feb 9, 2016
0 parents commit b7b905a096d2dad7a83d88bfa10f48510e8c1589
Showing with 1,092 additions and 0 deletions.
  1. +9 −0 .gitignore
  2. +1 −0 app/.gitignore
  3. +27 −0 app/build.gradle
  4. +17 −0 app/proguard-rules.pro
  5. +13 −0 app/src/androidTest/java/razerdp/friendcircle/ApplicationTest.java
  6. +20 −0 app/src/main/AndroidManifest.xml
  7. +26 −0 app/src/main/java/razerdp/friendcircle/MainActivity.java
  8. +9 −0 app/src/main/java/razerdp/friendcircle/api/ptrwidget/OnLoadMoreRefreshListener.java
  9. +9 −0 app/src/main/java/razerdp/friendcircle/api/ptrwidget/OnPullDownRefreshListener.java
  10. +9 −0 app/src/main/java/razerdp/friendcircle/api/ptrwidget/PullMode.java
  11. +9 −0 app/src/main/java/razerdp/friendcircle/api/ptrwidget/PullStatus.java
  12. +116 −0 app/src/main/java/razerdp/friendcircle/utils/UIHelper.java
  13. +109 −0 app/src/main/java/razerdp/friendcircle/widget/ptrwidget/FriendCirclePtrFooter.java
  14. +149 −0 app/src/main/java/razerdp/friendcircle/widget/ptrwidget/FriendCirclePtrHeader.java
  15. +163 −0 app/src/main/java/razerdp/friendcircle/widget/ptrwidget/FriendCirclePtrListView.java
  16. BIN app/src/main/res/drawable-xhdpi/rotate_icon.png
  17. +35 −0 app/src/main/res/layout/activity_main.xml
  18. +8 −0 app/src/main/res/layout/widget_ptr_header.xml
  19. BIN app/src/main/res/mipmap-hdpi/ic_launcher.png
  20. BIN app/src/main/res/mipmap-mdpi/ic_launcher.png
  21. BIN app/src/main/res/mipmap-xhdpi/ic_launcher.png
  22. BIN app/src/main/res/mipmap-xxhdpi/ic_launcher.png
  23. BIN app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
  24. +6 −0 app/src/main/res/values-w820dp/dimens.xml
  25. +6 −0 app/src/main/res/values/attrs.xml
  26. +10 −0 app/src/main/res/values/colors.xml
  27. +4 −0 app/src/main/res/values/colors_values.xml
  28. +5 −0 app/src/main/res/values/dimens.xml
  29. +5 −0 app/src/main/res/values/dimens_values.xml
  30. +3 −0 app/src/main/res/values/strings.xml
  31. +12 −0 app/src/main/res/values/styles.xml
  32. +15 −0 app/src/test/java/razerdp/friendcircle/ExampleUnitTest.java
  33. +23 −0 build.gradle
  34. +17 −0 gradle.properties
  35. BIN gradle/wrapper/gradle-wrapper.jar
  36. +6 −0 gradle/wrapper/gradle-wrapper.properties
  37. +160 −0 gradlew
  38. +90 −0 gradlew.bat
  39. +1 −0 settings.gradle
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.idea
@@ -0,0 +1 @@
/build
@@ -0,0 +1,27 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "razerdp.friendcircle"
minSdkVersion 15
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'in.srain.cube:ultra-ptr:1.0.11'
}
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\android developer\adt-bundle-windows-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 *;
#}
@@ -0,0 +1,13 @@
package razerdp.friendcircle;

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);
}
}
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="razerdp.friendcircle">

<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">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

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

</manifest>
@@ -0,0 +1,26 @@
package razerdp.friendcircle;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import in.srain.cube.views.ptr.PtrUIHandler;
import razerdp.friendcircle.widget.ptrwidget.FriendCirclePtrListView;

public class MainActivity extends AppCompatActivity {
private FriendCirclePtrListView mFriendCirclePtrListView;
private ImageView rotateIcon;
private RelativeLayout actionBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actionBar= (RelativeLayout) findViewById(R.id.action_bar);
rotateIcon= (ImageView) findViewById(R.id.rotate_icon);
mFriendCirclePtrListView= (FriendCirclePtrListView) findViewById(R.id.listview);
mFriendCirclePtrListView.setRotateIcon(rotateIcon);

}
}
@@ -0,0 +1,9 @@
package razerdp.friendcircle.api.ptrwidget;

/**
* Created by 大灯泡 on 2016/2/9.
* 加载更多接口
*/
public interface OnLoadMoreRefreshListener {
void onRefreshing();
}
@@ -0,0 +1,9 @@
package razerdp.friendcircle.api.ptrwidget;

/**
* Created by 大灯泡 on 2016/2/9.
* 下拉刷新接口
*/
public interface OnPullDownRefreshListener {
void onRefreshing();
}
@@ -0,0 +1,9 @@
package razerdp.friendcircle.api.ptrwidget;

/**
* Created by 大灯泡 on 2016/2/9.
* 当前模式
*/
public enum PullMode {
FROM_START,FROM_BOTTOM
}
@@ -0,0 +1,9 @@
package razerdp.friendcircle.api.ptrwidget;

/**
* Created by 大灯泡 on 2016/2/9.
* 当前状态
*/
public enum PullStatus {
NORMAL,REFRESHING
}
@@ -0,0 +1,116 @@
package razerdp.friendcircle.utils;

import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
* Created by 大灯泡 on 2016/2/9.
* ui工具类
*/
public class UIHelper {
/**
* dip转px
*/
public static int dipToPx(Context context, float dip) {
return (int) (dip * context.getResources().getDisplayMetrics().density + 0.5f);
}

/**
* px转dip
*/
public static int pxToDip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}

/**
* 将sp值转换为px值
*/
public static int sp2px(Context context, float spValue) {
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
return (int) (spValue * fontScale + 0.5f);
}

/**
* 获取屏幕分辨率:宽
*/
public static int getScreenPixWidth(Context context) {
return context.getResources().getDisplayMetrics().widthPixels;
}

/**
* 获取屏幕分辨率:高
*/
public static int getScreenPixHeight(Context context) {
return context.getResources().getDisplayMetrics().heightPixels;
}

/**
* 获取状态栏的高度
*/
public static int getStatusHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen",
"android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}

/**
* 隐藏软键盘
*/
public static void hideInputMethod(View view) {
InputMethodManager imm = (InputMethodManager) view.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}

public static void hideInputMethod(final View view, long delayMillis) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
hideInputMethod(view);
}
}, delayMillis);
}

/**
* 显示软键盘
*/
public static void showInputMethod(View view) {
InputMethodManager imm = (InputMethodManager) view.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}

/**
* 显示软键盘
*/
public static void showInputMethod(Context context) {
InputMethodManager imm = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}

/**
* 多少时间后显示软键盘
*/
public static void showInputMethod(final View view, long delayMillis) {
// 显示输入法
new Handler().postDelayed(new Runnable() {

@Override
public void run() {
UIHelper.showInputMethod(view);
}
}, delayMillis);
}
}
@@ -0,0 +1,109 @@
package razerdp.friendcircle.widget.ptrwidget;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrUIHandler;
import in.srain.cube.views.ptr.indicator.PtrIndicator;
import razerdp.friendcircle.R;

/**
* Created by 大灯泡 on 2016/2/9.
* 下拉刷新的头头
*/
public class FriendCirclePtrFooter extends RelativeLayout{
private static final String TAG = "FriendCirclePtrHeader";

private ImageView mRotateIcon;
private View rootView;

public FriendCirclePtrFooter(Context context) {
this(context,null);
}

public FriendCirclePtrFooter(Context context, AttributeSet attrs) {
this(context, attrs,0);
}

public FriendCirclePtrFooter(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public FriendCirclePtrFooter(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

private void initView(Context context) {
rootView= LayoutInflater.from(context).inflate(R.layout.widget_ptr_header,this,false);
mRotateIcon= (ImageView) rootView.findViewById(R.id.rotate_icon);
}

//=============================================================ptr:
private PtrUIHandler mPtrUIHandler=new PtrUIHandler() {
/**回到初始位置*/
@Override
public void onUIReset(PtrFrameLayout frame) {
mRotateIcon.setRotation(0);

}

/**离开初始位置*/
@Override
public void onUIRefreshPrepare(PtrFrameLayout frame) {

}

/**开始刷新动画*/
@Override
public void onUIRefreshBegin(PtrFrameLayout frame) {
RotateAnimation rotateAnimation = new RotateAnimation(mRotateIcon.getRotation(), 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(600);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setRepeatCount(Animation.INFINITE);
if (mRotateIcon.getAnimation()!=null){
mRotateIcon.clearAnimation();
}
mRotateIcon.startAnimation(rotateAnimation);

}

/**刷新完成*/
@Override
public void onUIRefreshComplete(PtrFrameLayout frame) {

}

/**位移更新重载*/
@Override
public void onUIPositionChange(PtrFrameLayout frame, boolean isUnderTouch, byte status, PtrIndicator ptrIndicator) {
final int mOffsetToRefresh = frame.getOffsetToRefresh();
final int currentPos = ptrIndicator.getCurrentPosY();
final int lastPos = ptrIndicator.getLastPosY();

if (currentPos < mOffsetToRefresh && lastPos >= mOffsetToRefresh) {
//未到达刷新线
if (isUnderTouch && status == PtrFrameLayout.PTR_STATUS_PREPARE) {
mRotateIcon.setRotation(currentPos);
}
} else if (currentPos > mOffsetToRefresh && lastPos <= mOffsetToRefresh) {
//到达或超过刷新线
if (isUnderTouch && status == PtrFrameLayout.PTR_STATUS_PREPARE) {
mRotateIcon.setRotation(currentPos);
}
}

}
};
}
Oops, something went wrong.

0 comments on commit b7b905a

Please sign in to comment.
You can’t perform that action at this time.