Welcome 微信登录

首页 / 操作系统 / Linux / Android应用--->睡眠助手

睡眠助手闲来无聊 , 练手做一个Android的小应用。功能:有一个开关控制该应用的开启和关闭; 能设置时间,时间到了可以闹铃的方式将主人闹醒;     记录开启之前的手机情景模式,在开启该应用时自动将情景模式切换成静音模式,并在时间到了的时候自动将情景模式切换成开启之前的模式;   在开启到时间到(或手动关闭)之间来电话,手机自动挂断,并会回复一条短信给来电号码,告知您拨打的用户正在睡觉,回复的内容可自己编辑也可调用模板,并将来电号码以notification的方式通知主人有未接来电。相关阅读:Android 应用--->睡眠助手功能实现 http://www.linuxidc.com/Linux/2011-07/39464.htm第一天第一天主要是完成一些布局文件和一些控件的基本实现。一、首先是布局文件的设置main.xml :
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7. <LinearLayout  
  8.     android:orientation="vertical"  
  9.     android:layout_width="fill_parent"  
  10.     android:layout_height="250px"  
  11.     >  
  12. <LinearLayout  
  13.     android:orientation="horizontal"  
  14.     android:layout_width="fill_parent"  
  15.     android:layout_height="wrap_content"  
  16.     >  
  17. <TextView    
  18.     android:layout_width="100px"   
  19.     android:layout_height="wrap_content"  
  20.     android:text="时间显示"  
  21.     android:padding="5px"  
  22. />  
  23. <TextView  
  24.     android:id="@+id/timeShow"  
  25.     android:layout_width="wrap_content"  
  26.     android:layout_height="wrap_content"  
  27. />  
  28. </LinearLayout>  
  29. <LinearLayout  
  30.     android:orientation="horizontal"  
  31.     android:layout_width="fill_parent"  
  32.     android:layout_height="wrap_content"  
  33.     >  
  34. <TextView    
  35.     android:layout_width="100px"   
  36.     android:layout_height="wrap_content"  
  37.     android:text="回复内容显示"  
  38.     android:padding="5px"  
  39. />  
  40. <TextView    
  41.     android:layout_width="wrap_content"   
  42.     android:layout_height="wrap_content"  
  43.     android:id="@+id/reply_show"   
  44.     android:padding="5px"  
  45.     android:hint="@string/content_hint"  
  46. />  
  47. </LinearLayout>  
  48. <LinearLayout  
  49.     android:orientation="horizontal"  
  50.     android:layout_width="fill_parent"  
  51.     android:layout_height="wrap_content"  
  52.     >  
  53. <TextView    
  54.     android:layout_width="100px"   
  55.     android:layout_height="wrap_content"  
  56.     android:text="铃声显示"  
  57.     android:padding="5px"  
  58. />  
  59. <TextView    
  60.     android:layout_width="wrap_content"   
  61.     android:layout_height="wrap_content"  
  62.     android:id="@+id/ringtone_show"   
  63.     android:padding="5px"  
  64.     android:hint="卡农"  
  65. />  
  66. </LinearLayout>  
  67. <LinearLayout  
  68.     android:orientation="horizontal"  
  69.     android:layout_width="fill_parent"  
  70.     android:layout_height="wrap_content"  
  71.     >  
  72. <TextView    
  73.     android:layout_width="100px"   
  74.     android:layout_height="wrap_content"  
  75.     android:text="模式显示"  
  76.     android:padding="5px"  
  77. />  
  78. <TextView    
  79.     android:layout_width="wrap_content"   
  80.     android:layout_height="wrap_content"  
  81.     android:id="@+id/mode_show"   
  82.     android:padding="5px"  
  83.     android:hint="睡眠"  
  84. />  
  85. </LinearLayout>  
  86. <LinearLayout  
  87.     android:orientation="horizontal"  
  88.     android:layout_width="fill_parent"  
  89.     android:layout_height="wrap_content"  
  90.     >  
  91. <TextView  
  92.     android:layout_width="100px"   
  93.     android:layout_height="wrap_content"  
  94.     android:text="开关显示"  
  95.     android:padding="5px"  
  96. />  
  97. <TextView    
  98.     android:layout_width="wrap_content"   
  99.     android:layout_height="wrap_content"  
  100.     android:id="@+id/on_off_show"   
  101.     android:padding="5px"  
  102.     android:hint="关"  
  103. />  
  104. </LinearLayout>  
  105. </LinearLayout>  
  106. <TableLayout  
  107.     android:layout_width="fill_parent"  
  108.     android:layout_height="wrap_content"  
  109. >  
  110. <TableRow>  
  111.     <Button  
  112.         android:layout_column="1"  
  113.         android:id="@+id/setTime"  
  114.         android:text="设置时间"  
  115.         android:layout_width="150px"  
  116.         android:layout_height="wrap_content"  
  117.     />  
  118.     <Button  
  119.         android:text="设置回复内容"  
  120.         android:id="@+id/setReply"  
  121.         android:layout_width="150px"  
  122.         android:layout_height="wrap_content"  
  123.     />  
  124. </TableRow>  
  125. <TableRow>  
  126.     <Button  
  127.         android:layout_column="1"  
  128.         android:id="@+id/setRingTone"  
  129.         android:text="设置铃声"  
  130.         android:layout_width="150px"  
  131.         android:layout_height="wrap_content"  
  132.     />  
  133.     <Button  
  134.         android:text="设置模式"  
  135.         android:id="@+id/setMode"  
  136.         android:layout_width="150px"  
  137.         android:layout_height="wrap_content"  
  138.     />  
  139. </TableRow>  
  140. <TableRow>  
  141.     <Button  
  142.         android:layout_column="1"  
  143.         android:text="设置开关"  
  144.         android:id="@+id/setOnOff"  
  145.         android:layout_width="150px"  
  146.         android:layout_height="wrap_content"  
  147.     />  
  148.     <Button  
  149.         android:text="查看帮助信息"  
  150.         android:id="@+id/help"  
  151.         android:layout_width="150px"  
  152.         android:layout_height="wrap_content"  
  153.     />  
  154.       
  155. </TableRow>  
  156. </TableLayout>  
  157. </LinearLayout>  
效果如下图: