Back to project page android_device.
The source code is released under:
[Apache License](http://www.apache.org/licenses/): Version 2.0, January 2004 =============== ## TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION ## ### 1. Definitions. ### "License" sha...
If you think the Android project android_device listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * ================================================================================================= * Copyright (C) 2013 - 2014 Martin Albedinsky [Wolf-ITechnologies] * ================================================================================================= * Licensed under the Apache License, Version 2.0 or later (further "License" only). * ------------------------------------------------------------------------------------------------- * You may use this file only in compliance with the License. More details and copy of this License * you may obtain at//from ww w . ja v a 2 s . c o m * * http://www.apache.org/licenses/LICENSE-2.0 * * You can redistribute, modify or publish any part of the code written within this file but as it * is described in the License, the software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES or CONDITIONS OF ANY KIND. * * See the License for the specific language governing permissions and limitations under the License. * ================================================================================================= */ package com.wit.android.device.examples.fragment; import android.content.Context; import android.net.NetworkInfo; import android.os.Bundle; import android.support.annotation.NonNull; import android.view.View; import android.widget.ListView; import com.wit.android.device.examples.R; import com.wit.android.device.examples.adapter.ConnectionInfoAdapter; import com.wit.android.device.examples.model.ConnectionInfo; import com.wit.android.device.Connection; import com.wit.android.examples.libs.fragment.annotation.ExActionBarOptions; import com.wit.android.examples.libs.fragment.annotation.ExContentView; /** * <p> * Description. * </p> * * @author Martin Albedinsky */ @ExContentView(R.layout.fragment_listview) @ExActionBarOptions(title = R.string.Navigation_Label_ConnectionInfo) public class ConnectionInfoFragment extends BaseDeviceFragment { /** * Log TAG. */ // private static final String TAG = ConnectionInfoFragment.class.getSimpleName(); /** * */ private final NetworkListener NETWORK_LISTENER = new NetworkListener(); /** * */ private ConnectionInfoAdapter mAdapter; /** */ @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // Set up list view and adapter. if (mAdapter == null) { this.mAdapter = new ConnectionInfoAdapter(getActivity()); } ((ListView) view.findViewById(android.R.id.list)).setAdapter(mAdapter); final Connection connection = getAndroidDevice().getConnection(); // Register network listener. // Register network broadcast receivers. connection.registerOnConnectionListener(NETWORK_LISTENER); connection.registerConnectionReceiver(getActivity()); } /** */ @Override public void onDestroyView() { super.onDestroyView(); final Connection connection = getAndroidDevice().getConnection(); // UnRegister network listener. // UnRegister network broadcast receivers. connection.unregisterOnConnectionListener(NETWORK_LISTENER); connection.unregisterConnectionReceiver(getActivity()); } /** * * @param type * @param info */ private void dispatchConnectionChange(Connection.ConnectionType type, NetworkInfo info, boolean connected) { if (connected) { mAdapter.dispatchNewInfo(new ConnectionInfo(type, info)); } else { final ConnectionInfo connectionInfo = new ConnectionInfo(); connectionInfo.setLostType(type); mAdapter.dispatchNewInfo(connectionInfo); } } /** * */ private class NetworkListener implements Connection.OnConnectionListener { @Override public void onConnectionEstablished(@NonNull Connection.ConnectionType type, NetworkInfo info, @NonNull Context context) { dispatchConnectionChange(type, info, true); } @Override public void onConnectionLost(@NonNull Connection.ConnectionType type, @NonNull Context context) { dispatchConnectionChange(type, null, false); } } }