Skip to content

sangeethnandakumar/TestTube

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introducing TestTube

The TestTube library project for easy Android implimentations

Travis branch Travis branch Travis branch

TestTube Logo

**HIT THAT STAR ONLY AFTER THIS HELPS YOU | ** **FIRE A MAIL DIRECTLY : sangeethnandakumar@gmail.com | ** DROP A MSG ON WHATSAPP: +91 9495661468

Star

Include the Gradle Dependency

  1. On project level Gradle, add
        allprojects
	{
		repositories 
		{
			...
			maven { url 'https://jitpack.io' }
		}
	}
  1. In app/module level Gradle, add
        dependencies 
	{
	        compile 'com.github.sangeethnandakumar:TestTube:[LATEST_VERSION]' 
	}
  1. LATEST_VERSION (Use this version on dependency) :
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:

Travis branch Travis branch Travis branch Travis branch

SIMPLE STANDARD LISTVIEW (adapter)

Runtime permission demo

Its very simple to use a standard list now

  1. Declare your listview
        ListView list=(ListView)findViewById(R.id.listview);
  1. 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"));
  1. Create a SimpleAdapter
        SimpleAdapter simpleAdapter=new SimpleAdapter(getApplicationContext(),simpleItems, AdapterType.LISTVIEW, AdapterLayering.LINEAR);
  1. Just attach the Adapter to your listview and its over
        list.setAdapter(simpleAdapter);

You done everything.!!!, For further minimal customizing

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"));

Another way

a) You can change the AdapterLayering to CARD if you need it

        SimpleAdapter simpleAdapter=new SimpleAdapter(getApplicationContext(),simpleItems, AdapterType.LISTVIEW, AdapterLayering.CARD);

DUAL STANDARD LISTVIEW (adapter)

Like Simple Standard listview before, Use a standard dual list view

  1. 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

TRIPLE STANDARD LISTVIEW (adapter)

Like Dual Standard listview before, Use a standard triple list view

  1. 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

SIMPLE/DUAL/TRIPLE STANDARD GRIDVIEW (adapter)

Runtime permission demo

Like Simple/Dual/Tripple Standard listview before, Simple change this to make into a GridView

  1. Previous statements are same except here
        DualAdapter dualAdapter=new DualAdapter(getApplicationContext(),dualItems,AdapterType.GRIDVIEW,AdapterLayering.CARD);
	grid.setAdapter(dualAdapter);

ASKING RUNTIME PERMISSIONS (permissions)

Runtime permission demo

Android runtime permissions are no longer RoCketScience

  1. Initialise the Permit object, passing your current activity
	Permit permit=new Permit(MainActivity.this);
  1. 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
                    }
                });
  1. 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);

PERMANANT SETTINGS FOR YOUR APP (managers)

App Settings Demo

  1. Wan't to store/retrive your application settings? Simple initialise the AppSettings class with any context
	AppSettings settings=new AppSettings(getApplicationContext());
  1. 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");
  1. 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)

AUTOSTACK FOR YOUR PAGE MANAGEMENTS (managers)

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.

  1. Just initialise the AutoStack
	AutoStack stack=new AutoStack();
  1. 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");
  1. 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

GOOGLE DISTANCE MATRIX FOR YOUR ADDRESSES (extended)

Runtime permission demo

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

  1. Look at the GoogleDistanceMatrix class initialisation syntax
	GoogleDistanceMatrix gdm=new GoogleDistanceMatrix("<YOUR_GOOGLE_KEY>","<ORIGIN_LATTITUDE>","<ORIGIN_LONGITUDE>","<DESTINATION_LATTITUDE>","<DESTINATION_LONGITUDE>",<ANY CONTEXT>);
  1. 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());
  1. 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
                }
         });
  1. 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

DOWNLOAD A FILE (network)

File Downloading Demo

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>);
  1. Now initialise the object like before
        FileDownloader downloader=new FileDownloader(getApplicationContext(),"http://www.example.com/test.pdf")
  1. 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()
                    {
                    }
                });
  1. 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 REQUEST (network)

Http GET Demo

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

  1. 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() {

                    }
                });
  1. Now just call the server with GET parameters
		server.connectWithGET("https://www.google.com/test.php?name=Sangeeth&loc=India");

HTTP POST REQUEST (network)

Http GET Demo

Http POST methord requests a server with unvisible parameters. Usefull to transport passwords.

  1. 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() {

                    }
                });
  1. 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"));
  1. 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);

SUPER DATABASE (managers)

Runtime permission demo

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>);
  1. 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;");

SUPER ASSET DATABASE (managers)

Runtime permission demo

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

SYNTAX HIGHLIGHTING (extended)

Runtime permission demo

Online syntax highlighting highlights any language code segment with HTML that you can render on a WebView easly

  1. Create the object
	SyntaxLight syntax=new SyntaxLight(getApplicationContext(),"PHP","<?php echo 'Hello world'; ?>");
  1. Implement the listners
                    syntax.setOnCodeStatusListner(new SyntaxLight.OnCodeStatusListner() {
                        @Override
                        public void parsedToHTML(String s) {
                            //You got HTML here
                        }

                        @Override
                        public void parseError() {

                        }
                    });
  1. Now highlight the code
	syntax.highlightCode();