Thursday 27 March 2014

Actionbar Tutorials Part 03----Setting custom Icon,Title and Color to the ActionBar

output:

MainActivity.java:
package com.example.demo;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

public class MainActivity extends ActionBarActivity {

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

        ActionBar actionBar = getSupportActionBar();

        //setting icon to actionbar
        actionBar.setIcon(R.drawable.spoon);
       
        //setting title to actionbar
        actionBar.setTitle("ActionBar Tutorials");
      
       // setting custom color
        actionBar.setBackgroundDrawable(new ColorDrawable(Color.RED));
    }
}


Actionbar Tutorials Part 02----Removing Action Bar

We can hide the action bar at runtime by calling hide()

Example:

ActionBar actionBar = getSupportActionBar();
actionBar.hide();

On API level 11 or higher Get the ActionBar with the getActionBar() method.

Example Program:
ScreenShot:

MainActivity.java:
package com.example.demo;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
      
        //hiding ActionBar
        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();
    }
}

Tuesday 25 March 2014

Actionbar Tutorials Part 01----Adding ActionBar to the Activity

The action bar is a window feature that identifies the user location, and provides user actions and navigation modes. Using the action bar offers your users a familiar interface across applications that the system gracefully adapts for different screen configurations.

The action bar provides several key functions:

1.Provides a dedicated space for giving your app an identity and indicating the user's location in the app.

2.Makes important actions prominent and accessible in a predictable way (such as Search)

3.Supports consistent navigation and view switching within apps (with tabs or drop-down lists).

The ActionBar APIs were first added in Android 3.0 (API level 11) but they are also available in the Support Library for compatibility with Android 2.1 (API level 7) and above.

This Tutorial will focus how to use ActionBar class APIs in the support library. So before we can add the action bar, we must set up our project with the appcompat v7 support library by following the instructions in the Support Library Setup.



Support Library Set-up procedure:
1.Start the Android SDK Manager.

2.In the SDK Manager window, scroll to the end of the Packages list, find the Extras folder and, if necessary, expand to show its contents.

3.Select the Android Support Library item.

4.Click the Install packages... button.



After downloading, the tool installs the Support Library files to your existing Android SDK directory. The library files are located in the following subdirectory of your SDK: <sdk>/extras/android/support/ directory.

1.Make sure you have downloaded the Android Support Library using the SDK Manager.

2.Create a library project and ensure the required JAR files are included in the project's build path:

3.Select File > Import.

4.Select Existing Android Code Into Workspace and click Next.

5.Browse to the SDK installation directory and then to the Support Library  

   folder. For example, if you are adding the appcompat project,
  browse to <sdk>/extras/android/support/v7/appcompat/.

6.Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.

7.In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example,
  when creating the the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.

8.Right-click the library project folder and select Build Path > Configure Build Path.

9.In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this
  library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-
  appcompat.jar files.

10.Uncheck Android Dependencies.

11.Click OK to complete the changes.

We now have a library project for our selected Support Library that we can use with one or more application projects.


Add the library to our application project:
1.In the Project Explorer, right-click your project and select Properties.
2.In the category panel on the left side of the dialog, select Android.
3.In the Library pane, click the Add button.
4.Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.
5.In the properties window, click OK.


Once our project is set up with the support library, here's how to add the action bar:

1.Create your activity by extending ActionBarActivity.
 

2.Use (or extend) one of the Theme.AppCompat themes for your activity.

Here in following example i have given code how it looks like:

activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="HelloWorld"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>


MainActivity.java:
package com.example.demo;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;

public class MainActivity extends ActionBarActivity {

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

    }
}




AndroidManifest.xml: 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.demo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.demo.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.AppCompat.Light" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest> 


ScreenShots:

Before adding ActionBar
After adding ActionBar



Monday 24 March 2014

Making Phone Call using Intent

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

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:onClick="call"
        android:text="call" />

</RelativeLayout>


MainActivity.java:
package com.ram.telephonymanager;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends Activity {

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

    public void call(View v) {
        Intent intent = new Intent(Intent.ACTION_DIAL,
                Uri.parse("tel:9848012345"));
        startActivity(intent);
    }
}


AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ram.telephonymanager"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.ram.telephonymanager.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Tuesday 18 March 2014

Introducing Android Wear

Android Wear extends the Android platform to a new generation of wearable devices.
The user experience is designed specifically for wearables.

The Android Wear Developer Preview lets you create wearable experiences for your existing Android apps and see how they will appear on square and round Android wearables.

To get developer preview visit this website http://developer.android.com/wear/index.html

Monday 10 March 2014

Android Internship Program Starts on 13-03-2014 Thursday at 1:30 pm afternoon

 Android Internship Program                By Mr Ram


Demo Class on  13-03-2014 Thursday at 1:30 pm afternoon

place: Inspire IT Global Services,
            #501, Sree Swathi Anukar,
            Beside Aditya Trade center, Mythrivanam ,Ameerpet,Hyderabad
            Contact 9581411199

Duration of Internship Program : 45 - 60 days

What will be covered in this Internship program?

·         Brush-up all Android Concepts.

·         Getting strong knowledge in Real Time oriented concepts.

·         3 - 5  applications can be developed by each student.

·         Android Soft copy will be provided.

·         Source code of Android Concepts will be available at Ram Android Blog .
you can visit the blog :  www.ramsandroid4all.blogspot.in

·         Placement  Assistance

For more details contact  :
Mr Ram
9581411199
Email : rams4android@gmail.com

Saturday 8 March 2014

Gallery using ViewPager Example in Android

ScreenShots:



 

you can download the images those are used in this project from this link https://www.google.co.in/search?q=android+images&tbm=isch&tbo=u&source=univ&sa=X&ei=oPAaU-K9Cc-eiQfE1IDIDQ&ved=0CCcQsAQ&biw=1366&bih=677


activity_main.xml:
<LinearLayout 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:orientation="vertical" >

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>


MainActivity.java:
package com.ram.galleryusingviewpager;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class MainActivity extends Activity {

    private int[] IMAGES = { R.drawable.android1, R.drawable.android2,
            R.drawable.android3, R.drawable.android4, R.drawable.android5,
            R.drawable.android6 };

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

        ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
        ImageAdapter adapter = new ImageAdapter();
        viewPager.setAdapter(adapter);
    }

    class ImageAdapter extends PagerAdapter {

        @Override
        public int getCount() {
            return IMAGES.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == ((ImageView) object);
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ImageView imageView = new ImageView(getApplicationContext());
            imageView.setImageResource(IMAGES[position]);
            ((ViewPager) container).addView(imageView, 0);
            return imageView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            ((ViewPager) container).removeView((ImageView) object);
        }
    }
}

Wednesday 5 March 2014

Google Maps Android API V2 updated video Tutorial

Back Button Confirmation with AlertDialog tutorial

Screen Shots:


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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>


MainActivity.java:
package com.ram.backbuttonpermission;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;

public class MainActivity extends Activity {

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

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode != KeyEvent.KEYCODE_BACK)
            return super.onKeyDown(keyCode, event);

        Builder builder = new Builder(MainActivity.this);
        builder.setTitle("alert");
        builder.setMessage("Are you sure?");
        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                finish();
            }
        });
        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

            }
        });
        AlertDialog alert = builder.create();
        alert.show();

        return super.onKeyDown(keyCode, event);
    }
}
 


Tuesday 4 March 2014

New Android Batch is Starting at Inspire IT Global Services

My New Android Batch is starting From Thursday on wards (06-03-2014)
at Morning 7:30 am in Inspire IT Global Services.
Duration:35-40 days
Fees: 3000/-

For Details:
Inspire IT Global Services,
#501,Sree Swathi Anukar,
Beside Aditya Trade center,Mythrivanam,
PH: 040-40181096,40181101
Mobile:9848212652

Monday 3 March 2014

Marquee TextView (Horizontal Scrolling TextView)

ScreenShots:
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" >

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:padding="5dip"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="example textview for horizontal scrolling ........................ "
        android:textSize="20sp" />

</RelativeLayout>


MainActivity.java:
package com.ram.marqueetextview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {

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

        TextView tv = (TextView) this.findViewById(R.id.text);
        tv.setSelected(true);
    }

}
 


Sunday 2 March 2014

ListView with CheckBoxes

ScreenShots:


activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
          android:choiceMode="multipleChoice"
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

MainActivity.java:
package com.ram.listviewwithcheckboxes;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnItemClickListener {
    String[] ITEMS = { "item1", "item2", "item3", "item4", "item5", "item6",
            "item7", "item8", "item9", "item10" };

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

        ListView listView = (ListView) findViewById(R.id.listView);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_multiple_choice, ITEMS);

        listView.setAdapter(adapter);

        listView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View arg1,
            int position, long arg3) {
        ListView listview = (ListView) adapterView;

        if (listview.isItemChecked(position)) {
            Toast.makeText(getApplicationContext(),
                    adapterView.getItemAtPosition(position) + " Checked",
                    Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(getApplicationContext(),
                    adapterView.getItemAtPosition(position) + " Un Checked",
                    Toast.LENGTH_LONG).show();
        }
    }

}