Android Open Source - SpunkyCharts Price By Volume Chart Fragment






From Project

Back to project page SpunkyCharts.

License

The source code is released under:

GNU General Public License

If you think the Android project SpunkyCharts listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jogden.spunkycharts.pricebyvolumechart;
/* //w  ww .j  av a  2s .  c  om
Copyright (C) 2014 Jonathon Ogden     < jeog.dev@gmail.com >

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see http://www.gnu.org/licenses.
*/
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.LocalBroadcastManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnLayoutChangeListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jogden.spunkycharts.ApplicationPreferences;
import com.jogden.spunkycharts.BaseChartFragmentA;
import com.jogden.spunkycharts.MainApplication;
import com.jogden.spunkycharts.R;
import com.jogden.spunkycharts.data.DataContentService;
import com.jogden.spunkycharts.traditionalchart.TraditionalChartPanel;
import com.jogden.spunkycharts.traditionalchart.TraditionalChartPreferences;


public class PriceByVolumeChartFragment 
    extends BaseChartFragmentA
{    
    /* our important inner views */
    private LinearLayout _yAxis;
    private LinearLayout _xAxis;
    private PriceByVolumeChartPanel _mainPanel;
    private LinearLayout _rightPanel;

    /* all the internal logical and view management*/
    private PriceByVolumeChartFragmentAdapter _chartAdapter;
    private PriceByVolumeChartFragment _this = this;
    private ViewGroup _myViewGroup = null;
    private String _symbol;        
    
    /* private settings */
    private int _ySegHeight = 
        ApplicationPreferences.getSegmentWidth();    
    private float _segThickness =
        TraditionalChartPreferences.getDefaultSegThickness();
    private int _foreColor = 
        TraditionalChartPreferences.getDefaultForegroundColor();
    private int _backColor = 
        TraditionalChartPreferences.getDefaultBackgroundColor();

    /* cache these to avoid myriad getter calls */ 
    static boolean majorMarkFlag =
        ApplicationPreferences.getShowMajorMark();
    static boolean minorMarkFlag =
        ApplicationPreferences.getShowMinorMark();

    /* used to draw ALL axis marks of this chart type */
    public static final Paint axisMarkBrush 
        = new Paint(Paint.ANTI_ALIAS_FLAG);
    static{
        axisMarkBrush.setStrokeWidth( 
            ApplicationPreferences.getAxisMarkThickness() 
            );
        axisMarkBrush.setColor( 
            ApplicationPreferences.getAxisMarkColor() 
            );
        }
    
    /*|--------->         begin PUBLIC interface         <--------|*/    
    /* getter/setters for universal preferences*/
    static public void setAxisMarkColor(int colorId)
    {
        axisMarkBrush.setColor(colorId);            
    }
    static public int getAxisMarktColor()
    {
        return axisMarkBrush.getColor();
    }
    static public void setAxisMarkThickness(int pixSize)
    {
        axisMarkBrush.setStrokeWidth(pixSize);        
    }
    static public float getAxisMarkThickness()
    {
        return axisMarkBrush.getStrokeWidth();
    }
    static public void setShowMinorMark(boolean show)
    {
        minorMarkFlag = show;        
    }
    static public boolean getShowMinorMark()
    {
        return minorMarkFlag;
    }
    static public void setShowMajorMark(boolean show)
    {
        majorMarkFlag = show;    
    }
    static public boolean getShowMajorMark()
    {
        return majorMarkFlag;
    }
    @Override
    public void setAxisFontSize(int sp)
    {
        if( _chartAdapter != null)
            _chartAdapter.setAxisFontSize(sp);
    }
    @Override
    public void setAxisFontColor(int colorId)
    {
        if( _chartAdapter != null)
            _chartAdapter.setAxisFontColor(colorId);
    }
    @Override
    public void setXAxisPaddingSize(int pixSize)
    {
       // if(_chartAdapter != null)
          //  _chartAdapter.setXAxisPaddingSize(pixSize);
    }
    @Override
    public void setAxisTimeout(int value)
    {
        if(_chartAdapter != null)
            _chartAdapter.setAxisTimeout(value);
    }
    @Override
    public void setTimeoutIncrement(int value)
    {
        if(_chartAdapter != null)
            _chartAdapter.setTimeoutIncrement(value);
    }
    @Override
    public void refresh()
    {                   
            if(MainApplication.readyForData)  
                DataContentService.load(_symbol, _chartAdapter);            
        _chartAdapter.reset();         
      //  _mainPanel.forceDraw();
    }        
    
    //
    // TODO: local chart preferences   
    //
    
    @Override
    public void hide()
    {
        super.hide();
        _mainPanel.forceStop();   
    }
    @Override
    public void show()
    {
        super.show();   
        _mainPanel.forceStart();
    }
    
    /*|--------->         end PUBLIC interface         <--------|*/
    /*|--------->     begin PROTECTED interface     <--------|*/    
    
    protected void setForegroundColor( int colorId )
    {
        _foreColor = colorId; 
        _yAxis.setBackgroundColor( colorId );
        _xAxis.setBackgroundColor( colorId );        
        super.setColor(colorId);
    }
    protected int getForegroundColor()
    {
        return _foreColor;
    }
    protected void setBackgroundColor( int colorId )
    {
        _backColor = colorId;
        _myViewGroup.setBackgroundColor(colorId);
    }
    protected int getBackgroundColor()
    {
        return _backColor;
    }
    
    protected void setSegmentThickness( float thickness)
    {
        _mainPanel.setSegmentThickness(thickness);
        _mainPanel.forceDraw();
        _segThickness = thickness;
    }
    protected float getSegmentThickness()
    {
        return _segThickness;
    }  
    @Override
    protected void setRefreshRate( int refreshRate)
    { 
        super.setRefreshRate(refreshRate);
    }
    @Override /* should be a mirror of onSavedState handler */
    protected void extractState(Bundle savedState)
    {        
        if(savedState == null)
            return;
        if( _symbol == null) 
            _symbol = savedState.getString("symbol");
        if( _symbol == null)
            throw new IllegalStateException(
                "ChartFragment does not have valid symbol string"
                );
        //
        //  TODO: sync with local preferences
        //
        super.extractState(savedState);
    }       
    /* how to handle a held/long touch of the frag view */
    @Override
    protected void onHoldDown()
    {
        //
        //TODO: implement hold down behavior
        //
    }    
    @Override
    protected void onStacked(    
        BaseChartFragmentA base,
        BaseChartFragmentA oldTop,
        BaseChartFragmentA newTop
    ){
        //
        //TODO: implement stack behavior
        //
    }
    @Override
    protected void onDeStacked(    
        BaseChartFragmentA base,
        BaseChartFragmentA oldTop,
        BaseChartFragmentA newTop
    ){
        //
        //TODO: implement de-stack behavior
        //
    } 
    
    /*|--------->         end PROTECTED interface         <--------|*/
    /*|--------->         begin PRIVATE methods         <--------|*/
    
    private void _syncPanels()
    {
        final TextView tv = 
            (TextView)_rightPanel.findViewById(R.id.xAxis_mirror);
        /* synch X-Axis heights */
        _xAxis.addOnLayoutChangeListener(
            new OnLayoutChangeListener(){
                @Override
                public void onLayoutChange(
                    View v, int left, int top,int right, int bottom, 
                    int oldLeft, int oldTop, int oldRight, int oldBottom){
                        tv.setLayoutParams( 
                            new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.WRAP_CONTENT,
                                (int)(bottom-top)                                              
                            )
                        );
                        _rightPanel.invalidate();                  
                    }                
                }
            );     
    }  
    
    /*|--------->         end PRIVATE methods         <--------|*/
    /*|--------->     begin LIFE-CYCLE handlers     <--------|*/
    
    @Override
    public void onAttach(Activity activity) 
    {
        super.onAttach(activity); 
        _symbol = this.getArguments().getString("symbol");    
    }    
    @Override
    public void onCreate(Bundle savedState) 
    { 
        super.onCreate(savedState);              
    }
   
    @Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedState
    ){    
        super.onCreateView(inflater, container, savedState);       
        _myViewGroup = 
            (ViewGroup)inflater.inflate( 
                R.layout.chart_fragment_pricebyvolume, 
                ourViewGroup, true 
                ).findViewById(R.id.pbv_chart_main); 
        _yAxis = (LinearLayout)_myViewGroup.findViewById(
            R.id.label_yAxis
            );
        _xAxis = (LinearLayout)_myViewGroup.findViewById(
            R.id.label_xAxis
            ); 
        _mainPanel = 
            (PriceByVolumeChartPanel)_myViewGroup.findViewById(
                R.id.main_lay
                );
        _rightPanel = (LinearLayout)_myViewGroup.findViewById(
            R.id.chart_right_panel
            );   
        _syncPanels();    
        setBackgroundColor( _backColor );
        setForegroundColor( _foreColor );
        return ourViewGroup;
    }
    @Override 
    public void onActivityCreated(Bundle savedState){
        super.onActivityCreated(savedState);       
        _chartAdapter = 
            new PriceByVolumeChartFragmentAdapter(
                parentActivity, new Handler(),
                MainApplication.getLocalBroadcastManager(),
                _mainPanel, _xAxis, _yAxis, _myViewGroup, 
                _ySegHeight, null, _symbol                          
                );
        DataContentService.addChannel(_symbol,_chartAdapter);
    }
    @Override 
    public void onStart()
    {      
        super.onStart();
        if(MainApplication.readyForData)
            DataContentService.load(_symbol, _chartAdapter);       
    }    
    @Override 
    public void onResume() 
    {
        super.onResume();                    
            
    }
    @Override 
    public void onPause() 
    {
        super.onPause();                    
    }

    @Override
    public void onSaveInstanceState(Bundle savedState) 
    {
        savedState.putString("symbol",_symbol);        
        super.onSaveInstanceState(savedState);         
        //
        //TODO: sync with local prefs
        //
    }    
    
    @Override
    public void onStop() 
    {        
        super.onStop();        
        _chartAdapter.cleanUpAndUpdate();  
    }    
    @Override
    public void onDestroyView() 
    {
        super.onDestroyView();    
    }    
    @Override 
    public void onDestroy() 
    {
        DataContentService.removeChannel(_symbol,_chartAdapter);
        super.onDestroy();        
    }    
    @Override
    public void onDetach() 
    {
        super.onDetach();
    }    

   
   

    

}




Java Source Code List

com.jogden.spunkycharts.ApplicationPreferences.java
com.jogden.spunkycharts.BaseChartFragmentA.java
com.jogden.spunkycharts.ChartPanelSurfaceView.java
com.jogden.spunkycharts.DockingPanelActivity.java
com.jogden.spunkycharts.GlobalChartPreferences.java
com.jogden.spunkycharts.InitActivity.java
com.jogden.spunkycharts.MainApplication.java
com.jogden.spunkycharts.OpeningView.java
com.jogden.spunkycharts.animations.BaseAnimationA.java
com.jogden.spunkycharts.animations.BaseEntExAnimationA.java
com.jogden.spunkycharts.animations.BaseSelectAnimationA.java
com.jogden.spunkycharts.animations.HorizontalBulgeAnimation.java
com.jogden.spunkycharts.animations.HorizontalShakeAnimation.java
com.jogden.spunkycharts.animations.VerticalBulgeAnimation.java
com.jogden.spunkycharts.animations.VerticalShakeAnimation.java
com.jogden.spunkycharts.animations.WiggleAnimation.java
com.jogden.spunkycharts.data.DataClientLocalDebug.java
com.jogden.spunkycharts.data.DataContentService.java
com.jogden.spunkycharts.misc.BorderOverlay.java
com.jogden.spunkycharts.misc.ColorPaletteDialog.java
com.jogden.spunkycharts.misc.HideHorizontalLeftOverflowWrapper.java
com.jogden.spunkycharts.misc.OHLC.java
com.jogden.spunkycharts.misc.Pair.java
com.jogden.spunkycharts.misc.TextInput.java
com.jogden.spunkycharts.misc.Triple.java
com.jogden.spunkycharts.pricebyvolumechart.PriceByVolumeChartFragmentAdapter.java
com.jogden.spunkycharts.pricebyvolumechart.PriceByVolumeChartFragment.java
com.jogden.spunkycharts.pricebyvolumechart.PriceByVolumeChartPanel.java
com.jogden.spunkycharts.pricebyvolumechart.PriceByVolumeChartPreferences.java
com.jogden.spunkycharts.pricebyvolumechart.draw.DrawSemanticsA.java
com.jogden.spunkycharts.pricebyvolumechart.draw.DrawSemantics_SILO.java
com.jogden.spunkycharts.traditionalchart.InnerXAxis.java
com.jogden.spunkycharts.traditionalchart.TraditionalChartFragmentAdapter.java
com.jogden.spunkycharts.traditionalchart.TraditionalChartFragment.java
com.jogden.spunkycharts.traditionalchart.TraditionalChartPanel.java
com.jogden.spunkycharts.traditionalchart.TraditionalChartPreferences.java
com.jogden.spunkycharts.traditionalchart.XAxisTimeLabel.java
com.jogden.spunkycharts.traditionalchart.YAxisPriceLabel.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemanticsA_C.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemanticsA.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemantics_CANDLE.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemantics_LINE.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemantics_OC.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemantics_OHLC.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemantics_POINT.java
com.jogden.spunkycharts.traditionalchart.draw.DrawSemantics_SILO.java