Skip to content

Instantly share code, notes, and snippets.

package your.awesome.app;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import com.android.volley.toolbox.ImageLoader.ImageCache;
public class LruBitmapCache extends LruCache<String, Bitmap> implements ImageCache {
public LruBitmapCache(int maxSize) {
super(maxSize);
package your.awesome.app;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import com.android.volley.toolbox.ImageLoader.ImageCache;
public class LruBitmapCache extends LruCache<String, Bitmap> implements ImageCache {
public LruBitmapCache(int maxSize) {
super(maxSize);
@ZoroLu
ZoroLu / gist:6950931
Created October 12, 2013 15:03
遍历HashMap的两种方法
第一种:
Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
}
效率高,以后一定要使用此种方式!
第二种:
@ZoroLu
ZoroLu / makePointCloud
Created October 12, 2013 14:37
the method to make point cloud in GlowPadView .you can see this method in PointCloud.java of open source about GlowPadView or android source 4.3 \platform\frameworks\base\core\java\com\android\internal\widget\multiwaveview
public void makePointCloud(float innerRadius, float outerRadius) {
if (innerRadius == 0) {
Log.w(TAG, "Must specify an inner radius");
return;
}
mOuterRadius = outerRadius;
mPointCloud.clear();
final float pointAreaRadius = (outerRadius - innerRadius);
final float ds = (2.0f * PI * innerRadius / INNER_POINTS);
final int bands = (int) Math.round(pointAreaRadius / ds);
@ZoroLu
ZoroLu / android screen brightness 屏幕亮度调节
Created October 23, 2012 04:25
android screen brightness 屏幕亮度调节
private void setBrightness( int barValue) {
int birghtness = barValue + MIN_BRIGHTNESS;
LayoutParams lp = getWindow().getAttributes();
lp. screenBrightness = (birghtness / 255.0F); // 预览亮度, 一个浮点数0-1
getWindow().setAttributes(lp);
Settings.System. putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS , birghtness);// brightness设置屏幕亮度,值为30-255
}
// <uses-permission android:name="android.permission.WRITE_SETTINGS" />
@ZoroLu
ZoroLu / gist:3426074
Created August 22, 2012 14:21
android camera pictrue 启动系统相机保存无压缩图片
String status = Environment.getExternalStorageState();
if(status.equals(Environment.MEDIA_MOUNTED))
{
filePath = sdcardDir + "/" + filename + ".jpg";
Intent getImageByCamera = new Intent("android.media.action.IMAGE_CAPTURE");
//得到的filePath这个路径的文件图片没有被压缩,使用是直接根据路径filePath获得这个文件
getImageByCamera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(filePath)));
startActivityForResult(getImageByCamera,RESULT_OK_CAMERA);
}
else
@ZoroLu
ZoroLu / android bitmap 缩略图
Created August 22, 2012 14:16
android bitmap 缩略图
//把图片文件按比例生产高度为240的btimap
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds =true;
bmp = BitmapFactory.decodeFile(filePath, options );
options.inJustDecodeBounds =false;
int be = (int)(options.outHeight/ (float)240);
if(be <= 0)
be = 1;
options.inSampleSize = be;
bmp=BitmapFactory.decodeFile(filePath,options);
@ZoroLu
ZoroLu / android camera pictrue album
Created August 15, 2012 06:50
a method open camera or picture album //对话框打开相机或相册
private void choosePic()
{
final CharSequence[] items = {"拍照上传", "从相册上传", "取消"};
AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle("添加相片")
.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
@ZoroLu
ZoroLu / android tabhost
Created July 26, 2012 17:46
android user-defined tabhost tabactivity 自定义tabhost for use you animation to change tab
/* user-defined TabHost,remenber in you layout use full-name for you tabhost such as com.gng.view.MyTabHost,
you need to write you class extends TabHost,
and override the method setCurrentTab() ,
in this method you can use you own animation to change activity
*/
//this is my setCurrentTab
@Override
public void setCurrentTab(int index)
@ZoroLu
ZoroLu / android notification notificationManager
Created July 26, 2012 02:28
android notification 通知
NotificationManager notificationManager =
(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon,title,when);
Intent openIntent = new Intent(this, MyNotificationActivity);
PendingIntent pIntent = PendingIntent.getActivity(this,0,openIntent,0);
notification.setLatesEventInfo(this, "标题", "内容", pIntent);
notificationManager.notify(0,notification);