Friday, 1 June 2012

Google Map View in our Program

mapexp.clas

package com.ann;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

import android.app.Activity;
import android.os.Bundle;

public class mapexp extends MapActivity{
MapView mv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    mv=(MapView)findViewById(R.id.map);
    mv.setClickable(true);
    mv.setBuiltInZoomControls(true);
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

}








AndroidManifest.xml




<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ann"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
         >
        <uses-library android:name="com.google.android.maps"/>
         <activity
            android:name=".mapexp"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
       
    </application>

</manifest>



main.xml

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

   <com.google.android.maps.MapView
       android:id="@+id/map"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:apiKey="0jG4xjFXTdrDqmRbIPau0v1DZnjdpNQ4Lu07qqg"
                 />

</LinearLayout>

Thursday, 31 May 2012

Google Map API key genaration in ubuntu

To the generation of the Google Map API,we first find out where is our java files are stored in ubuntu.In most cases the java files should be in the File System.

Here giving commands to get the Google API using terminal.

:~$ cd /
:~$ cd user
:~$ cd lib
:~$ cd jvm
:~$ cd java-6-openjdk
:~$ cd bin
then we want to get the keystore.To get the android default debug keystore:

eclipse->windows->preferences->Android ->Build, then copy the  default debug keystore.

eg: /home/anna/.android/debug.keystore \

:~$ keytool -list -alias androiddebugkey \-keystore /home/anna/.android/debug.keystore \
> -storepass android -keypass android


Then we will get an MD5 encrypted key.Copy that key,example(36:EF:BD:0C:1B:7F:7B:06:F9:34:90:A7:8E:83:34:28).
Then take the following link: https://developers.google.com/android/maps-api-signup
Then agree the teams and conditions to generate key.



then copy the given example xml layout to your application.

<com.google.android.maps.MapView
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:apiKey="0jG4xjFXTdrDqmRbIPau0v1DZnjdpNQ4Lu07qqg"
                 />

SplashScreen

package com.ann;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.MotionEvent;
import android.widget.TextView;

public class splashSereen extends Activity {
    protected boolean _active = true;
    protected int _splashTime = 10000;
  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
      
        SharedPreferences app_preferences =
                PreferenceManager.getDefaultSharedPreferences(this);
          
            // Get the value for the run counter
            int counter = app_preferences.getInt("counter", 0);
            if(counter==0)
            {
                 TextView txt=(TextView)findViewById(R.id.textView1);
               //  txt.setText(read());
               
                 // thread for displaying the SplashScreen
                 Thread splashTread = new Thread() {
                     @Override
                     public void run() {
                         try {
                             int waited = 0;
                             while(_active && (waited < _splashTime)) {
                                 sleep(100);
                                 if(_active) {
                                     waited += 100;
                                 }
                             }
                         } catch(InterruptedException e) {
                             // do nothing
                         } finally {
                             finish();
                             startActivity(new Intent("com.ann.MyBirthdayReminderActivity"));
                             stop();
                         }
                     }
                 };
                 splashTread.start();
            }
            else
            {
                Intent intent=new Intent(this,MyBirthdayReminderActivity.class);
                startActivity(intent);
            }
            SharedPreferences.Editor editor = app_preferences.edit();
            editor.putInt("counter", ++counter);
            editor.commit(); // Very important
    }
  
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            _active = false;
        }
        return true;
    }
  private String read()
  {
InputStream inputStream = getResources().openRawResource(R.raw.birth);
     
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
      
        int i;
     try {
      i = inputStream.read();
      while (i != -1)
         {
          byteArrayOutputStream.write(i);
          i = inputStream.read();
         }
         inputStream.close();
     } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
  
        return byteArrayOutputStream.toString();
   }
}


Splash screen using Activity


package com.ann;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;

public class splash extends Activity {
    protected boolean _active = true;
    protected int _splashTime = 5000;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
       
        // thread for displaying the SplashScreen
        Thread splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) {
                        sleep(100);
                        if(_active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    startActivity(new Intent("com.ann.start"));
                    stop();
                }
            }
        };
        splashTread.start();
    }
   
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            _active = false;
        }
        return true;
    }
}

Monday, 28 May 2012

Popup in android


Creating one window as PopupWindow to display the data

To create the popupwindow we want to create separate XML layout.
Here giving example 
popup.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@android:color/background_light">
 <LinearLayout
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:orientation="vertical"
     android:layout_margin="1dp"
     android:background="@android:color/darker_gray">
     >
     <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:layout_margin="20dp">
      <TextView
          android:layout_width="fill_parent"
          android:textColor="#00FF00"
          android:textStyle="bold"
          android:layout_height="wrap_content"
          android:text="It's a PopupWindow" />
      <ImageView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:src="@drawable/ic_launcher" />
      <Button
          android:id="@+id/dismiss"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Dismiss" />
      </LinearLayout>
 </LinearLayout>
</LinearLayout>

 PopupActivity.java


package com.ann;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;

public class PopupActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        final Button btnOpenPopup = (Button)findViewById(R.id.openpopup);
        btnOpenPopup.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
    LayoutInflater layoutInflater
     = (LayoutInflater)getBaseContext()
      .getSystemService(LAYOUT_INFLATER_SERVICE); 
    View popupView = layoutInflater.inflate(R.layout.popoup, null); 
             final PopupWindow popupWindow = new PopupWindow(
               popupView,
               LayoutParams.WRAP_CONTENT, 
                     LayoutParams.WRAP_CONTENT); 
            
             Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
             btnDismiss.setOnClickListener(new Button.OnClickListener(){

     @Override
     public void onClick(View v) {
      // TODO Auto-generated method stub
      popupWindow.dismiss();
     }});
              
             popupWindow.showAsDropDown(btnOpenPopup, 50, 30);
        
   }});
    }
}

main.xml

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

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <Button
        android:id="@+id/openpopup"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Open Popup Window" />
   
</LinearLayout>