Android Open Source - NerdRoll Action Bar Owner






From Project

Back to project page NerdRoll.

License

The source code is released under:

Apache License

If you think the Android project NerdRoll listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.bignerdranch.android.nerdroll.android;
/*w  ww  .ja va2  s.c o m*/
import android.content.Context;
import android.os.Bundle;

import mortar.Mortar;
import mortar.MortarScope;
import mortar.Presenter;
import rx.functions.Action0;

/**
 * Allows shared configuration of the Android ActionBar.
 */
public class ActionBarOwner extends Presenter<ActionBarOwner.View> {

    public interface View {

        void setShowHomeEnabled(boolean enabled);

        void setUpButtonEnabled(boolean enabled);

        void setTitle(CharSequence title);

        void setMenu(MenuAction action);

        Context getMortarContext();

    }

    public static class Config {

        public final boolean showHomeEnabled;
        public final boolean upButtonEnabled;
        public final CharSequence title;
        public final MenuAction action;

        public Config(boolean showHomeEnabled, boolean upButtonEnabled, CharSequence title, MenuAction action) {
            this.showHomeEnabled = showHomeEnabled;
            this.upButtonEnabled = upButtonEnabled;
            this.title = title;
            this.action = action;
        }

        public Config withAction(MenuAction action) {
            return new Config(showHomeEnabled, upButtonEnabled, title, action);
        }

    }

    public static class MenuAction {

        public final int title;
        public final int icon;
        public final int flag;
        public final Action0 action;

        public MenuAction(int title, int icon, int flag, Action0 action) {
            this.title = title;
            this.icon = icon;
            this.flag = flag;
            this.action = action;
        }

    }

    private Config config;

    ActionBarOwner() {
    }

    @Override
    public void onLoad(Bundle savedInstanceState) {
        if (config != null) update();
    }

    public void setConfig(Config config) {
        this.config = config;
        update();
    }

    public Config getConfig() {
        return config;
    }

    @Override
    protected MortarScope extractScope(View view) {
        return Mortar.getScope(view.getMortarContext());
    }

    private void update() {
        View view = getView();
        if (view == null) return;

        view.setShowHomeEnabled(config.showHomeEnabled);
        view.setUpButtonEnabled(config.upButtonEnabled);
        view.setTitle(config.title);
        view.setMenu(config.action);
    }

}




Java Source Code List

com.bignerdranch.android.nerdroll.ApplicationTest.java
com.bignerdranch.android.nerdroll.ApplicationTest.java
com.bignerdranch.android.nerdroll.MainActivity.java
com.bignerdranch.android.nerdroll.MainActivity.java
com.bignerdranch.android.nerdroll.MainApplicationModule.java
com.bignerdranch.android.nerdroll.MainApplicationModule.java
com.bignerdranch.android.nerdroll.MainApplication.java
com.bignerdranch.android.nerdroll.MainApplication.java
com.bignerdranch.android.nerdroll.android.ActionBarModule.java
com.bignerdranch.android.nerdroll.android.ActionBarOwner.java
com.bignerdranch.android.nerdroll.controller.DieFragment.java
com.bignerdranch.android.nerdroll.controller.DieListFragment.java
com.bignerdranch.android.nerdroll.model.DieList.java
com.bignerdranch.android.nerdroll.model.DieList.java
com.bignerdranch.android.nerdroll.model.Die.java
com.bignerdranch.android.nerdroll.model.Die.java
com.bignerdranch.android.nerdroll.screen.DieListScreen.java
com.bignerdranch.android.nerdroll.screen.DieScreen.java
com.bignerdranch.android.nerdroll.screen.MainScreen.java
com.bignerdranch.android.nerdroll.util.CanShowScreen.java
com.bignerdranch.android.nerdroll.util.FlowOwner.java
com.bignerdranch.android.nerdroll.util.GsonParcer.java
com.bignerdranch.android.nerdroll.util.MainScope.java
com.bignerdranch.android.nerdroll.util.ScreenConductor.java
com.bignerdranch.android.nerdroll.view.DieListView.java
com.bignerdranch.android.nerdroll.view.DieView.java
com.bignerdranch.android.nerdroll.view.MainView.java