Sunday, January 1, 2017

Talks



Shivaji The Managemeent Guru.





How to love and live in the life.





Ramleela 2016.




Saturday, December 24, 2016

Custom Toast In Android

What is Toast in android?

Andorid Toast can be used to display information for the short period of time. A toast contains message to be displayed quickly and disappears after sometime. 

The android.widget.Toast class is the subclass of java.lang.Object class.
You can also create custom toast as well for example toast displaying image.

Syntax for displaying simple toast.

Toast.makeText(getApplicationContext,"Your message comes here",2000).show();


This is about displaying the simple toast. this message will appear till the 2 second on screen.


Custom Toast

We can create custom toast in android. So, you can display some images like congratulations or some network status etc. It means you are able to customize the toast now.


Steps to create the custom toast in android
1) Create the customtoast.xml file. save it on res/drawable folder.
2) In MainActivity.java.  
    i) Create the LayoutInflater  instance.
   ii) Get the view object as defined in the customtoast.xml.
  iii)  Create the Toast class object.



activitymain.xml


  1. <RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:layout_centerHorizontal="true"  
  11.         android:layout_centerVertical="true"  
  12.         android:text="@string/hello_world" />  
  13.   
  14. </RelativeLayout>  




customtoast.xml


  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:androclass="http://schemas.android.com/apk/res/android"  
  3.       android:id="@+id/custom_toast_layout"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     android:orientation="vertical"  
  7.     android:background="#FF00FF"  
  8.      >  
  9.        
  10.     <ImageView  
  11.         android:id="@+id/custom_toast_image"  
  12.         android:layout_width="wrap_content"  
  13.         android:layout_height="wrap_content"  
  14.         android:src="@drawable/congratulation"/>  
  15.       
  16. <TextView  
  17.         android:id="@+id/custom_toast_message"  
  18.         android:layout_width="wrap_content"  
  19.         android:layout_height="wrap_content"  
  20.         android:text="custom toast" />  
  21. </LinearLayout> 




Activity class

  1. package com.baba.customtoastexample;  
  2. import android.os.Bundle;  
  3. import android.app.Activity;  
  4. import android.view.Gravity;  
  5. import android.view.LayoutInflater;  
  6. import android.view.Menu;  
  7. import android.view.View;  
  8. import android.view.ViewGroup;  
  9. import android.widget.Toast;  
  10.   
  11. public class MainActivity extends Activity {  
  12.      @Override  
  13.         public void onCreate(Bundle savedInstanceState) {  
  14.             super.onCreate(savedInstanceState);  
  15.             setContentView(R.layout.activity_main);  
  16.               
  17.         //Creating the LayoutInflater instance  
  18.             LayoutInflater li = getLayoutInflater();  
  19.         //Getting the View object as defined in the customtoast.xml file  
  20.             View layout = li.inflate(R.layout.customtoast,  
  21.               (ViewGroup) findViewById(R.id.custom_toast_layout));  
  22.            
  23.         //Creating the Toast object   
  24.             Toast toast = new Toast(getApplicationContext());  
  25.             toast.setDuration(Toast.LENGTH_SHORT);  
  26.             toast.setGravity(Gravity.CENTER_VERTICAL, 00);  
  27.             toast.setView(layout);//setting the view of custom toast layout  
  28.             toast.show();  
  29.         }  
  30.         @Override  
  31.         public boolean onCreateOptionsMenu(Menu menu) {  
  32.             getMenuInflater().inflate(R.menu.activity_main, menu);  
  33.             return true;  
  34.         }  
  35.   
  36. }  

Saturday, November 12, 2016

Intents in android

Android Intent is the message that is passed between components such as activities, content providers, broadcast receivers, services etc.
It is used with startActivity() method to invoke activity, broadcast receiver etc.
Android intents are mainly used to:
Start the service
Launch an activity
Display a web page
Display a list of contacts
Broadcast a message
Dial a phone call etc.
Types of Android Intents
There are two types of intents in android: implicit and explicit.
1) Implicit Intent

Implicit Intent doesn't specifiy the component. In such case, intent provides information of available components provided by the system that is to be invoked.
For example, you may write the following code to view the webpage.
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.javatpoint.com"));
startActivity(intent);

2) Explicit Intent

Explicit Intent specifies the component. In such case, intent provides the external class to be invoked.

Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
startActivity(i);
To get the full code of explicit intent, visit the next page.

Thursday, March 6, 2014

Background image in Android


In android activity we can give the background image. using the android:background="@drawable/imagename" we can give the image of particular activity.


Steps :-
step1:- crete the new android project.
step2:- copy the image.
step3:- paste it into res/drawable-hdpi folder.
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD step4:- open the main_activity.xml file and write the code        android:background="@drawable/yourimagename".
   Note:-give the image name without extension.


following some screen shots helps you .

Before copy of the image in you project your project structure is:



Copy image in your drive
paste your image into drawable-hdpi folder
 
After pase image file in drawable-hdpi folder your project structure shoud be like this


 in main_activity.xml file coding image

Coding:-
MainActivity.java

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

public class MainActivity extends Activity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}


2)activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/background"
    tools:context=".MainActivity" >

</RelativeLayout>




OUTPUT


 

Tuesday, February 25, 2014

Intent in Android

An intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components

An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities.
Simply and activity means if you press on particular button the another activity will be open.

Types of Android Activities/Intent.
  • Explicit Intent
  • Implicit Intent
Explicit Intent: After writing a single Activity, There comes a need   to call another activity to perform another task . For this we need the Explit Intent.

   Android provide android.content package in that we have to use Intent class. import the that class. as like import android.content.Intent;  
                                                       1)MainActivity.
   
                                                 2)AnotherActivity


Steps to implement Explicit Intent.

Step 1:- create New android project.

Step 2: Take one button in activity_main.xml file .
Step 3: set onClickListner  on them.
Step 4: create Intent class object and pass two argument of that class constructor that is (getApplicationContext(), AnotherActivity.class) 
1) first parametr is getApplicationContext() it will call the system resources
2)second parameter is your another activity class file name.

Step 5:How to create new activity in you project.
  •    Click on your project and press ctrl+n . or click on the prject then new->other->AndroidActivity.
        
  •    Click Next Button then give the of your own name for the your activity.

         Then automatically you .java and .xml file will be created.You can chek.
 

Following are the coding file of this Application.

MainActivity.java
package com.example.explicitintentdemo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
    Button b;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        b=(Button)findViewById(R.id.button_call_another_activity);
        b.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
            Intent intent=new Intent(getApplicationContext(),AnotherActivity.class);
            startActivity(intent);
               
            }
        });
       
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}


AnotherActivity.java
package com.example.explicitintentdemo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class AnotherActivity extends Activity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.another, menu);
        return true;
    }

}

activity_main.xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff00ff"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button_call_another_activity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="41dp"
        android:text="@string/call_another_activity" />

</RelativeLayout>
 
activity_another.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:background="#fff000"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".AnotherActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="62dp"
        android:text="This is Another Activity"
        android:textSize="30sp" />

</RelativeLayout>
String.xml

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

    <string name="app_name">ExplicitIntentDemo</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="call_another_activity">Call Another Activity</string>
    <string name="title_activity_another">AnotherActivity</string>

</resources>


AndroidManifest.xml

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.explicitintentdemo.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.explicitintentdemo.AnotherActivity"
            android:label="@string/title_activity_another" >
        </activity>
    </application>

</manifest>

Output:-
                                                         Our Application Output will be.
                                                  1)MainActivity
                                        if you click on call Another Activity then AnotherActiviy will be call.

Saturday, February 8, 2014

working with Button

User Interface in Android. 
     After successfully running the your hellow world example we turn to some UI (User Interface)Concept.
in Android.

     The graphical user interface for an Android app is built using a hierarchy of View and ViewGroup objects. View objects are usually UI widgets such as buttons or text fields and ViewGroup objects are invisible view containers that define how the child views are laid out, such as in a grid or a vertical list.
Android provides an XML vocabulary that corresponds to the subclasses of View and ViewGroup so you can define your UI in XML using a hierarchy of UI elements.

     Their are various User Interface are aviable thar are as follows:
  1. TextView.
  2. Button.
  3. ToggleButton.
  4. CheckBox.
  5. RadioButton.
  6. Spinner.
  7. ProgressBar.
  8. SeekBar.
  9. ImageView.
  10. DatePicker & TimePicker. 
Our Output Will be Following:-


working with Button  
 

Step 1:- First you need to create the new  Android Applicaiton Project.
 How to create it goto File->New->AndroidApplicationProject. One window will be open in that fill the requird information such as, Application Name, Project Name, Package Name etc.
  

    




















step2 :- follow the process till Finish Window will not come.
























After clicking the finish button. it will create the folder structure. and font of the window show the activity_main.xml and MainActivity.java file's.

















Step 3:-delete the hello world content in activity_main.xml file.
            on the left hand site of the screen Paletee ber select the  FormWidgest tab and take button from that.
 
















Step 4:- On Button you see the one triange in yellow color that is warning how to solve that warning.
              Goto res->values->string.xml(click on it) . Android Resources(Default) window will open on the     screen in that click on string  ->Add  




















Step 5:- In activiy_main.xml just click on button . and right bottom corner Propery window is there in that click on Button then one window will be disple in that choose the name wich you register in string.xml file ->ok.













after completing the this process you warning will remove from button.




















Step  6:- we have to perform the action on the button. that's why we need to write code in java file just open MainActivity.java file following is code of the java file.

MainActivity.java       

package com.baba.workingwithbutton;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //getting the reference of button.
        Button button=(Button)findViewById(R.id.button1);
       
        //set the event handeling on button
        button.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View arg0) {
                //when you click on the button then tost will be execuated
                Toast.makeText(getApplicationContext(), "Congratulation ! Your Button is working ",Toast.LENGTH_LONG).show();
               
            }
        });
       
       
    }
}


2)activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="76dp"
        android:text="@string/button" />

</RelativeLayout>






















 Output