List of usage examples for android.support.v4.content ContextCompat getDrawable
public static final Drawable getDrawable(Context context, int i)
From source file:com.areebbeigh.qrcodeutility.listadapters.DetailOptionsListAdapter.java
@NonNull @Override//from ww w .j a v a 2 s .c o m public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = LayoutInflater.from(getContext()); View customView = inflater.inflate(R.layout.list_item, parent, false); String title = getItem(position); TextView textView = (TextView) customView.findViewById(R.id.list_item_title); ImageView iconView = (ImageView) customView.findViewById(R.id.list_item_vector_icon); textView.setText(title); int drawableID = map.get(title); if (drawableID != -1) { // TODO: IDK why the F-word does this throw a resource not found exception here on API 16 and maybe lower try { iconView.setImageDrawable(ContextCompat.getDrawable(getContext(), drawableID)); } catch (Resources.NotFoundException e) { e.printStackTrace(); // nothing, you just wont get the awesome icons on the phone :( } } return customView; }
From source file:com.heinrichreimersoftware.materialdrawer.adapter.DrawerProfileAdapter.java
@NonNull @Override/*from w w w . j av a2 s . co m*/ public View getView(int position, View convertView, @NonNull ViewGroup parent) { DrawerProfile drawerProfile = getItem(position); DrawerTheme drawerTheme = this.drawerTheme; assert drawerProfile != null; if (drawerProfile.hasDrawerTheme()) { drawerTheme = drawerProfile.getDrawerTheme(); } if (convertView == null || !(convertView instanceof RelativeLayout)) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.md_drawer_item, parent, false); } final ViewHolder viewHolder = new ViewHolder(convertView); int textColorPrimary = drawerTheme.getTextColorPrimary(); if (drawerTheme.isLightTheme()) { viewHolder.getRoot() .setForeground(ContextCompat.getDrawable(getContext(), R.drawable.md_selector_light)); } else { viewHolder.getRoot() .setForeground(ContextCompat.getDrawable(getContext(), R.drawable.md_selector_dark)); } if (drawerTheme.getBackgroundColor() != 0) { viewHolder.getRoot().setBackgroundColor(drawerTheme.getBackgroundColor()); } else { viewHolder.getRoot() .setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); } if (position == 0) { viewHolder.getRoot().setSelected(true); viewHolder.getRoot().setClickable(false); textColorPrimary = drawerTheme.getHighlightColor(); } else { viewHolder.getRoot().setSelected(false); viewHolder.getRoot().setClickable(true); } if (drawerProfile.hasAvatar()) { viewHolder.getImageView().setVisibility(View.VISIBLE); viewHolder.getImageView().setImageDrawable(drawerProfile.getAvatar()); ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) viewHolder.getImageView() .getLayoutParams(); layoutParams.height = getContext().getResources().getDimensionPixelSize(R.dimen.md_avatar_size); layoutParams.width = getContext().getResources().getDimensionPixelSize(R.dimen.md_baseline_content) - getContext().getResources().getDimensionPixelSize(R.dimen.md_baseline); int imagePaddingEnd = getContext().getResources().getDimensionPixelSize(R.dimen.md_baseline_content) - getContext().getResources().getDimensionPixelSize(R.dimen.md_baseline) - getContext().getResources().getDimensionPixelSize(R.dimen.md_avatar_size); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { viewHolder.getImageView().setPaddingRelative(0, 0, imagePaddingEnd, 0); } else { viewHolder.getImageView().setPadding(0, 0, imagePaddingEnd, 0); } } else { viewHolder.getImageView().setVisibility(View.GONE); } if (drawerProfile.hasName()) { viewHolder.getTextViewPrimary().setText(drawerProfile.getName()); viewHolder.getTextViewPrimary().setTextColor(textColorPrimary); if (drawerProfile.hasDescription()) { viewHolder.getTextViewSecondary().setText(drawerProfile.getDescription()); viewHolder.getTextViewSecondary().setTextColor(drawerTheme.getTextColorSecondary()); viewHolder.getTextViewSecondary().setVisibility(View.VISIBLE); viewHolder.getTextViewSecondary().setMaxLines(1); } else { viewHolder.getTextViewSecondary().setVisibility(View.GONE); } } else if (drawerProfile.hasDescription()) { viewHolder.getTextViewPrimary().setText(drawerProfile.getDescription()); viewHolder.getTextViewPrimary().setTextColor(textColorPrimary); viewHolder.getTextViewSecondary().setVisibility(View.GONE); } return convertView; }
From source file:com.jun.fakeoschina.widget.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs) { super(context, attrs); setHorizontalScrollBarEnabled(false); // ?????? if (attrs != null) { // TypedArray attrsTypedArray = context.obtainStyledAttributes(attrs, // R.styleable.PagerSlidingTabStrip); // if (attrsTypedArray != null) { allowWidthFull = true;//from w ww.ja v a 2 s . com //?drawable slidingBlockDrawable = ContextCompat.getDrawable(getContext(), R.drawable.image_sliding_block); disableViewPager = false; // attrsTypedArray.recycle(); // } } }
From source file:com.bitdubai.fermat_android_api.ui.Views.DividerItemDecoration.java
/** * Create a {@link RecyclerView.ItemDecoration} that act has divider for a RecyclerView with horizontal or vertical orientation * using a resource (for example a shape drawable) to draw the divider * * @param context the context activity where is the reciclerView * @param resId the resource id use a drawable xml, for example a shape * @param orientation one of this: {@link DividerItemDecoration#VERTICAL_LIST} or {@link DividerItemDecoration#HORIZONTAL_LIST} *//*w w w .j a va 2 s. com*/ public DividerItemDecoration(Context context, int resId, int orientation) { mDivider = ContextCompat.getDrawable(context, resId); setOrientation(orientation); }
From source file:com.filemanager.free.activities.DbViewer.java
@Override public void onCreate(Bundle savedInstanceState) { this.checkStorage = false; super.onCreate(savedInstanceState); if (theme1 == 1) { setTheme(R.style.appCompatDark); getWindow().getDecorView()/*from www .java 2 s. c om*/ .setBackgroundColor(ContextCompat.getColor(getBaseContext(), R.color.holo_dark_background)); } setContentView(R.layout.activity_db_viewer); toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); skin = PreferenceUtils.getPrimaryColorString(Sp); if (Build.VERSION.SDK_INT >= 21) { ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("File Manager", ((BitmapDrawable) ContextCompat.getDrawable(this, R.mipmap.ic_launcher)).getBitmap(), Color.parseColor(skin)); ((Activity) this).setTaskDescription(taskDescription); } skinStatusBar = PreferenceUtils.getStatusColor(skin); assert (getSupportActionBar()) != null; getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(skin))); getSupportActionBar().setDisplayHomeAsUpEnabled(true); if (Build.VERSION.SDK_INT == 20 || Build.VERSION.SDK_INT == 19) { SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintColor(Color.parseColor(skin)); FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.parentdb) .getLayoutParams(); SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); p.setMargins(0, config.getStatusBarHeight(), 0, 0); } else if (Build.VERSION.SDK_INT >= 21) { boolean colourednavigation = Sp.getBoolean("colorednavigation", true); Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor((PreferenceUtils.getStatusColor(skin))); if (colourednavigation) window.setNavigationBarColor((PreferenceUtils.getStatusColor(skin))); } String path = getIntent().getStringExtra("path"); pathFile = new File(path); listView = (ListView) findViewById(R.id.listView); load(pathFile); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); DbViewerFragment fragment = new DbViewerFragment(); Bundle bundle = new Bundle(); bundle.putString("table", arrayList.get(position)); fragment.setArguments(bundle); fragmentTransaction.add(R.id.content_frame, fragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } }); }
From source file:com.finchuk.clock2.timers.ui.TimerViewHolder.java
public TimerViewHolder(ViewGroup parent, OnListItemInteractionListener<Timer> listener, AsyncTimersTableUpdateHandler asyncTimersTableUpdateHandler) { super(parent, R.layout.item_timer, listener); Log.d(TAG, "New TimerViewHolder"); mAsyncTimersTableUpdateHandler = asyncTimersTableUpdateHandler; mStartIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_start_24dp); mPauseIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_pause_24dp); // TODO: This is bad! Use a Controller/Presenter instead... // or simply pass in an instance of FragmentManager to the ctor. AppCompatActivity act = (AppCompatActivity) getContext(); mAddLabelDialogController = new AddLabelDialogController(act.getSupportFragmentManager(), new AddLabelDialog.OnLabelSetListener() { @Override// ww w . j ava 2s .c om public void onLabelSet(String label) { mController.updateLabel(label); } }); // The item layout is inflated in the super ctor, so we can safely reference our views. mPopupMenu = new PopupMenu(getContext(), mMenuButton); mPopupMenu.inflate(R.menu.menu_timer_viewholder); mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_delete: mController.deleteTimer(); return true; } return false; } }); }
From source file:com.gelakinetic.mtgfam.helpers.ImageGetterHelper.java
/** * This function returns a custom ImageGetter which replaces glyphs with text. * This could have been a new subclass of ImageGetter with a constructor that takes a resource, but I guess * I didn't feel like writing it that way on that day. * * @param context the context to get resources to get drawables from * @return a custom ImageGetter/*from www .j a va2 s.co m*/ */ public static ImageGetter GlyphGetter(final Context context) { return new ImageGetter() { public Drawable getDrawable(String source) { Drawable d = null; source = source.replace("/", ""); if (source.equalsIgnoreCase("w")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_w);//ContextCompat.getDrawable(context, R.drawable.glyph_w, null); } else if (source.equalsIgnoreCase("u")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_u); } else if (source.equalsIgnoreCase("b")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_b); } else if (source.equalsIgnoreCase("r")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_r); } else if (source.equalsIgnoreCase("g")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_g); } else if (source.equalsIgnoreCase("t")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_tap); } else if (source.equalsIgnoreCase("q")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_untap); } else if (source.equalsIgnoreCase("wu") || source.equalsIgnoreCase("uw")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_wu); } else if (source.equalsIgnoreCase("ub") || source.equalsIgnoreCase("bu")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_ub); } else if (source.equalsIgnoreCase("br") || source.equalsIgnoreCase("rb")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_br); } else if (source.equalsIgnoreCase("rg") || source.equalsIgnoreCase("gr")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_rg); } else if (source.equalsIgnoreCase("gw") || source.equalsIgnoreCase("wg")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_gw); } else if (source.equalsIgnoreCase("wb") || source.equalsIgnoreCase("bw")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_wb); } else if (source.equalsIgnoreCase("bg") || source.equalsIgnoreCase("gb")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_bg); } else if (source.equalsIgnoreCase("gu") || source.equalsIgnoreCase("ug")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_gu); } else if (source.equalsIgnoreCase("ur") || source.equalsIgnoreCase("ru")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_ur); } else if (source.equalsIgnoreCase("rw") || source.equalsIgnoreCase("wr")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_rw); } else if (source.equalsIgnoreCase("2w") || source.equalsIgnoreCase("w2")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_w2); } else if (source.equalsIgnoreCase("2u") || source.equalsIgnoreCase("u2")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_u2); } else if (source.equalsIgnoreCase("2b") || source.equalsIgnoreCase("b2")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_b2); } else if (source.equalsIgnoreCase("2r") || source.equalsIgnoreCase("r2")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_r2); } else if (source.equalsIgnoreCase("2g") || source.equalsIgnoreCase("g2")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_g2); } else if (source.equalsIgnoreCase("s")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_s); } else if (source.equalsIgnoreCase("pw") || source.equalsIgnoreCase("wp")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_pw); } else if (source.equalsIgnoreCase("pu") || source.equalsIgnoreCase("up")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_pu); } else if (source.equalsIgnoreCase("pb") || source.equalsIgnoreCase("bp")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_pb); } else if (source.equalsIgnoreCase("pr") || source.equalsIgnoreCase("rp")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_pr); } else if (source.equalsIgnoreCase("pg") || source.equalsIgnoreCase("gp")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_pg); } else if (source.equalsIgnoreCase("p")) { d = ContextCompat.getDrawable(context, getResourceIdFromAttr(context.getTheme(), R.attr.glyph_p)); } else if (source.equalsIgnoreCase("+oo")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_inf); } else if (source.equalsIgnoreCase("100")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_100); } else if (source.equalsIgnoreCase("1000000")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_1000000); } else if (source.equalsIgnoreCase("hr") || source.equalsIgnoreCase("rh")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_hr); } else if (source.equalsIgnoreCase("hw") || source.equalsIgnoreCase("wh")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_hw); } else if (source.equalsIgnoreCase("c")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_c); } else if (source.equalsIgnoreCase("chaos")) { d = ContextCompat.getDrawable(context, getResourceIdFromAttr(context.getTheme(), R.attr.glyph_chaos)); } else if (source.equalsIgnoreCase("z")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_z); } else if (source.equalsIgnoreCase("y")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_y); } else if (source.equalsIgnoreCase("x")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_x); } else if (source.equalsIgnoreCase("h")) { d = ContextCompat.getDrawable(context, R.drawable.glyph_half); } else if (source.equalsIgnoreCase("pwk")) { d = ContextCompat.getDrawable(context, getResourceIdFromAttr(context.getTheme(), R.attr.glyph_pwk)); } else if (source.equalsIgnoreCase("e")) { d = ContextCompat.getDrawable(context, getResourceIdFromAttr(context.getTheme(), R.attr.glyph_e)); } else { for (int i = 0; i < drawableNumbers.length; i++) { if (source.equals(Integer.valueOf(i).toString())) { d = ContextCompat.getDrawable(context, drawableNumbers[i]); } } } if (d == null) { return null; } d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); return d; } }; }
From source file:com.bitdubai.fermat_android_api.ui.util.FermatDividerItemDecoration.java
/** * Create a {@link RecyclerView.ItemDecoration} that act has divider for a RecyclerView with horizontal or vertical orientation * using a resource (for example a shape drawable) to draw the divider * * @param context the context activity where is the reciclerView * @param resId the resource id use a drawable xml, for example a shape * @param orientation one of this: {@link FermatDividerItemDecoration#VERTICAL_LIST} or {@link FermatDividerItemDecoration#HORIZONTAL_LIST} *///from ww w. jav a 2s . c om public FermatDividerItemDecoration(Context context, int resId, int orientation) { mDivider = ContextCompat.getDrawable(context, resId); setOrientation(orientation); }
From source file:com.igniva.filemanager.activities.DbViewer.java
@Override public void onCreate(Bundle savedInstanceState) { this.checkStorage = false; super.onCreate(savedInstanceState); if (theme1 == 1) { setTheme(R.style.appCompatDark); getWindow().getDecorView().setBackgroundColor(getResources().getColor(R.color.holo_dark_background)); }// w w w .j av a 2 s .c o m setContentView(R.layout.activity_db_viewer); toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (Build.VERSION.SDK_INT >= 21) { ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("Filemanager", ((BitmapDrawable) ContextCompat.getDrawable(this, R.mipmap.ic_launcher)).getBitmap(), Color.parseColor(MainActivity.currentTab == 1 ? skinTwo : skin)); ((Activity) this).setTaskDescription(taskDescription); } getSupportActionBar().setBackgroundDrawable( new ColorDrawable(Color.parseColor(MainActivity.currentTab == 1 ? skinTwo : skin))); getSupportActionBar().setDisplayHomeAsUpEnabled(true); int sdk = Build.VERSION.SDK_INT; if (sdk == 20 || sdk == 19) { SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintColor(Color.parseColor(MainActivity.currentTab == 1 ? skinTwo : skin)); FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.parentdb) .getLayoutParams(); SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); p.setMargins(0, config.getStatusBarHeight(), 0, 0); } else if (Build.VERSION.SDK_INT >= 21) { boolean colourednavigation = Sp.getBoolean("colorednavigation", true); Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(PreferenceUtils.getStatusColor(MainActivity.currentTab == 1 ? skinTwo : skin)); if (colourednavigation) window.setNavigationBarColor( (PreferenceUtils.getStatusColor(MainActivity.currentTab == 1 ? skinTwo : skin))); } path = getIntent().getStringExtra("path"); pathFile = new File(path); listView = (ListView) findViewById(R.id.listView); load(pathFile); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); DbViewerFragment fragment = new DbViewerFragment(); Bundle bundle = new Bundle(); bundle.putString("table", arrayList.get(position)); fragment.setArguments(bundle); fragmentTransaction.add(R.id.content_frame, fragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } }); }
From source file:com.agna.setmaster.ui.screen.condition.time.widget.DaysOfWeekView.java
public void setAccentColor(int accentColor) { for (CheckedTextView v : dayViews) { int redColor = ContextCompat.getColor(getContext(), R.color.profile_active_bg); Drawable drawable;//from w ww.j a v a 2 s . c o m if (accentColor == redColor) { drawable = ContextCompat.getDrawable(getContext(), R.drawable.day_of_week_red_bg); } else { drawable = ContextCompat.getDrawable(getContext(), R.drawable.day_of_week_blue_bg); } v.setBackground(drawable); } }