@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_zoom_image); AmbientMode.attachAmbientSupport(this); // Check if integer was actually given. if (!(getIntent().hasExtra(getString(R.string.intent_extra_image)))) { throw new NotFoundException("Expecting extras"); } // Grab the resource id from extras and set the image resource. int value = getIntent().getIntExtra(getString(R.string.intent_extra_image), 0); ImageView expandedImage = findViewById(R.id.expanded_image); expandedImage.setImageResource(value); }
@NonNull public String[] getStringArray(@ArrayRes int id) throws NotFoundException { Map<Integer, String> idNameMap = getArrayIdTable(); Map<String, List<String>> stringArrayMap = getResourceStringArrayMap(); if (idNameMap.containsKey(id)) { String name = idNameMap.get(id); if (stringArrayMap.containsKey(name)) { List<String> stringList = stringArrayMap.get(name); return stringList.toArray(new String[0]); } } throw new Resources.NotFoundException("String array resource ID #0x" + Integer.toHexString(id)); }
@NonNull public int[] getIntArray(@ArrayRes int id) throws NotFoundException { Map<Integer, String> idNameMap = getArrayIdTable(); Map<String, List<Integer>> intArrayMap = getResourceIntArrayMap(); if (idNameMap.containsKey(id)) { String name = idNameMap.get(id); if (intArrayMap.containsKey(name)) { List<Integer> intList = intArrayMap.get(name); int[] intArray = new int[intList.size()]; for (int i = 0; i < intList.size(); i++) { intArray[i] = intList.get(i); } return intArray; } } return new int[0]; }
private Drawable resolveResource() { Resources rsrc = getResources(); if (rsrc == null) { return null; } Drawable d = null; if (nResource != 0) { try { d = rsrc.getDrawable(nResource); } catch (NotFoundException e) { // Don't try again. nResource = 0; } } return SelectableRoundedCornerDrawable.fromDrawable(d, getResources()); }
public void showToast(String resId, int duration) { String res = null; if (TextUtils.empty(resId)) { resId = "umgr_rcode_fail"; } try { res = L10NString.getString(resId); } catch (NotFoundException e) { LOG.e(TAG, "[resId:" + resId + "] get string failed(NotFoundException)", e); } try { if (!TextUtils.empty(res)) { ToastHelper.getInstance().shortOrLongToast((Context) this, res, duration); } } catch (NotFoundException e2) { LOG.e(TAG, "[resId:" + resId + "] show toast failed(NotFoundException)", e2); } }
/** * Obtains the view's background from a specific typed array. * * @param typedArray * The typed array, the background should be obtained from, as an instance of the class * {@link TypedArray}. The typed array may not be null */ private void obtainBackground(@NonNull final TypedArray typedArray) { Drawable background = typedArray.getDrawable(R.styleable.TabSwitcher_android_background); if (background == null) { try { background = themeHelper.getDrawable(getLayout(), R.attr.tabSwitcherBackground); } catch (NotFoundException e) { background = null; } } if (background != null) { ViewUtil.setBackground(this, background); } }
/** * Returns the icon of tabs. * * @param tab * The tab, the icon should be returned for, as an instance of the class {@link Tab} or * null, if the icon should not be returned for a specific tab * @return The icon of tabs as an instance of the class {@link Drawable} or null, if no icon is * set */ @Nullable public final Drawable getTabIcon(@Nullable final Tab tab) { Drawable icon = tab != null ? tab.getIcon(model.getContext()) : null; if (icon == null) { icon = model.getTabIcon(); if (icon == null) { try { icon = themeHelper .getDrawable(tabSwitcher.getLayout(), R.attr.tabSwitcherTabIcon); } catch (NotFoundException e) { icon = null; } } } return icon; }
/** * Returns the title of the toolbar, which is shown, when the tab switcher is shown. When using * the tablet layout, the title corresponds to the primary toolbar. * * @return The title of the toolbar, which is shown, when the tab switcher is shown, as an * instance of the type {@link CharSequence} or null, if no title is set */ @Nullable public final CharSequence getToolbarTitle() { CharSequence title = model.getToolbarTitle(); if (TextUtils.isEmpty(title)) { try { title = themeHelper .getText(tabSwitcher.getLayout(), R.attr.tabSwitcherToolbarTitle); } catch (NotFoundException e) { title = null; } } return title; }
/** * Returns the navigation icon of the toolbar, which is shown, when the tab switcher is shown. * When using the tablet layout, the icon corresponds to the primary toolbar. * * @return The icon of the toolbar, which is shown, when the tab switcher is shown, as an * instance of the class {@link Drawable} or null, if no icon is set */ @Nullable public final Drawable getToolbarNavigationIcon() { Drawable icon = model.getToolbarNavigationIcon(); if (icon == null) { try { themeHelper.getDrawable(tabSwitcher.getLayout(), R.attr.tabSwitcherToolbarNavigationIcon); } catch (NotFoundException e) { icon = null; } } return icon; }
/** * Returns the color, which corresponds to a specific theme attribute, regarding the theme, * which is used when using a specific layout. * * @param layout * The layout as a value of the enum {@link Layout}. The layout may not be null * @param resourceId * The resource id of the theme attribute, the color should be obtained from, as an * {@link Integer} value. The resource id must correspond to a valid theme attribute * @return The color, which has been obtained, as an {@link Integer} value */ @ColorInt public int getColor(@NonNull final Layout layout, @AttrRes final int resourceId) { try { return ThemeUtil.getColor(context, resourceId); } catch (NotFoundException e1) { int themeResourceId = getThemeResourceId(layout); try { return ThemeUtil.getColor(context, themeResourceId, resourceId); } catch (NotFoundException e) { themeResourceId = obtainThemeFromThemeAttributes(layout, themeResourceId); return ThemeUtil.getColor(context, themeResourceId, resourceId); } } }
/** * Returns the color state list, which corresponds to a specific theme attribute, regarding the * theme, which is used when using a specific layout. * * @param layout * The layout as a value of the enum {@link Layout}. The layout may not be null * @param resourceId * The resource id of the theme attribute, the color state list should be obtained from, * as an {@link Integer} value. The resource id must correspond to a valid theme * attribute * @return The color state list, which has been obtained, as an instance of the class {@link * ColorStateList} */ public ColorStateList getColorStateList(@NonNull final Layout layout, @AttrRes final int resourceId) { try { return ThemeUtil.getColorStateList(context, resourceId); } catch (NotFoundException e1) { int themeResourceId = getThemeResourceId(layout); try { return ThemeUtil.getColorStateList(context, themeResourceId, resourceId); } catch (NotFoundException e) { themeResourceId = obtainThemeFromThemeAttributes(layout, themeResourceId); return ThemeUtil.getColorStateList(context, themeResourceId, resourceId); } } }
private Drawable resolveResource() { Resources rsrc = getResources(); if (rsrc == null) { return null; } Drawable d = null; if (this.mResource != 0) { try { d = rsrc.getDrawable(this.mResource); } catch (NotFoundException e) { Log.w(TAG, "Unable to find resource: " + this.mResource, e); this.mResource = 0; } } return SelectableRoundedCornerDrawable.fromDrawable(d, getResources()); }
private Drawable resolveResource() { Resources rsrc = getResources(); if (rsrc == null) { return null; } Drawable d = null; if (mResource != 0) { try { d = rsrc.getDrawable(mResource); } catch (NotFoundException e) { // Log.w(TAG, "Unable to find resource: " + mResource, e); // Don't try again. mResource = 0; } } return SelectableRoundedCornerDrawable.fromDrawable(d, getResources()); }
public int getColor(int resId){ int originColor = context.getResources().getColor(resId); if(mResources == null || isDefaultSkin){ return originColor; } String resName = context.getResources().getResourceEntryName(resId); int trueResId = mResources.getIdentifier(resName, "color", skinPackageName); int trueColor = 0; try{ trueColor = mResources.getColor(trueResId); }catch(NotFoundException e){ e.printStackTrace(); trueColor = originColor; } return trueColor; }
private String getDescriptionOrId(View view) { String result = view.getContentDescription() != null ? view .getContentDescription().toString() : null; if (isNullOrEmpty(result)) { if (view.getId() != View.NO_ID) { try { result = String.format("with id: \"%s\"", view.getContext() .getResources().getResourceEntryName(view.getId())); } catch (NotFoundException e) { result = String.format(Locale.ENGLISH, "with id: \"%d\"", view.getId()); } } } else { result = String.format("\"%s\"", result); } return result; }
private Drawable resolveResource() { Resources rsrc = getResources(); if (rsrc == null) { return null; } Drawable d = null; if (mResource != 0) { try { d = rsrc.getDrawable(mResource); } catch (NotFoundException e) { Log.w(TAG, "Unable to find resource: " + mResource, e); // Don't try again. mResource = 0; } } return SelectableRoundedCornerDrawable.fromDrawable(d, getResources()); }
/** * Updates the view associated to the activity after the finish of an operation * trying create a new folder * * @param operation Creation operation performed. * @param result Result of the creation. */ private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { dismissLoadingDialog(); populateDirectoryList(); } else { dismissLoadingDialog(); try { Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), Toast.LENGTH_LONG); msg.show(); } catch (NotFoundException e) { Log_OC.e(TAG, "Error while trying to show fail message " , e); } } }
/** * Updates the view associated to the activity after the finish of an operation trying * to create a new folder. * * @param operation Creation operation performed. * @param result Result of the creation. */ private void onCreateFolderOperationFinish( CreateFolderOperation operation, RemoteOperationResult result ) { if (result.isSuccess()) { refreshListOfFilesFragment(); } else { try { Toast msg = Toast.makeText(FolderPickerActivity.this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), Toast.LENGTH_LONG); msg.show(); } catch (NotFoundException e) { Log_OC.e(TAG, "Error while trying to show fail message " , e); } } }
/** * Updates the view associated to the activity after the finish of an operation trying to move a * file. * * @param operation Move operation performed. * @param result Result of the move operation. */ private void onMoveFileOperationFinish(MoveFileOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { dismissLoadingDialog(); refreshListOfFilesFragment(); } else { dismissLoadingDialog(); try { Toast msg = Toast.makeText(FileDisplayActivity.this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), Toast.LENGTH_LONG); msg.show(); } catch (NotFoundException e) { Log_OC.e(TAG, "Error while trying to show fail message ", e); } } }
/** * Updates the view associated to the activity after the finish of an operation trying to copy a * file. * * @param operation Copy operation performed. * @param result Result of the copy operation. */ private void onCopyFileOperationFinish(CopyFileOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { dismissLoadingDialog(); refreshListOfFilesFragment(); } else { dismissLoadingDialog(); try { Toast msg = Toast.makeText(FileDisplayActivity.this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), Toast.LENGTH_LONG); msg.show(); } catch (NotFoundException e) { Log_OC.e(TAG, "Error while trying to show fail message ", e); } } }
/** * Updates the view associated to the activity after the finish of an operation trying create a * new folder * * @param operation Creation operation performed. * @param result Result of the creation. */ private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { dismissLoadingDialog(); refreshListOfFilesFragment(); } else { dismissLoadingDialog(); try { Toast msg = Toast.makeText(FileDisplayActivity.this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), Toast.LENGTH_LONG); msg.show(); } catch (NotFoundException e) { Log_OC.e(TAG, "Error while trying to show fail message ", e); } } }
private void displayUploadResultDialog(Bundle extras) { int descriptionId = extras.getInt(UploaderService.INTENT_KEY_RESULT_DESCRIPTION); try { String descriptionContent = getString(descriptionId); Log.d("displayUploadResultDialog(): Received extras: %s", descriptionId); // display dialog AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); alertDialog.setTitle(R.string.uploader_result_dialog_title); alertDialog.setMessage(descriptionContent); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alertDialog.show(); } catch (NotFoundException ex) { Log.w("displayUploadResultDialog(): Invalid string id received with intent extras: %s", descriptionId); MyApplication.getAnalytics().sendException(ex, Boolean.FALSE); ACRA.getErrorReporter().handleSilentException(ex); } }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) //Resources#getDrawable(int, Theme) @SuppressWarnings("deprecation") //Resources#getDrawable(int) private Drawable getGifOrDefaultDrawable(int resId) { if (resId == 0) { return null; } final Resources resources = getResources(); if (!isInEditMode() && "drawable".equals(resources.getResourceTypeName(resId))) { try { return new GifDrawable(resources, resId); } catch (IOException | NotFoundException ignored) { // ignored } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return resources.getDrawable(resId, getContext().getTheme()); } else { return resources.getDrawable(resId); } }
public int getColor(int resId) { int originColor = context.getResources().getColor(resId); if (mResources == null || isDefaultSkin) { return originColor; } String resName = context.getResources().getResourceEntryName(resId); int trueResId = mResources.getIdentifier(resName, "color", skinPackageName); int trueColor = 0; try { trueColor = mResources.getColor(trueResId); } catch (NotFoundException e) { e.printStackTrace(); trueColor = originColor; } return trueColor; }
@SuppressLint("NewApi") public Drawable getDrawable(int resId) { Drawable originDrawable = context.getResources().getDrawable(resId); if (mResources == null || isDefaultSkin) { return originDrawable; } String resName = context.getResources().getResourceEntryName(resId); int trueResId = mResources.getIdentifier(resName, "drawable", skinPackageName); Drawable trueDrawable = null; try { if (android.os.Build.VERSION.SDK_INT < 22) { trueDrawable = mResources.getDrawable(trueResId); } else { trueDrawable = mResources.getDrawable(trueResId, null); } } catch (NotFoundException e) { e.printStackTrace(); trueDrawable = originDrawable; } return trueDrawable; }
public static String getErrorInfo(Context vContext, int vType) throws NotFoundException { switch(vType) { case SUCCESS: return "success"; case E_NOSDCARD: return vContext.getResources().getString(R.string.error_no_sdcard); case E_STATE_RECODING: return vContext.getResources().getString(R.string.error_state_record); case E_UNKOWN: default: return "未知错误"; } }
public static BitmapDrawable readDrawable(Resources res, int resId, Config bitmapConfig) { BitmapDrawable drawable = null; Bitmap bitmap = null; BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inPreferredConfig = Config.RGB_565; if (bitmapConfig != null) { opts.inPreferredConfig = bitmapConfig; } opts.inPurgeable = true; opts.inInputShareable = true; try { InputStream ips = res.openRawResource(resId); if (ips != null) { bitmap = BitmapFactory.decodeStream(ips, null, opts); } if (bitmap != null) { drawable = new BitmapDrawable(res, bitmap); } } catch (NotFoundException e) { e.printStackTrace(); } return drawable; }
public final void setBackgroundResource(View paramView, int paramInt) { if (paramInt == 0) { return; } Resources localResources = paramView.getResources(); Drawable localDrawable = paramView.getBackground(); if ((localDrawable instanceof CardViewBackgroundDrawable)) { try { ColorStateList localColorStateList = localResources.getColorStateList(paramInt); ((CardViewBackgroundDrawable)localDrawable).setBackgroundColorStateList(localColorStateList); return; } catch (Resources.NotFoundException localNotFoundException) { Log.w("CardViewGroupDelegates", "Unable to set background - ColorStateList not found.", localNotFoundException); return; } } Log.w("CardViewGroupDelegates", "Unable to set background. CardView is not using a CardViewBackgroundDrawable."); }
/** * Load existing users based on user data stored on the file system (no * authentication data is loaded). * * @param _context * @return * @throws NotFoundException * @throws IOException */ public static List<User> loadExistingUsers(Context _context) throws NotFoundException, IOException { if (!isSdCardAvailableRW()) { throw new SdCardNotAvailableException(); } File mediaDir = getMediaStorageDirectory(_context.getResources().getString(R.string.app_media_directory_name)); // load from fs/db File[] files = mediaDir.listFiles(PANSHOT_USER_FOLDER_FILE_FILTER); List<User> list = new ArrayList<User>(); for (File inFile : files) { if (inFile.isDirectory()) { // split id / name String name = inFile.getName().split("_")[0]; String id = inFile.getName().split("_")[1]; list.add(new User(id, name)); } } return list; }
public DisplayMetrics getDisplayMetrics() { // try { // return mFirst.getDisplayMetrics(); // } catch (NotFoundException e) { // if (DEBUG) { // e.printStackTrace(); // } // } // return mSecond.getDisplayMetrics(); try { return mSecond.getDisplayMetrics(); } catch (NotFoundException e) { if (DEBUG) { e.printStackTrace(); } } throw new RuntimeException("error in getDisplayMetrics()."); // return mSecond.getDisplayMetrics(); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @SuppressWarnings("deprecation") //new method not available on older API levels void setResource(boolean isSrc, int resId, Resources res) { try { GifDrawable d = new GifDrawable(res, resId); if (isSrc) setImageDrawable(d); else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) setBackground(d); else setBackgroundDrawable(d); return; } catch (IOException | NotFoundException ignored) { //ignored } if (isSrc) super.setImageResource(resId); else super.setBackgroundResource(resId); }
/** * Obtains the background of the button bar from the activity's current theme. */ private void obtainButtonBarBackground() { try { int color = ThemeUtil.getColor(getActivity(), R.attr.restoreDefaultsButtonBarBackground); setButtonBarBackgroundColor(color); } catch (NotFoundException e) { int resourceId = ThemeUtil .getResId(getActivity(), R.attr.restoreDefaultsButtonBarBackground, -1); if (resourceId != -1) { setButtonBarBackground(resourceId); } else { setButtonBarBackgroundColor( ContextCompat.getColor(getActivity(), R.color.button_bar_background_light)); } } }