WidgetConfig.java :  » Widget » wetherwidget » de » sdw » android » weather » widget » Android Open Source

Android Open Source » Widget » wetherwidget 
wetherwidget » de » sdw » android » weather » widget » WidgetConfig.java
/**
 * 
 */
package de.sdw.android.weather.widget;

import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import de.sdw.android.weather.R;

/**
 * @author Steffen David Weber
 * 
 */
public class WidgetConfig extends Activity {

  EditText location;
  Button saveButton;
  int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    Log.d(WeatherWidget.TAG_WEATHER, "Creation of WeatherConfig view started.");
    super.onCreate(savedInstanceState);
  
    // Set the result to CANCELED. This will cause the widget host to cancel
    // out of the widget placement if they press the back button.
    setResult(RESULT_CANCELED);

    // Set the view layout resource to use.
    setContentView(R.layout.widget_config);

    location = (EditText) findViewById(R.id.PostCodeField);

    saveButton = (Button) findViewById(R.id.SaveSettings);

    saveButton.setOnClickListener(createOnClickListener());

    // Find the widget id from the intent.
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
      appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
          AppWidgetManager.INVALID_APPWIDGET_ID);
    }

    // If they gave us an intent without the widget id, just bail.
    if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
      finish();
    }

  }

  private OnClickListener createOnClickListener() {
    return new View.OnClickListener() {
      public void onClick(View v) {

        Intent resultValue = new Intent();        
        if (location.getText().length() > 0) {
            int value = Integer.valueOf(location.getText().toString());
            Log.d(WeatherWidget.TAG_WEATHER, "New location for widget" + appWidgetId + " : " + value);
            WeatherWidget.setPLZ(v.getContext(), appWidgetId, value);
            WeatherWidget.updateView(v.getContext(), new int[]{appWidgetId});
        }
        // Make sure we pass back the original appWidgetId
        resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        setResult(RESULT_OK, resultValue);
        finish();
      }
    };
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.