List of usage examples for android.support.v4.content ContextCompat getDrawable
public static final Drawable getDrawable(Context context, int i)
From source file:com.example.ysh.myapplication.view.readview.PageFactory.java
public void convertBetteryBitmap() { batteryView = (ProgressBar) LayoutInflater.from(mContext).inflate(R.layout.layout_battery_progress, null); batteryView.setProgressDrawable(ContextCompat.getDrawable(mContext, SettingManager.getInstance().getReadTheme() < 4 ? R.drawable.seekbar_battery_bg : R.drawable.seekbar_battery_night_bg)); batteryView.setProgress(battery);//from w ww . j a v a 2s . c om batteryView.setDrawingCacheEnabled(true); batteryView.measure(View.MeasureSpec.makeMeasureSpec(ScreenUtils.dpToPxInt(26), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(ScreenUtils.dpToPxInt(14), View.MeasureSpec.EXACTLY)); batteryView.layout(0, 0, batteryView.getMeasuredWidth(), batteryView.getMeasuredHeight()); batteryView.buildDrawingCache(); batteryBitmap = batteryView.getDrawingCache(); }
From source file:com.github.andrewlord1990.snackbarbuilder.SnackbarBuilder.java
private Drawable getDrawable(@DrawableRes int drawableResId) { return ContextCompat.getDrawable(context, drawableResId); }
From source file:com.apache.fastandroid.novel.view.readview.PageFactory.java
public void convertBetteryBitmap() { batteryView = (ProgressBar) LayoutInflater.from(mContext).inflate(R.layout.layout_battery_progress, null); batteryView.setProgressDrawable(ContextCompat.getDrawable(mContext, SettingManager.getInstance().getReadTheme() < 4 ? R.drawable.seekbar_battery_bg : R.drawable.seekbar_battery_night_bg)); batteryView.setProgress(battery);/*from w w w . j a v a2 s .c o m*/ batteryView.setDrawingCacheEnabled(true); batteryView.measure( View.MeasureSpec.makeMeasureSpec(DimensUtil.dp2px(mContext, 26), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(DimensUtil.dp2px(mContext, 14), View.MeasureSpec.EXACTLY)); batteryView.layout(0, 0, batteryView.getMeasuredWidth(), batteryView.getMeasuredHeight()); batteryView.buildDrawingCache(); //batteryBitmap = batteryView.getDrawingCache(); // tips: @link{https://github.com/JustWayward/BookReader/issues/109} batteryBitmap = Bitmap.createBitmap(batteryView.getDrawingCache()); batteryView.setDrawingCacheEnabled(false); batteryView.destroyDrawingCache(); }
From source file:am.widget.basetabstrip.BaseTabStrip.java
/** * Tab?/*w w w .j ava 2s. c o m*/ * * @param background */ @SuppressWarnings("unused") public void setItemBackground(int background) { setItemBackground(ContextCompat.getDrawable(getContext(), background)); }
From source file:com.dm.material.dashboard.candybar.activities.CandyBarMainActivity.java
private void initNavigationView(Toolbar toolbar) { mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.txt_open, R.string.txt_close) {//from w w w .j a v a2 s. c om @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); SoftKeyboardHelper.closeKeyboard(CandyBarMainActivity.this); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); selectPosition(mPosition); } }; mDrawerToggle.setDrawerIndicatorEnabled(false); toolbar.setNavigationIcon(R.drawable.ic_toolbar_navigation); toolbar.setNavigationOnClickListener(view -> mDrawerLayout.openDrawer(GravityCompat.START)); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawerLayout.addDrawerListener(mDrawerToggle); mNavigationView.getMenu().getItem(3).setVisible(getResources().getBoolean(R.bool.enable_icon_request) || Preferences.getPreferences(this).isPremiumRequestEnabled()); if (WallpaperHelper.getWallpaperType(this) == WallpaperHelper.UNKNOWN) mNavigationView.getMenu().getItem(4).setVisible(false); ColorStateList itemStateList = ContextCompat.getColorStateList(this, Preferences.getPreferences(this).isDarkTheme() ? R.color.navigation_view_item_highlight_dark : R.color.navigation_view_item_highlight); mNavigationView.setItemTextColor(itemStateList); mNavigationView.setItemIconTintList(itemStateList); Drawable background = ContextCompat.getDrawable(this, Preferences.getPreferences(this).isDarkTheme() ? R.drawable.navigation_view_item_background_dark : R.drawable.navigation_view_item_background); mNavigationView.setItemBackground(background); mNavigationView.setNavigationItemSelectedListener(item -> { int id = item.getItemId(); if (id == R.id.navigation_view_home) mPosition = 0; else if (id == R.id.navigation_view_apply) mPosition = 1; else if (id == R.id.navigation_view_icons) mPosition = 2; else if (id == R.id.navigation_view_request) mPosition = 3; else if (id == R.id.navigation_view_wallpapers) mPosition = 4; else if (id == R.id.navigation_view_settings) mPosition = 5; else if (id == R.id.navigation_view_faqs) mPosition = 6; else if (id == R.id.navigation_view_about) mPosition = 7; item.setChecked(true); mDrawerLayout.closeDrawers(); return true; }); NavigationMenuView navigationMenuView = (NavigationMenuView) mNavigationView.getChildAt(0); if (navigationMenuView != null) { navigationMenuView.setVerticalScrollBarEnabled(false); } }
From source file:com.github.irshulx.Components.InputExtensions.java
public void UpdateTextStyle(EditorTextStyle style, TextView editText) { /// String type = getControlType(getActiveView()); try {//from w ww. ja va 2 s . c o m if (editText == null) { editText = (EditText) editorCore.getActiveView(); } EditorControl tag = editorCore.getControlTag(editText); int pBottom = editText.getPaddingBottom(); int pRight = editText.getPaddingRight(); int pTop = editText.getPaddingTop(); if (isEditorTextStyleHeaders(style)) { updateTextStyle(editText, style); return; } if (isEditorTextStyleContentStyles(style)) { boolean containsHeadertextStyle = containsHeaderTextStyle(tag); if (style == EditorTextStyle.BOLD) { boldifyText(tag, editText, containsHeadertextStyle ? HEADING : CONTENT); } else if (style == EditorTextStyle.ITALIC) { italicizeText(tag, editText, containsHeadertextStyle ? HEADING : CONTENT); } return; } if (style == EditorTextStyle.INDENT) { if (editorCore.containsStyle(tag.editorTextStyles, EditorTextStyle.INDENT)) { tag = editorCore.updateTagStyle(tag, EditorTextStyle.INDENT, Op.Delete); editText.setPadding(0, pTop, pRight, pBottom); editText.setTag(tag); } else { tag = editorCore.updateTagStyle(tag, EditorTextStyle.INDENT, Op.Insert); editText.setPadding(30, pTop, pRight, pBottom); editText.setTag(tag); } } else if (style == EditorTextStyle.OUTDENT) { if (editorCore.containsStyle(tag.editorTextStyles, EditorTextStyle.INDENT)) { tag = editorCore.updateTagStyle(tag, EditorTextStyle.INDENT, Op.Delete); editText.setPadding(0, pTop, pRight, pBottom); editText.setTag(tag); } } else if (style == EditorTextStyle.BLOCKQUOTE) { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) editText.getLayoutParams(); if (editorCore.containsStyle(tag.editorTextStyles, EditorTextStyle.BLOCKQUOTE)) { tag = editorCore.updateTagStyle(tag, EditorTextStyle.BLOCKQUOTE, Op.Delete); editText.setPadding(0, pTop, pRight, pBottom); editText.setBackgroundDrawable(ContextCompat.getDrawable(this.editorCore.getContext(), R.drawable.invisible_edit_text)); params.setMargins(0, 0, 0, (int) editorCore.getContext().getResources() .getDimension(R.dimen.edittext_margin_bottom)); } else { float marginExtra = editorCore.getContext().getResources() .getDimension(R.dimen.edittext_margin_bottom) * 1.5f; tag = editorCore.updateTagStyle(tag, EditorTextStyle.BLOCKQUOTE, Op.Insert); editText.setPadding(30, pTop, 30, pBottom); editText.setBackgroundDrawable( editText.getContext().getResources().getDrawable(R.drawable.block_quote_background)); params.setMargins(0, (int) marginExtra, 0, (int) marginExtra); } editText.setTag(tag); } } catch (Exception e) { } }
From source file:com.google.android.exoplayer2.demo.MediaPlayerFragment.java
private void setFastForwardOrRewind(long changingTime, @DrawableRes int drawableId) { centerInfo.setVisibility(View.VISIBLE); centerInfo.setText(generateFastForwardOrRewindTxt(changingTime)); centerInfo.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(getContext(), drawableId), null, null); }
From source file:com.caseystalnaker.android.popinvideodemo.fragments.Camera2VideoFragment.java
private void startRecordingVideo() { if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return;//from www . ja v a 2 s. c o m } try { lockOrientation(); closePreviewSession(); setUpMediaRecorder(); final SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<>(); // Set up Surface for the camera preview final Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); // Set up Surface for the MediaRecorder mRecorderSurface = mMediaRecorder.getSurface(); surfaces.add(mRecorderSurface); mPreviewBuilder.addTarget(mRecorderSurface); // Start a capture session // Once the session starts, we can update the UI and start recording mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // UI mIsRecordingVideo = true; // Start recording mMediaRecorder.start(); startCountdownTimer(); mButtonVideo.setBackgroundDrawable( ContextCompat.getDrawable(mContext, R.drawable.stop_btn)); } }); } @Override public void onConfigureFailed(final @NonNull CameraCaptureSession cameraCaptureSession) { final Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:android.support.v7.preference.Preference.java
/** * Sets the icon for this Preference with a resource ID. * * @see #setIcon(Drawable)/* w ww. ja v a 2 s .com*/ * @param iconResId The icon as a resource ID. */ public void setIcon(int iconResId) { setIcon(ContextCompat.getDrawable(mContext, iconResId)); mIconResId = iconResId; }
From source file:com.cerema.cloud2.ui.activity.FileDisplayActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { boolean retval = true; switch (item.getItemId()) { case R.id.action_sync_account: { startSynchronization();//from w ww . j ava 2s.com break; } case android.R.id.home: { FileFragment second = getSecondFragment(); OCFile currentDir = getCurrentDir(); if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.closeDrawer(GravityCompat.START); } else if ((currentDir != null && currentDir.getParentId() != 0) || (second != null && second.getFile() != null)) { onBackPressed(); } else { mDrawerLayout.openDrawer(GravityCompat.START); } break; } case R.id.action_sort: { SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Read sorting order, default to sort by name ascending Integer sortOrder = appPreferences.getInt("sortOrder", FileStorageUtils.SORT_NAME); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.actionbar_sort_title).setSingleChoiceItems(R.array.actionbar_sortby, sortOrder, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: sortByName(true); break; case 1: sortByDate(false); break; } dialog.dismiss(); } }); builder.create().show(); break; } case R.id.action_switch_view: { if (isGridView()) { item.setTitle(getString(R.string.action_switch_grid_view)); item.setIcon(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_view_module)); getListOfFilesFragment().setListAsPreferred(); } else { item.setTitle(getApplicationContext().getString(R.string.action_switch_list_view)); item.setIcon(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_view_list)); getListOfFilesFragment().setGridAsPreferred(); } return true; } default: retval = super.onOptionsItemSelected(item); } return retval; }