One updateSummary method called by all VPN prefs
Having multiple methods means inevitably when new features are added to
the preferences, the right calls aren't made so information on the
screen lags between updates.
Bug: 28257641
Change-Id: I336aeefd5941ccf808dc9070427209a7d2530032
(cherry picked from commit 903843e6f9
)
This commit is contained in:
@@ -32,9 +32,8 @@ import com.android.internal.net.VpnConfig;
|
|||||||
*/
|
*/
|
||||||
public class AppPreference extends ManageablePreference {
|
public class AppPreference extends ManageablePreference {
|
||||||
public static final int STATE_CONNECTED = LegacyVpnInfo.STATE_CONNECTED;
|
public static final int STATE_CONNECTED = LegacyVpnInfo.STATE_CONNECTED;
|
||||||
public static final int STATE_DISCONNECTED = LegacyVpnInfo.STATE_DISCONNECTED;
|
public static final int STATE_DISCONNECTED = STATE_NONE;
|
||||||
|
|
||||||
private int mState = STATE_DISCONNECTED;
|
|
||||||
private String mPackageName;
|
private String mPackageName;
|
||||||
private String mName;
|
private String mName;
|
||||||
|
|
||||||
@@ -70,22 +69,11 @@ public class AppPreference extends ManageablePreference {
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getState() {
|
|
||||||
return mState;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setState(int state) {
|
|
||||||
mState = state;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void update() {
|
private void update() {
|
||||||
if (mPackageName == null || mUserId == UserHandle.USER_NULL) {
|
if (mPackageName == null || mUserId == UserHandle.USER_NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSummary(getSummaryString(mState == STATE_DISCONNECTED ? STATE_NONE : mState));
|
|
||||||
|
|
||||||
mName = mPackageName;
|
mName = mPackageName;
|
||||||
Drawable icon = null;
|
Drawable icon = null;
|
||||||
|
|
||||||
@@ -113,6 +101,7 @@ public class AppPreference extends ManageablePreference {
|
|||||||
}
|
}
|
||||||
setTitle(mName);
|
setTitle(mName);
|
||||||
setIcon(icon);
|
setIcon(icon);
|
||||||
|
updateSummary();
|
||||||
|
|
||||||
notifyHierarchyChanged();
|
notifyHierarchyChanged();
|
||||||
}
|
}
|
||||||
|
@@ -31,9 +31,6 @@ import static com.android.internal.net.LegacyVpnInfo.STATE_CONNECTED;
|
|||||||
public class LegacyVpnPreference extends ManageablePreference {
|
public class LegacyVpnPreference extends ManageablePreference {
|
||||||
private VpnProfile mProfile;
|
private VpnProfile mProfile;
|
||||||
|
|
||||||
/** One of the STATE_* fields from LegacyVpnInfo, or STATE_NONE */
|
|
||||||
private int mState = STATE_NONE;
|
|
||||||
|
|
||||||
LegacyVpnPreference(Context context) {
|
LegacyVpnPreference(Context context) {
|
||||||
super(context, null /* attrs */);
|
super(context, null /* attrs */);
|
||||||
}
|
}
|
||||||
@@ -44,16 +41,6 @@ public class LegacyVpnPreference extends ManageablePreference {
|
|||||||
|
|
||||||
public void setProfile(VpnProfile profile) {
|
public void setProfile(VpnProfile profile) {
|
||||||
mProfile = profile;
|
mProfile = profile;
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setState(int state) {
|
|
||||||
mState = state;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void update() {
|
|
||||||
setSummary(getSummaryString(mState));
|
|
||||||
if (mProfile != null) {
|
if (mProfile != null) {
|
||||||
setIcon(R.mipmap.ic_launcher_settings);
|
setIcon(R.mipmap.ic_launcher_settings);
|
||||||
setTitle(mProfile.name);
|
setTitle(mProfile.name);
|
||||||
@@ -93,5 +80,4 @@ public class LegacyVpnPreference extends ManageablePreference {
|
|||||||
}
|
}
|
||||||
super.onClick(v);
|
super.onClick(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -34,6 +34,7 @@ public abstract class ManageablePreference extends GearPreference {
|
|||||||
public static int STATE_NONE = -1;
|
public static int STATE_NONE = -1;
|
||||||
|
|
||||||
boolean mIsAlwaysOn = false;
|
boolean mIsAlwaysOn = false;
|
||||||
|
int mState = STATE_NONE;
|
||||||
int mUserId;
|
int mUserId;
|
||||||
|
|
||||||
public ManageablePreference(Context context, AttributeSet attrs) {
|
public ManageablePreference(Context context, AttributeSet attrs) {
|
||||||
@@ -56,24 +57,35 @@ public abstract class ManageablePreference extends GearPreference {
|
|||||||
return mIsAlwaysOn;
|
return mIsAlwaysOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getState() {
|
||||||
|
return mState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setState(int state) {
|
||||||
|
mState = state;
|
||||||
|
updateSummary();
|
||||||
|
}
|
||||||
|
|
||||||
public void setAlwaysOn(boolean isEnabled) {
|
public void setAlwaysOn(boolean isEnabled) {
|
||||||
mIsAlwaysOn = isEnabled;
|
mIsAlwaysOn = isEnabled;
|
||||||
|
updateSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* State is not shown for {@code STATE_NONE}
|
* Update the preference summary string (see {@see Preference#setSummary}) with a string
|
||||||
|
* reflecting connection status and always-on setting.
|
||||||
*
|
*
|
||||||
* @return summary string showing current connection state and always-on-vpn state
|
* State is not shown for {@code STATE_NONE}.
|
||||||
*/
|
*/
|
||||||
protected String getSummaryString(int state) {
|
protected void updateSummary() {
|
||||||
final Resources res = getContext().getResources();
|
final Resources res = getContext().getResources();
|
||||||
final String[] states = res.getStringArray(R.array.vpn_states);
|
final String[] states = res.getStringArray(R.array.vpn_states);
|
||||||
String summary = state == STATE_NONE ? "" : states[state];
|
String summary = (mState == STATE_NONE ? "" : states[mState]);
|
||||||
if (mIsAlwaysOn) {
|
if (mIsAlwaysOn) {
|
||||||
final String alwaysOnString = res.getString(R.string.vpn_always_on_active);
|
final String alwaysOnString = res.getString(R.string.vpn_always_on_active);
|
||||||
summary = TextUtils.isEmpty(summary) ? alwaysOnString : res.getString(
|
summary = TextUtils.isEmpty(summary) ? alwaysOnString : res.getString(
|
||||||
R.string.join_two_unrelated_items, summary, alwaysOnString);
|
R.string.join_two_unrelated_items, summary, alwaysOnString);
|
||||||
}
|
}
|
||||||
return summary;
|
setSummary(summary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user