Skip to content

Instantly share code, notes, and snippets.

@TheLester
Created October 5, 2015 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheLester/003ec8b6310a1b6f9843 to your computer and use it in GitHub Desktop.
Save TheLester/003ec8b6310a1b6f9843 to your computer and use it in GitHub Desktop.
Abstract Activity
public abstract class EffectiveActivity extends AppCompatActivity {
private ViewGroup mainFrame;
private ScreenContainer screenContainer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
screenContainer = createScreenContainer();
mainFrame = screenContainer.bind(this);
getLayoutInflater().inflate(getLayout(), mainFrame);
ButterKnife.bind(this);
}
ScreenContainer createScreenContainer() {
return new ScreenContainerImpl();
}
@NonNull
abstract Integer getLayout();
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
screenContainer.getDrawerLayout().openDrawer(GravityCompat.START);
return true;
}
return super.onOptionsItemSelected(item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment