Extend single line summary preference to multi line.
also updated some strings char limit. Change-Id: Ie068ecc410bb8211b4cd5e32a5539c824c48040f Fix: 36413664 Fix: 62079108 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -94,6 +94,10 @@
|
|||||||
|
|
||||||
<attr name="footerPreferenceStyle" format="reference" />
|
<attr name="footerPreferenceStyle" format="reference" />
|
||||||
|
|
||||||
|
<declare-styleable name="FixedLineSummaryPreference">
|
||||||
|
<attr name="summaryLineCount" format="integer" />
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
<!-- For Search -->
|
<!-- For Search -->
|
||||||
<declare-styleable name="Preference">
|
<declare-styleable name="Preference">
|
||||||
<attr name="keywords" format="string" />
|
<attr name="keywords" format="string" />
|
||||||
|
@@ -8430,7 +8430,7 @@
|
|||||||
<!-- Preference menu title for accessing the deletion helper from the storage manager settings. [CHAR LIMIT=30]-->
|
<!-- Preference menu title for accessing the deletion helper from the storage manager settings. [CHAR LIMIT=30]-->
|
||||||
<string name="deletion_helper_preference_title">Free up space now</string>
|
<string name="deletion_helper_preference_title">Free up space now</string>
|
||||||
|
|
||||||
<!-- Preference title for gesture settings [CHAR LIMIT=25]-->
|
<!-- Preference title for gesture settings [CHAR LIMIT=40]-->
|
||||||
<string name="gesture_preference_title">Gesture shortcuts</string>
|
<string name="gesture_preference_title">Gesture shortcuts</string>
|
||||||
|
|
||||||
<!-- Preference summary for gesture settings (phone) [CHAR LIMIT=NONE]-->
|
<!-- Preference summary for gesture settings (phone) [CHAR LIMIT=NONE]-->
|
||||||
|
@@ -15,7 +15,9 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<com.android.settings.applications.LayoutPreference
|
<com.android.settings.applications.LayoutPreference
|
||||||
android:key="header_view"
|
android:key="header_view"
|
||||||
@@ -40,11 +42,12 @@
|
|||||||
android:title="@string/notifications_label"
|
android:title="@string/notifications_label"
|
||||||
android:selectable="true"/>
|
android:selectable="true"/>
|
||||||
|
|
||||||
<com.android.settings.widget.SingleLineSummaryPreference
|
<com.android.settings.widget.FixedLineSummaryPreference
|
||||||
android:key="permission_settings"
|
android:key="permission_settings"
|
||||||
android:title="@string/permissions_label"
|
android:title="@string/permissions_label"
|
||||||
android:summary="@string/summary_placeholder"
|
android:summary="@string/summary_two_lines_placeholder"
|
||||||
android:selectable="true"/>
|
android:selectable="true"
|
||||||
|
app:summaryLineCount="2" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="storage_settings"
|
android:key="storage_settings"
|
||||||
|
@@ -15,19 +15,36 @@
|
|||||||
package com.android.settings.widget;
|
package com.android.settings.widget;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceViewHolder;
|
import android.support.v7.preference.PreferenceViewHolder;
|
||||||
import android.text.TextUtils.TruncateAt;
|
import android.text.TextUtils.TruncateAt;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A preference whose summary text will only span one single line.
|
* A preference whose summary text will only span one single line.
|
||||||
*/
|
*/
|
||||||
public class SingleLineSummaryPreference extends Preference {
|
public class FixedLineSummaryPreference extends Preference {
|
||||||
|
|
||||||
public SingleLineSummaryPreference(Context context, AttributeSet attrs) {
|
private int mSummaryLineCount;
|
||||||
|
|
||||||
|
public FixedLineSummaryPreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FixedLineSummaryPreference,
|
||||||
|
0, 0);
|
||||||
|
if (a.hasValue(R.styleable.FixedLineSummaryPreference_summaryLineCount)) {
|
||||||
|
mSummaryLineCount = a.getInteger(
|
||||||
|
R.styleable.FixedLineSummaryPreference_summaryLineCount, 1);
|
||||||
|
} else {
|
||||||
|
mSummaryLineCount = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSummaryLineCount(int count) {
|
||||||
|
mSummaryLineCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -35,7 +52,8 @@ public class SingleLineSummaryPreference extends Preference {
|
|||||||
super.onBindViewHolder(holder);
|
super.onBindViewHolder(holder);
|
||||||
TextView summary = (TextView) holder.findViewById(android.R.id.summary);
|
TextView summary = (TextView) holder.findViewById(android.R.id.summary);
|
||||||
if (summary != null) {
|
if (summary != null) {
|
||||||
summary.setSingleLine();
|
summary.setMinLines(mSummaryLineCount);
|
||||||
|
summary.setMaxLines(mSummaryLineCount);
|
||||||
summary.setEllipsize(TruncateAt.END);
|
summary.setEllipsize(TruncateAt.END);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -15,19 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.widget;
|
package com.android.settings.widget;
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v7.preference.PreferenceViewHolder;
|
import android.support.v7.preference.PreferenceViewHolder;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.widget.SingleLineSummaryPreference;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -36,22 +33,27 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class SingleLineSummaryPreferenceTest {
|
public class FixedLineSummaryPreferenceTest {
|
||||||
|
|
||||||
@Mock private TextView mSummary;
|
@Mock
|
||||||
|
private TextView mSummary;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private PreferenceViewHolder mHolder;
|
private PreferenceViewHolder mHolder;
|
||||||
private SingleLineSummaryPreference mPreference;
|
private FixedLineSummaryPreference mPreference;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mPreference = new SingleLineSummaryPreference(mContext, null);
|
mPreference = new FixedLineSummaryPreference(mContext, null);
|
||||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||||
final View view = inflater.inflate(mPreference.getLayoutResource(),
|
final View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||||
new LinearLayout(mContext), false);
|
new LinearLayout(mContext), false);
|
||||||
@@ -62,8 +64,17 @@ public class SingleLineSummaryPreferenceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onBindViewHolder_shouldSetSingleLine() {
|
public void onBindViewHolder_shouldSetSingleLine() {
|
||||||
mPreference.onBindViewHolder(mHolder);
|
mPreference.onBindViewHolder(mHolder);
|
||||||
final TextView summary = (TextView) mHolder.findViewById(android.R.id.summary);
|
|
||||||
|
|
||||||
verify(mSummary).setSingleLine();
|
verify(mSummary).setMinLines(1);
|
||||||
|
verify(mSummary).setMaxLines(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onBindViewHolder_TwoLineSummary_shouldSetTwoLines() {
|
||||||
|
mPreference.setSummaryLineCount(2);
|
||||||
|
mPreference.onBindViewHolder(mHolder);
|
||||||
|
|
||||||
|
verify(mSummary).setMinLines(2);
|
||||||
|
verify(mSummary).setMaxLines(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user