mansi_singhal

java and xml code for Bedroom 2 Ac

Jul 11th, 2018
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. ###### java code Bedroom 2 AC
  2.  
  3. package com.example.shikhadwivedi.homeautomation;
  4.  
  5. import android.content.Intent;
  6. import android.net.Uri;
  7. import android.os.Bundle;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.CompoundButton;
  12. import android.widget.ToggleButton;
  13.  
  14. /**
  15. * Created by root on 13/6/18.
  16. */
  17.  
  18. public class Room2Ac extends AppCompatActivity {
  19. ToggleButton room1,living,room2;
  20. Button read;
  21. Thread thread ;
  22. Intent intent;
  23. @Override
  24. protected void onCreate(Bundle savedInstanceState) {
  25. super.onCreate(savedInstanceState);
  26. setContentView(R.layout.room2ac);
  27. read = (Button) findViewById(R.id.acreadings);
  28. read.setOnClickListener(new View.OnClickListener() {
  29. @Override
  30. public void onClick(View v) {
  31. startActivity(new Intent(Room2Ac.this,Readings.class));
  32. }
  33. });
  34.  
  35. room2 = (ToggleButton) findViewById(R.id.room2act);
  36. room2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  37. @Override
  38. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  39. if (isChecked){
  40. Url_run xyz = new Url_run("http://192.168.0.15/br2_acon");
  41. thread = new Thread(xyz);
  42. thread.start();
  43. Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://192.168.0.15/br2_acon"));
  44.  
  45. }
  46. else{
  47. Url_run xyz = new Url_run("http://192.168.0.15/br2_acoff");
  48. thread = new Thread(xyz);
  49. thread.start();
  50. Intent intent1=new Intent(Intent.ACTION_VIEW, Uri.parse("http://192.168.0.15/br2_acoff"));
  51. }
  52. }
  53. });
  54. }
  55.  
  56. }
  57.  
  58.  
  59. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  60.  
  61. ###### xml code of Bedroom 2 AC
  62.  
  63. <?xml version="1.0" encoding="utf-8"?>
  64. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  65. xmlns:tools="http://schemas.android.com/tools"
  66. android:layout_width="match_parent"
  67. android:layout_height="match_parent"
  68. android:background="@drawable/bedroom1"
  69. android:orientation="vertical"
  70. >
  71.  
  72.  
  73. <LinearLayout
  74. android:id="@+id/roomac"
  75. android:layout_width="match_parent"
  76. android:layout_height="100sp"
  77. android:layout_margin="20sp"
  78. android:background="@drawable/headings"
  79. android:gravity="center">
  80.  
  81. <TextView
  82. android:layout_width="wrap_content"
  83. android:layout_height="match_parent"
  84. android:gravity="center"
  85. android:text="AC Status"
  86. android:textColor="#ffffff"
  87. android:textSize="35sp" />
  88. </LinearLayout>
  89. <LinearLayout
  90. android:layout_width="match_parent"
  91. android:layout_height="70sp"
  92. android:layout_margin="20sp"
  93. android:gravity="center"
  94. >
  95. <Button
  96. android:layout_width="match_parent"
  97. android:layout_height="match_parent"
  98. android:text="Readings"
  99. android:textSize="30sp"
  100. android:textColor="#3c0660"
  101. android:background="@drawable/oval"
  102. android:id="@+id/acreadings"/>
  103. </LinearLayout>
  104.  
  105. <RelativeLayout
  106. android:layout_width="match_parent"
  107. android:layout_height="70sp"
  108. android:layout_margin="20sp"
  109. android:background="@drawable/oval"
  110. android:orientation="horizontal">
  111.  
  112. <TextView
  113. android:id="@+id/actext"
  114. android:layout_width="match_parent"
  115. android:layout_height="match_parent"
  116. android:layout_marginLeft="10sp"
  117. android:gravity="left"
  118. android:text=" AC"
  119. android:textColor="#3c0660"
  120. android:textSize="30sp"
  121. android:drawableLeft="@drawable/ac"
  122. android:padding="10sp"
  123. />
  124.  
  125.  
  126. <ToggleButton
  127. android:id="@+id/room2act"
  128. android:layout_width="60sp"
  129. android:layout_height="wrap_content"
  130. android:layout_alignParentRight="true"
  131. android:layout_marginRight="30sp"
  132. android:layout_marginTop="10sp"
  133. android:background="@drawable/headings"
  134. android:textColor="#ffffff"
  135. android:textSize="20sp"
  136. android:fontFamily="cursive"
  137. android:layout_marginBottom="10sp"/>
  138. </RelativeLayout>
  139.  
  140. </LinearLayout>
Add Comment
Please, Sign In to add comment