An android application that will display toast(Message) on specific interval of time. - android programming

No comments
Create an application that will display toast(Message) on specific interval of time.

Program:

AndroidManifest.xml

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

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

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

</manifest>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:id="@+id/activity_main"
   
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="com.android.infiapps.p7.MainActivity"
>

    <TextView
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="Hello World!"
/>
</RelativeLayout>

MainActivity.java

package com.android.infiapps.p7;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {
    Timer t=new Timer();


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

        final Handler h=new Handler();
        final Runnable r=new Runnable() {
            @Override
           
public void run() {
                Toast.makeText(getApplicationContext(),"hello",Toast.LENGTH_SHORT).show();
            }
        };
        t.scheduleAtFixedRate(new TimerTask() {
            @Override
           
public void run() {
                h.post(r);
            }
        },1000,5000);
    }

    protected void onDestroy(){
        Toast.makeText(this,"Finish",Toast.LENGTH_SHORT).show();
        t.cancel();
        t.purge();
    }
}

Output:

No comments :

Post a Comment

Create sample application that draw the circle, oval shape and square in android - android programming

No comments
Create sample application that draw the circle, oval shape and square.

Program:

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:id="@+id/activity_main"
   
android:layout_width="wrap_content"
   
android:layout_height="wrap_content"
   
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="com.example.anksh.prac9.MainActivity">

    <
ImageView
       
android:layout_width="match_parent"
       
android:layout_height="200dp"
       
android:layout_marginTop="100dp"
       
android:id="@+id/imageView2"
       
android:layout_alignParentTop="true"
       
android:layout_centerHorizontal="true" />

    <
Button
       
android:text="Start"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:id="@+id/bsrt1"
       
android:layout_alignParentBottom="true"
       
android:layout_alignParentStart="true"
       
android:layout_marginBottom="17dp" />

    <
Button
       
android:text="Stop"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:id="@+id/Bsp2"
       
android:layout_marginBottom="35dp"
       
android:layout_alignParentBottom="true"
       
android:layout_alignParentEnd="true" />

</
RelativeLayout>

MainActivity.java

package com.example.anksh.prac9;

import android.graphics.drawable.AnimationDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    Button
bst2,bstr1;
   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);

       
final ImageView gyroView = (ImageView) findViewById(R.id.imageView2);
       
bstr1=(Button)findViewById(R.id.bsrt1);
       
bst2=(Button)findViewById(R.id.Bsp2);

        gyroView.setBackgroundResource(R.drawable.
file1); //1
        //create an animation drawable using the background
       
final AnimationDrawable gyroAnimation = (AnimationDrawable) gyroView.getBackground();//2

        //start the animation
       
bstr1.setOnClickListener(new View.OnClickListener() {

           
@Override
           
public void onClick(View v) {
               
// TODO Auto-generated method stub

               
gyroView.post(new Runnable() {

                   
@Override
                   
public void run() {
                       
// TODO Auto-generated method stub
                       
gyroAnimation.start(); //3
                   
}
                });
            }
        });

       
bst2.setOnClickListener(new View.OnClickListener() {

           
@Override
           
public void onClick(View v) {
               
// TODO Auto-generated method stub
               
gyroAnimation.stop();
                System.exit(
0);
            }
        });
    }
    }

File1.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
   
android:oneshot="false"
>

    <
item
       
android:drawable="@drawable/a1"
       
android:duration="200"
/>
    <
item
       
android:drawable="@drawable/a2"
       
android:duration="100"
/>
    <
item
       
android:drawable="@drawable/a3"
       
android:duration="100"
/>
    <
item
       
android:drawable="@drawable/a4"
       
android:duration="100"
/>
    <
item
       
android:drawable="@drawable/a5"
       
android:duration="100"
/>
    <
item
       
android:drawable="@drawable/a6"
       
android:duration="100"
/>
    <
item
       
android:drawable="@drawable/a7"
       
android:duration="100"
/>
    <
item
       
android:drawable="@drawable/a8"
       
android:duration="100"
/>

</
animation-list>

Output:



No comments :

Post a Comment

Create the sample application that Rotate a green rectangle shape/image and after that double the size of that object and then shrink back to our starting size. - animation in android

No comments
Create the sample application that Rotate a green rectangle shape/image and after that double the size of that object and then shrink back to our starting size.

Program:

AndroidManifest.xml

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

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

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

</manifest>

activity_main.xml

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:id="@+id/activity_main"

    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="com.android.infiapps.myapplication10.MainActivity">



    <ImageView

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:layout_centerHorizontal="true"

        android:id="@+id/iv"

        android:layout_alignParentTop="true" />

</RelativeLayout>
MainActivity.java
package com.android.infiapps.myapplication10;



import android.graphics.Color;

import android.graphics.drawable.ShapeDrawable;

import android.graphics.drawable.shapes.RectShape;

import android.media.Image;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.widget.ImageView;



public class MainActivity extends AppCompatActivity {



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);



        ImageView iv;

        iv=(ImageView)findViewById(R.id.iv);



        ShapeDrawable sd=new ShapeDrawable(new RectShape());

        sd.setIntrinsicHeight(100);

        sd.setIntrinsicWidth(200);

        sd.getPaint().setColor(Color.GREEN);

        iv.setImageDrawable(sd);



        Animation a= AnimationUtils.loadAnimation(this,R.anim.spin);

        iv.startAnimation(a);

    }

}
Output:

No comments :

Post a Comment