use of com.android.settingslib.wifi.LongPressWifiEntryPreference in project android_packages_apps_Settings by omnirom.
the class WifiSettings method updateWifiEntryPreferences.
private void updateWifiEntryPreferences() {
// in case state has changed
if (mWifiPickerTracker.getWifiState() != WifiManager.WIFI_STATE_ENABLED) {
return;
}
boolean hasAvailableWifiEntries = false;
mStatusMessagePreference.setVisible(false);
mWifiEntryPreferenceCategory.setVisible(true);
final WifiEntry connectedEntry = mWifiPickerTracker.getConnectedWifiEntry();
mConnectedWifiEntryPreferenceCategory.setVisible(connectedEntry != null);
if (connectedEntry != null) {
final LongPressWifiEntryPreference connectedPref = mConnectedWifiEntryPreferenceCategory.findPreference(connectedEntry.getKey());
if (connectedPref == null || connectedPref.getWifiEntry() != connectedEntry) {
mConnectedWifiEntryPreferenceCategory.removeAll();
final ConnectedWifiEntryPreference pref = new ConnectedWifiEntryPreference(getPrefContext(), connectedEntry, this);
pref.setKey(connectedEntry.getKey());
pref.refresh();
mConnectedWifiEntryPreferenceCategory.addPreference(pref);
pref.setOnPreferenceClickListener(preference -> {
if (connectedEntry.canSignIn()) {
connectedEntry.signIn(null);
} else {
launchNetworkDetailsFragment(pref);
}
return true;
});
pref.setOnGearClickListener(preference -> {
launchNetworkDetailsFragment(pref);
});
if (mClickedConnect) {
mClickedConnect = false;
scrollToPreference(mConnectedWifiEntryPreferenceCategory);
}
}
} else {
mConnectedWifiEntryPreferenceCategory.removeAll();
}
int index = 0;
cacheRemoveAllPrefs(mWifiEntryPreferenceCategory);
List<WifiEntry> wifiEntries = mWifiPickerTracker.getWifiEntries();
for (WifiEntry wifiEntry : wifiEntries) {
hasAvailableWifiEntries = true;
String key = wifiEntry.getKey();
LongPressWifiEntryPreference pref = (LongPressWifiEntryPreference) getCachedPreference(key);
if (pref != null) {
if (pref.getWifiEntry() == wifiEntry) {
pref.setOrder(index++);
continue;
} else {
// Create a new preference if the underlying WifiEntry object has changed
removePreference(key);
}
}
pref = createLongPressWifiEntryPreference(wifiEntry);
pref.setKey(wifiEntry.getKey());
pref.setOrder(index++);
pref.refresh();
if (wifiEntry.getHelpUriString() != null) {
pref.setOnButtonClickListener(preference -> {
openSubscriptionHelpPage(wifiEntry);
});
}
mWifiEntryPreferenceCategory.addPreference(pref);
}
removeCachedPrefs(mWifiEntryPreferenceCategory);
if (!hasAvailableWifiEntries) {
setProgressBarVisible(true);
Preference pref = new Preference(getPrefContext());
pref.setSelectable(false);
pref.setSummary(R.string.wifi_empty_list_wifi_on);
pref.setOrder(index++);
pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
mWifiEntryPreferenceCategory.addPreference(pref);
} else {
// Continuing showing progress bar for an additional delay to overlap with animation
getView().postDelayed(mHideProgressBarRunnable, 1700);
}
mAddWifiNetworkPreference.setOrder(index++);
mWifiEntryPreferenceCategory.addPreference(mAddWifiNetworkPreference);
setAdditionalSettingsSummaries();
}
use of com.android.settingslib.wifi.LongPressWifiEntryPreference in project android_packages_apps_Settings by omnirom.
the class NetworkProviderSettings method onPreferenceTreeClick.
@Override
public boolean onPreferenceTreeClick(Preference preference) {
// If the preference has a fragment set, open that
if (preference.getFragment() != null) {
preference.setOnPreferenceClickListener(null);
return super.onPreferenceTreeClick(preference);
}
if (preference instanceof LongPressWifiEntryPreference) {
final WifiEntry selectedEntry = ((LongPressWifiEntryPreference) preference).getWifiEntry();
if (selectedEntry.shouldEditBeforeConnect()) {
launchConfigNewNetworkFragment(selectedEntry);
return true;
}
connect(selectedEntry, true, /* editIfNoConfig */
true);
} else if (preference == mAddWifiNetworkPreference) {
onAddNetworkPressed();
} else {
return super.onPreferenceTreeClick(preference);
}
return true;
}
use of com.android.settingslib.wifi.LongPressWifiEntryPreference in project android_packages_apps_Settings by omnirom.
the class NetworkProviderSettings method updateWifiEntryPreferences.
protected void updateWifiEntryPreferences() {
// bypass the update if the activity and the view are not ready, or it's restricted UI.
if (getActivity() == null || getView() == null || mIsRestricted) {
return;
}
// in case state has changed
if (mWifiPickerTracker.getWifiState() != WifiManager.WIFI_STATE_ENABLED) {
return;
}
boolean hasAvailableWifiEntries = false;
mWifiEntryPreferenceCategory.setVisible(true);
final WifiEntry connectedEntry = mWifiPickerTracker.getConnectedWifiEntry();
PreferenceCategory connectedWifiPreferenceCategory = getConnectedWifiPreferenceCategory();
connectedWifiPreferenceCategory.setVisible(connectedEntry != null);
if (connectedEntry != null) {
final LongPressWifiEntryPreference connectedPref = connectedWifiPreferenceCategory.findPreference(connectedEntry.getKey());
if (connectedPref == null || connectedPref.getWifiEntry() != connectedEntry) {
connectedWifiPreferenceCategory.removeAll();
final ConnectedWifiEntryPreference pref = createConnectedWifiEntryPreference(connectedEntry);
pref.setKey(connectedEntry.getKey());
pref.refresh();
connectedWifiPreferenceCategory.addPreference(pref);
pref.setOnPreferenceClickListener(preference -> {
if (connectedEntry.canSignIn()) {
connectedEntry.signIn(null);
} else {
launchNetworkDetailsFragment(pref);
}
return true;
});
pref.setOnGearClickListener(preference -> {
launchNetworkDetailsFragment(pref);
});
if (mClickedConnect) {
mClickedConnect = false;
scrollToPreference(connectedWifiPreferenceCategory);
}
}
} else {
connectedWifiPreferenceCategory.removeAll();
}
int index = 0;
cacheRemoveAllPrefs(mWifiEntryPreferenceCategory);
List<WifiEntry> wifiEntries = mWifiPickerTracker.getWifiEntries();
for (WifiEntry wifiEntry : wifiEntries) {
hasAvailableWifiEntries = true;
String key = wifiEntry.getKey();
LongPressWifiEntryPreference pref = (LongPressWifiEntryPreference) getCachedPreference(key);
if (pref != null) {
if (pref.getWifiEntry() == wifiEntry) {
pref.setOrder(index++);
continue;
} else {
// Create a new preference if the underlying WifiEntry object has changed
removePreference(key);
}
}
pref = createLongPressWifiEntryPreference(wifiEntry);
pref.setKey(wifiEntry.getKey());
pref.setOrder(index++);
pref.refresh();
if (wifiEntry.getHelpUriString() != null) {
pref.setOnButtonClickListener(preference -> {
openSubscriptionHelpPage(wifiEntry);
});
}
mWifiEntryPreferenceCategory.addPreference(pref);
}
removeCachedPrefs(mWifiEntryPreferenceCategory);
if (!hasAvailableWifiEntries) {
setProgressBarVisible(true);
Preference pref = new Preference(getPrefContext());
pref.setSelectable(false);
pref.setSummary(R.string.wifi_empty_list_wifi_on);
pref.setOrder(index++);
pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
mWifiEntryPreferenceCategory.addPreference(pref);
} else {
// Continuing showing progress bar for an additional delay to overlap with animation
getView().postDelayed(mHideProgressBarRunnable, 1700);
}
mAddWifiNetworkPreference.setOrder(index++);
mWifiEntryPreferenceCategory.addPreference(mAddWifiNetworkPreference);
setAdditionalSettingsSummaries();
}
use of com.android.settingslib.wifi.LongPressWifiEntryPreference in project android_packages_apps_Settings by omnirom.
the class NetworkProviderSettings method onCreateContextMenu.
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo info) {
Preference preference = (Preference) view.getTag();
if (!(preference instanceof LongPressWifiEntryPreference)) {
// Do nothing.
return;
}
// Cache the WifiEntry for onContextItemSelected. Don't use it in other methods.
mSelectedWifiEntry = ((LongPressWifiEntryPreference) preference).getWifiEntry();
menu.setHeaderTitle(mSelectedWifiEntry.getTitle());
if (mSelectedWifiEntry.canConnect()) {
menu.add(Menu.NONE, MENU_ID_CONNECT, 0, /* order */
R.string.wifi_connect);
}
if (mSelectedWifiEntry.canDisconnect()) {
menu.add(Menu.NONE, MENU_ID_SHARE, 0, /* order */
R.string.share);
menu.add(Menu.NONE, MENU_ID_DISCONNECT, 1, /* order */
R.string.wifi_disconnect_button_text);
}
// could only be disconnected and be put in blocklists so it won't be used again.
if (canForgetNetwork()) {
menu.add(Menu.NONE, MENU_ID_FORGET, 0, /* order */
R.string.forget);
}
WifiConfiguration config = mSelectedWifiEntry.getWifiConfiguration();
// Some configs are ineditable
if (WifiUtils.isNetworkLockedDown(getActivity(), config)) {
return;
}
if (mSelectedWifiEntry.isSaved() && mSelectedWifiEntry.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED) {
menu.add(Menu.NONE, MENU_ID_MODIFY, 0, /* order */
R.string.wifi_modify);
}
}
use of com.android.settingslib.wifi.LongPressWifiEntryPreference in project android_packages_apps_Settings by omnirom.
the class WifiSettingsTest method onCreateContextMenu_shouldHaveForgetAndDisconnectMenuForConnectedWifiEntry.
@Test
public void onCreateContextMenu_shouldHaveForgetAndDisconnectMenuForConnectedWifiEntry() {
final FragmentActivity activity = mock(FragmentActivity.class);
when(activity.getApplicationContext()).thenReturn(mContext);
when(mWifiSettings.getActivity()).thenReturn(activity);
final WifiEntry wifiEntry = mock(WifiEntry.class);
when(wifiEntry.canDisconnect()).thenReturn(true);
when(wifiEntry.canForget()).thenReturn(true);
when(wifiEntry.isSaved()).thenReturn(true);
when(wifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
final LongPressWifiEntryPreference connectedWifiEntryPreference = mWifiSettings.createLongPressWifiEntryPreference(wifiEntry);
final View view = mock(View.class);
when(view.getTag()).thenReturn(connectedWifiEntryPreference);
final ContextMenu menu = mock(ContextMenu.class);
mWifiSettings.onCreateContextMenu(menu, view, null);
verify(menu).add(anyInt(), eq(WifiSettings.MENU_ID_FORGET), anyInt(), anyInt());
verify(menu).add(anyInt(), eq(WifiSettings.MENU_ID_DISCONNECT), anyInt(), anyInt());
}
Aggregations