Pages

Android Blink Animation (Resource Animation)

     As a developer, we always wanted to build a great application. Users can be attracted by using sleek design or using animation. What is animation? According to definition, it is a simulation of movement created by displaying a series of pictures or frames. Android platform provided us an easy way of creating animation.

     We have animation resources that defines two types of animations which are Property Animation and View animation. When we say property animation, it is an animation by modifying and object's property values over a set time or an animation defined in XML that modifies properties of the target object, such as background color/image or alpha value, over a set of time. while View animation can be divided into two categories: Tween animation and Frame animation. Tween animation is an animation by performing a series of transformation on a single image with an Animation. An animation showing a sequence of images in order with an AnimationDrawable.

     Enough on the discussion and let the fun begin :). I will show you how to make a "blink" animation on Android.

First, download the images below, we'll use it for the animation.





Or you can use your own images.We'll make a traffic light that blinks randomly :).

Create a new Android project on Eclipse and name it whatever you want. (It is not important and you can change it later)
Under res/ folder, create a new folder "anim" without the quotation and create a new XML file and name it "tween.xml". Copy and paste this code:
<set >
<alpha
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="100"
    android:repeatMode="reverse"
    android:repeatCount="infinite" />
</set>
Edit the main.xml file and copy and paste the code below:
<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:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sample Blink Animation on Android"
        android:textAppearance="?android:attr/textAppearanceMedium" />

        <FrameLayout
            android:id="@+id/rightIcon"
            android:layout_width="30.0dip"
            android:layout_height="30.0dip"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="10.0dip"
            android:layout_marginRight="10.0dip" >

            <ImageView
                android:id="@+id/bsecond"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:scaleType="fitXY"
                android:src="@drawable/img_red"
                android:visibility="visible" />

            <ImageView
                android:id="@+id/bfirst"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:scaleType="fitXY"
                android:src="@drawable/img_yellow"
                android:visibility="visible" />
        </FrameLayout>

        <FrameLayout
            android:id="@+id/rightIcon"
            android:layout_width="30.0dip"
            android:layout_height="30.0dip"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="10.0dip"
            android:layout_marginRight="10.0dip" >

             <ImageView
                android:id="@+id/bfourth"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:scaleType="fitXY"
                android:src="@drawable/img_green"
                android:visibility="visible" />
            <ImageView
                android:id="@+id/bthird"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:scaleType="fitXY"
                android:src="@drawable/img_red"
                android:visibility="visible" />

          
        </FrameLayout>

        <FrameLayout
            android:id="@+id/rightIcon"
            android:layout_width="30.0dip"
            android:layout_height="30.0dip"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="10.0dip"
            android:layout_marginRight="10.0dip" >

            <ImageView
                android:id="@+id/bsix"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:scaleType="fitXY"
                android:src="@drawable/img_red"
                android:visibility="visible" />
            <ImageView
                android:id="@+id/bfifth"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:scaleType="fitXY"
                android:src="@drawable/img_green"
                android:visibility="visible" />

           
        </FrameLayout>
    </LinearLayout>
For the main Activity, used the code below:


public class AndroidBlinkAnimationActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        animate();
    }
    
    private void animate(){
     ImageView myImageView1 = (ImageView) findViewById(R.id.bfirst);
     ImageView myImageView2 = (ImageView) findViewById(R.id.bthird);
     ImageView myImageView3 = (ImageView) findViewById(R.id.bfifth);
     
     Animation myFadeInAnimation = AnimationUtils.loadAnimation(AndroidBlinkAnimationActivity.this,
    R.anim.tween);
 
        myImageView1.startAnimation(myFadeInAnimation);
     myImageView2.startAnimation(myFadeInAnimation);
     myImageView3.startAnimation(myFadeInAnimation);
    }
        
}
 
In the code, I created a method "animate" that will handle the 
ImageViews and the Animation itself. And you now have a blink animation!
 
Output:


 


 

Android Accelerometer values for Compass


If you are wondering how to get the values of accelerometer on Android, this is the right place for you. Today, I will show you to display sensor values which you can use in implementing a compass.



Compass activity
package com.scamex.compass;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;

public class Compass extends Activity implements SensorEventListener {

 
 TextView tvvalues;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.compass);
  tvvalues = (TextView) findViewById(R.id.sensorvalues);
 }
 
 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
  attachSensor();
 }
 
 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  detachSensor();
 }
 
 private void attachSensor() {
  SensorManager sensorManager = getSensorManager();

  List sensors = sensorManager
    .getSensorList(Sensor.TYPE_ACCELEROMETER);
  if (sensors.size() > 0) {
   Sensor sensor = sensors.get(0);
   sensorManager.registerListener(this, sensor,
     SensorManager.SENSOR_DELAY_NORMAL);
  } else {

  }
 }
 
 private void detachSensor() {
  SensorManager sensorManager = getSensorManager();
  sensorManager.unregisterListener(this);
 }

 private SensorManager getSensorManager() {
  return (SensorManager) getBaseContext().getSystemService(
    Context.SENSOR_SERVICE);
 }
 
 
 public void onAccuracyChanged(Sensor sensor, int accuracy) {
 
  
 }

 public void onSensorChanged(SensorEvent event) { 
  float valuex = event.values[0];
  float valuey = event.values[1];
  float valuez = event.values[2];  
  tvvalues.setText("x: " + valuex + "\n" + "y: " + valuey + "\n" + "z: " + valuez);
 
 }

}




Edit you main XML file and add a TextView with the ID of 
android:id="@+id/sensorvalues" and run you application. That's it.



The ouput:



Radiant Defense Game

MILLIONS OF ALIENS WILL DIE
Radiant Defense is a tower defense game set in a vibrant universe invaded by countless alien hordes.
Build your space fortress any way you wish, set up wide variety of weapons and traps and let the invasions begin!
FEATURES
• Tower Defense set in the Radiant Universe
• Build your own route for incoming waves of enemies!
• More than 300 waves of aliens across 10 missions
• 9 upgradable weapons to kill the aliens with style
• 3 superweapons of mass defense
• Online hall of fame - your scores can only grow
• Signature soundtrack by Kubatko
IN-APP PURCHASES
Radiant Defense is free to play without any ads, supported only by in-app purchases. Each in-app purchase greatly enhances your tactical options.
REVIEWS
"Radiant Defense Is One Of The Best Tower Defense Games On Android Right Now"
- Android Police
"It's refreshing to find a game that respects your intelligence, money, and time. All the better that it's good fun, too."
- Touch Arcade
"Radiant Defense is one of the best interpretations of the genre we’ve witnessed in an age. If you like this kind of game, you really should download it immediately."
- KnowYourMobile
"Radiant Defense is still a tower defense game, but it's a really good one. Get this game and start fending off the brilliantly bright waves of invaders that come your way."
- GameZebo
"Radiant Defense is an engrossing strategy game with lovely spacey visuals and just enough quirky touches to set it apart from the crowd. It's another triumph for Hexage"
- NokNok
SPECIAL THANKS
James Nichols
SUPPORT AND FEEDBACK
Please contact support@hexage.net with any inquiry or feedback.
Follow @hexage on Twitter for the latest development updates, news, events, tips:
MORE HEXAGE GAMES
Robotek
http://market.android.com/details?id=net.hexage.robotek.hd
In the great robot uprising machines took the planet over. It's time to take it back! One node at a time.
Radiant
http://market.android.com/details?id=net.hexage.radiant.hd
Radiant is a highly acclaimed retro arcade spaceshooter. Easy to play and challenging to master, Radiant is an action game with fun storyline, dozens of weapons, power-ups and bossfights.

EVAC
http://market.android.com/details?id=net.hexage.evac.hd
EVAC is an arcade game set in colorful neon mazes. EVAC provides classic chaser gameplay with action, puzzle and stealth elements. The game encourages replay with ever-growing total score and multiple ways how to beat each level.
Everlands
http://market.android.com/details?id=net.hexage.everlands.hd
Everlands is a turn-based game set in a colorful world of hand-painted animals. As their homeland gets invaded by mysterious evil, animals of the land have to unite, combine the best of their abilities and together stand against the threat.
Totemo
http://market.android.com/details?id=net.hexage.totemo.hd
Totemo is a mind-soothing logic/puzzle game designed for all people who like intelligent gameplay, atmosphere and a freedom to play at their own pace. Totemo provides 100 puzzle levels in story mode and a survival mode for those who like extra challenge and the opportunity to write their name into on-line leaderboard.
Buka
http://market.android.com/details?id=net.hexage.buka.hd
Buka is a cute game of skill. Facing the impossible odds of countless baddies, Buka has set on a quest to find The Happy Place. Protect her with powerful explosion blasts and shockwaves in a colorful cosmic mayhem.






Mobi Mosquito Repellent

Mobi Mosquito Repellent creates unique high frequency sound that repel mosquitoes. You no longer have to worry about pesky mosquitoes bothering you again.
This application works by creating a high pitch sound that mimics the known predators of the mosquito. This in turn scares away any mosquitoes that are in your vicinity.

Works only on devices that support of high-frequency speaker audio. Please ensure that your phone can produce high frequency sounds. Most phones for which this application is compatible can do so.
Use this application on your next camping trip or late night barbeque.




The Ultimate Dog Whistle

Your dog whistle, powered by the Android, has the ability to create sounds that can call a dog for far off distances. Amaze your friends and family with Dog Whistle - Ultimate. This whistle has an adjustable slider that allows you to change the frequency on the fly.
Main Uses:
  • Calling your dog
  • Training your dog and cats
  • Irriating the neighborhood animials (not recommended)

Enjoy hours of fun with this application.
Wikipedia Notes:
A dog whistle (also known as silent whistle or Galton's whistle) is a type of whistle used in the training of dogs and cats. It was invented by Francis Galton; the whistle was mentioned in his book Inquiries into Human Faculty and its Development. In his discussion (Galton 1883:26-27) of his experiments to test the range of frequencies that could be heard by various animals, he notes that cats have the most all-round sensitive hearing, being able from a considerable distance to hear notes too high in frequency for humans to hear, and small dogs can also hear these notes, while large dogs cannot.
The frequency range of a dog whistle is largely out of the range of human hearing. Human hearing is typically considered to be between 20 Hz and 20 kHz. A dog whistle is within the range of 23 to 54 kHz. Some dog whistles have adjustable sliders for active control of the frequency produced. Depending on the way the whistle is used, a trainer may simply gather a dog's attention or inflict pain for the purpose of behavior modification.



Android Mobi Solar Charger - Solar Cell

      Amaze your friends when you show them that your phone can act as a solar cell that charges your phone battery by just using the sunlight. Features included: Detects the amount of light in an area Vibrates when charging is completed Nice charging animation Future updates: Charge your car battery with your phone. The creator of this application does not take any responsibility for the damage and injury what the user may cause or suffer in the future, present or past with or without this software. 

      Note: Of course this application is not charging your phone. You didn't think so, did you?! The only reason for this app is to collect the mentally challenged trolls - who never read the description this far - complaining about every app. Or you can fool your friends with this nice 'charging feature' if you like. Do not let your device overheat! Be careful when you put your device under the direct sunlight!



Java Asterisk Pattern using Loops - Pattern Two

This is another simple application in Java that uses for loops in creating asterisk patterns.


public class PatternTwo {

    public static void main(String[] args) {

        for (int j = 5; j > 0; j--) {

   System.out.println("");

            for (int i = 5; i >= j; i--) {
                System.out.print(" ");
  
            }
for (int q = 0; q < j; q++) {
                System.out.print("*");
            }
        }
        System.out.println("");
    }
}


This is the sample output of the code above.

How to write and read files in Java?

Question

How can I write to and read from files in Java?

Answer 

Java applications have access to local files. It means that it can read and write to files. Let's take a look at two simple applications that write lines of text and read it back.

Application one:

import java.io.*;

public class WriteFile
{
 
 public static void main (String args[]) //entry point
 {
  // FileOutputStream object
  FileOutputStream fout;  

  try
  {
      // Open an output stream
      fout = new FileOutputStream ("myfile.txt");

      // Print a line of text
      new PrintStream(fout).println ("This is simple application to write lines of text. Pretty Cool!!");

      // Close our output stream
      fout.close();  
  }
  // Catches any error conditions
  catch (IOException e)
  {
   System.err.println ("There were some errors writing lines.");
   System.exit(-1);
  }
 } 
}

The above code creates a FileOutputStream and writes a line of text to a file called myfile.txt. We must enclose the writing of file with try{...}catch block to trap or catch any exception that may occur.

Reading files in Java is easy as well. The code below creates FileInputStream to read file and display it to the user.

Application Two:

import java.io.*;

public class ReadFile
{
 // Main method
 public static void main (String args[])
 {
  // FileInputStream to read file
  FileInputStream fin;  

  try
  {
      // Open an input stream
      fin = new FileInputStream ("myfile.txt");

      // Read a line of text
      System.out.println( new DataInputStream(fin).readLine() );

      // Close our input stream
      fin.close();  
  }
  // Catches any error conditions
  catch (IOException e)
  {
   System.err.println ("Unable to read lines from file");
   System.exit(-1);
  }
 } 
}


Java Asterisk Pattern using Loops - Pattern One

        To understand better about loops, asterisk patterns will be a very big help for aspiring programmers. There are lots of patterns to form using loops in Java (while, do while, for loops). One can even draw shapes, text, figures and others. Today, I will show you some of the asterisk patterns in Java.

       
public class PatterOne
{

 public static void main(String[]args){  
   for (int j = 7; j > 0; j--){
                System.out.println("");
   for (int i = 5; i >= j; i--){
                System.out.print("*");
            }
            }
  System.out.println("");

 }

}

Here is the sample output of the code above:



Implementing the QuaQua LookAndFeel in Java

      I like to show you how to implement the QuaQua Look And Feel in Java. I heard someone says that Java isn't that good when it comes to look and feel and Java is only good for algorithms, back ends and all other good stuffs. I found that statement partially true. Why? Because Java is really good for algorithms. But I must say that Java is as good as other programming language when talking about LAF. There are lots of workaround of customizing the LAF of your Java Desktop Application.

You can create an application what uses Windows LAF, Metal and other available LAF for Java. You can also create a desktop application that uses other LAF like the QuaQua Look and Feel described here.

Examples of the implementation of the QuaQua Look and Feel in Java.

quaqua look and feel in java

quaqua look and feel in java

quaqua look and feel in java


Wow! That is very nice and very professional looking for a Java application.
So, how to do that?

Download the  QuaQua package from the QuaQua Look And Feel website.
Add add quaquar.jar and swing-layout.jar to the classpath of your project.

 SwingUtilities.invokeLater(
new Runnable() {

public void run() {
try {
UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
} catch (Exception e) {
}
MainFrame MF = new MainFrame();
MF.setSize(647, 410);
MF.setLocationRelativeTo(null);
MF.setVisible(true);
MF.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
MF.getRootPane().setFont(UIManager.getFont("SystemFont"));
MF.getRootPane().putClientProperty("Quaqua.RootPane.isVertical", Boolean.FALSE);
MF.getRootPane().putClientProperty("Quaqua.RootPane.isPalette", Boolean.FALSE);
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);

Just use the code above to implement QuaQua Look And Feel in Java.

Credits:
Joel Benaldo
Jakemar Bantugan

Quingz - Web Designing and Development

If you are looking for a firm that can help you to create your own professional site, please visit this site which will answer your needs.

http://quingz.x10.mx

They offer reasonable price for your  professional website. Quingz - Web Designing and Development is the leading firm in creating professional and sleek looking website. They can also design a website banner for you (images like png, jpeg, gif or even flash) professionally.

Samples of their works: