am 38ce5194
: Merge "Enable to delete a stored persistent group from p2p settings."
* commit '38ce5194e89b83697466abe2994016507109ec54': Enable to delete a stored persistent group from p2p settings.
This commit is contained in:
committed by
Android Git Automerger
commit
300457bad2
@@ -1433,6 +1433,8 @@
|
||||
<string name="wifi_p2p_menu_rename">Rename device</string>
|
||||
<!-- Title for available p2p devices -->
|
||||
<string name="wifi_p2p_peer_devices">Peer devices</string>
|
||||
<!-- Title for remembered p2p groups -->
|
||||
<string name="wifi_p2p_remembered_groups">Remembered groups</string>
|
||||
<!-- Toast text for a failed connection initiation -->
|
||||
<string name="wifi_p2p_failed_connect_message">Couldn\'t connect.</string>
|
||||
<!-- Message text for failure to rename -->
|
||||
@@ -1447,6 +1449,10 @@
|
||||
<string name="wifi_p2p_cancel_connect_title">Cancel invitation?</string>
|
||||
<!-- Message text for disconnection from one device-->
|
||||
<string name="wifi_p2p_cancel_connect_message">Do you want to cancel invitation to connect with <xliff:g id="peer_name">%1$s</xliff:g>?</string>
|
||||
<!-- Title for delete group dialog -->
|
||||
<string name="wifi_p2p_delete_group_title">Delete group?</string>
|
||||
<!-- Message text for remembered group deletion-->
|
||||
<string name="wifi_p2p_delete_group_message">Do you want to delete the group <xliff:g id="group_name">%1$s</xliff:g>?</string>
|
||||
|
||||
<!-- Wifi AP settings-->
|
||||
<!-- Label for wifi tether checkbox. Toggles Access Point on/off -->
|
||||
|
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.p2p;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.p2p.WifiP2pGroup;
|
||||
import android.preference.Preference;
|
||||
import android.view.View;
|
||||
|
||||
public class WifiP2pPersistentGroup extends Preference {
|
||||
|
||||
public WifiP2pGroup mGroup;
|
||||
|
||||
public WifiP2pPersistentGroup(Context context, WifiP2pGroup group) {
|
||||
super(context);
|
||||
mGroup = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindView(View view) {
|
||||
setTitle(mGroup.getNetworkName());
|
||||
super.onBindView(view);
|
||||
}
|
||||
|
||||
int getNetworkId() {
|
||||
return mGroup.getNetworkId();
|
||||
}
|
||||
|
||||
String getGroupName() {
|
||||
return mGroup.getNetworkName();
|
||||
}
|
||||
}
|
@@ -30,8 +30,12 @@ import android.net.NetworkInfo;
|
||||
import android.net.wifi.p2p.WifiP2pConfig;
|
||||
import android.net.wifi.p2p.WifiP2pDevice;
|
||||
import android.net.wifi.p2p.WifiP2pDeviceList;
|
||||
import android.net.wifi.p2p.WifiP2pGroup;
|
||||
import android.net.wifi.p2p.WifiP2pGroupList;
|
||||
import android.net.wifi.p2p.WifiP2pManager;
|
||||
import android.net.wifi.p2p.WifiP2pManager.GroupInfoListener;
|
||||
import android.net.wifi.p2p.WifiP2pManager.PeerListListener;
|
||||
import android.net.wifi.p2p.WifiP2pManager.PersistentGroupInfoListener;
|
||||
import android.net.wifi.WpsInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -62,7 +66,7 @@ import java.util.Collection;
|
||||
* Displays Wi-fi p2p settings UI
|
||||
*/
|
||||
public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
implements PeerListListener {
|
||||
implements PeerListListener, PersistentGroupInfoListener, GroupInfoListener {
|
||||
|
||||
private static final String TAG = "WifiP2pSettings";
|
||||
private static final boolean DBG = false;
|
||||
@@ -75,19 +79,24 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
private OnClickListener mRenameListener;
|
||||
private OnClickListener mDisconnectListener;
|
||||
private OnClickListener mCancelConnectListener;
|
||||
private OnClickListener mDeleteGroupListener;
|
||||
private WifiP2pPeer mSelectedWifiPeer;
|
||||
private WifiP2pPersistentGroup mSelectedGroup;
|
||||
private EditText mDeviceNameText;
|
||||
|
||||
private boolean mWifiP2pEnabled;
|
||||
private boolean mWifiP2pSearching;
|
||||
private int mConnectedDevices;
|
||||
private WifiP2pGroup mConnectedGroup;
|
||||
|
||||
private PreferenceGroup mPeersGroup;
|
||||
private PreferenceGroup mPersistentGroup;
|
||||
private Preference mThisDevicePref;
|
||||
|
||||
private static final int DIALOG_DISCONNECT = 1;
|
||||
private static final int DIALOG_CANCEL_CONNECT = 2;
|
||||
private static final int DIALOG_RENAME = 3;
|
||||
private static final int DIALOG_DELETE_GROUP = 4;
|
||||
|
||||
private static final String SAVE_DIALOG_PEER = "PEER_STATE";
|
||||
private static final String SAVE_DEVICE_NAME = "DEV_NAME";
|
||||
@@ -114,6 +123,9 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
if (mWifiP2pManager == null) return;
|
||||
NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(
|
||||
WifiP2pManager.EXTRA_NETWORK_INFO);
|
||||
if (mWifiP2pManager != null) {
|
||||
mWifiP2pManager.requestGroupInfo(mChannel, WifiP2pSettings.this);
|
||||
}
|
||||
if (networkInfo.isConnected()) {
|
||||
if (DBG) Log.d(TAG, "Connected");
|
||||
} else {
|
||||
@@ -134,6 +146,10 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
} else {
|
||||
updateSearchMenu(false);
|
||||
}
|
||||
} else if (WifiP2pManager.WIFI_P2P_PERSISTENT_GROUPS_CHANGED_ACTION.equals(action)) {
|
||||
if (mWifiP2pManager != null) {
|
||||
mWifiP2pManager.requestPersistentGroupInfo(mChannel, WifiP2pSettings.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -147,6 +163,7 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
|
||||
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
|
||||
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION);
|
||||
mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PERSISTENT_GROUPS_CHANGED_ACTION);
|
||||
|
||||
final Activity activity = getActivity();
|
||||
mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
|
||||
@@ -230,6 +247,27 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
};
|
||||
|
||||
//delete persistent group dialog listener
|
||||
mDeleteGroupListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
if (mWifiP2pManager != null) {
|
||||
mWifiP2pManager.deletePersistentGroup(mChannel,
|
||||
mSelectedGroup.getNetworkId(),
|
||||
new WifiP2pManager.ActionListener() {
|
||||
public void onSuccess() {
|
||||
if (DBG) Log.d(TAG, " delete group success");
|
||||
}
|
||||
public void onFailure(int reason) {
|
||||
if (DBG) Log.d(TAG, " delete group fail " + reason);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
@@ -242,6 +280,9 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
mPeersGroup = new PreferenceCategory(getActivity());
|
||||
mPeersGroup.setTitle(R.string.wifi_p2p_peer_devices);
|
||||
|
||||
mPersistentGroup = new PreferenceCategory(getActivity());
|
||||
mPersistentGroup.setTitle(R.string.wifi_p2p_remembered_groups);
|
||||
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
}
|
||||
|
||||
@@ -342,6 +383,9 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (preference instanceof WifiP2pPersistentGroup) {
|
||||
mSelectedGroup = (WifiP2pPersistentGroup) preference;
|
||||
showDialog(DIALOG_DELETE_GROUP);
|
||||
}
|
||||
return super.onPreferenceTreeClick(screen, preference);
|
||||
}
|
||||
@@ -396,6 +440,16 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
.setNegativeButton(getActivity().getString(R.string.dlg_cancel), null)
|
||||
.create();
|
||||
return dialog;
|
||||
} else if (id == DIALOG_DELETE_GROUP) {
|
||||
int stringId = R.string.wifi_p2p_delete_group_message;
|
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.wifi_p2p_delete_group_title)
|
||||
.setMessage(getActivity().getString(stringId, mSelectedGroup.getGroupName()))
|
||||
.setPositiveButton(getActivity().getString(R.string.dlg_ok), mDeleteGroupListener)
|
||||
.setNegativeButton(getActivity().getString(R.string.dlg_cancel), null)
|
||||
.create();
|
||||
return dialog;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -423,6 +477,21 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
if (DBG) Log.d(TAG, " mConnectedDevices " + mConnectedDevices);
|
||||
}
|
||||
|
||||
public void onPersistentGroupInfoAvailable(WifiP2pGroupList groups) {
|
||||
mPersistentGroup.removeAll();
|
||||
|
||||
for (WifiP2pGroup group: groups.getGroupList()) {
|
||||
if (DBG) Log.d(TAG, " group " + group);
|
||||
mPersistentGroup.addPreference(new WifiP2pPersistentGroup(getActivity(), group));
|
||||
}
|
||||
}
|
||||
|
||||
public void onGroupInfoAvailable(WifiP2pGroup group) {
|
||||
if (DBG) Log.d(TAG, " group " + group);
|
||||
mConnectedGroup = group;
|
||||
updateDevicePref();
|
||||
}
|
||||
|
||||
private void handleP2pStateChanged() {
|
||||
updateSearchMenu(false);
|
||||
if (mWifiP2pEnabled) {
|
||||
@@ -435,6 +504,9 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
mPeersGroup.setEnabled(true);
|
||||
preferenceScreen.addPreference(mPeersGroup);
|
||||
|
||||
mPersistentGroup.setEnabled(true);
|
||||
preferenceScreen.addPreference(mPersistentGroup);
|
||||
|
||||
/* Request latest set of peers */
|
||||
mWifiP2pManager.requestPeers(mChannel, WifiP2pSettings.this);
|
||||
}
|
||||
|
Reference in New Issue
Block a user