Thursday, 31 May 2012

[TUTORIAL]How to make your own boot animations (with sound if you want)

NOTE: This method is tested and it works on CM7 ROMs and AOSP ROMs. I don't guarantee that it will work for stock ROMs (The ROM that came with your device)!

Xperia X8 users with cm6 0.25-follow this guide: http://se-lifestyle.com/viewtopic.php?f=42&t=5947

Introducion
Hi guys!
Today, I'm going to teach you how to make your own boot animations. Please read this thread carefully to the end, in order to succeed in making your boot animation.

Requirements:
-A photo-editing program (GIMP and Photoshop are the best), which can save pictures in .png format
-A text editor (everyone has that)
-An archive-managing program (Power Archiver, WinZip), that is capable of making .zip archives

Tutorial:
1. Create part0 and part1 folders (in this folders, the frames of the boot animation are stored. Usually, there are only 2 parts in a boot animation, but you can add as many as you want. The frames in the part0 folder are usually repeated once, and the frames in part1 folder are usually looped several times, or infinite.)
2. Draw every frame of your boot animation manually (save every frame as you do it. Save the first one as 10001.png, the second one as 10002.png, and so on. Save them in the part0 and part1 folders - the frames in part0 folder will be showed only once, and the frames in part1 folder will be looped. But, you can change that if you want. Changing the looping property will be discussed in the following steps. WARNING: ALWAYS SAVE THE FRAMES IN .PNG OR .JPG FORMAT!)
3. Make a desc.txt file in the directory where the part0 and part1 folders are and edit it as following:
320 480 30
p 1 0 part0
p 0 0 part1
(The numbers 320 and 480 is the resolution of your boot animation. Change them as you want. The number 30 means the speed of the animation. Speed set to 30 is good for me. Then, the "p 1 0 part0" property means that the frames in part0 folder will be repeated once - you point that with the first number in the "p 1 0 part0" property, which in this case is 1. The second number is the delay between loops, and it's expressed in milliseconds (1000ms = 1s). I've set it to 0 because I don't want to be any delay between my loops (p 1 0 part0). And last, but not least, you set the folder with the folder name - in this case is part0. Then, you type the property for the part1 folder - that's "p 0 0 part1". The first "0" means that the folder will be looping infinite times, the second "0" means there's no delay between loops, and then we set the folder to part1. Note: if you have more folders, you'll have to write properties for them too!WARNING: DON'T FORGET TO LEAVE AN EMPTY LINE AT THE END OF THE DESC.TXT FILE!)
4. Compress the folders and the desc.txt file in a zip file (WARNING: MAKE SURE YOUR COMPRESSION METHOD IS STORE! OTHERWISE, THE BOOT ANIMATION WON'T WORK!)
5. Open your new boot animation and check the folders, if there are Thumbs.db files. If there are Thumbs.db files in your boot animation, delete them from the archive.
6. Install your boot animation on your device with one of the following methods:
Root Explorer method:
1. Rename your boot animation to bootanimation
2. Put it on your SD card
3. Open Root Explorer and copy bootanimation.zip to /system/media. This will replace the existing boot animation
4. Reboot your phone

ADB method:
1. Make sure you have downloaded android sdk 
2. Put android sdk in C:\
3. Set the directory of command prompt to C:\android-sdk-windows\platform-tools. Click here for a video tutorial.
4. Rename your boot animation to bootanimation and put it in C:\android-sdk-windows\platform-tools
5. Open cmd
6. Type in order:
-adb remount
-adb push bootanimation.zip /system/media/bootanimation.zip
-adb reboot
7. Enjoy your new boot animation!

[B][SIZE="3"]Note: You can always preview your boot animation with my program called Boot Animation Previewer.
[SIZE="3"][B]Note: I've made a program called Boot Animation Creator, that makes the desc.txt file for you and compresses the animation with the right settings.

How to add sound:
Originally Posted by hockeyfamily737
0. It's recommended to do a nandroid backup first!

1. Download the "bootsnd.sh" file and put it on the root of your sd card.

2. Download the "android_audio.mp3" file and using root explorer copy it to /system/media

3. Open Terminal Emulator and type the following commands using the stock keyboard. Press enter after each line:
su
cd /sdcard
sh bootsnd.sh
reboot

4. As the device boots up you will be greeted by the "Dolby THX" test sound heard before movies. You are now free to replace the android_audio.mp3 file in /system/media with any .mp3 file you like as long as you rename it to "android_audio.mp3"

5. DO NOT ATTEMPT TO OUTSMART THESE DIRECTIONS OR YOU WILL BE RESTORING YOUR NANDROID BACKUP!

6. Enjoy

http://dl.dropbox.com/u/30200380/bootsnd.sh
http://dl.dropbox.com/u/30200380/android_audio.mp3
Video tutorial:




Common mistakes that people make:
-Wrong compression method: you MUST set the compression method to Store!
-Missing empty line at the end of the desc.txt file: an empty line is needed! Otherwise, the boot animation won't work!
-Frames drawn in wrong color mode: you MUST draw your frames in RGB 8bit or RGB 16bit COLOR MODE!

Monday, 21 May 2012

Running a service in background on Android


Here the code is generate to run some process in background through service. For example we are running the time in background and displaying it in the UI. The service coding will be in a seperate class MyService.java

MyService.java
package com.services.demo;

import java.util.Date;
import android.app.Service; import android.content.Intent; import android.os.Handler; import android.os.IBinder; public class MyService extends Service { public static final String BROADCAST_ACTION = "com.services.demo.ServiceDemoActivity"; private final Handler handler = new Handler(); Intent intent;
int counter = 0; @Override public void onCreate() { // Called on service created intent = new Intent(BROADCAST_ACTION); } @Override
public void onDestroy() { // Called on service stopped }
@Override public void onStart(Intent intent, int startid) { int i = 0; while (i < 101) { if (i > 100) { this.onDestroy(); } else { counter = i; i++; handler.removeCallbacks(sendUpdatesToUI); handler.postDelayed(sendUpdatesToUI, 1 * 1000); // 1 sec }
} } private Runnable sendUpdatesToUI = new Runnable() { public void run() { DisplayLoggingInfo(); handler.postDelayed(this, 1 * 1000); // 1 sec }
}; private void DisplayLoggingInfo() { intent.putExtra("time", new Date().toLocaleString()); intent.putExtra("counter", String.valueOf(counter)); sendBroadcast(intent); }
public static boolean isRunning() { return true; } @Override
public IBinder onBind(Intent intent) { return null; } }

So for starting the service and stopping the service we will be using

Java
startService(new Intent(ServiceDemoActivity.this, MyService.class));
stopService(new Intent(ServiceDemoActivity.this, MyService.class));

For updating the UI we need to use the broadcast service. In that BroadcastReceiver we will update the UI

Java
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateDate(intent);
}
}; private void updateDate(Intent intent) { String time = intent.getStringExtra("time"); TextView date = (TextView) findViewById(R.id.date); date.setText(time); }
In the MyService.java the method DisplayLoggingInfo() will send the broadcast to the activity to update the UI, the UI xml code is
main.xml
<?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"
 android:id="@+id/notification"
 />

 <TextView
 android:layout_width="fill_parent" android:id="@+id/date"
 android:layout_height="wrap_content" android:text="" android:gravity="center" android:textSize="20sp" android:padding="20dp"/>
 <Button android:id="@+id/stop" android:text="Stop Service" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>

If we are opening the application on the first time means, it will be like this

and if we go out and come back to the page means, it will be showing a message like this

and if we stop the service means, it will be showing a message like this

You can download the full source code


Download source

Creating keystore and google api key for android google maps

Open the command prompt and follow the steps

D:\Android\tools
(Where android SDK is installed)

$ keytool -genkey -v -keystore my-release-key.keystore-alias alias_name -keyalg RSA -keysize 2048 -validity 10000
(which is for getting key from android)


C:\Users\balaji\.android
(this is area to get the debugkey
note if u r attempting second time the name the "debug key"  need to be changed)



D:\android-sdk-windows-1.6_r1\tools>keytool -genkey -v -keystore projectkey.keystore -alias aliasname -keyalg RSA -keysize 2048 -validity 15000
Enter keystore password: ------------
What is your first and last name?
[Unknown]: ------------
What is the name of your organizational unit?
[Unknown]: ------------
What is the name of your organization?
[Unknown]: ------------
What is the name of your City or Locality?
[Unknown]: ------------
What is the name of your State or Province?
[Unknown]: ------------
What is the two-letter country code for this unit?
[Unknown]: ------------

D:\android-sdk-windows-1.6_r1\tools>keytool -list -alias aliasname -keystore projectkey.keystore
Enter keystore password:
aliasname, Dec 7, 2010, PrivateKeyEntry,
Certificate fingerprint (MD5): CA:CF:AA:0E:5A:2B:88:C8:64:F1:FA:F7:29:21:50:FF

Using your Certificate fingerprint (MD5) get google api key from this site
http://code.google.com/android/maps-api-signup.html

Friday, 18 May 2012

Dynamically adding rows to TableLayout



@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

/* creating the table layout*/
       
        TableLayout layout = new TableLayout (this);
       
        /* creating the table row*/
        TableRow tr = new TableRow(this);
        /* add row in table*/
       
           TextView b = new TextView (this);
            b.setText("Train No.");     
         b.setTextSize(14.5f);       
         b.setTextColor(Color.YELLOW);
         /* add textview in row*/
         tr.addView(b);


super.setContentView(layout);
}

Thursday, 17 May 2012

Basic Android background Service

Running sample program for background service

Step 1 :
Create sample service class
package com.javaorigin.android.sample.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class MyService extends Service {
 
   String tag="TestService";
   @Override
   public void onCreate() {
       super.onCreate();
       Toast.makeText(this, "Service created...", Toast.LENGTH_LONG).show();      
       Log.i(tag, "Service created...");
   }
 
   @Override
   public void onStart(Intent intent, int startId) {      
       super.onStart(intent, startId);  
       Log.i(tag, "Service started...");
   }
   @Override
   public void onDestroy() {
       super.onDestroy();
       Toast.makeText(this, "Service destroyed...", Toast.LENGTH_LONG).show();
   }

   @Override
   public IBinder onBind(Intent intent) {
       return null;
   }
}


Step 2 :
Create sample Activity class
package com.javaorigin.android.sample.service;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

public class SampleAction extends Activity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {      
       super.onCreate(savedInstanceState);
       TextView view = new TextView(this);      
       view.setText("Service Test");
       Intent i = new Intent();
       i.setClassName( "com.javaorigin.android.sample.service",
        "com.javaorigin.android.sample.service.MyService" );
       bindService( i, null, Context.BIND_AUTO_CREATE);
       this.startService(i);      
       setContentView(view);
   }
}


Step 3:
Configure AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.javaorigin.android.sample.service" android:versionCode="1"
   android:versionName="1.0">
   <application icon="@drawable/icon" label="@string/app_name">
       <service class=".MyService" name=".MyService">
         <intent-filter>
           <action android:value="com.javaorigin.android.sample.service.MY_SERVICE"
                   android:name=".MyService" />

           </intent-filter>
       </service>
      <activity android:name=".SampleAction"
                 android:label="@string/app_name">
           <intent-filter>
               <action name="android.intent.action.MAIN">
               <category name="android.intent.category.LAUNCHER">
           </intent-filter>
       </activity>

   </application>
   <uses-sdk minsdkversion="8">

</manifest>