Wednesday, 1 October 2014

Registration Login and Forgot password UI ANDROID

REGISTRATION SCREEN XML Layout Android:-





<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/register_main"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true" >

    <View
        android:id="@+id/view"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true" />

    <ScrollView
        android:id="@+id/ScrollView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/view"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:background="@drawable/registration_background"
        android:padding="25dp" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/Register_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="30dp"
                android:text="Register"
                android:textSize="30dp"
                android:textStyle="bold"
                android:typeface="monospace" />

            <EditText
                android:id="@+id/username_edtext"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/Register_tv"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/register_uname"
                android:gravity="center"
                android:hint="Username"
                android:inputType="text"
                android:textColor="#000000"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/passwd_edtext"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/username_edtext"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/register_password"
                android:gravity="center"
                android:hint="Password"
                android:inputType="textPassword"
                android:textColor="#000000"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/cnfpasswd_edtext"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/passwd_edtext"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/register_cnfpassword"
                android:gravity="center"
                android:hint="Confirm Password"
                android:inputType="textPassword"
                android:textColor="#000000"
                android:textStyle="bold" />

            <Button
                android:id="@+id/register_button"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/cnfpasswd_edtext"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/register_button"
                android:text="REGISTER"
                android:textColor="#ffffff"
                android:textSize="20dp" />

            <TextView
                android:id="@+id/member_login_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/register_button"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="30dp"
                android:text="Memeber Login?"
                android:textSize="15dp"
                android:textStyle="bold"
                android:typeface="monospace" />
        </RelativeLayout>
    </ScrollView>

    <ImageView
        android:id="@+id/view_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:background="@drawable/register_imview" />

</RelativeLayout>

LOGIN SCREEN XML layout Android Code:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/register_main"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true" >

    <View
        android:id="@+id/view"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true" />

    <ScrollView
        android:id="@+id/ScrollView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/view"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:background="@drawable/registration_background"
        android:padding="25dp" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/member_login_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="30dp"
                android:text="Member Login"
                android:textSize="25dp"
                android:textStyle="bold"
                android:typeface="monospace" />

            <EditText
                android:id="@+id/username_edtext"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/member_login_tv"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/register_uname"
                android:gravity="center"
                android:hint="Username"
                android:inputType="text"
                android:textColor="#000000"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/passwd_edtext"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/username_edtext"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/register_password"
                android:gravity="center"
                android:hint="**************"
                android:inputType="textPassword"
                android:textColor="#000000"
                android:textStyle="bold" />

            <Button
                android:id="@+id/login_button"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/passwd_edtext"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/register_button"
                android:text="LOGIN"
                android:textColor="#ffffff"
                android:textSize="20dp" />

            <TextView
                android:id="@+id/forgot_passwd_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/login_button"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="30dp"
                android:text="Forgot Password?"
                android:textSize="15dp"
                android:textStyle="bold"
                android:typeface="monospace" />
        </RelativeLayout>
    </ScrollView>

    <ImageView
        android:id="@+id/view_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:background="@drawable/member_imview" />

</RelativeLayout>


FORGOT PASSWORD XML Layout in Android:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/register_main"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true" >

    <View
        android:id="@+id/view"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true" />

    <ScrollView
        android:id="@+id/ScrollView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/view"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:background="@drawable/registration_background"
        android:padding="25dp" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/member_login_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="30dp"
                android:text="Forgot Password"
                android:textSize="20dp"
                android:textStyle="bold"
                android:typeface="monospace" />

            <EditText
                android:id="@+id/email_edtext"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/member_login_tv"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/register_uname"
                android:gravity="center"
                android:hint="Email Id"
                android:inputType="textEmailAddress"
                android:textColor="#000000"
                android:textStyle="bold" />

           <!--  <EditText
                android:id="@+id/passwd_edtext"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/username_edtext"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/register_password"
                android:gravity="center"
                android:hint="**************"
                android:inputType="textPassword"
                android:textColor="#000000"
                android:textStyle="bold" /> -->

            <Button
                android:id="@+id/login_button"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/email_edtext"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/register_button"
                android:text="SEND"
                android:textColor="#ffffff"
                android:textSize="20dp" />

          <!--   <TextView
                android:id="@+id/tv_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/login_button"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="30dp"
                android:text="Forgot Password?"
                android:textSize="15dp"
                android:textStyle="bold"
                android:typeface="monospace" /> -->
        </RelativeLayout>
    </ScrollView>

    <ImageView
        android:id="@+id/view_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:background="@drawable/member_imview" />

</RelativeLayout>


Please download all the images for Ui for Screens:








Thursday, 19 June 2014

Android Bus Ticket App Source code

Screen Layout for Android XML


activity_seat_selection_screen.xml


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

    <include
        android:id="@+id/header"
        layout="@layout/common_header_with_sub_title" />

    <RelativeLayout
        android:id="@+id/busDeckSelectionLayout"
        android:layout_width="fill_parent"
        android:layout_height="45.0dip"
        android:layout_below="@+id/header" >

        <RelativeLayout
            android:id="@+id/busDeckSelectionButtons"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="#ffeeeeee" >

            <Button
                android:id="@+id/lowerDeck"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:background="@drawable/left_button"
                android:text="@string/lower"
                android:textColor="@color/black"
                android:textSize="12.0sp" />

            <Button
                android:id="@+id/upperDeck"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/lowerDeck"
                android:background="@drawable/right_button"
                android:text="@string/upper"
                android:textColor="@color/black"
                android:textSize="12.0sp" />
        </RelativeLayout>
    </RelativeLayout>

    <View
        android:id="@+id/busDeckSelectionMargin"
        android:layout_width="fill_parent"
        android:layout_height="1.0dip"
        android:layout_below="@+id/busDeckSelectionLayout"
        android:background="#ffdddddd" />

    <RelativeLayout
        android:id="@+id/seatSelectionHeader"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/busDeckSelectionMargin" >

        <RelativeLayout
            android:id="@+id/seatsLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="5.0dip"
            android:layout_marginTop="5.0dip" >

            <TextView
                android:id="@+id/seatsSelectedText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:text="@string/seats_selected"
                android:textColor="@color/black"
                android:textSize="12.0sp" />

            <TextView
                android:id="@+id/seatsSelected"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/seatsSelectedText"
                android:layout_marginTop="10.0dip"
                android:textColor="@color/black"
                android:textSize="14.0sp" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/fareLayout"
            android:layout_width="wrap_content"
            android:layout_height="40.0dip"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/seatsLayout"
            android:background="@layout/fare_seat_selection_background" >

            <TextView
                android:id="@+id/rsText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginBottom="10.0dip"
                android:layout_marginLeft="5.0dip"
                android:layout_marginTop="10.0dip"
                android:text="@string/rupees"
                android:textColor="@color/black"
                android:textSize="18.0sp" />

            <TextView
                android:id="@+id/fare"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginBottom="10.0dip"
                android:layout_marginRight="5.0dip"
                android:layout_marginTop="10.0dip"
                android:textColor="@color/black"
                android:textSize="18.0sp" />
        </RelativeLayout>
    </RelativeLayout>

    <View
        android:id="@+id/seatSelectionHeaderMargin"
        android:layout_width="fill_parent"
        android:layout_height="1.0dip"
        android:layout_below="@+id/seatSelectionHeader"
        android:background="#ffdddddd" />

    <RelativeLayout
        android:id="@+id/seatLayoutScroll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/bottomBarSeatSelection"
        android:layout_below="@+id/seatSelectionHeaderMargin"
        android:background="@color/white" >

        <RelativeLayout
            android:id="@+id/scrollableLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <RelativeLayout
                android:id="@+id/seatLegendLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5.0dip"
                android:layout_marginTop="5.0dip" >

                <RelativeLayout
                    android:id="@+id/availableImageLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true" >

                    <ImageView
                        android:id="@+id/availableImage"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_marginLeft="10.0dip"
                        android:rotation="90.0"
                        android:src="@drawable/seat_layout_tab_nor_avl" />

                    <TextView
                        android:id="@+id/availableText"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="5.0dip"
                        android:layout_toRightOf="@+id/availableImage"
                        android:text="@string/available"
                        android:textSize="12.0sp" />
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/bookedImageLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@+id/availableImageLayout" >

                    <ImageView
                        android:id="@+id/bookedImage"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="10.0dip"
                        android:rotation="90.0"
                        android:src="@drawable/seat_layout_tab_nor_bkd" />

                    <TextView
                        android:id="@+id/bookedText"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="5.0dip"
                        android:layout_toRightOf="@+id/bookedImage"
                        android:text="@string/booked"
                        android:textSize="12.0sp" />
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/selectedImageLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@+id/bookedImageLayout" >

                    <ImageView
                        android:id="@+id/selectedImage"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10.0dip"
                        android:rotation="90.0"
                        android:src="@drawable/seat_layout_tab_nor_std" />

                    <TextView
                        android:id="@+id/selectedText"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="5.0dip"
                        android:layout_toRightOf="@+id/selectedImage"
                        android:text="@string/selected"
                        android:textSize="12.0sp" />
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/ladiesImageLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/availableImageLayout"
                    android:layout_marginTop="5.0dip" >

                    <ImageView
                        android:id="@+id/ladiesImage"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10.0dip"
                        android:rotation="90.0"
                        android:src="@drawable/seat_layout_tab_nor_lad_avl" />

                    <TextView
                        android:id="@+id/ladiesText"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="5.0dip"
                        android:layout_toRightOf="@+id/ladiesImage"
                        android:text="@string/ladies"
                        android:textSize="12.0sp" />
                </RelativeLayout>
            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/seatLayoutLowerMain"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_below="@+id/seatLegendLayout"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10.0dip"
                android:background="@layout/seat_layout_border"
                android:paddingBottom="5.0dp"
                android:paddingRight="5.0dp" >

                <GridView
                    android:id="@+id/gridView1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="4dp"
                    android:columnWidth="100dp"
                    android:gravity="center"
                    android:numColumns="4"
                    android:stretchMode="columnWidth"
                    android:layout_below="@+id/driver" >
                </GridView>
               
                <RelativeLayout
                    android:id="@+id/driver"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_alignRight="@+id/gridView1"
                    android:layout_marginRight="20.0dp"
                    android:layout_marginTop="5.0dp"
                    android:background="@drawable/steering_icon"
                    android:orientation="horizontal" >
                </RelativeLayout>
            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/seatLayoutUpper"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/seatLegendLayout"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10.0dip"
                android:background="@layout/seat_layout_border"
                android:visibility="invisible" />
        </RelativeLayout>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/bottomBarSeatSelection"
        android:layout_width="fill_parent"
        android:layout_height="49.0dip"
        android:layout_alignParentBottom="true"
        android:background="@color/white" >

        <Button
            android:id="@+id/doneButton"
            android:layout_width="160.0dip"
            android:layout_height="48.0dip"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="1.0dip"
            android:background="@drawable/selector_red_btn"
            android:text="@string/done"
            android:textColor="@color/white"
            android:textSize="18.0sp" />

        <Button
            android:id="@+id/cancelButton"
            android:layout_width="160.0dip"
            android:layout_height="48.0dip"
            android:layout_alignParentRight="true"
            android:layout_marginTop="1.0dip"
            android:background="@drawable/selector_black_btn"
            android:text="@string/goBack"
            android:textColor="@color/white"
            android:textSize="18.0sp" />
    </RelativeLayout>

</RelativeLayout>

Android Java Code For Seat Selection


SeatSelectionActivity.java

package com.ipay.mobilemoney;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;

import com.ipay.arrayadapter.CustomGridViewAdapter;
import com.ipay.arrayadapter.CustomGridViewAdapter.RecordHolder;
import com.ipay.arrayadapter.Item;

/**
 *
 * @author Saurabh tomar
 *
 */

public class SeatSelectionActivityNew extends Activity implements OnItemClickListener
{
    GridView gridView;
    ArrayList<Item> gridArray = new ArrayList<Item>();
    CustomGridViewAdapter customGridAdapter;
    public Bitmap seatIcon;
    public Bitmap seatSelect;

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

        // set grid view item
        seatIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.seat_layout_screen_nor_avl);
        seatSelect = BitmapFactory.decodeResource(this.getResources(), R.drawable.seat_layout_screen_nor_std);
        totalSeat(50);

        gridView = (GridView) findViewById(R.id.gridView1);
        customGridAdapter = new CustomGridViewAdapter(this, R.layout.seatrow_grid, gridArray);
        gridView.setAdapter(customGridAdapter);
        gridView.setOnItemClickListener(this);
    }

    public void totalSeat(int n)
    {
        for (int i = 1; i <= n; ++i)
        {
            gridArray.add(new Item(seatIcon, "seat " + i));

        }
    }

    public void seatSelected(int pos)
    {
        gridArray.remove(pos);
        gridArray.add(pos, new Item(seatSelect, "select"));
        customGridAdapter.notifyDataSetChanged();
    }

    public void seatDeselcted(int pos)
    {

        gridArray.remove(pos);
        int i = pos + 1;
        gridArray.add(pos, new Item(seatIcon, "seat" + i));
        customGridAdapter.notifyDataSetChanged();
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {

        Item item = gridArray.get(position);
        Bitmap seatcompare = item.getImage();
        if (seatcompare == seatIcon)
        {
            seatSelected(position);
        }
        else
        {
            seatDeselcted(position);

        }

    }

}

Custom Array Adapter For GridView

package com.ipay.arrayadapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ipay.mobilemoney.R;

/**
 *
 * @author Saurabh Tomar
 *
 */
public class CustomGridViewAdapter extends ArrayAdapter<Item>
{

    Context context;
    int layoutResourceId;
    ArrayList<Item> data = new ArrayList<Item>();

    public CustomGridViewAdapter(Context context, int layoutResourceId, ArrayList<Item> data)
    {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View row = convertView;
        RecordHolder holder = null;

        if (row == null)
        {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new RecordHolder();
            holder.txtTitle = (TextView) row.findViewById(R.id.item_text);
            holder.imageItem = (ImageView) row.findViewById(R.id.item_image);
            row.setTag(holder);
        }
        else
        {
            holder = (RecordHolder) row.getTag();
        }

        Item item = data.get(position);
        holder.txtTitle.setText(item.getTitle());
        holder.imageItem.setImageBitmap(item.getImage());

        return row;
    }

    public static class RecordHolder
    {
        public TextView txtTitle;
        public ImageView imageItem;

    }
}

OUTPUT FROM THE CODE:





Saturday, 26 October 2013

OpenCv

Prerequisites

  1. Having installed Eclipse in your workstation (only the CDT plugin for C/C++ is needed). You can follow the following steps:
  2. Having installed OpenCV. If not yet, go here.

Making a project

  1. Start Eclipse. Just run the executable that comes in the folder.
  2. Go to File -> New -> C/C++ Project
    Eclipse Tutorial Screenshot 0
  3. Choose a name for your project (i.e. DisplayImage). An Empty Project should be okay for this example.
    Eclipse Tutorial Screenshot 1
  4. Leave everything else by default. Press Finish.
  5. Your project (in this case DisplayImage) should appear in the Project Navigator (usually at the left side of your window).
    Eclipse Tutorial Screenshot 3
  6. Now, let’s add a source file using OpenCV:
    • Right click on DisplayImage (in the Navigator). New -> Folder .
      Eclipse Tutorial Screenshot 4
    • Name your folder src and then hit Finish
    • Right click on your newly created src folder. Choose New source file:
    • Call it DisplayImage.cpp. Hit Finish
      Eclipse Tutorial Screenshot 7
  7. So, now you have a project with a empty .cpp file. Let’s fill it with some sample code (in other words, copy and paste the snippet below):
    #include <cv.h>
    #include <highgui.h>
    
    using namespace cv;
    
    int main( int argc, char** argv )
    {
      Mat image;
      image = imread( argv[1], 1 );
    
      if( argc != 2 || !image.data )
        {
          printf( "No image data \n" );
          return -1;
        }
    
      namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
      imshow( "Display Image", image );
    
      waitKey(0);
    
      return 0;
    }
    
  8. We are only missing one final step: To tell OpenCV where the OpenCV headers and libraries are. For this, do the following:
    • Go to Project–>Properties
    • In C/C++ Build, click on Settings. At the right, choose the Tool Settings Tab. Here we will enter the headers and libraries info:
      1. In GCC C++ Compiler, go to Includes. In Include paths(-l) you should include the path of the folder where opencv was installed. In our example, this is /usr/local/include/opencv.
        Eclipse Tutorial Screenshot 9
        Note
        If you do not know where your opencv files are, open the Terminal and type:
        pkg-config --cflags opencv
        
        For instance, that command gave me this output:
        -I/usr/local/include/opencv -I/usr/local/include
        
      2. Now go to GCC C++ Linker,there you have to fill two spaces:
        First in Library search path (-L) you have to write the path to where the opencv libraries reside, in my case the path is:
        /usr/local/lib
        Then in Libraries(-l) add the OpenCV libraries that you may need. Usually just the 3 first on the list below are enough (for simple applications) . In my case, I am putting all of them since I plan to use the whole bunch:
        opencv_core opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_features2d opencv_calib3d opencv_objdetect opencv_contrib opencv_legacy opencv_flann
        Eclipse Tutorial Screenshot 10 If you don’t know where your libraries are (or you are just psychotic and want to make sure the path is fine), type in Terminal:
        pkg-config --libs opencv
        
        My output (in case you want to check) was: .. code-block:: bash
        -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
        Now you are done. Click OK
    • Your project should be ready to be built. For this, go to Project->Build all
      In the Console you should get something like
      Eclipse Tutorial Screenshot 12 If you check in your folder, there should be an executable there.

Running the executable

So, now we have an executable ready to run. If we were to use the Terminal, we would probably do something like:
cd <DisplayImage_directory>
cd src
./DisplayImage ../images/HappyLittleFish.png
Assuming that the image to use as the argument would be located in <DisplayImage_directory>/images/HappyLittleFish.png. We can still do this, but let’s do it from Eclipse:
  1. Go to Run->Run Configurations
  2. Under C/C++ Application you will see the name of your executable + Debug (if not, click over C/C++ Application a couple of times). Select the name (in this case DisplayImage Debug).
  3. Now, in the right side of the window, choose the Arguments Tab. Write the path of the image file we want to open (path relative to the workspace/DisplayImage folder). Let’s use HappyLittleFish.png:
    Eclipse Tutorial Screenshot 14
  4. Click on the Apply button and then in Run. An OpenCV window should pop up with the fish image (or whatever you used).
    Eclipse Tutorial Screenshot 15
  5. Congratulations! You are ready to have fun with OpenCV using Eclipse.

V2: Using CMake+OpenCV with Eclipse (plugin CDT)

Say you have or create a new file, helloworld.cpp in a directory called foo:
#include <cv.h>
#include <highgui.h>
int main ( int argc, char **argv )
{
  cvNamedWindow( "My Window", 1 );
  IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 );
  CvFont font;
  double hScale = 1.0;
  double vScale = 1.0;
  int lineWidth = 1;
  cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC,
              hScale, vScale, 0, lineWidth );
  cvPutText( img, "Hello World!", cvPoint( 200, 400 ), &font,
             cvScalar( 255, 255, 0 ) );
  cvShowImage( "My Window", img );
  cvWaitKey();
  return 0;
}
  1. Create a build directory, say, under foo: mkdir /build. Then cd build.
  2. Put a CmakeLists.txt file in build:
PROJECT( helloworld_proj )
FIND_PACKAGE( OpenCV REQUIRED )
ADD_EXECUTABLE( helloworld helloworld.cxx )
TARGET_LINK_LIBRARIES( helloworld ${OpenCV_LIBS} )
  1. Run: cmake-gui .. and make sure you fill in where opencv was built.
  2. Then click configure and then generate. If it’s OK, quit cmake-gui
  3. Run make -j4 (the ``-j4`` is optional, it just tells the compiler to build in 4 threads). Make sure it builds.
  4. Start eclipse . Put the workspace in some directory but not in foo or foo\\build
  5. Right click in the Project Explorer section. Select Import And then open the C/C++ filter. Choose Existing Code as a Makefile Project``
  6. Name your project, say helloworld. Browse to the Existing Code location foo\\build (where you ran your cmake-gui from). Select Linux GCC in the “Toolchain for Indexer Settings” and press Finish.
  7. Right click in the Project Explorer section. Select Properties. Under C/C++ Build, set the build directory: from something like ${workspace_loc:/helloworld} to ${workspace_loc:/helloworld}/build since that’s where you are building to.
  1. You can also optionally modify the Build command: from make to something like make VERBOSE=1 -j4 which tells the compiler to produce detailed symbol files for debugging and also to compile in 4 parallel threads.
  1. Done!