Skip to content

Instantly share code, notes, and snippets.

@ixiyang
ixiyang / CircleProgressButton
Last active August 29, 2015 14:03
from circleprogressbutton
public class CircularProgressButton extends Button{
public static final int IDLE_STATE_PROGRESS = 0;
public static final int ERROR_STATE_PROGRESS = -1;
private GradientDrawable background;
private State mState;
private String mIdleText;
private String mCompleteText;
private String mErrorText;
@ixiyang
ixiyang / Scroll
Last active August 29, 2015 14:03
Scroll View 涉及到的类
OverScroller
startScroll() 开始滚动
computeScrollOffset() 方法不断计算滚动到的最新的位置,当滚动动画结束时,方法返回false。所以通常使用以下方式不断根据最新的位置绘制view来达到滚动的效果
if (mScroller.computeScrollOffset()) {
// This is called at drawing time by ViewGroup. We use
// this method to keep the fling animation going through
// to completion.
int oldX = getScrollX();
int oldY = getScrollY();
int x = mScroller.getCurrX();
@ixiyang
ixiyang / matrix
Created July 15, 2014 10:15
matrix preXXX and postXXX
matrix代表一个3*3矩阵,其内容如下
MSCALE_X MSKEW_X MTRANS_X
MSKEW_Y MSKEW_Y MTRANS_Y
MPERSP_0 MPERSP_1 MPERSP_2
Matrix matrix=new Matrix();
System.err.println(matrix.toShortString());
matrix.postScale(2, 3);
public class RotateZoomImageView extends ImageView {
private ScaleGestureDetector mScaleDetector;
private Matrix mImageMatrix;
/* Last Rotation Angle */
private int mLastAngle = 0;
/* Pivot Point for Transforms */
private int mPivotX, mPivotY;
private float mStartX, mStartY;
public RotateZoomImageView(Context context) {
@ixiyang
ixiyang / hit
Created July 28, 2014 00:53
find the child view that was touched in a listview
Rect rect = new Rect();
int childCount = mListView.getChildCount();
int[] listViewCoords = new int[2];
mListView.getLocationOnScreen(listViewCoords);
System.err.println("listViewCoords[0]====>"+listViewCoords[0]);
System.err.println("listViewCoords[1]====>"+listViewCoords[1]);
int x = (int) motionEvent.getRawX() - listViewCoords[0];
int y = (int) motionEvent.getRawY() - listViewCoords[1];
View child;
for (int i = 0; i < childCount; i++) {
@ixiyang
ixiyang / img
Created July 29, 2014 07:52
scale image to match view bounds
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
public class ResizableImageView extends ImageView {
public ResizableImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
Drawable d = getDrawable();
@ixiyang
ixiyang / getPath
Created July 31, 2014 02:21
get file path from uri
public String getPath(Uri uri) {
String siPath;
// 1:MEDIA GALLERY --- query from MediaStore.Images.Media.DATA
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if (cursor != null) {
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
siPath = cursor.getString(column_index);
@ixiyang
ixiyang / WebviewFragment
Last active August 29, 2015 14:04
webview file upload,handle 4.4.x
public class WebFragment extends Fragment implements OnRefreshListener<WebView> {
public static final String TAG = "WebFragment";
public static final String URL = "url";
public static final String IS_SINGLE_COLUMN = "is_single_column";
private String url;
PullToRefreshWebView refreshWebView;
private WebView webView;
private ProgressBar progressBar;
private boolean isSingleColumn;
private ValueCallback<Uri> mUploadMessage;
@ixiyang
ixiyang / demo
Created August 1, 2014 00:57
disable webview zoom
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setLoadsImagesAutomatically(true);
settings.setBuiltInZoomControls(false);
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT) {
settings.setUseWideViewPort(true);
}else {
settings.setUseWideViewPort(false);
}