|
1 |
| -package com.stock.drawing; |
| 1 | +package com.stock.view; |
2 | 2 |
|
3 | 3 | import java.util.ArrayList;
|
4 | 4 | import java.util.Iterator;
|
5 | 5 | import java.util.List;
|
6 | 6 |
|
| 7 | +import android.content.Context; |
7 | 8 | import android.graphics.Bitmap;
|
8 | 9 | import android.graphics.Bitmap.Config;
|
9 | 10 | import android.graphics.Canvas;
|
10 | 11 | import android.graphics.Color;
|
11 | 12 | import android.graphics.Paint;
|
12 | 13 | import android.graphics.Rect;
|
| 14 | +import android.util.AttributeSet; |
13 | 15 |
|
14 | 16 | import com.stock.data.PriceBar;
|
15 | 17 | import com.stock.data.StockData;
|
16 | 18 | import com.stock.index.StockIndex;
|
17 | 19 |
|
18 |
| -public class CandleImage { |
| 20 | +public class CandleImage extends StockPhoto { |
| 21 | + |
| 22 | + public CandleImage(Context context) { |
| 23 | + super(context); |
| 24 | + } |
| 25 | + |
| 26 | + public CandleImage(Context context, AttributeSet attrs) { |
| 27 | + super(context, attrs); |
| 28 | + } |
19 | 29 |
|
20 | 30 | private List<PriceBar> bar_list;
|
21 | 31 | private List<StockIndex> indexes = new ArrayList<StockIndex>();
|
22 | 32 |
|
23 |
| - private int step = 8; |
24 | 33 | private int trans = 0; ///< transform the initialize position of candle image to left
|
25 | 34 | private int scoll = 0; ///< scoll screen
|
26 |
| - private float scale = .8f; |
27 |
| - private int background = Color.BLACK; |
28 | 35 |
|
29 |
| - public CandleImage(StockData data) { |
30 |
| - this.bar_list = data.getBarSet(); |
31 |
| - } |
| 36 | +// public CandleImage(StockData data) { |
| 37 | +// this.bar_list = data.getBarSet(); |
| 38 | +// } |
32 | 39 |
|
33 | 40 | public void AddIndex(StockIndex index) {
|
34 | 41 | index.calcIndex(bar_list);
|
@@ -169,27 +176,4 @@ private void drawCandle(Canvas g, Paint p, PriceBar[] bars, Rect rect, double hi
|
169 | 176 | }
|
170 | 177 | }
|
171 | 178 |
|
172 |
| - private void drawVolume(Canvas g, Paint p, PriceBar[] bars, Rect rect, double maxv) { |
173 |
| - int delta = step / 8, bar_width = step * 3 / 4; |
174 |
| - int x = rect.width() - step + delta, bottom = rect.top + rect.height(); |
175 |
| - double vhp = rect.height() / maxv * 0.8f; |
176 |
| - |
177 |
| -// ((Graphics2D)g).setStroke(new BasicStroke(1)); |
178 |
| - |
179 |
| - for( int i = 0; i < bars.length; i ++ ) { |
180 |
| - PriceBar curr = bars[i]; |
181 |
| - |
182 |
| - if( curr.close > curr.open ) |
183 |
| - p.setColor(Color.RED); |
184 |
| - else |
185 |
| - p.setColor(Color.GREEN); |
186 |
| - |
187 |
| - int vh = (int) Math.round( curr.volume * vhp ); |
188 |
| - p.setStyle(Paint.Style.FILL); |
189 |
| - g.drawRect(x, bottom - vh, bar_width, vh, p); |
190 |
| - |
191 |
| - x -= step; |
192 |
| - } |
193 |
| - } |
194 |
| - |
195 | 179 | }
|
0 commit comments