【小软件】年度优秀员工

部门快要年会了,最近做了个小软件,“年度优秀员工”apk。

需求:部门的七个小组每组推荐两名候选人,部门所有员工投票选出七名优秀员工。每人必须选不是同一组的两人,不能多选或者少选,必须是本部门的员工才有资格选,选定两个后最终本软件以短信的形式向同一个手机号发送过去,最终通过短信数据库导出表格,统计即可。

实现界面如下:

 

代码如下:

activity_main.xml

  1 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2     xmlns:tools="http://schemas.android.com/tools"
  3     android:id="@+id/layout"
  4     android:layout_width="match_parent"
  5     android:layout_height="match_parent"
  6     tools:context="${relativePackage}.${activityClass}" >
  7 
  8 <TableRow>
  9     <TextView
 10         android:id="@+id/text_view"
 11         android:layout_width="wrap_content"
 12         android:layout_height="wrap_content"
 13         android:text="@string/name"
 14         android:textSize="10pt" 
 15         android:background="#CCCCCC" 
 16         android:paddingLeft="20dip" 
 17         android:paddingRight="20dip"
 18         android:paddingTop="10dip" 
 19         android:paddingBottom="10dip"
 20         android:layout_marginRight="5dip"
 21         android:layout_marginLeft="25dip"  
 22         android:layout_marginTop="5dip"
 23         android:layout_marginBottom="5dip"/>
 24     <EditText 
 25         android:id="@+id/edit_text"
 26         android:layout_width="wrap_content"
 27         android:layout_height="wrap_content"
 28         android:inputType="number"
 29         android:hint="@string/nameber"
 30         android:background="#CCCCCC"
 31         android:paddingLeft="20dip" 
 32         android:paddingRight="20dip"
 33         android:paddingTop="10dip" 
 34         android:paddingBottom="10dip"
 35         android:layout_marginRight="5dip"
 36         android:layout_marginLeft="5dip"  
 37         android:layout_marginTop="5dip"
 38         android:layout_marginBottom="5dip"/>
 39 </TableRow>
 40 <TableRow>
 41     <RadioGroup 
 42         android:id="@+id/radio_group1"
 43         android:layout_width="wrap_content"
 44         android:layout_height="wrap_content"
 45         android:background="#CAE1FF"
 46         android:paddingLeft="20dip" 
 47         android:paddingRight="20dip"
 48         android:paddingTop="10dip" 
 49         android:paddingBottom="10dip"
 50         android:layout_marginRight="5dip"
 51         android:layout_marginLeft="25dip"  
 52         android:layout_marginTop="5dip"
 53         android:layout_marginBottom="5dip">
 54         <TextView 
 55             android:layout_width="wrap_content"
 56             android:layout_height="wrap_content"
 57             android:text="@string/n1"/>
 58         <RadioButton 
 59             android:id="@+id/radiob1"
 60             android:layout_width="wrap_content"
 61             android:layout_height="wrap_content"
 62             android:text="@string/name1"/>
 63         <RadioButton 
 64             android:id="@+id/radiob2"
 65             android:layout_width="wrap_content"
 66             android:layout_height="wrap_content"
 67             android:text="@string/name2"/>
 68     </RadioGroup>
 69     <RadioGroup 
 70         android:id="@+id/radio_group2"
 71         android:layout_width="wrap_content"
 72         android:layout_height="wrap_content"
 73         android:background="#CAE1FF"
 74         android:paddingLeft="20dip" 
 75         android:paddingRight="20dip" 
 76         android:paddingTop="10dip" 
 77         android:paddingBottom="10dip"
 78         android:layout_marginRight="5dip" 
 79         android:layout_marginLeft="5dip" 
 80         android:layout_marginTop="5dip"
 81         android:layout_marginBottom="5dip">
 82         <TextView 
 83             android:layout_width="wrap_content"
 84             android:layout_height="wrap_content"
 85             android:text="@string/n2"/>
 86         <RadioButton 
 87             android:id="@+id/radiob3"
 88             android:layout_width="wrap_content"
 89             android:layout_height="wrap_content"
 90             android:text="@string/name3"/>
 91         <RadioButton 
 92             android:id="@+id/radiob4"
 93             android:layout_width="wrap_content"
 94             android:layout_height="wrap_content"
 95             android:text="@string/name4"/>
 96     </RadioGroup>
 97     </TableRow>
 98     <TableRow>
 99     <RadioGroup 
100         android:id="@+id/radio_group3"
101         android:layout_width="wrap_content"
102         android:layout_height="wrap_content"
103         android:background="#CAE1FF"
104         android:paddingLeft="20dip" 
105         android:paddingRight="20dip"
106         android:paddingTop="10dip" 
107         android:paddingBottom="10dip"
108         android:layout_marginRight="5dip" 
109         android:layout_marginLeft="25dip" 
110         android:layout_marginTop="5dip"
111         android:layout_marginBottom="5dip">
112         <TextView 
113             android:layout_width="wrap_content"
114             android:layout_height="wrap_content"
115             android:text="@string/n3"/>
116         <RadioButton 
117             android:id="@+id/radiob5"
118             android:layout_width="wrap_content"
119             android:layout_height="wrap_content"
120             android:text="@string/name5"/>
121         <RadioButton 
122             android:id="@+id/radiob6"
123             android:layout_width="wrap_content"
124             android:layout_height="wrap_content"
125             android:text="@string/name6"/>
126     </RadioGroup>
127     <RadioGroup 
128         android:id="@+id/radio_group4"
129         android:layout_width="wrap_content"
130         android:layout_height="wrap_content"
131         android:background="#CAE1FF"
132         android:paddingLeft="20dip" 
133         android:paddingRight="20dip"
134         android:paddingTop="10dip" 
135         android:paddingBottom="10dip"
136         android:layout_marginRight="5dip" 
137         android:layout_marginLeft="5dip" 
138         android:layout_marginTop="5dip"
139         android:layout_marginBottom="5dip">
140         <TextView 
141             android:layout_width="wrap_content"
142             android:layout_height="wrap_content"
143             android:text="@string/n4"/>
144         <RadioButton 
145             android:id="@+id/radiob7"
146             android:layout_width="wrap_content"
147             android:layout_height="wrap_content"
148             android:text="@string/name7"/>
149         <RadioButton 
150             android:id="@+id/radiob8"
151             android:layout_width="wrap_content"
152             android:layout_height="wrap_content"
153             android:text="@string/name8"/>
154     </RadioGroup>
155     </TableRow>
156     <TableRow>
157     <RadioGroup 
158         android:id="@+id/radio_group5"
159         android:layout_width="wrap_content"
160         android:layout_height="wrap_content"
161         android:background="#CAE1FF"
162         android:paddingLeft="20dip" 
163         android:paddingRight="20dip" 
164         android:paddingTop="10dip" 
165         android:paddingBottom="10dip"
166         android:layout_marginRight="5dip" 
167         android:layout_marginLeft="25dip" 
168         android:layout_marginTop="5dip"
169         android:layout_marginBottom="5dip" >
170         <TextView 
171             android:layout_width="wrap_content"
172             android:layout_height="wrap_content"
173             android:text="@string/n5"/>
174         <RadioButton 
175             android:id="@+id/radiob9"
176             android:layout_width="wrap_content"
177             android:layout_height="wrap_content"
178             android:text="@string/name9"/>
179         <RadioButton 
180             android:id="@+id/radiob10"
181             android:layout_width="wrap_content"
182             android:layout_height="wrap_content"
183             android:text="@string/name10"/>
184     </RadioGroup>
185     <RadioGroup 
186         android:id="@+id/radio_group6"
187         android:layout_width="wrap_content"
188         android:layout_height="wrap_content"
189         android:background="#CAE1FF"
190         android:paddingLeft="20dip" 
191         android:paddingRight="20dip"
192         android:paddingTop="10dip" 
193         android:paddingBottom="10dip"
194         android:layout_marginRight="5dip"
195         android:layout_marginLeft="5dip"  
196         android:layout_marginTop="5dip"
197         android:layout_marginBottom="5dip">
198         <TextView 
199             android:layout_width="wrap_content"
200             android:layout_height="wrap_content"
201             android:text="@string/n6"/>
202         <RadioButton 
203             android:id="@+id/radiob11"
204             android:layout_width="wrap_content"
205             android:layout_height="wrap_content"
206             android:text="@string/name11"/>
207         <RadioButton 
208             android:id="@+id/radiob12"
209             android:layout_width="wrap_content"
210             android:layout_height="wrap_content"
211             android:text="@string/name12"/>
212     </RadioGroup>
213     </TableRow>
214     <TableRow>
215     <RadioGroup 
216         android:id="@+id/radio_group7"
217         android:layout_width="wrap_content"
218         android:layout_height="wrap_content"
219         android:background="#CAE1FF"
220         android:layout_marginRight="5dip"
221         android:layout_marginLeft="25dip"  
222         android:layout_marginTop="5dip"
223         android:layout_marginBottom="5dip"
224         android:paddingLeft="20dip" 
225         android:paddingRight="20dip"
226         android:paddingTop="10dip" 
227         android:paddingBottom="10dip">
228         <TextView 
229             android:layout_width="wrap_content"
230             android:layout_height="wrap_content"
231             android:text="@string/n7"/>
232         <RadioButton 
233             android:id="@+id/radiob13"
234             android:layout_width="wrap_content"
235             android:layout_height="wrap_content"
236             android:text="@string/name13"/>
237         <RadioButton 
238             android:id="@+id/radiob14"
239             android:layout_width="wrap_content"
240             android:layout_height="wrap_content"
241             android:text="@string/name14"/>
242     </RadioGroup>
243     </TableRow>
244     <TableRow>
245     <Button 
246         android:id="@+id/button1"
247         android:layout_width="wrap_content"
248         android:layout_height="wrap_content"
249         android:text="@string/confirm"
250         android:background="#CCCCCC"
251         android:layout_marginRight="5dip" 
252         android:layout_marginLeft="25dip" 
253         android:layout_marginTop="5dip"
254         android:layout_marginBottom="5dip"
255         android:paddingLeft="20dip" 
256         android:paddingRight="20dip"
257         android:paddingTop="10dip" 
258         android:paddingBottom="10dip"/>
259     <Button 
260         android:id="@+id/button2"
261         android:layout_width="wrap_content"
262         android:layout_height="wrap_content"
263         android:background="#CCCCCC"
264         android:text="@string/cancel"
265         android:layout_marginRight="5dip"
266         android:layout_marginLeft="5dip"  
267         android:layout_marginTop="5dip"
268         android:layout_marginBottom="5dip"
269         android:paddingLeft="20dip" 
270         android:paddingRight="20dip"
271         android:paddingTop="10dip" 
272         android:paddingBottom="10dip"/>
273     </TableRow>
274 </TableLayout>
View Code

strings.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <resources>
 3     <string name="app_name">优秀员工</string>
 4     <string name="name">账号:</string>
 5     <string name="nameber">请输入您的工号</string>
 6     <string name="confirm">确认投票</string>
 7     <string name="cancel">重新选择</string>
 8     <string name="name1"></string>
 9     <string name="name2"></string>    
10     <string name="name3"></string>
11     <string name="name4"></string>
12     <string name="name5"></string>
13     <string name="name6"></string>
14     <string name="name7"></string>
15     <string name="name8"></string>
16     <string name="name9"></string>
17     <string name="name10"></string>
18     <string name="name11"></string>
19     <string name="name12"></string>
20     <string name="name13"></string>
21     <string name="name14"></string>
22     <string name="n1">协议组:</string>
23     <string name="n2">应用组:</string>
24     <string name="n3">系统组:</string>
25     <string name="n4">协议组:</string>
26     <string name="n5">软件配置管理:</string>
27     <string name="n6">驱动组:</string>
28     <string name="n7">项目管理:</string>
29 </resources>
View Code

MainActivity.java

  1 package com.junhao.newoutstanding;
  2 import com.junhao.newoutstanding.SendMessage;
  3 
  4 import android.app.Activity;
  5 import android.content.BroadcastReceiver;
  6 import android.content.Context;
  7 import android.content.Intent;
  8 import android.content.IntentFilter;
  9 import android.os.Bundle;
 10 import android.telephony.TelephonyManager;
 11 import android.util.Log;
 12 import android.view.View;
 13 import android.view.inputmethod.InputMethodManager;
 14 import android.widget.Button;
 15 import android.widget.EditText;
 16 import android.widget.RadioButton;
 17 import android.widget.RadioGroup;
 18 import android.widget.RadioGroup.OnCheckedChangeListener;
 19 import android.widget.TableLayout;
 20 import android.widget.Toast;
 21 
 22 public class MainActivity extends Activity
 23     implements Button.OnClickListener,OnCheckedChangeListener{
 24     private static final String TAG = "MainActivity";
 25     private Button confirm;
 26     private Button cancel;
 27     private EditText edit;
 28     private RadioGroup group1,group2,group3,group4,group5,group6,group7;
 29     private RadioGroup[] rg = {group1,group2,group3,group4,group5,group6,group7};
 30     private int[] group = {R.id.radio_group1,R.id.radio_group2,R.id.radio_group3,R.id.radio_group4,R.id.radio_group5,R.id.radio_group6,R.id.radio_group7};
 31     private SendMessage mSendMessage = new SendMessage();
 32     private TelephonyManager mTelephonyManager;
 33     private TableLayout mLayout;
 34     APRPhoneStateListener phone_state_listener = APRPhoneStateListener.getInstance();
 35     CharSequence str1,str2,str3,str4,str5,str6,str7 = null;
 36     String str = null;
 37     String names = null;
 38     int num = 0;
 39     CharSequence[] strings = new CharSequence[] {str1,str2,str3,str4,str5,str6,str7};
 40     private  boolean firstInServer = true;
 41     //private static final String VOTE_SUCCESS = "com.junhao.newoutstanding.VOTE_SUCCESS";
 42     //private  boolean VOTE_SUCCESS_FLAG = false;
 43     @Override
 44     protected void onCreate(Bundle savedInstanceState) {
 45         super.onCreate(savedInstanceState);
 46         setContentView(R.layout.activity_main);
 47         mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
 48         mTelephonyManager.listen(phone_state_listener,APRPhoneStateListener.LISTEN_SERVICE_STATE);
 49         Log.d(TAG, "phone_state_listener = " + phone_state_listener);
 50         IntentFilter filter = new IntentFilter("android.intent.action.SERVICE_STATE");
 51         registerReceiver(mServiceStateReceiver, filter);
 52         confirm = (Button)findViewById(R.id.button1);
 53         cancel = (Button)findViewById(R.id.button2);
 54         edit = (EditText)findViewById(R.id.edit_text);
 55         mLayout = (TableLayout)findViewById(R.id.layout);
 56         confirm.setOnClickListener(this);
 57         cancel.setOnClickListener(this);
 58         mLayout.setOnClickListener(this);
 59         for(int i = 0 ;i < rg.length ;i++){
 60             rg[i] = (RadioGroup)this.findViewById(group[i]);
 61             rg[i].setOnCheckedChangeListener(this);
 62         }
 63     }
 64 
 65     @Override
 66     public void onCheckedChanged(RadioGroup b, int checked) {
 67         int radioButtonId = b.getCheckedRadioButtonId();
 68            RadioButton rb = (RadioButton)MainActivity.this.findViewById(radioButtonId);
 69            int id = 0;
 70            for(id = 0; id < rg.length ; id++){
 71                if(b.getId() == group[id]){
 72                    break;
 73                }
 74            }
 75            
 76         if(rb != null){
 77                if(strings[id] == null) num++;
 78                Log.e(TAG,"strings[id] = "+strings[id]);
 79                  strings[id] = rb.getText();
 80                }
 81             if(num <= 2) {
 82                 return;
 83             }else{
 84                 num --;
 85                 strings[id] = null;
 86                 b.clearCheck();
 87                 Log.e(TAG,"b = "+b);
 88                 Toast.makeText(MainActivity.this, "你只能选择两名候选人", Toast.LENGTH_SHORT).show();
 89             }
 90            }
 91            
 92     
 93     public void onDestroy() {
 94         try{ 
 95             Log.d(TAG, "onDestroy");
 96             unregisterReceiver(mServiceStateReceiver);
 97             } 
 98        catch(Exception ex){} 
 99        super.onDestroy(); 
100 
101     }
102     public void onClick(View button){
103         String array[] ={"380273","1050358","525683","370773","392023","432407","477321","523075","559526","568442",
104                         "1204486","1258406","1870738","1880417","593081","2013806","2056502","2056503","2064329","2062845",
105                         "370791","1883161","1610914","460312","1249497","389075","438017","650363","1027080","1206493",
106                         "1209166","1237131","1225065","1846012","1708895","2020723","2032732","2040465","2062771","2064391",
107                         "1092565","369931","1082733","1659716","2063824","2062846","522622","525678","1223066","466162",
108                         "370780","362547","392443","396128","468921","522794","594011","1202554","701616","571237",
109                         "1202992","2062769","2062801","2063740","471554","469703","1180670","1846852","2062785","2073025",
110                         "2106796","453545","456201","574701","579713","589142","1204551","1210024","1220737","1839418",
111                         "1765654","2064541","2062916","580009","1826044","603808","2064398","295808","1634674","531963",
112                         "394013","1208146","1221088","1224923","1658971","1189964","1845139","2013807","2064325","393471",
113                         "475840","531533","568530","507956","2062802","2062871","2091017","361288","389000","430284",
114                         "451904","479732","585093","549977","587770","1155067","1200391","1201729","1206546","1207177",
115                         "1679004","1835970","1835969","1982688","1999116","2005171","2044123","2063823","566351","438068",
116                         "580017","594021","1849431","1164792","1870736","1897299","2001869","2110239","1867392",};
117         switch (button.getId()) {
118 
119          case R.id.button1:
120              str = edit.getText().toString();
121             if ("".equals(str)) {
122                 Toast.makeText(MainActivity.this, "请输入工号", Toast.LENGTH_SHORT).show();
123                 return;
124             }
125            Log.d(TAG,"get the str = " + str);
126             boolean checknum = false ;
127             for(int i = 0;i< array.length; i++){
128                 if (array[i].equals(str)){
129                     checknum = true ;
130                     break;
131                 }
132             }
133             if(!checknum){
134                 Toast.makeText(MainActivity.this, "输入的工号不正确", Toast.LENGTH_SHORT).show();
135             }else{
136                 names = "";
137                 for (int i = 0; i < strings.length; i++){
138                     if(strings[i]!=null){
139                         names += strings[i]+" ";
140                         Log.d(TAG, "names = "+names);
141                     }
142                 }
143                 if(num != 2){
144                     Toast.makeText(MainActivity.this, "您要选择两名候选人", Toast.LENGTH_SHORT).show();
145                     Log.d(TAG, "num = "+num);
146                     Log.d(TAG, "str000 = "+str1);
147                     //return;
148                 }else{
149                     Toast.makeText(MainActivity.this, "投票成功", Toast.LENGTH_SHORT).show();
150                     String content = str + "_" + names ;
151                     Log.d(TAG, "content = "+content);
152                     mSendMessage.sendSMSOnly(content);
153                     return; 
154                 }
155             }
156             
157         break;
158         case R.id.button2:
159             for(int i = 0; i< 7; i++){
160                 rg[i].clearCheck();
161                 strings[i] = null;
162             }
163             num = 0;
164             Toast.makeText(MainActivity.this, "重新选择", Toast.LENGTH_SHORT).show();    
165         break;
166         case R.id.layout:
167             InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  
168             imm.hideSoftInputFromWindow(button.getWindowToken(), 0);
169         break;
170         }
171     }
172     
173     private final BroadcastReceiver mServiceStateReceiver = new BroadcastReceiver() {
174               
175         @SuppressWarnings("static-access")
176         @Override
177         public void onReceive(Context context, Intent intent) {
178             Log.d(TAG, "isPhoneInService = " + phone_state_listener.isPhoneInService() + " firstInServer" + firstInServer);
179                 if (phone_state_listener.isPhoneInService() && firstInServer) {
180                         Log.d(TAG,"the phone in service");                       
181                 }
182             }
183 };
184 }
View Code

APRPhoneStateListener.java

 1 package com.junhao.newoutstanding;
 2 
 3 import android.telephony.PhoneStateListener;
 4 import android.telephony.ServiceState;
 5 import android.util.Log;
 6 
 7 public class APRPhoneStateListener extends PhoneStateListener{
 8     static final String TAG = "APRPhoneStateListener";
 9     private static APRPhoneStateListener mInstance;
10     private static boolean phone_in_service = false;
11     private static String mcc_mnc = null;
12 
13     static {
14         mInstance = null;
15     }
16 
17     public static APRPhoneStateListener getInstance() {
18         if (mInstance == null)
19             mInstance = new APRPhoneStateListener();
20 
21         return mInstance;
22     }
23 
24     public static boolean isPhoneInService() {
25         return phone_in_service;
26     }
27 
28     public static String getOperatorNumberic() {
29         Log.d(TAG,"get the mcc_mnc = " + mcc_mnc);
30         return mcc_mnc;
31     }
32 
33     public final void onServiceStateChanged(ServiceState paramServiceState) {
34         Log.d(TAG,"get servicestate = " + paramServiceState.getState());
35         super.onServiceStateChanged(paramServiceState);
36         mcc_mnc = paramServiceState.getOperatorNumeric();
37         if(mcc_mnc != null){
38             switch (paramServiceState.getState()) {
39                 case 1:
40                     phone_in_service = false;
41                     break;
42 
43                 case 0:
44                     phone_in_service = true;
45                     break;
46 
47                 default:
48                     phone_in_service = false;
49                     break;
50             }
51         }
52     }
53 }
View Code

SendMessage.java

 1 package com.junhao.newoutstanding;
 2 
 3 import android.app.Activity;
 4 import android.telephony.SmsManager;
 5 import android.text.TextUtils;
 6 import android.util.Log;
 7 import java.util.List;
 8 public class SendMessage extends Activity {
 9     private static final String TAG = "SendMessage";
10     private static final String AUTO_SMS_BEIJING_NUM = "+8618611011111";
11     private static final int BEIJING_MCC = 460;
12     APRPhoneStateListener phone_state_listener = APRPhoneStateListener.getInstance();
13     private static String MCC_MNC = null;
14     private static int MCC = 0;
15     public void sendSMSOnly(String paramString) {
16         MCC = getMCCNumber();
17         Log.d(TAG,"get the MCC = " + MCC);
18         switch(MCC) {
19 
20             case BEIJING_MCC:
21                 sendSMS(AUTO_SMS_BEIJING_NUM, paramString);
22                 break;
23 
24             default :
25                 break;
26         }
27     }
28 
29     @SuppressWarnings("static-access")
30     private int getMCCNumber() {
31          Log.d(TAG,"get the phone_state_listener = " + phone_state_listener);
32         MCC_MNC = phone_state_listener.getOperatorNumberic();
33         Log.d(TAG,"get the MCC_MNC = " + MCC_MNC);
34         int mcc = 0;
35 
36         if (!TextUtils.isEmpty(MCC_MNC)) {
37             String mccstr = MCC_MNC.substring(0, 3);
38            Log.d(TAG, "[jiwei]  get MCC_MNC =  " + MCC_MNC + " and mcc = " + mccstr);
39             mcc = Integer.valueOf(mccstr).intValue();
40         }
41 
42         return mcc;
43 
44     }
45 
46     public void sendSMS(String phoneNumber, String paramString) {
47         SmsManager sms = SmsManager.getDefault();
48         List<String> texts = sms.divideMessage(paramString);
49       Log.d(TAG," get the text = " + texts);
50         for (String text : texts) {
51             sms.sendTextMessage(phoneNumber, null, text, null, null);
52         }
53     }
54 
55 }
View Code

 

posted @ 2015-01-17 03:06  lelelong  阅读(657)  评论(0编辑  收藏  举报