GithubHelp home page GithubHelp logo

androidnavigator's Introduction

Build Status

AndroidNavigation

Use POJOs instead of Activities and/or Fragments to handle the different screens of an app!

  • Pojo will survive across configuration changes.
  • Useful for fast app prototyping.
  • AndroidNavigation users ButterKnife for injecting views.

2 Steps Usage

Create an instance of Screen:

public class FirstScreen extends Screen {

    private static final String TAG = FirstScreen.class.getSimpleName();

    /*
     * View injection with ButterKnife.
     * Injected views will be automatically removed and re-injected on configuration changes
     */
    @InjectView(R.id.text1) protected TextView mTextView1;
    @InjectView(R.id.text2) protected TextView mTextView2;

    protected int mCounter;
    private String mSampleString = "a sample string";

    @Override
    public void afterViewInjection(View view) {
        // here views have been injected

        mTextView1.setText("afterViewInjection: " + (++mCounter));

        mTextView2.setText(mSampleString);
    }

    @Override
    public int getLayoutId() {
        // the layout resource for this screen
        return R.layout.first_screen_layout;
    }

    @Override
    public String getId() {
        // return and identifier for this screen
        return TAG;
    }

    @OnClick(R.id.btn_go_to_second_screen)
    public void onButtonClicked(View v) {
        // go to another screen
        getNavigator().goTo(new SecondScreen());
    }
}

Create an Activity with an instance of Navigator:

public class MainActivity extends AppCompatActivity {

    private Navigator mNavigator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mNavigator = Navigator.getInstanceFor(this);
        mNavigator.setContainerResId(R.id.container); // id of FrameLayout that will act as fragment container
        mNavigator.setActionBar(getSupportActionBar());

        mNavigator.goTo(new FirstScreen());
    }

    @Override
    public void onBackPressed() {
        if(!mNavigator.onBackPressed()) {
            super.onBackPressed();
        }
    }
}

androidnavigator's People

Contributors

techisfun avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.