com.mikepenz.materialdrawer.model.interfaces.IProfile Java Examples

The following examples show how to use com.mikepenz.materialdrawer.model.interfaces.IProfile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccountHeaderBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 6 votes vote down vote up
/**
 * a small helper to handle the selectionView
 *
 * @param on
 */
private void handleSelectionView(IProfile profile, boolean on) {
    if (on) {
        if (Build.VERSION.SDK_INT >= 21) {
            ((FrameLayout) mAccountHeaderContainer).setForeground(UIUtils.getCompatDrawable(mAccountHeaderContainer.getContext(), mAccountHeaderTextSectionBackgroundResource));
            mAccountHeaderContainer.setOnClickListener(onSelectionClickListener);
            mAccountHeaderContainer.setTag(R.id.material_drawer_profile_header, profile);
        } else {
            mAccountHeaderTextSection.setBackgroundResource(mAccountHeaderTextSectionBackgroundResource);
            mAccountHeaderTextSection.setOnClickListener(onSelectionClickListener);
            mAccountHeaderTextSection.setTag(R.id.material_drawer_profile_header, profile);
        }
    } else {
        if (Build.VERSION.SDK_INT >= 21) {
            ((FrameLayout) mAccountHeaderContainer).setForeground(null);
            mAccountHeaderContainer.setOnClickListener(null);
        } else {
            UIUtils.setBackground(mAccountHeaderTextSection, null);
            mAccountHeaderTextSection.setOnClickListener(null);
        }
    }
}
 
Example #2
Source File: AccountHeaderBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 6 votes vote down vote up
/**
 * 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 = position + mDrawer.getAdapter().getHeaderOffset();
                }
            }
            if (profile instanceof IDrawerItem) {
                ((IDrawerItem) profile).withSetSelected(false);
                profileDrawerItems.add((IDrawerItem) profile);
            }
            position = position + 1;
        }
    }
    mDrawer.switchDrawerContent(onDrawerItemClickListener, onDrawerItemLongClickListener, profileDrawerItems, selectedPosition);
}
 
Example #3
Source File: MiniDrawer.java    From MaterialDrawer-Xamarin with Apache License 2.0 6 votes vote down vote up
/**
 * call this method to trigger the onProfileClick on the MiniDrawer
 */
public void onProfileClick() {
    //crossfade if we are cross faded
    if (mCrossFader != null) {
        if (mCrossFader.isCrossfaded()) {
            mCrossFader.crossfade();
        }
    }

    //update the current profile
    if (mAccountHeader != null) {
        IProfile profile = mAccountHeader.getActiveProfile();
        if (profile instanceof IDrawerItem) {
            mDrawerAdapter.setDrawerItem(0, generateMiniDrawerItem((IDrawerItem) profile));
        }
    }
}
 
Example #4
Source File: AccountHeaderBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 6 votes vote down vote up
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());

    boolean consumed = false;
    if (mOnAccountHeaderListener != null) {
        consumed = mOnAccountHeaderListener.onProfileChanged(v, profile, current);
    }

    if (!consumed) {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (mDrawer != null) {
                    mDrawer.closeDrawer();
                }
            }
        }, 200);
    }
}
 
Example #5
Source File: MainActivity.java    From IdeaTrackerPlus with MIT License 6 votes vote down vote up
/**
 * After project deletion, selects another project
 *
 * @param index the index of the deleted project
 */
private void switchToExistingProject(int index) {
    index -= 1;
    boolean inBounds = (index >= 0) && (index < mProfiles.size());

    if (!mNoProject) {

        if (inBounds) mSelectedProfileIndex = index;
        else mSelectedProfileIndex = 0;

        IProfile profileToSelect = mProfiles.get(mSelectedProfileIndex);
        String tableToSelect = profileToSelect.getName().getText();
        header.setActiveProfile(profileToSelect);
        mToolbar.setTitle(tableToSelect);
        mDbHelper.switchTable(tableToSelect);
        displayIdeasCount();

        switchToProjectColors();
    }

}
 
Example #6
Source File: MainActivity.java    From IdeaTrackerPlus with MIT License 6 votes vote down vote up
private void switchToProject(String projectName) {

        mSelectedProfileIndex = getIndexOfProject(projectName);
        IProfile profileToSelect = mProfiles.get(mSelectedProfileIndex);
        header.setActiveProfile(profileToSelect);

        mToolbar.setTitle(projectName);
        mDbHelper.switchTable(projectName);
        DatabaseHelper.notifyAllLists();
        displayIdeasCount();
        switchToProjectColors();

        //favorite star
        refreshStar();

        //search mode
        disableSearchMode();
    }
 
Example #7
Source File: MainActivity.java    From IdeaTrackerPlus with MIT License 6 votes vote down vote up
private void selectFavoriteProject() {

        if (!mNoProject) {
            mSelectedProfileIndex = getIndexOfFavorite();
            IProfile activeProfile = mProfiles.get(mSelectedProfileIndex);
            String activeProfileName = activeProfile.getName().getText();

            ActionBar bar;
            if ((bar = getSupportActionBar()) != null) {
                bar.setTitle(activeProfileName);
            }

            DataEntry.setTableName(activeProfileName);

            switchToProjectColors();
        }
    }
 
Example #8
Source File: MainViewModel.java    From hacker-news-android with Apache License 2.0 6 votes vote down vote up
IProfile[] getLoggedInProfileItem() {
    if (mLoggedInProfiles == null) {
        mLoggedInProfiles = new IProfile[2];
        User currentUser = Select.from(User.class).first();
        ProfileDrawerItem profileDrawerItem = new ProfileDrawerItem().withIdentifier(LOGGED_IN_PROFILE_ITEM)
                                                                     .withIcon(TextDrawable.builder()
                                                                                           .buildRound(String.valueOf(currentUser.getUserName().charAt(0)),
                                                                                                       mResources.getColor(R.color.colorPrimaryDark)))
                                                                     .withName(currentUser.getUserName());
        ProfileSettingDrawerItem logoutDrawerItem = new ProfileSettingDrawerItem().withIdentifier(LOG_OUT_PROFILE_ITEM)
                                                                                  .withName("Logout")
                                                                                  .withDescription("Logout of current account")
                                                                                  .withIcon(mResources.getDrawable(R.drawable.ic_close));

        mLoggedInProfiles[0] = profileDrawerItem;
        mLoggedInProfiles[1] = logoutDrawerItem;
    }

    return mLoggedInProfiles;
}
 
Example #9
Source File: AccountHeaderBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (mOnAccountHeaderProfileImageListener != null) {
        IProfile profile = (IProfile) v.getTag(R.id.material_drawer_profile_header);
        return mOnAccountHeaderProfileImageListener.onProfileImageLongClick(v, profile, true);
    }
    return false;
}
 
Example #10
Source File: AccountHeaderBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #11
Source File: AccountHeaderBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (mOnAccountHeaderProfileImageListener != null) {
        IProfile profile = (IProfile) v.getTag(R.id.material_drawer_profile_header);
        return mOnAccountHeaderProfileImageListener.onProfileImageLongClick(v, profile, false);
    }
    return false;
}
 
Example #12
Source File: AccountHeaderBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * add single ore more DrawerItems to the Drawer
 *
 * @param profiles
 * @return
 */
public AccountHeaderBuilder addProfiles(@NonNull IProfile... profiles) {
    if (this.mProfiles == null) {
        this.mProfiles = new ArrayList<>();
    }

    Collections.addAll(this.mProfiles, IdDistributor.checkIds(profiles));

    return this;
}
 
Example #13
Source File: AccountHeaderBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * get the current selection
 *
 * @return
 */
protected int getCurrentSelection() {
    if (mCurrentProfile != null && mProfiles != null) {
        int i = 0;
        for (IProfile profile : mProfiles) {
            if (profile == mCurrentProfile) {
                return i;
            }
            i++;
        }
    }
    return -1;
}
 
Example #14
Source File: AccountHeaderBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    boolean consumed = false;
    if (mOnAccountHeaderSelectionViewClickListener != null) {
        consumed = mOnAccountHeaderSelectionViewClickListener.onClick(v, (IProfile) v.getTag(R.id.material_drawer_profile_header));
    }

    if (mAccountSwitcherArrow.getVisibility() == View.VISIBLE && !consumed) {
        toggleSelectionList(v.getContext());
    }
}
 
Example #15
Source File: HomeActivity.java    From wmn-safety with MIT License 5 votes vote down vote up
public void updateProfile() {
    IProfile profile = new ProfileDrawerItem().withName(mFullName)
            .withTextColor(getResources().getColor(android.R.color.black))
            .withEmail(mEmail).withIcon(R.mipmap.ic_launcher)
            .withIdentifier(100);
    headerResult.updateProfile(profile);
}
 
Example #16
Source File: AccountHeader.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new profile at a specific position to the list
 *
 * @param profile
 * @param position
 */
public void addProfile(@NonNull IProfile profile, int position) {
    if (mAccountHeaderBuilder.mProfiles == null) {
        mAccountHeaderBuilder.mProfiles = new ArrayList<>();
    }
    mAccountHeaderBuilder.mProfiles.add(position, IdDistributor.checkId(profile));

    mAccountHeaderBuilder.updateHeaderAndList();
}
 
Example #17
Source File: AccountHeader.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * Add new profiles to the existing list of profiles
 *
 * @param profiles
 */
public void addProfiles(@NonNull IProfile... profiles) {
    if (mAccountHeaderBuilder.mProfiles == null) {
        mAccountHeaderBuilder.mProfiles = new ArrayList<>();
    }

    Collections.addAll(mAccountHeaderBuilder.mProfiles, IdDistributor.checkIds(profiles));

    mAccountHeaderBuilder.updateHeaderAndList();
}
 
Example #18
Source File: AccountHeader.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to update a profile using it's identifier
 *
 * @param newProfile
 */
@Deprecated
public void updateProfileByIdentifier(@NonNull IProfile newProfile) {
    int found = getPositionByIdentifier(newProfile.getIdentifier());
    if (found > -1) {
        mAccountHeaderBuilder.mProfiles.set(found, newProfile);
        mAccountHeaderBuilder.updateHeaderAndList();
    }
}
 
Example #19
Source File: AccountHeaderBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onItemClick(final View view, int position, final IDrawerItem drawerItem) {
    final boolean isCurrentSelectedProfile;
    if (drawerItem != null && drawerItem instanceof IProfile && drawerItem.isSelectable()) {
        isCurrentSelectedProfile = switchProfiles((IProfile) drawerItem);
    } else {
        isCurrentSelectedProfile = false;
    }

    if (mResetDrawerOnProfileListClick) {
        mDrawer.setOnDrawerItemClickListener(null);
    }

    //wrap the onSelection call and the reset stuff within a handler to prevent lag
    if (mResetDrawerOnProfileListClick && mDrawer != null && view != null && view.getContext() != null) {
        resetDrawerContent(view.getContext());
    }

    boolean consumed = false;
    if (drawerItem != null && drawerItem instanceof IProfile) {
        if (mOnAccountHeaderListener != null) {
            consumed = mOnAccountHeaderListener.onProfileChanged(view, (IProfile) drawerItem, isCurrentSelectedProfile);
        }
    }

    //if a custom behavior was chosen via the CloseDrawerOnProfileListClick then use this. else react on the result of the onProfileChanged listener
    if (mCloseDrawerOnProfileListClick != null) {
        return !mCloseDrawerOnProfileListClick;
    } else {
        return consumed;
    }
}
 
Example #20
Source File: AccountHeaderBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onItemLongClick(View view, int position, IDrawerItem drawerItem) {
    //if a longClickListener was defined use it
    if (mOnAccountHeaderItemLongClickListener != null) {
        final boolean isCurrentSelectedProfile;
        isCurrentSelectedProfile = drawerItem != null && drawerItem.isSelected();

        if (drawerItem != null && drawerItem instanceof IProfile) {
            return mOnAccountHeaderItemLongClickListener.onProfileLongClick(view, (IProfile) drawerItem, isCurrentSelectedProfile);
        }
    }
    return false;
}
 
Example #21
Source File: AccountHeader.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * Selects a profile by its identifier
 *
 * @param identifier
 */
public void setActiveProfile(int identifier, boolean fireOnProfileChanged) {
    if (mAccountHeaderBuilder.mProfiles != null) {
        for (IProfile profile : mAccountHeaderBuilder.mProfiles) {
            if (profile != null) {
                if (profile.getIdentifier() == identifier) {
                    setActiveProfile(profile, fireOnProfileChanged);
                    return;
                }
            }
        }
    }
}
 
Example #22
Source File: AccountHeader.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * Selects the given profile and sets it to the new active profile
 *
 * @param profile
 */
public void setActiveProfile(IProfile profile, boolean fireOnProfileChanged) {
    final boolean isCurrentSelectedProfile = mAccountHeaderBuilder.switchProfiles(profile);
    //if the selectionList is shown we should also update the current selected profile in the list
    if (mAccountHeaderBuilder.mDrawer != null && isSelectionListShown()) {
        mAccountHeaderBuilder.mDrawer.setSelection(profile.getIdentifier(), false);
    }
    //fire the event if enabled and a listener is set
    if (fireOnProfileChanged && mAccountHeaderBuilder.mOnAccountHeaderListener != null) {
        mAccountHeaderBuilder.mOnAccountHeaderListener.onProfileChanged(null, profile, isCurrentSelectedProfile);
    }
}
 
Example #23
Source File: MainActivity.java    From IdeaTrackerPlus with MIT License 5 votes vote down vote up
private void resetColorsDialog() {
    new LovelyStandardDialog(this, mDarkTheme ? android.support.v7.appcompat.R.style.Theme_AppCompat_Dialog_Alert : 0)
            .setTopColor(mPrimaryColor)
            .setButtonsColorRes(R.color.md_pink_a200)
            .setIcon(R.drawable.ic_drop)
            .setTitle(R.string.reset_color_prefs)
            .setMessage(R.string.reset_color_pref_message)
            .setPositiveButton(android.R.string.yes, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mPrimaryColor = defaultPrimaryColor;
                    mSecondaryColor = defaultSecondaryColor;
                    mTextColor = defaultTextColor;
                    saveProjectColors();
                    updateColors();

                    //change project icon
                    Drawable disk = ContextCompat.getDrawable(getApplicationContext(), R.drawable.disk);
                    disk.setColorFilter(mPrimaryColor, PorterDuff.Mode.SRC_ATOP);
                    IProfile p = header.getActiveProfile();
                    p.withIcon(disk);
                    header.updateProfile(p);
                }
            })
            .setNegativeButton(android.R.string.no, null)
            .show();
}
 
Example #24
Source File: MainViewModel.java    From hacker-news-android with Apache License 2.0 5 votes vote down vote up
IProfile[] getLoggedOutProfileItem() {
    if (mLoggedOutProfileItems == null) {
        mLoggedOutProfileItems = new IProfile[1];
        ProfileSettingDrawerItem profileAddAccountItem = new ProfileSettingDrawerItem().withIdentifier(ADD_ACCOUNT_PROFILE_ITEM)
                                                                                       .withName(mResources.getString(R.string.nav_drawer_login))
                                                                                       .withDescription(mResources.getString(R.string.nav_drawer_add_an_account))
                                                                                       .withIcon(mResources.getDrawable(R.drawable.ic_add));
        mLoggedOutProfileItems[0] = profileAddAccountItem;
    }
    return mLoggedOutProfileItems;
}
 
Example #25
Source File: LeftDrawerManager.java    From timecat with Apache License 2.0 5 votes vote down vote up
private IProfile createProfile(DBUser u) {
    return new ProfileDrawerItem()
            .withIdentifier(u.id().intValue())
            .withName(u.name())
            .withEmail(u.getEmail())
            .withIcon(AvatarManager.res(u.avatar()));
}
 
Example #26
Source File: MiniDrawer.java    From MaterialDrawer-Xamarin with Apache License 2.0 4 votes vote down vote up
/**
 * creates the items for the MiniDrawer
 */
public void createItems() {
    mDrawerAdapter.clearDrawerItems();

    if (mAccountHeader != null) {
        IProfile profile = mAccountHeader.getActiveProfile();
        if (profile instanceof IDrawerItem) {
            mDrawerAdapter.addDrawerItem(generateMiniDrawerItem((IDrawerItem) profile));
        }
    }

    if (mDrawer != null) {
        if (getDrawerItems() != null) {
            //migrate to miniDrawerItems
            for (IDrawerItem drawerItem : getDrawerItems()) {
                IDrawerItem miniDrawerItem = generateMiniDrawerItem(drawerItem);
                if (miniDrawerItem != null) {
                    mDrawerAdapter.addDrawerItem(miniDrawerItem);
                }
            }
        }
    }

    //listener
    if (mOnMiniDrawerItemClickListener != null) {
        mDrawerAdapter.setOnClickListener(mOnMiniDrawerItemClickListener);
    } else {
        mDrawerAdapter.setOnClickListener(new BaseDrawerAdapter.OnClickListener() {
            @Override
            public void onClick(View v, int position, IDrawerItem item) {
                int type = getMiniDrawerType(item);
                if (type == ITEM) {
                    //fire the onClickListener also if the specific drawerItem is not Selectable
                    if (item.isSelectable()) {
                        //make sure we are on the original drawerItemList
                        if (mAccountHeader != null && mAccountHeader.isSelectionListShown()) {
                            mAccountHeader.toggleSelectionList(v.getContext());
                        }
                        //set the selection
                        mDrawer.setSelection(item, true);
                    } else if (mDrawer.getOnDrawerItemClickListener() != null) {
                        //get the original `DrawerItem` from the Drawer as this one will contain all information
                        mDrawer.getOnDrawerItemClickListener().onItemClick(v, position, DrawerUtils.getDrawerItem(getDrawerItems(), item.getIdentifier()));
                    }
                } else if (type == PROFILE) {
                    if (mAccountHeader != null && !mAccountHeader.isSelectionListShown()) {
                        mAccountHeader.toggleSelectionList(v.getContext());
                    }
                    if (mCrossFader != null) {
                        mCrossFader.crossfade();
                    }
                }
            }
        });
    }
    mDrawerAdapter.setOnLongClickListener(mOnMiniDrawerItemLongClickListener);
    mRecyclerView.scrollToPosition(0);
}
 
Example #27
Source File: MainFrameActivity.java    From hipda with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean onProfileImageLongClick(View view, IProfile profile, boolean current) {
    return false;
}
 
Example #28
Source File: MainViewModel.java    From hacker-news-android with Apache License 2.0 4 votes vote down vote up
IProfile[] getProfileItems(){
    return isLoggedIn() ? getLoggedInProfileItem() : getLoggedOutProfileItem();
}
 
Example #29
Source File: LeftDrawerManager.java    From timecat with Apache License 2.0 4 votes vote down vote up
public void onUserCreated(DBUser u) {

        IProfile profile = createProfile(u);
        headerResult.addProfiles(profile);
    }
 
Example #30
Source File: AccountHeaderBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
            }
        }
    }

    buildProfiles();

    return false;
}