Wednesday 27 June 2012

Covert Seconds to HH:mm:ss Format

Here the below gettimeFormat() method is taken no of seconds as input and retuns "HH:mm:ss" As Output

public String gettimeFormat(int noofseconds) {
TimeZone timeZone = TimeZone.getTimeZone("UTC");
SimpleDateFormat sdateFormat = new SimpleDateFormat("HH:mm:ss");
sdateFormat.setTimeZone(timeZone);
String formatedTime = sdateFormat.format(new Date(noofseconds));
return formatedTime;
}

Wednesday 20 June 2012

AutoCompleteTextView in Android

AutoCompleteTextView is a sub class of EditText.

AutoCompleteTextView  shows completion suggestions automatically while the user is typing.

The list of suggestions is displayed in a drop down menu from which the user can choose
an item to replace the content of the edit box with.

The drop down can be dismissed at any time by pressing the back key or,
if no item is selected in the drop down, by pressing the enter/dpad center key.

The list of suggestions is obtained from a data adapter and appears only
after a given number of characters defined by the threshold.

The following Eample shows how to create a text view which suggests various states names
while the user is typing:

UI Layout(autocomplite_tv.xml)
<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:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Enter your state name ?" />
    <AutoCompleteTextView
        android:id="@+id/states"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

Android Activity class(AutoCompliteTextViewExample.java)

package com.androidsurya.autocomplite;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class AutoCompliteTextViewExample extends Activity {
    /** Called when the activity is first created. */

    // Creating an create an array of states in india

    String[] states = { "Andhra Pradesh", "Arunachal Pradesh", "Assam",
            "Bihar", "Chhattisgarh", "Goa", "Gujarat", "Haryana",
            "Himachal Pradesh", "Himachal Pradesh", "Jammu and Kashmir",
            "Jharkhand", "Karnataka", "Kerala", "Madhya Pradesh",
            "Maharashtra", "Manipur", "Meghalaya", "Mizoram", "Nagaland",
            "Odisha", "Punjab", "Rajasthan", "Sikkim", "Tamil Nadu", "Tripura",
            "Uttar Pradesh", "Uttarakhand", "West Bengal" };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.autocomplite_tv);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, states);
        AutoCompleteTextView actvDev = (AutoCompleteTextView) findViewById(R.id.states);
        actvDev.setThreshold(1);
        actvDev.setAdapter(adapter);

    }
}

Register Activity in AndroidManifest file

 <activity
            android:name="com.androidsurya.autocomplite.AutoCompliteTextViewExample"
            android:label="@string/app_name" >

Output Screenshot:


 





For more information about AutoCompliteTextView : Android Developers

Thursday 14 June 2012

Set Wallpaper Programmatically in Android


In Android we can set wallpaper progrmatically using WallpaperManager class.and one SET_WALLPAPER Permistion in AndroidManifest file

Example code :


Use this Permission in AndroidManifest file


<uses-permission  android:name="android.permission.SET_WALLPAPER"/>


(Copy Below code in Android Activity)


//code to get a wallpaperManager instance and use setResouce method to set wallpaper

WallpaperManager WallpaperManager = WallpaperManager
                .getInstance(getApplicationContext());

WallpaperManager.setResource(R.drawable.wall);


Friday 1 June 2012

Use system wallpaper in android application(Total Application/Specific Activity)

Android provides other built-in resouces using in android project.

He we can see how to set System wallpaper as our application wallpaper.

To set this theme for all the activites of your application,

Use android:theme attribute with the theme name to <application> tag in AndroidManifest file

To set this theme for one Acitivty in your application,

Use android:theme attribute with the theme name to <acitvity> tag in Android Manifest file.

AndroidManifest file (Apply theme for all the activities of your application)
 <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Wallpaper" >

For only Specific Activity

 <activity
            android:name="com.androidsurya.usewallpaper"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Wallpaper"  >

Output Screenshot:

Android SQLite Database Viewer or Debuging with Stetho

Every Android Developer uses SQLite Database to store data into the Android Application data. But to view the data in SQLite have a lot of...