您的位置:首页 > 编程语言

代码碎片

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); 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: