-
Notifications
You must be signed in to change notification settings - Fork 1
Use Cases
edolganov edited this page May 1, 2013
·
10 revisions
- Setup
static {
LogFactory.setTagPrefix("SOME-TAG");
}- Use
Logger log = LogFactory.getLog(getClass());
log.info("some info msg");
log.error("ups error", e);No need of super calls anymore:
import easydroid.core.BaseActivity;
public class YourActivity extends BaseActivity {
@Override
protected void onCreateSafe(Bundle bundle) {
//no need of super.onCreate(bundle)
}
@Override
protected void onDestroySafe() {
//no need of super.onDestroy()
}
}Use @InjectView annotation:
import easydroid.core.BaseActivity;
public class YourActivity extends BaseActivity {
@InjectView(R.id.browser_back)
View backButton;
@InjectView(R.id.browser_home)
View homeButton;
@Override
protected void onCreateSafe(Bundle savedInstanceState) {
setContentView(R.layout.browser);
//access to backButton and homeButton
}
}Use @ContentView instead of setContentView function:
import easydroid.core.BaseActivity;
@ContentView(R.layout.browser)
public class YourActivity extends BaseActivity {
@InjectView(R.id.browser_back)
View backButton;
@InjectView(R.id.browser_home)
View homeButton;
@Override
protected void onCreateSafe(Bundle savedInstanceState) {
//access to backButton and homeButton
}
}- Create Singleton class:
import easydroid.core.Singleton;
import android.content.Context;
public class BrowserState extends Singleton {
//you can inject android context
//and other singletons
@Inject
Context context;
@Inject
OtherSingleton otherSingleton;
}- Use @Inject annotation in Activity:
public class YourActivity extends BaseActivity {
@Inject
BrowserState singletonObj;
@Override
protected void onCreateSafe(Bundle savedInstanceState) {
//access to singletonObj
}
}BaseAsyncTask has flexible API for async work:
public class YourActivity extends BaseActivity {
@Override
protected void onCreateSafe(Bundle savedInstanceState) {
//call execute method
execute(new BaseAsyncTask<UserState>() {
@Override
protected void onPreExecute() {
showLoadindDialog("Loading...");
}
@Override
protected UserState doInBackground() throws Throwable {
return someLongService.getUserState();
}
@Override
protected void beforeResult() {
dismissCreatedDialog();
}
@Override
protected void onSuccess(UserState result) {
showUserState(result);
}
@Override
protected void onFail(Throwable t) {
log.error("ups", t);
}
});
}
private void showUserState(UserState result) { ... }
}- showLoadindDialog
- showOkDialog
- dismissCreatedDialog
- execute (for BaseAsyncTask)
- finishWithOkResult