代码碎片
2015-01-28 11:44
155 查看
1.import android.os.Environment;
import android.net.Uri;
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
2. CharSequence[] voiceRes = mPref.getEntryValues();
int rawId = mContext.getResources().getIdentifier(voiceRes[i].toString(), "raw",
mContext.getPackageName());
AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(rawId);
if (afd == null) {
// illegal raw file
throw new IllegalAccessError();
}
mVoicePlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(),
afd.getLength());
3.
<string-array name="jigsaw_bg_thumb_ic_array">
<item>@drawable/ic_jigsaw_bg1</item>
<item>@drawable/ic_jigsaw_bg2</item>
<item>@drawable/ic_jigsaw_bg3</item>
<!-- item>@drawable/ic_jigsaw_bg4</item>
<item>@drawable/ic_jigsaw_bg5</item>-->
</string-array>
int iconsRes = R.array.jigsaw_bg_thumb_ic_array;
Resources res = getContext().getResources();
int[] icons = getIds(res, iconsRes);
private int[] getIds(Resources res, int resId) {
if (resId == 0) return null;
TypedArray array = res.obtainTypedArray(resId);
int n = array.length();
int ids[] = new int
;
for (int i = 0; i < n; ++i) {
ids[i] = array.getResourceId(i, 0);
}
array.recycle();
return ids;
}
private SparseIntArray mItems;
if (icons != null && elements != null && icons.length > 0
&& elements.length >= icons.length) {
// load image resources to mItems
if (mItems == null) {
mItems = new SparseIntArray(icons.length);
}
if (mItems != null) {
mItems.clear();
for (int i = 0; i < icons.length; i++) {
mItems.put(icons[i], elements[i]);
}
}
}
for (int i = 0; i < mItems.size(); i++) {
RelativeLayout item = (RelativeLayout) LayoutInflater.from(getContext()).inflate(
R.layout.assemble_thumb_item, this, false);
ImageView iv = (ImageView) item.findViewById(R.id.jigsaws);
iv.setImageResource(mItems.keyAt(i));
item.setId(mItems.keyAt(i));
}
Resources res = getContext().getResources();
bitmap = BitmapFactory.decodeResource(res, resID);
File thumbnailFile = new File(thumbnaiFullName);
File primitiveFile = new File(primitiveFullName);
URL thumbnailUrl = null;
URL primitiveUrl = null;
String tUrlStr = "";
String pUrlStr = "";
try {
thumbnailUrl = thumbnailFile.toURL();
primitiveUrl = primitiveFile.toURL();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (thumbnailUrl != null) {
tUrlStr = ECUtil.utf8UrlEncode(thumbnailUrl.toString());
}
if (primitiveUrl != null) {
pUrlStr = ECUtil.utf8UrlEncode(primitiveUrl.toString());
}
bitmap = getDiskBitmap(resURL);
public static Bitmap getDiskBitmap(String ) {
Bitmap bitmap = null;
InputStream in = null;
BufferedOutputStream out = null;
try {
in = new BufferedInputStream(new URL(url).openStream(), 1024);
final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
out = new BufferedOutputStream(dataStream, 1024);
copy(in, out);
out.flush();
byte[] data = dataStream.toByteArray();
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
data = null;
return bitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
只显示上面menu
try {
ViewConfiguration mconfig = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(mconfig, false);
}
} catch (Exception ex) {
}
默认弹出软键盘
mInfoEdit.setFocusable(true);
mInfoEdit.setFocusableInTouchMode(true);
mInfoEdit.requestFocus();
Timer timer = new Timer();
timer.schedule(new TimerTask()
{
public void run()
{
InputMethodManager inputManager =
(InputMethodManager)mInfoEdit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(mInfoEdit, 0);
}
},500);
import android.net.Uri;
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
2. CharSequence[] voiceRes = mPref.getEntryValues();
int rawId = mContext.getResources().getIdentifier(voiceRes[i].toString(), "raw",
mContext.getPackageName());
AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(rawId);
if (afd == null) {
// illegal raw file
throw new IllegalAccessError();
}
mVoicePlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(),
afd.getLength());
3.
<string-array name="jigsaw_bg_thumb_ic_array">
<item>@drawable/ic_jigsaw_bg1</item>
<item>@drawable/ic_jigsaw_bg2</item>
<item>@drawable/ic_jigsaw_bg3</item>
<!-- item>@drawable/ic_jigsaw_bg4</item>
<item>@drawable/ic_jigsaw_bg5</item>-->
</string-array>
int iconsRes = R.array.jigsaw_bg_thumb_ic_array;
Resources res = getContext().getResources();
int[] icons = getIds(res, iconsRes);
private int[] getIds(Resources res, int resId) {
if (resId == 0) return null;
TypedArray array = res.obtainTypedArray(resId);
int n = array.length();
int ids[] = new int
;
for (int i = 0; i < n; ++i) {
ids[i] = array.getResourceId(i, 0);
}
array.recycle();
return ids;
}
private SparseIntArray mItems;
if (icons != null && elements != null && icons.length > 0
&& elements.length >= icons.length) {
// load image resources to mItems
if (mItems == null) {
mItems = new SparseIntArray(icons.length);
}
if (mItems != null) {
mItems.clear();
for (int i = 0; i < icons.length; i++) {
mItems.put(icons[i], elements[i]);
}
}
}
for (int i = 0; i < mItems.size(); i++) {
RelativeLayout item = (RelativeLayout) LayoutInflater.from(getContext()).inflate(
R.layout.assemble_thumb_item, this, false);
ImageView iv = (ImageView) item.findViewById(R.id.jigsaws);
iv.setImageResource(mItems.keyAt(i));
item.setId(mItems.keyAt(i));
}
Resources res = getContext().getResources();
bitmap = BitmapFactory.decodeResource(res, resID);
File thumbnailFile = new File(thumbnaiFullName);
File primitiveFile = new File(primitiveFullName);
URL thumbnailUrl = null;
URL primitiveUrl = null;
String tUrlStr = "";
String pUrlStr = "";
try {
thumbnailUrl = thumbnailFile.toURL();
primitiveUrl = primitiveFile.toURL();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (thumbnailUrl != null) {
tUrlStr = ECUtil.utf8UrlEncode(thumbnailUrl.toString());
}
if (primitiveUrl != null) {
pUrlStr = ECUtil.utf8UrlEncode(primitiveUrl.toString());
}
bitmap = getDiskBitmap(resURL);
public static Bitmap getDiskBitmap(String ) {
Bitmap bitmap = null;
InputStream in = null;
BufferedOutputStream out = null;
try {
in = new BufferedInputStream(new URL(url).openStream(), 1024);
final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
out = new BufferedOutputStream(dataStream, 1024);
copy(in, out);
out.flush();
byte[] data = dataStream.toByteArray();
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
data = null;
return bitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
只显示上面menu
try {
ViewConfiguration mconfig = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(mconfig, false);
}
} catch (Exception ex) {
}
默认弹出软键盘
mInfoEdit.setFocusable(true);
mInfoEdit.setFocusableInTouchMode(true);
mInfoEdit.requestFocus();
Timer timer = new Timer();
timer.schedule(new TimerTask()
{
public void run()
{
InputMethodManager inputManager =
(InputMethodManager)mInfoEdit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(mInfoEdit, 0);
}
},500);
相关文章推荐
- 代码碎片
- 代码碎片(用户控件使用客户端脚本)
- Tarena代码-一些代码碎片
- 第一行代码笔记,第四章-------探究碎片
- phpstorm之自定义代码碎片(tab键自动填充代码)
- 代码碎片记录
- SpringMVC代码碎片拾遗(01)_一个SpringMVC中对于领域模型绑定的不注意错误
- 《第一行代码--Android》读书笔记之碎片
- Android Fragment 碎片 简单代码
- [zhuan]自动整理索引碎片的代码
- Firefly《暗黑世界》碎片合成部分代码
- Wordpress代码碎片插件Code Snippets折腾白屏
- linux内核网络代码学习之碎片整理篇
- Firefly《暗黑世界》碎片合成部分代码
- iPhone代码碎片:处理objective-c里html特殊字符显示问题的一个函数
- 【phpcms-v9】后台编辑碎片时会自动篡改你的代码
- Unity 代码碎片敌人的AI
- Jfinal开发代码碎片_导出报表_配置druid数据源_使用guava_获取当前操作系统_JDK版本_jfinal-utils_jfinal验证码
- 第一行代码笔记 (fragment)碎片的使用
- 第一代码第二版(郭霖著)笔记之第四章(探究碎片)