Skip to content

Instantly share code, notes, and snippets.

View chiemy's full-sized avatar

chiemy chiemy

View GitHub Profile
@chiemy
chiemy / 0_reuse_code.js
Created March 27, 2014 13:51
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
public class CircularProgressDrawable extends Drawable
implements Animatable {
private static final Interpolator ANGLE_INTERPOLATOR = new LinearInterpolator();
private static final Interpolator SWEEP_INTERPOLATOR = new DecelerateInterpolator();
private static final int ANGLE_ANIMATOR_DURATION = 2000;
private static final int SWEEP_ANIMATOR_DURATION = 600;
private static final int MIN_SWEEP_ANGLE = 30;
private final RectF fBounds = new RectF();
// Queries the user dictionary and returns results
mCursor = getContentResolver().query(
UserDictionary.Words.CONTENT_URI, // The content URI of the words table
mProjection, // The columns to return for each row
mSelectionClause // Selection criteria
mSelectionArgs, // Selection criteria
mSortOrder);
// 查询返回的列
String[] mProjection ={
UserDictionary.Words._ID,    // Contract class constant for the _ID column name   
UserDictionary.Words.WORD,   // Contract class constant for the word column name   
UserDictionary.Words.LOCALE  // Contract class constant for the locale column name};
// 查询条件
String mSelectionClause = null;
// 查询条件的参数值
String[] mSelectionArgs = {""};
/*
* This defines a one-element String array to contain the selection argument.
*/
String[] mSelectionArgs = {""};
// 从UI中获取单词
mSearchString = mSearchWord.getText().toString();
// Remember to insert code here to check for invalid or malicious input.
// 如果为空,则获取全部单词
if (TextUtils.isEmpty(mSearchString)) {
// 设置选择条件为空,会返回所有
// Defines a list of columns to retrieve from the Cursor and load into an output row
String[] mWordListColumns ={
UserDictionary.Words.WORD, // Contract class constant containing the word column name UserDictionary.Words.LOCALE // Contract class constant containing the locale column name
};
// Defines a list of View IDs that will receive the Cursor columns for each row
int[] mWordListItems = { R.id.dictWord, R.id.locale};
// Creates a new SimpleCursorAdapter
mCursorAdapter = new SimpleCursorAdapter(
getApplicationContext(), // 上下文对象
R.layout.wordlistrow, // ListView的Item(一行)
@chiemy
chiemy / ColorOptionsView.java
Last active August 29, 2015 14:06
blog code snippet
package com.vogella.android.customview.compoundview;
import com.vogella.android.view.compoundview.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
private AudioManager.OnAudioFocusChangeListener mOnAudioFocusChangeListener;
//…
mOnAudioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
Log.i(TAG, "AUDIOFOCUS_GAIN");
// Set volume level to desired levels
/*
* Copyright 2014 Chris Banes
*
* 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
public Bitmap blurBitmap(Bitmap bitmap){
//Let's create an empty bitmap with the same size of the bitmap we want to blur
Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
//Instantiate a new Renderscript
RenderScript rs = RenderScript.create(getApplicationContext());
//Create an Intrinsic Blur Script using the Renderscript
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));