LG launches its own Cloud services

April 30th, 2012 No comments

LG has announced the new LG Cloud service which is set to go live on May 1, LG Cloud allows users to stream content between their smartphone, television, and PC.

The service utilizes an app on LG smartphones and TVs, and is different from the cloud storage services that are offered by Google, Microsoft, and others. LG Cloud will synchronize a user’s smartphone content with LG’s servers, and it then can be watched on a television or PC. Additionally, photos and videos that are edited on a user’s PC can be pushed to LG’s servers for viewing on a smartphone or TV. Apps are available for Android – LG Cloud as well as from the LG SmartWorld store on LG Smart TVs, together with PC apps from the LG Cloud site.

LG says that the new Cloud service utilizes its proprietary Real-time Streaming Transcoding technology that converts the content on the server and then streams it to the device, preventing the user from having to wait for the video or image to download. Users do not have to install special codecs or converters to view their content on their devices. LG also says that LG Cloud will also work with 3D content captured with its 3D-capable smartphones, like its Optimus 3D Max.

Both free and paid versions of the LG Cloud will be offered, with pricing and free storage depending on market. Initially, LG is offering 5GB of free space for Korean users with 50GB of extra space for six months for those buying LG phones or smart TVs.

Categories: Uncategorized Tags:

Android ViewFlinger

April 12th, 2012 1 comment

ViewFlinger this an android widget (extends ViewGroup) that allows to group a set of views that can be swiped horizontally. It offers a smoother transition that cannot be accomplished using ViewFlipper. This is based on the Workspace class on the iosched project, which is based in the class with the same name of the Launcher app.

You can see in the video, how ViewFlinger actually works:


1) You can download requisite package here

2) Unpack zip file and copy the above downloaded package com.egoclean.android.widget.flinger into your project i.e in src directory.

Directory structure is given below:

In main.xml , define custom view ViewFlinger

<?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">

	 <com.egoclean.android.widget.flinger.ViewFlinger
	 	android:layout_height="fill_parent"
    	android:layout_width="fill_parent"
    	android:id="@+id/viewFlipper1">
     </com.egoclean.android.widget.flinger.ViewFlinger>
</LinearLayout>


Adding Limited number of views

Create view.xml in layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical">
  		<ImageView android:id="@+id/image"
    		android:layout_height="wrap_content"
    		android:layout_width="wrap_content"
    		android:background="@drawable/icon"/>
    	<TextView android:id="@+id/text"
    	   android:layout_width="wrap_content"
    	   android:layout_height="wrap_content"
    	   android:text="hello view flinger"/>
</LinearLayout>


Create two more xml’s as view1.xml and view2.xml. Add the above code in it and add different image names in ImageView

MainActivity
will look like:

package com.mobisys.android.viewflinger;

import com.egoclean.android.widget.flinger.ViewFlinger;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

public class MainActivity extends Activity{

	ViewFlinger viewFlinger;
	View cur_view,next_view,prev_view;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        viewFlinger=(ViewFlinger)findViewById(R.id.viewFlinger1);

        LayoutInflater inflate=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        cur_view=inflate.inflate(R.layout.view, null);
        prev_view=inflate.inflate(R.layout.view1, null);
        next_view=inflate.inflate(R.layout.view2, null);

        viewFlinger.addView(cur_view);
        viewFlinger.addView(prev_view);
        viewFlinger.addView(next_view);
        }

}


Run the project and swipe the screen.

Adding unlimited number of views

Suppose there are 100 views, so it will not be efficient to add 100 views. So here we will play with only 3 views not the 100 and we will reposition the views as explained below.

Whenever we swipe forward, we will remove prev_view from ViewFlinger, then we will assign curr_view to prev_view and next_view to cur_view.

i.e

               View temp_view=prev_view;
               prev_view=cur_view;
	       cur_view=next_view;
	       next_view=temp_view;

             if(viewFlinger.indexOfChild(next_view)!=-1)
						viewFlinger.removeViewFromFront();


Also for backward swipe, we remove next_view from ViewFlinger, then we will assign cur_view to next_view and prev_view to cur_view.

i.e

 temp_View=next_view;
					next_view=cur_view;
					cur_view=prev_view;
					prev_view=temp_View;

                         if(viewFlinger.indexOfChild(prev_view)!=-1)
						viewFlinger.removeViewFromBack();



i.e.
view.xml contains:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical">
  		<ImageView android:id="@+id/image"
    		android:layout_height="wrap_content"
    		android:layout_width="wrap_content"
    		android:background="@drawable/icon"/>
    	<TextView android:id="@+id/text"
    	   android:layout_width="wrap_content"
    	   android:layout_height="wrap_content"
    	   android:text="hello view flinger"/>
    	 <TextView android:id="@+id/flashCardNo"
	          android:layout_height="wrap_content"
	          android:layout_width="wrap_content"
	          android:layout_marginTop="200dp"

	          />
</LinearLayout>


and MainActivity contains:

package com.mobisys.android.viewflinger;

import com.egoclean.android.widget.flinger.ViewFlinger;
import com.egoclean.android.widget.flinger.ViewFlinger.OnScreenChangeListener;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity implements OnScreenChangeListener{

	ViewFlinger viewFlinger;
	View cur_view,next_view,prev_view;
	int currentIndex;
	int currentScreenIndex = 0;
	int total_count=5;
	private boolean from_start=true;
	TextView txt;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        viewFlinger=(ViewFlinger)findViewById(R.id.viewFlinger1);
        currentIndex=0;

        LayoutInflater inflate=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        cur_view=inflate.inflate(R.layout.view, null);
        prev_view=inflate.inflate(R.layout.view, null);
        next_view=inflate.inflate(R.layout.view, null);

        if(currentIndex>total_count) currentIndex=0;

        int start_index=currentIndex;
		from_start=start_index==0;

		if(currentIndex > 0) loadView(prev_view,currentIndex-1,currentScreenIndex++,true);
		if(currentIndex <= total_count-1) loadView(cur_view,currentIndex++,currentScreenIndex++,true);
		if(currentIndex <= total_count-1) loadView(next_view,currentIndex++,currentScreenIndex,true);

		if(start_index>0) currentScreenIndex=1;
		else currentScreenIndex=0;

		viewFlinger.setCurrentScreenNow(currentScreenIndex, false);
	    viewFlinger.setOnScreenChangeListener(this,false);
    }
	private void loadView(View v, int cur_index, int screen_index,boolean init) {

		if(cur_index%2==0)
			v.findViewById(R.id.image).setBackgroundResource(R.drawable.icon);
		else if(cur_index%2==1)
			v.findViewById(R.id.image).setBackgroundResource(R.drawable.icon1);

		txt=(TextView)v.findViewById(R.id.flashCardNo);
		txt.setText("Card number: "+(cur_index+1)+" of "+total_count);

		if(init)
			viewFlinger.addView(v,screen_index);

		else{

			if(screen_index!=0)
				viewFlinger.addView(v,screen_index);
			else
				viewFlinger.addViewToFront(v);

		}
	}
	@Override
	public void onScreenChanged(View newScreen, int newScreenIndex) {
		if(currentScreenIndex!=newScreenIndex){

			if(newScreenIndex>currentScreenIndex){
				if(from_start||currentScreenIndex==1){
					from_start=false;
					//if(currentIndex<total_count){
					View temp_view=prev_view;
					prev_view=cur_view;
					cur_view=next_view;
					next_view=temp_view;

					if(viewFlinger.indexOfChild(next_view)!=-1)
						viewFlinger.removeViewFromFront();

					if(currentIndex<total_count)
						loadView(next_view,currentIndex++,2,false);
					else{
						loadView(next_view,0,2,false);
						currentIndex=0;
						currentIndex++;
					}

					viewFlinger.setCurrentScreenNow(1,false);
					currentScreenIndex=1;
					//}
					/*else{
						vFlinger.setCurrentScreenNow(2,false);
						currentScreenIndex=2;
					}*/
				}
				else{
					if(!from_start) currentScreenIndex=1;
				}
			}
			else if(newScreenIndex<currentScreenIndex){
				if(currentScreenIndex==1){
					View temp_View=next_view;
					next_view=cur_view;
					cur_view=prev_view;
					prev_view=temp_View;

					if(viewFlinger.indexOfChild(prev_view)!=-1)
						viewFlinger.removeViewFromBack();

					if(currentIndex-4>=0)
						loadView(prev_view,currentIndex-4,0,false);
					else{
						if(total_count>4)
							loadView(prev_view, total_count+(currentIndex-4),0,false);
						else
							loadView(prev_view,total_count+(currentIndex - total_count),0,false);
					}

					viewFlinger.setCurrentScreenNow(1,false);
					currentScreenIndex=1;
					currentIndex--;
					if(currentIndex<0) currentIndex=total_count-1;
				}
				else
					currentScreenIndex=1;
			}
		}

	}
	@Override
	public void onScreenChanging(View newScreen, int newScreenIndex) {
		// TODO Auto-generated method stub

	}
}


Wordy in Android Market (Google Play)

March 12th, 2012 No comments

UPDATE: You can also download Wordy and Wordy-Pro from Amazon App Store.

Introduction

We are introducing a new app “Wordy”, for those who are willing to increase their Vocabulary, who are preparing for Exams like GRE, GMAT, TOEFL, SAT, IELTS etc. and also who are wanted to get proficient in English.

Wordy is the quickest and easiest way to get definitions, synonyms and more. We are launching two versions of Wordy. i.e Wordy-Free and Wordy-Pro

Wordy-Free Features are:

1) There are 74 lists containing 50 words each

2) Track the progress of each wordlist with how many words learnt, read etc.

3) You can bookmark words, rate words and mark words as learnt

4) Word searching is faster.

5) Keeps detail record of which wordlist you have accessed and for how much time.

6) Tracks number of times you read the words

Wordy-Pro Contains all features from Wordy-free app and some additionals are:

1) Personalised Word list i.e you can add new wordlist, new words, also modify the existing word details.

2) Instantly access to wordlist by creating shortcut. Also you can have Add word shortcut to the android desktop.

3) You can generate the QR Code of existing words and share it to your friends on FB, twitter etc.

Highlights

1) Search Words

EX. a) Search all words starting with ‘A’, which you have read within 1 week

within 1 week



Searched Words



EX. b) Search all words starting with ‘A’, which are marked as learnt



Searched words



2) Generate QR code and share it on FB, Twitter, gmail etc

Step-1 Go to Wordlist

Step-2 To generate QR code, long click on word, Select option “generate QR Code”.

Long Click on Word and Select Generate QR code


Step-3 QR image will be generated for selected word and then you can share this QR image to your friends on click of share button.



share with friends



3) Add words to your personalized wordlist from android desktop

Step-1 Go to settings. Enable add word shortcut checkbox. It will create shortcut to your android desktop. Now go to Desktop, click on icon add word, select your list,then add the word.




Select List


Then select any of the method from which you want add word. i.e

Here we will select method “By scanning Qr code” and scan the QR image, the scanning process shown below.
(We also have set up a Web-based Wordy QR code generator: http://mobisys.in/qrcode.php. With this, you can create the word, generate the QR code and share it on FB with your friends. Or you can add the word by scanning QR code)


Click “OK” after scanning done. It will add word to your mentioned wordlist.

4) Instantly access your favourite wordlist from android desktop

Step-1 long click on your favourite wordlist and click on “create shortcut”, it will add shortcut to desktop.





Download Links using QR Code



Google Play store:


Wordy Free

Wordy Pro




Amazon app Store

Wordy Free

Wordy Pro




Enjoy both versions of Wordy and feel free to ask queries if any. :-)

Categories: Android, News Tags: , ,

Scan and charge credit cards with your phone

March 7th, 2012 No comments

card.io is the fast and easy way to accept credit card payments from your phone.

Hold a credit card in front of the phone camera, and it’s scanned automatically! There’s no typing or swiping, and no extra card readers – just point, scan, and start accepting payments. It’s simple, and you can process your first credit card purchase in minutes.

There’s no contracts, setup fees, or monthly fees. You only pay when you charge a card. Pricing is 3.5% plus 30 cents per transaction, and charged amounts are paid to your bank account or PayPal account after 7 days.

card.io is safe and secure. No card numbers or payment information is saved, all communication is protected with high-grade encryption, and our servers are hosted in secure facilities.

card.io is currently only available in the US. :(

Let’s Hope, we can see this app in future in India. :-)

Categories: Android, News Tags: , ,

Android ScrollView

March 7th, 2012 No comments

A ScrollView is a special type of FrameLayout in that it allows users to scroll through a list of views that occupy more space than the physical display. The ScrollView can contain only one child view or ViewGroup, which normally is a LinearLayout.

Note: Do not use a ListView together with the ScrollView. The ListView is designed for showing a list of related information and is optimized for dealing with large lists.

Vertical ScrollView

The following main.xml content shows a ScrollView containing a LinearLayout, which in turn contains some Button and ImageView:

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
	<LinearLayout
	    android:orientation="vertical"
	    android:layout_width="fill_parent"
	    android:layout_height="fill_parent">
		<ImageView android:layout_width="fill_parent"
			android:layout_height="250dp"
			android:src="@drawable/myImage"/>

		<Button android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:text="Button 1"
			android:layout_marginTop="4dp"
			android:layout_gravity="center"/>

		<Button android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:layout_marginTop="4dp"
			android:text="Button 2"
			android:layout_gravity="center"/>

		<Button android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:layout_marginTop="4dp"
			android:text="Button 3"
			android:layout_gravity="center"/>

		<Button android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:layout_marginTop="4dp"
			android:text="Button 4"
			android:layout_gravity="center"/>

		<Button android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:text="Button 5"
			android:layout_marginTop="4dp"
			android:layout_gravity="center"/>
	</LinearLayout>
</ScrollView>


i.e.

Vertical ScrollView


Horizontal ScrollView

So what do we do if we want to display this layout Horizontally ? In this case we’re going to use another container which is HorizontalScrollView. This container acts the same as the ScrollView except that it scrolls child controls horizontally.

Now our main.xml will be like this:

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center">

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <Button android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:text="Button 1"
			android:layout_marginTop="4dp"
			android:layout_gravity="center"/>

		<Button android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:layout_marginTop="4dp"
			android:text="Button 2"
			android:layout_gravity="center"/>

		<Button android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:layout_marginTop="4dp"
			android:text="Button 3"
			android:layout_gravity="center"/>

		<Button android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:layout_marginTop="4dp"
			android:text="Button 4"
			android:layout_gravity="center"/>

		<Button android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:text="Button 5"
			android:layout_marginTop="4dp"
			android:layout_gravity="center"/>
</LinearLayout>
</HorizontalScrollView>

i.e

Horizontal ScrollView

Good bye Android market, Hello Google Play!!!

March 7th, 2012 No comments

Boom!goodbye Android Market, hello Google Play. :-) Google’s new portal content is now the place for all your Android apps, games, music, books, videos and more. Google Play is now live at play.google.com and replaces the Android Market, effective immediately. All of Google’s services, Google Music, Google Books and Videos service are now all in centralized in a one-stop shop for content.

“Google Play is entirely cloud-based so all your music, movies, books and apps are stored online, always available to you, and you never have to worry about losing them or moving them again.”


Categories: Android, News Tags: ,

Drawable Resources

February 21st, 2012 Comments off

A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon. There are several different types of drawables. We will be explaining some of them, those we always use in business. :-)

1. XML Bitmap

An XML bitmap is a resource defined in XML that points to a bitmap file. The XML can specify additional properties for the bitmap such as dithering and tiling.

Note: You can use a <bitmap> element as a child of an <item> element

XML file must be saved in res/drawable floder. The filename is used as the resource ID.

Elements:

<Bitmap>

Defines the bitmap source and its properties.

Attributes:
xmlns:android
String. Defines the XML namespace, which must be “http://schemas.android.com/apk/res/android“. This is required only if the is the root element—it is not needed when the is nested inside an <item>.

android:src
Drawable resource. Required. Reference to a drawable resource.

android:antialias
Boolean. Enables or disables antialiasing.

android:dither
Boolean. Enables or disables dithering of the bitmap if the bitmap does not have the same pixel configuration as the screen

android:filter
Boolean. Enables or disables bitmap filtering. Filtering is used when the bitmap is shrunk or stretched to smooth its apperance.

android:gravity
Keyword. Defines the gravity for the bitmap. The gravity indicates where to position the drawable in its container if the bitmap is smaller than the container.

Example

XML file saved at res/drawable/bitmap.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/icon"
        android:tileMode="repeat" />


This layout XML applies the drawable to a View:

<ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/bitmap" />


2. State List

A StateListDrawable is a drawable object defined in XML that uses a several different images to represent the same graphic, depending on the state of the object. For example, a Button can exist in one of several different states (pressed, focused, or neither) and, using a state list drawable, you can provide a different background image for each state.

You can describe the state list in an XML file. Each graphic is represented by an <item> element inside a single <selector> element. Each <item> uses various attributes to describe the state in which it should be used as the graphic for the drawable.

XML file must be saved in res/drawable floder. The filename is used as the resource ID.

Elements:

<selector>

Required. This must be the root element. Contains one or more <item> elements.

Attributes:
xmlns:android
String. Required. Defines the XML namespace, which must be “http://schemas.android.com/apk/res/android“.

android:dither
Boolean. “true” to enable dithering of the bitmap if the bitmap does not have the same pixel configuration as the screen ; “false” to disable dithering. Default is true.

<item>

Defines a drawable to use during certain states, as described by its attributes. Must be a child of a <selector> element.

Attributes:
android:drawable
Drawable resource. Required. Reference to a drawable resource.

android:state_pressed
Boolean. “true” if this item should be used when the object is pressed (such as when a button is touched/clicked); “false” if this item should be used in the default, non-pressed state.

android:state_focused
Boolean. “true” if this item should be used when the object has input focus (such as when the user selects a text input); “false” if this item should be used in the default, non-focused state.

android:state_enabled
Boolean. “true” if this item should be used when the object is enabled (capable of receiving touch/click events); “false” if it should be used when the object is disabled.

Example

XML file saved at res/drawable/state_list.xml:

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

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

    <item android:state_focused="true"
    	android:state_pressed="false"
    	android:state_enabled="true"
        android:drawable="@drawable/back_selected" />

    <item android:state_pressed="true"
   		android:state_enabled="true"
    	android:drawable="@drawable/back_selected" />

    <item android:state_enabled="true"
    	android:state_focused="false"
    	android:state_pressed="false"
        android:drawable="@drawable/back" />

    <item android:drawable="@drawable/back" />
</selector>



This layout XML applies the state list drawable to a Button.

<Button
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:background="@drawable/state_list" />


Run the application and output would be:
1) When the Button is pressed or focused, following will image will appear


2) For normal state


3. Layer List

A LayerDrawable is a drawable object that manages an array of other drawables. Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top.

Each drawable is represented by an <item> element inside a single <layer-list> element.

XML file must be saved in res/drawable floder. The filename is used as the resource ID.

Elements:

<layer-list>

Required. This must be the root element. Contains one or more <item> elements.

Attributes:
xmlns:android
String. Required. Defines the XML namespace, which must be “http://schemas.android.com/apk/res/android“.

<item>

Defines a drawable to place in the layer drawable, in a position defined by its attributes. Must be a child of a <selector> element. Accepts child <bitmap> elements.

Attributes:
android:drawable
Drawable resource. Required. Reference to a drawable resource.

android:id
Resource ID. A unique resource ID for this drawable. To create a new resource ID for this item, use the form: “@+id/name“. The plus symbol indicates that this should be created as a new ID.

android:top
Integer. The top offset in pixels

android:right
Integer. The right offset in pixels.

android:bottom
Integer. The bottom offset in pixels.

android:left
Integer. The left offset in pixels.

All drawable items are scaled to fit the size of the containing View, by default. Thus, placing your images in a layer list at different positions might increase the size of the View and some images scale as appropriate. To avoid scaling items in the list, use a <bitmap> element inside the <item> element to specify the drawable and define the gravity to something that does not scale, such as “center“. For example, the following <item> defines an item that scales to fit its container View:

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



To avoid scaling, the following example uses a <bitmap> element with centered gravity:

<item>
  <bitmap android:src="@drawable/image"
          android:gravity="center" />
</item>


Example

XML file saved at res/drawable/layers.xml:

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

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
      <bitmap android:src="@drawable/bottom_image"
        android:gravity="center" />
    </item>
    <item android:top="20dp" android:left="20dp">
      <bitmap android:src="@drawable/top_image"
        android:gravity="center" />
    </item>

</layer-list>


This layout XML applies the drawable to a View:

<ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:background="@drawable/layers" />


Run the application & output screen would be

4. Level List

A Drawable that manages a number of alternate Drawables, each assigned a maximum numerical value. Setting the level value of the drawable with setLevel() loads the drawable resource in the level list that has a android:maxLevel value greater than or equal to the value passed to the method.

XML file must be saved in res/drawable floder. The filename is used as the resource ID.

Elements:

<level-list>

This must be the root element. Contains one or more <item> elements.

Attributes:
xmlns:android
String. Required. Defines the XML namespace, which must be “http://schemas.android.com/apk/res/android“.

<item>

Defines a drawable to use at a certain level.

Attributes:
android:drawable
Drawable resource. Required. Reference to a drawable resource.

android:maxLevel
Integer. The maximum level allowed for this item.

android:minLevel
Integer
. The minimum level allowed for this item.

Example

XML file saved at res/drawable/layers.xml:

<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:drawable="@drawable/back"
        android:maxLevel="0" />
    <item
        android:drawable="@drawable/back_selected"
        android:maxLevel="1" />
</level-list>



This layout XML applies the drawable to a View

<ImageView android:id="@+id/iv"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/level_list" />


java code will look like:

package com.mobisys.android.drawable_resources;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

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

	ImageView iv;
	int level;
	    @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.main);
	        iv=(ImageView)findViewById(R.id.iv);
	        level=0;
	        iv.setOnClickListener(new View.OnClickListener(){

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

					if(level==0){
						iv.setImageLevel(1);
						level=1;
					}
					else{
						iv.setImageLevel(0);
						level=0;
					}

				}

	        });

	        }
    }


Run the application & click on image




Again click on image:


5. Shape Drawable

This is a generic shape defined in XML.

XML file must be saved in res/drawable floder. The filename is used as the resource ID.

Elements:

<shape>

The shape drawable. This must be the root element.

Attributes:
xmlns:android
String. Required. Defines the XML namespace, which must be “http://schemas.android.com/apk/res/android“.

android:shape
Keyword.Defines the type of shape. Valid values are: Rectangle, line, Oval , ring.

The following attributes are used only when android:shape=”ring”

android:innerRadius
Dimension.The radius for the inner part of the ring (the hole in the middle), as a dimension value

android:thickness
Dimension.The thickness of the ring, as a dimension value

android:useLevel
Boolean. “true” if this is used as a LevelListDrawable. This should normally be “false” or your shape may not appear.

<corners>

Creates rounded corners for the shape. Applies only when the shape is a rectangle.

Attributes:
android:radius
Dimension.The radius for all corners, as a dimension value . This is overridden for each corner by the following attributes.

android:topLeftradius
Dimension.The radius for the top-left corner, as a dimension value

android:topRightradius
Dimension.The radius for the top-right corner, as a dimension value

android:bottomLeftradius
Dimension.The radius for the bottom-left corner, as a dimension value

android:bottomRightradius
Dimension.The radius for the bottom-right corner, as a dimension value

<gradient>

Specifies a gradient color for the shape.

Attributes:
android:angle
Integer.The angle for the gradient, in degrees. 0 is left to right, 90 is bottom to top. It must be a multiple of 45. Default is 0.

android:centerColor
Color.Optional color that comes between the start and end colors, as a hexadecimal value.

android:endColor
Color.The ending color, as a hexadecimal value

android:startColor
Color.The starting color, as a hexadecimal value

android:type
Keyword.The type of gradient pattern to apply. Valid values are: linear, radial, sweep

android:useLevel
Boolean.”true” if this is used as a LevelListDrawable.

<padding>

Padding to apply to the containing View element (this pads the position of the View content, not the shape).

Attributes:
android:left
Dimension.Left padding, as a dimension value.

android:top
Dimension.Top padding, as a dimension value

android:right
Dimension.Right padding, as a dimension value

android:bottom
Dimension.Bottom padding, as a dimension value

<size>

The size of the shape.

Attributes:
android:height
Dimension.The height of the shape, as a dimension value

android:width
Dimension.The width of the shape, as a dimension value

<solid>

A solid color to fill the shape.

Attributes:
android:color
Color.The color to apply to the shape, as a hexadecimal value

<stroke>

A stroke line for the shape.

Attributes:
android:width
Dimension.The thickness of the line, as a dimension value

android:color
Color.The color of the line, as a hexadecimal value

Example 1-Rectangle

XML file saved at res/drawable/gradient_box.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle">

  	<gradient
        android:startColor="#FFFF0000"
        android:endColor="#80FF00FF"
        android:angle="45"/>

	<padding android:left="5dp"
        android:top="5dp"
        android:right="5dp"
        android:bottom="5dp" />

    <corners android:radius="2dp" />

</shape>


This layout XML applies the shape drawable to a View:

<TextView android:id="@+id/tv"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
  	 android:text="Rectangle Shape"
    android:background="@drawable/gradient_box"/>


This application code gets the shape drawable and applies it to a View:

   TextView tv1=(TextView)findViewById(R.id.tv);
	        tv1.setBackgroundDrawable(getResources().getDrawable(R.drawable.gradient_box));


Output will look like:

Example 2-Oval

XML file saved at res/drawable/gradient_box.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="oval">

  	<gradient
        android:startColor="#FFFF0000"
        android:endColor="#80FF00FF"
        android:angle="0"/>

	<padding android:left="20dp"
        android:top="20dp"
        android:right="20dp"
        android:bottom="20dp" />

        </shape>


This layout XML applies the shape drawable to a View

<TextView android:id="@+id/tv"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
  	 android:text="Oval Shape"
    android:background="@drawable/gradient_box"/>


This application code gets the shape drawable and applies it to a View

TextView tv1=(TextView)findViewById(R.id.tv);
	        tv1.setBackgroundDrawable(getResources().getDrawable(R.drawable.gradient_box));



Output will look like this:


Example 3-Line

XML file saved at res/drawable/gradient_box.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="line">

    <stroke android:width="1dp"
    		android:color="#FFFF0000"/>
    <size android:height="5dp" />
</shape>



This layout XML applies the shape drawable to a View:

<TextView android:id="@+id/tv"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:background="@drawable/gradient_box"/>



This application code gets the shape drawable and applies it to a View:

TextView tv1=(TextView)findViewById(R.id.tv);
	       tv1.setBackgroundDrawable(getResources().getDrawable(R.drawable.gradient_box));


output will look like this:




Example 4-Ring

XML file saved at res/drawable/gradient_box.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="ring"
  android:innerRadiusRatio="4"
  android:thicknessRatio="10"
  android:useLevel="false">

 <size android:width="100dp"
 	android:height="100dp" />

 <gradient
     android:startColor="#FFFF0000"
     android:endColor="#80FF00FF"
     android:angle="0"/>



This layout XML applies the shape drawable to a View:

<TextView android:id="@+id/tv"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:background="@drawable/gradient_box"/>



This application code gets the shape drawable and applies it to a View:

TextView tv1=(TextView)findViewById(R.id.tv);
	       tv1.setBackgroundDrawable(getResources().getDrawable(R.drawable.gradient_box));


Output will look like this:

Android: Using Camera API

February 16th, 2012 No comments

In this tutorial, we will implement one simple camera app with following features:
1) Launch the camera app and it will start the camera with capture and exit button at bottom.
1) On capture, it will capture the picture and show it in ImageView.
2) If you press save, it will save the picture on SD card
3) If you recapture, it will again start the camera to take the picture.
4) If you exit the app, it will exit from the app.

Screenshot

Lets start by creating the project with name CameraApp with CameraAppActivity.

Define Layout XML file

Once the project with Activity, CameraAppActivity is created, first step is to create XML layout file. It is defined as follows:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <LinearLayout android:id="@+id/button_layout"
  	android:layout_alignParentBottom="true"
  	android:orientation="horizontal"
  	android:gravity="center"
  	android:layout_width="fill_parent"
  	android:layout_height="wrap_content">
  	<Button android:id="@+id/exit_button"
  		android:layout_width="wrap_content"
  		android:layout_height="wrap_content"
  		android:layout_gravity="left"
  		android:text="Exit"/>
  	<Button android:id="@+id/ok_button"
  		android:layout_width="wrap_content"
  		android:layout_height="wrap_content"
  		android:layout_gravity="left"
  		android:text="Upload"/>
  	<Button android:id="@+id/recapture_button"
  		android:layout_width="wrap_content"
  		android:layout_height="wrap_content"
  		android:layout_gravity="right"
  		android:text="Recapture"/>
  	<Button android:id="@+id/capture_button"
  		android:layout_width="wrap_content"
  		android:layout_height="wrap_content"
  		android:layout_gravity="right"
  		android:text="Capture"/>
  </LinearLayout>
  <FrameLayout android:id="@+id/preview"
  		android:layout_width="fill_parent"
  		android:layout_height="fill_parent"
  		android:layout_above="@id/button_layout">
  </FrameLayout>
  <ImageView android:id="@+id/img"
  		android:layout_width="wrap_content"
  		android:layout_height="wrap_content"
  		android:layout_above="@id/button_layout"/>
</RelativeLayout>

It has linear horizontal layout of all buttons. All buttons are self-explanatory. FrameLayout to hold the preview of camera. It also have ImageView which will display the preview of the captured picture.

Basic logic is:
1) When application is launched, it will start also the camera preview and will make the ImageView invisible.
2) Camera Preview will be displayed on SurfaceView. So we will create our own SurfaceView preview.
2) When picture is captured, it is displayed in ImageView. So, ImageView is made visible while preview invisible.
3) When OK button is pressed, captured bitmap is saved to SD card.

Create Preview

We will create the SurfaceView on which it will show preview from the camera.

import java.io.IOException;
import java.util.List;

import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class Preview extends SurfaceView implements SurfaceHolder.Callback{

	SurfaceHolder mHolder;
	public Camera camera;

	public Preview(Context context) {
		super(context);
		// Install a SurfaceHolder.Callback so we get notified when the
		// underlying surface is created and destroyed.
		mHolder = getHolder();
		mHolder.addCallback(this);
		mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
	}

	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		camera.startPreview();
	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		// The Surface has been created, acquire the camera and tell it where
		// to draw.
		camera = Camera.open();
		try {
			camera.setPreviewDisplay(holder);
			Camera.Parameters parameters=camera.getParameters();
			List<Size> sizes=parameters.getSupportedPictureSizes();
			parameters.setPictureSize(sizes.get(0).width, sizes.get(0).height);
			camera.setParameters(parameters);
			camera.startPreview();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		// Surface will be destroyed when we return, so stop the preview.
		// Because the CameraDevice object is not a shared resource, it's very
		// important to release it when the activity is paused.
		camera.stopPreview();
		camera.release();
		camera = null;
	}

}

Activity class

Application only have one Activity, CameraAppActivity. It is as below:

public class CameraAppActivity extends Activity{
	private Bitmap bmp=null;
	ProgressDialog pg=null;
	private Preview preview;
	Button ok_button,click_button,cancel_button,try_again_button;
	//public static byte[] bitmapArray=null;
	@Override
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.camera_layout);

		preview=new Preview(this);
		((FrameLayout) findViewById(R.id.preview)).addView(preview);
		findViewById(R.id.preview).setVisibility(View.VISIBLE);
		findViewById(R.id.img).setVisibility(View.GONE);

		ButtonListener listener=new ButtonListener();
		click_button=((Button) findViewById(R.id.capture_button));
		click_button.setVisibility(View.VISIBLE);
		click_button.setOnClickListener(listener);

		try_again_button=((Button) findViewById(R.id.recapture_button));
		try_again_button.setVisibility(View.GONE);
		try_again_button.setOnClickListener(listener);

		cancel_button=((Button) findViewById(R.id.cancel_button));
		cancel_button.setVisibility(View.VISIBLE);
		cancel_button.setOnClickListener(listener);

		ok_button=((Button) findViewById(R.id.ok_button));
		ok_button.setVisibility(View.GONE);
		ok_button.setOnClickListener(listener);
	}

	private class ButtonListener implements View.OnClickListener{

		@Override
		public void onClick(View v) {
			if(v.equals(findViewById(R.id.capture_button))){
				pg=ProgressDialog.show(CameraAppActivity.this, null, "Capturing Image..");
				pg.show();
				preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
			}else if(v.equals(findViewById(R.id.cancel_button))){
				finish();
			}else if(v.equals(findViewById(R.id.ok_button))){
				saveImage();
			}else if(v.equals(findViewById(R.id.recapture_button))){
				findViewById(R.id.img).setVisibility(View.GONE);
				findViewById(R.id.preview).setVisibility(View.VISIBLE);
				preview.camera.startPreview();
				ok_button.setVisibility(View.GONE);
				cancel_button.setVisibility(View.VISIBLE);
				try_again_button.setVisibility(View.GONE);
				click_button.setVisibility(View.VISIBLE);
			}
		}

	}

	ShutterCallback shutterCallback = new ShutterCallback() {
		public void onShutter() {
			//Log.d(TAG, "onShutter'd");
			System.out.println("In ShutterCallback");
		}
	};

	/** Handles data for raw picture */
	PictureCallback rawCallback = new PictureCallback() {
		public void onPictureTaken(byte[] data, Camera camera) {
			if(data!=null){
				bmp=BitmapFactory.decodeByteArray(data,0,data.length);
				findViewById(R.id.img).setVisibility(View.VISIBLE);
				((ImageView)findViewById(R.id.img)).setImageBitmap(bmp);
				findViewById(R.id.preview).setVisibility(View.GONE);

				if(pg!=null)
					pg.dismiss();
				ok_button.setVisibility(View.VISIBLE);
				click_button.setVisibility(View.GONE);
				try_again_button.setVisibility(View.VISIBLE);
			}
		}
	};

	/** Handles data for jpeg picture */
	PictureCallback jpegCallback = new PictureCallback() {
		public void onPictureTaken(byte[] data, Camera camera) {
			if(data!=null){
				bmp=BitmapFactory.decodeByteArray(data,0,data.length);
				findViewById(R.id.img).setVisibility(View.VISIBLE);
				((ImageView)findViewById(R.id.img)).setImageBitmap(bmp);
				findViewById(R.id.preview).setVisibility(View.GONE);

				if(pg!=null)
					pg.dismiss();
				ok_button.setVisibility(View.VISIBLE);
				click_button.setVisibility(View.GONE);
				try_again_button.setVisibility(View.VISIBLE);
			}
		}
	};

	public void saveImage(){
		FileOutputStream out;
		try {
			File file=new File(Environment.getExternalStorageDirectory()+"temp.jpg");
			if(!file.exists()) file.createNewFile();
			out = new FileOutputStream(file);
			bmp.compress(CompressFormat.JPEG, 90, out);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

Take Picture

To take the picture, we call takePicture() method of Camera. takePicture() is asynchronous method so we pass series of callbacks like ShutterCallback and PictureCallback (RawCallback & JPEGCallback).

ShutterCallback is a callback for image capture moment.
Raw PictureCallback is a callback for raw image data.
JPEG PictureCallback is a callback for JPEG encoding image data.

It’s upto you to do something with the data such as save it on SD card.

preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);

Saving picture on SD card

public void saveImage(){
	FileOutputStream out;
	try {
		File file=new File(Environment.getExternalStorageDirectory()+"temp.jpg");
		if(!file.exists()) file.createNewFile();
		out = new FileOutputStream(file);
		bmp.compress(CompressFormat.JPEG, 90, out);
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	} catch (Exception e) {
		e.printStackTrace();
	}
}

Finally, please don’t forgot to add following permissions in AndroidManifest.xml which we always forget :-) .

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

Google developing Android powered Home entertainment system

February 10th, 2012 1 comment

According to The Wall Street Journal, Google is in the process of developing a home entertainment system based on Android and controlled by Android devices. The product appears to be similar to what Apple offers with its Apple TV and AirPlay service, and will allow users to stream music and video throughout their homes wirelessly.

Google has already attempted to break into the home entertainment business with its Google TV product, however, this new device is said to be built under Google’s own brand and will be marketed as such (Google TV devices are made and branded by outside companies like Logitech and Sony).

Google has been working on home automation for a while now home entertainment system would be a logical next step to a fully smart home. The home automation stuff that Google showed off at Google I/O in the past has yet to make it to the market.

So, droid is now trying to enter in your home too :-) .

Google Chrome Now on Android!!

February 10th, 2012 No comments

Well good news for android users. Google announced the Google Chrome for its users and it’s being made available immediately as a beta release for phones and tablets running Ice Cream Sandwich 4.0.

Browse fast on your Android smartphone or tablet, and bring your personalized Chrome experience with you anywhere you go.

Google says that the long-term plan is to make Chrome Android’s default browser, and everything we’ve seen here suggests that’s the right move. :-) In the meantime, it’ll be a free Android Market download, where it’ll install side by side with your existing browser.

Download google chrome here.


Google Chrome for Android 4.0 ICS



Categories: Android, News Tags: , ,