Thursday, December 8, 2016

Kundali Match Android Application

Greeting of the Day!!!

Some days back, When I went to a temple somebody was asking to the priest to get match their son's and his would be's Kundali. I was just watching what he would do.

He asked about the Gotra, Raashi, Nakshtra, Charana and Naadi of the bride and groom. Then he opened a table from the Panchanga and told the result. He told it's just the basic Kundali Matching and it's not detail. Then I got it how he does it and the result is our Android Kundali Match app.

It's so simple to do it. Please note it's just the basic. We do not check the Mangalik and other doshas. We check here how many number of characters match based on the Groom's and bride's Raashi/Nakshatra details.

In our SRSM Pachanga, we have a table which tells you the number of characters that match based on the Rashi and Nakshatra of Groom and Bride. And it tells if the Characters are less that 17, it's not good. If the Characters are more that 17 and less that 33, It's good. If it's more than 33 it's very very Good.

Based on this info I have a back end Sqlite database which contains this table. And fro the front end I get the information about Gotra, Raashi, Nakshtra and Nadi of Bride and Groom. And then I get the characters from the table for respective Raashi, Nakshatra details. And then I show the result based on the characters Match. This is just the intial basic check. For the more detailed Kundali match you can visit to a astrologer.

Here are the screen shots of the app. And you can download it from the Google play. Kundali match



Monday, August 1, 2016

Adding Internet Radio to Android Application

Greetings of the day!!!

I was working with my SRSM panchanga and wanted to add the internet radio station which was developed by my friend Rajaraman. This radio is a 24X7 gururaghavendra radio station: www.gururaghavendra.net/radio/  which plays Sri Raghavendra songs, pravachanas etc from Mantralaya.

You can download the working of this here:

SRSM Panchanga


  


It's very easy to develop this.

First I have added a button in the main.xml to display the radio by clicking on it, application should invoke the Radio Screen. Here is the xml code for that Button:

 <Button
            android:id="@+id/button8"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center_horizontal"
            android:text="Gururaghvendra Radio"
            android:textColor="#FF0000"
            android:textSize="10pt"
            android:textStyle="bold"/>


In the Main.java, I have created a referenced to this Button as below

Button  b8=(Button)findViewById(R.id.button8);

And in Main.java, for clicking of this button I want to invoke radio. So I assume I will create radio.java which contains the Radio Activity.

So Here is the code to invoke that. For that I use setOnClickListener():

 b8.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent k=new Intent(Main.this, radio.class);
startActivity(k);
}
});


For Radio activity, I create the xml as radio.xml. In this I create two buttons as Play and Stop which I am going to use to play and Stop the Radio. Here is the code for Radio.xml

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:text="Sri Gururaghavendra Radio"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/ekadashi_text_color"
        android:textStyle="bold" />

    <Button
        android:id="@+id/play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_margin="10dip"
        android:layout_marginLeft="17dp"
        android:layout_marginTop="70dp"
        android:text="Play" />

    <Button
        android:id="@+id/stop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/play"
        android:layout_margin="10dip"
        android:layout_marginTop="21dp"
        android:text="Stop" />

   </RelativeLayout>

Now I will create Radio.java file

public class radio extends Activity {
private Button b1,b2,b3,b4;
private ProgressBar ProgressBar;
private ProgressDialog pDialog;

MediaPlayer  mPlayer = new MediaPlayer();
    private Button buttonPlay;

    private Button buttonStop;

    private MediaPlayer player;
    final String url ="<Radio URL-Stream>";// you need to update your radio link
 
 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.radio);

        buttonPlay = (Button) findViewById(R.id.play);
        buttonStop = (Button) findViewById(R.id.stop);
     
        buttonStop.setEnabled(false);


buttonPlay.setOnClickListener(new OnClickListener() {
       
            public void onClick(View v) {
            
             mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
             GetConnect_Radio Rd = new GetConnect_Radio();
             Rd.execute();

  }
        });
     

 buttonStop.setOnClickListener(new OnClickListener() {
         
            public void onClick(View v) {
            
            
             if(mPlayer!=null && mPlayer.isPlaying()){
            
                     mPlayer.stop();
                   
                 }
            
              buttonStop.setEnabled(false);
                  buttonPlay.setEnabled(true);
            }
        });  
 }
 

**
     * Background Async Task to connect to Radio
     */
    class GetConnect_Radio extends AsyncTask<String, String, String> {

    
     /**
         * Before starting background thread Show Progress Dialog
         */
        @Override
        protected void onPreExecute() {
         pDialog =new ProgressDialog(radio.this);

            pDialog.setMessage("Connecting to Radio. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();

        }
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
        try {
        
            mPlayer.setDataSource(url);
        } catch (IllegalArgumentException e) {
         pDialog.dismiss();
            //Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        } catch (SecurityException e) {
         pDialog.dismiss();
           // Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        } catch (IllegalStateException e) {
         pDialog.dismiss();
           // Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        } catch (IOException e) {
         pDialog.dismiss();
            e.printStackTrace();
        }
        try {
         //mPlayer.prepareAsync();
            mPlayer.prepare();
        } catch (IllegalStateException e) {
         pDialog.dismiss();
            //Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        } catch (IOException e) {
         pDialog.dismiss();
            //Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        }
        mPlayer.start();
return null;
}
/**
     * After completing background task Dismiss the progress dialog
     **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog once got all details
        pDialog.dismiss();
     
        ///

        runOnUiThread(new Runnable() {
            public void run() {
               buttonStop.setEnabled(true);
                   buttonPlay.setEnabled(false);
            }
         
        });

     }
    
    }
}


 " final String url " you have to assign the Radio stream URL.  Now run this code and see how the radio plays . You can download and see this apk to run this radio here:


All the best and happy coding!!!
        

Thursday, June 30, 2016

Populating listview with multiple columns from sqlite database in android

Greetings Of The Day!!!

This Blog teaches you how to implement multi column list view in Android. Data of the list view is fetched from the sqlite database or it can be hard coded. We discuss both the scenarios.

Here is the listview with multiple rows and multiple columns as : Maas, Paksha, Tithi, Aradhane and Vrudavan Place.


This information is available in the sqlite database.Table Name is: Aradhane and the structure is as below:


The sample of the data's available is as below:


First Create the Keys for the hashmap to store the strings

private static final String TAG_MAAS = "maas";
private static final String TAG_PAKSHA = "paksha";
private static final String TAG_TITHI = "tithi";
private static final String TAG_ARADHANE = "aradhane";
private static final String TAG_VRD = "vrindavan_place";

Create a Listview



ListView lv;


lv = (ListView) findViewById(R.id.listView);
?
Create an Arraylist which will hold the HashMap



ArrayList<HashMap<String, String>> aradhanelist=
new ArrayList<HashMap<String, String>>();



HashMap<String, String> map = new HashMap<String, String>();



Add data to HashMap in Key-Value form
Here the data is hard coded.
1
2
3
4
5
map.put(TAG_MAAS, "Chaitra");
map.put(TAG_PAKSHA, "Shukla"); map.put(TAG_TITHI, "Navami"); map.put(TAG_ARADHANE, "Kaveendra Teertharu"); map.put(TAG_VRD, "Navavrumdavan Gadde");
Add HashMap to ArrayList
1
aradhanelist.add(map);
Now Create a SimpleAdapter


  • Pass context as first argument.
  • In the second argument you need to pass the layout in which you want your list to appear.
  • Then for each column you need to add a string value which is a key in your hashmap. Keys as defined at start of the program
  • Corresponding to each column you need to pass the view-item id to this constructor as a fourth argument.
  • Each new hashmap is our new row.

SimpleAdapter adapter =
new SimpleAdapter(Aradhane.this,aradhaneList, R.layout.aradhane_list,
new String[]{TAG_MAAS, TAG_PAKSHA, TAG_TITHI,TAG_ARADHANE,TAG_VRD},
new int[]{R.id.maas, R.id.paksha, R.id.tithi,R.id.aradhane,R.id.vrind});
// updating listview
lv.setAdapter(adapter);

Instead of hard coding the data, you can get from the sqlite. for that you can use the below code:


DBAdapter dbAdapter=DBAdapter.getDBAdapterInstance(Aradhane.this);
try { dbAdapter.createDataBase(); } catch (IOException e) { Log.i("*** select ",e.getMessage()); } dbAdapter.openDataBase(); String query="SELECT * FROM aradhane"; ArrayList<ArrayList<String>> stringList = dbAdapter.selectRecordsFromDBList(query, null); dbAdapter.close(); int max= stringList.size()-1; for (int i = 0; i < max; i++) { ArrayList<String> list = stringList.get(i); HashMap<String, String> map = new HashMap<String, String>(); String maas=list.get(0); String paksha=list.get(1); String tithi=list.get(2); String aradhane=list.get(3); String vrinda=list.get(4); map.put(TAG_MAAS, maas); map.put(TAG_PAKSHA, paksha); map.put(TAG_TITHI, tithi); map.put(TAG_ARADHANE, aradhane); map.put(TAG_VRD, vrinda); aradhaneList.add(map); } SimpleAdapter adapter =
new SimpleAdapter(Aradhane.this,aradhaneList, R.layout.aradhane_list,
new String[]{TAG_MAAS, TAG_PAKSHA, TAG_TITHI,TAG_ARADHANE,TAG_VRD}, new int[]{R.id.maas, R.id.paksha, R.id.tithi,R.id.aradhane,R.id.vrind}); // updating listview lv.setAdapter(adapter);           


Aradhane.java looks like this:


package com.sarga.simplecal;

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

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import android.app.Activity;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class Aradhane extends Activity  {
    ListView listView,lv;
    private static final String TAG_MAAS = "maas";
    private static final String TAG_PAKSHA = "paksha";
    private static final String TAG_TITHI = "tithi";
    private static final String TAG_ARADHANE = "aradhane";
    private static final String TAG_VRD = "vrindavan_place";

    

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.aradhane);
        
        aradhaneList = new ArrayList<HashMap<String, String>>();
        
        lv = (ListView) findViewById(R.id.list);
        GetAradhaneList();
        
         }
   
    public void GetAradhaneList(){
    
    
      
DBAdapter dbAdapter=DBAdapter.getDBAdapterInstance(Aradhane.this);
  try {
  dbAdapter.createDataBase();
  } catch (IOException e) {
  Log.i("*** select ",e.getMessage());
  }
      dbAdapter.openDataBase();
 
      String query="SELECT * FROM aradhane";
     
      ArrayList<ArrayList<String>> stringList = dbAdapter.selectRecordsFromDBList(query, null);
 
  dbAdapter.close();
 
  int max= stringList.size()-1;
  for (int i = 0; i < max; i++) {
  ArrayList<String> list = stringList.get(i);
  HashMap<String, String> map = new HashMap<String, String>();
  String  maas=list.get(0);
  String  paksha=list.get(1);
  String  tithi=list.get(2);
  String  aradhane=list.get(3);
  String vrinda=list.get(4);
 
  map.put(TAG_MAAS, maas);
                        map.put(TAG_PAKSHA, paksha);
                        map.put(TAG_TITHI, tithi);
                        map.put(TAG_ARADHANE, aradhane);
                        map.put(TAG_VRD, vrinda);
                        aradhaneList.add(map);
  }
 
    
  SimpleAdapter adapter =
 new SimpleAdapter(Aradhane.this,aradhaneList, 
R.layout.aradhane_list, new String[]{TAG_MAAS, TAG_PAKSHA, TAG_TITHI,TAG_ARADHANE,TAG_VRD},
                 new int[]{R.id.maas, R.id.paksha, R.id.tithi,R.id.aradhane,R.id.vrind});
          // updating listview
          lv.setAdapter(adapter);
          
          return;
    
    }
    

      
}



Layouts :
aradhane.xm

<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:shrinkColumns="*" android:stretchColumns="*" android:orientation="vertical"> <TableRow android:layout_height="match_parent" android:gravity="center_horizontal" > <include layout="@layout/aradhaneheader" /> </TableRow> <TableRow android:layout_height="match_parent" android:gravity="center_horizontal" > <ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/list" android:layout_gravity="center_horizontal" android:layout_weight="1" /> </TableRow> </TableLayout>
Aradhaneheader.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <TableLayout
        android:background="#008000"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal">

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

            <TextView
                android:textColor="#1B0082"
                android:layout_span="10"
                android:text="Aradhane List"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:textStyle="bold"
                android:gravity="top|center"
                />

        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <TextView
                android:text="Maas"
                 android:textColor="#1B0082"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="15dp"
               />

            <TextView
                android:text="Paksha"
                 android:textColor="#1B0082"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:layout_marginRight="10dp"
                />



            <TextView
                android:text="Tithi"
                 android:textColor="#1B0082"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_column="7"
                android:layout_marginRight="15dp"/>
         
            <TextView
                android:text="Aradhane"
                android:textColor="#1B0082"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_column="7"
                android:layout_marginRight="10dp"
                android:layout_marginLeft="4dp" />
         
           
            <TextView
                android:text="Vrundavan@"
                 android:textColor="#1B0082"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_column="7"
                android:layout_marginRight="5dp"/>

        </TableRow>


    </TableLayout>


</LinearLayout>

Aradhane_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:shrinkColumns="*"
    android:stretchColumns="*"
    android:orientation="vertical">


    <TableRow
     
        android:layout_margin="1dip"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:layout_width="0dp"
        android:background="#ff9999" >

 
    <TextView
        android:id="@+id/maas"
   
        android:textColor="#1B0082"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="left|center"
        android:layout_margin="1dip"
        android:layout_span="10"/>

        <TextView
            android:id="@+id/paksha"
         
            android:textColor="#1B0082"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="left|center"
            android:layout_margin="1dip"
            android:layout_span="10"/>

    <TextView
        android:id="@+id/tithi"
     
        android:textColor="#1B0082"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="left|center"
        android:layout_margin="1dip"
        android:layout_span="10" />
 
     <TextView
        android:id="@+id/aradhane"
     
        android:textColor="#1B0082"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:layout_margin="1dip"
        android:layout_span="20" />
   
      <TextView
        android:id="@+id/vrind"
     
        android:textColor="#1B0082"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:layout_margin="1dip"
        android:layout_span="10" />

 
    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    </TableRow>


</TableLayout>
 

That's it. Happy Coding