Larger touch targets, snap to persisted value.
Extend ListView content to screen edges, and use InsetBoundsDrawable to draw separator and divider with expected padding. Sweep touch targets are now much larger. Snap sweep to persisted value, and fix NFE when parsing label value. Bug: 5274249 Bug: 5262865 Bug: 5242857 Change-Id: Ifa0f3e622767d5b4dc85a73d6340207e6038a429
This commit is contained in:
@@ -58,7 +58,6 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:id="@android:id/summary"
|
android:id="@android:id/summary"
|
||||||
android:layout_columnSpan="2"
|
android:layout_columnSpan="2"
|
||||||
android:layout_gravity="fill_horizontal"
|
|
||||||
android:layout_marginTop="4dip"
|
android:layout_marginTop="4dip"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
@@ -20,10 +20,13 @@
|
|||||||
android:id="@+id/chart"
|
android:id="@+id/chart"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/data_usage_chart_height"
|
android:layout_height="@dimen/data_usage_chart_height"
|
||||||
android:paddingLeft="16dip"
|
android:layout_marginLeft="-16dip"
|
||||||
android:paddingRight="16dip"
|
android:layout_marginRight="-16dip"
|
||||||
|
android:layout_marginBottom="-32dip"
|
||||||
|
android:paddingLeft="24dip"
|
||||||
|
android:paddingRight="24dip"
|
||||||
android:paddingTop="16dip"
|
android:paddingTop="16dip"
|
||||||
android:paddingBottom="16dip"
|
android:paddingBottom="48dip"
|
||||||
settings:optimalWidth="@dimen/data_usage_chart_optimalWidth"
|
settings:optimalWidth="@dimen/data_usage_chart_optimalWidth"
|
||||||
settings:optimalWidthWeight="0.4">
|
settings:optimalWidthWeight="0.4">
|
||||||
|
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingLeft="@*android:dimen/preference_fragment_padding_side"
|
||||||
|
android:paddingRight="@*android:dimen/preference_fragment_padding_side"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:clipChildren="false"
|
android:clipChildren="false"
|
||||||
android:clipToPadding="false">
|
android:clipToPadding="false">
|
||||||
|
25
res/layout/data_usage_item.xml
Normal file
25
res/layout/data_usage_item.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2011 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingLeft="@*android:dimen/preference_fragment_padding_side"
|
||||||
|
android:paddingRight="@*android:dimen/preference_fragment_padding_side">
|
||||||
|
|
||||||
|
<include layout="@layout/app_percentage_item" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
@@ -28,7 +28,7 @@
|
|||||||
<dimen name="description_margin_top">26dip</dimen>
|
<dimen name="description_margin_top">26dip</dimen>
|
||||||
<dimen name="description_margin_sides">40dip</dimen>
|
<dimen name="description_margin_sides">40dip</dimen>
|
||||||
|
|
||||||
<dimen name="data_usage_chart_height">220dip</dimen>
|
<dimen name="data_usage_chart_height">252dip</dimen>
|
||||||
<dimen name="data_usage_chart_optimalWidth">440dip</dimen>
|
<dimen name="data_usage_chart_optimalWidth">440dip</dimen>
|
||||||
|
|
||||||
<dimen name="volume_seekbar_side_margin">8dip</dimen>
|
<dimen name="volume_seekbar_side_margin">8dip</dimen>
|
||||||
|
@@ -64,7 +64,9 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.graphics.drawable.InsetDrawable;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.INetworkPolicyManager;
|
import android.net.INetworkPolicyManager;
|
||||||
import android.net.INetworkStatsService;
|
import android.net.INetworkStatsService;
|
||||||
@@ -120,6 +122,8 @@ import android.widget.TabWidget;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.internal.telephony.Phone;
|
import com.android.internal.telephony.Phone;
|
||||||
|
import com.android.settings.drawable.InsetBoundsDrawable;
|
||||||
|
import com.android.settings.drawable.DrawableWrapper;
|
||||||
import com.android.settings.net.NetworkPolicyEditor;
|
import com.android.settings.net.NetworkPolicyEditor;
|
||||||
import com.android.settings.net.SummaryForAllUidLoader;
|
import com.android.settings.net.SummaryForAllUidLoader;
|
||||||
import com.android.settings.widget.ChartDataUsageView;
|
import com.android.settings.widget.ChartDataUsageView;
|
||||||
@@ -275,7 +279,12 @@ public class DataUsageSummary extends Fragment {
|
|||||||
mListView = (ListView) view.findViewById(android.R.id.list);
|
mListView = (ListView) view.findViewById(android.R.id.list);
|
||||||
|
|
||||||
// adjust padding around tabwidget as needed
|
// adjust padding around tabwidget as needed
|
||||||
prepareCustomPreferencesList(container, view, mListView);
|
prepareCustomPreferencesList(container, view, mListView, true);
|
||||||
|
|
||||||
|
// inset selector and divider drawables
|
||||||
|
final int insetSide = view.getResources().getDimensionPixelOffset(
|
||||||
|
com.android.internal.R.dimen.preference_fragment_padding_side);
|
||||||
|
insetListViewDrawables(mListView, insetSide);
|
||||||
|
|
||||||
mTabHost.setup();
|
mTabHost.setup();
|
||||||
mTabHost.setOnTabChangedListener(mTabListener);
|
mTabHost.setOnTabChangedListener(mTabListener);
|
||||||
@@ -1391,7 +1400,7 @@ public class DataUsageSummary extends Fragment {
|
|||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
convertView = LayoutInflater.from(parent.getContext()).inflate(
|
convertView = LayoutInflater.from(parent.getContext()).inflate(
|
||||||
R.layout.app_percentage_item, parent, false);
|
R.layout.data_usage_item, parent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Context context = parent.getContext();
|
final Context context = parent.getContext();
|
||||||
@@ -1912,6 +1921,24 @@ public class DataUsageSummary extends Fragment {
|
|||||||
return TextUtils.join(limited);
|
return TextUtils.join(limited);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inset both selector and divider {@link Drawable} on the given
|
||||||
|
* {@link ListView} by the requested dimensions.
|
||||||
|
*/
|
||||||
|
private static void insetListViewDrawables(ListView view, int insetSide) {
|
||||||
|
final Drawable selector = view.getSelector();
|
||||||
|
final Drawable divider = view.getDivider();
|
||||||
|
|
||||||
|
// fully unregister these drawables so callbacks can be maintained after
|
||||||
|
// wrapping below.
|
||||||
|
final Drawable stub = new ColorDrawable(Color.TRANSPARENT);
|
||||||
|
view.setSelector(stub);
|
||||||
|
view.setDivider(stub);
|
||||||
|
|
||||||
|
view.setSelector(new InsetBoundsDrawable(selector, insetSide));
|
||||||
|
view.setDivider(new InsetBoundsDrawable(divider, insetSide));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set {@link android.R.id#title} for a preference view inflated with
|
* Set {@link android.R.id#title} for a preference view inflated with
|
||||||
* {@link #inflatePreference(LayoutInflater, ViewGroup, View)}.
|
* {@link #inflatePreference(LayoutInflater, ViewGroup, View)}.
|
||||||
|
@@ -377,7 +377,8 @@ public class Utils {
|
|||||||
* when outside scrollbars are requested. Usually used to display
|
* when outside scrollbars are requested. Usually used to display
|
||||||
* {@link ListView} and {@link TabWidget} with correct padding.
|
* {@link ListView} and {@link TabWidget} with correct padding.
|
||||||
*/
|
*/
|
||||||
public static void prepareCustomPreferencesList(ViewGroup parent, View child, ListView list) {
|
public static void prepareCustomPreferencesList(
|
||||||
|
ViewGroup parent, View child, ListView list, boolean ignoreSidePadding) {
|
||||||
final boolean movePadding = list.getScrollBarStyle() == View.SCROLLBARS_OUTSIDE_OVERLAY;
|
final boolean movePadding = list.getScrollBarStyle() == View.SCROLLBARS_OUTSIDE_OVERLAY;
|
||||||
if (movePadding && parent instanceof PreferenceFrameLayout) {
|
if (movePadding && parent instanceof PreferenceFrameLayout) {
|
||||||
((PreferenceFrameLayout.LayoutParams) child.getLayoutParams()).removeBorders = true;
|
((PreferenceFrameLayout.LayoutParams) child.getLayoutParams()).removeBorders = true;
|
||||||
@@ -387,7 +388,9 @@ public class Utils {
|
|||||||
com.android.internal.R.dimen.preference_fragment_padding_side);
|
com.android.internal.R.dimen.preference_fragment_padding_side);
|
||||||
final int paddingBottom = res.getDimensionPixelSize(
|
final int paddingBottom = res.getDimensionPixelSize(
|
||||||
com.android.internal.R.dimen.preference_fragment_padding_bottom);
|
com.android.internal.R.dimen.preference_fragment_padding_bottom);
|
||||||
list.setPadding(paddingSide, 0, paddingSide, paddingBottom);
|
|
||||||
|
final int effectivePaddingSide = ignoreSidePadding ? 0 : paddingBottom;
|
||||||
|
list.setPadding(effectivePaddingSide, 0, effectivePaddingSide, paddingBottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -646,7 +646,7 @@ public class ManageApplications extends Fragment implements
|
|||||||
tabHost.setOnTabChangedListener(this);
|
tabHost.setOnTabChangedListener(this);
|
||||||
|
|
||||||
// adjust padding around tabwidget as needed
|
// adjust padding around tabwidget as needed
|
||||||
prepareCustomPreferencesList(container, mTabHost, mListView);
|
prepareCustomPreferencesList(container, mTabHost, mListView, false);
|
||||||
|
|
||||||
return mTabHost;
|
return mTabHost;
|
||||||
}
|
}
|
||||||
|
162
src/com/android/settings/drawable/DrawableWrapper.java
Normal file
162
src/com/android/settings/drawable/DrawableWrapper.java
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.drawable;
|
||||||
|
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.ColorFilter;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.Region;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.android.internal.util.Preconditions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base wrapper that delegates all calls to another {@link Drawable}. The
|
||||||
|
* wrapped {@link Drawable} <em>must</em> be fully released from any
|
||||||
|
* {@link View} before wrapping, otherwise internal {@link Drawable.Callback}
|
||||||
|
* may be dropped.
|
||||||
|
*/
|
||||||
|
public class DrawableWrapper extends Drawable implements Drawable.Callback {
|
||||||
|
private final Drawable mDrawable;
|
||||||
|
|
||||||
|
public DrawableWrapper(Drawable drawable) {
|
||||||
|
mDrawable = Preconditions.checkNotNull(drawable);
|
||||||
|
mDrawable.setCallback(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Canvas canvas) {
|
||||||
|
mDrawable.draw(canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBounds(int left, int top, int right, int bottom) {
|
||||||
|
super.setBounds(left, top, right, bottom);
|
||||||
|
mDrawable.setBounds(left, top, right, bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setChangingConfigurations(int configs) {
|
||||||
|
mDrawable.setChangingConfigurations(configs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getChangingConfigurations() {
|
||||||
|
return mDrawable.getChangingConfigurations();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDither(boolean dither) {
|
||||||
|
mDrawable.setDither(dither);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFilterBitmap(boolean filter) {
|
||||||
|
mDrawable.setFilterBitmap(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAlpha(int alpha) {
|
||||||
|
mDrawable.setAlpha(alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setColorFilter(ColorFilter cf) {
|
||||||
|
mDrawable.setColorFilter(cf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStateful() {
|
||||||
|
return mDrawable.isStateful();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setState(final int[] stateSet) {
|
||||||
|
return mDrawable.setState(stateSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] getState() {
|
||||||
|
return mDrawable.getState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void jumpToCurrentState() {
|
||||||
|
mDrawable.jumpToCurrentState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable getCurrent() {
|
||||||
|
return mDrawable.getCurrent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setVisible(boolean visible, boolean restart) {
|
||||||
|
return super.setVisible(visible, restart) || mDrawable.setVisible(visible, restart);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOpacity() {
|
||||||
|
return mDrawable.getOpacity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Region getTransparentRegion() {
|
||||||
|
return mDrawable.getTransparentRegion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIntrinsicWidth() {
|
||||||
|
return mDrawable.getIntrinsicWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIntrinsicHeight() {
|
||||||
|
return mDrawable.getIntrinsicHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMinimumWidth() {
|
||||||
|
return mDrawable.getMinimumWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMinimumHeight() {
|
||||||
|
return mDrawable.getMinimumHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getPadding(Rect padding) {
|
||||||
|
return mDrawable.getPadding(padding);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
public void invalidateDrawable(Drawable who) {
|
||||||
|
invalidateSelf();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
public void scheduleDrawable(Drawable who, Runnable what, long when) {
|
||||||
|
scheduleSelf(what, when);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
public void unscheduleDrawable(Drawable who, Runnable what) {
|
||||||
|
unscheduleSelf(what);
|
||||||
|
}
|
||||||
|
}
|
37
src/com/android/settings/drawable/InsetBoundsDrawable.java
Normal file
37
src/com/android/settings/drawable/InsetBoundsDrawable.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.drawable;
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper around another {@link Drawable} that insets requested bounds by a
|
||||||
|
* specific amount.
|
||||||
|
*/
|
||||||
|
public class InsetBoundsDrawable extends DrawableWrapper {
|
||||||
|
private final int mInsetBoundsSides;
|
||||||
|
|
||||||
|
public InsetBoundsDrawable(Drawable drawable, int insetBoundsSides) {
|
||||||
|
super(drawable);
|
||||||
|
mInsetBoundsSides = insetBoundsSides;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBounds(int left, int top, int right, int bottom) {
|
||||||
|
super.setBounds(left + mInsetBoundsSides, top, right - mInsetBoundsSides, bottom);
|
||||||
|
}
|
||||||
|
}
|
@@ -496,32 +496,32 @@ public class ChartDataUsageView extends ChartView {
|
|||||||
public long buildLabel(Resources res, SpannableStringBuilder builder, long value) {
|
public long buildLabel(Resources res, SpannableStringBuilder builder, long value) {
|
||||||
|
|
||||||
final CharSequence unit;
|
final CharSequence unit;
|
||||||
float result = value;
|
final long unitFactor;
|
||||||
long labelValue = 1;
|
if (value <= 100 * MB_IN_BYTES) {
|
||||||
if (result <= 100 * MB_IN_BYTES) {
|
|
||||||
unit = res.getText(com.android.internal.R.string.megabyteShort);
|
unit = res.getText(com.android.internal.R.string.megabyteShort);
|
||||||
result /= MB_IN_BYTES;
|
unitFactor = MB_IN_BYTES;
|
||||||
labelValue = MB_IN_BYTES;
|
|
||||||
} else {
|
} else {
|
||||||
unit = res.getText(com.android.internal.R.string.gigabyteShort);
|
unit = res.getText(com.android.internal.R.string.gigabyteShort);
|
||||||
result /= GB_IN_BYTES;
|
unitFactor = GB_IN_BYTES;
|
||||||
labelValue = GB_IN_BYTES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final double result = (double) value / unitFactor;
|
||||||
|
final double resultRounded;
|
||||||
final CharSequence size;
|
final CharSequence size;
|
||||||
if (result < 10) {
|
if (result < 10) {
|
||||||
size = String.format("%.1f", result);
|
size = String.format("%.1f", result);
|
||||||
|
resultRounded = (unitFactor * Math.round(result * 10)) / 10;
|
||||||
} else {
|
} else {
|
||||||
size = String.format("%.0f", result);
|
size = String.format("%.0f", result);
|
||||||
|
resultRounded = unitFactor * Math.round(result);
|
||||||
}
|
}
|
||||||
labelValue *= Float.parseFloat(size.toString());
|
|
||||||
|
|
||||||
final int[] sizeBounds = findOrCreateSpan(builder, sSpanSize, "^1");
|
final int[] sizeBounds = findOrCreateSpan(builder, sSpanSize, "^1");
|
||||||
builder.replace(sizeBounds[0], sizeBounds[1], size);
|
builder.replace(sizeBounds[0], sizeBounds[1], size);
|
||||||
final int[] unitBounds = findOrCreateSpan(builder, sSpanUnit, "^2");
|
final int[] unitBounds = findOrCreateSpan(builder, sSpanUnit, "^2");
|
||||||
builder.replace(unitBounds[0], unitBounds[1], unit);
|
builder.replace(unitBounds[0], unitBounds[1], unit);
|
||||||
|
|
||||||
return labelValue;
|
return (long) resultRounded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
@@ -45,11 +45,13 @@ public class ChartSweepView extends View {
|
|||||||
|
|
||||||
private static final boolean DRAW_OUTLINE = false;
|
private static final boolean DRAW_OUTLINE = false;
|
||||||
|
|
||||||
|
// TODO: clean up all the various padding/offset/margins
|
||||||
|
|
||||||
private Drawable mSweep;
|
private Drawable mSweep;
|
||||||
private Rect mSweepPadding = new Rect();
|
private Rect mSweepPadding = new Rect();
|
||||||
|
|
||||||
/** Offset of content inside this view. */
|
/** Offset of content inside this view. */
|
||||||
private Point mContentOffset = new Point();
|
private Rect mContentOffset = new Rect();
|
||||||
/** Offset of {@link #mSweep} inside this view. */
|
/** Offset of {@link #mSweep} inside this view. */
|
||||||
private Point mSweepOffset = new Point();
|
private Point mSweepOffset = new Point();
|
||||||
|
|
||||||
@@ -229,6 +231,8 @@ public class ChartSweepView extends View {
|
|||||||
if (mLabelTemplate != null && mAxis != null) {
|
if (mLabelTemplate != null && mAxis != null) {
|
||||||
mLabelValue = mAxis.buildLabel(getResources(), mLabelTemplate, mValue);
|
mLabelValue = mAxis.buildLabel(getResources(), mLabelTemplate, mValue);
|
||||||
invalidate();
|
invalidate();
|
||||||
|
} else {
|
||||||
|
mLabelValue = mValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,9 +337,9 @@ public class ChartSweepView extends View {
|
|||||||
// only start tracking when in sweet spot
|
// only start tracking when in sweet spot
|
||||||
final boolean accept;
|
final boolean accept;
|
||||||
if (mFollowAxis == VERTICAL) {
|
if (mFollowAxis == VERTICAL) {
|
||||||
accept = event.getX() > getWidth() - (mSweepPadding.right * 3);
|
accept = event.getX() > getWidth() - (mSweepPadding.right * 8);
|
||||||
} else {
|
} else {
|
||||||
accept = event.getY() > getHeight() - (mSweepPadding.bottom * 3);
|
accept = event.getY() > getHeight() - (mSweepPadding.bottom * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
final MotionEvent eventInParent = event.copy();
|
final MotionEvent eventInParent = event.copy();
|
||||||
@@ -392,6 +396,7 @@ public class ChartSweepView extends View {
|
|||||||
}
|
}
|
||||||
case MotionEvent.ACTION_UP: {
|
case MotionEvent.ACTION_UP: {
|
||||||
mTracking = null;
|
mTracking = null;
|
||||||
|
mValue = mLabelValue;
|
||||||
dispatchOnSweep(true);
|
dispatchOnSweep(true);
|
||||||
setTranslationX(0);
|
setTranslationX(0);
|
||||||
setTranslationY(0);
|
setTranslationY(0);
|
||||||
@@ -534,23 +539,30 @@ public class ChartSweepView extends View {
|
|||||||
mMargins.bottom = mSweepPadding.bottom;
|
mMargins.bottom = mSweepPadding.bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
mContentOffset.x = 0;
|
mContentOffset.set(0, 0, 0, 0);
|
||||||
mContentOffset.y = 0;
|
|
||||||
|
|
||||||
// make touch target area larger
|
// make touch target area larger
|
||||||
if (mFollowAxis == HORIZONTAL) {
|
|
||||||
final int widthBefore = getMeasuredWidth();
|
final int widthBefore = getMeasuredWidth();
|
||||||
final int widthAfter = widthBefore * 3;
|
|
||||||
setMeasuredDimension(widthAfter, getMeasuredHeight());
|
|
||||||
mContentOffset.offset((widthAfter - widthBefore) / 2, 0);
|
|
||||||
} else {
|
|
||||||
final int heightBefore = getMeasuredHeight();
|
final int heightBefore = getMeasuredHeight();
|
||||||
|
if (mFollowAxis == HORIZONTAL) {
|
||||||
|
final int widthAfter = widthBefore * 3;
|
||||||
|
setMeasuredDimension(widthAfter, heightBefore);
|
||||||
|
mContentOffset.left = (widthAfter - widthBefore) / 2;
|
||||||
|
|
||||||
|
final int offset = mSweepPadding.bottom * 2;
|
||||||
|
mContentOffset.bottom -= offset;
|
||||||
|
mMargins.bottom += offset;
|
||||||
|
} else {
|
||||||
final int heightAfter = heightBefore * 3;
|
final int heightAfter = heightBefore * 3;
|
||||||
setMeasuredDimension(getMeasuredWidth(), heightAfter);
|
setMeasuredDimension(widthBefore, heightAfter);
|
||||||
mContentOffset.offset(0, (heightAfter - heightBefore) / 2);
|
mContentOffset.offset(0, (heightAfter - heightBefore) / 2);
|
||||||
|
|
||||||
|
final int offset = mSweepPadding.right * 2;
|
||||||
|
mContentOffset.right -= offset;
|
||||||
|
mMargins.right += offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
mSweepOffset.offset(mContentOffset.x, mContentOffset.y);
|
mSweepOffset.offset(mContentOffset.left, mContentOffset.top);
|
||||||
mMargins.offset(-mSweepOffset.x, -mSweepOffset.y);
|
mMargins.offset(-mSweepOffset.x, -mSweepOffset.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,7 +604,7 @@ public class ChartSweepView extends View {
|
|||||||
if (isEnabled() && mLabelLayout != null) {
|
if (isEnabled() && mLabelLayout != null) {
|
||||||
final int count = canvas.save();
|
final int count = canvas.save();
|
||||||
{
|
{
|
||||||
canvas.translate(mContentOffset.x, mContentOffset.y + labelOffset);
|
canvas.translate(mContentOffset.left, mContentOffset.top + labelOffset);
|
||||||
mLabelLayout.draw(canvas);
|
mLabelLayout.draw(canvas);
|
||||||
}
|
}
|
||||||
canvas.restoreToCount(count);
|
canvas.restoreToCount(count);
|
||||||
@@ -602,18 +614,18 @@ public class ChartSweepView extends View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mFollowAxis == VERTICAL) {
|
if (mFollowAxis == VERTICAL) {
|
||||||
mSweep.setBounds(labelSize, mSweepOffset.y, width,
|
mSweep.setBounds(labelSize, mSweepOffset.y, width + mContentOffset.right,
|
||||||
mSweepOffset.y + mSweep.getIntrinsicHeight());
|
mSweepOffset.y + mSweep.getIntrinsicHeight());
|
||||||
} else {
|
} else {
|
||||||
mSweep.setBounds(mSweepOffset.x, labelSize,
|
mSweep.setBounds(mSweepOffset.x, labelSize, mSweepOffset.x + mSweep.getIntrinsicWidth(),
|
||||||
mSweepOffset.x + mSweep.getIntrinsicWidth(), height);
|
height + mContentOffset.bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
mSweep.draw(canvas);
|
mSweep.draw(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getLabelTop(ChartSweepView view) {
|
public static float getLabelTop(ChartSweepView view) {
|
||||||
return view.getY() + view.mContentOffset.y;
|
return view.getY() + view.mContentOffset.top;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getLabelBottom(ChartSweepView view) {
|
public static float getLabelBottom(ChartSweepView view) {
|
||||||
|
Reference in New Issue
Block a user