Search in sources :

Example 11 with Drawable

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;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable) SpannableString(android.text.SpannableString)

Example 12 with 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);
}
Also used : Drawable(android.graphics.drawable.Drawable) SpannableString(android.text.SpannableString)

Example 13 with Drawable

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);
        }
    });
}
Also used : Context(android.content.Context) AbstractDrawerImageLoader(com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) Uri(android.net.Uri) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable)

Example 14 with Drawable

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);
    }
}
Also used : IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) Drawable(android.graphics.drawable.Drawable)

Example 15 with Drawable

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;
}
Also used : Context(android.content.Context) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) AbsListView(android.widget.AbsListView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) LinearLayout(android.widget.LinearLayout)

Aggregations

Drawable (android.graphics.drawable.Drawable)4516 BitmapDrawable (android.graphics.drawable.BitmapDrawable)795 View (android.view.View)579 Bitmap (android.graphics.Bitmap)476 ColorDrawable (android.graphics.drawable.ColorDrawable)473 ImageView (android.widget.ImageView)471 TextView (android.widget.TextView)439 Paint (android.graphics.Paint)322 LayerDrawable (android.graphics.drawable.LayerDrawable)314 Test (org.junit.Test)276 Context (android.content.Context)267 Resources (android.content.res.Resources)252 Rect (android.graphics.Rect)243 PackageManager (android.content.pm.PackageManager)233 StateListDrawable (android.graphics.drawable.StateListDrawable)212 TypedArray (android.content.res.TypedArray)205 Intent (android.content.Intent)155 ViewGroup (android.view.ViewGroup)148 AnimationDrawable (android.graphics.drawable.AnimationDrawable)147 ArrayList (java.util.ArrayList)139