[Settings] Limit height of TextView when text too long
Adjust the layout through having ConstraintLayout for limiting the height of TextView. Bug: 205460459 Test: local Change-Id: Ic15af4c9be393a6855d78a5d9af086b099c9b689
This commit is contained in:
71
res/layout/vpn_app_management_preference.xml
Normal file
71
res/layout/vpn_app_management_preference.xml
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2023 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
|
||||||
|
-->
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||||
|
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||||
|
android:background="?android:attr/selectableItemBackground">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/icon_frame"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<androidx.preference.internal.PreferenceImageView
|
||||||
|
android:id="@android:id/icon"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:maxWidth="48dp"
|
||||||
|
app:maxHeight="48dp" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<TextView android:id="@android:id/title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:singleLine="true"
|
||||||
|
app:layout_constraintLeft_toRightOf="@android:id/icon_frame"
|
||||||
|
app:layout_constraintHeight="wrap_content_constrained"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:fadingEdge="horizontal" />
|
||||||
|
|
||||||
|
<TextView android:id="@android:id/summary"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toBottomOf="@android:id/title"
|
||||||
|
app:layout_constraintLeft_toLeftOf="@android:id/title"
|
||||||
|
app:layout_constraintHeight="wrap_content_constrained"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Preference should place its actual preference widget here. -->
|
||||||
|
<LinearLayout android:id="@android:id/widget_frame"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@@ -194,16 +194,6 @@
|
|||||||
<item name="android:textAppearance">@android:style/TextAppearance.DeviceDefault.Small</item>
|
<item name="android:textAppearance">@android:style/TextAppearance.DeviceDefault.Small</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="vpn_app_management_version_title">
|
|
||||||
<item name="android:textAppearance">?android:attr/textAppearanceListItem</item>
|
|
||||||
<item name="android:textColor">?android:attr/textColorPrimary</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="vpn_app_management_version_summary">
|
|
||||||
<item name="android:textAppearance">?android:attr/textAppearanceListItemSecondary</item>
|
|
||||||
<item name="android:textColor">?android:attr/textColorSecondary</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="TextAppearance" parent="android:TextAppearance.DeviceDefault"/>
|
<style name="TextAppearance" parent="android:TextAppearance.DeviceDefault"/>
|
||||||
|
|
||||||
<style name="TextAppearance.info_label">
|
<style name="TextAppearance.info_label">
|
||||||
|
@@ -71,4 +71,8 @@
|
|||||||
<item name="android:layout">@layout/setup_preference</item>
|
<item name="android:layout">@layout/setup_preference</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="VpnAppManagementPreferenceStyle" parent="@style/PreferenceFragment.Material">
|
||||||
|
<item name="layout">@layout/vpn_app_management_preference</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@@ -15,24 +15,15 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
xmlns:settings="http://schemas.android.com/apk/res-auto">
|
||||||
orderingFromXml="false"
|
|
||||||
>
|
|
||||||
|
|
||||||
<!-- To limit the size (in height) of version Preference displayed here,
|
|
||||||
maximum height of TextView need to be set programmingly.
|
|
||||||
Therefore, this Preference got removed from here and will be added
|
|
||||||
dynamically through source code.
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:order="0"
|
android:theme="@style/VpnAppManagementPreferenceStyle"
|
||||||
|
android:title="@string/vpn_version"
|
||||||
android:key="version"
|
android:key="version"
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
|
||||||
android:selectable="false"/>
|
android:selectable="false"/>
|
||||||
-->
|
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
android:order="10"
|
|
||||||
android:key="always_on_vpn"
|
android:key="always_on_vpn"
|
||||||
android:title="@string/vpn_menu_lockdown"
|
android:title="@string/vpn_menu_lockdown"
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
@@ -42,7 +33,6 @@
|
|||||||
settings:restrictedSwitchSummary="@string/disabled_by_admin_summary_text" />
|
settings:restrictedSwitchSummary="@string/disabled_by_admin_summary_text" />
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
android:order="20"
|
|
||||||
android:key="lockdown_vpn"
|
android:key="lockdown_vpn"
|
||||||
android:title="@string/vpn_require_connection"
|
android:title="@string/vpn_require_connection"
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
@@ -52,7 +42,6 @@
|
|||||||
settings:restrictedSwitchSummary="@string/disabled_by_admin_summary_text" />
|
settings:restrictedSwitchSummary="@string/disabled_by_admin_summary_text" />
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:order="30"
|
|
||||||
android:key="forget_vpn"
|
android:key="forget_vpn"
|
||||||
android:title="@string/vpn_forget_long"
|
android:title="@string/vpn_forget_long"
|
||||||
android:icon="@drawable/ic_delete"
|
android:icon="@drawable/ic_delete"
|
||||||
|
@@ -34,13 +34,11 @@ import android.os.UserHandle;
|
|||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceViewHolder;
|
|
||||||
|
|
||||||
import com.android.internal.net.VpnConfig;
|
import com.android.internal.net.VpnConfig;
|
||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
@@ -81,6 +79,7 @@ public class AppManagementFragment extends SettingsPreferenceFragment
|
|||||||
private String mVpnLabel;
|
private String mVpnLabel;
|
||||||
|
|
||||||
// UI preference
|
// UI preference
|
||||||
|
private Preference mPreferenceVersion;
|
||||||
private RestrictedSwitchPreference mPreferenceAlwaysOn;
|
private RestrictedSwitchPreference mPreferenceAlwaysOn;
|
||||||
private RestrictedSwitchPreference mPreferenceLockdown;
|
private RestrictedSwitchPreference mPreferenceLockdown;
|
||||||
private RestrictedPreference mPreferenceForget;
|
private RestrictedPreference mPreferenceForget;
|
||||||
@@ -126,6 +125,7 @@ public class AppManagementFragment extends SettingsPreferenceFragment
|
|||||||
mVpnManager = getContext().getSystemService(VpnManager.class);
|
mVpnManager = getContext().getSystemService(VpnManager.class);
|
||||||
mFeatureProvider = FeatureFactory.getFactory(getContext()).getAdvancedVpnFeatureProvider();
|
mFeatureProvider = FeatureFactory.getFactory(getContext()).getAdvancedVpnFeatureProvider();
|
||||||
|
|
||||||
|
mPreferenceVersion = findPreference(KEY_VERSION);
|
||||||
mPreferenceAlwaysOn = (RestrictedSwitchPreference) findPreference(KEY_ALWAYS_ON_VPN);
|
mPreferenceAlwaysOn = (RestrictedSwitchPreference) findPreference(KEY_ALWAYS_ON_VPN);
|
||||||
mPreferenceLockdown = (RestrictedSwitchPreference) findPreference(KEY_LOCKDOWN_VPN);
|
mPreferenceLockdown = (RestrictedSwitchPreference) findPreference(KEY_LOCKDOWN_VPN);
|
||||||
mPreferenceForget = (RestrictedPreference) findPreference(KEY_FORGET_VPN);
|
mPreferenceForget = (RestrictedPreference) findPreference(KEY_FORGET_VPN);
|
||||||
@@ -141,52 +141,8 @@ public class AppManagementFragment extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
boolean isInfoLoaded = loadInfo();
|
boolean isInfoLoaded = loadInfo();
|
||||||
if (isInfoLoaded) {
|
if (isInfoLoaded) {
|
||||||
|
mPreferenceVersion.setSummary(mPackageInfo.versionName);
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
Preference version = getPreferenceScreen().findPreference(KEY_VERSION);
|
|
||||||
if (version != null) {
|
|
||||||
// Version field has been added.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create version field at runtime, and set max height on the display area.
|
|
||||||
*
|
|
||||||
* When long length of text given within version field, a large text area
|
|
||||||
* might be created and inconvenient to the user (User need to scroll
|
|
||||||
* for a long time in order to get to the Preferences after this field.)
|
|
||||||
*/
|
|
||||||
version = new Preference(getPrefContext()) {
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
|
||||||
super.onBindViewHolder(holder);
|
|
||||||
|
|
||||||
TextView titleView =
|
|
||||||
(TextView) holder.findViewById(android.R.id.title);
|
|
||||||
if (titleView != null) {
|
|
||||||
titleView.setTextAppearance(R.style.vpn_app_management_version_title);
|
|
||||||
}
|
|
||||||
|
|
||||||
TextView summaryView =
|
|
||||||
(TextView) holder.findViewById(android.R.id.summary);
|
|
||||||
if (summaryView != null) {
|
|
||||||
summaryView.setTextAppearance(R.style.vpn_app_management_version_summary);
|
|
||||||
|
|
||||||
// Set max height in summary area.
|
|
||||||
int versionMaxHeight = getListView().getHeight();
|
|
||||||
summaryView.setMaxHeight(versionMaxHeight);
|
|
||||||
summaryView.setVerticalScrollBarEnabled(false);
|
|
||||||
summaryView.setHorizontallyScrolling(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
version.setOrder(0); // Set order to 0 in order to be placed
|
|
||||||
// in front of other Preference(s).
|
|
||||||
version.setKey(KEY_VERSION); // Set key to avoid from creating multi instance.
|
|
||||||
version.setTitle(R.string.vpn_version);
|
|
||||||
version.setSummary(mPackageInfo.versionName);
|
|
||||||
version.setSelectable(false);
|
|
||||||
getPreferenceScreen().addPreference(version);
|
|
||||||
} else {
|
} else {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,7 @@ import com.android.internal.net.LegacyVpnInfo;
|
|||||||
import com.android.internal.net.VpnConfig;
|
import com.android.internal.net.VpnConfig;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link androidx.preference.Preference} containing information about a VPN
|
* {@link androidx.preference.Preference} containing information about a VPN
|
||||||
@@ -42,7 +43,7 @@ public class AppPreference extends ManageablePreference {
|
|||||||
private final String mName;
|
private final String mName;
|
||||||
|
|
||||||
public AppPreference(Context context, int userId, String packageName) {
|
public AppPreference(Context context, int userId, String packageName) {
|
||||||
super(context, null /* attrs */);
|
super(context, null /* attrs */, R.style.VpnAppManagementPreferenceStyle, 0);
|
||||||
super.setUserId(userId);
|
super.setUserId(userId);
|
||||||
|
|
||||||
mPackageName = packageName;
|
mPackageName = packageName;
|
||||||
|
@@ -44,7 +44,12 @@ public abstract class ManageablePreference extends GearPreference {
|
|||||||
int mUserId;
|
int mUserId;
|
||||||
|
|
||||||
public ManageablePreference(Context context, AttributeSet attrs) {
|
public ManageablePreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
this(context, attrs, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ManageablePreference(Context context, AttributeSet attrs,
|
||||||
|
int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
setPersistent(false);
|
setPersistent(false);
|
||||||
setOrder(0);
|
setOrder(0);
|
||||||
setUserId(UserHandle.myUserId());
|
setUserId(UserHandle.myUserId());
|
||||||
|
@@ -33,6 +33,11 @@ public class GearPreference extends RestrictedPreference implements View.OnClick
|
|||||||
protected boolean mGearState = true;
|
protected boolean mGearState = true;
|
||||||
private OnGearClickListener mOnGearClickListener;
|
private OnGearClickListener mOnGearClickListener;
|
||||||
|
|
||||||
|
public GearPreference(Context context, AttributeSet attrs,
|
||||||
|
int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
public GearPreference(Context context, AttributeSet attrs) {
|
public GearPreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user