Tuesday, 23 January 2018

ConstraintLayout CheatSheet


1. Constraint Parent

<?xml
version="1.0"
encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"

   xmlns:app="http://schemas.android.com/apk/res-auto"

   xmlns:tools="http://schemas.android.com/tools"

   android:layout_width="match_parent"

   android:layout_height="match_parent"

   tools:context="slider.app.com.constraintapp.MainActivity">
</android.support.constraint.ConstraintLayout>
2. Type of Constraint of current view – Must use of to use margin, padding and more


app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/idTv1"
app:layout_constraintEnd_toEndOf="parent"
3. Layout Margin

android:layout_margin="16dp"
or
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
or
android:layout_marginLeft="16dp"
android:layout_marginRight="20dp"
or
android:layout_marginHorizontal="20dp"
android:layout_marginVertical="20dp"
or
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/idBottomView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintLeft_toLeftOf="@+id/idBottomView"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintRight_toRightOf="@+id/idBottomView"
app:layout_constraintRight_toLeftOf="parent"
Note
-
The
designer creates android:layout_marginLeft
when
you move the button, but android:layout_marginStart
4.
Padding 
android:padding="16dp"
android:paddingStart="16dp"
android:paddingTop="16dp"
android:paddingEnd="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:includeFontPadding="true"
5.
Bias
A.
Horizontal Bias
app:layout_constraintHorizontal_bias="0.3"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
A.
Vertical Bias
app:layout_constraintVertical_bias="0.8"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
6.
 layout_editor_absolute position
tools:layout_editor_absoluteY="50dp"
tools:layout_editor_absoluteX="40dp"
7.
Ratio
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="parent"
or
android:layout_width="0dp"
android:layout_height="0dp"

   app:layout_constraintDimensionRatio="H,3:1"

   app:layout_constraintBottom_toBottomOf="parent"
   
app:layout_constraintTop_toTopOf="parent"
8.
Chain Style
<?xml
version="1.0"
encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"

   xmlns:app="http://schemas.android.com/apk/res-auto"

   android:layout_width="match_parent"

   android:layout_height="match_parent">

   <Button

       android:id="@+id/view1"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:text="View
1"

       app:layout_constraintVertical_chainStyle="spread"

       app:layout_constraintTop_toTopOf="parent"

       app:layout_constraintBottom_toTopOf="@+id/view2"

       app:layout_constraintRight_toRightOf="parent"

       app:layout_constraintLeft_toLeftOf="parent"
/>

   <Button

       android:id="@+id/view2"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:text="View
2"

       app:layout_constraintTop_toBottomOf="@+id/view1"

       app:layout_constraintBottom_toTopOf="@+id/view3"

       app:layout_constraintVertical_chainStyle="packed"

       app:layout_constraintRight_toRightOf="parent"

       app:layout_constraintLeft_toLeftOf="parent"
/>

   <Button

       android:id="@+id/view3"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:text="View
3"

       app:layout_constraintTop_toBottomOf="@+id/view2"

       app:layout_constraintBottom_toBottomOf="parent"

       app:layout_constraintVertical_chainStyle="packed"

       app:layout_constraintRight_toRightOf="parent"

       app:layout_constraintLeft_toLeftOf="parent"
/>
</android.support.constraint.ConstraintLayout>


9.
GuideLine
<android.support.constraint.Guideline

   android:id="@+id/guideline"

   android:layout_width="wrap_content"

   android:layout_height="wrap_content"

   app:layout_constraintGuide_begin="192dp"

   android:orientation="vertical"/>
<TextView

   android:id="@+id/max_width_demo_view"

   android:layout_width="0dp"

   android:layout_height="wrap_content"

   app:layout_constraintLeft_toLeftOf="parent"

   app:layout_constraintRight_toRightOf="parent"

   app:layout_constraintRight_toLeftOf="@id/guideline"

   app:layout_constraintTop_toTopOf="parent"

   android:padding="8dp"

   android:text="Text
emulating maxWidth of 192dp" />
<TextView

   android:id="@+id/min_width_demo_view"

   android:layout_width="0dp"

   android:layout_height="wrap_content"

   app:layout_constraintLeft_toLeftOf="parent"

   app:layout_constraintRight_toRightOf="parent"

   app:layout_constraintLeft_toRightOf="@id/guideline"

   app:layout_constraintTop_toBottomOf="@id/max_width_demo_view"

   android:padding="8dp"
    android:text="Text
emulating minWidth of 192dp" />


22
22
22











22

Tuesday, 2 January 2018

Fragment Precise Tutorial



URL : http://abhiandroid.com/ui/fragment-lifecycle-example-android-studio.html

Fragment means isolated or incomplete part of something.

Android introduced fragments in Android 3.0 (API level 11), primarily to support more dynamic and flexible UI designs on large screens

Some of feature are - 

  • Modularity: Dividing complex activity code across fragments for better organization and maintenance.
  • Reusability: Placing behavior or UI parts into fragments that can be shared across multiple activities.
  • Adaptability: Representing sections of a UI as different fragments and utilizing different layouts depending on screen orientation and size.

Method of Fragment

1. onAttach()
2. onCreate()
3. onCreateView()
4. onViewCreated()
5. onActivityCreated()
6. onStart()
7. onResume()
8. onPause()
9. onStop()
10. onDestroyView()
11. onDestroy()
12. onDetach()

-> LifeCycle method of Fragment

Case 1 : When Activity created and fragment attach.

1. First Activity onCreate() event
2. first Fragment onAttach() event
3. First Activity onAttachFragment() event
4. first Fragment onCreate() event
5. first Fragment onCreateView() event
6. first Fragment onViewCreated() event
7. first Fragment onActivityCreated() event
8. first Fragment onStart() event
9. First Activity onStart() event
10. First Activity onPostCreate() event
11. First Activity onResume() event
12. first Fragment onResume() event
13. First Activity onPostResume() event

Case 2 : When one fragment replace another fragment.

1. First Fragment onPause() event
2. First Fragment onStop() event
3. First Fragment onDestroyView() event
4. First Fragment onDestroy() event
5. First Fragment onDetach() event
6. Second Fragment onAttach() event
7. First Activity onAttachFragment() event
8. Second Fragment onCreate() event
9. Second Fragment onCreateView() event
10. Second Fragment onViewCreated() event
11. Second Fragment onActivityCreated() event
12. Second Fragment onStart() event
13. Second Fragment onResume() event

Case 3 : Remove fragment.

Fragment onPause() event
Fragment onStop() event
Fragment onDestroyView() event
Fragment onDestroy() event
Fragment onDetach() event

-> Fragment Transaction

STATIC
Case 1 : Add static fragment

<fragment
 android:name="slider.app.com.appsfortest.FirstFragment"
 android:id="@+id/idFirstFragment"
 android:layout_width="match_parent"
 android:layout_height="300dp"/>

DYNAMIC
Case 1 : Adding Fragment

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.idContainer, firstFragment);
fragmentTransaction.commit();

ShortCut

getSupportFragmentManager().beginTransaction().add(R.id.idContainer, firstFragment).commit();

Case 2 : Replacing Fragment

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.idContainer, secondFragment);
fragmentTransaction.commit();

ShortCut

getSupportFragmentManager().beginTransaction().replace(R.id.idContainer, secondFragment).commit();

Case 3 : Remove Fragment

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.remove(secondFragment);
fragmentTransaction.commit();

ShortCut

getSupportFragmentManager().beginTransaction().remove(secondFragment).commit();

-> Fragment to AddToBackStack() method

Definition : Re-attach a fragment after it had previously been detached from the UI with detach(Fragment). This causes its view hierarchy to be re-created, attached to the UI, and displayed.

Parameter - An optional name for this back stack state, or null.

Case 1 : null parameter

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.idContainer, new FirstFragment());
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();

Case 2 : With parameter and tag

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.idContainer, new FirstFragment(), "FirstFragment");
fragmentTransaction.addToBackStack("TAG");
fragmentTransaction.commit();


-> Find Fragment By Tag

Fragment fragment = fragmentManager.findFragmentByTag("firstFragment");

-> PopStack/Remove Fragment By Tag

fragmentManager.popBackStack("firstFragment",FragmentManager.POP_BACK_STACK_INCLUSIVE);

-> Hide fragment

Hides an existing fragment. This is only relevant for fragments whose views have been added to a container, as this will cause the view to be hidden.

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.hide(secondFragment);
fragmentTransaction.commit();

-> Show fragment

Shows a previously hidden fragment. This is only relevant for fragments whose views have been added to a container, as this will cause the view to be shown.

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.show(secondFragment);
fragmentTransaction.commit();


-> isAddToBackStackAllowed

Returns true if this FragmentTransaction is allowed to be added to the back stack. If this method would return false, addToBackStack(String) will throw IllegalStateException.

 FragmentManager fragmentManager = getSupportFragmentManager();
 FragmentTransaction fragmentTransaction =   fragmentManager.beginTransaction();
 fragmentTransaction.add(R.id.idContainer, new FirstFragment());
 fragmentTransaction.addToBackStack(null);
 Log.d(tag, "isAddToBackStackAllowed : "+fragmentTransaction.isAddToBackStackAllowed());
 fragmentTransaction.commit();


-> 
isEmpty

true if this transaction contains no operations, false otherwise.

 FragmentManager fragmentManager = getSupportFragmentManager();
 FragmentTransaction fragmentTransaction =   fragmentManager.beginTransaction();
 fragmentTransaction.add(R.id.idContainer, new FirstFragment());
 fragmentTransaction.addToBackStack(null);
 Log.d(tag, "isAddToBackStackAllowed : "+fragmentTransaction.isEmpty());
 fragmentTransaction.commit();

-> setReorderingAllowed(boolean).

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.idContainer, new FirstFragment());
fragmentTransaction.addToBackStack(null);
fragmentTransaction.setReorderingAllowed(true);
fragmentTransaction.commit();









22






Tuesday, 4 July 2017

Java Execution Sequence : Method, Constructor, Static Initializer Block



JAVA CODE
---------------

package Test;

/** * Created by Akash on 7/5/2017. */class A
{
    A()
    {
        System.out.println("Parent Constructor");
    }
    static {System.out.println("Parent Static Initializer Block!");}
    public void methodA()
    {
        System.out.println("Parent method");
        {System.out.println("Parent Initializer Block!");}
    }
}
public class TestTwo extends A
{
    TestTwo()
    {
        super();
        System.out.println("Child Constructor");
    }
    static {
        System.out.println("Child Static Initializer Block!");}
    public static void main(String[] args)
    {
        TestTwo testTwo = new TestTwo();
        testTwo.methodA();
        System.out.println("Main before Initializer block");
        {System.out.println("Child Initializer Block");}
        System.out.println("Main after Initializer block");
    }

}




OUTPUT
-----------

Child Static Initializer Block!
Parent Constructor
Child Constructor
Parent method
Parent Initializer Block!
Main before Initializer block
Child Initializer Block
Main after Initializer block

Friday, 30 June 2017

SQLite Database


STEP-1 : DBConnection

package jcb.heavyvehicle.app.com.jcb.adapter;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class DBConnectionClass extends SQLiteOpenHelper {

    private static String DB_NAME = "dbJCB18";
    private SQLiteDatabase myDataBase;
    private final Context myContext;
    private static String DB_PATH= "";

    public DBConnectionClass(Context context) {
        super(context, DB_NAME, null, 1);
        this.myContext = context;
        DB_PATH=myContext.getApplicationInfo().dataDir + "/databases/";
    }
    public void createDataBase() throws IOException {
        boolean dbExist = checkDataBase();
        if(dbExist){
            //do nothing - database already exist
        }else{
            //By calling this method and empty database will be created into the default system path
            //of your application so we are gonna be able to overwrite that database with our database.
           // this.getReadableDatabase();
            this.getWritableDatabase();

            try {

                copyDataBase();

            } catch (IOException e) {

                throw new Error("Error copying database");

            }
        }

    }

    /**
     * Check if the database already exist to avoid re-copying the file each time you open the application.
     * @return true if it exists, false if it doesn't
     */
    private boolean checkDataBase(){

        SQLiteDatabase checkDB = null;

        try{
            String myPath = DB_PATH + DB_NAME;
            checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
        }catch(SQLiteException e){
        }

        if(checkDB != null){
            checkDB.close();
        }

        return checkDB != null;
    }
    private void copyDataBase() throws IOException{
        //Open your local db as the input stream
        InputStream myInput = myContext.getAssets().open("dbJCB18.sqlite");
        // Path to the just created empty db
        String outFileName = DB_PATH + DB_NAME;
        //Open the empty db as the output stream
        OutputStream myOutput = new FileOutputStream(outFileName);

        //transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer))>0){
            myOutput.write(buffer, 0, length);
        }

        //Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close();

    }

    public void openDataBase() throws SQLException {

        //Open the database
        String myPath = DB_PATH + DB_NAME;
       // myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
         myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

    }

    @Override
    public synchronized void close() {

        if(myDataBase != null)
            myDataBase.close();

        super.close();

    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    // Add your public helper methods to access and get content from the database.
    // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy
    // to you to create adapters for your views.

}




STEP-2 : DBAdapter

package jcb.heavyvehicle.app.com.jcb.adapter;

/**
 * Created by Cyber Matrix3 on 11/18/2016.
 */
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AlertDialog;
import android.util.Log;

import java.io.IOException;
import java.util.ArrayList;

import jcb.heavyvehicle.app.com.jcb.pojo.BannerPojo;
import jcb.heavyvehicle.app.com.jcb.pojo.CategoryPojo;
import jcb.heavyvehicle.app.com.jcb.pojo.ProductPojo;
import jcb.heavyvehicle.app.com.jcb.pojo.ProjectUpdatePojo;
import jcb.heavyvehicle.app.com.jcb.pojo.AppDescMasterPojo;

public class DBAdapterClass {
    protected static final String TAG = "DataAdapter";

    private final Context mContext;
    private SQLiteDatabase mDb;
    private DBConnectionClass mDbHelper;

    public DBAdapterClass(Context context) {
        this.mContext = context;
        mDbHelper = new DBConnectionClass(mContext);
    }

    public DBAdapterClass createDatabase() throws SQLException {
        try {
            mDbHelper.createDataBase();
        } catch (IOException mIOException) {
            Log.e(TAG, mIOException.toString() + "  UnableToCreateDatabase");
            throw new Error("UnableToCreateDatabase");
        }
        return this;
    }

    public DBAdapterClass open() throws SQLException {
        try {
            mDbHelper.openDataBase();
            mDbHelper.close();
            //mDb = mDbHelper.getReadableDatabase();
            mDb = mDbHelper.getWritableDatabase();

        } catch (SQLException mSQLException) {
            Log.e(TAG, "open >>" + mSQLException.toString());
            throw mSQLException;
        }
        return this;
    }

    public void close() {
        mDbHelper.close();
    }


    // --- QUERY BELOW

    // PROJECT UPDATE SECTION
    public ArrayList<ProjectUpdatePojo> getProjectUpdateData()
    {
        ArrayList<ProjectUpdatePojo> arrayListProjectUpdate = new ArrayList<>();

        try {
            String sql = "SELECT * FROM tblUpdate";
            Cursor mCur = mDb.rawQuery(sql, null);
            if (mCur != null) {
                mCur.moveToNext();
            }
            while (mCur.isAfterLast() == false) {
                String table_name = mCur.getString(mCur.getColumnIndex("table_name"));
                String last_update_date = mCur.getString(mCur.getColumnIndex("last_update_date"));

                ProjectUpdatePojo productUpdatePojo = new ProjectUpdatePojo(table_name,last_update_date);
                arrayListProjectUpdate.add(productUpdatePojo);
                mCur.moveToNext();
            }
        }catch (SQLException se)
        {
            Log.e(TAG,"Error : "+se, se);
        }
        return arrayListProjectUpdate;
    }

    // SPLASH SCREEN SECTION
    public ArrayList<AppDescMasterPojo> getSplashData() {
        ArrayList<AppDescMasterPojo> splashArrList = new ArrayList<>();

        try {

            String sql = "select msg_data from tbl_splash_screen";
            Cursor mCur = mDb.rawQuery(sql, null);

            if (mCur != null) {
                mCur.moveToNext();
            }
            while (mCur.isAfterLast() == false) {

                String data = mCur.getString(mCur.getColumnIndex("msg_data"));

                AppDescMasterPojo splashMasterPojo = new AppDescMasterPojo(data);
                splashArrList.add(splashMasterPojo);
                mCur.moveToNext();
            }
        }catch (SQLException mSQLException)
        {
            Log.e(TAG," SQL Error"+mSQLException, mSQLException );
        }
        return splashArrList;
    }

    // OFFER SECTION
    public ArrayList<BannerPojo> getBannerData()
    {
        ArrayList<BannerPojo> bannerAL = new ArrayList<>();

        try {

            String sql = "select * from tblOfferBanner";
            Cursor mCur = mDb.rawQuery(sql, null);
            if (mCur != null) {
                mCur.moveToNext();
            }
            while (mCur.isAfterLast() == false) {
                String bannerImgDir = mCur.getString(mCur.getColumnIndex("offer_img_dir"));
                String bannerImg = mCur.getString(mCur.getColumnIndex("offer_img"));

                BannerPojo bannerPojo = new BannerPojo(bannerImgDir, bannerImg);
                bannerAL.add(bannerPojo);
            mCur.moveToNext();
            }

        }catch (SQLException se)
        {
            Log.e(TAG, "Error"+se, se);
        }
        return bannerAL;
    }

    public void updateOfferTable(String dir, String image, String date)
    {
        try
        {
            ContentValues cv = new ContentValues();
          //  cv.put("id", 3);


          //  insert into tblOfferBanner (offer_img_dir, offer_img,last_update_date) values
            cv.put("offer_img_dir", dir);
            cv.put("offer_img", image);
         //   cv.put("last_update_date", date);
          //  cv.put("Mobile", arr.get(i).mobile);
            mDb.insert("tblOfferBanner", null, cv);

        }catch (SQLException se)
        {
            new AlertDialog.Builder(mContext)
                    .setTitle("OfferTable Update")
                    .setMessage("Something went wromg!")
                    .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    })
                    .show();

        }
    }


    public void deleteOfferTable()
    {
        try
        {
            mDb.delete("tblOfferBanner",null,null);
        }catch (SQLException se)
        {
            Log.e(TAG, "Error : "+se,se);
        }
    }


    // --- CATEGORY SECTION

    public ArrayList<CategoryPojo> getCategoryData()
    {
        ArrayList<CategoryPojo> arrayListCategory = new ArrayList<>();

        try {
            String sql = "SELECT * FROM tblCategory";
            Cursor mCur = mDb.rawQuery(sql, null);
            if (mCur != null) {
                mCur.moveToNext();
            }
            while (mCur.isAfterLast() == false) {
           //     int category_id = mCur.getInt(mCur.getColumnIndex("category_id"));
                String category_name = mCur.getString(mCur.getColumnIndex("category_name"));
                String category_dir = mCur.getString(mCur.getColumnIndex("category_dir"));
                String category_img = mCur.getString(mCur.getColumnIndex("category_img"));

                CategoryPojo categoryPojo = new CategoryPojo(0, category_name, category_dir, category_img);
                arrayListCategory.add(categoryPojo);
                mCur.moveToNext();
            }
        }catch (SQLException se)
        {
            Log.e(TAG,"Error : "+se, se);
        }
        return arrayListCategory;
    }
    public ArrayList<CategoryPojo> getCategoryIdData(int id)
    {
        ArrayList<CategoryPojo> arrayListProduct = new ArrayList<>();

        try {
            String sql = "SELECT category_id FROM tblCategory where id='"+id+"'";
            Cursor mCur = mDb.rawQuery(sql, null);
            if (mCur != null) {
                mCur.moveToNext();
            }
            while (mCur.isAfterLast() == false) {
                int category_id = mCur.getInt(mCur.getColumnIndex("category_id"));

                CategoryPojo categoryPojo = new CategoryPojo(category_id, null, null, null);
                arrayListProduct.add(categoryPojo);
                mCur.moveToNext();
            }
        }catch (SQLException se)
        {
            Log.e(TAG,"Error : "+se, se);
        }
        return arrayListProduct;
    }

    public void updateCategoryTable(String categoryID, String categoryName,String categoryImage,String categoryDir, String date)
    {
        try
        {
            ContentValues cv = new ContentValues();
                   cv.put("category_id", categoryID);
            cv.put("category_name", categoryName);
            cv.put("category_img", categoryImage);
            cv.put("category_dir", categoryDir);
            //   cv.put("last_update_date", date);
            //  cv.put("Mobile", arr.get(i).mobile);
            mDb.insert("tblCategory", null, cv);

        }catch (SQLException se)
        {
            new AlertDialog.Builder(mContext)
                    .setTitle("OfferTable Update")
                    .setMessage("Something went wromg!")
                    .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    })
                    .show();
        }
    }

    public void deleteCategoryTable()
    {
        try
        {
            mDb.delete("tblCategory",null,null);
            //    mDb.close();
           /*String sql = "DELETE FROM tblOfferBanner";
            Cursor cursor = mDb.rawQuery(sql,null);*/


        }catch (SQLException se)
        {
            new AlertDialog.Builder(mContext)
                    .setTitle("Category Table Refreshing")
                    .setMessage("Something went wromg!")
                    .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    })
                    .show();
        }
    }


    // ---- PRODUCT SECTION

    public ArrayList<ProductPojo> getProductData(int cate_id)
    {
        ArrayList<ProductPojo> arrayListProduct = new ArrayList<>();

        try {
            String sql = "SELECT * FROM tblProduct where category_id='"+cate_id+"'";
            Cursor mCur = mDb.rawQuery(sql, null);
            if (mCur != null) {
                mCur.moveToNext();
            }
            while (mCur.isAfterLast() == false) {
                String product_name = mCur.getString(mCur.getColumnIndex("product_name"));
                String product_dir = mCur.getString(mCur.getColumnIndex("product_dir"));
                String product_img = mCur.getString(mCur.getColumnIndex("product_img"));

                ProductPojo productPojo = new ProductPojo(0, product_name, product_dir, product_img,null);
                arrayListProduct.add(productPojo);
                mCur.moveToNext();
            }
        }catch (SQLException se)
        {
            Log.e(TAG,"Error : "+se, se);
        }
        return arrayListProduct;
    }


    public void updateProductTable(String categoryID, String productName,String productImage,String productUrl, String productDir, String date)
    {
        try
        {
            ContentValues cv = new ContentValues();
            cv.put("category_id", categoryID);
            cv.put("product_name", productName);
            cv.put("product_img", productImage);
             cv.put("product_url", productUrl);
            cv.put("product_dir", productDir);
            //   cv.put("last_update_date", date);
            //  cv.put("Mobile", arr.get(i).mobile);
            mDb.insert("tblProduct", null, cv);

        }catch (SQLException se)
        {
            new AlertDialog.Builder(mContext)
                    .setTitle("OfferTable Update")
                    .setMessage("Something went wromg!")
                    .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    })
                    .show();
        }
    }

    public void deleteProductTable()
    {
        try
        {
            mDb.delete("tblProduct",null,null);
            //    mDb.close();
           /*String sql = "DELETE FROM tblOfferBanner";
            Cursor cursor = mDb.rawQuery(sql,null);*/


        }catch (SQLException se)
        {
            new AlertDialog.Builder(mContext)
                    .setTitle("Product Table Refreshing")
                    .setMessage("Something went wromg!")
                    .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    })
                    .show();
        }
    }

// --------  project update
    public void projectOfferUpdate(String offer_date)
    {
        try
        {
            ContentValues cv = new ContentValues();
            //  cv.put("id", 3);
            //  insert into tblOfferBanner (offer_img_dir, offer_img,last_update_date) values
            cv.put("last_update_date", offer_date);


                mDb.update("tblUpdate", cv, "table_name='offer_update'", null);

          /*  insert(String table, String nullColumnHack, ContentValues values)
            Convenience method for inserting a row into the database.

            update(String table, ContentValues values, String whereCl-ause, String[] whereArgs)
            Convenience method for updating rows in the database.*/

        }catch (SQLException se)
        {
            new AlertDialog.Builder(mContext)
                    .setTitle("OfferTable Update")
                    .setMessage("Something went wromg!")
                    .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    })
                    .show();

        }
    }

    public void projectProductUpdate(String product_date)
    {
        try
        {
            ContentValues cv = new ContentValues();
            //  cv.put("id", 3);


            //  insert into tblOfferBanner (offer_img_dir, offer_img,last_update_date) values
            cv.put("last_update_date", product_date);


                mDb.update("tblUpdate",cv,"table_name='product_update'",null);

            /*  insert(String table, String nullColumnHack, ContentValues values)
            Convenience method for inserting a row into the database.

            update(String table, ContentValues values, String whereClause, String[] whereArgs)
            Convenience method for updating rows in the database.*/

        }catch (SQLException se)
        {
            new AlertDialog.Builder(mContext)
                    .setTitle("ProductTable Update")
                    .setMessage("Something went wromg!")
                    .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    })
                    .show();

        }
    }

    public ArrayList<ProductPojo> getProductKnowMoreData(String prodName)
    {
        ArrayList<ProductPojo> arrayListProduct = new ArrayList<>();

        try {
            String sql = "SELECT product_url FROM tblProduct where product_name='"+prodName+"'";
            Cursor mCur = mDb.rawQuery(sql, null);
            if (mCur != null) {
                mCur.moveToNext();
            }
            while (mCur.isAfterLast() == false) {
                String product_url = mCur.getString(mCur.getColumnIndex("product_url"));

                ProductPojo productPojo = new ProductPojo(0,null,null,null,product_url);
                arrayListProduct.add(productPojo);
                mCur.moveToNext();
            }
        }catch (SQLException se)
        {
            Log.e(TAG,"Error : "+se, se);
        }
        return arrayListProduct;
    }
}















22