SelectFromListWizardFragment.java revision 6316b89e65828d537da309851529d1295efd5730
165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/* 265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Copyright (C) 2014 The Android Open Source Project 365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Licensed under the Apache License, Version 2.0 (the "License"); 565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * you may not use this file except in compliance with the License. 665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * You may obtain a copy of the License at 765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * http://www.apache.org/licenses/LICENSE-2.0 965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 1065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Unless required by applicable law or agreed to in writing, software 1165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * distributed under the License is distributed on an "AS IS" BASIS, 1265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * See the License for the specific language governing permissions and 1465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * limitations under the License. 1565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 1665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepackage com.android.tv.settings.connectivity.setup; 1865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.app.Activity; 2065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.app.Fragment; 2165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Context; 2265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.net.wifi.ScanResult; 2365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.net.wifi.WifiManager; 2465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Bundle; 2565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Handler; 2665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Parcel; 2765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Parcelable; 2865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.util.Log; 2965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.LayoutInflater; 3065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.View; 3165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.ViewGroup; 3265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.inputmethod.InputMethodManager; 3365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.widget.AdapterView; 3465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.widget.FrameLayout; 3565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.widget.ImageView; 3665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.widget.TextView; 3765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 386316b89e65828d537da309851529d1295efd5730Tony Mantlerimport com.android.tv.settings.R; 396316b89e65828d537da309851529d1295efd5730Tony Mantlerimport com.android.tv.settings.connectivity.WifiSecurity; 406316b89e65828d537da309851529d1295efd5730Tony Mantlerimport com.android.tv.settings.util.AccessibilityHelper; 416316b89e65828d537da309851529d1295efd5730Tony Mantlerimport com.android.tv.settings.widget.ScrollAdapterView; 426316b89e65828d537da309851529d1295efd5730Tony Mantlerimport com.android.tv.settings.widget.ScrollArrayAdapter; 436316b89e65828d537da309851529d1295efd5730Tony Mantler 4465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport java.util.ArrayList; 4565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport java.util.Comparator; 4665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 4765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/** 4865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Displays a UI for selecting a wifi network from a list in the "wizard" style. 4965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 5065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepublic class SelectFromListWizardFragment extends Fragment { 5165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 5265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String TAG = "SelectFromListWizardFragment"; 5365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final boolean DEBUG = false; 5465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 5565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static class ListItemComparator implements Comparator<ListItem> { 5665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 5765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public int compare(ListItem o1, ListItem o2) { 5865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ScanResult o1ScanResult = o1.getScanResult(); 5965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ScanResult o2ScanResult = o2.getScanResult(); 6065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (o1ScanResult == null) { 6165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (o2ScanResult == null) { 6265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return 0; 6365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 6465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return 1; 6565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 6665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 6765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (o2ScanResult == null) { 6865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return -1; 6965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 7065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int levelDiff = o2ScanResult.level - o1ScanResult.level; 7165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (levelDiff != 0) { 7265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return levelDiff; 7365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 7465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return o1ScanResult.SSID.compareTo(o2ScanResult.SSID); 7565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 7665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 7765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 7865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 7965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 8065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static class ListItem implements Parcelable { 8165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 8265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private final String mName; 8365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private final int mIconResource; 8465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private final int mIconLevel; 8565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private final boolean mHasIconLevel; 8665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private final ScanResult mScanResult; 8765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 8865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public ListItem(String name, int iconResource) { 8965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mName = name; 9065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mIconResource = iconResource; 9165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mIconLevel = 0; 9265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mHasIconLevel = false; 9365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mScanResult = null; 9465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 9565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 9665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public ListItem(ScanResult scanResult) { 9765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mName = scanResult.SSID; 9865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mIconResource = WifiSecurity.isOpen(scanResult) ? R.drawable.setup_wifi_signal_open 9965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane : R.drawable.setup_wifi_signal_lock; 10065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mIconLevel = WifiManager.calculateSignalLevel(scanResult.level, 4); 10165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mHasIconLevel = true; 10265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mScanResult = scanResult; 10365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 10465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 10565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public String getName() { 10665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mName; 10765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 10865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 10965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int getIconResource() { 11065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mIconResource; 11165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 11265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 11365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int getIconLevel() { 11465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mIconLevel; 11565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 11665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 11765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane boolean hasIconLevel() { 11865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mHasIconLevel; 11965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 12165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ScanResult getScanResult() { 12265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mScanResult; 12365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 12565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 12665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public String toString() { 12765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mName; 12865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 13065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static Parcelable.Creator<ListItem> CREATOR = new Parcelable.Creator<ListItem>() { 13165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 13265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 13365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public ListItem createFromParcel(Parcel source) { 13465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ScanResult scanResult = (ScanResult) source.readParcelable( 13565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ScanResult.class.getClassLoader()); 13665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (scanResult == null) { 13765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return new ListItem(source.readString(), source.readInt()); 13865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 13965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return new ListItem(scanResult); 14065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 14165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 14265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 14365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 14465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public ListItem[] newArray(int size) { 14565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return new ListItem[size]; 14665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 14765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane }; 14865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 14965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 15065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public int describeContents() { 15165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return 0; 15265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 15365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 15465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 15565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void writeToParcel(Parcel dest, int flags) { 15665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeParcelable(mScanResult, flags); 15765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mScanResult == null) { 15865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeString(mName); 15965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeInt(mIconResource); 16065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 16165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 16265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 16365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 16465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public boolean equals(Object o) { 16565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (o instanceof ListItem) { 16665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ListItem li = (ListItem) o; 16765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mScanResult == null && li.mScanResult == null) { 16865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mName.equals(li.mName); 16965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 17065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return (mScanResult != null && li.mScanResult != null && mName.equals(li.mName) && 17165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane WifiSecurity.getSecurity(mScanResult) 17265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane == WifiSecurity.getSecurity(li.mScanResult)); 17365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 17465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return false; 17565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 17665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 17765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 17865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public interface Listener { 17965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane void onListSelectionComplete(ListItem listItem); 18065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane void onListFocusChanged(ListItem listItem); 18165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 18265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 18365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String EXTRA_TITLE = "title"; 18465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String EXTRA_DESCRIPTION = "description"; 18565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String EXTRA_LIST_ELEMENTS = "list_elements"; 18665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String EXTRA_LAST_SELECTION = "last_selection"; 18765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 18865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static SelectFromListWizardFragment newInstance(String title, String description, 18965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ArrayList<ListItem> listElements, ListItem lastSelection) { 19065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane SelectFromListWizardFragment fragment = new SelectFromListWizardFragment(); 19165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Bundle args = new Bundle(); 19265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane args.putString(EXTRA_TITLE, title); 19365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane args.putString(EXTRA_DESCRIPTION, description); 19465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane args.putParcelableArrayList(EXTRA_LIST_ELEMENTS, listElements); 19565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane args.putParcelable(EXTRA_LAST_SELECTION, lastSelection); 19665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane fragment.setArguments(args); 19765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return fragment; 19865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 19965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 20065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private Handler mHandler; 20165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private View mMainView; 20265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private ScrollArrayAdapter<ListItem> mAdapter; 20365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private ScrollAdapterView mScrollAdapterView; 20465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private ArrayList<ListItem> mListItems; 20565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private ListItem mLastSelected; 20665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 20765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void update(ArrayList<ListItem> listElements) { 20865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ListItem lastSelection = mLastSelected; 20965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mListItems = listElements; 21065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAdapter.clear(); 21165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAdapter.addAll(listElements); 21265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (lastSelection != null) { 21365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane for (int i = 0, size = listElements.size(); i < size; i++) { 21465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (lastSelection.equals(listElements.get(i))) { 21565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (DEBUG) { 21665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Log.d(TAG, "Found " + lastSelection.getName() + " with ssid " 21765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane + (mLastSelected.getScanResult() == null ? null 21865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane : mLastSelected.getScanResult().SSID) 21965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane + " and bssid " + (mLastSelected.getScanResult() == null ? null 22065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane : mLastSelected.getScanResult().BSSID)); 22165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 22265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mScrollAdapterView.setSelection(i); 22365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 22465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 22565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 22665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 22765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 22865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 22965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 23065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle) { 23165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mHandler = new Handler(); 23265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mMainView = inflater.inflate(R.layout.account_content_area, container, false); 2336316b89e65828d537da309851529d1295efd5730Tony Mantler 2346316b89e65828d537da309851529d1295efd5730Tony Mantler final ViewGroup descriptionArea = (ViewGroup) mMainView.findViewById(R.id.description); 2356316b89e65828d537da309851529d1295efd5730Tony Mantler final View content = inflater.inflate(R.layout.wifi_content, descriptionArea, false); 2366316b89e65828d537da309851529d1295efd5730Tony Mantler descriptionArea.addView(content); 2376316b89e65828d537da309851529d1295efd5730Tony Mantler 2386316b89e65828d537da309851529d1295efd5730Tony Mantler final ViewGroup actionArea = (ViewGroup) mMainView.findViewById(R.id.action); 23965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mScrollAdapterView = (ScrollAdapterView) inflater.inflate( 2406316b89e65828d537da309851529d1295efd5730Tony Mantler R.layout.setup_scroll_adapter_view, actionArea, false); 2416316b89e65828d537da309851529d1295efd5730Tony Mantler actionArea.addView(mScrollAdapterView); 24265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 24365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane TextView titleText = (TextView) content.findViewById(R.id.title_text); 24465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane TextView descriptionText = (TextView) content.findViewById(R.id.description_text); 24565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 24665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Bundle args = getArguments(); 24765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane String title = args.getString(EXTRA_TITLE); 24865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane String description = args.getString(EXTRA_DESCRIPTION); 24965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mListItems = args.getParcelableArrayList(EXTRA_LIST_ELEMENTS); 25065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ListItem lastSelection = args.getParcelable(EXTRA_LAST_SELECTION); 25165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 25265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAdapter = new ScrollArrayAdapter<ListItem>(getActivity(), R.layout.setup_list_item, 25365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane R.id.list_item_text, mListItems) { 25465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 25565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public View getView(int position, View convertView, ViewGroup parent) { 25665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane View v = super.getView(position, convertView, parent); 25765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ListItem item = getItem(position); 25865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane FrameLayout iconHolder = (FrameLayout) v.findViewById(R.id.list_item_icon); 25965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane iconHolder.removeAllViews(); 26065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Activity a = getActivity(); 26165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (a != null) { 26265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ImageView icon = new ImageView(a); 26365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane icon.setImageResource(item.getIconResource()); 26465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (item.hasIconLevel()) { 26565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane icon.setImageLevel(item.getIconLevel()); 26665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 26765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane iconHolder.addView(icon); 26865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 26965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return v; 27065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 27165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane }; 27265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mScrollAdapterView.setAdapter(mAdapter); 27365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 27465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane boolean forceFocusable = AccessibilityHelper.forceFocusableViews(getActivity()); 27565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (title != null) { 27665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane titleText.setText(title); 27765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane titleText.setVisibility(View.VISIBLE); 27865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (forceFocusable) { 27965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane titleText.setFocusable(true); 28065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane titleText.setFocusableInTouchMode(true); 28165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 28265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 28365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane titleText.setVisibility(View.GONE); 28465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 28565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 28665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (description != null) { 28765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane descriptionText.setText(description); 28865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane descriptionText.setVisibility(View.VISIBLE); 28965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (forceFocusable) { 29065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane descriptionText.setFocusable(true); 29165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane descriptionText.setFocusableInTouchMode(true); 29265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 29365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 29465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane descriptionText.setVisibility(View.GONE); 29565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 29665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 29765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (lastSelection != null) { 29865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane for (int i = 0, size = mListItems.size(); i < size; i++) { 29965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (lastSelection.equals(mListItems.get(i))) { 30065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mScrollAdapterView.setSelection(i); 30165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 30265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 30365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 30465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 30565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 30665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mScrollAdapterView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 30765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 30865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onItemClick(AdapterView<?> pare, View view, int position, long id) { 30965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Activity a = getActivity(); 31065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (a instanceof Listener) { 31165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ((Listener) a).onListSelectionComplete(mListItems.get(position)); 31265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 31365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 31465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane }); 31565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 31665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mScrollAdapterView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 31765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 31865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { 31965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mLastSelected = mListItems.get(position); 32065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (DEBUG) { 32165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Log.d(TAG, "Scrolled to " + mLastSelected.getName() + " with ssid " 32265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane + (mLastSelected.getScanResult() == null ? null 32365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane : mLastSelected.getScanResult().SSID) + " and bssid " 32465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane + (mLastSelected.getScanResult() == null ? null 32565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane : mLastSelected.getScanResult().BSSID)); 32665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 32765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Activity a = getActivity(); 32865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (a instanceof Listener) { 32965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ((Listener) a).onListFocusChanged(mLastSelected); 33065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 33165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 33265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 33365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 33465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onNothingSelected(AdapterView<?> parent) { 33565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 33665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 33765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane }); 33865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 33965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mMainView; 34065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 34165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 34265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 34365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onResume() { 34465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane super.onResume(); 34565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mHandler.post(new Runnable() { 34665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 34765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void run() { 34865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane InputMethodManager inputMethodManager = (InputMethodManager) getActivity() 34965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .getSystemService(Context.INPUT_METHOD_SERVICE); 35065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane inputMethodManager.hideSoftInputFromWindow( 35165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mMainView.getApplicationWindowToken(), 0); 35265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 35365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane }); 35465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 35565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane} 356