• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.widget;
18 
19 import android.content.res.Resources;
20 import android.text.SpannableStringBuilder;
21 
22 /**
23  * Utility to invert another {@link ChartAxis}.
24  */
25 public class InvertedChartAxis implements ChartAxis {
26     private final ChartAxis mWrapped;
27     private float mSize;
28 
InvertedChartAxis(ChartAxis wrapped)29     public InvertedChartAxis(ChartAxis wrapped) {
30         mWrapped = wrapped;
31     }
32 
33     @Override
setBounds(long min, long max)34     public boolean setBounds(long min, long max) {
35         return mWrapped.setBounds(min, max);
36     }
37 
38     @Override
setSize(float size)39     public boolean setSize(float size) {
40         mSize = size;
41         return mWrapped.setSize(size);
42     }
43 
44     @Override
convertToPoint(long value)45     public float convertToPoint(long value) {
46         return mSize - mWrapped.convertToPoint(value);
47     }
48 
49     @Override
convertToValue(float point)50     public long convertToValue(float point) {
51         return mWrapped.convertToValue(mSize - point);
52     }
53 
54     @Override
buildLabel(Resources res, SpannableStringBuilder builder, long value)55     public long buildLabel(Resources res, SpannableStringBuilder builder, long value) {
56         return mWrapped.buildLabel(res, builder, value);
57     }
58 
59     @Override
getTickPoints()60     public float[] getTickPoints() {
61         final float[] points = mWrapped.getTickPoints();
62         for (int i = 0; i < points.length; i++) {
63             points[i] = mSize - points[i];
64         }
65         return points;
66     }
67 
68     @Override
shouldAdjustAxis(long value)69     public int shouldAdjustAxis(long value) {
70         return mWrapped.shouldAdjustAxis(value);
71     }
72 }
73