Tuesday 12 March 2013

ScrollView in android | horizontal scroll view in android | scroll image horizonatlly and vertically both


Hello friends,

Using the following xml code you can scroll an image in both horizontally and vertically.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/white"
    android:orientation="vertical" >

       <ScrollView
         android:id="@+id/ScrollView01"
         android:layout_width="wrap_content"
         android:layout_height="320px"
         android:layout_below="@+id/buttonlayout"
         android:scrollbars="horizontal|vertical" >

        <HorizontalScrollView
            android:id="@+id/HorizontalScrollView01"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent" >

            <LinearLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/linearMain3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/imageDetail"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:scaleType="fitXY" />
            </LinearLayout>
        </HorizontalScrollView>
    </ScrollView>
</RelativeLayout>

Thursday 7 March 2013

Setting working Environment for Android


Hello My Droid Friends,

Set Working environment for Android
To work on android we need to setup working environment. Before setting up android environment we
need to fulfill some basics like
1. JDK must be installed (to install
http://www.oracle.com/technetwork/java/javase/downloads/index.html)
2. Eclipse for java must be installed (http://www.eclipse.org/downloads/)
We are expecting that eclipse is working fine.
1. Download Android SDK
It includes only the core Standard development Kit (SDK) Tools, which will help us in developing Android Applications.
Download Android SDK from http://developer.android.com/sdk/index.html
After downloading .zip or .tgz package (instead of the SDK installer), unpack it to a safe location on your machine.
We will be using it later on in coming steps.
2. Install Android development Tools (ADT)
In Eclipse From Help menu click on Install New Software option



Click on Add button and on Add Site window fill following url to download Android ADT, you can enter any name in Name field, and click on Ok button.




Eclipse will search for the available tools and show their list.


Select all tools and click on Next. It will start checking the things and will show list of tools which will be installed.



Click on Next button and after a license verification it will start downloading and may take some time depending upon the speed of Internet. After successfully installing it will ask to restart eclipse.
Restart it.

3. Adding SDK Location
From Window menu click on Preferences there would be Android option visible (which is also assurance that android ADT is installed :) ). Here we need to tell Eclipse where the Android SDK is located. So click on Android from list, and then browse it to the SDK unzipped directory and click on Ok.





4. Install SDK Latest Version
After that come up on Android SDK and AVD Manager from the Window menu. Select available packages and select the latest version of the SDK, in my case I will select followings, you can select based on your own choice and click on Install Selected to complete the installation, and restart eclipse after it.


During installation It would be looking like this.


5. Set Up Device
As we are almost done, last step is we need to set up device to work, real device can be attached, but we will be using simulator for the scope of our work. From eclipse interface click on this icon from top left side of IDE.
               
                                                                                                   
Select the option Virtual Devices and click on New.
On Android Virtual Device screen fill the followings and click on Create AVD.



It will show the device added in Android SDK and AVD manager screen


Now our setup is complete and we are ready to develop android applications.


Enjoy Coding :)
Cheers...... :)

You may also like this link:
1. Roboelectric test case Integration in Android

Wednesday 27 February 2013

Sunday 17 February 2013

Android Dropbox Integration

Hello Droid Guys,

Today, I am going to provide you a full tutorial of dropbox integration into your
android application with source code. Using this you can easily :
            1. upload your image in your dropbox.
            2. upload your text file and document  into your dropbox.
            3. upload your audio and video file into  your dropbox.

Also , List or fetch all your dropbox file, folder and images by your android application.

Step 1: Create an app and get the API KEY and SECRET KEY:
          a) Open this link https://www.dropbox.com/developers and logged in with your
              dropbox credential.

dropbox sync
                           



android dropbox sample


 b) After Logged in , the next page ask you for create an app

android dropbox sample

C) Insert the app name and description and provide the access as full dropbox by 
selecting the second option.
dropbox integration


d) Note your app key and secret key
dropbox integration

                                            
Step 2) Download the android  Sdk for dropbox form HERE

dropbox integration

Now all Done , import the project into your android eclipse and please remember to 
change secret key and App key with your own key.


Hope this will helps you.
Enjoy Coding :)


Saturday 16 February 2013

android.os.NetworkOnMainThreadException in android

Hello Droid Guys,

Yesterday , I found a strange issue, my application is running fine on most of
the android devices. But when I run the same application on Samsung S-3, S2,
Samsung Galaxy Duos it will be crashed and give me the error

"android.os.NetworkOnMainThreadException".


Caused by: android.os.NetworkOnMainThreadException
10-30 15:07:35.341: E/AndroidRuntime(732):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)

In my application basically I am showing a alert dialog with an logout button and on click of logout
button I am calling the service. This functionality is not working on above few device
and crashes every time on clickinng the logout button .

After spending a lot of time on it I came to know that on device api version below 9 we 
can call or write  network call in Main UI Thread but above api version 9 it gives error
android.os.NetworkOnMainThreadException. This is happening my  case.

There are Two way to fix this Issue:
    1.Instead of writing network call in Main UI Thread use Async Task.
    2.Add below code into your activity class inside onCreate() method just  after the 

      setContentView(R.layout.activity_main).
      
     if( Build.VERSION.SDK_INT >= 9){
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy); 
     }



Hoping , this will helps you.
Enjoy Coding :)
   

Sunday 20 January 2013

Android animation

Hello Droid Guys,

In my previous article or blog , i had explain how to show shake animation
in android. Now , in this blog I am covering the other animation.
like:
1, left to right animation in android
2. right to left animation in android
3. fade out animation in android
4. zoom in animation in android
5. slide up animation in android
6. slide down animation in andriod

1.res/anim/slideoutleft.xml

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

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@integer/fastAnim"
    android:fromXDelta="0"
    android:interpolator="@android:anim/overshoot_interpolator"
    android:toXDelta="-100%p" />

2. res/anim/slideinright.xml

    <?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="@integer/fastAnim"
        android:fromXDelta="100%p"
        android:interpolator="@android:anim/overshoot_interpolator"
        android:toXDelta="0" />

3.res/anim/fadeout.xml


<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@integer/fastAnim"
    android:fromAlpha="1.0"
    android:toAlpha="0.0" />


 Another link
 1. Shake animation in android

Android Shake animation

Hello Droid Friends,

This is my another android blog in which I am going to explain the Animation
effect(shake Animation ) in android. When you fill wrong input then instead of
showing the toast messege you can also shake the view.

shake animation

Steps :
1. Create a project with name "Shake animation" and package name
    "com.mukesh.shakeanimation".
2. add an "anim" folder inside the res folder.see the image below.

android shake animation
 
Source Code:

1. Activity Class:




package com.mukesh.shakeanimation;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;

public class MainActivity extends Activity implements View.OnClickListener {

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

  View loginButton = findViewById(R.id.login);
  loginButton.setOnClickListener(this);
 }

 public void onClick(View v) {
  Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
     findViewById(R.id.pw).startAnimation(shake);
     Toast.makeText(this, "Wrong Password", Toast.LENGTH_SHORT).show();
 }

}


2) activity_main.xml




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

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background="@drawable/blue_gradient"

    android:orientation="vertical"

    android:padding="10dip" >



    <TextView

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_marginBottom="10dip"

        android:text="Please enter your password:"

        android:textColor="@android:color/white"

        android:textStyle="bold" />



    <EditText

        android:id="@+id/pw"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:clickable="true"

        android:password="true"

        android:singleLine="true" />



    <Button

        android:id="@+id/login"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:background="@drawable/btn_active_pressed"

        android:padding="5dp"

        android:text="Login"

        android:textColor="@android:color/white"

        android:textStyle="bold" />



</LinearLayout>

3. res/anim/shake.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXDelta="0"
    android:interpolator="@anim/cycle_7"
    android:toXDelta="10" />

4. res/anim/cycle_7.xml

<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
    android:cycles="7" />



May this will helps someone.
Enjoy coding  :)


Following link also helps you :
1. left to right animation in android
2. right to left animation in android
3. fade out animation in android
4. zoom in animation in android
5. slide up animation in android
6. slide down animation in andriod

 

Copyright @ 2013 Android Developers Blog.