topalbu / android-binding

Automatically exported from code.google.com/p/android-binding
0 stars 0 forks source link

Any plans to integrate IoC (like roboguice) in your code-base? #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, 

This is a great library, and thank you for coming up with one like this!!!

Do you have any plans to integrate or develop an IoC container (similar or 
better than http://code.google.com/p/roboguice/)?

Thanks
SK

Original issue reported on code.google.com by shivkuma...@gmail.com on 5 Jun 2011 at 1:43

GoogleCodeExporter commented 9 years ago
What particular issue if using RoboGuice with Android Binding you encountered? 
I haven't really tried that out, but if that works with AB, then there's no 
point to develop my own. 

Original comment by gueei....@gmail.com on 25 Jun 2011 at 6:10

GoogleCodeExporter commented 9 years ago
RoboGuice works fine. You have to merge BindingActivity + RoboGuice Activity to 
your own base activity.

Original comment by egandro on 30 Dec 2011 at 9:09

GoogleCodeExporter commented 9 years ago
Add the following JARs to your project:

android-support-v4.jar, guice-3.0-no_aop.jar, javax.inject.jar, 
roboguice-2.0b3.jar (check the roboguice homepage for more informations).

Also add the androidbinding.jar for our framework.

This is the RoboActivity:

http://code.google.com/p/roboguice/source/browse/roboguice/src/main/java/robogui
ce/activity/RoboActivity.java

-- RoboBindingActivity.java -- (is derived from BindingActivity - instead of 
the android Activity).

public class RoboBindingActivity extends BindingActivity {
    protected EventManager eventManager;

    @Inject ContentViewListener ignored; // BUG find a better place to put this

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        final RoboInjector injector = RoboGuice.getInjector(this);
        eventManager = injector.getInstance(EventManager.class);
        injector.injectMembersWithoutViews(this);
        super.onCreate(savedInstanceState);
        eventManager.fire(new OnCreateEvent(savedInstanceState));
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        eventManager.fire(new OnRestartEvent());
    }

    @Override
    protected void onStart() {
        super.onStart();
        eventManager.fire(new OnStartEvent());
    }

    @Override
    protected void onResume() {
        super.onResume();
        eventManager.fire(new OnResumeEvent());
    }

    @Override
    protected void onPause() {
        super.onPause();
        eventManager.fire(new OnPauseEvent());
    }

    @Override
    protected void onNewIntent( Intent intent ) {
        super.onNewIntent(intent);
        eventManager.fire(new OnNewIntentEvent());
    }

    @Override
    protected void onStop() {
        try {
            eventManager.fire(new OnStopEvent());
        } finally {
            super.onStop();
        }
    }

    @Override
    protected void onDestroy() {
        try {
            eventManager.fire(new OnDestroyEvent());
        } finally {
            try {
                RoboGuice.destroyInjector(this);
            } finally {
                super.onDestroy();
            }
        }
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        final Configuration currentConfig = getResources().getConfiguration();
        super.onConfigurationChanged(newConfig);
        eventManager.fire(new OnConfigurationChangedEvent(currentConfig, newConfig));
    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
        RoboGuice.getInjector(this).injectViewMembers(this);
        eventManager.fire(new OnContentChangedEvent());
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        eventManager.fire(new OnActivityResultEvent(requestCode, resultCode, data));
    }
}

Original comment by egandro on 2 Jan 2012 at 8:30

GoogleCodeExporter commented 9 years ago

Original comment by gueei....@gmail.com on 3 Jan 2012 at 1:57

GoogleCodeExporter commented 9 years ago
Great! Thanks so much!!!

Original comment by shivkuma...@gmail.com on 6 Jan 2012 at 3:18