Thursday, 25 February 2016

Chart in Android

Hi!

To handle the chart in android will differ based on the library. I have developed reusable .AAR file to handle your chart on existing available Github library.

By using this .AAR, you can reduce your code and RD timing. simply pass the parameters to display on chart. It will give you a result on Pie,Bar & Line chart.

Download sample APK to test the output.

Steps To Do:

  • Download this .aar file,
  • Import as .aar file into your workspace,
  • Add this .aar file into your project and synchronize your project,
  • Reuse the available classes on any of your projects.


To call the Pie-Chart

public class Pi_Crt extends ActionBarActivity {

// call the xml chart 
PieChart xml_chart;
// call / create object for Pie-Chart
Pie_Chart P_Chart; // Array list for values ArrayList<Entry> dataSets_2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().hide(); setContentView(R.layout.activity_pi__crt);
        xml_chart = (PieChart) findViewById(R.id.xml_pie_chart);
        P_Chart = new Pie_Chart();
// Array List for values
        dataSets_2 = new ArrayList<>();
// Label to display
        P_Chart.Top_Title.add("NSE");
        P_Chart.Top_Title.add("BSE");
        P_Chart.Top_Title.add("NFT");
// Value to show on position
        dataSets_2.add(new Entry(Float.valueOf("100"), 0));
        dataSets_2.add(new Entry(Float.valueOf("380"), 1));
        dataSets_2.add(new Entry(Float.valueOf("625"), 2));
// Fix on chart
        P_Chart.set_Pie(xml_chart, dataSets_2);
    }
}

To call the Bar-Chart (Fallow the same Steps of Pie-Chart)

public class Bar_Crt extends ActionBarActivity {

    BarChart xml_chart;
    Bar_Chart l_Chart;

    ArrayList<Customer_Data_B> main_list;


    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();
        setContentView(R.layout.activity_bar__crt);
        xml_chart = (BarChart) findViewById(R.id.xml_bar_chart);
        l_Chart = new Bar_Chart();

        main_list = new ArrayList<>();

        l_Chart.Top_Title.add("NSE");
        l_Chart.Top_Title.add("BSE");
        l_Chart.Top_Title.add("NFT");

        main_list.add(new Customer_Data_B("200", "350", "480"));

        ArrayList<BarEntry> valueSet1;
        ArrayList<BarEntry> valueSet2;
        ArrayList<BarEntry> valueSet3;

        valueSet1 = new ArrayList<>();
        valueSet2 = new ArrayList<>();
        valueSet3 = new ArrayList<>();


        BarEntry v_Set_1 = new BarEntry(Float.valueOf(main_list.get(0).getMarker_Rate()), 0);
        BarEntry v_Set_2 = new BarEntry(Float.valueOf(main_list.get(0).getActual_Rate()), 1);
        BarEntry v_Set_3 = new BarEntry(Float.valueOf(main_list.get(0).getExpected_Rate()), 2);

        valueSet1.add(v_Set_1);
        valueSet2.add(v_Set_2);
        valueSet3.add(v_Set_3);

        BarDataSet B1 = new BarDataSet(valueSet1, "Expected Value");
        B1.setColor(Color.rgb(255, 102, 0));
        BarDataSet B2  = new BarDataSet(valueSet2, "Actual Value");
        B2.setColor(Color.rgb(106, 150, 31));
        BarDataSet B3  = new BarDataSet(valueSet3, "Market Value");
        B3.setColor(Color.rgb(215, 12, 100));

        l_Chart.dataSets.add(B1);
        l_Chart.dataSets.add(B2);
        l_Chart.dataSets.add(B3);
        l_Chart.set_Bar(xml_chart);
    }
}

To call the Line-Chart (Fallow the same Steps of Pie-Chart)

public class Line_Crt extends ActionBarActivity {

    LineChart xml_chart;
    Line_Chart l_Chart;

    ArrayList<Sales_Revenue_B> main_list;


    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();
        setContentView(R.layout.activity_line__crt);
        xml_chart = (LineChart) findViewById(R.id.xml_line_chart);
        l_Chart = new Line_Chart();

        main_list = new ArrayList<>();

        l_Chart.Top_Title.add("3 Months");
        l_Chart.Top_Title.add("6 Months");
        l_Chart.Top_Title.add("9 Months");
        l_Chart.Top_Title.add("1 Year");
        l_Chart.Top_Title.add("2 Years");

        l_Chart.Lower_Title.add("NSE");
        l_Chart.Lower_Title.add("BSE");
        l_Chart.Lower_Title.add("NFT");

        main_list.add(new Sales_Revenue_B("100", "200", "350", "480", "850"));
        main_list.add(new Sales_Revenue_B("50", "125", "480", "520", "700"));
        main_list.add(new Sales_Revenue_B("150", "600", "800", "920", "1000"));


        ArrayList<Entry> Entry_List = null;

        for (int i = 0; i < main_list.size(); i++) {

            Entry_List = new ArrayList<>();
            BarEntry ThreeMonthRevenue_val = new BarEntry(Float.valueOf(main_list.get(i).getThreeMonthRevenue()), 0);
            BarEntry SixMonthRevenue_val = new BarEntry(Float.valueOf(main_list.get(i).getSixMonthRevenue()), 1);
            BarEntry NineMonthRevenue_val = new BarEntry(Float.valueOf(main_list.get(i).getNineMonthRevenue()), 2);
            BarEntry OneYearRevenue_val = new BarEntry(Float.valueOf(main_list.get(i).getOneYearRevenue()), 3);
            BarEntry TwoYearsRevenue_val = new BarEntry(Float.valueOf(main_list.get(i).getTwoYearsRevenue()), 4);

            Entry_List.add(ThreeMonthRevenue_val);
            Entry_List.add(SixMonthRevenue_val);
            Entry_List.add(NineMonthRevenue_val);
            Entry_List.add(OneYearRevenue_val);
            Entry_List.add(TwoYearsRevenue_val);

            l_Chart.Bar_Set_ = new LineDataSet(Entry_List, l_Chart.set_indicator(i));
            l_Chart.set_Range(i);
            l_Chart.dataSets.add(l_Chart.Bar_Set_);
        }
        l_Chart.set_line(xml_chart);

    }
}


On your XML


To call Pie-Chart

<com.github.mikephil.charting.charts.PieChart    android:id="@+id/xml_pie_chart"    android:layout_width="match_parent"    android:layout_height="match_parent" />


To call Bar-Chart

<com.github.mikephil.charting.charts.BarChart    android:id="@+id/xml_bar_chart"    android:layout_width="match_parent"    android:layout_height="match_parent" />


To call Line-Chart

<com.github.mikephil.charting.charts.LineChart    android:id="@+id/xml_line_chart"    android:layout_width="match_parent"    android:layout_height="match_parent" />


Thats All!

Enjoy Your Code..,

Please Leave Your Comment..,



Have A Happy Day..,

Thursday, 5 November 2015

Android API V - 23 NameValuePair Deprecated Solution

Hi 

By Brand New Android API V-23 update, all of our android developers are facing a big issue on "Apache HTTP Client Removal". In my circle also by update of API V-23 lots of developer unable to connect with sever Page.

Apache Removed Reference :

org.apache.http.NameValuePair;
org.apache.http.message.BasicNameValuePair;
Android 6.0 release removes support for the Apache HTTP client. But in our existing Android Projects we connected & Receive the JSON through the server page by using the Apache's NameValuePair & BasicNameValuePair till API V-22.

 Because of deprecated of Apache, we need to use HttpURLConnection, But the problem is have to change & correct all of your android Logic & Code in all projects.

My self i have try to find the solution by using the HttpURLConnection without changing your Logic & Code. i took small risk for you,  just by relax you may download my .AAR file and attach into your project and run with your same code by small changes.

(If it is useful to you don't forget to leave a comment)

Download my raj_namevaluepair.aar file & add it into your project.


Android Code to Use My .AAR file :


// my server page link
String URL_My_Server_Page="http://xxxxx.com/xxxxx/xxxxxxxx/xxxxxxx.php";
@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_jsonparser);
    tv_op = (TextView)findViewById(R.id.tv_op);
    listView = (ListView) findViewById(R.id.listView);
// class to execute the URL
new Page_Executer().execute();
}

class Page_Executer extends AsyncTask<String, String, String> {
    ProgressDialog p_dialog;
    String op_esult = null;
    @Override    protected void onPreExecute() {
        super.onPreExecute();
        p_dialog = new ProgressDialog(JSONParser.this);
        p_dialog.setTitle("Loading");
        p_dialog.setCancelable(false);
        p_dialog.setIndeterminate(false);
        p_dialog.show();
    }

    @Override    protected String doInBackground(String... strings) {
        a_list = new ArrayList();
        try {
// My class to handle            
R_JSONParser raj_parser = new R_JSONParser();
// My NameValuePair to pass your parameters            
ArrayList<R_NameValuePair> n_pair = new ArrayList<>();
// can pass number of parameters as you need            
n_pair.add(new R_NameValuePair("",""));
// method to return the result as string , you need to pass server page link, Method, Parameters with values            
op_esult = raj_parser.Load_Data_From_URL(URL_My_Server_Page, "GET", n_pair);
            Log.d("result", op_esult);
// As usual you can handle JSONArray & JSONObject            
JSONArray j_array = new JSONArray(op_esult);
            for (int i = 0; i < j_array.length(); i++) {
                JSONObject j_obj_t = j_array.getJSONObject(i);
                String MS01key = j_obj_t.getString("MS01key");
                String BloodGroupName = j_obj_t.getString("BloodGroupName");
                a_list.add(new Raj_B(MS01key, BloodGroupName));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        Raj_Adapter r_adptr = new Raj_Adapter(getApplicationContext(), R.layout.list_a, a_list);
        listView.setAdapter(r_adptr);
        p_dialog.dismiss();
    }
}


The Output is :



Enjoy..,

Have A Happy Day..,

Monday, 26 October 2015

Upload Selected Image On Server

Hi!

  Some of our Android developers are struggle with Images, for Upload on Server & Download from the server.

Normally we can Upload & Download Images from the server, But the thing is, the Base64 is the only format to help us. In this blog i have explain how to do this, and i have reduce your working time, within 3 Mins you can do this, Needn't to R&D for this i have done and attached my Raj_Img_Upload.aar file for you. Just download the file and fallow the below.

As usual we can use Json format to Upload & Download the image. But the method should be "POST".

Link to Download My .aar file  download this .aar file and add in your project, That's all.


My Activity Class :

public class MainActivity extends ActionBarActivity {


// Image Button to set the selected Image
    ImageButton img_btn_prf_img;

// My .AAR file to handle all your risk part.
    Raj_Image_Handler raj_Handler;
// TextView to show your converted format (Image into Base64)
    TextView base_64_txt;
// To open up Image Gallery 
    private static final int GALLERY = 1;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        img_btn_prf_img = (ImageButton) findViewById(R.id.img_btn_prf_img);
        base_64_txt = (TextView) findViewById(R.id.base_64_txt);
// Pass your ImageButton & Activity to my .aar
        raj_Handler = new Raj_Image_Handler(getApplicationContext(), img_btn_prf_img);

        img_btn_prf_img.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
// Get Default Bitmap date what i have set
                Bitmap Image = raj_Handler.get_Image();
                img_btn_prf_img.setImageBitmap(null);
                if (Image != null)
                    Image.recycle();
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(
                        Intent.createChooser(intent, "Select Picture"), GALLERY);
            }
        });
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == GALLERY && resultCode != 0) {
            Uri mImageUri = data.getData();
// Pass the selected image Uri to my .aar
String enc_img = raj_Handler.set_Image_From_Gallery(mImageUri);
// get the Base64 format of your selected Image
            base_64_txt.setText(enc_img);
        }
    }
}









Convert From Base64 to Image :

If you want to convert from Base64 to Image please do the fallowing

//ImageButton for check the output 
ImageButton imb_set;

imb_set = (ImageButton) findViewById(R.id.imb_set);

// Action to convert Base64 to Image
imb_set.setOnClickListener(new View.OnClickListener() {
    @Override    public void onClick(View view) {

// Single line parameter (ImageButton & Base64 output)
        raj_Handler.set_Image_Base_64(imb_set,your_base64_string);
    }
});


Sample APK: Download APK

Out Put:



Enjoy!..,

Thank You!

Have A Happy Day..,

Friday, 12 June 2015

Android Bar/QR Code Scanner!

Hi!

Today i am going to show the example how to read Bar / QR Code form android device.


1) Function on Call Class to Scan the Sequence

// startActivityForResult for safety carry of sequence.
Intent int_brcd = new Intent(PO_Entry.this, InitiatBarCd.class);
startActivityForResult(int_brcd, 3);


2) Class to Scan the Bar/QR Code


package vgs.raj.tot.ivnt;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;


public class InitiatBarCd extends ActionBarActivity {

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

        IntentIntegrator scanIntegrator = new IntentIntegrator(this);
        scanIntegrator.initiateScan();
    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        IntentResult scanningResult = IntentIntegrator.parseActivityResult(
                requestCode, resultCode, intent);
        if (scanningResult != null) {
            playSound();
            String scanContent = scanningResult.getContents();
            Intent int_get_br_bk = new Intent();
            int_get_br_bk.putExtra("ip_br_code", scanContent);
            setResult(3, int_get_br_bk);
            finish();
        } else {
            Toast.makeText(getApplicationContext(), "No scan data received!",
                    Toast.LENGTH_SHORT).show();
        }
    }

    public void playSound() {
        MediaPlayer mp = MediaPlayer.create(InitiatBarCd.this,
                R.drawable.camerasound);
        mp.start();
    }

    @Override    public void onBackPressed() {
        // super.onBackPressed();        finish();
    }
}


3) Class To receive the sequence of Code


@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (data != null) {
        if (resultCode == 3) {
            String brcode_val = data.getStringExtra("ip_br_code");
            et_po_enty_brcd.setText(brcode_val);
        }
    }
}

Thank You!

Please Leave Your Comment..,

Have A Happy Day..,

Monday, 4 May 2015

Storage On Android

Hi!

In Android to store the data, we are using the fallowing  format

On server :  SQL , MySQL & etc..,
On Local  : SharedPreferences & SQLite

Today i am going to cover about the SQLite. The SQLite is a lightweight library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.

Because of it's nature we are using the SQLite to store the data on the OS of ANDROID & IOS, etc..,

In Android we should extends the super class of SQLiteOpenHelper, the Helper class contains two superclass methods onCreate() & onUpgrade(). On the Oncreate method is used to create the tables, the  onUpgrade method is used to Update the tables.
For this class we should create one constructor which will carry the Database details to the superclass.

All the fields should be PRIVATE, STATIC & FINAL.

Android Code : 


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

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

/**
 * Created by Selvaraj on 4/28/2015.
 */

public class Hotel_DB extends SQLiteOpenHelper
{

    private static final int Db_Version = 1;
    private static final String Db_Name = "hotelvgs3";

    private static final String Tb_booking = "Tb_booking";

    // Field for Room Booking
    final String Book_Rm_ID="IAvil_ID";

    final String Book_Rm_in_fl_date="Book_Rm_in_fl_date";
    final String Book_Rm_out_fl_date="Book_Rm_out_fl_date";
    final String Book_Rm_in_dt="Book_Rm_in_dt";
    final String Book_Rm_in_day="Book_Rm_in_day";
    final String Book_Rm_in_mnth="Book_Rm_in_mnth";
    final String Book_Rm_in_year="Book_Rm_in_year";
    final String Book_Rm_out_dt="Book_Rm_out_dt";
    final String Book_Rm_out_day="Book_Rm_out_day";
    final String Book_Rm_out_mnth="Book_Rm_out_mnth";
    final String Book_Rm_out_year="Book_Rm_out_year";

    final String Book_Rm_adlt="Book_Rm_adlt";
    final String Book_Rm_chld="Book_Rm_chld";

    final String Book_Rm_rom_typ="Book_Rm_rom_typ";
    final String Book_Rm_rom_rate="Book_Rm_rom_rate";
    final String Book_Rm_tot_rom="Book_Rm_tot_rom";

    final String Book_Rm_cust_fname="Book_Rm_cust_fname";
    final String Book_Rm_cust_lname="Book_Rm_cust_lname";
    final String Book_Rm_email="Book_Rm_email";
    final String Book_Rm_mob="Book_Rm_mob";
    final String Book_Rm_adrs="Book_Rm_adrs";
    final String Book_Rm_status="Book_Rm_status";

    final String Book_Rm_ack_tot="Book_Rm_ack_tot";
    final String Book_Rm_ack_advnc="Book_Rm_ack_advnc";






    public Hotel_DB(Context context) {
        super(context, Db_Name, null, Db_Version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        String CREATE_BOOKING_TABLE="CREATE TABLE " +Tb_booking+"("+Book_Rm_ID+" INTEGER PRIMARY KEY,"+Book_Rm_in_fl_date+" TEXT," +
                Book_Rm_out_fl_date+" TEXT,"+Book_Rm_in_dt+" TEXT,"+Book_Rm_in_day+" TEXT,"+Book_Rm_in_mnth+" TEXT,"+Book_Rm_in_year+
                " TEXT,"+Book_Rm_out_dt+" TEXT,"+Book_Rm_out_day+" TEXT,"+Book_Rm_out_mnth+" TEXT,"+Book_Rm_out_year+
                " TEXT,"+Book_Rm_adlt+" TEXT,"+Book_Rm_chld+" TEXT,"+Book_Rm_rom_typ+" TEXT,"+Book_Rm_rom_rate+" TEXT,"+Book_Rm_tot_rom+
                " TEXT,"+Book_Rm_cust_fname+" TEXT,"+Book_Rm_cust_lname+" TEXT,"+Book_Rm_email+" TEXT,"+Book_Rm_mob+" TEXT,"+Book_Rm_adrs+
                " TEXT,"+Book_Rm_status+" TEXT, "+Book_Rm_ack_tot+" TEXT, "+Book_Rm_ack_advnc+" TEXT "+")";
        
        db.execSQL(CREATE_BOOKING_TABLE);
    }

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

    // Add Objects on the table
    public void addBooking(Booking_B Rpl_lst)
    {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(Book_Rm_in_fl_date,Rpl_lst.getBook_Rm_in_fl_date());
        values.put(Book_Rm_out_fl_date,Rpl_lst.getBook_Rm_out_fl_date());
        values.put(Book_Rm_in_dt,Rpl_lst.getBook_Rm_in_dt());
        values.put(Book_Rm_in_day,Rpl_lst.getBook_Rm_in_day());
        values.put(Book_Rm_in_mnth,Rpl_lst.getBook_Rm_in_mnth());
        values.put(Book_Rm_in_year,Rpl_lst.getBook_Rm_in_year());
        values.put(Book_Rm_out_dt,Rpl_lst.getBook_Rm_out_dt());
        values.put(Book_Rm_out_day,Rpl_lst.getBook_Rm_out_day());
        values.put(Book_Rm_out_mnth,Rpl_lst.getBook_Rm_out_mnth());
        values.put(Book_Rm_out_year,Rpl_lst.getBook_Rm_out_year());
        values.put(Book_Rm_adlt,Rpl_lst.getBook_Rm_adlt());
        values.put(Book_Rm_chld,Rpl_lst.getBook_Rm_chld());
        values.put(Book_Rm_rom_typ,Rpl_lst.getBook_Rm_rom_typ());
        values.put(Book_Rm_rom_rate,Rpl_lst.getBook_Rm_rom_rate());
        values.put(Book_Rm_tot_rom,Rpl_lst.getBook_Rm_tot_rom());
        values.put(Book_Rm_cust_fname,Rpl_lst.getBook_Rm_cust_fname());
        values.put(Book_Rm_cust_lname,Rpl_lst.getBook_Rm_cust_lname());
        values.put(Book_Rm_email,Rpl_lst.getBook_Rm_email());
        values.put(Book_Rm_mob,Rpl_lst.getBook_Rm_mob());
        values.put(Book_Rm_adrs,Rpl_lst.getBook_Rm_adrs());
        values.put(Book_Rm_status,Rpl_lst.getBook_Rm_status());
        values.put(Book_Rm_ack_tot,Rpl_lst.getBook_Rm_ack_tot());
        values.put(Book_Rm_ack_advnc,Rpl_lst.getBook_Rm_ack_advnc());

        db.insert(Tb_booking, null, values);
        db.close();
        Log.d("BD Log", "EXECUTIVE SUCESS");
    }

    // Select list of all available records
    public ArrayList<Booking_B> get_All_Booking()
    {
        ArrayList<Booking_B> repay_list=new ArrayList<Booking_B>();
        String sltqry="SELECT * FROM "+ Tb_booking+" ORDER BY "+Book_Rm_cust_fname+" DESC";
        SQLiteDatabase db=this.getWritableDatabase();
        Cursor cursor=db.rawQuery(sltqry, null);
        if(cursor.moveToFirst())
        {
            do{
                Booking_B repy=new Booking_B();
                //exe.setId(String.valueOf(Integer.parseInt(cursor.getString(0))));
                repy.setBook_Rm_in_fl_date(cursor.getString(1));
                repy.setBook_Rm_out_fl_date(cursor.getString(2));
                repy.setBook_Rm_in_dt(cursor.getString(3));
                repy.setBook_Rm_in_day(cursor.getString(4));
                repy.setBook_Rm_in_mnth(cursor.getString(5));
                repy.setBook_Rm_in_year(cursor.getString(6));
                repy.setBook_Rm_out_dt(cursor.getString(7));
                repy.setBook_Rm_out_day(cursor.getString(8));
                repy.setBook_Rm_out_mnth(cursor.getString(9));
                repy.setBook_Rm_out_year(cursor.getString(10));
                repy.setBook_Rm_adlt(cursor.getString(11));
                repy.setBook_Rm_chld(cursor.getString(12));
                repy.setBook_Rm_rom_typ(cursor.getString(13));
                repy.setBook_Rm_rom_rate(cursor.getString(14));
                repy.setBook_Rm_tot_rom(cursor.getString(15));
                repy.setBook_Rm_cust_fname(cursor.getString(16));
                repy.setBook_Rm_cust_lname(cursor.getString(17));
                repy.setBook_Rm_email(cursor.getString(18));
                repy.setBook_Rm_mob(cursor.getString(19));
                repy.setBook_Rm_adrs(cursor.getString(20));
                repy.setBook_Rm_status(cursor.getString(21));
                repy.setBook_Rm_ack_tot(cursor.getString(22));
                repy.setBook_Rm_ack_advnc(cursor.getString(23));
                repay_list.add(repy);
            }
            while (cursor.moveToNext());
        }

        cursor.close();
        db.close();
        return repay_list;
    }

    // Delete on Object from the database
    public void Delete_Booking(Booking_B contact) {
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(Tb_booking, Book_Rm_cust_fname + " = ?",
                new String[] { String.valueOf(contact.getBook_Rm_cust_fname()) });
        db.close();
    }

    
    // Select list of records by passing one parameter
    public List<Booking_B> get_Single_Bk_Detail_List(String fist_nm)
    {

        List<Booking_B> BBilllist=new ArrayList<Booking_B>();
        SQLiteDatabase db=this.getWritableDatabase();
        Cursor cursor=db.rawQuery("SELECT * FROM "+Tb_booking+" WHERE "+Book_Rm_cust_fname+" = ?",new String[] { fist_nm });
        if(cursor.moveToFirst())
        {
            do{
                Booking_B gn=new Booking_B();
                gn.setBook_Rm_cust_fname(cursor.getString(1));
                gn.setBook_Rm_cust_lname(cursor.getString(2));
                gn.setBook_Rm_mob(cursor.getString(3));
                gn.setBook_Rm_adrs(cursor.getString(4));
                BBilllist.add(gn);
            }
            while(cursor.moveToNext());
        }
        return BBilllist;

    }

    // Update Table By Objects

public int update_Plt_Detail(Mngr_Updt_B mngr_up_likst) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(price, mngr_up_likst.getPrice());
    values.put(status, mngr_up_likst.getStatus());

    return db.update(Tb_Plt_Detail, values, plat_number + " = ?",
            new String[]{String.valueOf(mngr_up_likst.getPlat_number())});
}

}


On The above code the "Booking_B" is the Business class for the Objects.

Lets Enjoy The Android..,

Thank You!

Have A Happy Day..,


Tuesday, 21 April 2015

Working With Google Map On Android Studio

Hi!

Working with Android Studio will make some problem when compare with Eclipse IDE, while working on google map we are using V2 & so on.

But in Android Studio Automatically it will generate the Layout file, if you unable to call the marker, do the fallowing by editing your XML & Java file..,


Layout File :

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.SupportMapFragment"/>


Java Class:

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class Agent_Track extends FragmentActivity implements OnMapReadyCallback {

    private SupportMapFragment sMapFragment;
    double LLangi,LLatitude;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_agent__track);
        String LL=getIntent().getStringExtra("LLangi");
        String LLe=getIntent().getStringExtra("LLatitude");
        LLangi=Double.valueOf(LL);
        LLatitude=Double.valueOf(LLe);
        sMapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
        sMapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        LatLng one = new LatLng(10.178, 122.560);
        //LatLng zoomg = new LatLng(10.730278, 122.548889);

        //googleMap.setBuildingsEnabled(true);
        //googleMap.setMyLocationEnabled(true);
        //googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
        //googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(zoomg , 12));

        googleMap.addMarker(new MarkerOptions()
                .title("Demo Location")
                .snippet("Ha, Ha, Ha..,")
                .position(one)
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
    }
}


By edit your xml file you can show your location on Map with Marker..,

Thank You!

Have A Happy Day..,

Friday, 13 February 2015

Custom Battery icon and time display

Hi!

          If we wants to create our application should have the uniqueness, we have to crate tour own theme. today i am going to give you the tips and code. How to Custom Our Own Battery Icon & Time Displaying..,


1) On the activity class create your own  Broadcast receiver
2) Have to create own battery icon for according to the status of the battery like..,
(Charging, Battery full, 5%,10,50%,80%,100%  and etc..,)


//TextView for display the Time
TextView header_tv_time;
header_tv_time = (TextView) findViewById(R.id.header_tv_time);
header_tv_time.setText(getCurrentTime());

// ImageView for battery 
ImageView header_imv_btry;
header_imv_btry = (ImageView) findViewById(R.id.header_imv_btry);
this.registerReceiver(this.BRecer, new IntentFilter(
Intent.ACTION_BATTERY_CHANGED));

// BroadcastReceiver for Battery 
private BroadcastReceiver BRecer = new BroadcastReceiver() {
@Override
public void onReceive(Context ctxt, Intent intent) {
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);

if (level == 0) {
header_imv_btry.setImageResource(R.drawable.zero);
} else if (level >= 1 && level <= 5) {
header_imv_btry.setImageResource(R.drawable.five);
} else if (level >= 6 && level <= 10) {
header_imv_btry.setImageResource(R.drawable.ten);
} else if (level >= 11 && level <= 15) {
header_imv_btry.setImageResource(R.drawable.fiften);
} else if (level >= 16 && level <= 20) {
header_imv_btry.setImageResource(R.drawable.twenty);
} else if (level >= 19 && level <= 25) {
header_imv_btry.setImageResource(R.drawable.twentyfive);
} else if (level >= 24 && level <= 30) {
header_imv_btry.setImageResource(R.drawable.thrty);
} else if (level >= 29 && level <= 35) {
header_imv_btry.setImageResource(R.drawable.thrtyfive);
} else if (level >= 36 && level <= 40) {
header_imv_btry.setImageResource(R.drawable.fourty);
} else if (level >= 41 && level <= 45) {
header_imv_btry.setImageResource(R.drawable.fourtyfive);
} else if (level >= 46 && level <= 50) {
header_imv_btry.setImageResource(R.drawable.fifty);
} else if (level >= 51 && level <= 55) {
header_imv_btry.setImageResource(R.drawable.fiftyfive);
} else if (level >= 56 && level <= 60) {
header_imv_btry.setImageResource(R.drawable.sixty);
} else if (level >= 61 && level <= 65) {
header_imv_btry.setImageResource(R.drawable.sixtyfive);
} else if (level >= 66 && level <= 70) {
header_imv_btry.setImageResource(R.drawable.seventy);
} else if (level >= 71 && level <= 75) {
header_imv_btry.setImageResource(R.drawable.seventyfive);
} else if (level >= 76 && level <= 80) {
header_imv_btry.setImageResource(R.drawable.eigty);
} else if (level >= 81 && level <= 85) {
header_imv_btry.setImageResource(R.drawable.eigtyfive);
} else if (level >= 86 && level <= 90) {
header_imv_btry.setImageResource(R.drawable.ninty);
} else if (level >= 91 && level <= 95) {
header_imv_btry.setImageResource(R.drawable.nintyfive);
} else if (level >= 96 && level <= 100) {
header_imv_btry.setImageResource(R.drawable.sentm);
}
}
};

// Method for provide the current time in Hour:Minutes AM / PM
private String getCurrentTime() {
String delegate = "hh:mm aaa";
return (String) DateFormat.format(delegate, Calendar.getInstance()
.getTime());
}


Thats all..,

Thank You!

Please Leave Your Comment..,


Have A Happy Day..,