24 July, 2013

Animation and External Fonts

External Fonts
You can add your favorite fonts using this code

Syntax:
Typeface typeface_name = Typeface.createFromAsset(getAssets(), "path");
obj_name.setTypeface(typeface_name);
obj_name.setTextSize(text_size);
obj_name.setText("Your Text");

Example:
Typeface font0 = Typeface.createFromAsset(getAssets(), "fonts/GOTHIC.TTF");
TextView txtMessage = (TextView) findViewById(R.id.txtMessage);
txtMessage.setTypeface(font0);
txtMessage.setTextSize(50.f);
txtMessage.setText("hello android");

From where you fetch the Font file?
Understand this screen-shot

Animation List
- Bink
- Bounce
- Cross Fade
- Fade In
- Fade Out
- Move
- Rotate
- Sequential Animation
- Slide Down
- Slide Up
- Zoom In
- Zoom Out
- Together Animation


Download

Different InputTypes

activity_main.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >

        <EditText
            android:id="@+id/et1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_margin="10dp"
            android:hint="text|textCapCharacters"
            android:inputType="text|textCapCharacters" />

        <EditText
            android:id="@+id/et2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/et1"
            android:layout_margin="10dp"
            android:hint="text|textEmailAddress"
            android:inputType="text|textEmailAddress" />

        <EditText
            android:id="@+id/et3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/et2"
            android:layout_margin="10dp"
            android:hint="text|textPassword"
            android:inputType="text|textPassword" />

        <EditText
            android:id="@+id/et4"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/et3"
            android:layout_margin="10dp"
            android:hint="number"
            android:inputType="number" />

        <EditText
            android:id="@+id/et5"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/et4"
            android:layout_margin="10dp"
            android:hint="phone"
            android:inputType="phone" />

        <EditText
            android:id="@+id/et6"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/et5"
            android:layout_margin="10dp"
            android:hint="datetime"
            android:inputType="datetime" />

        <EditText
            android:id="@+id/et7"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/et6"
            android:layout_margin="10dp"
            android:hint="text|textCapSentences|textMultiline"
            android:inputType="text|textCapSentences|textMultiLine" />

        <EditText
            android:id="@+id/et8"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/et7"
            android:layout_margin="10dp"
            android:hint="text|textUri"
            android:inputType="text|textUri" />
    </RelativeLayout>

</ScrollView>

Screen-Shots



Download

19 July, 2013

Validation PopUp

activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
    
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="20dp"
        android:layout_marginTop="50dp"
        android:background="@color/grey" >
        
        <TextView
            android:id="@+id/tvsign"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_margin="10dp"
            android:text="@string/sign"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/black" />
        
        <TextView
            android:id="@+id/tvusername"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/tvsign"
            android:layout_margin="10dp"
            android:text="@string/username"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/red"
            android:textStyle="bold" />
        
        <EditText
            android:id="@+id/etusername"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tvusername"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:inputType="none" />
        
         <TextView
            android:id="@+id/tvpassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/etusername"
            android:layout_margin="10dp"
            android:text="@string/password"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/red"
            android:textStyle="bold" />
         
         <EditText
            android:id="@+id/etpass"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tvpassword"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:inputType="textPassword" />
         
          <Button
            android:id="@+id/btnsignin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/etpass"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="30dp"
            android:background="@drawable/btn"
            android:text="@string/sign"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/white" >
        </Button>
        
          <Button
            android:id="@+id/btnclear"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/etpass"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="30dp"
            android:layout_toRightOf="@+id/btnsignin"
            android:background="@drawable/btn"
            android:text="@string/cleardata"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/white" >
        </Button>
    </RelativeLayout>


</RelativeLayout>

MainActivity.java
package ums.androideasycode.validation;

import ums.androideasycode.validation.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity 
{
Button btnSignedIn, btnClearData;
EditText etUsername, etPassword;

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

etUsername = (EditText) findViewById(R.id.etusername);
etPassword = (EditText) findViewById(R.id.etpass);

btnSignedIn = (Button) findViewById(R.id.btnsignin);
btnSignedIn.setOnClickListener(new OnClickListener() 
{

@Override
public void onClick(View v) 
{
// TODO Auto-generated method stub
String strName = etUsername.getText().toString();
String strPass = etPassword.getText().toString();

if (null == strName || strName.trim().length() == 0)
{
etUsername.setError("Enter Your Name");
etUsername.requestFocus();

else if (null == strPass || strPass.trim().length() == 0)
{
etPassword.setError("Enter Your Password");
etPassword.requestFocus();

else
{
Toast.makeText(getApplicationContext(), "Username: " + strName + "\nPassword: " + strPass, Toast.LENGTH_LONG).show();
}
}
});

btnClearData = (Button) findViewById(R.id.btnclear);
btnClearData.setOnClickListener(new OnClickListener() 
{

@Override
public void onClick(View v) 
{
etUsername.setText("");
etPassword.setText("");
etUsername.requestFocus();

}
});
}

}

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

    <item android:drawable="@drawable/btn_pressed" android:state_focused="true" android:state_pressed="true"></item>
    <item android:drawable="@drawable/btn_default" android:state_focused="true" android:state_pressed="false"></item>
    <item android:drawable="@drawable/btn_pressed" android:state_focused="false" android:state_pressed="true"></item>
    <item android:drawable="@drawable/btn_default"></item>


</selector>

res/values/color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <color name="black">#000000</color>
    <color name="grey">#DCDCDC</color>
    <color name="white">#FFFFFF</color>
    <color name="red">#FF0000</color>


</resources>

res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="action_settings">Settings</string>
    <string name="sign">Sign in</string>
    <string name="app_name">Validation PopUp</string>
    <string name="username">Username</string>
    <string name="password">Password</string>
    <string name="keepme">Keep me logged in</string>
    <string name="cleardata">Clear</string>


</resources>

Screen-Shots
Sign In
Successfully Sign In

popup on username edittext
Username Popup

popup on password edittext
Password Popup

17 July, 2013

Image Switcher

main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Gallery
        android:id="@+id/gallery1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" />

    <ImageSwitcher
        android:id="@+id/imageSwitcher1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/gallery1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp" >
    </ImageSwitcher>

</RelativeLayout>

ImageSwitcherActivity.java
package ums.androideasycode.imageswitcher;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ViewSwitcher.ViewFactory;

public class ImageSwitcherActivity extends Activity implements ViewFactory
{
int imgs[] = 

R.drawable.love_island, 
R.drawable.blue_bird,
R.drawable.paris,
R.drawable.kittens,
R.drawable.morning_paris
};

ImageSwitcher imgSwitcher;

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

imgSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher1);
imgSwitcher.setFactory(this);

imgSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
imgSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));

Gallery gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(this));

gallery.setOnItemClickListener(new OnItemClickListener() 
{

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
imgSwitcher.setImageResource(imgs[arg2]);
}
});
}

public class ImageAdapter extends BaseAdapter
{

private Context ctx;

public ImageAdapter(Context c) 
{
ctx = c; 
}

public int getCount() 
{

return imgs.length;
}

public Object getItem(int arg0) 
{

return arg0;
}

public long getItemId(int arg0)
{

return arg0;
}

public View getView(int arg0, View arg1, ViewGroup arg2) 
{

ImageView iView = new ImageView(ctx);
iView.setImageResource(imgs[arg0]);
iView.setScaleType(ImageView.ScaleType.FIT_XY);
iView.setLayoutParams(new Gallery.LayoutParams(130, 170));
return iView;
}
}

public View makeView()
{
ImageView iView = new ImageView(this);
iView.setScaleType(ImageView.ScaleType.FIT_CENTER);
iView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
iView.setBackgroundColor(0xFF000000);
return iView;
}
}


Screen-Shots
Kittens
Kittens

Blue Bird
Blue Bird