Monday, 20 February 2017

SPLASH SCREEN


input



activity_main.xml code

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:id="@+id/activity_main"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:paddingBottom="@dimen/activity_vertical_margin"
  8. android:paddingLeft="@dimen/activity_horizontal_margin"
  9. android:paddingRight="@dimen/activity_horizontal_margin"
  10. android:paddingTop="@dimen/activity_vertical_margin"
  11. tools:context="com.example.saketh.couponsmania.MainActivity">

  12.     <ImageView
  13. android:id="@+id/logo"
  14. android:layout_width="match_parent"
  15. android:layout_height="match_parent"
  16. android:scaleType="centerCrop"
  17. android:src="@drawable/l" />
  1. </RelativeLayout>



                                   Main Activity.java



  1. package com.example.saketh.couponsmania;

  2. import android.content.Intent;
  3. import android.os.Handler;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.widget.ImageView;

  7. public class MainActivity extends AppCompatActivity {
  8.     ImageView logon;
  9. //splash screen timer
  10. private static int SPLASH_TIME_OUT=5000;


  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14.         setContentView(R.layout.activity_main);
  15. logon=(ImageView) findViewById(R.id.logo);

  16. new Handler().postDelayed(new Runnable(){

  17. @Override
  18. public void run() {
  19. //It is used to excute the below programme after the timer
  20. Intent in=new Intent(getApplicationContext(),Registration.class);
  21.                 startActivity(in);
  22. // close this activity
  23. finish();

  24.             }
  25.         },SPLASH_TIME_OUT);

  26.     }
  27. }




                                                      Registration.java code(take 1 new empty activity by right click on com. example.saketcoupons in your system it is different url and select new->activity->empty activity and rename it as Registration)




  1. package com.example.saketh.couponsmania;

  2. import android.support.v7.app.AppCompatActivity;
  3. import android.os.Bundle;

  4. public class Registration extends AppCompatActivity {

  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8.         setContentView(R.layout.activity_registration);
  9.     }
  10. }




activity_Registration.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:id="@+id/activity_registration"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:paddingBottom="@dimen/activity_vertical_margin"
  8. android:paddingLeft="@dimen/activity_horizontal_margin"
  9. android:paddingRight="@dimen/activity_horizontal_margin"
  10. android:paddingTop="@dimen/activity_vertical_margin"
  11. tools:context="com.example.saketh.couponsmania.Registration">
  12. </RelativeLayout>

















Image View xaml code




    First copy the desired image then copy and paste the image in DRAWABLE folder then write the xml code


  1. <ImageView
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:src="@drawable/l"
  5. android:scaleType="centerCrop"
  6. android:id="@+id/logo"
  7. />


in android:src in "l" place you can give image name and android:id in logo place you can give any name

Friday, 17 February 2017

Quantity picker with Strings

input


xml code

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:id="@+id/activity_main"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:orientation="vertical"
  8. android:paddingBottom="@dimen/activity_vertical_margin"
  9. android:paddingLeft="@dimen/activity_horizontal_margin"
  10. android:paddingRight="@dimen/activity_horizontal_margin"
  11. android:paddingTop="@dimen/activity_vertical_margin"
  12. tools:context="com.example.saketh.firstprojectman.MainActivity">
  13. <TextView
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:layout_marginBottom="16dp"
  17. android:text="quantity"
  18. android:textAllCaps="true" />
  19. <LinearLayout
  20. android:layout_width="match_parent"
  21. android:layout_height="wrap_content"
  22. android:orientation="horizontal">
  23. <Button
  24. android:layout_width="48dp"
  25. android:layout_height="48dp"
  26. android:onClick="decrement"
  27. android:text="-" />
  28. <TextView
  29. android:id="@+id/quantity_text_view"
  30. android:layout_width="wrap_content"
  31. android:layout_height="wrap_content"
  32. android:layout_marginBottom="16dp"
  33. android:layout_marginLeft="8dp"
  34. android:text="0"
  35. android:textAllCaps="true"
  36. android:textColor="@android:color/black"
  37. android:textSize="16sp"
  38. android:paddingLeft="8dp"
  39. android:paddingRight="8dp"/>
  40. <Button
  41. android:layout_width="48dp"
  42. android:layout_height="48dp"
  43. android:layout_marginLeft="8dp"
  44. android:onClick="increment"
  45. android:text="+" />
  46. </LinearLayout>
  47. <TextView
  48. android:layout_width="wrap_content"
  49. android:layout_height="wrap_content"
  50. android:layout_marginBottom="16dp"
  51. android:layout_marginTop="16dp"
  52. android:text="price"
  53. android:textAllCaps="true" />
  54. <TextView
  55. android:id="@+id/price_text_view"
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:layout_marginBottom="16dp"
  59. android:text="0"
  60. android:textAllCaps="true"
  61. android:textColor="@android:color/black"
  62. android:textSize="16sp" />
  63. <Button
  64. android:layout_width="wrap_content"
  65. android:layout_height="wrap_content"
  66. android:onClick="submitOrder"
  67. android:text="order" />
  68. </LinearLayout>
java code
  1. package com.example.saketh.firstprojectman; /**
  2. * Add your package below. Package name can be found in the project's AndroidManifest.xml file.
  3. * This is the package name our example uses:
  4. *
  5. * package com.example.android.justjava;
  6. */
  7. import android.icu.text.NumberFormat;
  8. import android.os.Bundle;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.view.View;
  11. import android.widget.TextView;
  12. import com.example.saketh.firstprojectman.R;
  13. import static android.icu.text.NumberFormat.getCurrencyInstance;
  14. /**
  15. * This app displays an order form to order coffee.
  16. */
  17. public class MainActivity extends AppCompatActivity {
  18. int quantity=0;
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.activity_main);
  23. }
  24. /**
  25. * This method is called when the order button is clicked.
  26. */
  27. public void submitOrder(View view) {
  28. int price=quantity*5;
  29. String lat="Thank you!";
  30. String priceMessage="Total:"+ price +"\n"+ lat;
  31. displayMessage(priceMessage);
  32. }
  33. private void displayMessage(String priceMessage) {
  34. TextView priceTextView=(TextView) findViewById(R.id.price_text_view);
  35. priceTextView.setText(priceMessage);
  36. }
  37. /**
  38. * This method displays the given quantity value on the screen.
  39. */
  40. private void display(int number) {
  41. TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
  42. quantityTextView.setText("" + number);
  43. }
  44. private void priceBox(int number){
  45. TextView pricetext=(TextView) findViewById(R.id.price_text_view);
  46. pricetext.setText(NumberFormat.getCurrencyInstance().format(number));
  47. }
  48. public void increment(View view){
  49. quantity=quantity+1;
  50. display(quantity);
  51. }
  52. public void decrement(View view){
  53. quantity=quantity-1;
  54. display(quantity);
  55. }
  56. }
output

Nested View and Quantity Picker 3rd project

input

xml code

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:id="@+id/activity_main"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:orientation="vertical"
  8. android:paddingBottom="@dimen/activity_vertical_margin"
  9. android:paddingLeft="@dimen/activity_horizontal_margin"
  10. android:paddingRight="@dimen/activity_horizontal_margin"
  11. android:paddingTop="@dimen/activity_vertical_margin"
  12. tools:context="com.example.saketh.firstprojectman.MainActivity">
  13. <TextView
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:layout_marginBottom="16dp"
  17. android:text="quantity"
  18. android:textAllCaps="true" />
  19. <LinearLayout
  20. android:layout_width="match_parent"
  21. android:layout_height="wrap_content"
  22. android:orientation="horizontal">
  23. <Button
  24. android:layout_width="48dp"
  25. android:layout_height="48dp"
  26. android:onClick="decrement"
  27. android:text="-" />
  28. <TextView
  29. android:id="@+id/quantity_text_view"
  30. android:layout_width="wrap_content"
  31. android:layout_height="wrap_content"
  32. android:layout_marginBottom="16dp"
  33. android:layout_marginLeft="8dp"
  34. android:text="0"
  35. android:textAllCaps="true"
  36. android:textColor="@android:color/black"
  37. android:textSize="16sp"
  38. android:paddingLeft="8dp"
  39. android:paddingRight="8dp"/>
  40. <Button
  41. android:layout_width="48dp"
  42. android:layout_height="48dp"
  43. android:layout_marginLeft="8dp"
  44. android:onClick="increment"
  45. android:text="+" />
  46. </LinearLayout>
  47. <TextView
  48. android:layout_width="wrap_content"
  49. android:layout_height="wrap_content"
  50. android:layout_marginBottom="16dp"
  51. android:layout_marginTop="16dp"
  52. android:text="price"
  53. android:textAllCaps="true" />
  54. <TextView
  55. android:id="@+id/price_text_view"
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:layout_marginBottom="16dp"
  59. android:text="0"
  60. android:textAllCaps="true"
  61. android:textColor="@android:color/black"
  62. android:textSize="16sp" />
  63. <Button
  64. android:layout_width="wrap_content"
  65. android:layout_height="wrap_content"
  66. android:onClick="submitOrder"
  67. android:text="order" />
  68. </LinearLayout>
java code
  1. package com.example.saketh.firstprojectman; /**
  2. * Add your package below. Package name can be found in the project's AndroidManifest.xml file.
  3. * This is the package name our example uses:
  4. *
  5. * package com.example.android.justjava;
  6. */
  7. import android.icu.text.NumberFormat;
  8. import android.os.Bundle;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.view.View;
  11. import android.widget.TextView;
  12. import com.example.saketh.firstprojectman.R;
  13. import static android.icu.text.NumberFormat.getCurrencyInstance;
  14. /**
  15. * This app displays an order form to order coffee.
  16. */
  17. public class MainActivity extends AppCompatActivity {
  18. int quantity=0;
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.activity_main);
  23. }
  24. /**
  25. * This method is called when the order button is clicked.
  26. */
  27. public void submitOrder(View view) {
  28. int numberOfCoffee=quantity;
  29. display(numberOfCoffee);
  30. priceBox(numberOfCoffee*2);
  31. }
  32. /**
  33. * This method displays the given quantity value on the screen.
  34. */
  35. private void display(int number) {
  36. TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
  37. quantityTextView.setText("" + number);
  38. }
  39. private void priceBox(int number){
  40. TextView pricetext=(TextView) findViewById(R.id.price_text_view);
  41. pricetext.setText(NumberFormat.getCurrencyInstance().format(number));
  42. }
  43. public void increment(View view){
  44. quantity=quantity+1;
  45. display(quantity);
  46. }
  47. public void decrement(View view){
  48. quantity=quantity-1;
  49. display(quantity);
} }



output