whitespace COMPANY whitespace SERVICES whitespace PRODUCTS whitespace PURCHASE whitespace SUPPORT whitespace CONTACTS whitespace Home whitespace Contact Us whitespace Site Map whitespace
whitespace
WHY ARTFULBITS
whitespace
OUR APPROACH
whitespace
OUR TEAM
whitespace
FACT SHEET
whitespace
NEWS & EVENTS
whitespace
PRIVACY
whitespace
whitespace

Widget Sample

Overview

This sample demonstrates how to add chart to the widget.

zip archive Download sample

<?xml version="1.0" encoding="utf-8"?>
<ImageView
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:id="@+id/imageView"
	android:background="@android:drawable/alert_dark_frame"
	android:scaleType="centerInside"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent">
</ImageView>
package com.artfulbits.aiCharts.WidgetSample;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.graphics.Bitmap;
import android.widget.RemoteViews;

import com.artfulbits.aiCharts.Base.ChartArea;
import com.artfulbits.aiCharts.Base.ChartEngine;
import com.artfulbits.aiCharts.Base.ChartSeries;
import com.artfulbits.aiCharts.Types.ChartTypes;

public class ChartWidgetProvider extends AppWidgetProvider
{
	@Override
	public void onUpdate(Context context, AppWidgetManager appWidgetManager,
			int[] appWidgetIds)
	{
		for (int appWidgetId : appWidgetIds)
		{
			RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
			
			views.setImageViewBitmap(R.id.imageView, getChartImage(context));
			
			appWidgetManager.updateAppWidget(appWidgetId, views);
		}
		
		super.onUpdate(context, appWidgetManager, appWidgetIds);
	}
	
	private Bitmap getChartImage(Context context)
	{
		int width = context.getResources().getDimensionPixelSize(R.dimen.chart_width);
		int height = context.getResources().getDimensionPixelSize(R.dimen.chart_height);

		Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

		ChartEngine chart = new ChartEngine();
		ChartSeries series = new ChartSeries(ChartTypes.Area);

		chart.getAreas().add(new ChartArea());
		series.getPoints().setData(new double[]{ 10, 30, 20, 40, 60});
		chart.getSeries().add(series);
		chart.save(bmp, true);
		
		return bmp; 
	}
}
No code
Company | Services | Practices | Technologies | Career | Contacts | Privacy
© 2005-2016 ArtfulBits. All rights reserved.