• RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
Posted by Jack - - 4 comments


SPLASH SCREEN

SOURCE CODE [splash.xml] is

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
android:layout_width="fill_parent"
                android:layout_height="fill_parent">
               
                <ImageView android:src="@drawable/ splash "
android:id="@+id/imageView1"
                                android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
                                android:layout_width="250px"
android:layout_height="400px">
                </ImageView>

</RelativeLayout>

SOURCE CODE [SplashScreenExample.java] is

package com.SplashScreenExample;

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

public class SplashScreenExample extends Activity
{

                // how long until we go to the next activity
                protected int _splashTime = 5000;

                private Thread splashTread;

                /** Called when the activity is first created. */
                @Override
                public void onCreate(Bundle savedInstanceState)
{

                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.splash);

                                final SplashScreenExample sPlashScreen = this;

                                // thread for displaying the SplashScreen
                                splashTread = new Thread()
{
                                                @Override
                                                public void run()
{
                                                                try {
                                                                                synchronized (this) {
// wait 5 sec
                                                                                                wait(_splashTime);
                                                                                }
                                                                }
catch (InterruptedException e)
{
                //Exception handling
                                                                }
finally
{
                                                                                finish();

                                                                                // start a new activity
                                                                                Intent i = new Intent();
                                                                                i.setClass(sPlashScreen, MainActivity.class);
                                                                                startActivity(i);

                                                                                stop();
                                                                }
                                                }
                                };

                                splashTread.start();
                }

                // Function that will handle the touch
                @Override
                public boolean onTouchEvent(MotionEvent event)
{
                                if (event.getAction() == MotionEvent.ACTION_DOWN)
{
                                                synchronized (splashTread)
{
                                                                splashTread.notifyAll();
                                                }
                                }
                                return true;
                }

}

The OUTPUT will be


Added soon

Posted by Jack - - 20 comments

CUSTOM RATINGBAR

SOURCE CODE [main.xml] is

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

                <RatingBar android:id="@+id/ratingbar"
android:layout_width="wrap_content"
                                style="@style/CustomRatingBar"
android:layout_height="50px" />

</LinearLayout>


SOURCE CODE [styles.xml] is

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomRatingBar" parent="@android:style/Widget.RatingBar.Small">
<item name="android:progressDrawable”>@drawable/custom_ratingbar</item>
                <item name="android:minHeight">16dip</item>
                <item name="android:maxHeight">16dip</item>
</style>
</resources>

SOURCE CODE [custom_ratingbar.xml] is

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+android:id/background"
android:drawable="@drawable/custom_ratingbar_empty" />
    <item android:id="@+android:id/secondaryProgress"
android:drawable="@drawable/custom_ratingbar_empty" />
    <item android:id="@+android:id/progress"
android:drawable="@drawable/custom_ratingbar_filled" />
</layer-list>

SOURCE CODE [custom_ratingbar_filled.xml] is

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

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

<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/star_on" />

<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/star_on" />

<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/star_on" />

<item android:drawable="@drawable/star_on" />

</selector>

SOURCE CODE [custom_ratingbar_empty.xml] is

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

<selector xmlns:android="http://schemas.android.com/apk/res/android">
               
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/star_off" />

<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/star_off" />

<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/star_off" />

<item android:drawable="@drawable/star_off" />

</selector>

SOURCE CODE [CustomRatingBarExample.java] is

package Com.CustomRatingBarExample;

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

public class CustomRatingBarExample extends Activity
{
               
                RatingBar rb;

public void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

rb = (RatingBar) findViewById(R.id.ratingbar);
rb.setRating(3.5f);

}
}

Note:

Save the file [styles.xml] in values folder. This folder already has a file [strings.xml].
Save the files [custom_ratingbar.xml], [custom_ratingbar_filled.xml], [custom_ratingbar_empty.xml] in drawable folder.
Save the images [custom ratings icon – star_on.png, star_off.png] in the drawable folder.







The OUTPUT will be

 https://lh6.googleusercontent.com/-Of1zNlHcbe4/Tf7efZpeQJI/AAAAAAAAAJ0/00hnktman7E/custom_ratingbar.png

Posted by Jack - - 5 comments


SINGLE LINE TOAST 


Toast.makeText(getBaseContext(), "YOUR TEXT HERE", Toast.LENGTH_LONG).show();