Commit ca9f19b4 authored by Sophie Chang's avatar Sophie Chang Committed by Commit Bot

Center "empty screen" textview in data reduction screen

Bug: 867129
Change-Id: I4eb4fe573b0a0e9adb6a23859d2263adce9c6fe7
Reviewed-on: https://chromium-review.googlesource.com/1182606
Commit-Queue: Sophie Chang <sophiechang@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585313}
parent b4509e8b
......@@ -3,108 +3,105 @@
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/data_reduction_stats_container"
<org.chromium.ui.widget.OptimizedFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical" >
android:layout_height="match_parent">
<TextView
android:id="@+id/initial_data_savings"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center_horizontal"
android:layout_gravity="center"
android:drawablePadding="3dp"
android:text="@string/data_reduction_initial_title"
android:textAppearance="@style/BlackDisabledText1" />
<LinearLayout
android:id="@+id/data_savings_summary_container"
android:id="@+id/data_reduction_stats_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center_horizontal"
android:baselineAligned="false"
android:orientation="vertical" >
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<LinearLayout
<TextView
android:id="@+id/data_reduction_savings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/data_reduction_savings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.DataReductionHeadline" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:paddingStart="3dp"
android:text="@string/data_reduction_savings_label"
android:textAppearance="@style/BlueLink2" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="3dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.DataReductionHeadline" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/data_reduction_usage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@style/BlackBody" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="3dp"
android:text="@string/data_reduction_usage_label"
android:textAppearance="@style/BlackBody" />
</LinearLayout>
android:layout_marginTop="3dp"
android:paddingStart="3dp"
android:text="@string/data_reduction_savings_label"
android:textAppearance="@style/BlueLink2" />
</LinearLayout>
</LinearLayout>
<include layout="@layout/data_usage_chart" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="4dp"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/chart_dates"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/data_reduction_usage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@style/BlackBody" />
<TextView
android:id="@+id/data_reduction_start_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/BlackBody" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="3dp"
android:text="@string/data_reduction_usage_label"
android:textAppearance="@style/BlackBody" />
</LinearLayout>
<TextView
android:id="@+id/data_reduction_end_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/BlackBody" />
<include layout="@layout/data_usage_chart" />
</FrameLayout>
<FrameLayout
android:id="@+id/chart_dates"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<include layout="@layout/data_usage_breakdown" />
<TextView
android:id="@+id/data_reduction_start_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/BlackBody" />
<Button
android:id="@+id/data_reduction_reset_statistics"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="24dp"
android:text="@string/data_reduction_usage_reset_statistics_button" />
<TextView
android:id="@+id/data_reduction_end_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/BlackBody" />
</FrameLayout>
<include layout="@layout/data_usage_breakdown" />
<Button
android:id="@+id/data_reduction_reset_statistics"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="24dp"
android:text="@string/data_reduction_usage_reset_statistics_button" />
</LinearLayout>
</LinearLayout>
</org.chromium.ui.widget.OptimizedFrameLayout>
......@@ -38,6 +38,8 @@ import org.chromium.chrome.browser.util.FileSizeUtil;
import org.chromium.third_party.android.datausagechart.ChartDataUsageView;
import org.chromium.third_party.android.datausagechart.NetworkStats;
import org.chromium.third_party.android.datausagechart.NetworkStatsHistory;
import org.chromium.ui.widget.RectProvider;
import org.chromium.ui.widget.ViewRectProvider;
import java.util.List;
import java.util.TimeZone;
......@@ -64,9 +66,9 @@ public class DataReductionStatsPreference extends Preference {
private NetworkStatsHistory mReceivedNetworkStatsHistory;
private List<DataReductionDataUseItem> mSiteBreakdownItems;
private ViewRectProvider mDataReductionStatsPreferenceViewRectProvider;
private LinearLayout mDataReductionStatsContainer;
private TextView mInitialDataSavingsTextView;
private LinearLayout mDataSavingsSummaryContainer;
private FrameLayout mDataSavingsChartDatesContainer;
private TextView mDataSavingsTextView;
private TextView mDataUsageTextView;
private TextView mStartDateTextView;
......@@ -235,13 +237,8 @@ public class DataReductionStatsPreference extends Preference {
if (mShouldShowRealData) updateDetailData();
mInitialDataSavingsTextView.setVisibility(mShouldShowRealData ? View.GONE : View.VISIBLE);
mDataReductionStatsContainer.setVisibility(mShouldShowRealData ? View.VISIBLE : View.GONE);
mDataSavingsSummaryContainer.setVisibility(mShouldShowRealData ? View.VISIBLE : View.GONE);
mChartDataUsageView.setVisibility(mShouldShowRealData ? View.VISIBLE : View.GONE);
mResetStatisticsButton.setVisibility(mShouldShowRealData ? View.VISIBLE : View.GONE);
mDataSavingsChartDatesContainer.setVisibility(
mShouldShowRealData ? View.VISIBLE : View.GONE);
mStartDateTextView.setText(mShouldShowRealData ? mStartDatePhrase : "");
mStartDateTextView.setContentDescription(mShouldShowRealData
? context.getString(R.string.data_reduction_start_date_content_description,
......@@ -267,6 +264,30 @@ public class DataReductionStatsPreference extends Preference {
((FrameLayout.LayoutParams) mEndDateTextView.getLayoutParams()).gravity = Gravity.RIGHT;
}
/**
* Initializes a view rect observer to listen for when the bounds of the view has changed, so we
* can update the minimum height of the view accordingly.
*
* @param view The view to listen for bounds changes on.
*/
private void initializeViewBounds(final View view) {
if (mDataReductionStatsPreferenceViewRectProvider != null) {
mDataReductionStatsPreferenceViewRectProvider.stopObserving();
}
mDataReductionStatsPreferenceViewRectProvider = new ViewRectProvider(view);
mDataReductionStatsPreferenceViewRectProvider.startObserving(new RectProvider.Observer() {
@Override
public void onRectChanged() {
int screenHeight = getContext().getResources().getDisplayMetrics().heightPixels;
int offset = mDataReductionStatsPreferenceViewRectProvider.getRect().top;
view.setMinimumHeight(screenHeight - offset);
}
@Override
public void onRectHidden() {}
});
}
/**
* Sets up a data usage chart and text views containing data reduction statistics.
* @param view The current view.
......@@ -274,16 +295,19 @@ public class DataReductionStatsPreference extends Preference {
@Override
protected void onBindView(View view) {
super.onBindView(view);
initializeViewBounds(view);
mInitialDataSavingsTextView = (TextView) view.findViewById(R.id.initial_data_savings);
mInitialDataSavingsTextView.setCompoundDrawablesWithIntrinsicBounds(null,
VectorDrawableCompat.create(getContext().getResources(),
R.drawable.data_reduction_big, getContext().getTheme()),
null, null);
mDataSavingsSummaryContainer =
(LinearLayout) view.findViewById(R.id.data_savings_summary_container);
mDataReductionStatsContainer =
(LinearLayout) view.findViewById(R.id.data_reduction_stats_container);
mDataUsageTextView = (TextView) view.findViewById(R.id.data_reduction_usage);
mDataSavingsTextView = (TextView) view.findViewById(R.id.data_reduction_savings);
mDataSavingsChartDatesContainer = (FrameLayout) view.findViewById(R.id.chart_dates);
mStartDateTextView = (TextView) view.findViewById(R.id.data_reduction_start_date);
mEndDateTextView = (TextView) view.findViewById(R.id.data_reduction_end_date);
mDataReductionBreakdownView =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment