Search in sources :

Example 11 with IProfile

use of com.mikepenz.materialdrawer.model.interfaces.IProfile in project MaterialDrawer by mikepenz.

the class AccountHeaderBuilder method onProfileClick.

protected void onProfileClick(View v, boolean current) {
    final IProfile profile = (IProfile) v.getTag(R.id.material_drawer_profile_header);
    switchProfiles(profile);
    //reset the drawer content
    resetDrawerContent(v.getContext());
    //notify the MiniDrawer about the clicked profile (only if one exists and is hooked to the Drawer
    if (mDrawer != null && mDrawer.getDrawerBuilder() != null && mDrawer.getDrawerBuilder().mMiniDrawer != null) {
        mDrawer.getDrawerBuilder().mMiniDrawer.onProfileClick();
    }
    //notify about the changed profile
    boolean consumed = false;
    if (mOnAccountHeaderListener != null) {
        consumed = mOnAccountHeaderListener.onProfileChanged(v, profile, current);
    }
    if (!consumed) {
        if (mOnProfileClickDrawerCloseDelay > 0) {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (mDrawer != null) {
                        mDrawer.closeDrawer();
                    }
                }
            }, mOnProfileClickDrawerCloseDelay);
        } else {
            if (mDrawer != null) {
                mDrawer.closeDrawer();
            }
        }
    }
}
Also used : Handler(android.os.Handler) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile)

Example 12 with IProfile

use of com.mikepenz.materialdrawer.model.interfaces.IProfile in project MaterialDrawer by mikepenz.

the class AccountHeaderBuilder method buildDrawerSelectionList.

/**
     * helper method to build and set the drawer selection list
     */
protected void buildDrawerSelectionList() {
    int selectedPosition = -1;
    int position = 0;
    ArrayList<IDrawerItem> profileDrawerItems = new ArrayList<>();
    if (mProfiles != null) {
        for (IProfile profile : mProfiles) {
            if (profile == mCurrentProfile) {
                if (mCurrentHiddenInList) {
                    continue;
                } else {
                    selectedPosition = mDrawer.mDrawerBuilder.getItemAdapter().getGlobalPosition(position);
                }
            }
            if (profile instanceof IDrawerItem) {
                ((IDrawerItem) profile).withSetSelected(false);
                profileDrawerItems.add((IDrawerItem) profile);
            }
            position = position + 1;
        }
    }
    mDrawer.switchDrawerContent(onDrawerItemClickListener, onDrawerItemLongClickListener, profileDrawerItems, selectedPosition);
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) ArrayList(java.util.ArrayList) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile)

Example 13 with IProfile

use of com.mikepenz.materialdrawer.model.interfaces.IProfile in project MaterialDrawer by mikepenz.

the class AccountHeaderBuilder method switchProfiles.

/**
     * helper method to switch the profiles
     *
     * @param newSelection
     * @return true if the new selection was the current profile
     */
protected boolean switchProfiles(IProfile newSelection) {
    if (newSelection == null) {
        return false;
    }
    if (mCurrentProfile == newSelection) {
        return true;
    }
    if (mAlternativeProfileHeaderSwitching) {
        int prevSelection = -1;
        if (mProfileFirst == newSelection) {
            prevSelection = 1;
        } else if (mProfileSecond == newSelection) {
            prevSelection = 2;
        } else if (mProfileThird == newSelection) {
            prevSelection = 3;
        }
        IProfile tmp = mCurrentProfile;
        mCurrentProfile = newSelection;
        if (prevSelection == 1) {
            mProfileFirst = tmp;
        } else if (prevSelection == 2) {
            mProfileSecond = tmp;
        } else if (prevSelection == 3) {
            mProfileThird = tmp;
        }
    } else {
        if (mProfiles != null) {
            ArrayList<IProfile> previousActiveProfiles = new ArrayList<>(Arrays.asList(mCurrentProfile, mProfileFirst, mProfileSecond, mProfileThird));
            if (previousActiveProfiles.contains(newSelection)) {
                int position = -1;
                for (int i = 0; i < 4; i++) {
                    if (previousActiveProfiles.get(i) == newSelection) {
                        position = i;
                        break;
                    }
                }
                if (position != -1) {
                    previousActiveProfiles.remove(position);
                    previousActiveProfiles.add(0, newSelection);
                    mCurrentProfile = previousActiveProfiles.get(0);
                    mProfileFirst = previousActiveProfiles.get(1);
                    mProfileSecond = previousActiveProfiles.get(2);
                    mProfileThird = previousActiveProfiles.get(3);
                }
            } else {
                mProfileThird = mProfileSecond;
                mProfileSecond = mProfileFirst;
                mProfileFirst = mCurrentProfile;
                mCurrentProfile = newSelection;
            }
        }
    }
    //if we only show the small profile images we have to make sure the first (would be the current selected) profile is also shown
    if (mOnlySmallProfileImagesVisible) {
        mProfileThird = mProfileSecond;
        mProfileSecond = mProfileFirst;
        mProfileFirst = mCurrentProfile;
    //mCurrentProfile = mProfileThird;
    }
    buildProfiles();
    return false;
}
Also used : ArrayList(java.util.ArrayList) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile)

Example 14 with IProfile

use of com.mikepenz.materialdrawer.model.interfaces.IProfile in project MaterialDrawer by mikepenz.

the class AccountHeaderBuilder method onProfileImageClick.

/**
     * calls the mOnAccountHEaderProfileImageListener and continues with the actions afterwards
     *
     * @param v
     * @param current
     */
private void onProfileImageClick(View v, boolean current) {
    IProfile profile = (IProfile) v.getTag(R.id.material_drawer_profile_header);
    boolean consumed = false;
    if (mOnAccountHeaderProfileImageListener != null) {
        consumed = mOnAccountHeaderProfileImageListener.onProfileImageClick(v, profile, current);
    }
    //if the event was already consumed by the click don't continue. note that this will also stop the profile change event
    if (!consumed) {
        onProfileClick(v, current);
    }
}
Also used : IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile)

Example 15 with IProfile

use of com.mikepenz.materialdrawer.model.interfaces.IProfile in project Weather by Sparker0i.

the class WeatherActivity method initDrawer.

public void initDrawer() {
    final Context context = this;
    final IProfile profile = new ProfileDrawerItem().withName(getString(R.string.app_name)).withEmail(getString(R.string.drawer_version_header) + " : " + BuildConfig.VERSION_NAME).withIcon(R.mipmap.ic_launcher_x);
    AccountHeader headerResult = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header).withTextColor(ContextCompat.getColor(this, R.color.md_amber_400)).addProfiles(profile).withSelectionListEnabled(false).withProfileImagesClickable(false).build();
    SecondaryDrawerItem item1 = new SecondaryDrawerItem().withIdentifier(1).withName(R.string.drawer_item_home).withIcon(new IconicsDrawable(this).icon(WeatherIcons.Icon.wic_day_sunny));
    SecondaryDrawerItem item2 = new SecondaryDrawerItem().withIdentifier(2).withName(R.string.drawer_item_graph).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_trending_up));
    SecondaryDrawerItem item3 = new SecondaryDrawerItem().withIdentifier(3).withName(R.string.drawer_item_map).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_map));
    SecondaryDrawerItem item7 = new SecondaryDrawerItem().withIdentifier(7).withName(R.string.drawer_item_about).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_info)).withSelectable(false);
    SecondaryDrawerItem item6 = new SecondaryDrawerItem().withIdentifier(6).withName(getString(R.string.drawer_item_custom_key)).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_create)).withSelectable(false);
    SecondarySwitchDrawerItem item4 = new SecondarySwitchDrawerItem().withIdentifier(4).withName(getString(R.string.drawer_item_fahrenheit)).withChecked(preferences.getUnits().equals(Constants.IMPERIAL)).withIcon(new IconicsDrawable(this).icon(WeatherIcons.Icon.wic_fahrenheit)).withSelectable(false);
    SecondarySwitchDrawerItem item5 = new SecondarySwitchDrawerItem().withIdentifier(5).withName(getString(R.string.drawer_item_notifications)).withChecked(preferences.getNotifs()).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_notifications)).withSelectable(false);
    item4.withOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(IDrawerItem drawerItem, CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                preferences.setUnits(Constants.IMPERIAL);
            } else {
                preferences.setUnits(Constants.METRIC);
            }
            Fragment f = getSupportFragmentManager().findFragmentById(R.id.fragment);
            if (f instanceof WeatherFragment) {
                wf = new WeatherFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
                drawer.closeDrawer();
            }
        }
    });
    item5.withOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(IDrawerItem drawerItem, CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                preferences.setNotifs(true);
                startService(new Intent(context, AlarmTriggerService.class));
            } else {
                preferences.setNotifs(false);
                stopService(new Intent(context, AlarmTriggerService.class));
                mManager.cancelAll();
            }
        }
    });
    drawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withSelectedItem(1).withTranslucentStatusBar(true).withAccountHeader(headerResult).withActionBarDrawerToggleAnimated(true).addDrawerItems(item1, item2, item3, new DividerDrawerItem(), item4, item5, new DividerDrawerItem(), item6, item7).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            // do something with the clicked item :D
            if (drawerItem != null) {
                switch((int) drawerItem.getIdentifier()) {
                    case 1:
                        Fragment f = getSupportFragmentManager().findFragmentById(R.id.fragment);
                        if (!(f instanceof WeatherFragment)) {
                            wf = new WeatherFragment();
                            getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
                        }
                        break;
                    case 2:
                        f = getSupportFragmentManager().findFragmentById(R.id.fragment);
                        if (!(f instanceof GraphsFragment)) {
                            GraphsFragment graphsFragment = newGraphInstance(new ArrayList<>(wf.getDailyJson()));
                            getSupportFragmentManager().beginTransaction().replace(R.id.fragment, graphsFragment).commit();
                        }
                        break;
                    case 3:
                        f = getSupportFragmentManager().findFragmentById(R.id.fragment);
                        if (!(f instanceof MapsFragment)) {
                            MapsFragment mapsFragment = new MapsFragment();
                            getSupportFragmentManager().beginTransaction().replace(R.id.fragment, mapsFragment).commit();
                        }
                        break;
                    case 6:
                        showApiKeyBox();
                        break;
                    case 7:
                        startActivity(new Intent(WeatherActivity.this, AboutActivity.class));
                        break;
                }
            }
            return false;
        }
    }).build();
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) ArrayList(java.util.ArrayList) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) WeatherFragment(com.a5corp.weather.fragment.WeatherFragment) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) GraphsFragment(com.a5corp.weather.fragment.GraphsFragment) Fragment(android.support.v4.app.Fragment) MapsFragment(com.a5corp.weather.fragment.MapsFragment) WeatherFragment(com.a5corp.weather.fragment.WeatherFragment) AccountHeader(com.mikepenz.materialdrawer.AccountHeader) MapsFragment(com.a5corp.weather.fragment.MapsFragment) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) Context(android.content.Context) OnCheckedChangeListener(com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener) Intent(android.content.Intent) Drawer(com.mikepenz.materialdrawer.Drawer) BindView(butterknife.BindView) View(android.view.View) SecondarySwitchDrawerItem(com.mikepenz.materialdrawer.model.SecondarySwitchDrawerItem) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) CompoundButton(android.widget.CompoundButton) GraphsFragment(com.a5corp.weather.fragment.GraphsFragment)

Aggregations

IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)15 View (android.view.View)10 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)9 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)9 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)9 IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)9 ProfileDrawerItem (com.mikepenz.materialdrawer.model.ProfileDrawerItem)8 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)7 Toolbar (android.support.v7.widget.Toolbar)6 SectionDrawerItem (com.mikepenz.materialdrawer.model.SectionDrawerItem)6 Drawer (com.mikepenz.materialdrawer.Drawer)5 DividerDrawerItem (com.mikepenz.materialdrawer.model.DividerDrawerItem)5 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)4 BadgeStyle (com.mikepenz.materialdrawer.holder.BadgeStyle)4 ProfileSettingDrawerItem (com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem)4 Nameable (com.mikepenz.materialdrawer.model.interfaces.Nameable)4 Intent (android.content.Intent)3 SwitchDrawerItem (com.mikepenz.materialdrawer.model.SwitchDrawerItem)3 ToggleDrawerItem (com.mikepenz.materialdrawer.model.ToggleDrawerItem)3 ArrayList (java.util.ArrayList)3