Skip to content

Instantly share code, notes, and snippets.

@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);
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 / 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"
@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++) {
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 / 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);
@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 / 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;
package net.yscs.android.square_progressbar_example.dialogs;
import net.yscs.android.square_progressbar_example.R;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.widget.Button;
@ixiyang
ixiyang / Singleton
Created June 17, 2014 03:00
Singleton pattern example
/**
*
* thread-safe
*
*/
public class Singleton {
private static final Singleton INSTANCE = new Singleton();
private Singleton() {
}