Search in sources :

Example 1 with AbstractDrawerImageLoader

use of com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader 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 2 with AbstractDrawerImageLoader

use of com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader 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 AbstractDrawerImageLoader

use of com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader in project Tusky by tuskyapp.

the class MainActivity method setupDrawer.

private void setupDrawer() {
    headerResult = new AccountHeaderBuilder().withActivity(this).withDividerBelowHeader(false).withHeaderBackgroundScaleType(ImageView.ScaleType.CENTER_CROP).withCurrentProfileHiddenInList(true).withOnAccountHeaderListener((view, profile, current) -> handleProfileClick(profile, current)).addProfiles(new ProfileSettingDrawerItem().withIdentifier(DRAWER_ITEM_ADD_ACCOUNT).withName(R.string.add_account_name).withDescription(R.string.add_account_description).withIcon(GoogleMaterial.Icon.gmd_add)).build();
    headerResult.getView().findViewById(R.id.material_drawer_account_header_current).setContentDescription(getString(R.string.action_view_profile));
    ImageView background = headerResult.getHeaderBackgroundView();
    background.setColorFilter(ContextCompat.getColor(this, R.color.header_background_filter));
    background.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark));
    DrawerImageLoader.init(new AbstractDrawerImageLoader() {

        @Override
        public void set(ImageView imageView, Uri uri, Drawable placeholder, String tag) {
            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);
    List<IDrawerItem> listItem = new ArrayList<>();
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_EDIT_PROFILE).withName(getString(R.string.action_edit_profile)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person));
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_FAVOURITES).withName(getString(R.string.action_view_favourites)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star));
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_LISTS).withName(R.string.action_lists).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_list));
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_MUTED_USERS).withName(getString(R.string.action_view_mutes)).withSelectable(false).withIcon(muteDrawable));
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_BLOCKED_USERS).withName(getString(R.string.action_view_blocks)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block));
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_SEARCH).withName(getString(R.string.action_search)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_search));
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_SAVED_TOOT).withName(getString(R.string.action_access_saved_toot)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_save));
    listItem.add(new DividerDrawerItem());
    listItem.add(new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_PREFERENCES).withName(getString(R.string.action_view_preferences)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings));
    listItem.add(new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_ABOUT).withName(getString(R.string.about_title_activity)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_info));
    listItem.add(new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_LOG_OUT).withName(getString(R.string.action_logout)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app));
    IDrawerItem[] array = new IDrawerItem[listItem.size()];
    // fill the array
    listItem.toArray(array);
    drawer = new DrawerBuilder().withActivity(this).withAccountHeader(headerResult).withHasStableIds(true).withSelectedItem(-1).addDrawerItems(array).withOnDrawerItemClickListener((view, position, drawerItem) -> {
        if (drawerItem != null) {
            long drawerItemIdentifier = drawerItem.getIdentifier();
            if (drawerItemIdentifier == DRAWER_ITEM_EDIT_PROFILE) {
                Intent intent = new Intent(MainActivity.this, EditProfileActivity.class);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_FAVOURITES) {
                Intent intent = new Intent(MainActivity.this, FavouritesActivity.class);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_MUTED_USERS) {
                Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                intent.putExtra("type", AccountListActivity.Type.MUTES);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_BLOCKED_USERS) {
                Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                intent.putExtra("type", AccountListActivity.Type.BLOCKS);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_SEARCH) {
                Intent intent = new Intent(MainActivity.this, SearchActivity.class);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_PREFERENCES) {
                Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_ABOUT) {
                Intent intent = new Intent(MainActivity.this, AboutActivity.class);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_LOG_OUT) {
                logout();
            } else if (drawerItemIdentifier == DRAWER_ITEM_FOLLOW_REQUESTS) {
                Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_SAVED_TOOT) {
                Intent intent = new Intent(MainActivity.this, SavedTootActivity.class);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_LISTS) {
                startActivity(ListsActivity.newIntent(this));
            }
        }
        return false;
    }).build();
    if (BuildConfig.DEBUG) {
        IDrawerItem debugItem = new SecondaryDrawerItem().withIdentifier(1337).withName("debug").withDisabledTextColor(Color.GREEN).withSelectable(false).withEnabled(false);
        drawer.addItem(debugItem);
    }
    updateProfiles();
}
Also used : ImageButton(android.widget.ImageButton) Bundle(android.os.Bundle) Uri(android.net.Uri) ImageView(android.widget.ImageView) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Drawable(android.graphics.drawable.Drawable) DrawerImageLoader(com.mikepenz.materialdrawer.util.DrawerImageLoader) Picasso(com.squareup.picasso.Picasso) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) Account(com.keylesspalace.tusky.entity.Account) ProfileSettingDrawerItem(com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem) DispatchingAndroidInjector(dagger.android.DispatchingAndroidInjector) NotificationHelper(com.keylesspalace.tusky.util.NotificationHelper) Log(android.util.Log) FloatingActionButton(android.support.design.widget.FloatingActionButton) AndroidInjector(dagger.android.AndroidInjector) AccountHeader(com.mikepenz.materialdrawer.AccountHeader) Fragment(android.support.v4.app.Fragment) ContextCompat(android.support.v4.content.ContextCompat) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) GoogleMaterial(com.mikepenz.google_material_typeface_library.GoogleMaterial) List(java.util.List) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) Nullable(android.support.annotation.Nullable) HasSupportFragmentInjector(dagger.android.support.HasSupportFragmentInjector) Call(retrofit2.Call) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) KeyEvent(android.view.KeyEvent) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) NonNull(android.support.annotation.NonNull) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) Response(retrofit2.Response) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) Drawer(com.mikepenz.materialdrawer.Drawer) ThemeUtils(com.keylesspalace.tusky.util.ThemeUtils) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) TimelinePagerAdapter(com.keylesspalace.tusky.pager.TimelinePagerAdapter) TimelineReceiver(com.keylesspalace.tusky.receiver.TimelineReceiver) Color(android.graphics.Color) AbstractDrawerImageLoader(com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Callback(retrofit2.Callback) Configuration(android.content.res.Configuration) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) MastodonApi(com.keylesspalace.tusky.network.MastodonApi) AccountManager(com.keylesspalace.tusky.db.AccountManager) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) AbstractDrawerImageLoader(com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) ProfileSettingDrawerItem(com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem) Drawable(android.graphics.drawable.Drawable) ArrayList(java.util.ArrayList) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) Intent(android.content.Intent) Uri(android.net.Uri) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) ImageView(android.widget.ImageView) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder)

Aggregations

Drawable (android.graphics.drawable.Drawable)3 Uri (android.net.Uri)3 ImageView (android.widget.ImageView)3 Intent (android.content.Intent)2 VectorDrawableCompat (android.support.graphics.drawable.VectorDrawableCompat)2 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)2 Drawer (com.mikepenz.materialdrawer.Drawer)2 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)2 DividerDrawerItem (com.mikepenz.materialdrawer.model.DividerDrawerItem)2 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)2 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)2 AbstractDrawerImageLoader (com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader)2 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Configuration (android.content.res.Configuration)1 Color (android.graphics.Color)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1