Removed some commented code, and general code cleanup. Turned many
[zxing.git] / android / src / com / google / zxing / client / android / wifi / ConnectedReceiver.java
1 /*
2  * Copyright (C) 2010 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.google.zxing.client.android.wifi;
18
19 import android.app.Activity;
20 import android.content.BroadcastReceiver;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.net.ConnectivityManager;
24 import android.net.NetworkInfo;
25 import android.widget.TextView;
26
27 import com.google.zxing.client.android.R;
28
29 /**
30  * Get a broadcast when the network is connected, and kill the activity.
31  */
32 final class ConnectedReceiver extends BroadcastReceiver {
33
34   private final Activity parent;
35   private final TextView statusView;
36
37   ConnectedReceiver(Activity wifiActivity, TextView statusView) {
38     this.parent = wifiActivity;
39     this.statusView = statusView;
40   }
41
42   @Override
43   public void onReceive(Context context, Intent intent) {
44     if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
45       ConnectivityManager con = (ConnectivityManager) parent.getSystemService(Context.CONNECTIVITY_SERVICE);
46       final NetworkInfo[] s = con.getAllNetworkInfo();
47       for (NetworkInfo i : s){
48         if (i.getTypeName().contentEquals("WIFI")){
49           NetworkInfo.State state = i.getState();
50           if (state == NetworkInfo.State.CONNECTED){
51             statusView.setText(R.string.wifi_connected);
52             Runnable delayKill = new Killer(parent);
53             delayKill.run();
54           }
55         }
56       }
57     }
58   }
59 }