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;
}
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();
}
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);
}
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);
}
Aggregations