The TestTube library project for easy Android implimentations
**HIT THAT STAR ONLY AFTER THIS HELPS YOU | ** **FIRE A MAIL DIRECTLY : sangeethnandakumar@gmail.com | ** DROP A MSG ON WHATSAPP: +91 9495661468
- On project level Gradle, add
allprojects
{
repositories
{
...
maven { url 'https://jitpack.io' }
}
}
- In app/module level Gradle, add
dependencies
{
compile 'com.github.sangeethnandakumar:TestTube:[LATEST_VERSION]'
}
Library Version | Improvements | Dependency |
---|---|---|
Prior to v2.0.1 | Not available on GitHub | Not available on GitHub |
v2.0.1 | New : Standard listview (SLV) Removed : Old WebServer class |
com.github.sangeethnandakumar:TestTube:v2.0.1 |
v2.0.2 | Upgraded : SLV now supports linear/card layerings Upgraded : Specification added to adapter |
com.github.sangeethnandakumar:TestTube:v2.0.2 |
v2.0.3 | New : Fully implemented FileDownloader class for url downloads Minor bug fixes and improvements New : WebDoc class to convert a webpage to pdf |
com.github.sangeethnandakumar:TestTube:v2.0.3 |
v2.0.4 | New : Standard gridview (SGV) New : Support for gridview card/linear layering New : SGV supports drawable or web resource Upgraded : Code optimised |
com.github.sangeethnandakumar:TestTube:v2.0.4 |
v2.0.5 | New : Android runtime permission helper Upgraded : Permit class to support multimple permissions at once Upgraded : Permission reponce interface |
com.github.sangeethnandakumar:TestTube:v2.0.5 |
v2.1.0 | New : Permanant settings New : Autostack page stack Beta : Google Distance Metrix initial phase (GDM) |
com.github.sangeethnandakumar:TestTube:v2.1.0 |
v2.5.0 | Upgraded : Google Distance Metrix fully implemented New : Support for Http GET request New : Support for Http POST request Upgraded : POST request to send a DataRack |
com.github.sangeethnandakumar:TestTube:v2.5.0 |
v2.5.1 | Removed : RW External storage permission New : 'SuperDatabase', a pure local SQL database Upgraded : injectSQL to do non returning SQL queries Upgraded : ejectSQL to do returning SQL queries Upgraded : ArrayString, JSON and XML out from Database Beta : Ability to import 'Asset DB' and use Beta : Importing .db database with existing control New : Syntax highlighter with a number of language support |
com.github.sangeethnandakumar:TestTube:v2.5.1 |
v2.5.2 | Applied : Minor bug fixes | com.github.sangeethnandakumar:TestTube:v2.5.2 |
v2.5.3 | Applied : Major bug fixes | com.github.sangeethnandakumar:TestTube:v2.5.3 |
Important:
Its very simple to use a standard list now
- Declare your listview
ListView list=(ListView)findViewById(R.id.listview);
- Add your items in a SimpleItem list
List<SimpleItem> simpleItems=new ArrayList<>();
simpleItems.add(new SimpleItem("United States"));
simpleItems.add(new SimpleItem("India"));
simpleItems.add(new SimpleItem("Russia"));
simpleItems.add(new SimpleItem("China"));
- Create a SimpleAdapter
SimpleAdapter simpleAdapter=new SimpleAdapter(getApplicationContext(),simpleItems, AdapterType.LISTVIEW, AdapterLayering.LINEAR);
- Just attach the Adapter to your listview and its over
list.setAdapter(simpleAdapter);
a) Add optional resource image if you want it
simpleItems.add(new SimpleItem("Lotus Flower",R.drawable.lotus));
simpleItems.add(new SimpleItem("Lilly Flower",R.drawable.lilly));
simpleItems.add(new SimpleItem("Rose Flower",R.drawable.rose));
b) Add optional web image if you want it (requires internet)
simpleItems.add(new SimpleItem("Google","https://www.google.com/something.png"));
simpleItems.add(new SimpleItem("Facebook","https://www.facebook.com/something.png"));
simpleItems.add(new SimpleItem("YouTube","https://www.youtube.com/something.png"));
c) Feel free to mix all these
simpleItems.add(new SimpleItem("Simply text"));
simpleItems.add(new SimpleItem("Resource image",R.drawable.elephant));
simpleItems.add(new SimpleItem("Web image","https://www.google.com/something.png"));
a) You can change the AdapterLayering to CARD if you need it
SimpleAdapter simpleAdapter=new SimpleAdapter(getApplicationContext(),simpleItems, AdapterType.LISTVIEW, AdapterLayering.CARD);
Like Simple Standard listview before, Use a standard dual list view
- Previous statements are same except here
List<DualItem> dualItems=new ArrayList<>();
dualItems.add(new DualItem("Samsung","User in Korea"));
dualItems.add(new DualItem("Pixel","User in California"));
dualItems.add(new DualItem("Sony Xperia","User in Japan"));
DualAdapter dualAdapter=new DualAdapter(getApplicationContext(),dualItems,AdapterType.LISTVIEW,AdapterLayering.CARD);
list.setAdapter(dualAdapter);
NOTE : Images from resources and web are also compatable here
Like Dual Standard listview before, Use a standard triple list view
- Statements are changed like
List<TripleItem> tripleItems=new ArrayList<>();
tripleItems.add(new TripleItem("Billy","Cat","At Kerala"));
tripleItems.add(new TripleItem("Snoory","Cat","At Banglore"));
tripleItems.add(new TripleItem("Dingi","Dog","At Mumbai"));
tripleItems.add(new TripleItem("Pupy","Dog","At Jammu"));
TripleAdapter tripleAdapter=new TripleAdapter(getApplicationContext(),tripleItems,AdapterType.LISTVIEW,AdapterLayering.LINEAR);
list.setAdapter(tripleAdapter);
NOTE : Images from resources and web are also compatable here
Like Simple/Dual/Tripple Standard listview before, Simple change this to make into a GridView
- Previous statements are same except here
DualAdapter dualAdapter=new DualAdapter(getApplicationContext(),dualItems,AdapterType.GRIDVIEW,AdapterLayering.CARD);
grid.setAdapter(dualAdapter);
Android runtime permissions are no longer RoCketScience
- Initialise the Permit object, passing your current activity
Permit permit=new Permit(MainActivity.this);
- Simply listen to the permission events using event listner
permit.setOnPermitStatusListner(new Permit.OnPermitStatusListner()
{
@Override
public void onAllPermitsGranded()
{
// ALL PERMITS ACCEPTED
}
@Override
public void onSomePermitsDenied(ArrayList<String> deniedPermits)
{
// SOME PERMITS ACCEPTED
}
@Override
public void onAllPermitsDenied()
{
// ALL PERMITS DENIED
}
});
- Now just ask for what permissions you need. Yes, It's over
permit.askPermitsFor(
Manifest.permission.CAMERA,
Manifest.permission.READ_CALENDAR,
Manifest.permission.READ_CONTACTS);
- Wan't to store/retrive your application settings? Simple initialise the AppSettings class with any context
AppSettings settings=new AppSettings(getApplicationContext());
- Store what all stuffs you want like (KEY-VALUE) style
settings.saveSettings("username","sangeeth");
settings.saveSettings("password","sangeeth@123");
settings.saveSettings("points","250");
settings.saveSettings("level","5");
settings.saveSettings("gender","male");
- Retrive what all stored
String username=settings.retriveSettings("username");
Toast.makeText(MainActivity.this, "Username is - " + username, Toast.LENGTH_SHORT).show();
NOTE : The settings stores here will persist even the app is closed. (Until uninstalled)
Its simply a string stack. When you are on a page, then push that PAGE_KEY. When user press BACK button, pop out the PAGE_KEY and check. If nothing to pop out, exit the app. Don't undersatand? It's simple like catching a frog from your pond.
- Just initialise the AutoStack
AutoStack stack=new AutoStack();
- Push while you traverse each pages of something (Assume a book)
// Assume user is presented with a menu
// As he enters each menu another menu is appearing (Like a directory)
// User at page SPACE (SPACE)
page.push("space");
// User clicks on EARTH (SPACE/EARTH)
page.push("earth");
// User clicks on ASIA (SPACE/EARTH/ASIA)
page.push("asia");
// User clicks on INDIA (SPACE/EARTH/ASIA/INDIA)
page.push("india");
- Override the onBackPressed() methord of your activity
@Override
public void onBackPressed()
{
if (page.isEmpty())
{
super.onBackPressed();
}
else
{
switch (page.pop())
{
case "india" :
showAsiaMenu();
break;
case "asia" :
showEarthMenu();
break;
case "space" :
showSpaceMenu();
break;
}
}
}
NOTE : STACK space used is not persistant and will be cleared when app restarts or context switched
New feature that brings you the address of locations, distance to travel on road along with units and time to travel along with units from Google Servers in its most simplest way
- Look at the GoogleDistanceMatrix class initialisation syntax
GoogleDistanceMatrix gdm=new GoogleDistanceMatrix("<YOUR_GOOGLE_KEY>","<ORIGIN_LATTITUDE>","<ORIGIN_LONGITUDE>","<DESTINATION_LATTITUDE>","<DESTINATION_LONGITUDE>",<ANY CONTEXT>);
- Now initialise it as depected
//Initialise key. You will get this key from here : https://developers.google.com/maps/documentation/distance-matrix/get-api-key
String key = "ABcdEfGHIJ7L4YhXw01INDIAHbVlgIhjmouSeVc";
//Set origin to
String origin_lat="36.752071";
String origin_lng="-119.823064";
// Set destination to
String dest_lat="36.773276";
String dest_lng="-119.845252";
GoogleDistanceMatrix gdm = new GoogleDistanceMatrix(key,origin_lat,origin_lng,dest_lat,dest_lng,getApplicationContext());
- Simplicity starts right now. Attach that listner
gdm.setOnGDMStatusListner(new GoogleDistanceMatrix.OnGDMStatusListner()
{
@Override
public void onGDMAvailable(GoogleDistanceMatrix gdm)
{
//Quickly collect details
String origin_address = gdm.getOrgin_address();
String dest_address = gdm.getDest_address();
String distance = gdm.getDistance();
String duration = gdm.getDuration();
}
@Override
public void onGDMFailed()
{
//Failed due to some resons
}
});
- Now send that request to GoogleServers via Our server (Complex codes are implimented on our server to keep you smiling). Now just request.!
gdm.getDistanceMatrix();
NOTE : Details will be arrived at the listners as soon us our server sends it back
Thinking for an ultimate simple way to download an file from an URL? With multithreading and simultanious download features, Here comes the new FileDownloader class 0. Look at the initialisation syntax
FileDownloader downloader=new FileDownloader(<ANY_CONTEXT>,<URL>);
- Now initialise the object like before
FileDownloader downloader=new FileDownloader(getApplicationContext(),"http://www.example.com/test.pdf")
- Keep track of downloader with these event listners
downloader.setOnDownloadStatusListner(new FileDownloader.OnDownloadStatusListner() {
@Override
public void onStarted()
{
}
@Override
public void onConnecting()
{
}
@Override
public void onConnected(long total, boolean isRangeSupport)
{
}
@Override
public void onDownloading(long finished, long total, int progress)
{
}
@Override
public void onCompleted()
{
}
@Override
public void onFailed(String message)
{
}
@Override
public void onPaused()
{
}
@Override
public void onCancelled()
{
}
});
- This is the last step to download. So simple...
downloader.downloadFile("/storage/emulated/0","newfile.pdf");
NOTE : The construction and devolopment of this class is in BETA. Unfortunatelly, Pause and Cancel is not working as of now. You can use without any other problems. Pause and Cancel support will be added soon.
Http GET methord requests a server with inline parameters on its URL. DOn't use Http GET to transfer passwords!. Http GET is best for visible parameters and easy to debug
- Initialise a WebServer instance and start its listners
WebServer server=new WebServer(getApplicationContext());
server.setOnServerStatusListner(new WebServer.OnServerStatusListner() {
@Override
public void onServerResponded(String responce) {
}
@Override
public void onServerRevoked() {
}
});
- Now just call the server with GET parameters
server.connectWithGET("https://www.google.com/test.php?name=Sangeeth&loc=India");
Http POST methord requests a server with unvisible parameters. Usefull to transport passwords.
- Initialise a WebServer instance and start its listners
WebServer server=new WebServer(getApplicationContext());
server.setOnServerStatusListner(new WebServer.OnServerStatusListner() {
@Override
public void onServerResponded(String responce) {
}
@Override
public void onServerRevoked() {
}
});
- Create a list of DataRack for your key-value pairs
List<DataRack> racks=new ArrayList<DataRack>();
racks.add(new DataRack("name","Simon"));
racks.add(new DataRack("age","40"));
racks.add(new DataRack("location","Canada"));
- Now just call the server with POST rack along caller activity
server.connectWithPOST(MainActivity.this,"http://sangeethnandakumar.esy.es/PROJECTS/PUBLIC_SERVICE/posttest.php",racks);
Messed up with Android database implementations? Here is the perfect pure simple SQL database 0. Look at the syntax
SuperDatabase database=new SuperDatabase(<CONTEXT>,<DATABASE_NAME>,<DB_SCHEMA>);
- Declare the SuperDatabase
SuperDatabase database=new SuperDatabase(getApplicationContext(),"Foods","CREATE TABLE IF NOT EXISTS food('name' VARCHAR(20),'vitamin' VARCHAR(20);");
Now fire the queries
a). Create an INJECT statement, If you have a non returning query
database.sqlInject("INSERT INTO food VALUES('Banana','Vitamin A');");
database.sqlInject("INSERT INTO food VALUES('Apple','Vitamin B');");
database.sqlInject("INSERT INTO food VALUES('Grapes','Vitamin C');");
It will simply executes...
b). Create an EJECT statement, If you have a returning query
<return_var> = database.sqlEjectCSV("SELECT * FROM food;");
b). EJECT statement can eject data in CSV, JSON & XML formats. CSV needs an ArrayList
CSV
ArrayList<String> rows=new ArrayList<String>();
rows=database.sqlEjectCSV("SELECT * FROM food;");
for (int i=0;i<rows.size();i++)
{
//Do stuffs with each row
}
JSON
String json=database.sqlEjectJSON("SELECT * FROM food;");
XML
String xml=database.sqlEjectXML("SELECT * FROM food;");
Already have a database with you? Here is the simplest solution to make in Android 0. Look at the syntax
SuperDatabase database=new SuperDatabase(<CONTEXT>,<DATABASE_NAME>,<DB_SCHEMA>,<ASSET_IMPORT_MODE>);
1 a). If your app runs for the first time after installation, Then import the database from asset. So declare like this
SuperDatabase database=new SuperDatabase(getApplicationContext(),"foods.db", AssetDatabaseMode.COPY_TO_SYSTEM);
1 b). If your app runs after first time, Never import the asset database again. So declare like this
SuperDatabase database=new SuperDatabase(getApplicationContext(),"foods.db", AssetDatabaseMode.READ_FROM_DEVICE);
NOTE : Now do the INJECT and EJECT queries as before (Also supports CSV, JSON and XML)
IMPORTANT NOTE
1. You need a .db database for this
2. Download DB Browser For SQLite (Recomended Windows) - http://sqlitebrowser.org/
3. Click on 'New Database'
4. On save prompt - Include ".db" extension after filename
5. Done, Now import to assets folder
Online syntax highlighting highlights any language code segment with HTML that you can render on a WebView easly
- Create the object
SyntaxLight syntax=new SyntaxLight(getApplicationContext(),"PHP","<?php echo 'Hello world'; ?>");
- Implement the listners
syntax.setOnCodeStatusListner(new SyntaxLight.OnCodeStatusListner() {
@Override
public void parsedToHTML(String s) {
//You got HTML here
}
@Override
public void parseError() {
}
});
- Now highlight the code
syntax.highlightCode();