Code Monkey home page Code Monkey logo

breadcrumbsview's Introduction

BreadcrumbsView

中文说明

Material Design Breadcrumbs Navigation Widget on Android (SDK 19+, Maybe can be lower)

How to use

Import (Gradle)

First, add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Add the dependency to your app modules:

dependencies {
    compile 'moe.feng:BreadcrumbsView:latest-version'
}

XML

Place a BreadcrumbsView to where you want in your layout xml.

For example:

<android.support.design.widget.AppBarLayout...>

	<android.support.v7.widget.Toolbar.../>

	<moe.feng.common.view.breadcrumbs.BreadcrumbsView
		android:id="@+id/breadcrumbs_view"
		android:layout_width="match_parent"
		android:layout_height="?attr/actionBarSize"
		app:popupTheme="@style/AppTheme.PopupOverlay"/>

</android.support.design.widget.AppBarLayout>

Add/Remove BreadcrumbItem

When your interface navigates to next step, create a new BreadcrumbItem and add it to BreadcrumbsView. (After 0.2.0, you can implement your own IBreadcrumbItem to use.)

Use removeItemAfter(int) or removeLastItem to remove items or last item.

Listen events

You can set a callback for BreadcrumbsView to receive item click/changed events.

To simplify events, I recommend to use DefaultBreadcrumbsCallback :

new DefaultBreadcrumbsCallback<BreadcrumbItem>() {
	@Override
	public void onNavigateBack(BreadcrumbItem item, int position) {
		// ...
	}

	@Override
	public void onNavigateNewLocation(BreadcrumbItem newItem, int changedPosition) {
		// ...
	}
}

License

MIT License

Copyright (c) 2017-2018 Fung Go (fython)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

breadcrumbsview's People

Contributors

fython avatar mflisar avatar pigcasso avatar swordfish90 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

breadcrumbsview's Issues

Sync BreadcrumbView items with app back stack history

Hi!
I am currently using fragments that replace the data elements on an activity and I am having a hard time keeping the app back stack "history" in-sync with BreadcrumbView.

For example:
Lets say, I have 4 fragments - A, B, C & D of the order below. All these fragments have a RecyclerView list items with onClick listeners that use a pushFragment() method which replaces Fragment accordingly.

Fragment order:
A->B->C->D

Problem:
If I click on B fragment, the BreadcrumbsView updates properly however the app back stack history still persists!
So, when a user taps Back button, he still goes to C fragment`.

I believe this could be an issue with my implementation.

Some code:

public static void pushFragment(AppCompatActivity activity, Fragment fragment) {
        int holder =  R.id.content_view_module_details_activity;
        FragmentManager fragmentManager = activity.getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager
                .beginTransaction()
                .addToBackStack(null);
        fragmentTransaction.replace(holder, fragment,
                fragment.getClass().toString());
        fragmentTransaction.commit();
    }

public void handleItemClick(View view, ClassModel m) {
        // Get current list of items
        List<IBreadcrumbItem> items = breadcrumbsView.getItems();
       // Create a new BreadcrumbItem
        ArrayList<String> list = new ArrayList<>();
        list.add(m.getTitle());
        BreadcrumbItem breadcrumbItem = new BreadcrumbItem(list);
        breadcrumbItem.setSelectedItem(m.getTitle());
        items.add(breadcrumbItem);
        breadcrumbsView.setItems(items);
        // Set data model on rootActivity
        rootActivity.setClassModel(m);
        // Goto Subjects view                          <-  goes to Fragment B
        Utils.pushFragment(rootActivity, new SubjectsListFragment());
    }

ClassCastException

Caused by: java.lang.ClassCastException: android.view.View$BaseSavedState cannot be cast to moe.feng.common.view.breadcrumbs.BreadcrumbsView$State
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at moe.feng.common.view.breadcrumbs.BreadcrumbsView.onRestoreInstanceState(BreadcrumbsView.java:210)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at android.view.View.dispatchRestoreInstanceState(View.java:17706)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3745)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3751)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3751)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3751)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3751)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3751)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at android.view.View.restoreHierarchyState(View.java:17684)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2131)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at android.app.Activity.onRestoreInstanceState(Activity.java:1103)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at android.app.Activity.performRestoreInstanceState(Activity.java:1058)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1260)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
12-04 17:30:09.092 10096 10096 E AndroidRuntime: ... 9 more

关于颜色、字号请教

hello hello,请问项目中,颜色、字号等,在我通过gradle引用,是不是就不支持修改了?可以对外暴露个方法呢?谢谢

API level 19 not supported

You have wrong information about your supported API levels. API level 19 does not work and crashes during runtime cause you're using the "android:tint" attribute for example in "breadcrumbs_view_item_arrow.xml".

Problem with setItems(), addItem() and unmodified list

After putting unmodified list into setItems() method, when you try to invoke addItem() method you get reasonable java.lang.UnsupportedOperationException. It would be nice to create a new list inside setItems() method.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.