Aim: To know about GPU in Android 


Topic Covered:

  • What is GPU
  • Role of GPU
  • Rendering GPU  graph
  • Rendering Graph Explained 
  • Color Indications and its meaning



What is GPU:

GPU is graphical processing unit in the android operating system Since from the smartphone revolution with extensive use of the graphics in the normall phone led to evolution of the GPU
It is consider as the soul of the CPU.
GPU performs the various graphical and transformation calculation so the CPU does not have to burden by these operations.
GPU is mostly available in stand alone form with chip only where CPU has multiple cores.
Most popular brands manufacturing the Nvidea's Gforce and Adreno by qualcomm.


Rendering the GPU Profiling Graph :

  1. On your mobile device, go to Settings and Developer Options.
  2. In the Monitoring section, select Profile GPU Rendering.
  3. In the Profile GPU Rendering popup, choose On screen as bars to overlay the graphs on the screen of your mobile device.
  4. Go to the app that you want to profile.



 





Rendering Graph Explained :


  • After enabling the profile gpu rendering it will start to show the graph in the form of bars.
  • Bar graphs will be in the colored format of blue red green where as each color signifies the time taken to render the graphics
  • Vertical bar represents rendering of one frame against the time

Color Indications and its meaning :

  • Blue 
The blue section of the bar represents the time used to create and update the View's display lists. If this part of the bar is tall, there may be a lot of custom view drawing, or a lot of work in onDraw methods.

  • Purple
Android 4.0 and higher: The purple section of the bar represents the time spent transferring resources to the render thread.







  • Red
The red section of the bar represents the time spent by Android's 2D renderer issuing commands to OpenGL to draw and redraw display lists. The height of this bar is directly proportional to the sum of the time it takes each display list to execute—more display lists equals a taller red bar


  • Orange

The orange section of the bar represents the time the CPU is waiting for the GPU to finish its work. If this bar gets tall, it means the app is doing too much work on the GPU.



Aim :

This tutorial mainly aims to give the recommended way for doing the HTTP connection for new api changes after API 23.
As per the new changes Apache classes are removed from the API23 so this post gives one of the way by using HttpURLConnection class.


Topics Covered :

-How to make connection using URLCoonection classes
-Setting Properties
-Making request
-Getting the Response.
-Code Snippep



-How to make connection using URLCoonection classes:

Obtain the URL Connection by making URL.openconnection()

The stream can be called by URLConnection.getInputStream()

Use the Stream classes like inputStream or Buffer reader to read the stream


-Setting Properties
 Various Properties can be set in following way
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("USER-AGENT", "Mozilla/5.0");
connection.setRequestProperty("ACCEPT-LANGUAGE", "en-US,en;0.5");
connection.setDoOutput(true); 
-Making request
   

URL url;
    HttpURLConnection urlConnection = null;
    try {
        url = new URL("http://www.yoursite.com");

        urlConnection = (HttpURLConnection) url
                .openConnection();

        InputStream in = urlConnection.getInputStream();

        InputStreamReader isw = new InputStreamReader(in);

        int data = isw.read();
        while (data != -1) {
            char current = (char) data;
            data = isw.read();
            System.out.print(current);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (urlConnection != null) {
            urlConnection.disconnect();
        }    
    }

wfrrsdfa








Aim: To know the use of selector and its implementation 

Topics Covered:
-What is Selector
-How to write
-Implementation of Selectors
-How to Apply to Button


What is selector :
Android allows different states of the button to be changed as per the users action to identify 
various action getting performed on the Button by modifying it visual appearance .The state are
pressed,selected and Normall the visual representation of these changes is manged through the Selectors  .
Selectors are basically xml part of the android project which are written in xml and placed in the drawable folder of the project.


How to write :
Selectors are written in xml and are placed in the draw-able directory of the project. 

Implementation of Selectors:


 



    
    
    




Here in this case

    



this line will pick the image with name numpad_button_bg_selected n when the state of the button is selected similarly it will work for rest of the states.



How to Apply to Button:


The Selector which you have written can be applied to button in following way
   
   



This is how you can implement the selector for the button in android it can be implemented in simillar way for image view and imagebutton as well.


Understanding SQLITE DataBase in Android

Aim: TO know about SQLITE database in android Application.

Topics: Introduction to SQLITE
             Architecture of SQLITE
             Creating Simple Model
             OPerations in SQLITE Database :
             CodeSnnipets


Introduction to SQLITE :

Sqlite is OPen-Source portable database in android .It is an inbuilt database which can be accessible
from the device OS without any external libraries .
These support many operation as like normal database like upgrade,create ,delete,insert etc.
there are certain set of stander ed API to query the database which we will cover further in the post .


Architecture of SQLITE :



The Figure shows the architecture of the SQLITE database in android which is comprise of various parts like CORE,SQL Compiler,Backend.

The SQLITE database is in the package android.database.sqlite.*

If your application creates a database, this database is by default saved in the directoryDATA/data/APP_NAME/databases/FILENAME.
SQLiteOpenHelper class provides the functionality to use the SQLite database.


Creating Simple Model :
For creating and accessing the SQLite database a standard step is to Extend a class with SQLiteOpenHelper.After that have to provide the implementation of onCreate() and onUpgrade() methods of SQLiteOpenHelper class.

package sqlite.blazin.in.sqlite;
/**
 * Created by bhushan on 29/2/16.
 */
public class Contact {
    int _id;
    String _name;
    String _phone_number;

    public Contact() {
    }

    public Contact(int id, String name, String _phone_number) {
        this._id = id;
        this._name = name;
        this._phone_number = _phone_number;
    }

    public Contact(String name, String _phone_number) {
        this._name = name;
        this._phone_number = _phone_number;
    }

    public int getID() {
        return this._id;
    }

    public void setID(int id) {
        this._id = id;
    }

    public String getName() {
        return this._name;
    }

    public void setName(String name){
        this._name = name;
    }

    public String getPhoneNumber(){
        return this._phone_number;
    }

    public void setPhoneNumber(String phone_number){
        this._phone_number = phone_number;
    }
}

This the Model class for making the contact object which are going to use for data operation. Now this is how the way is to write the OPENHelper Class for the database related operations
package sqlite.blazin.in.sqlite;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by bhushan on 29/2/16.
 */
public class DatabaseHandler extends SQLiteOpenHelper {
    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "contactsManager";
    private static final String TABLE_CONTACTS = "contacts";
    private static final String KEY_ID = "id";
    private static final String KEY_NAME = "name";
    private static final String KEY_PH_NO = "phone_number";

    public DatabaseHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        //3rd argument to be passed is CursorFactory instance
    }

    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
                + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
                + KEY_PH_NO + " TEXT" + ")";
        db.execSQL(CREATE_CONTACTS_TABLE);
    }

    // Upgrading database
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);

        // Create tables again
        onCreate(db);
    }

    // code to add the new contact
    void addContact(Contact contact) {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_NAME, contact.getName()); // Contact Name
        values.put(KEY_PH_NO, contact.getPhoneNumber()); // Contact Phone

        // Inserting Row
        db.insert(TABLE_CONTACTS, null, values);
        //2nd argument is String containing nullColumnHack
        db.close(); // Closing database connection
    }

    // code to get the single contact
    Contact getContact(int id) {
        SQLiteDatabase db = this.getReadableDatabase();

        Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
                        KEY_NAME, KEY_PH_NO }, KEY_ID + "=?",
                new String[] { String.valueOf(id) }, null, null, null, null);
        if (cursor != null)
            cursor.moveToFirst();

        Contact contact = new Contact(Integer.parseInt(cursor.getString(0)),
                cursor.getString(1), cursor.getString(2));
        // return contact
        return contact;
    }

    // code to get all contacts in a list view
    public List getAllContacts() {
        List contactList = new ArrayList();
        // Select All Query
        String selectQuery = "SELECT  * FROM " + TABLE_CONTACTS;

        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                Contact contact = new Contact();
                contact.setID(Integer.parseInt(cursor.getString(0)));
                contact.setName(cursor.getString(1));
                contact.setPhoneNumber(cursor.getString(2));
                // Adding contact to list
                contactList.add(contact);
            } while (cursor.moveToNext());
        }

        // return contact list
        return contactList;
    }

    // code to update the single contact
    public int updateContact(Contact contact) {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_NAME, contact.getName());
        values.put(KEY_PH_NO, contact.getPhoneNumber());

        // updating row
        return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?",
                new String[] { String.valueOf(contact.getID()) });
    }

    // Deleting single contact
    public void deleteContact(Contact contact) {
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(TABLE_CONTACTS, KEY_ID + " = ?",
                new String[] { String.valueOf(contact.getID()) });
        db.close();
    }

    // Getting contacts Count
    public int getContactsCount() {
        String countQuery = "SELECT  * FROM " + TABLE_CONTACTS;
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery(countQuery, null);
        cursor.close();

        // return count
        return cursor.getCount();
    }

}
Your main Activity class looks like this.
package sqlite.blazin.in.sqlite;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

         Button insert,Print;
        final TextView info;


        insert=(Button)findViewById(R.id.btnInsert);
        Print=(Button)findViewById(R.id.btnPrint);
        info=(TextView)findViewById(R.id.tvInfo);

        final DatabaseHandler databaseHelper = new DatabaseHandler(this);

        insert.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Inserting Contacts
                Log.d("Insert: ", "Inserting ..");
                databaseHelper.addContact(new Contact("BlazinRavi", "9100000000"));
                databaseHelper.addContact(new Contact("BlazinGanesh", "88888888"));
                databaseHelper.addContact(new Contact("Amnda", "56897566"));
                databaseHelper.addContact(new Contact("stephy", "123456"));
                Toast.makeText(MainActivity.this,"DATA INserted ",Toast.LENGTH_SHORT).show();
            }
        });



        Print.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // Reading all contacts
                Log.d("Reading: ", "Reading all contacts..");
                StringBuilder sb= new StringBuilder();

                List contacts = databaseHelper.getAllContacts();

                for (Contact cn : contacts) {
                    String log = "Id: "+cn.getID()+" ,Name: " + cn.getName() + " ,Phone: " +
                            cn.getPhoneNumber();
                    // Writing Contacts to log
                 sb.append(log);
                    sb.append("\n");
                    sb.append("\n");
                    Log.d("Name: ", log);
                }
                info.setText(sb);
            }
        });
    }
}
This is how the Code looks when we run





For loading the contacts fast from the content provider we need to provide the projection while querying the contacts cursor



Important Cursors:

Type 1: ContactsContract.CommonDataKinds.Phone.CONTENT_URI

Type2:   ContactsContract.Contacts.CONTENT_URI


We will be using the type 1 cursor for getting the name,number of the user.
void getAllContacts() {
        long startnow;
        long endnow;
        
        startnow = android.os.SystemClock.uptimeMillis();
        ArrayList arrContacts = new ArrayList();
        
        Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
        String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER;
        Cursor cursor = ctx.getContentResolver().query(uri, new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER,   ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone._ID, ContactsContract.Contacts._ID}, selection, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
        
        cursor.moveToFirst();
        while (cursor.isAfterLast() == false) {

            String contactNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
            String contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            int phoneContactID = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID));
            int contactID = cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts._ID));
            Log.d("con ", "name " + contactName + " " + " PhoeContactID " + phoneContactID + "  ContactID " + contactID)

            cursor.moveToNext();
        }
        cursor.close();
        cursor = null;

        endnow = android.os.SystemClock.uptimeMillis();
        Log.d("END", "TimeForContacts " + (endnow - startnow) + " ms");
    }



The above method will give the list of contacts along with time taken to load the details.
in my case i have 500 contacts in my phonebook which takes 470ms (less than half second).








100 Bestselling Courses-The Complete Android Developer Course - Build 14 Apps




ORMLite is lightweight Java ORM supports for android Sqlite Database.The full form of ORMLite is Object Relational Mapping Lite(ORMLite).and it provides some light weight functionality to store and retrieve Java Objects.And it avoiding the complexity and more standard Object Relational Mapping.

ORMLite supports more than one database using JDBC and also sqlite with native calls to android database APIs..


                             


ORMLite simply add objects of java using annotations.and its have powerful abstract Database Access Object classes.also provides simple and  flexible query using QueryBuilder.Auto generates SQL to create and drop database tables.and its have basic supports for database transactions.


In Android security model, one application cannot directly access (read/write) other application's data. Every application has its own id data directory and own protected memory area.
Content provider is the best way to share data across applications. Content provider is a set of data wrapped up in a custom API to read and write. Applications/Processes have to register themselves as a provider of data. Other applications can request Android to read/write that data through a fixed API.
Content provider API adheres to CRUD principle.


Examples for content provider are Contacts-that exposes user information to other applications, Media store-Allows other applications to access,store media files.

Content providers are simple interfaces which uses standard insert(), query(), update(), delete() methods to access application data. So it is easy to implement a content provider.

A special URI starting with content:// will be assigned to each content providers and that will be recognized across applications.

Writing a content provider:
The ContentProvider class is the central component of a content provider. To create a content provider we have to
1. Create sub class for ContentProvider.
2. Define content URI
3. Implement all the unimplemented methods. insert(), update(), query(), delete(), getType().
4. Declare the content provider in AndroidManifest.xml

Defining URI:
Content provider URI consists of four parts.
content://authority/path/id
content:// All the content provider URIs should start with this value
'authority' is Java namespace of the content provider implementation. (fully qualified Java package name)
'path' is the virtual directory within the provider that identifies the kind of data being requested.
'id' is optional part that specifies the primary key of a record being requested. We can omit this part to request all records.

Adding new records:
We need to override insert() method of the ContentProvider to insert new record to the database via content provider. The caller method will have to specify the content provider URI and the values to be inserted without the ID. Successful insert operation will return the URI value with the newly inserted ID.
For example: If we insert a new record to the content provider content://com.example/sample
the insert method will return content://com.example/sample/1

Updating records:
To update one or more records via content provider we need to specify the content provider URI. update() method of the ContentProvider is used to update records. We have to specify the ID of the record to update a single record. To update multiple records, we have to specify 'selection' parameter to indicate which rows are to be changed.
This method will return the number of rows updated.

Deleting records:
Deleting one or more records is similar to update process. We need to specify either ID or 'selection' to delete records. delete() method of the ContentProvider will return the number of records deleted.

Querying the content provider:
To query the data via content provider we orverride query() method of ContentProvider. This method has many parameters.  We can specify list columns to put into the result cursor using 'projection' parameter. We can specify 'selection' criteria. We can specify 'sortOrder' too.
If we do not specify projection, all the columns will be included in the result cursor. If we do not specify sortOrder the provider will choose its own sort order.

getType() method:

This method is used handle requests for the MIME type of the data at the given URI. We use either vnd.android.cursor.item or vnd.android.cursor.dir/
vnd.android.cursor.item is used to represent specific item. Another one is used to specify all items.

Registering the provider in AndroidManifest.xml
As with any other major parts of Android application, we have to register the content providers too in the AndroidManifest.xml.  element is used to register the content providers. is its parent element.



Here authorities is the URI authority to access the content provider. Typically this will be the fully qualified name of the content provider class.


1. Application 'MyProvider'

This application will create a content provider and share its data. This uses SQLite database 'mydb'. It has a table called 'names'. The table names have two columns id,name.
The URI of this content provider is content://com.androidBlazin.contentproviderexample.MyProvider/cte
We have layout to insert new records to the database table.

Layout xml file:

    
    
    
Content provider class: MyProvider.java
package com.androidblazin.contentproviderexample;

import java.util.HashMap;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;

public class MyProvider extends ContentProvider {
 static final String PROVIDER_NAME = "com.example.contentproviderexample.MyProvider";
 static final String URL = "content://" + PROVIDER_NAME + "/cte";
 static final Uri CONTENT_URI = Uri.parse(URL);

 static final String id = "id";
 static final String name = "name";
 static final int uriCode = 1;
 static final UriMatcher uriMatcher;
 private static HashMap values;
 static {
  uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
  uriMatcher.addURI(PROVIDER_NAME, "cte", uriCode);
  uriMatcher.addURI(PROVIDER_NAME, "cte/*", uriCode);
 }

 @Override
 public int delete(Uri uri, String selection, String[] selectionArgs) {
  int count = 0;
  switch (uriMatcher.match(uri)) {
  case uriCode:
   count = db.delete(TABLE_NAME, selection, selectionArgs);
   break;
  default:
   throw new IllegalArgumentException("Unknown URI " + uri);
  }
  getContext().getContentResolver().notifyChange(uri, null);
  return count;
 }

 @Override
 public String getType(Uri uri) {
  switch (uriMatcher.match(uri)) {
  case uriCode:
   return "vnd.android.cursor.dir/cte";

  default:
   throw new IllegalArgumentException("Unsupported URI: " + uri);
  }
 }

 @Override
 public Uri insert(Uri uri, ContentValues values) {
  long rowID = db.insert(TABLE_NAME, "", values);
  if (rowID > 0) {
   Uri _uri = ContentUris.withAppendedId(CONTENT_URI, rowID);
   getContext().getContentResolver().notifyChange(_uri, null);
   return _uri;
  }
  throw new SQLException("Failed to add a record into " + uri);
 }

 @Override
 public boolean onCreate() {
  Context context = getContext();
  DatabaseHelper dbHelper = new DatabaseHelper(context);
  db = dbHelper.getWritableDatabase();
  if (db != null) {
   return true;
  }
  return false;
 }

 @Override
 public Cursor query(Uri uri, String[] projection, String selection,
   String[] selectionArgs, String sortOrder) {
  SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
  qb.setTables(TABLE_NAME);

  switch (uriMatcher.match(uri)) {
  case uriCode:
   qb.setProjectionMap(values);
   break;
  default:
   throw new IllegalArgumentException("Unknown URI " + uri);
  }
  if (sortOrder == null || sortOrder == "") {
   sortOrder = name;
  }
  Cursor c = qb.query(db, projection, selection, selectionArgs, null,
    null, sortOrder);
  c.setNotificationUri(getContext().getContentResolver(), uri);
  return c;
 }

 @Override
 public int update(Uri uri, ContentValues values, String selection,
   String[] selectionArgs) {
  int count = 0;
  switch (uriMatcher.match(uri)) {
  case uriCode:
   count = db.update(TABLE_NAME, values, selection, selectionArgs);
   break;
  default:
   throw new IllegalArgumentException("Unknown URI " + uri);
  }
  getContext().getContentResolver().notifyChange(uri, null);
  return count;
 }

 private SQLiteDatabase db;
 static final String DATABASE_NAME = "mydb";
 static final String TABLE_NAME = "names";
 static final int DATABASE_VERSION = 1;
 static final String CREATE_DB_TABLE = " CREATE TABLE " + TABLE_NAME
   + " (id INTEGER PRIMARY KEY AUTOINCREMENT, "
   + " name TEXT NOT NULL);";

 private static class DatabaseHelper extends SQLiteOpenHelper {
  DatabaseHelper(Context context) {
   super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
   db.execSQL(CREATE_DB_TABLE);
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
   db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
   onCreate(db);
  }
 }
}

Activity calss: MainActivity.java
package com.androidblazin.contentproviderexample;

import android.app.Activity;
import android.content.ContentValues;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
 }

 public void onClickAddName(View view) {
  ContentValues values = new ContentValues();
  values.put(MyProvider.name, ((EditText) findViewById(R.id.txtName))
    .getText().toString());
  Uri uri = getContentResolver().insert(MyProvider.CONTENT_URI, values);
  Toast.makeText(getBaseContext(), "New record inserted", Toast.LENGTH_LONG)
    .show();
 }
}

Manifest.xml
?xml version="1.0" encoding="utf-8"?>


    

    
        
            
                

                
            
        
        
        
    




When designing your application, you can use styles and themes to apply uniform formatting to its various screens and UI elements.
  • A style is a set of one or more formatting attributes that you can apply as a unit to single elements in your layout XML file(s). For example, you could define a style that specifies a certain text size and color, then apply it to instances of a certain type of View element.
  • A theme is a set of one or more formatting attributes that you can apply as a unit to all activities in an application or just a single activity. For example, you could define a theme that sets specific colors for the window frame and the panel foreground and background, and sets text sizes and colors for menus, then apply it to the activities of your application.
Styles and themes are resources. Android provides some default style and theme resources that you can use, or you can declare your owncustom style and theme resources.
To create custom styles and themes:
  1. Create a file named styles.xml in the your application's res/values directory. Add a root  node.
  2. For each style or theme, add a 


Style:-

Here's an example declaration of a style:

    

As shown, you can use  elements to set specific formatting values for the style. The name attribute in the item can refer to a standard string, a hex color value, or a reference to any other resource type.
Notice the parent attribute in the 

This tutorial will cover the creating the Multiple tables in sqlite Database for that we will need to have 2 separate packages Model and helper.

Creating the Model and Helpler Class;

Next step is to create model classes for database tables just to make single row as an object. We need only two models for Tasks and Cat. For task_cat we don’t need a model class.



- Create a new class file under com.shir60bhushan.sqlite.helper package named Tasks.java and type the code like below. This is the model class for Tasks table

Task.java

package shir60bhushan.sqlite.model;



public class Task {
 

 int id;
   
 String note;
    
 int status;
   
 String created_at;

   
 
// constructors
    

public Task() {
    }

    

public Task(String note, int status) {
 
       this.note = note;
    
    this.status = status;
  
  }

   
 
public Task(int id, String note, int status)
 {
        
  this.id = id;
      
  this.note = note;
  
  this.status = status;
    }

 
  
 // setters
   
 
public void setId(int id) 
{
        this.id = id;
    }

  
  
public void setNote(String note)
 {
      
  this.note = note;
   
 }

   
 public void setStatus(int status)
 {
   
    this.status = status;
   
 }
 

  
  public void setCreatedAt(String created_at)
{
    
    this.created_at = created_at;
 
   }

   
 // getters
   
 public long getId() 
{
  
      return this.id;
   
 }


   
 public String getNote()
 {
        return this.note;
   
 }

   
 public int getStatus() 
{
        return this.status;
  
  }
}


4. Create one more model class for Cat table named Cat.java under the same package.


package shir60bhushan.sqlite.model;

public class cat {

    int id;
    String cat_name;

    // constructors
    public cat() {

    }

    public cat(String cat_name) {
        this.cat_name = cat_name;
    }

    public cat(int id, String cat_name) {
        this.id = id;
        this.cat_name = cat_name;
    }

    // setter
    public void setId(int id) {
        this.id = id;
    }

    public void setcatName(String cat_name) {
        this.cat_name = cat_name;
    }

    // getter
    public int getId() {
        return this.id;
    }

    public String getcatName() {
        return this.cat_name;
    }
}

cat.java
package com.shir60bhushan.sqlite.model;

public class cat {

    int id;
    String cat_name;

    // constructors
    public cat() {

    }

    public cat(String cat_name) {
        this.cat_name = cat_name;
    }

    public cat(int id, String cat_name) {
        this.id = id;
        this.cat_name = cat_name;
    }

    // setter
    public void setId(int id) {
        this.id = id;
    }

    public void setcatName(String cat_name) {
        this.cat_name = cat_name;
    }

    // getter
    public int getId() {
        return this.id;
    }

    public String getcatName() {
        return this.cat_name;
    }
}

Database Helper Class

Database helper class contains all the methods to perform database operations like opening connection, closing connection, insert, update, read, delete and other things. As this class is helper class, place this under helper package.
So create another class named DatabaseHelper.java under com.shir60bhushan.sqlite.helper package and extend the class from SQLiteOpenHelper

public class DatabaseHelper extends SQLiteOpenHelper {

. Add required variables like database name, database version, column names. I also executed table create statements in onCreate() method. Type the following code in DatabaseHelper.java class

DatabaseHelper.java

public class DatabaseHelper extends SQLiteOpenHelper {

    // Logcat cat
    private static final String LOG = "DatabaseHelper";

    // Database Version
    private static final int DATABASE_VERSION = 1;

    // Database Name
    private static final String DATABASE_NAME = "contactsManager";

    // Table Names
    private static final String TABLE_tasks = "tasks";
    private static final String TABLE_cat = "cats";
    private static final String TABLE_tasks_cat = "tasks_cats";

    // Common column names
    private static final String KEY_ID = "id";
    private static final String KEY_CREATED_AT = "created_at";

    // NOTES Table - column nmaes
    private static final String KEY_tasks = "tasks";
    private static final String KEY_STATUS = "status";

    // catS Table - column names
    private static final String KEY_cat_NAME = "cat_name";

    // NOTE_catS Table - column names
    private static final String KEY_tasks_ID = "tasks_id";
    private static final String KEY_cat_ID = "cat_id";

    // Table Create Statements
    // tasks table create statement
    private static final String CREATE_TABLE_tasks = "CREATE TABLE "
            + TABLE_tasks + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_tasks
            + " TEXT," + KEY_STATUS + " INTEGER," + KEY_CREATED_AT
            + " DATETIME" + ")";

    // cat table create statement
    private static final String CREATE_TABLE_cat = "CREATE TABLE " + TABLE_cat
            + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_cat_NAME + " TEXT,"
            + KEY_CREATED_AT + " DATETIME" + ")";

    // tasks_cat table create statement
    private static final String CREATE_TABLE_tasks_cat = "CREATE TABLE "
            + TABLE_tasks_cat + "(" + KEY_ID + " INTEGER PRIMARY KEY,"
            + KEY_tasks_ID + " INTEGER," + KEY_cat_ID + " INTEGER,"
            + KEY_CREATED_AT + " DATETIME" + ")";

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        // creating required tables
        db.execSQL(CREATE_TABLE_tasks);
        db.execSQL(CREATE_TABLE_cat);
        db.execSQL(CREATE_TABLE_tasks_cat);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // on upgrade drop older tables
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_tasks);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_cat);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_tasks_cat);

        // create new tables
        onCreate(db);
    }



Create, Read, Update and Delete Operations

From now on we are going to add one by one method into DatabaseHelper.class

1. Creating a Task

The function will create a task item in tasks table. In this same function we are assigning the task to a tag name which inserts a row in task_cat table.

public long createToDo(Task task, long[] cat_ids) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_TASK, task.getNote());
    values.put(KEY_STATUS, task.getStatus());
    values.put(KEY_CREATED_AT, getDateTime());

    // insert row
    long task_id = db.insert(TABLE_TASK, null, values);

    // assigning CATS to TASK
    for (long cat_id : cat_ids) {
        createTodoTag(task_id, task_id);
    }

    return task_id;
}

2. Fetching a TASK
Following will fetch a TASK from TASKS table.
SELECT * FROM TASKS WHERE id = 1;

public TASK getTASK(long TASK_id) {
    SQLiteDatabase db = this.getReadableDatabase();

    String selectQuery = "SELECT  * FROM " + TABLE_TASK + " WHERE "
            + KEY_ID + " = " + TASK_id;

    Log.e(LOG, selectQuery);

    Cursor c = db.rawQuery(selectQuery, null);

    if (c != null)
        c.moveToFirst();

    TASK td = new TASK();
    td.setId(c.getInt(c.getColumnIndex(KEY_ID)));
    td.setNote((c.getString(c.getColumnIndex(KEY_TASK))));
    td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));

    return td;
}

3. Fetching all TASKS

Fetching all tasks involves reading all task rows and adding them to a list array.
SELECT * FROM tasks;

public List getAlltasks() {
    List tasks = new ArrayList();
    String selectQuery = "SELECT  * FROM " + TABLE_task;

    Log.e(LOG, selectQuery);

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (c.moveToFirst()) {
        do {
            task td = new task();
            td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
            td.setNote((c.getString(c.getColumnIndex(KEY_task))));
            td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));

            // adding to task list
            tasks.add(td);
        } while (c.moveToNext());
    }

    return tasks;
}
dfgdgsdfg




4. Fetching all Task under a cat name

 SELECT * FROM tasks td, cats tg, task_cats tt WHERE tg.cat_name = ‘Manner’ AND tg.id = tt.cat_id AND td.id = tt.task_id;


public List getAlltasksBycat(String cat_name) {
    List tasks = new ArrayList();

    String selectQuery = "SELECT  * FROM " + TABLE_task + " td, "
            + TABLE_cat + " tg, " + TABLE_task_cat + " tt WHERE tg."
            + KEY_cat_NAME + " = '" + cat_name + "'" + " AND tg." + KEY_ID
            + " = " + "tt." + KEY_cat_ID + " AND td." + KEY_ID + " = "
            + "tt." + KEY_task_ID;

    Log.e(LOG, selectQuery);

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (c.moveToFirst()) {
        do {
            task td = new task();
            td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
            td.setNote((c.getString(c.getColumnIndex(KEY_task))));
            td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));

            // adding to task list
            tasks.add(td);
        } while (c.moveToNext());
    }

    return tasks;
}

5. Updating a task

Following function will update a task. It will update task values only, not the tag name.

public int updatetask(task task) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_task, task.getNote());
    values.put(KEY_STATUS, task.getStatus());

    // updating row
    return db.update(TABLE_task, values, KEY_ID + " = ?",
            new String[] { String.valueOf(task.getId()) });
}
6. Deleting a Task

Pass task_id to the following function to delete the task from db.

public void deleteTa(long tas_id) {

    SQLiteDatabase db = this.getWritableDatabase();

    db.delete(TABLE_Task, KEY_ID + " = ?",

            new String[] { String.valueOf(tas_id) });

}
Until now we are done creating the CRUD methods onto tasks table. Now we can start the methods required on cats table.


7. Creating cat

Following method will insert a row into cats table.



public long createcat(cat cat) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_cat_NAME, cat.getcatName());
    values.put(KEY_CREATED_AT, getDateTime());

    // insert row
    long cat_id = db.insert(TABLE_cat, null, values);

    return cat_id;
}
8. Fetching all cat names

Performing select all statement on cats table will give you list of cat names.
SELECT * FROM cats;


public List getAllcats() {
    List cats = new ArrayList();
    String selectQuery = "SELECT  * FROM " + TABLE_cat;

    Log.e(LOG, selectQuery);

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (c.moveToFirst()) {
        do {
            cat t = new cat();
            t.setId(c.getInt((c.getColumnIndex(KEY_ID))));
            t.setcatName(c.getString(c.getColumnIndex(KEY_cat_NAME)));

            // adding to cats list
            cats.add(t);
        } while (c.moveToNext());
    }
    return cats;
}

9. Updating cats
Following method will update cat.
public int updatecat(cat cat) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_cat_NAME, cat.getcatName());

    // updating row
    return db.update(TABLE_cat, values, KEY_ID + " = ?",
            new String[] { String.valueOf(cat.getId()) });
}
10. Deleting cat and tasks under the cat name Following method will delete a cat from db. This also will delete all the tasks under the cat name, but this is optional.
should_delete_all_cat_tasks = Passing true will delete all the tasks under the cat name

public void deletecat(cat cat, boolean should_delete_all_cat_tasks) {
    SQLiteDatabase db = this.getWritableDatabase();

    // before deleting cat
    // check if tasks under this cat should also be deleted
    if (should_delete_all_cat_tasks) {
        // get all tasks under this cat
        List allcattasks = getAlltasksBycat(cat.getcatName());

        // delete all tasks
        for (task task : allcattasks) {
            // delete task
            deletetask(task.getId());
        }
    }

    // now delete the cat
    db.delete(TABLE_cat, KEY_ID + " = ?",
            new String[] { String.valueOf(cat.getId()) });
}




Here is the collection of some of the secret codes common to the android platform. All of these would be entered through the phone dialer (just punch in the sequence as shown). Since most hidden menus are manufacturer specific, there’s no guarantee that they’ll work across all Androidsmartphones, but you can try them out nevertheless on your Samsung, HTC, Motorola, Sony and other devices. Be advised, though, that some of these can cause serious changes to your device’s configuration, so don’t play with something that you don’t fully understand.


At Google I/O last year, the search engine giant showcased a faster way to make network requests within an Android application by introducing the Volley networking library. Volley includes a lot of features useful for managing network requests and their response caches in a fast and easy way.
One can use Volley to run simultaneous requests on a pool of threads that can be given priority over another. In addition, it can be used to handle JSON requests, image request or files of that size and nature.
In this tutorial, we will learn how to setup Volley for Android and write a sample code to make a JSON request. 


                    




What is Async Task :
Android modifies the user interface via one thread, the so called UI Thread. If you perform a long running operation directly on the UI Thread, for example downloading a file from the internet, the user interface of your application will “freeze” until the corresponding task is finished. When this happens it is very easy for the user to perceive your application as slow.


As a concrete example of a bad implementation and what happens when a long running operation is done on the UI Thread, I want to refer to one of my previous tutorials: Creating A Simple RSS Application in Android. Well, that application is working fine, and it does what it is supposed to do – parse an XML feed and display the headlines in a ListView. The “vulnerability” of that application is that the network access is done directly on the UI Thread which makes the application to “freeze” while the XML feed is downloaded
When I created that tutorial I wanted to make it as simple as possible without dealing with more advanced topics like asynchronous tasks. The intent of tutorial was to show the working process with feeds on a high level. But I promise you, by the end of this article you will be able to fix it and have a Cool Rss App that runs smoothly! :)

To provide a good user experience all long running operations in an Android application should run asynchronously. To achieve this we will be using the AsyncTask class.

What does AsyncTask do?
AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers. 
In order to use the AsyncTask class, you must extend it and override at least thedoInBackground() method.
The most common methods you will need to implement are these:

   1. onPreExecute() – called on the UI thread before the thread starts running. This method is usually used to setup the task, for example by displaying a progress bar.

   2. doInBackground(Params…) – this is the method that runs on the background thread. In this method you should put all the code you want the application to perform in background. Referring to our Simple RSS Aplication, you would put here the code that downloads the XML feed and does the parsing. The doInBackground() is called immediately after onPreExecute(). When it finishes, it sends the result to the onPostExecute().

   3. onProgressUpdate() – called when you invoke publishProgress() in the doInBackground().

   4. onPostExecute(Result) – called on the UI thread after the background thread finishes. It takes as parameter the result received from doInBackground().

AsyncTask is a generic class, it uses 3 types: AsyncTask.

  1. Params – the input. what you pass to the AsyncTask
  2. Progress – if you have any updates, passed to onProgressUpdate()
  3. Result – the output. what returns doInBackground()



private class DownloadFilesTask extends AsyncTask { protected Long doInBackground(URL... urls) { int count = urls.length; long totalSize = 0; for (int i = 0; i < count; i++) { totalSize += Downloader.downloadFile(urls[i]); publishProgress((int) ((i / (float) count) * 100)); // Escape early if cancel() is called if (isCancelled()) break; } return totalSize; } protected void onProgressUpdate(Integer... progress) { setProgressPercent(progress[0]); } protected void onPostExecute(Long result) { showDialog("Downloaded " + result + " bytes"); } }
Once a task is created, it can be executed like this:

new DownloadTast().execute(url1, url2, urln);