Change another string to a resource.
[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 /**
28  * Get a broadcast when the network is connected, and kill the activity.
29  */
30 final class ConnectedReceiver extends BroadcastReceiver {
31
32   private final Activity parent;
33   private final TextView statusView;
34
35   ConnectedReceiver(Activity wifiActivity, TextView statusView) {
36     parent = wifiActivity;
37     this.statusView = statusView;
38   }
39
40   @Override
41   public void onReceive(Context context, Intent intent) {
42     if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
43       ConnectivityManager con = (ConnectivityManager) parent.getSystemService(Context.CONNECTIVITY_SERVICE);
44       NetworkInfo[] s = con.getAllNetworkInfo();
45       for (NetworkInfo i : s){
46         if (i.getTypeName().contentEquals("WIFI")){
47           NetworkInfo.State state = i.getState();
48           if (state == NetworkInfo.State.CONNECTED){
49             statusView.setText("Connected!");
50             Runnable delayKill = new Killer(parent);
51             delayKill.run();
52           }
53         }
54       }
55     }
56   }
57 }