Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement on line graph views: #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<activity android:name="CustomLabelFormatterActivity"></activity>
<activity android:name="OwnModelAsData"></activity>
<activity android:name="NegativeValuesGraph"></activity>

<activity android:name="com.jjoe64.graphviewdemos.dataselection.SampleSeriesDemoActivity"></activity>

</application>
</manifest>
35 changes: 35 additions & 0 deletions res/layout/activity_garmin_series_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SampleSeriesDemoActivity" >

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>

<LinearLayout
android:id="@+id/graph1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1" />

<Spinner
android:layout_weight="1"
android:id="@+id/graphSeries"
android:layout_width="wrap_content"
android:layout_height="100dip"
android:layout_alignLeft="@+id/linearLayout1"
android:layout_below="@+id/linearLayout1"
android:layout_marginLeft="17dp" />
</LinearLayout>

</RelativeLayout>
5 changes: 5 additions & 0 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,10 @@
android:layout_height="wrap_content"
android:id="@+id/btn_negativevalues"
android:text="Negative Values" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/btn_sampleSelection"
android:text="Sample Selection" />
</LinearLayout>
</ScrollView>
9 changes: 9 additions & 0 deletions res/menu/garmin_series_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>

</menu>
8 changes: 8 additions & 0 deletions res/values-sw600dp/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<resources>

<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw600dp devices (e.g. 7" tablets) here.
-->

</resources>
9 changes: 9 additions & 0 deletions res/values-sw720dp-land/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<resources>

<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
-->
<dimen name="activity_horizontal_margin">128dp</dimen>

</resources>
7 changes: 7 additions & 0 deletions res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<resources>

<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>

</resources>
5 changes: 5 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="hello">Hello World, SimpleGraph!</string>
<string name="app_name">GraphViewDemos</string>
<string name="title_activity_sample_series_demo">Data selection example</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>

</resources>
62 changes: 62 additions & 0 deletions src/com/jjoe64/graphviewdemos/ColorUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2013 by Garmin Ltd. or its subsidiaries.
*/

package com.jjoe64.graphviewdemos;

/**
* @author becze
*
*/
public class ColorUtil {
// ------------------------------------------------------------------------
// TYPES
// ------------------------------------------------------------------------

// ------------------------------------------------------------------------
// STATIC FIELDS
// ------------------------------------------------------------------------

// ------------------------------------------------------------------------
// STATIC INITIALIZERS
// ------------------------------------------------------------------------

// ------------------------------------------------------------------------
// STATIC METHODS
// ------------------------------------------------------------------------

/**
* Changes the alpha component of the given color to the newAlpha value.
* @param color the input color
* @param newAlpha the alpha component between the values [0, 255]
* @return the new color
*/
public static int changeColorAlpha(int color, int newAlpha) {

int mask = 0xFF;
int a = (color >> 24) & mask;
int r = (color >> 16) & mask;
int g = (color >> 8) & mask;
int b = color & mask;

// Put it all back in place
return (newAlpha << 24) + (r << 16) + (g << 8) + b;

}

// ------------------------------------------------------------------------
// FIELDS
// ------------------------------------------------------------------------

// ------------------------------------------------------------------------
// INITIALIZERS
// ------------------------------------------------------------------------

// ------------------------------------------------------------------------
// CONSTRUCTORS
// ------------------------------------------------------------------------

// ------------------------------------------------------------------------
// METHODS
// ------------------------------------------------------------------------
}
8 changes: 8 additions & 0 deletions src/com/jjoe64/graphviewdemos/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jjoe64.graphviewdemos;

import com.jjoe64.graphviewdemos.dataselection.SampleSeriesDemoActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
Expand Down Expand Up @@ -69,6 +71,12 @@ public void onClick(View v) {
startGraphActivity(NegativeValuesGraph.class);
}
});
((Button) findViewById(R.id.btn_sampleSelection)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startGraphActivity(SampleSeriesDemoActivity.class);
}
});
}

private void startGraphActivity(Class<? extends Activity> activity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (C) 2013 by Garmin Ltd. or its subsidiaries.
*/

package com.jjoe64.graphviewdemos.dataselection;

import com.jjoe64.graphview.GraphViewDataInterface;

/**
* @author becze
*/
public class SampleGraphViewData implements GraphViewDataInterface {

// ------------------------------------------------------------------------
// TYPES
// ------------------------------------------------------------------------

// ------------------------------------------------------------------------
// STATIC FIELDS
// ------------------------------------------------------------------------

// ------------------------------------------------------------------------
// STATIC INITIALIZERS
// ------------------------------------------------------------------------

// ------------------------------------------------------------------------
// STATIC METHODS
// ------------------------------------------------------------------------

// ------------------------------------------------------------------------
// FIELDS
// ------------------------------------------------------------------------
private double x;

private double y;


// The parent series where this data value belongs to.
private SampleGraphViewSeries parentSeries;

// ------------------------------------------------------------------------
// INITIALIZERS
// ------------------------------------------------------------------------

// ------------------------------------------------------------------------
// CONSTRUCTORS
// ------------------------------------------------------------------------
/**
* Makes a new sample.
*
* @param parentSeries the series where the data element will belong to.
* @param x the value on the x axes (horizontal axes)
* @param y the value on the y axes (the vertical axes)
*/
public SampleGraphViewData(SampleGraphViewSeries parentSeries, double x, double y) {
this.parentSeries = parentSeries;
this.x = x;
this.y = y;
}

// ------------------------------------------------------------------------
// METHODS
// ------------------------------------------------------------------------
/**
* Just simply return the stored X value. We don't have to scale it.
*
* @return
* @see com.jjoe64.graphview.GraphViewDataInterface#getX()
*/
@Override
public double getX() {
return x;
}

/**
* This value is scaled down to fit between the [-1, 1] interval. we will
* use the parent series max. value and min. value to determine it.
*
* @return
* @see com.jjoe64.graphview.GraphViewDataInterface#getY()
*/
@Override
public double getY() {
return y/parentSeries.getMaxScaleSize();
}

/**
* Setter for Y
* @param y
*/
public void setY(double y) {
this.y = y;
}
}
Loading