3232 */
3333public final class WifiDisplayStatus implements Parcelable {
3434 private final boolean mEnabled ;
35- private final WifiDisplay mConnectedDisplay ;
35+ private final int mScanState ;
36+ private final int mActiveDisplayState ;
37+ private final WifiDisplay mActiveDisplay ;
3638 private final WifiDisplay [] mKnownDisplays ;
37- private final boolean mScanInProgress ;
38- private final boolean mConnectionInProgress ;
39+
40+ public static final int SCAN_STATE_NOT_SCANNING = 0 ;
41+ public static final int SCAN_STATE_SCANNING = 1 ;
42+
43+ public static final int DISPLAY_STATE_NOT_CONNECTED = 0 ;
44+ public static final int DISPLAY_STATE_CONNECTING = 1 ;
45+ public static final int DISPLAY_STATE_CONNECTED = 2 ;
3946
4047 public static final Creator <WifiDisplayStatus > CREATOR = new Creator <WifiDisplayStatus >() {
4148 public WifiDisplayStatus createFromParcel (Parcel in ) {
4249 boolean enabled = (in .readInt () != 0 );
50+ int scanState = in .readInt ();
51+ int activeDisplayState = in .readInt ();
4352
44- WifiDisplay connectedDisplay = null ;
53+ WifiDisplay activeDisplay = null ;
4554 if (in .readInt () != 0 ) {
46- connectedDisplay = WifiDisplay .CREATOR .createFromParcel (in );
55+ activeDisplay = WifiDisplay .CREATOR .createFromParcel (in );
4756 }
4857
4958 WifiDisplay [] knownDisplays = WifiDisplay .CREATOR .newArray (in .readInt ());
5059 for (int i = 0 ; i < knownDisplays .length ; i ++) {
5160 knownDisplays [i ] = WifiDisplay .CREATOR .createFromParcel (in );
5261 }
5362
54- boolean scanInProgress = (in .readInt () != 0 );
55- boolean connectionInProgress = (in .readInt () != 0 );
56-
57- return new WifiDisplayStatus (enabled , connectedDisplay , knownDisplays ,
58- scanInProgress , connectionInProgress );
63+ return new WifiDisplayStatus (enabled , scanState , activeDisplayState ,
64+ activeDisplay , knownDisplays );
5965 }
6066
6167 public WifiDisplayStatus [] newArray (int size ) {
@@ -64,21 +70,21 @@ public WifiDisplayStatus[] newArray(int size) {
6470 };
6571
6672 public WifiDisplayStatus () {
67- this (false , null , WifiDisplay .EMPTY_ARRAY , false , false );
73+ this (false , SCAN_STATE_NOT_SCANNING , DISPLAY_STATE_NOT_CONNECTED ,
74+ null , WifiDisplay .EMPTY_ARRAY );
6875 }
6976
70- public WifiDisplayStatus (boolean enabled ,
71- WifiDisplay connectedDisplay , WifiDisplay [] knownDisplays ,
72- boolean scanInProgress , boolean connectionInProgress ) {
77+ public WifiDisplayStatus (boolean enabled , int scanState , int activeDisplayState ,
78+ WifiDisplay activeDisplay , WifiDisplay [] knownDisplays ) {
7379 if (knownDisplays == null ) {
7480 throw new IllegalArgumentException ("knownDisplays must not be null" );
7581 }
7682
7783 mEnabled = enabled ;
78- mConnectedDisplay = connectedDisplay ;
84+ mScanState = scanState ;
85+ mActiveDisplayState = activeDisplayState ;
86+ mActiveDisplay = activeDisplay ;
7987 mKnownDisplays = knownDisplays ;
80- mScanInProgress = scanInProgress ;
81- mConnectionInProgress = connectionInProgress ;
8288 }
8389
8490 /**
@@ -94,40 +100,48 @@ public boolean isEnabled() {
94100 }
95101
96102 /**
97- * Gets the currently connected Wifi display or null if none.
103+ * Returns the current state of the Wifi display scan.
104+ *
105+ * @return One of: {@link #SCAN_STATE_NOT_SCANNING} or {@link #SCAN_STATE_SCANNING}.
98106 */
99- public WifiDisplay getConnectedDisplay () {
100- return mConnectedDisplay ;
107+ public int getScanState () {
108+ return mScanState ;
101109 }
102110
103111 /**
104- * Gets the list of all known Wifi displays, never null.
112+ * Get the state of the currently active display.
113+ *
114+ * @return One of: {@link #DISPLAY_STATE_NOT_CONNECTED}, {@link #DISPLAY_STATE_CONNECTING},
115+ * or {@link #DISPLAY_STATE_CONNECTED}.
105116 */
106- public WifiDisplay [] getKnownDisplays () {
107- return mKnownDisplays ;
117+ public int getActiveDisplayState () {
118+ return mActiveDisplayState ;
108119 }
109120
110121 /**
111- * Returns true if there is currently a Wifi display scan in progress.
122+ * Gets the Wifi display that is currently active. It may be connecting or
123+ * connected.
112124 */
113- public boolean isScanInProgress () {
114- return mScanInProgress ;
125+ public WifiDisplay getActiveDisplay () {
126+ return mActiveDisplay ;
115127 }
116128
117129 /**
118- * Returns true if there is currently a Wifi display connection in progress .
130+ * Gets the list of all known Wifi displays, never null .
119131 */
120- public boolean isConnectionInProgress () {
121- return mConnectionInProgress ;
132+ public WifiDisplay [] getKnownDisplays () {
133+ return mKnownDisplays ;
122134 }
123135
124136 @ Override
125137 public void writeToParcel (Parcel dest , int flags ) {
126138 dest .writeInt (mEnabled ? 1 : 0 );
139+ dest .writeInt (mScanState );
140+ dest .writeInt (mActiveDisplayState );
127141
128- if (mConnectedDisplay != null ) {
142+ if (mActiveDisplay != null ) {
129143 dest .writeInt (1 );
130- mConnectedDisplay .writeToParcel (dest , flags );
144+ mActiveDisplay .writeToParcel (dest , flags );
131145 } else {
132146 dest .writeInt (0 );
133147 }
@@ -136,9 +150,6 @@ public void writeToParcel(Parcel dest, int flags) {
136150 for (WifiDisplay display : mKnownDisplays ) {
137151 display .writeToParcel (dest , flags );
138152 }
139-
140- dest .writeInt (mScanInProgress ? 1 : 0 );
141- dest .writeInt (mConnectionInProgress ? 1 : 0 );
142153 }
143154
144155 @ Override
@@ -150,10 +161,10 @@ public int describeContents() {
150161 @ Override
151162 public String toString () {
152163 return "WifiDisplayStatus{enabled=" + mEnabled
153- + ", connectedDisplay=" + mConnectedDisplay
164+ + ", scanState=" + mScanState
165+ + ", activeDisplayState=" + mActiveDisplayState
166+ + ", activeDisplay=" + mActiveDisplay
154167 + ", knownDisplays=" + Arrays .toString (mKnownDisplays )
155- + ", scanInProgress=" + mScanInProgress
156- + ", connectionInProgress=" + mConnectionInProgress
157168 + "}" ;
158169 }
159170}
0 commit comments