This document will cover the main features of this library. it will be always growing.
The classes named xUtils (MapUtils, DateUtils), contain for now a dozen or so methods that i've found useful during my android dev life and that i don't want to have to write again. never. ever. what a damn pain to remember every name!
This is a fancy class. to implement it, create a custom activity class (MyAbstractActivity) , and extend abstract activity. this will provide some cool functionality.
i'll start showing off the abstract activity code.
publicabstractclassAbstractActivityextendsAppCompatActivity {
publicabstractBooleansetupView();
publicabstractintlayoutId();
}we will use the setupView method as the activity's oncreate method. i made it return a boolean. you can override it or create a new one if you want another functionality. in my code, i use the boolean in the next context:
the layoutID() method will provide the abstract activity's oncreate the information on what to inflate.
so let's take a look at a test implementation of it, called MyAbstractActivity
publicabstractclassMyAbstractActivityextendsAbstractActivity {
@OverrideprotectedvoidonCreate(BundlesavedInstanceState ) {
super.onCreate(savedInstanceState);
setContentView(layoutId());
Booleaninterior = setupView();
Toolbart = (Toolbar) findViewById(R.id.myToolbar);
TextViewtext = (TextView) t.findViewById(R.id.toolbarTtitle);
text.setText(findViewText(layoutId()));
if (interior) {
t.setDisplayHomeAsUpEnabled(true);
}
}
privateStringfindViewText(intid) {
Stringret = "NoNameFoundActivity";
switch(id)
{
caseR.layout.activity_main:
ret = getResources().getString(R.string.title_activity_main);
break;
caseR.layout.activity_news:
ret = getResources().getString(R.string.title_activity_news);
break;
}
returnret;
}
@OverridepublicbooleanonCreateOptionsMenu(Menumenu) {
// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.menu_main, menu);
returntrue;
}
@OverridepublicbooleanonOptionsItemSelected(MenuItemitem) {
switch (item.getItemId()) {
caseandroid.R.id.home:
this.finish();
returntrue;
default:
returnsuper.onOptionsItemSelected(item);
}
}
}BUT , what does it do?
basically what we're doing here is defining a very basic functionality.
calling the setContentView(layoutId()) will retrieve the activity's layout id.
we then retrieve if the window is meant to have a go back home button on the toolbar.
Boolean interior = setupView();
using the layout id we then get the activity title and set it up, and also put if necessary the homeup button.
text.setText(findViewText(layoutId()));
if (interior) {
actionBar.setDisplayHomeAsUpEnabled(true);
}let's take a look at MyTestActivity
publicclassMyTestActivityextendsMyAbstractActivity {
@OverridepublicBooleansetupView() {
/** * INSERT ANY VIEW SETUP HERE, findViewById, API calls, * whatever you would put on a normal oncreate method. * this is your activity oncreate now. enjoy it. * **///you are inside a list, so show a back button to get back to it. because i say so.returntrue;
}
@OverridepublicintlayoutId() {
returnR.layout.activity_details;
}
}enjoy your clutter-less activities.
Soon to be added, those classes should provide even more functionality to my utils classes by, for example, helping you query the google maps API for a location, or for the list of polylines between A and B, or an extended webview that has, by default, all ready-to-work required features ( html5, chromium, javascript, tel: and mailto: detection intents...), etc...
using Jcenter() on your gradle file of choice ( but it won't work unless it's in your app's build.gradle),
compile 'com.cpteric:ericutils2:0.+'