Example usage for android.net.wifi WifiInfo LINK_SPEED_UNITS

List of usage examples for android.net.wifi WifiInfo LINK_SPEED_UNITS

Introduction

In this page you can find the example usage for android.net.wifi WifiInfo LINK_SPEED_UNITS.

Prototype

String LINK_SPEED_UNITS

To view the source code for android.net.wifi WifiInfo LINK_SPEED_UNITS.

Click Source Link

Document

Link speed in Mbps

Usage

From source file:com.vrem.wifianalyzer.wifi.AccessPointsDetail.java

public void setView(@NonNull Resources resources, @NonNull View view, @NonNull WiFiDetail wiFiDetail,
        boolean child, boolean frequencyRange) {
    ((TextView) view.findViewById(R.id.ssid)).setText(wiFiDetail.getTitle());

    TextView textIPAddress = (TextView) view.findViewById(R.id.ipAddress);
    TextView textLinkSpeed = (TextView) view.findViewById(R.id.linkSpeed);
    String ipAddress = wiFiDetail.getWiFiAdditional().getIPAddress();
    if (StringUtils.isBlank(ipAddress)) {
        textIPAddress.setVisibility(View.GONE);
        textLinkSpeed.setVisibility(View.GONE);
    } else {/*  w  w  w.j  a  v a 2  s. c om*/
        textIPAddress.setVisibility(View.VISIBLE);
        textIPAddress.setText(ipAddress);

        int linkSpeed = wiFiDetail.getWiFiAdditional().getLinkSpeed();
        if (linkSpeed == WiFiConnection.LINK_SPEED_INVALID) {
            textLinkSpeed.setVisibility(View.GONE);
        } else {
            textLinkSpeed.setVisibility(View.VISIBLE);
            textLinkSpeed.setText(String.format("%d%s", linkSpeed, WifiInfo.LINK_SPEED_UNITS));
        }
    }

    ImageView configuredImage = (ImageView) view.findViewById(R.id.configuredImage);
    if (wiFiDetail.getWiFiAdditional().isConfiguredNetwork()) {
        configuredImage.setVisibility(View.VISIBLE);
        configuredImage.setColorFilter(resources.getColor(R.color.connected));
    } else {
        configuredImage.setVisibility(View.GONE);
    }

    WiFiSignal wiFiSignal = wiFiDetail.getWiFiSignal();
    Strength strength = wiFiSignal.getStrength();
    ImageView imageView = (ImageView) view.findViewById(R.id.levelImage);
    imageView.setImageResource(strength.imageResource());
    imageView.setColorFilter(resources.getColor(strength.colorResource()));

    Security security = wiFiDetail.getSecurity();
    ImageView securityImage = (ImageView) view.findViewById(R.id.securityImage);
    securityImage.setImageResource(security.imageResource());
    securityImage.setColorFilter(resources.getColor(R.color.icons_color));

    TextView textLevel = (TextView) view.findViewById(R.id.level);
    textLevel.setText(String.format("%ddBm", wiFiSignal.getLevel()));
    textLevel.setTextColor(resources.getColor(strength.colorResource()));

    ((TextView) view.findViewById(R.id.channel))
            .setText(String.format("%d", wiFiSignal.getWiFiChannel().getChannel()));
    ((TextView) view.findViewById(R.id.frequency))
            .setText(String.format("%d%s", wiFiSignal.getFrequency(), WifiInfo.FREQUENCY_UNITS));
    ((TextView) view.findViewById(R.id.distance)).setText(String.format("%.1fm", wiFiSignal.getDistance()));
    ((TextView) view.findViewById(R.id.capabilities)).setText(wiFiDetail.getCapabilities());

    TextView textVendor = ((TextView) view.findViewById(R.id.vendor));
    String vendor = wiFiDetail.getWiFiAdditional().getVendorName();
    if (StringUtils.isBlank(vendor)) {
        textVendor.setVisibility(View.GONE);
    } else {
        textVendor.setVisibility(View.VISIBLE);
        textVendor.setText(vendor);
    }

    if (child) {
        view.findViewById(R.id.tab).setVisibility(View.VISIBLE);
    } else {
        view.findViewById(R.id.tab).setVisibility(View.GONE);
    }

    if (frequencyRange) {
        view.findViewById(R.id.channel_frequency_range_row).setVisibility(View.VISIBLE);
        ((TextView) view.findViewById(R.id.channel_frequency_range)).setText(String.format("%d - %d %s",
                wiFiSignal.getFrequencyStart(), wiFiSignal.getFrequencyEnd(), WifiInfo.FREQUENCY_UNITS));
    } else {
        view.findViewById(R.id.channel_frequency_range_row).setVisibility(View.GONE);
    }
}

From source file:com.vrem.wifianalyzer.wifi.AccessPointsDetailTest.java

@Test
public void testSetViewWithWiFiDetailAsConnection() throws Exception {
    // setup//from w  w  w.j a v  a2 s .  c om
    WiFiDetail wiFiDetail = new WiFiDetail("SSID", "BSSID", "capabilities",
            new WiFiSignal(1, WiFiWidth.MHZ_20, 2), new WiFiAdditional("VendorName", "IPAddress", 22));
    // execute
    fixture.setView(mainActivity.getResources(), view, wiFiDetail, false, false);
    // validate
    validateTextViewValues(wiFiDetail, "SSID");

    validateTextViewValue(wiFiDetail.getWiFiAdditional().getIPAddress(), R.id.ipAddress);
    assertEquals(View.VISIBLE, view.findViewById(R.id.ipAddress).getVisibility());

    assertEquals(View.VISIBLE, view.findViewById(R.id.configuredImage).getVisibility());

    validateTextViewValue(
            String.format("%d%s", wiFiDetail.getWiFiAdditional().getLinkSpeed(), WifiInfo.LINK_SPEED_UNITS),
            R.id.linkSpeed);
    assertEquals(View.VISIBLE, view.findViewById(R.id.linkSpeed).getVisibility());

    validateTextViewValue(wiFiDetail.getWiFiAdditional().getVendorName(), R.id.vendor);
    assertEquals(View.VISIBLE, view.findViewById(R.id.vendor).getVisibility());

    assertEquals(View.GONE, view.findViewById(R.id.tab).getVisibility());
    assertEquals(View.GONE, view.findViewById(R.id.groupIndicator).getVisibility());

    assertEquals(View.GONE, view.findViewById(R.id.channel_frequency_range_row).getVisibility());
}

From source file:eu.operando.proxy.wifi.AccessPointsDetail.java

public void setView(@NonNull Resources resources, @NonNull View view, @NonNull final WiFiDetail wiFiDetail) {

    TextView ssidLabel = (TextView) view.findViewById(R.id.ssid);
    ssidLabel.setText(wiFiDetail.getTitle());
    TextView textLinkSpeed = (TextView) view.findViewById(R.id.linkSpeed);
    String ipAddress = wiFiDetail.getWiFiAdditional().getIPAddress();
    boolean isConnected = StringUtils.isNotBlank(ipAddress);
    if (!isConnected) {
        textLinkSpeed.setVisibility(View.GONE);
        ssidLabel.setTextColor(resources.getColor(android.R.color.white));
    } else {/*  w  w  w .j  a v  a2s  .c  o m*/
        ssidLabel.setTextColor(resources.getColor(R.color.connected));

        int linkSpeed = wiFiDetail.getWiFiAdditional().getLinkSpeed();
        if (linkSpeed == WiFiConnection.LINK_SPEED_INVALID) {
            textLinkSpeed.setVisibility(View.GONE);
        } else {
            textLinkSpeed.setVisibility(View.VISIBLE);
            textLinkSpeed.setText(String.format("%d%s", linkSpeed, WifiInfo.LINK_SPEED_UNITS));
        }
    }

    WiFiSignal wiFiSignal = wiFiDetail.getWiFiSignal();
    Strength strength = wiFiSignal.getStrength();
    ImageView imageView = (ImageView) view.findViewById(R.id.levelImage);
    imageView.setImageResource(strength.imageResource());
    imageView.setColorFilter(resources.getColor(strength.colorResource()));

    Security security = wiFiDetail.getSecurity();
    ImageView securityImage = (ImageView) view.findViewById(R.id.securityImage);
    securityImage.setImageResource(security.imageResource());
    securityImage.setColorFilter(resources.getColor(R.color.icons_color));

    TextView textLevel = (TextView) view.findViewById(R.id.level);
    textLevel.setText(String.format("%ddBm", wiFiSignal.getLevel()));
    textLevel.setTextColor(resources.getColor(strength.colorResource()));

    ((TextView) view.findViewById(R.id.channel))
            .setText(String.format("%d", wiFiSignal.getWiFiChannel().getChannel()));
    ((TextView) view.findViewById(R.id.frequency))
            .setText(String.format("%d%s", wiFiSignal.getFrequency(), WifiInfo.FREQUENCY_UNITS));
    ((TextView) view.findViewById(R.id.distance)).setText(String.format("%.1fm", wiFiSignal.getDistance()));
    ((TextView) view.findViewById(R.id.capabilities)).setText(wiFiDetail.getCapabilities());

    LayoutInflater layoutInflater = mainContext.getLayoutInflater();

    final WiFiApConfig wiFiApConfig = wiFiDetail.getWiFiAdditional().getWiFiApConfig();
    ImageView configuredImage = (ImageView) view.findViewById(R.id.configuredImage);
    if (wiFiApConfig != null) {

        configuredImage.setVisibility(View.VISIBLE);

        if (isOperandoCompatible(wiFiApConfig)) {
            configuredImage.setColorFilter(resources.getColor(android.R.color.holo_green_light));
            view.setOnClickListener(
                    new ConfiguredClickListener(context, wiFiDetail, wiFiApConfig, isConnected));
        } else {
            configuredImage.setColorFilter(resources.getColor(android.R.color.holo_red_light));
            view.setOnClickListener(new ForgetClickListener(context, wiFiDetail));
        }

    } else {
        configuredImage.setVisibility(View.GONE);
        view.setOnClickListener(new ConnectClickListener(context, wiFiDetail, layoutInflater));
    }

}

From source file:eu.operando.operandoapp.wifi.AccessPointsDetail.java

public void setView(@NonNull Resources resources, @NonNull View view, @NonNull final WiFiDetail wiFiDetail) {

    TextView ssidLabel = (TextView) view.findViewById(R.id.ssid);
    ssidLabel.setText(wiFiDetail.getTitle());
    TextView textLinkSpeed = (TextView) view.findViewById(R.id.linkSpeed);
    textLinkSpeed.setTextColor(Color.BLACK);
    String ipAddress = wiFiDetail.getWiFiAdditional().getIPAddress();
    boolean isConnected = StringUtils.isNotBlank(ipAddress);
    if (!isConnected) {
        textLinkSpeed.setVisibility(View.GONE);
        ssidLabel.setTextColor(resources.getColor(android.R.color.black));
    } else {/*from  w ww  .  j a va 2 s  .co  m*/
        ssidLabel.setTextColor(resources.getColor(R.color.connected));

        int linkSpeed = wiFiDetail.getWiFiAdditional().getLinkSpeed();
        if (linkSpeed == WiFiConnection.LINK_SPEED_INVALID) {
            textLinkSpeed.setVisibility(View.GONE);
        } else {
            textLinkSpeed.setVisibility(View.VISIBLE);
            textLinkSpeed.setText(String.format("%d%s", linkSpeed, WifiInfo.LINK_SPEED_UNITS));
        }
    }

    WiFiSignal wiFiSignal = wiFiDetail.getWiFiSignal();
    Strength strength = wiFiSignal.getStrength();
    ImageView imageView = (ImageView) view.findViewById(R.id.levelImage);
    imageView.setImageResource(strength.imageResource());
    imageView.setColorFilter(resources.getColor(strength.colorResource()));

    Security security = wiFiDetail.getSecurity();
    ImageView securityImage = (ImageView) view.findViewById(R.id.securityImage);
    securityImage.setImageResource(security.imageResource());
    securityImage.setColorFilter(resources.getColor(R.color.icons_color));

    TextView textLevel = (TextView) view.findViewById(R.id.level);
    textLevel.setText(String.format("%ddBm", wiFiSignal.getLevel()));
    textLevel.setTextColor(Color.BLACK);
    //textLevel.setTextColor(resources.getColor(strength.colorResource()));

    ((TextView) view.findViewById(R.id.channel))
            .setText(String.format("%d", wiFiSignal.getWiFiChannel().getChannel()));
    ((TextView) view.findViewById(R.id.frequency))
            .setText(String.format("%d%s", wiFiSignal.getFrequency(), WifiInfo.FREQUENCY_UNITS));
    ((TextView) view.findViewById(R.id.distance)).setText(String.format("%.1fm", wiFiSignal.getDistance()));
    ((TextView) view.findViewById(R.id.capabilities)).setText(wiFiDetail.getCapabilities());

    LayoutInflater layoutInflater = mainContext.getLayoutInflater();

    final WiFiApConfig wiFiApConfig = wiFiDetail.getWiFiAdditional().getWiFiApConfig();
    ImageView configuredImage = (ImageView) view.findViewById(R.id.configuredImage);
    if (wiFiApConfig != null) {

        configuredImage.setVisibility(View.VISIBLE);

        if (isOperandoCompatible(wiFiApConfig)) {
            configuredImage.setColorFilter(resources.getColor(android.R.color.holo_green_light));
            view.setOnClickListener(
                    new ConfiguredClickListener(context, wiFiDetail, wiFiApConfig, isConnected));
        } else {
            configuredImage.setColorFilter(resources.getColor(android.R.color.holo_red_light));
            view.setOnClickListener(new ForgetClickListener(context, wiFiDetail));
        }

    } else {
        configuredImage.setVisibility(View.GONE);
        view.setOnClickListener(new ConnectClickListener(context, wiFiDetail, layoutInflater));
    }

}

From source file:com.ultrafunk.network_info.receiver.WifiStatusReceiver.java

private void setDetailsString(Context context) {
    String securityString = NetworkStateService.getWifiSecurityString();

    if (securityString == null)
        securityString = WifiUtils.getSecurityString(context, wifiManager, wifiInfo.getBSSID());

    if (wifiInfo.getLinkSpeed() != -1)
        detailsString = String.format("%s - %d %s", securityString, wifiInfo.getLinkSpeed(),
                WifiInfo.LINK_SPEED_UNITS);
    else//from   w ww.  j a va 2 s  .c om
        detailsString = context.getString(R.string.security) + ": " + securityString;
}

From source file:com.aqnote.app.wifianalyzer.wifi.ConnectionViewTest.java

@Test
public void testConnectionVisibleWithConnectionInformation() throws Exception {
    // setup//www.jav a 2  s .c  o  m
    WiFiAdditional wiFiAdditional = new WiFiAdditional(StringUtils.EMPTY, "IPADDRESS", 11);
    WiFiDetail connection = withConnection(wiFiAdditional);
    when(wiFiData.getConnection()).thenReturn(connection);
    when(wiFiData.getWiFiDetails(settings.getWiFiBand(), settings.getSortBy()))
            .thenReturn(new ArrayList<WiFiDetail>());
    // execute
    fixture.update(wiFiData);
    // validate
    View view = mainActivity.findViewById(R.id.connection);
    assertEquals(View.VISIBLE, view.getVisibility());

    TextView ipAddressView = (TextView) view.findViewById(R.id.ipAddress);
    assertEquals(View.VISIBLE, ipAddressView.getVisibility());
    assertEquals(wiFiAdditional.getIPAddress(), ipAddressView.getText().toString());

    TextView linkSpeedView = (TextView) view.findViewById(R.id.linkSpeed);
    assertEquals(View.VISIBLE, linkSpeedView.getVisibility());
    assertEquals(wiFiAdditional.getLinkSpeed() + WifiInfo.LINK_SPEED_UNITS, linkSpeedView.getText().toString());

    verify(wiFiData).getConnection();
    verify(accessPointsDetail).setView(mainActivity.getResources(), view, connection, false);
}

From source file:com.adamkruger.myipaddressinfo.NetworkInfoFragment.java

private void refreshView() {
    Context context = getActivity();
    mNetworkInfoTableLayout.removeAllViewsInLayout();

    if (mNetworkInfo != null) {
        String state = mNetworkInfo.getState().toString();
        String detailedState = mNetworkInfo.getDetailedState().toString();
        String reason = mNetworkInfo.getReason();
        if (detailedState.compareToIgnoreCase(state) == 0) {
            detailedState = "";
        }//from w w w .j  a  va  2s . c o  m
        if (reason == null || reason.compareToIgnoreCase(state) == 0
                || reason.compareToIgnoreCase(detailedState) == 0) {
            reason = "";
        }
        addTableRowTitle(context.getString(R.string.network_info_subtitle_active_network));
        addTableRow(new Row().addLine(mNetworkInfo.getTypeName(), state)
                .addLine(mNetworkInfo.getSubtypeName(), mNetworkInfo.getExtraInfo())
                .addLine(reason, detailedState));
    }

    if (mWifiEnabled) {
        if (mWifiInfo != null) {
            String wifiSSID = mWifiInfo.getSSID();
            if (wifiSSID != null && wifiSSID.length() > 0) {
                addTableRowSpacer();
                addTableRowTitle(context.getString(R.string.network_info_subtitle_wifi_info));
                addTableRow(new Row()
                        .addLine(wifiSSID,
                                mWifiInfo.getLinkSpeed() + WifiInfo.LINK_SPEED_UNITS + " ("
                                        + calculateSignalLevel(mWifiInfo.getRssi(), 100) + "%)")
                        .addLine(mWifiInfo.getHiddenSSID()
                                ? context.getString(R.string.network_info_hidden_network)
                                : "", ""));
            }
        }

        if (mDhcpInfo != null) {
            String dhcpIPAddress = intToHostAddress(mDhcpInfo.ipAddress);
            if (dhcpIPAddress.length() > 0) {
                addTableRowSpacer();
                addTableRowTitle(context.getString(R.string.network_info_subtitle_dhcp_info));
                addTableRow(new Row()
                        .addLineIfValue(context.getString(R.string.network_info_label_ip_address),
                                dhcpIPAddress)
                        .addLineIfValue(context.getString(R.string.network_info_label_gateway),
                                intToHostAddress(mDhcpInfo.gateway))
                        // TODO: netmask conversion doesn't work
                        .addLineIfValue(context.getString(R.string.network_info_label_netmask),
                                intToHostAddress(mDhcpInfo.netmask))
                        .addLineIfValue(context.getString(R.string.network_info_label_dns),
                                intToHostAddress(mDhcpInfo.dns1))
                        .addLineIfValue(context.getString(R.string.network_info_label_dns),
                                intToHostAddress(mDhcpInfo.dns2))
                        .addLineIfValue(context.getString(R.string.network_info_label_dhcp_server),
                                intToHostAddress(mDhcpInfo.serverAddress))
                        .addLineIfValue(context.getString(R.string.network_info_label_lease_duration),
                                Integer.toString(mDhcpInfo.leaseDuration)));
            }
        }
    }

    if (mDNSes.size() > 0) {
        addTableRowSpacer();
        addTableRowTitle(context.getString(R.string.network_info_subtitle_active_dns));
        Row row = new Row();
        for (String DNS : mDNSes) {
            row.addLine(context.getString(R.string.network_info_label_dns), DNS);
        }
        addTableRow(row);
    }

    if (mNetworkInterfaceInfos.size() > 0) {
        addTableRowSpacer();
        addTableRowTitle(context.getString(R.string.network_info_subtitle_interfaces));

        for (NetworkInterfaceInfo networkInterfaceInfo : mNetworkInterfaceInfos) {
            String valueColumn = "";
            for (String ipAddress : networkInterfaceInfo.ipAddresses) {
                valueColumn += ipAddress + "\n";
            }
            if (networkInterfaceInfo.MAC.length() > 0) {
                valueColumn += networkInterfaceInfo.MAC + "\n";
            }
            if (networkInterfaceInfo.MTU != -1) {
                valueColumn += String.format("%s: %d", context.getString(R.string.network_info_label_mtu),
                        networkInterfaceInfo.MTU);
            }
            addTableRow(new Row().addLine(networkInterfaceInfo.name, valueColumn));
        }
    }

    addTableRowSpacer();
}

From source file:kr.co.generic.wifianalyzer.wifi.ConnectionViewTest.java

@Test
public void testConnectionWithConnectionInformation() throws Exception {
    // setup/*from  w w w  .  j  a va2  s.  c o  m*/
    WiFiAdditional wiFiAdditional = withWiFiAdditional();
    WiFiDetail connection = withConnection(wiFiAdditional);
    withConnectionInformation(connection);
    withAccessPointDetailView(connection);
    // execute
    fixture.update(wiFiData);
    // validate
    WiFiConnection wiFiConnection = wiFiAdditional.getWiFiConnection();
    View view = mainActivity.findViewById(R.id.connection);
    assertEquals(wiFiConnection.getIpAddress(),
            ((TextView) view.findViewById(R.id.ipAddress)).getText().toString());
    TextView linkSpeedView = (TextView) view.findViewById(R.id.linkSpeed);
    assertEquals(View.VISIBLE, linkSpeedView.getVisibility());
    assertEquals(wiFiConnection.getLinkSpeed() + WifiInfo.LINK_SPEED_UNITS, linkSpeedView.getText().toString());
}

From source file:com.vrem.wifianalyzer.wifi.accesspoint.ConnectionViewTest.java

@Test
public void testConnectionWithConnectionInformation() throws Exception {
    // setup/*from w ww  . j  a va 2 s .c o m*/
    WiFiAdditional wiFiAdditional = withWiFiAdditional();
    WiFiDetail connection = withConnection(wiFiAdditional);
    when(settings.getConnectionViewType()).thenReturn(ConnectionViewType.COMPLETE);
    withConnectionInformation(connection);
    withAccessPointDetailView(connection, ConnectionViewType.COMPLETE.getAccessPointViewType());
    // execute
    fixture.update(wiFiData);
    // validate
    WiFiConnection wiFiConnection = wiFiAdditional.getWiFiConnection();
    View view = mainActivity.findViewById(R.id.connection);
    assertEquals(wiFiConnection.getIpAddress(),
            ((TextView) view.findViewById(R.id.ipAddress)).getText().toString());
    TextView linkSpeedView = (TextView) view.findViewById(R.id.linkSpeed);
    assertEquals(View.VISIBLE, linkSpeedView.getVisibility());
    assertEquals(wiFiConnection.getLinkSpeed() + WifiInfo.LINK_SPEED_UNITS, linkSpeedView.getText().toString());
}

From source file:fr.inria.ucn.collectors.NetworkStateCollector.java

private JSONObject getWifi(Context c) throws JSONException {
    WifiManager wm = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wi = wm.getConnectionInfo();

    // start a wifi AP scan
    Helpers.acquireWifiLock(c);/*from   ww w  .  ja  v  a  2s  .  c o m*/
    IntentFilter filter = new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    c.registerReceiver(this, filter);
    wm.startScan();

    JSONObject o = new JSONObject();
    o.put("link_speed", wi.getLinkSpeed());
    o.put("link_speed_units", WifiInfo.LINK_SPEED_UNITS);
    o.put("signal_level", WifiManager.calculateSignalLevel(wi.getRssi(), 100));
    o.put("rssi", wi.getRssi());
    o.put("bssid", wi.getBSSID());
    o.put("ssid", wi.getSSID().replaceAll("\"", ""));
    o.put("mac", wi.getMacAddress());

    int ip = wi.getIpAddress();
    String ipstr = String.format(Locale.US, "%d.%d.%d.%d", (ip & 0xff), (ip >> 8 & 0xff), (ip >> 16 & 0xff),
            (ip >> 24 & 0xff));
    o.put("ip", ipstr);

    return o;
}