@Override public void run() { try { if (end) return; if (evercamCamera.loadingStatus == ImageLoadingStatus.not_started) { if (evercamCamera.isActive()) { // showAndSaveLiveSnapshot(); } } else if (evercamCamera.loadingStatus == ImageLoadingStatus.live_received) { setLayoutForLiveImageReceived(); } else if (evercamCamera.loadingStatus == ImageLoadingStatus.live_not_received) { setLayoutForNoImageReceived(); } } catch (OutOfMemoryError e) { Log.e(TAG, e.toString() + "-::OOM::-" + Log.getStackTraceString(e)); handler.postDelayed(LoadImageRunnable, 5000); } catch (Exception e) { Log.e(TAG, e.toString() + "::" + Log.getStackTraceString(e)); if (!end) { handler.postDelayed(LoadImageRunnable, 5000); } } }
/** * 获取重新计算大小的Bitmap 最大边不超过max * * @param path 图片路径 * @param max 最大边长度 * @return 新Bitmap */ @Override public Bitmap resizeBitmap(String path, int max) { int sample = 1; BitmapFactory.Options opts = new Options(); opts.inJustDecodeBounds = true; opts.inSampleSize = sample; BitmapFactory.decodeFile(path, opts); int w = opts.outWidth; int h = opts.outHeight; if (Math.max(w, h) > max * 4) { sample = 8; } else if (Math.max(w, h) > max * 2) { sample = 4; } else if (Math.max(w, h) > max) { sample = 2; } opts.inPreferredConfig = Config.ARGB_8888; opts.inJustDecodeBounds = false; opts.inSampleSize = sample; try { return (sample == 1) ? BitmapFactory.decodeFile(path, opts) : getScaledBitmap(BitmapFactory.decodeFile(path, opts), max); } catch (OutOfMemoryError e) { Utils.debug(e.toString()); opts.inSampleSize = sample * 2; try { return getScaledBitmap(BitmapFactory.decodeFile(path, opts), max); } catch (OutOfMemoryError e1) { try { Utils.debug(e1.toString()); opts.inSampleSize = sample * 2; return getScaledBitmap(BitmapFactory.decodeFile(path, opts), max); } catch (Exception e2) { Utils.debug(e2.toString()); return null; } } } }
public void run() { int read = -1, size = 0, max = Integer.parseInt( System.getSettings().getString("PREF_HTTP_MAX_BUFFER_SIZE", "10485760")); byte[] chunk = new byte[CHUNK_SIZE]; try { while ((read = mReader.read(chunk, 0, CHUNK_SIZE)) > 0 && size < max) { mBuffer.append(chunk, read); size += read; } if (mBuffer.isEmpty() == false) { // do we have html ? if (mBuffer.indexOf(CONTENT_TEXT_HTML) != -1) { // split headers and body, then apply the filter String data = mBuffer.toString(); String[] split = data.split(HEAD_SEPARATOR, 2); String headers = split[0], body = (split.length > 1 ? split[1] : ""), patched = ""; body = mFilter.onHtmlReceived(body); // remove explicit content length, just in case the body changed after filtering for (String header : headers.split("\n")) { if (header.toLowerCase().contains("content-length") == false) patched += header + "\n"; } headers = patched; mBuffer.setData((headers + HEAD_SEPARATOR + body).getBytes()); } mWriter.write(mBuffer.getData()); mWriter.flush(); } } catch (OutOfMemoryError ome) { Log.e(TAG, ome.toString()); } catch (Exception e) { System.errorLogging(TAG, e); } finally { try { mWriter.flush(); mWriter.close(); mReader.close(); } catch (IOException e) { System.errorLogging(TAG, e); } } }
@Override public void onClick(View v) { try { BitmapDrawable bmp = null; int bmpW = 0, bmpH = 0; if (bmp != null) { bmp = null; } switch (mImageCounter) { case 0: bmp = (BitmapDrawable) getResources().getDrawable(R.drawable.img_big1); break; case 1: bmp = (BitmapDrawable) getResources().getDrawable(R.drawable.img_big3); break; case 2: bmp = (BitmapDrawable) getResources().getDrawable(R.drawable.img_big3); break; case 3: bmp = (BitmapDrawable) getResources().getDrawable(R.drawable.img_big4); break; case 4: bmp = (BitmapDrawable) getResources().getDrawable(R.drawable.img_big5); break; default: break; } // 불러온 이미지의 가로, 세로 너비를 구한다. bmpW = bmp.getIntrinsicWidth(); bmpH = bmp.getIntrinsicHeight(); mImageCounter++; if (mImageCounter > 4) { mImageCounter = 0; } mImgView.setImageDrawable(bmp); mImgView.getLayoutParams().width = bmpW; mImgView.getLayoutParams().height = bmpH; } catch (OutOfMemoryError error) { Log.e("TEST", error.toString()); } }
/* * 采用了新的办法获取APK图标,之前的失败是因为android中存在的一个BUG,通过 * appInfo.publicSourceDir = apkPath;来修正这个问题,详情参见: * http://code.google.com/p/android/issues/detail?id=9151 */ public static Drawable getApkIcon(Context context, String apkPath) { PackageManager pm = context.getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES); if (info != null) { ApplicationInfo appInfo = info.applicationInfo; appInfo.sourceDir = apkPath; appInfo.publicSourceDir = apkPath; try { return appInfo.loadIcon(pm); } catch (OutOfMemoryError e) { Log.e(LOG_TAG, e.toString()); } } return null; }
public CameraLayout(final Activity activity, EvercamCamera camera, boolean showThumbnails) { super(activity.getApplicationContext()); this.context = activity.getApplicationContext(); try { evercamCamera = camera; this.setOrientation(LinearLayout.VERTICAL); this.setGravity(Gravity.START); this.setBackgroundColor(getResources().getColor(R.color.custom_light_gray)); cameraRelativeLayout = new RelativeLayout(context); RelativeLayout.LayoutParams ivParams = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT); cameraRelativeLayout.setLayoutParams(ivParams); this.addView(cameraRelativeLayout); snapshotImageView = new ImageView(context); RelativeLayout.LayoutParams imageViewParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); snapshotImageView.setLayoutParams(imageViewParams); snapshotImageView.setBackgroundColor(Color.TRANSPARENT); snapshotImageView.setScaleType(ImageView.ScaleType.FIT_XY); cameraRelativeLayout.addView(snapshotImageView); offlineImage = new ImageView(context); RelativeLayout.LayoutParams offlineImageParams = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); offlineImageParams.addRule(RelativeLayout.CENTER_HORIZONTAL); offlineImageParams.addRule(RelativeLayout.CENTER_VERTICAL); offlineImage.setLayoutParams(offlineImageParams); cameraRelativeLayout.addView(offlineImage); offlineImage.setImageResource(R.drawable.cam_unavailable); offlineImage.setVisibility(View.INVISIBLE); gradientLayout = new GradientTitleLayout(activity); gradientLayout.setTitle(evercamCamera.getName()); cameraRelativeLayout.addView(gradientLayout); cameraRelativeLayout.setClickable(true); // Show thumbnail returned from Evercam if (showThumbnails) { showThumbnail(); } cameraRelativeLayout.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { VideoActivity.startPlayingVideoForCamera(activity, evercamCamera.getCameraId()); } }); } catch (OutOfMemoryError e) { Log.e(TAG, e.toString() + "-::OOM::-" + Log.getStackTraceString(e)); } }