Wednesday 24 December 2014

Android Hi-tech Park Project 12:Intent Basic






FirstActivity.java
package com.sattarintentbasic;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class FirstActivity extends Activity {
       Button button;
       TextView textView;
       EditText editText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);
       
       
        button=(Button) findViewById(R.id.button1);
        textView=(TextView) findViewById(R.id.textView1);
        editText=(EditText) findViewById(R.id.editText1);
       
       
       
    }

   
    public void send(View view) {
      
       String string=editText.getText().toString();
       Intent intent=new Intent(FirstActivity.this, LastActivity.class);
      
       intent.putExtra("PERSON_NAME", string);
       startActivity(intent);
             
       }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.first, menu);
        return true;
    }
   
}


Activity_first.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical" >

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

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:gravity="center"
        android:hint="Enter your Name"
        android:layout_height="wrap_content"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:onClick="send"
        android:layout_height="wrap_content"
        android:text="Send" />

</LinearLayout>


Activity_last.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=".LastActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="center"
      
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

</RelativeLayout>

LastActivity.java
package com.sattarintentbasic;

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

public class LastActivity extends Activity {
               
                TextView textViews;

                @Override
                protected void onCreate(Bundle savedInstanceState) {
                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.activity_last);
                               
                                textViews=(TextView) findViewById(R.id.textView2);
                               
//                            String spersontring=getIntent().getStringExtra("PERSON_NAME");
                                textViews.setText("Welcome !!!to \n"+getIntent().getStringExtra("PERSON_NAME"));
                               
                }

               
               
               
               
               
                @Override
                public boolean onCreateOptionsMenu(Menu menu) {
                                // Inflate the menu; this adds items to the action bar if it is present.
                                getMenuInflater().inflate(R.menu.last, menu);
                                return true;
                }

}

Android Hi-tech Park Project 13: Alert Message in Android





MainActivity.java
package com.sattar.aleartmessage;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {

                public void showAlart() {
                                ContextThemeWrapper wrapper = new ContextThemeWrapper(this,
                                                                android.R.style.Holo_Light_ButtonBar);
                                AlertDialog.Builder builder = new AlertDialog.Builder(wrapper);
                                builder.setIcon(R.drawable.ic_launcher);
                                builder.setTitle("Are You There!!");
                                final EditText editText = new EditText(this);
                                editText.setHint("Please Enter Your Name!!");
                                editText.setHintTextColor(Color.RED);
                                editText.setGravity(Gravity.CENTER);
                                setTitleColor(Color.RED);
                                builder.setView(editText);
                                builder.setMessage("Please Enter Your Name!!!");

                                builder.setPositiveButton("OK", null);
                                builder.setNegativeButton("Cancell",
                                                                new DialogInterface.OnClickListener() {

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

                                                                                }
                                                                });
                                builder.create().show();

                }

                // public void showAlart() {
                //
                // ContextThemeWrapper wrapper=new
                // ContextThemeWrapper(this,R.style.AppBaseTheme);
                // AlertDialog.Builder builder=new AlertDialog.Builder(wrapper);
                // builder.setMessage("Stop Your Process");
                // builder.setPositiveButton("OK", null);
                // builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
                //
                // @Override
                // public void onClick(DialogInterface dialog, int which) {
                // // TODO Auto-generated method stub
                //
                // }
                // });
                //
                // builder.create().show();
                //
                // }

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

                }

                public void aleart(View view) {

                                showAlart();

                }

                @Override
                public boolean onCreateOptionsMenu(Menu menu) {
                                // Inflate the menu; this adds items to the action bar if it is present.
                                getMenuInflater().inflate(R.menu.main, menu);
                                return true;
                }

}


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_alignParentTop="true"
        android:onClick="aleart"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="180dp"
        android:text="Show Alert" />

</RelativeLayout>