use of android.content.Context in project AndroidTraining by mixi-inc.
the class ContextInjectionTest method testGetInstance.
public void testGetInstance() {
Context context = new MockContext(mMockApplication);
assertEquals(context, Proton.getInjector(context).getInstance(Client.class).context1);
assertEquals(context, Proton.getInjector(context).getInstance(Client.class).context2);
assertEquals(context, Proton.getInjector(context).getInstance(Client.class).context2);
assertNotSame(context, Proton.getInjector(new MockContext(mMockApplication)).getInstance(Client.class).context2);
}
use of android.content.Context in project AndroidTraining by mixi-inc.
the class ContextScopedInjectionTest method testGetInstance.
public void testGetInstance() {
Context context1 = new MockContext(mMockApplication);
Client c = Proton.getInjector(context1).getInstance(Client.class);
assertNotNull(c);
assertEquals(c.contextScopedClass1, Proton.getInjector(context1).getInstance(ContextScopedClass.class));
assertNotSame(c.contextScopedClass1, Proton.getInjector(new MockContext(mMockApplication)).getInstance(ContextScopedClass.class));
}
use of android.content.Context in project MaterialDrawer by mikepenz.
the class CustomApplication method onCreate.
@Override
public void onCreate() {
super.onCreate();
LeakCanary.install(this);
/*
//initialize and create the image loader logic
DrawerImageLoader.init(new AbstractDrawerImageLoader() {
@Override
public void set(ImageView imageView, Uri uri, Drawable placeholder) {
Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
}
@Override
public void cancel(ImageView imageView) {
Picasso.with(imageView.getContext()).cancelRequest(imageView);
}
});
*/
//initialize and create the image loader logic
DrawerImageLoader.init(new AbstractDrawerImageLoader() {
@Override
public void set(ImageView imageView, Uri uri, Drawable placeholder, String tag) {
Glide.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
}
@Override
public void cancel(ImageView imageView) {
Glide.clear(imageView);
}
@Override
public Drawable placeholder(Context ctx, String tag) {
//custom ones can be checked via string. see the CustomUrlBasePrimaryDrawerItem LINE 111
if (DrawerImageLoader.Tags.PROFILE.name().equals(tag)) {
return DrawerUIUtils.getPlaceHolder(ctx);
} else if (DrawerImageLoader.Tags.ACCOUNT_HEADER.name().equals(tag)) {
return new IconicsDrawable(ctx).iconText(" ").backgroundColorRes(com.mikepenz.materialdrawer.R.color.primary).sizeDp(56);
} else if ("customUrlItem".equals(tag)) {
return new IconicsDrawable(ctx).iconText(" ").backgroundColorRes(R.color.md_red_500).sizeDp(56);
}
return super.placeholder(ctx, tag);
}
});
}
use of android.content.Context in project MaterialDrawer by mikepenz.
the class AccountDividerDrawerItem method bindView.
@Override
public void bindView(ViewHolder viewHolder, List payloads) {
super.bindView(viewHolder, payloads);
Context ctx = viewHolder.itemView.getContext();
//set the identifier from the drawerItem here. It can be used to run tests
viewHolder.itemView.setId(hashCode());
//define how the divider should look like
viewHolder.view.setClickable(false);
viewHolder.view.setEnabled(false);
viewHolder.view.setMinimumHeight(1);
ViewCompat.setImportantForAccessibility(viewHolder.view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);
//set the color for the divider
viewHolder.divider.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(ctx, com.mikepenz.materialdrawer.R.attr.material_drawer_divider, com.mikepenz.materialdrawer.R.color.material_drawer_divider));
//call the onPostBindView method to trigger post bind view actions (like the listener to modify the item if required)
onPostBindView(this, viewHolder.itemView);
}
use of android.content.Context in project MaterialDrawer by mikepenz.
the class CustomUrlBasePrimaryDrawerItem method bindViewHelper.
/**
* a helper method to have the logic for all secondaryDrawerItems only once
*
* @param viewHolder
*/
protected void bindViewHelper(CustomBaseViewHolder viewHolder) {
Context ctx = viewHolder.itemView.getContext();
//set the identifier from the drawerItem here. It can be used to run tests
viewHolder.itemView.setId(hashCode());
//set the item selected if it is
viewHolder.itemView.setSelected(isSelected());
//get the correct color for the background
int selectedColor = getSelectedColor(ctx);
//get the correct color for the text
int color = getColor(ctx);
int selectedTextColor = getSelectedTextColor(ctx);
//get the correct color for the icon
int iconColor = getIconColor(ctx);
int selectedIconColor = getSelectedIconColor(ctx);
//set the background for the item
UIUtils.setBackground(viewHolder.view, UIUtils.getSelectableBackground(ctx, selectedColor, true));
//set the text for the name
StringHolder.applyTo(this.getName(), viewHolder.name);
//set the text for the description or hide
StringHolder.applyToOrHide(this.getDescription(), viewHolder.description);
//set the colors for textViews
viewHolder.name.setTextColor(getTextColorStateList(color, selectedTextColor));
//set the description text color
ColorHolder.applyToOr(getDescriptionTextColor(), viewHolder.description, getTextColorStateList(color, selectedTextColor));
//define the typeface for our textViews
if (getTypeface() != null) {
viewHolder.name.setTypeface(getTypeface());
viewHolder.description.setTypeface(getTypeface());
}
//we make sure we reset the image first before setting the new one in case there is an empty one
DrawerImageLoader.getInstance().cancelImage(viewHolder.icon);
viewHolder.icon.setImageBitmap(null);
//get the drawables for our icon and set it
ImageHolder.applyTo(icon, viewHolder.icon, "customUrlItem");
//for android API 17 --> Padding not applied via xml
DrawerUIUtils.setDrawerVerticalPadding(viewHolder.view);
}
Aggregations