use of android.graphics.drawable.Drawable in project AndroidTraining by mixi-inc.
the class SuggestionsAdapter method getActivityIcon.
/**
* Gets the activity or application icon for an activity.
*
* @param component Name of an activity.
* @return A drawable, or {@code null} if neither the acitivy or the application
* have an icon set.
*/
private Drawable getActivityIcon(ComponentName component) {
PackageManager pm = mContext.getPackageManager();
final ActivityInfo activityInfo;
try {
activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
} catch (NameNotFoundException ex) {
Log.w(LOG_TAG, ex.toString());
return null;
}
int iconId = activityInfo.getIconResource();
if (iconId == 0)
return null;
String pkg = component.getPackageName();
Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
if (drawable == null) {
Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString());
return null;
}
return drawable;
}
use of android.graphics.drawable.Drawable in project AndroidTraining by mixi-inc.
the class SuggestionsAdapter method getIcon1.
private Drawable getIcon1(Cursor cursor) {
if (mIconName1Col == INVALID_INDEX) {
return null;
}
String value = cursor.getString(mIconName1Col);
Drawable drawable = getDrawableFromResourceValue(value);
if (drawable != null) {
return drawable;
}
return getDefaultIcon1(cursor);
}
use of android.graphics.drawable.Drawable 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.graphics.drawable.Drawable in project MaterialDrawer by mikepenz.
the class ImageHolder method applyDecidedIconOrSetGone.
/**
* decides which icon to apply or hide this view
*
* @param imageHolder
* @param imageView
* @param iconColor
* @param tint
* @param paddingDp
*/
public static void applyDecidedIconOrSetGone(ImageHolder imageHolder, ImageView imageView, int iconColor, boolean tint, int paddingDp) {
if (imageHolder != null && imageView != null) {
Drawable drawable = ImageHolder.decideIcon(imageHolder, imageView.getContext(), iconColor, tint, paddingDp);
if (drawable != null) {
imageView.setImageDrawable(drawable);
imageView.setVisibility(View.VISIBLE);
} else if (imageHolder.getBitmap() != null) {
imageView.setImageBitmap(imageHolder.getBitmap());
imageView.setVisibility(View.VISIBLE);
} else {
imageView.setVisibility(View.GONE);
}
} else if (imageView != null) {
imageView.setVisibility(View.GONE);
}
}
use of android.graphics.drawable.Drawable in project AndroidTraining by mixi-inc.
the class IcsListPopupWindow method buildDropDown.
private int buildDropDown() {
ViewGroup dropDownView;
int otherHeights = 0;
if (mDropDownList == null) {
Context context = mContext;
mDropDownList = new DropDownListView(context, !mModal);
if (mDropDownListHighlight != null) {
mDropDownList.setSelector(mDropDownListHighlight);
}
mDropDownList.setAdapter(mAdapter);
mDropDownList.setOnItemClickListener(mItemClickListener);
mDropDownList.setFocusable(true);
mDropDownList.setFocusableInTouchMode(true);
mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position != -1) {
DropDownListView dropDownList = mDropDownList;
if (dropDownList != null) {
dropDownList.mListSelectionHidden = false;
}
}
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
mDropDownList.setOnScrollListener(mScrollListener);
if (mItemSelectedListener != null) {
mDropDownList.setOnItemSelectedListener(mItemSelectedListener);
}
dropDownView = mDropDownList;
View hintView = mPromptView;
if (hintView != null) {
// if an hint has been specified, we accomodate more space for it and
// add a text view in the drop down menu, at the bottom of the list
LinearLayout hintContainer = new LinearLayout(context);
hintContainer.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f);
switch(mPromptPosition) {
case POSITION_PROMPT_BELOW:
hintContainer.addView(dropDownView, hintParams);
hintContainer.addView(hintView);
break;
case POSITION_PROMPT_ABOVE:
hintContainer.addView(hintView);
hintContainer.addView(dropDownView, hintParams);
break;
default:
break;
}
// measure the hint's height to find how much more vertical space
// we need to add to the drop down's height
int widthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.AT_MOST);
int heightSpec = MeasureSpec.UNSPECIFIED;
hintView.measure(widthSpec, heightSpec);
hintParams = (LinearLayout.LayoutParams) hintView.getLayoutParams();
otherHeights = hintView.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
dropDownView = hintContainer;
}
mPopup.setContentView(dropDownView);
} else {
dropDownView = (ViewGroup) mPopup.getContentView();
final View view = mPromptView;
if (view != null) {
LinearLayout.LayoutParams hintParams = (LinearLayout.LayoutParams) view.getLayoutParams();
otherHeights = view.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
}
}
// getMaxAvailableHeight() subtracts the padding, so we put it back
// to get the available height for the whole window
int padding = 0;
Drawable background = mPopup.getBackground();
if (background != null) {
background.getPadding(mTempRect);
padding = mTempRect.top + mTempRect.bottom;
// background so that content will line up.
if (!mDropDownVerticalOffsetSet) {
mDropDownVerticalOffset = -mTempRect.top;
}
}
// Max height available on the screen for a popup.
boolean ignoreBottomDecorations = mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED;
final int maxHeight = /*mPopup.*/
getMaxAvailableHeight(mDropDownAnchorView, mDropDownVerticalOffset, ignoreBottomDecorations);
if (mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
return maxHeight + padding;
}
final int listContent = /*mDropDownList.*/
measureHeightOfChildren(MeasureSpec.UNSPECIFIED, 0, -1, /*ListView.NO_POSITION*/
maxHeight - otherHeights, -1);
// the popup if it is not needed
if (listContent > 0)
otherHeights += padding;
return listContent + otherHeights;
}
Aggregations