Thursday, May 12, 2016

Android Splash Screen using Android Studio

Most of the Android apps uses splash screen before launching their application activity. You can see that with most popular apps such as Skype, Facebook, Dropbox etc.

While I was developing an Android APP POC for one of my customer, the requirement was to create a splash screen with their logo which stays on the screen for 3 seconds. It can be done very easily with the below steps.

First we have to create a new project in the Android studio :
1. Click on File -> New Project
2. Mention the application Name And Minimum SDK, Click on Next
3. Select Blank Activity and Click Next Button
4. Click on Finish

This create the android application with blank activity. Now we will add the Splash screen at the start this application.
First Create a layout to display the Splash screen. We call it as splash.xml.


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


We have to copy the splash_image.jpg image file to drawable folder. This is the image which is going to be shown in the splash screen.

Now create a activity which sets this splash content view. This activity we call it as SplashScreen.java. Put the below code to this class

SplashScreen.java   
package marutsoft.vehicledata;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.widget.ImageView;
 
/**
 * Created by Karjol G T on 11-05-2016.
 */
public class SplashScreen extends Activity {
 
    protected int _splashTime = 3000;
     private Thread splashThread;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Display display = getWindowManager().getDefaultDisplay();
        setContentView(R.layout.splash);
        Thread timerThread = new Thread(){
            public void run(){
                try{
                    sleep(3000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }finally{
                    Intent intent = 
                    new Intent(SplashScreen.this,MainActivity.class);
                    startActivity(intent);
                }
            }
        };
        timerThread.start();
    }
 
    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        finish();
    }
}
  
We have mentioned the sleep for 3000 ms that’s 3 seconds. Here Once the splash screen is done it invokes MainActivity.class.

Now we have to include the splash activity to Manifest and we have to make it as a launcher activity to start the application with this activity. You need to add the below code to the AndroidManifest .xml file. 

<activity
            android:name=".SplashScreen"
            android:label="@string/app_name" >
            <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>    

Now Run this Android application to check the Splash screen running at the beginning of the application.

That’s it. Happy Coding..


Saturday, May 7, 2016

Sorting Multi-Dimensional Arrays in PHP

I was working on a project. I had to do lot of interaction between mysql server and my android app. In that case I got a situation where I get the raw data from database which I need to sort and show on the fly. This data is in multi dimensional array.

I use to get the items data from mysql based on the user id.


    $result = mysql_query("SELECT * FROM savedlist where uid='$uid' ") or die(mysql_error());
   if (mysql_num_rows($result) > 0) {

         $response['products'] = array();
         while ($row = mysql_fetch_array($result)) {
         // temp user array
        $itemtypes = array();
        $itemtypes['id']=$row['pid'];
     
        $result1 = mysql_query("SELECT * FROM items where id='$row[pid]'") or die(mysql_error());
     
     
        while ($row1 = mysql_fetch_array($result1)) {
         
         
        $itemtypes['name'] = $row1['name'];
        $itemtypes['price']=$row1['price'];
        $itemtypes['bay']=$row1['bay'];
         
        }
         
            print_r($itemtypes, true);
   
         // push single product into final response array
        array_push($response['products'], $itemtypes);
     
        $bays = array();
        foreach ($response['products'] as $bay)
        {  
            $bays[] = $bay['bay'];
     
        }
        array_multisort($bays,SORT_ASC, $response['products'] );
     
     
     
    }

Here
$response['products']  is  a multi dimensional array which I want to sort it based on the BAY. So first I create another array $bays[] based on the bay type. And then sort it using array_multisort()

I used the below function to sort  $response['products'] array based on $bays as:

 array_multisort($response['products'], SORT_ASC, $bays);

That's it. Happy Coding

Thursday, May 5, 2016

Durmukhi Naam Samvastara SRSM Panchanga is available to Download

Greeting of the Day!!!

First of all I am very sorry for delaying in Updation of Durmukhi Naam Samvastara data. And Thanks to all those who written to me to update it. Now It's updated and the app is ready to download with all the data for Durmukhi Naam Samvastara.

Now it's available in English. Soon Kannada version of the app will be available to download.

You can download it from the play store at: SRSM panchanga
Please uninstall the older version of the application if installed and install this New version.

Sunday, April 3, 2016

How to make my facebook page status visible on my website

Greetings Of the day!!!

I was working on a website. And wanted to include the Updates from my facebook page to the website. I was wondering how to do it. But when I visited the facebook developer console I found the easy solution to do it. Here is the solution how you can include the facebook updates from the facebook page to the website:

The Page plugin lets you easily embed and promote any Facebook Page on your website. Just like on Facebook, your visitors can like and share the Page without leaving your site.

1. You can go to  https://developers.facebook.com/docs/plugins/page-plugin/

2. Enter the details about the facebook page

       

3. After entering all the details. Press on Get Code button:

4. Copy the code popped up after pressing the get code button

 

5. You can paste this code in the HTML file of your website. And you should be able to see the facebook page with like and share button and all the status updates on this page.

You can visit the website: http://drvbhosagoudar-bioresearch.org/  and you can see this stuff at the left side.

That's it. Happy coding.

Friday, April 1, 2016

How to import an SQL file using the command line in MySQL

When I was working with MySql command prompt, I was wondering how to import an available sql file into the available database. 

First you need to open the MySql Command prompt. And select the database. Here "smartcart" is the database. Now I select that database using "use" command as below:

mysql> use smartcart;
Database changed

Now you need know the path of the sql file. Here "items.sql" is the file exported from the other mysql database which I want to import to this "smartcart" database. For that we can use source command.

mysql> source f:/items.sql;
Query OK, 0 rows affected (0.07 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.76 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Now you can check that the new table of the sql file is added to the database

mysql> show tables;
+---------------------+
| Tables_in_smartcart |
+---------------------+
| items               |
| users               |
+---------------------+
2 rows in set (0.00 sec)

mysql> select * from items;
Empty set (0.06 sec)

That's it. Happy coding.