Search in sources :

Example 1 with VectorDrawableCompat

use of android.support.graphics.drawable.VectorDrawableCompat in project iosched by google.

the class UIUtils method vectorToBitmap.

public static Bitmap vectorToBitmap(@NonNull Context context, @DrawableRes int drawableResId) {
    VectorDrawableCompat vector = VectorDrawableCompat.create(context.getResources(), drawableResId, context.getTheme());
    final Bitmap bitmap = Bitmap.createBitmap(vector.getIntrinsicWidth(), vector.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);
    vector.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vector.draw(canvas);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat)

Example 2 with VectorDrawableCompat

use of android.support.graphics.drawable.VectorDrawableCompat in project Tusky by Vavassor.

the class MainActivity method setupDrawer.

private void setupDrawer() {
    headerResult = new AccountHeaderBuilder().withActivity(this).withSelectionListEnabledForSingleProfile(false).withDividerBelowHeader(false).withOnAccountHeaderProfileImageListener(new AccountHeader.OnAccountHeaderProfileImageListener() {

        @Override
        public boolean onProfileImageClick(View view, IProfile profile, boolean current) {
            if (current && loggedInAccountId != null) {
                Intent intent = new Intent(MainActivity.this, AccountActivity.class);
                intent.putExtra("id", loggedInAccountId);
                startActivity(intent);
                return true;
            }
            return false;
        }

        @Override
        public boolean onProfileImageLongClick(View view, IProfile profile, boolean current) {
            return false;
        }
    }).withCompactStyle(true).build();
    headerResult.getView().findViewById(R.id.material_drawer_account_header_current).setContentDescription(getString(R.string.action_view_profile));
    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);
        }
    });
    VectorDrawableCompat muteDrawable = VectorDrawableCompat.create(getResources(), R.drawable.ic_mute_24dp, getTheme());
    ThemeUtils.setDrawableTint(this, muteDrawable, R.attr.toolbar_icon_tint);
    drawer = new DrawerBuilder().withActivity(this).withAccountHeader(headerResult).withHasStableIds(true).withSelectedItem(-1).addDrawerItems(new PrimaryDrawerItem().withIdentifier(0).withName(getString(R.string.action_edit_profile)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person), new PrimaryDrawerItem().withIdentifier(1).withName(getString(R.string.action_view_favourites)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star), new PrimaryDrawerItem().withIdentifier(2).withName(getString(R.string.action_view_mutes)).withSelectable(false).withIcon(muteDrawable), new PrimaryDrawerItem().withIdentifier(3).withName(getString(R.string.action_view_blocks)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block), new DividerDrawerItem(), new SecondaryDrawerItem().withIdentifier(4).withName(getString(R.string.action_view_preferences)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings), new SecondaryDrawerItem().withIdentifier(5).withName(getString(R.string.about_title_activity)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_info), new SecondaryDrawerItem().withIdentifier(6).withName(getString(R.string.action_logout)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (drawerItem != null) {
                long drawerItemIdentifier = drawerItem.getIdentifier();
                if (drawerItemIdentifier == 0) {
                    Intent intent = new Intent(MainActivity.this, EditProfileActivity.class);
                    startActivity(intent);
                } else if (drawerItemIdentifier == 1) {
                    Intent intent = new Intent(MainActivity.this, FavouritesActivity.class);
                    startActivity(intent);
                } else if (drawerItemIdentifier == 2) {
                    Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                    intent.putExtra("type", AccountListActivity.Type.MUTES);
                    startActivity(intent);
                } else if (drawerItemIdentifier == 3) {
                    Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                    intent.putExtra("type", AccountListActivity.Type.BLOCKS);
                    startActivity(intent);
                } else if (drawerItemIdentifier == 4) {
                    Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
                    startActivity(intent);
                } else if (drawerItemIdentifier == 5) {
                    Intent intent = new Intent(MainActivity.this, AboutActivity.class);
                    startActivity(intent);
                } else if (drawerItemIdentifier == 6) {
                    logout();
                } else if (drawerItemIdentifier == 7) {
                    Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                    intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS);
                    startActivity(intent);
                }
            }
            return false;
        }
    }).build();
}
Also used : AbstractDrawerImageLoader(com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) Drawable(android.graphics.drawable.Drawable) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) Intent(android.content.Intent) Drawer(com.mikepenz.materialdrawer.Drawer) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) FloatingSearchView(com.arlib.floatingsearchview.FloatingSearchView) TextView(android.widget.TextView) Uri(android.net.Uri) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) ImageView(android.widget.ImageView) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder)

Example 3 with VectorDrawableCompat

use of android.support.graphics.drawable.VectorDrawableCompat in project SeriesGuide by UweTrottmann.

the class ActionsHelper method populateActions.

/**
     * Replaces all child views of the given {@link android.view.ViewGroup} with a {@link
     * android.widget.Button} per action plus one linking to {@link com.battlelancer.seriesguide.extensions.ExtensionsConfigurationActivity}.
     * Sets up {@link android.view.View.OnClickListener} if {@link com.battlelancer.seriesguide.api.Action#getViewIntent()}
     * of an  {@link com.battlelancer.seriesguide.api.Action} is not null.
     */
public static void populateActions(@NonNull LayoutInflater layoutInflater, @NonNull Resources.Theme theme, @Nullable ViewGroup actionsContainer, @Nullable List<Action> data, @NonNull final String logCategory) {
    if (actionsContainer == null) {
        // nothing we can do, view is already gone
        Timber.d("populateActions: action view container gone, aborting");
        return;
    }
    actionsContainer.removeAllViews();
    // re-use drawable for all buttons
    int vectorResId = Utils.resolveAttributeToResourceId(theme, R.attr.drawableExtension);
    VectorDrawableCompat drawable = VectorDrawableCompat.create(actionsContainer.getResources(), vectorResId, theme);
    // add a view per action
    if (data != null) {
        for (Action action : data) {
            Button actionView = (Button) layoutInflater.inflate(R.layout.item_action, actionsContainer, false);
            actionView.setText(action.getTitle());
            Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(actionView, drawable, null, null, null);
            CheatSheet.setup(actionView, action.getTitle());
            final Intent viewIntent = action.getViewIntent();
            if (viewIntent != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
                } else {
                    //noinspection deprecation
                    viewIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                }
                actionView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Utils.tryStartActivity(v.getContext(), viewIntent, true);
                    }
                });
            }
            actionsContainer.addView(actionView);
        }
    }
    // link to extensions configuration
    TextView configureView = (TextView) layoutInflater.inflate(R.layout.item_action_add, actionsContainer, false);
    configureView.setText(R.string.action_extensions_configure);
    configureView.setOnClickListener(new View.OnClickListener() {

        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(v.getContext(), ExtensionsConfigurationActivity.class);
            if (AndroidUtils.isJellyBeanOrHigher()) {
                v.getContext().startActivity(intent, ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight()).toBundle());
            } else {
                v.getContext().startActivity(intent);
            }
            Utils.trackAction(v.getContext(), logCategory, "Manage extensions");
        }
    });
    actionsContainer.addView(configureView);
}
Also used : Action(com.battlelancer.seriesguide.api.Action) Button(android.widget.Button) Intent(android.content.Intent) TextView(android.widget.TextView) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat) TextView(android.widget.TextView) View(android.view.View) TargetApi(android.annotation.TargetApi)

Example 4 with VectorDrawableCompat

use of android.support.graphics.drawable.VectorDrawableCompat in project SeriesGuide by UweTrottmann.

the class Utils method setVectorCompoundDrawable.

public static void setVectorCompoundDrawable(Resources.Theme theme, Button button, @AttrRes int vectorAttr) {
    int vectorResId = Utils.resolveAttributeToResourceId(theme, vectorAttr);
    VectorDrawableCompat drawable = VectorDrawableCompat.create(button.getResources(), vectorResId, theme);
    Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(button, drawable, null, null, null);
}
Also used : VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat) SuppressLint(android.annotation.SuppressLint)

Aggregations

VectorDrawableCompat (android.support.graphics.drawable.VectorDrawableCompat)4 Intent (android.content.Intent)2 View (android.view.View)2 TextView (android.widget.TextView)2 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 BindView (butterknife.BindView)1 FloatingSearchView (com.arlib.floatingsearchview.FloatingSearchView)1 Action (com.battlelancer.seriesguide.api.Action)1 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)1 Drawer (com.mikepenz.materialdrawer.Drawer)1 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)1 DividerDrawerItem (com.mikepenz.materialdrawer.model.DividerDrawerItem)1 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)1