Created
October 2, 2013 13:48
-
-
Save mLupine/6794081 to your computer and use it in GitHub Desktop.
View controller template used in the upcoming version of Quick Social. Extremely useful stuff. Usage example: [...]
viewController = new BlahBlahController(view, getActivity());
viewController.addExtraField(type);
viewController.initWithBundle(shareBundle); LICENSE: LGPL v2.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cc.lupine.quicksocial.controllers; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.view.View; | |
public class Controller { | |
/** | |
* Controlled view | |
*/ | |
private View v; | |
/** | |
* View's parent activity | |
*/ | |
private Activity mActivity; | |
/** | |
* Bundle containing controller's data | |
*/ | |
private Bundle mBundle; | |
/** | |
* Extra data object | |
*/ | |
private Object extra; | |
/** | |
* Constructor | |
* | |
* @param view | |
* The view to control | |
* @param activity | |
* View's parent activity | |
*/ | |
public Controller(View view, Activity activity) { | |
v = view; | |
mActivity = activity; | |
} | |
/** | |
* Private function for initializing the controller class | |
* | |
* @param bundle | |
* Bundle to init with | |
* @param object | |
* Extra field with data necessary to init | |
*/ | |
private void init(Bundle bundle, Object object) { | |
mBundle = bundle; | |
extra = object; | |
// Start controlling the view here | |
} | |
/** | |
* Public wrapper for {@link #init(Bundle, Object)} for initializing an | |
* empty controller | |
*/ | |
public void initWithNothing() { | |
this.init(new Bundle(), extra); | |
} | |
/** | |
* Public wrapper for {@link #init(Bundle, Object)} for initializing a | |
* controller with bundle | |
* | |
* @param bundle | |
* Data bundle | |
*/ | |
public void initWithBundle(Bundle bundle) { | |
this.init(bundle, extra); | |
} | |
/** | |
* Add an extra field to the controller before the actual init | |
* | |
* @param field | |
*/ | |
public void addExtraField(Object field) { | |
this.extra = field; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment