Sunday 29 September 2013

MultiSelectGridview

Some good links
=============

http://vikaskanani.wordpress.com/2011/07/20/android-custom-image-gallery-with-checkbox-in-grid-to-select-multiple/
http://stackoverflow.com/questions/14375118/gridview-item-list-selector-for-multiple-items-not-working-in-android
http://www.java2s.com/Code/Android/UI/ThisdemoillustratestheuseofCHOICEMODEMULTIPLEMODALakaselectionmodeonGridView.htm
http://www.coderzheaven.com/2013/04/26/multiple-selection-listview-android/
https://github.com/paramvir-b/AndroidGridViewCompatLib
http://www.java2s.com/Code/Android/UI/ThisdemoillustratestheuseofCHOICEMODEMULTIPLEMODALakaselectionmodeonGridView.htm


1)Create class MainActivity.java
===========================
package com.coderzheaven.multipleselectiongrid;

import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Checkable;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;

public class MainActivity extends Activity {

GridView mGrid;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

loadApps();

setContentView(R.layout.grid_1);
mGrid = (GridView) findViewById(R.id.myGrid);
mGrid.setAdapter(new AppsAdapter());
mGrid.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
mGrid.setMultiChoiceModeListener(new MultiChoiceModeListener());
}

private List mApps;

private void loadApps() {
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

mApps = getPackageManager().queryIntentActivities(mainIntent, 0);
}

public class AppsAdapter extends BaseAdapter {
public AppsAdapter() {
}

public View getView(int position, View convertView, ViewGroup parent) {
CheckableLayout l;
ImageView i;

if (convertView == null) {
i = new ImageView(MainActivity.this);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ViewGroup.LayoutParams(50, 50));
l = new CheckableLayout(MainActivity.this);
l.setLayoutParams(new GridView.LayoutParams(
GridView.LayoutParams.WRAP_CONTENT,
GridView.LayoutParams.WRAP_CONTENT));
l.addView(i);
} else {
l = (CheckableLayout) convertView;
i = (ImageView) l.getChildAt(0);
}

ResolveInfo info = mApps.get(position);
i.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));

return l;
}

public final int getCount() {
return mApps.size();
}

public final Object getItem(int position) {
return mApps.get(position);
}

public final long getItemId(int position) {
return position;
}
}

public class CheckableLayout extends FrameLayout implements Checkable {
private boolean mChecked;

public CheckableLayout(Context context) {
super(context);
}

@SuppressWarnings("deprecation")
public void setChecked(boolean checked) {
mChecked = checked;
setBackgroundDrawable(checked ? getResources().getDrawable(
R.drawable.blue) : null);
}

public boolean isChecked() {
return mChecked;
}

public void toggle() {
setChecked(!mChecked);
}

}

public class MultiChoiceModeListener implements
GridView.MultiChoiceModeListener {
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.setTitle("Select Items");
mode.setSubtitle("One item selected");
return true;
}

public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return true;
}

public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return true;
}

public void onDestroyActionMode(ActionMode mode) {
}

public void onItemCheckedStateChanged(ActionMode mode, int position,
long id, boolean checked) {
int selectCount = mGrid.getCheckedItemCount();
switch (selectCount) {
case 1:
mode.setSubtitle("One item selected");
break;
default:
mode.setSubtitle("" + selectCount + " items selected");
break;
}
}

}
}
2)Create activity_main.xml
====================
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

   
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

3)Create grid_1.xml
================
android:layout_width="match_parent" 
android:layout_height="match_parent"
    android:padding="10dp"
    android:verticalSpacing="10dp"
    
    android:horizontalSpacing="10dp"
    android:numColumns="auto_fit"
    android:columnWidth="60dp"
    android:stretchMode="columnWidth"
    
    android:gravity="center"
    />

Monday 23 September 2013

CalenderLinks

http://www.androiddevelopersolution.com/2013/05/android-calendar-sync.html


http://w2davids.wordpress.com/android-simple-calendar/

http://droidwalk.blogspot.in/2012/11/android-calendar-sample.html

git hub

https://github.com/nevalla/CalendarView/blob/master/src/com/examples/android/calendar/CalendarAdapter.java

cream color bog:

http://droidwalk.blogspot.in/2012/11/android-calendar-sample.html

https://github.com/nevalla/CalendarView/blob/master/src/com/examples/android/calendar/CalendarAdapter.java



Thursday 12 September 2013

Important Links



  1. https://github.com/openaphid/android-flip

  2. http://android-3d-flip-view-transition.googlecode.com/svn/trunk/

  3. http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html
  4.  
  5. https://github.com/mtparet/Drag-And-Drop-Android
  6.  
  7. https://github.com/bauerca/drag-sort-listview
  1.  


//image magic
  1. https://gist.github.com/kmansoft/2771791
  2.  
  3. http://android-drawable-converter.googlecode.com/svn/trunk/
  1.  


-----------------------------------
GCM NOTIFICATION


  1. http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
  2.  
  3.  
  1.  
http://viralpatel.net/blogs/android-install-uninstall-shortcut-example/


//Dynamic add view in android
====================
http://android-er.blogspot.in/2013/05/add-and-remove-view-dynamically.html
http://stackoverflow.com/questions/3721963/how-to-add-calendar-events-in-android

http://www.androiddevelopersolution.com/2013/05/android-calendar-sync.html


http://w2davids.wordpress.com/android-simple-calendar/

http://droidwalk.blogspot.in/2012/11/android-calendar-sample.html

git hub

https://github.com/nevalla/CalendarView/blob/master/src/com/examples/android/calendar/CalendarAdapter.java

cream color bog:

http://droidwalk.blogspot.in/2012/11/android-calendar-sample.html

https://github.com/nevalla/CalendarView/blob/master/src/com/examples/android/calendar/CalendarAdapter.java

Dynamically add new view in android
====================================
http://android-er.blogspot.in/2013/05/add-and-remove-view-dynamically.html
http://androiddesk.wordpress.com/2012/08/05/creating-dynamic-views-in-android/
http://stackoverflow.com/questions/16942486/add-imageview-dynamically-to-existing-view


Simple notification android
===========================
http://android-er.blogspot.in/2011/04/simple-example-to-send-notification.html

=================================================
How to cofigure GCM for android push notification
=================================================
http://wiki.gxtechnical.com/commwiki/servlet/hwiki?Configuring+Google+Cloud+Messaging+for+Android,

Tuesday 3 September 2013

Login Implementation

1)create xml login.xml
==================

  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/imgapp_bg">
                    android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:gravity="center_vertical"
              android:background="@drawable/imgtop_tab">
                                android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:text="@string/login_header"
                  android:layout_marginTop="3dip"
                  android:layout_marginBottom="3dip"
                  android:gravity="center"
                  android:textColor="@color/font_color"
                  android:textSize="20dip"/>
      

                 android:layout_width="fill_parent"
          android:layout_height="fill_parent">
                        android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical">
                                  android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:layout_marginTop="10dip"
                   android:gravity="top|right">
                                         android:id="@+id/viewfocus"
                    android:layout_width="0dip"
                    android:layout_height="0dip"
                    android:focusable="true"
                    android:focusableInTouchMode="true"/>
                  
                     

                                 android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:layout_marginTop="10dip"
                   android:orientation="horizontal">
                                         android:id="@+id/edt_username"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:singleLine="true"
                      android:hint="@string/login_username"
                      android:text="manisha.savaliya@gmail.com"
                      android:layout_marginLeft="10dip"
                      android:layout_marginRight="10dip"/>
            

     
                               android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="5dip"
                  android:orientation="horizontal">
                                        android:id="@+id/edt_Password"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:hint="@string/login_pass"
                      android:layout_marginLeft="10dip"
                      android:layout_marginRight="10dip"
                      android:text="manisha"
                      android:singleLine="true"
                      android:password="true"/>
           

                              android:layout_width="fill_parent"
                  android:layout_marginTop="5dip"
                  android:layout_height="wrap_content">
                                        android:id="@+id/chkbox_remember_psw"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginLeft="10dip"
                      android:layout_marginRight="10dip"
                      android:checked="true"         
                      android:textColor="@color/font_color"   
                      android:text="@string/login_remember_me"
                      />
           

     
                              android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="5dip"
                  android:orientation="horizontal">
                 

       

     


2)Create a java file named Login.java
===================================
package com.example.login;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class Login extends Activity implements OnClickListener{
    private Button btnSignUp,btnLogin;
    private CheckBox chk_Remember=null;
    private EditText edtUserName,edtPassword;
    private String uName, mPswd;
    private boolean remember_me = false;
    private    SOAPService mSoapService = null;
    private View viewfocus=null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        GetBasicData();
    }
   
    /*
     * Method Name : getBasicData()
     * User of Method : this methiod is used for mainly initilize the variable and memory*/   
    public void GetBasicData(){
        btnSignUp = (Button)findViewById(R.id.btnSignUp);
        btnSignUp.setOnClickListener(this);
        btnLogin = (Button)findViewById(R.id.btnLogin);
        btnLogin.setOnClickListener(this);
        chk_Remember = (CheckBox)findViewById(R.id.chkbox_remember_psw);
        edtUserName = (EditText)findViewById(R.id.edt_username);
        edtPassword = (EditText)findViewById(R.id.edt_Password);
       
        SharedPreferences get_remember_password = getSharedPreferences(Constant.SHAREDPREFERENCES, MODE_WORLD_READABLE);
        uName = get_remember_password.getString(Constant.USERNAME, "" );
        mPswd = get_remember_password.getString(Constant.PASSWORD, "" );
       
        if(!uName.equals("") || !mPswd.equals("")){
            edtUserName.setText( uName );
            edtPassword.setText( mPswd );
        }
    }
    /*
     * Method Name : remember Password
     * Use :    for remember password*/   
    private void remember_password(boolean remember){
        SharedPreferences mSharePref_password = getSharedPreferences(Constant.SHAREDPREFERENCES, MODE_WORLD_WRITEABLE);
        SharedPreferences.Editor mSharePref_pass_edit = mSharePref_password.edit();
       
        if( remember ){
            mSharePref_pass_edit.putString(Constant.USERNAME, edtUserName.getText().toString().trim() );
            mSharePref_pass_edit.putString(Constant.PASSWORD, edtPassword.getText().toString().trim() );
            mSharePref_pass_edit.commit();
           
        }else{
            mSharePref_pass_edit.putString(Constant.USERNAME, "");
            mSharePref_pass_edit.putString(Constant.PASSWORD, "");
            mSharePref_pass_edit.commit();           
        }
    }       
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
       
        if(v==btnLogin){
            if(edtUserName.getText().toString().equals("") || edtPassword.getText().toString().equals("")){
                Toast.makeText(this, Html.fromHtml(Constant.FILL_ALL_THE_FIELD), Toast.LENGTH_SHORT).show();
            }
            else{
                if(GlobalClass.isEmailValid(edtUserName.getText().toString()))
                {
                        if( chk_Remember.isChecked() ){
                            remember_me = true;
                            remember_password( remember_me );
                           
                        }else{
                            remember_me = false;
                            remember_password( remember_me );   
                        }   
                        if(GlobalClass.CheckNetwork(this)){
                            new getDataFromSoapWebService().execute("DATA_FROM_WEB");
                        }
                }
                else
                {
                    Toast.makeText(this,Html.fromHtml(Constant.REGISTER_VALID_EMAILID), Toast.LENGTH_SHORT).show();
                }
            }
        }
        else if(v==btnSignUp){
            Intent iv = new Intent(this,Register.class);
            startActivity(iv);
            finish();
        }
    }
//*******************************************************************************************************************************
    private class getDataFromSoapWebService extends AsyncTask {
        private ProcessDialog mProcessDialog = null;
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            mProcessDialog = new ProcessDialog(Login.this, "Login", Constant.LOADING);
            super.onPreExecute();
        }
       
        @Override
        protected String doInBackground(String... params) {
            String SOAP_URL         =     getResources().getString(R.string.Webservice_URL);
            String SOAP_ACTION         =    getResources().getString(R.string.SOAP_Action);
            String SOAP_NAMESPACE     =    getResources().getString(R.string.SOAP_NAMESPACE);
            String SOAP_METHOD        =    "validateLogin";

            mSoapService = new SOAPService(SOAP_URL, SOAP_ACTION, SOAP_NAMESPACE, SOAP_METHOD);       
            String keyName[] = {"username","password"};                       
            Object keyValue[]  = { edtUserName.getText().toString().trim() , edtPassword.getText().toString().trim() };
                   
            return mSoapService.getSoapData(keyName, keyValue);
        }
       
        @Override
        protected void onPostExecute(String result) {
            mProcessDialog.dismiss();
            if( result != null){
                JSONObject job_login=null;
                JSONObject json_user=null;
                String Status="",USERID="",LANGID="",LANGUAGE="";
               
                System.out.println("Login Response "  + result);
               
                try {
                    job_login = new JSONObject(result);
                    Status=job_login.getString("SUCCESS").toString();
                    USERID=job_login.getString("ID").toString();
                    LANGUAGE=job_login.getString("LANGUAGE").toString();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
               
                    if(job_login != null){
                        if(Status.equals("OK") ){
                       
                             try {
                                json_user=job_login.getJSONObject("USER");
                                LANGID=json_user.getString("pref_lang_id").toString();
                               
                                SharedPreferences spLoginUserDetails = getSharedPreferences(Constant.SHAREDPREFERENCES, MODE_WORLD_WRITEABLE);
                                SharedPreferences.Editor spEdit_Login_Details = spLoginUserDetails.edit();
                                spEdit_Login_Details.putString(Constant.USER_ID, USERID);
                                spEdit_Login_Details.putString(Constant.PREF_LANG_ID,LANGID);
                                spEdit_Login_Details.putString(Constant.PREF_LANG_NAME,LANGUAGE);
                                spEdit_Login_Details.commit();
                               
                                new GetCommunityListData().execute();
                               
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                           
//                                            if(json_user!=null){
//                                                try {
//                                                    jon_array=json_user.getJSONArray("COMMUNITY");
//                                                } catch (JSONException e) {
//                                                    e.printStackTrace();
//                                                }
//                                                if(jon_array!=null){
//                                                     
//                                                      for(int i=0;i//                                                             try {
//                                                                JsonObjectid=jon_array.getJSONObject(i);
//                                                            } catch (JSONException e) {
//                                                                e.printStackTrace();
//                                                            }
//                                                             if(JsonObjectid!=null){
//                                                                 String strcommunity_id="";
//                                                                try {
//                                                                    strcommunity_id = JsonObjectid.getString("id").toString();
//                                                                } catch (JSONException e) {
//                                                                    e.printStackTrace();
//                                                                }
//                                                                 Constant.alstTempCommunityID.add(strcommunity_id);
//                                                                 System.out.println("community id" + strcommunity_id);
//                                                             }
//                                                      }                                               
//   
//                                                }
//                                            }   
                           
                                               
                        }else{                                       
                            Toast.makeText(Login.this, Html.fromHtml(Constant.USERNAMEPASSWORD),Toast.LENGTH_SHORT).show();                                           
                        }
                    }
            }
            else{
                Toast.makeText(Login.this, Html.fromHtml(Constant.SERVERCONNERROR),Toast.LENGTH_SHORT).show();
            }

        super.onPostExecute(result);
        }
    }
//*******************************************************************************************************************************
//This function is used for get community
private class GetCommunityListData extends AsyncTask {
    private ProcessDialog mProcesCommunityDialog = null;
    @Override
    protected void onPreExecute() {
        mProcesCommunityDialog = new ProcessDialog(Login.this, "Community", Constant.LOADING);
        super.onPreExecute();
    }
   
    @Override
    protected String doInBackground(String... UserID) {
        String SOAP_URL         =     getResources().getString(R.string.Webservice_URL);
        String SOAP_ACTION         =    getResources().getString(R.string.SOAP_Action);
        String SOAP_NAMESPACE     =    getResources().getString(R.string.SOAP_NAMESPACE);
        String SOAP_METHOD        =    "GetMethodTable";
       
        SharedPreferences mReadSPreferences=getSharedPreferences(Constant.SHAREDPREFERENCES,MODE_WORLD_READABLE);   
        String strUserID = mReadSPreferences.getString(Constant.USER_ID, "");
       
        mSoapService = new SOAPService(SOAP_URL, SOAP_ACTION, SOAP_NAMESPACE, SOAP_METHOD);           
        String keyName[] = {"user_id"};                               
        Object keyValue[]  = {strUserID};   

        return mSoapService.getSoapData(keyName, keyValue);   
    }
    @Override
    protected void onPostExecute(String result) {
        mProcesCommunityDialog.dismiss();
                if(result != null){
                    String strSuccess,strMessage;
                    try {
                        System.out.println("Community Response : " + result);
                        JSONObject json_Community = new JSONObject(result);
                        if(json_Community != null)
                        {
                            strSuccess = json_Community.getString("SUCCESS").toString();
                            if(strSuccess.equals("OK")){
                                JSONArray jsonArray_CommunityList = json_Community.getJSONArray("COMMUNITY");
                                if(jsonArray_CommunityList!=null){
                                    OpenDatabase();
                                    mDbHelper.DeleteCommunityList(mSQLiteDatabase);
                                    for(int i=0;i                                        JSONObject jsonCommunity_attribute=jsonArray_CommunityList.getJSONObject(i);
                                        if(jsonCommunity_attribute!=null){
                                            int id =jsonCommunity_attribute.getInt("id");
                                         
                                            int level=jsonCommunity_attribute.getInt("level");
                                            String name=jsonCommunity_attribute.getString("name").toString();
                                            String status=jsonCommunity_attribute.getString("status").toString();
                                        
                                            mDbHelper.InsertCommunityList(mSQLiteDatabase, id, level, name, status);
                                        }
                                    }
                                    CloseDataBase();   
                                    new GetCategoryListData().execute("");   
                                }                                   
                            }
                            else{
                                strMessage = json_Community.getString("MESSAGE").toString();
                                Toast.makeText(Login.this, Html.fromHtml(strMessage), Toast.LENGTH_LONG).show();                               
                            }
                        }
                    } catch ( Exception e ) {
                        e.printStackTrace();
                    }
                }
                else{
                    Toast.makeText(Login.this, Html.fromHtml(Constant.SERVERCONNERROR),Toast.LENGTH_SHORT).show();
                }
                super.onPostExecute(result);
            }               
    }

//*******************************************************************************************************************************   
////This class is used for get Category List
private class GetCategoryListData extends AsyncTask {
    private ProcessDialog mProcesCategoryDialog = null;
    @Override
    protected void onPreExecute() {
        mProcesCategoryDialog = new ProcessDialog(Login.this, "Category", Constant.LOADING);
        super.onPreExecute();
    }
   
    @Override
    protected String doInBackground(String... params) {
        String SOAP_URL         =     getResources().getString(R.string.Webservice_URL);
        String SOAP_ACTION         =    getResources().getString(R.string.SOAP_Action);
        String SOAP_NAMESPACE     =    getResources().getString(R.string.SOAP_NAMESPACE);
        String SOAP_METHOD        =    "GetCategoryTable";

        SharedPreferences mReadSPreferences=getSharedPreferences(Constant.SHAREDPREFERENCES,MODE_WORLD_READABLE);   
        String strUserID = mReadSPreferences.getString(Constant.USER_ID, "");
       
        mSoapService = new SOAPService(SOAP_URL, SOAP_ACTION, SOAP_NAMESPACE, SOAP_METHOD);           
        String keyName[] = {"user_id"};                               
        Object keyValue[]  = {strUserID};   

        return mSoapService.getSoapData(keyName, keyValue);   
    }
    @Override
    protected void onPostExecute(String result) {
        mProcesCategoryDialog.dismiss();
        if(result != null){
            String strSuccess,strMessage;
            try {
                System.out.println("Category Response : " + result);
                JSONObject json_Category = new JSONObject(result);
                if(json_Category != null)
                {
                    strSuccess = json_Category.getString("SUCCESS").toString();
                    if(strSuccess.equals("OK")){
                        JSONArray jsonArray_CategoryList = json_Category.getJSONArray("CATEGORY");
                        if(jsonArray_CategoryList!=null){
                            OpenDatabase();
                            mDbHelper.DeleteCategoryList(mSQLiteDatabase);
                            for(int i=0;i                                JSONObject jsonCategory_attribute=jsonArray_CategoryList.getJSONObject(i);
                                if(jsonCategory_attribute!=null){
                                    int id =jsonCategory_attribute.getInt("id");
                                        int level=jsonCategory_attribute.getInt("level");
                                    String name=jsonCategory_attribute.getString("name").toString();
                                    String status=jsonCategory_attribute.getString("status").toString();                                                                           mDbHelper.InsertCategoryList(mSQLiteDatabase, id, level, name, status);
                                }
                            }
                            CloseDataBase();
                           
                            Intent in = new Intent(Login.this, HomeScreen.class);
                            startActivity(in);
                            finish();
                        }
                       
                    }
                    else{
                        strMessage = json_Category.getString("MESSAGE").toString();
                        Toast.makeText(Login.this, Html.fromHtml(strMessage), Toast.LENGTH_LONG).show();                               
                    }
                }
            } catch ( Exception e ) {
                e.printStackTrace();
            }
        }
        else{
            Toast.makeText(Login.this, Html.fromHtml(Constant.SERVERCONNERROR),Toast.LENGTH_SHORT).show();
        }
        super.onPostExecute(result);
    }               
}
       
//*******************************************************************************************************************************
//For open & close database
    private DbHelper mDbHelper=null;
    private SQLiteDatabase mSQLiteDatabase=null;
    private void OpenDatabase()
    {   
            mDbHelper = new DbHelper(this);
            mSQLiteDatabase = mDbHelper.getWritableDatabase();
            mSQLiteDatabase.setLockingEnabled(true);
    }
    private void CloseDataBase()
    {
        if(mDbHelper!=null && mSQLiteDatabase!=null){
            if(mSQLiteDatabase.isOpen()){
                mSQLiteDatabase.close();
                mDbHelper.close();
            }
        }
    }
}