Tools to make your life easier in java and android
- Java: DataTime, LinkedMap, Tools...
- Android: ViewTools, RunnableTask, NfcFragment, WebImage, DefaultAdapter, DateTime, RecyclerListView, Notification, Dialog, Translator...
Add this line + the current version to your app.gradle:
implementation 'com.github.MindFlare56:Tools:Tag'
Visit the below link to get the current version and the installation explanation
https://jitpack.io/#MindFlare56/Tools
Also require these usefull tools:
annotationProcessor "com.jakewharton:butterknife:8.5.1"
annotationProcessor "com.jakewharton:butterknife-compiler:8.5.1"
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
annotationProcessor "org.projectlombok:lombok:1.16.18"
compileOnly "javax.annotation:jsr250-api:1.0"
## Unfortunatly require:
in android studio: file->settings->plugins->browse reposistories->Lobok Plugin->Install
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
implementation 'com.github.MindFlare56.Tools:androidtools:1.4.5'
android { //put packaginOptions inside your android {} in your build.gradlepackagingOptions {
exclude'META-INF/DEPENDENCIES'exclude'META-INF/LICENSE'exclude'META-INF/LICENSE.txt'exclude'META-INF/license.txt'exclude'META-INF/NOTICE'exclude'META-INF/NOTICE.txt'exclude'META-INF/notice.txt'exclude'META-INF/ASL2.0'
} }RunnableTaskrunnableTask = newRunnableTask() {
@Overridepublicvoidrun() {
mainController.someMethodInitDatabase();
}
@Overridepublicvoidprogress() {
progressAfter(someMethodIsArrayFilled(), "Some message Array is filled", intProgress);
}
@Overridepublicvoidend() {
someMethodBuildUserArray() }
};
runnableTask.start(this, delayInMilliseconds);newTranslator("hello world I am Dave and it's nice to meet y'all", "en", "fr") {
@Override//lang can be optional it is English to French defaultpublicvoidonResult(Stringresult) {
ViewTools.logv(result);
}
};
//then you can reuse it if you declared Translator translator = new Translator(...translator.setDestination("fr");
translator.add("A phrase to traduce in french");
translator.add("Another phrase to traduce in french");
translator.add("Some other text", "en", "it");
translator.add("Some other text to traduce in italian");//Just extends the NfcFragment class and set thesepublicclassSomeFragmentextendsNfcFragment {
@OverridepublicintsetLayout() {
returnR.layout.some_fragment;//set your fragment layout here
}
@OverridepublicvoidonCreate(Viewview) {
//get fragment built view here
}
@OverridepublicvoidhandleMessage(Stringmessage) {
//get message here
}
}
//last step that I couldn't avoid unfortunatlypublicclassMainActivityextendsAppCompatActivity {
privateNfcFragmentnfcFragment;
@OverrideprotectedvoidonCreate(finalBundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nfcFragment = newSomeFragment();
ViewTools.changeFragment(this, R.id.main_frame, nfcFragment);
}
@OverrideprotectedvoidonNewIntent(Intentintent) {
setIntent(intent);
StringnfcTagData = nfcFragment.resolveIntent(intent);
}
}listView.setAdapter(newRecyclerAdapter(context, list.size(), R.layout.layout) {
@OverridepublicvoidadaptView(intposition, Viewview) {
WebImage.setImageView(activity, view.findViewById(R.id.image), list.get(position).getImageUrl(), someWidth, someHeight);
((TextView) view.findViewById(R.id.text)).setText(list.get(position).getInfo());
}
});@BindView(R.id.recyclerview) RecyclerViewrecyclerView;
@BindView(R.id.test_textview) TextViewtextView;
@OverrideprotectedvoidonCreate(finalBundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
finalArrayList<String> strings = newArrayList<>();
strings.add("string 1");
strings.add("string 2"); newRecyclerListView(recyclerView, this, strings.size(), R.layout.test_view) {
@OverrideprotectedvoidadaptView(intposition, Viewview) {
textView.setText(strings.get(position));
}
};
}// format == iso8601publicstaticStringgetCurrentDateTime(); // "yyyy-MM-dd HH:mm:ss"publicstaticStringgetCurrentDate(); // "yyyy-MM-dd"publicstaticStringgetCurrentYear(); // "yyyy"publicstaticStringgetCurrentTime(); // "HH:mm:ss"publicstaticStringgetCurrentHours();
publicstaticStringgetCurrentMilliSeconds();
publicstaticdoublegetCurrentMilliSecondsValue();
publicstaticStringgetADateMilliSeconds(StringdateString);
publicstaticStringchangeDateFormatToIso8601(StringstringDate, finalStringOLD_FORMAT);
publicstaticStringextractDay(StringdateString); // "dd"publicstaticbooleanisDateBefore(StringinputDate, StringcomparedDate);
publicstaticbooleanisDateValid(StringinputDate);
publicstaticintgetAge(StringbirthDate);
...............publicclassSomeFragmentextendsFragment {
...
privatevoidsomeMethod() { if (condition) {
ViewTools.changeFragment(activity, R.id.mainDrawerFrame, newSomeFragment(), getString("Fragment title"));
} else {
ViewTools.changeFragment(activity, R.id.mainDrawerFrame, newSomeOtherFragment(), getString("Other fragment title"));
}
}
}privatevoidsomeMethod(intprogress) {
ViewTools.logv("Progress made: " + progress + "!");
}
/** Console output example:V/Debug | 17:43:24 ->: Progress made: 100!**/notification = newNotification(this)
.setChannelId(getString(R.string.channel_id))
.setIcon(R.drawable.landfill)
.setDescription(getString(R.string.notification_description))
.setChannelText(getString(R.string.notification_channel_text))
.setTitle(getString(R.string.notification_title_plants))
.setContentText("")
.setTargetClass(PlantFragment.class);
notification.show();LinkedMap<String, MyObject>> myObjectMap = newLinkedMap<>(keyList, myObjectList);
for (MyObjectmyObject : myObjectMap.getValues()) {
//do something
}
...
MyObjectmyObject = myObjectMap.get("key");
...
//Here's one of the case that made me do thisprivateButtonbutton;
@OverrideprotectedvoidadaptView(inti, Viewview) {
findViews(view);
MyObjectmyObject = myObjectMap.get(i); button.setOnClickListener(v -> controller.doSomething(myObject));
}Map<String, SomeObject> someObjectMap = getSomeObjectMap();
List<SomeObject> someObjects = Tools.mapToArray(someObjectMap);
listView.setAdapter(newDefaultAdapter(context, list.size(), R.layout.layout) {
@OverridepublicvoidadaptView(intposition, Viewview) {
WebImage.setImageView(activity, view.findViewById(R.id.image), someObjects.get(position).getImageUrl(), someWidth, someHeight);
((TextView) view.findViewById(R.id.text)).setText(someObjects.get(position).getInfo());
}
});compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileOnly "javax.annotation:jsr250-api:1.0"
annotationProcessor "com.jakewharton:butterknife:8.5.1"
annotationProcessor "com.jakewharton:butterknife-compiler:8.5.1"
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
annotationProcessor "org.projectlombok:lombok:1.16.18"
implementation 'org.jetbrains:annotations:15.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.jakewharton:butterknife:8.5.1'
implementation 'com.jakewharton:butterknife-compiler:8.5.1'
implementation 'com.github.psinetron:slycalendarview:0.0.7' implementation 'org.projectlombok:lombok:1.16.18'
@BindView(R.id.lh_username) EditTextusername;
@BindView(R.id.lh_password) EditTextpassword;
@BindView(R.id.lh_checkbox) CheckBoxrememberMe;
@BindView(R.id.lh_button) Buttonsubmit;
@OverrideprotectedvoidonCreate(@NullableBundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_handler);
ButterKnife.bind(this);
Activityref = this;
LoginFieldsloginFields = newLoginFields(username, password, rememberMe, submit);
loginFields.setRequestFields("http://yourIpHere/phpFunctionHere", "userTableName", "passwordTableName");
LoginHandlerloginHandler = newLoginHandler(this, loginFields) {
@OverridepublicvoidonLogRequestEnd() {
ViewTools.logv("rdy to change activity !");
ViewTools.changeActivity(ref, NextActivity.class);
}
};
loginHandler.log();
}