Thursday 19 November 2015

Google Map With Live Navigation


This is a simple tutorial of Google Map Integration with out use of Google play service library . While developing with Google_playservice_lib , getting some heap memory issue.  This tutorial help you to integrate Google Map without API-KEY/Library . Simple !!!


Screens :-



    



                                  





Wednesday 18 November 2015

Base Adapter with Custom Layout


This is a simple tutorial  will explain , how to use Custom layouts inside Base Adapter.
Along with this , attached bunch of custom file with one Note file.  Just follow the instruction and do it. Simple !!! :-)


Click here to Download files



Tuesday 17 November 2015

Download HTML-Sides/HTML-Contents Directly using HTTP Request.

Simple HTTP Request call to access Web Content




This tutorial explains how Call simple HTTP Request using asynctask.  Can download HTML-Sides/HTML-Contents Directly from network

Sunday 18 October 2015

Pinch zoom On Image


**********************************************************************************

This tutorial explains how to build  your android applications with swipe and pinch zooming functionality using GestureImageView Library.
Click Here for Library - Gesture-Library

In this Example , we are inflating custom layout inside Oncreate method inside Activity .

Click here for sample Layout and function call from activity. 
Click here for sample files   - Sample layout $ function call

**********************************************************************************


Features:
  1. Pinch zoom in place (i.e. zoom occurs from point of touch)
  2. Panning with fling gesture
  3. Double tap zoom
  4. Configurable zoom boundaries (min/max).
**********************************************************************************

Monday 28 September 2015

Useful Online Links For Android Development :- )


What is Android Color Generator?

It is a free online tool which helps you to create colors.xml. A color name and value are defined in colors.xml which will be used in Android applications to apply colors to Views.
With the help of this tool, you can generate colors.xml with upto 50 colors at a time.

Online Link   :    Click here

==========================================================



What is Android Layout Finder ?

The Android Layout Finder helps you create the code that ties your Android UI and Java code together.
It's real easy! Just paste your Android XML layout code in the first text field, pick the views that you need, and your code is automatically generated for you.

Online Link   :     Click here

==========================================================

Sunday 13 September 2015

Custom Toast Alert :-)



In this example creating a custom toast alert.
android.widget.Toast class used to create toast alert message.
Toast alert is a notification message that display for certain amount of time, and automatically fades out after set time. 

Use
To show alert message to user.
To debugging your application.
To show alert from background service,broadcast,receiver,getting data from server...etc.






To access toast_border.xml - Click here Toast_Border
To access toast_border.xml - Click here Toast
 Function to call the customeToast from activity class- Calltoast();


public void Calltoast(){
Context context = getApplicationContext();
        // Create layout inflator object to inflate toast.xml file
        LayoutInflater inflater = getLayoutInflater();           
        // Call toast.xml file for toast layout 
        View toastRoot = inflater.inflate(R.layout.toast, null);       
        Toast toast = new Toast(context);      
        // Set layout to toast 
        toast.setView(toastRoot);
        toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL,
                0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.show();
}







Sunday 6 September 2015

Speech to Test Conversion


What is Speech Recognition?


Speech Recognition is a technology that allows the Mobile device to identify and understand words spoken by a person using a microphone. The ultimate goal of the technology is to be able to produce a system that can recognize with 100% accuracy all words that are spoken by any person.

Even after years of research in this area, the best speech recognition software applications still cannot recognize speech with 100% accuracy. Some applications are able to recognize over 90% of words when spoken under specific constraints regarding content and previous training to recognize the speaker's speech characteristics.

Android API , that understands your speech enables you to have conversations with Mobile device. These conversations would include you and the device speaking as commands or in response to events, input, or other feedback.

Speaking is easier and more intuitive than selecting buttons in keyboards. Human speech has evolved over many thousands of years to become an efficient method of sharing information and giving instructions.





GUI Components - 

Image Button ( call promptSpeechInput())
Text view Button ( To show the result) 


// Showing google speech input dialog (This function should call from Image button click event)
     
    private void promptSpeechInput() {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
        RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
        getString("Say something"+…));
        try {
           startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
        }  
            catch (ActivityNotFoundException a) {
            Toast.makeText(getApplicationContext(),
            getString("Sorry! Your device doesn\'t support speech input"),
            Toast.LENGTH_SHORT).show();
        }
    }


  // Receiving speech input     

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
        case REQ_CODE_SPEECH_INPUT: 
           {
          if (resultCode == RESULT_OK && null != data) {
         ArrayList<String> result = 
         data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
         txtSpeechInput.setText(result.get(0));
            }
            break;
        }
        }
    }


Thursday 13 August 2015

Signature Option in Android



  1. CREATE NEW ACTIVITY (SIGNATURE) --- SHOULD DECLARE IN MANIFEST.XML
  2. USING (startActivityForResult ()) CALL SIGNATURE ACTIVITY
  3. SAVE SIGNATURE PNG IN MEDIA STORAGE. 
  4. CONVERT .PNG FILE TO BASE64 FORMAT FOR EASY SHARE  
  5. SEND BACK TO MAIN ACTIVITY WITH BUNDLE VALUE 
  6. ACCESS THE BUNDLE VALUE USING (onActivityResult) FOR PROCESS.




Friday 17 April 2015

Image Upload from Android device and save/send as base64String type

Declare and initilize before OnCreate

private static int RESULT_LOAD_IMG = 1;
String imgDecodableStringPath; // file path


Inside Oncreate - Button clickevent

// Create intent to Open Image applications like Gallery,Google//Photos
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);


OutSide Oncreate

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
            try {
                  // When an Image is picked
      if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
                              && null != data) {
                        // Get the Image from data
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
// Get the cursor
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgDecodableStringPath = cursor.getString(columnIndex);
cursor.close();
Log.v("Path of Image file ->", imgDecodableStringPath);
/*
 * Step 1 - Converting File into BitMap Step 2 - Converting
 * Bitmap into ByteArray Step 3- Converting Byte Array into
 * Base64DataString
 */

Utility.getBytes((BitmapFactory.decodeFile(imgDecodableStringPath)));
String Base64DataSring = Base64.encodeToString(Utility.getBytes((BitmapFactory
.decodeFile(imgDecodableStringPath))),Base64.DEFAULT);
Log.v("Base64DataSring String ->", Base64DataSring);
} else {
Toast.makeText(this, "You haven't picked Image",
                                    Toast.LENGTH_LONG).show();
}    
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
                              .show();
            }

      }


=============================================




Utility.java



public class Utility {
      // convert from bitmap to byte array
      public static byte[] getBytes(Bitmap bitmap) {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(CompressFormat.PNG, 0, stream);
            return stream.toByteArray();
      }

      // convert from byte array to bitmap
      public static Bitmap getPhoto(byte[] image) {
            return BitmapFactory.decodeByteArray(image, 0, image.length);
      }
}







Wednesday 28 January 2015

Building an Android Application Using Parse

PART 1

1. Create Account in Parse.com

2. Create New application from Dashboard console
3. Go to - >"Settings" - > "Keys" can see Application ID and Clint ID .




PART 2

1. Download External Libraries from  https://parse.com/downloads/android/Parse/latest


PART 3

1. Create new application in Eclipse with min SDK version 14

2. Put External all .jar files (will get from Parse-1.5.2.zip) inside libs folder. then build application.



3. Add permission on application manifest file.

 <uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />



4. Create one new java Class . Here Task.java

import com.parse.ParseClassName;

import com.parse.ParseObject;

@ParseClassName("Task")

public class Task extends ParseObject{
  public Task(){

  }

  public boolean isCompleted(){
      return getBoolean("completed");
  }
  public void setCompleted(boolean complete){
      put("completed", complete);
  }
  public String getDescription(){
      return getString("description");
  }
  public void setDescription(String description){
      put("description", description);
  } }



5. Create one new java class to fetch data from server . Here TaskAdapter

import java.util.List;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class TaskAdapter extends ArrayAdapter<Task> {

  private Context mContext;
  private List<Task> mTasks;

  public TaskAdapter(Context context, List<Task> objects) {

      super(context, R.layout.task_row_item, objects);
      this.mContext = context;
      this.mTasks = objects;
  }
  public View getView(int position, View convertView, ViewGroup parent){
      if(convertView == null){
          LayoutInflater mLayoutInflater = LayoutInflater.from(mContext);
          convertView = mLayoutInflater.inflate(R.layout.task_row_item, null);
      }

      Task task = mTasks.get(position);


      TextView descriptionView = (TextView) convertView.findViewById(R.id.task_description);


      descriptionView.setText(task.getDescription());


      if(task.isCompleted()){

          descriptionView.setPaintFlags(descriptionView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
      }else{
          descriptionView.setPaintFlags(descriptionView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
      }
      return convertView;
  }
}



6. Create activity . Here "Todoactivity.java"  & Activity_todo.xml





7. Replace Activity_todo.xml file with given structure .

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:weightSum="2"
    tools:context=".TodoActivity" >

    <ListView

        android:id="@+id/task_list"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:stackFromBottom="true"
        android:layout_weight="1" />

    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <EditText

            android:id="@+id/task_input"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:hint="Enter a Task"
            android:inputType="text" >
            <requestFocus />
        </EditText>

        <Button

            android:id="@+id/submit_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="createTask"
            android:text="Submit" />
    </LinearLayout>

</LinearLayout>




8. Create new xml file to show DB data in listview . Here "task_row_item.xml"

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="horizontal" >

    <TextView

        android:id="@+id/task_description"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>







9. Add below functions in OnCreate method of TodoActivity.java

 Parse.initialize(this, //Application ID, //Client ID);

        ParseAnalytics.trackAppOpened(getIntent());
        ParseObject.registerSubclass(Task.class);
       
        TaskInput = (EditText) findViewById(R.id.task_input);
        ListView = (ListView) findViewById(R.id.task_list);
            
        mAdapter = new TaskAdapter(this, new ArrayList<Task>());
        ListView.setAdapter(mAdapter);
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
          @Override
         public void run() {
          // TODO Auto-generated method stub
           runOnUiThread(new  Runnable() {
           public void run() {
            if(questionInterval == 5) {
             questionInterval = 0;
            }       
            questionInterval++;
            updateData();
           
           }
          });
     
         }
        }, 1000, 1000);


10. Add below function after OnCreate method

 public void createTask(View v) {

        if (TaskInput.getText().length() > 0){
            Task t = new Task();
            t.setDescription(name +":" +TaskInput.getText().toString());
            t.setCompleted(false);
            t.saveEventually();
            TaskInput.setText("");
        }
    }
   
    public void updateData(){
       ParseQuery<Task> query = ParseQuery.getQuery(Task.class);
       query.findInBackground(new FindCallback<Task>() {
             
           @SuppressWarnings("static-access")
   @Override
           public void done(List<Task> tasks, ParseException error) {
               if(tasks != null){
                   mAdapter.clear();
                   mAdapter.addAll(tasks);
                   ListView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
               }
           }
       });
     }
   
===================================








Tuesday 6 January 2015

Find Location (Geolocation,Address)



Requirements  :


1. import library project. 
Eg: (E:\Android Setup\sdk\extras\google\google_play_services\libproject\google-play-services_lib).
2.Add reference with main project .
3.XML file to show the result.
4.Java class to access location.


public class MainActivity extends Activity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener

{

  LocationClient mLocationClient;
  private TextView addressLabel;
  private TextView locationLabel;
  private Button getLocationBtn;

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

      locationLabel = (TextView) findViewById(R.id.locationLabel);
     addressLabel = (TextView) findViewById(R.id.addressLabel);
     getLocationBtn = (Button) findViewById(R.id.getLocation);

     getLocationBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
           displayCurrentLocation();
        }
     });
 
     // Create the LocationRequest object
     mLocationClient = new LocationClient(this, this, this);
  }
  @Override
  protected void onStart() {
     super.onStart();
     // Connect the client.
     mLocationClient.connect();
     locationLabel.setText("Got connected....");
  }
  @Override
  protected void onStop() {
     // Disconnect the client.
     mLocationClient.disconnect();
     super.onStop();
     locationLabel.setText("Got disconnected....");
  }
  @Override
  public void onConnected(Bundle dataBundle) {
     // Display the connection status
     Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
  }
  @Override
  public void onDisconnected() {
     // Display the connection status
     Toast.makeText(this, "Disconnected. Please re-connect.",
     Toast.LENGTH_SHORT).show();
  }
  @Override
  public void onConnectionFailed(ConnectionResult connectionResult) {
     // Display the error code on failure
     Toast.makeText(this, "Connection Failure : " +
     connectionResult.getErrorCode(),
     Toast.LENGTH_SHORT).show();
  }
  public void displayCurrentLocation() {
     // Get the current location's latitude & longitude
     Location currentLocation = mLocationClient.getLastLocation();
     String msg = "Current Location: " +
     Double.toString(currentLocation.getLatitude()) + "," +
     Double.toString(currentLocation.getLongitude());
   
     // Display the current location in the UI
     locationLabel.setText(msg);
   
     // To display the current address in the UI
     (new GetAddressTask(this)).execute(currentLocation);
  }
  /*
   * Following is a subclass of AsyncTask which has been used to get
   * address corresponding to the given latitude & longitude.
   */
  private class GetAddressTask extends AsyncTask<Location, Void, String>{
     Context mContext;
     public GetAddressTask(Context context) {
        super();
        mContext = context;
     }

     /*
      * When the task finishes, onPostExecute() displays the address.
      */
     @Override
     protected void onPostExecute(String address) {
        // Display the current address in the UI
        addressLabel.setText(address);
     }
     @Override
     protected String doInBackground(Location... params) {
        Geocoder geocoder =
        new Geocoder(mContext, Locale.getDefault());
        // Get the current location from the input parameter list
        Location loc = params[0];
        // Create a list to contain the result address
        List<Address> addresses = null;
        try {
           addresses = geocoder.getFromLocation(loc.getLatitude(),
           loc.getLongitude(), 1);
        } catch (IOException e1) {
           Log.e("LocationSampleActivity",
           "IO Exception in getFromLocation()");
           e1.printStackTrace();
           return ("IO Exception trying to get address");
        } catch (IllegalArgumentException e2) {
           // Error message to post in the log
           String errorString = "Illegal arguments " +
           Double.toString(loc.getLatitude()) +
           " , " +
           Double.toString(loc.getLongitude()) +
           " passed to address service";
           Log.e("LocationSampleActivity", errorString);
           e2.printStackTrace();
           return errorString;
        }
        // If the reverse geocode returned an address
        if (addresses != null && addresses.size() > 0) {
           // Get the first address
           Address address = addresses.get(0);
           /*
           * Format the first line of address (if available),
           * city, and country name.
           */
           String addressText = String.format(
           "%s, %s, %s",
           // If there's a street address, add it
           address.getMaxAddressLineIndex() > 0 ?
           address.getAddressLine(0) : "",
           // Locality is usually a city
           address.getLocality(),
           // The country of the address
           address.getCountryName());
           // Return the text
           return addressText;
        } else {
           return "No address found";
        }
     }
  }// AsyncT

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

}


XML LAYOUT

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/getLocation"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/get_location" />

    <TextView
        android:id="@+id/locationLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/addressLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>






How to do text writing animation?  In Android Development we do not have the option to use any other custom font in our default Tex...