Skip to content

Instantly share code, notes, and snippets.

@ixiyang
ixiyang / copyview
Created January 13, 2014 14:18
copy view from animationadapter
public class ViewCopy extends View {
private Bitmap viewCopy;
public ViewCopy(View view) {
super(view.getContext());
copyView(view);
measure(MeasureSpec.makeMeasureSpec(view.getWidth(), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(view.getHeight(), MeasureSpec.EXACTLY));
layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
public static class RoundedDrawable extends Drawable {
protected final float cornerRadius;
protected final int margin;
protected final RectF mRect = new RectF(),
mBitmapRect;
protected final BitmapShader bitmapShader;
protected final Paint paint;
@Override
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
HttpGet httpRequest = new HttpGet(imageUri);
HttpResponse response = httpClient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
return bufHttpEntity.getContent();
}
@ixiyang
ixiyang / DrawingView
Created April 25, 2014 02:51
from androiddev
/*
* Copyright 2014 Gabriele Mariotti
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ixiyang
ixiyang / DownloadService
Last active August 29, 2015 14:01
文件下载
//使用Service实现文件下载
public class NewDownloadService extends IntentService {
public static final int UPDATE_PROGRESS = 8344;
public static final String DOWNLOAD_DIR=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()+"/";
public NewDownloadService() {
super("NewDownloadService");
}
@Override
private String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Audio.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
@ixiyang
ixiyang / package
Created May 20, 2014 12:30
Get installed Applications with Name, Package Name, Version and Icon
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}
@ixiyang
ixiyang / ResetAnimaiton
Created June 16, 2014 02:27
a simple animation
public class ResetAnimimation extends Animation {
int targetHeight;
int originalHeight;
int extraHeight;
View mView;
protected ResetAnimimation(View view, int targetHeight) {
this.mView = view;
this.targetHeight = targetHeight;
originalHeight = view.getHeight();
@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() {
}
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;