/** * Returns a PNG-encoded screenshot of the the window region at (|windowX|, |windowY|) with the * size |width| by |height| pixels. */ @CalledByNative public byte[] grabSnapshot(int windowX, int windowY, int width, int height) { try { // Take a screenshot of the root activity view. This generally includes UI // controls such as the URL bar and OS windows such as the status bar. View rootView = mActivity.findViewById(android.R.id.content).getRootView(); Bitmap bitmap = UiUtils.generateScaledScreenshot(rootView, 0, Bitmap.Config.ARGB_8888); if (bitmap == null) return null; // Clip the result into the requested region. if (windowX > 0 || windowY > 0 || width != bitmap.getWidth() || height != bitmap.getHeight()) { Rect clip = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); clip.intersect(windowX, windowY, windowX + width, windowY + height); bitmap = Bitmap.createBitmap(bitmap, clip.left, clip.top, clip.width(), clip.height()); } // Compress the result into a PNG. ByteArrayOutputStream result = new ByteArrayOutputStream(); if (!bitmap.compress(Bitmap.CompressFormat.PNG, 100, result)) return null; bitmap.recycle(); return result.toByteArray(); } catch (OutOfMemoryError e) { Log.e(TAG, "Out of memory while grabbing window snapshot.", e); return null; } }
private void updateFromCursor() { if (mCursor == null) { Log.error("mCursor is null."); return; } final Activity activity = getActivity(); if (activity == null) return; if (mCursor.getCount() <= 0) { // In case the query returned no rows. Log.error( "SubjectViewerFragment.updateFromCursor(): The ContentProvider query returned no rows."); UiUtils.warnAboutMissingNetwork(activity, mRootView); return; } mCursor.moveToFirst(); // There should only be one anyway. if (mRootView == null) { Log.error("SubjectViewerFragment.updateFromCursor(): mRootView is null."); return; } // This will return the actual ID if we asked for the NEXT id. if (mCursor.getCount() > 0) { final String itemId = mCursor.getString(COLUMN_INDEX_ID); setItemId(itemId); } // TODO: Just update them. addOrUpdateChildFragments(); }
/* */ public void onClick(DialogInterface dialog, int id) /* */ { /* */ try /* */ { /* 86 */ this.val$context.startActivity(this.val$intent); /* */ } /* */ catch (ActivityNotFoundException e) /* */ { /* 90 */ UiUtils.access$100(this.val$context); /* */ } /* */ }
private SharePrefrenceUtil() { sharedPreferences = UiUtils.getContext().getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); editor = sharedPreferences.edit(); }