Duvida com relação a Widgets

0 respostas
M

Bom caras, to começando a mexer com Widgets aqui no android e to com um pouco de dificuldade, segui um tutorial aqui explicando o básico, consegui fazer rodar certinho, mas quando fui mexer ele pra fazer oque eu quero, vieram meus problemas...

Seguinte, tenho um ImageButton que o meu objetivo é simplesmente alterar a imagem dele quando o usuário clicar, bom, vamos ao que eu fiz:

public class HelloWidget extends AppWidgetProvider {
	public static String ACTION_WIDGET_CONFIGURE = "ConfigureWidget";
	public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";

	
	@Override
	public void onUpdate(Context context, AppWidgetManager appWidgetManager,
			int[] appWidgetIds) {
		RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
				R.layout.main);
		Intent configIntent = new Intent(context, ClickOneActivity.class);
		configIntent.setAction(ACTION_WIDGET_CONFIGURE);
		Intent active = new Intent(context, HelloWidget.class);
		active.setAction(ACTION_WIDGET_RECEIVER);
		PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context,
				0, active, 0);
		PendingIntent configPendingIntent = PendingIntent.getActivity(context,
				0, configIntent, 0);
		remoteViews.setOnClickPendingIntent(R.id.button_wifi,
				actionPendingIntent);
		remoteViews.setOnClickPendingIntent(R.id.button_two,
				configPendingIntent);
		appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		// v1.5 fix that doesn't call onDelete Action
		final String action = intent.getAction();
		if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
			final int appWidgetId = intent.getExtras().getInt(
					AppWidgetManager.EXTRA_APPWIDGET_ID,
					AppWidgetManager.INVALID_APPWIDGET_ID);
			if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
				this.onDeleted(context, new int[] { appWidgetId });
			}
		} else {
			// check, if our Action was called
			if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
				Toast.makeText(context, "Teste", Toast.LENGTH_LONG).show();
				RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
				remoteViews.setInt(R.id.button_wifi, "toogleOnOff", R.drawable.icon);
				
			}
			super.onReceive(context, intent);
		}

	}
}

Boa parte do código é do tutorial que eu segui, e acho que não peguei como funciona a parte de RemoteView e Intent. Pelo oq eu entendi o RemoteView é como se eu estivesse na view(no caso a o main.xml) e tenho acesso ao seus membros. E o Intent realmente não entendi muito bem como funciona, ele meio que prepara o ambiente pra algo que pode acontecer? É isso?

Quem puder me dar uma mão ai, agradeço desde já =)

Criado 1 de outubro de 2011
Respostas 0
Participantes 1