Wednesday, 24 April 2013

BroadCastReceiver Demo 2

Demo:

1) MainActivity.java:
 
package com.venky.broadcastreceiverdemo2;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

public class MainActivity extends Activity {

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

            BroadcastReceiver bc = new MyBroadCastReceiver();

            registerReceiver(bc, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
      }
}

2) MyBroadCastReceiver.java:

 package com.venky.broadcastreceiverdemo2;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class MyBroadCastReceiver extends BroadcastReceiver {

      @Override
      public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub

            int batteryStatus = intent.getIntExtra("level", 0);

            Toast.makeText(context, "Battery Status => " + batteryStatus+" %", 3000)
                        .show();
      }

}

3) 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"
    tools:context=".MainActivity" >

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

</RelativeLayout>


4)Download this Project Click Here
 

BroadCastReceiver Demo 1

Demo:

1) MainActivity.java:

package com.venky.broadcastreceiverdemo;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends Activity {

      private BroadcastReceiver bc = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                  // TODO Auto-generated method stub

                  int batteryStatus = intent.getIntExtra("level", 0);

                  TextView tv = (TextView) findViewById(R.id.textView1);
                  tv.setText("Battery Status => " + batteryStatus + " %");

                  ProgressBar pb = (ProgressBar) findViewById(R.id.progressBar1);
                  pb.setProgress(batteryStatus);
            }
      };

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

            registerReceiver(bc, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
      }

}


2) 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"
    android:background="#5F04B4"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:layout_gravity="center"
        android:layout_marginTop="70dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp" />

</LinearLayout>


 3) Download this Project Click Here

Tuesday, 23 April 2013

USER QUESTIONS

Please post your questions as a comment.
If possible our Team will be give answers.

Fragment Demo 2

Demo:

1) MainActivity:
 
package com.venky.fragmentdemo2;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;

public class MainActivity extends Activity {

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

            FragmentTransaction fragmentTransaction = getFragmentManager()
                        .beginTransaction();

            MyFragment myFragment = new MyFragment();

            fragmentTransaction.add(R.id.fragment, myFragment);

            fragmentTransaction.commit();
      }
}


2) MyFragement.java:
 
package com.venky.fragmentdemo2;

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

@SuppressLint("NewApi")
public class MyFragment extends Fragment {

      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
            // TODO Auto-generated method stub

            View view = inflater.inflate(R.layout.fragment_style, container, false);

            return view;
      }
}

3) 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"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:text="Fragment Demo 2"
        android:textSize="25dp" />

    <FrameLayout
        android:id="@+id/fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </FrameLayout>

</LinearLayout>


4) fragment_style.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#5F04B4"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="Fragment"
        android:textColor="#ffffff"
        android:textSize="25dp" />

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

</LinearLayout>


5)Download this Project Click Here
 

Fragment Demo - 1

Demo:


1) Activity:
 
package com.venky.fragmentdemo;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MainActivity extends Activity {

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

      @SuppressLint("NewApi")
      public static class MyFragment extends Fragment {

            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                        Bundle savedInstanceState) {
                  // TODO Auto-generated method stub

                  View view = inflater.inflate(R.layout.fragment_style, container,
                              false);

                  return view;
            }
      }
}


2) 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"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:text="Fragment Demo"
        android:textSize="25dp" />

    <fragment
        android:id="@+id/fragment1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.venky.fragmentdemo.MainActivity$MyFragment" />

</LinearLayout>


3) fragment_xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#5F04B4"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="This is Fragment Area"
        android:textColor="#ffffff"
        android:textSize="25dp" />

</LinearLayout>


4) Download this Project Click Here