Android Open Source - Link-Schedule Bus Stop Widget Configure






From Project

Back to project page Link-Schedule.

License

The source code is released under:

GNU General Public License

If you think the Android project Link-Schedule 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

/**
 * Copyright 2011 Kurtis Nusbaum//ww w . j av  a 2s . c o  m
 *
 * This file is part of LinkSchedule.  
 *
 * LinkSchedule 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 2 of the 
 * License, or (at your option) any later version.  
 *
 * LinkSchedule 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 LinkSchedule. If not, see 
 * http://www.gnu.org/licenses/.
 */

package org.klnusbaum.linkschedule;

import android.app.ListActivity;
import android.os.Bundle;
import android.content.Intent;
import android.content.Context;
import android.view.View;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.RemoteViews;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.appwidget.AppWidgetManager;

import java.util.ArrayList;

/**
 * Class used for configureing a BusStopWidget 
 *
 * @author Kurtis Nusbaum
 * @version 1.0
 */
public class BusStopWidgetConfigure extends ListActivity{

  /** 
   * Id of the widget being configured.
   */
  int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;

  @Override
  public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setResult(RESULT_CANCELED);
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if(extras != null) {
      appWidgetId = extras.getInt(
        AppWidgetManager.EXTRA_APPWIDGET_ID, 
        AppWidgetManager.INVALID_APPWIDGET_ID);
    }
    if(appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
      finish();
    }
    
    ArrayList<String> stops = new ArrayList<String>();
    stops.add(getString(R.string.flynntown_name));
    stops.add(getString(R.string.gorecki_name));
    stops.add(getString(R.string.hcc_name));
    stops.add(getString(R.string.sexton_name));

    setListAdapter(new ArrayAdapter<String>(
      this,
      R.layout.bus_stop_configure,
      stops));


    getListView().setOnItemClickListener(new OnItemClickListener(){
      public void onItemClick(AdapterView<?> parent, View view,
        int position, long id)
      {
        String selectedBusStop = 
          ((ArrayAdapter<String>)parent.getAdapter()).getItem(position);
        /*SharedPreferences settings = getSharedPreferences(
          BusStopWidgetProvider.PREF_FILE_NAME, MODE_PRIVATE);*/
        SharedPreferences settings = 
          PreferenceManager.getDefaultSharedPreferences(BusStopWidgetConfigure.this);
        boolean showTimeTill = settings.getBoolean(
            getString(R.string.show_timetill_widget_key), false);
        SharedPreferences.Editor prefEditor = settings.edit();
        prefEditor.putString(String.valueOf(appWidgetId), selectedBusStop);
        prefEditor.commit();
        AppWidgetManager widgetManager = 
        AppWidgetManager.getInstance(BusStopWidgetConfigure.this);
        RemoteViews views = BusStopWidgetProvider.getWidgetView(
          BusStopWidgetConfigure.this, 
          selectedBusStop, 
          showTimeTill ? LinkSchedule.getCalendarInstance() : null);
        widgetManager.updateAppWidget(appWidgetId, views);
        Intent result = new Intent();
        result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        setResult(RESULT_OK, result);
        finish();  
      }
    });
      
  }



}




Java Source Code List

org.klnusbaum.linkschedule.AlarmReceiver.java
org.klnusbaum.linkschedule.BusStopActivity.java
org.klnusbaum.linkschedule.BusStopWidgetConfigure.java
org.klnusbaum.linkschedule.BusStopWidgetProvider.java
org.klnusbaum.linkschedule.CalendarBackedView.java
org.klnusbaum.linkschedule.ClockView.java
org.klnusbaum.linkschedule.DaySchedule.java
org.klnusbaum.linkschedule.LinkSchedule.java
org.klnusbaum.linkschedule.OmniScheduleActivity.java
org.klnusbaum.linkschedule.Refreshable.java
org.klnusbaum.linkschedule.SingleStopActivity.java
org.klnusbaum.linkschedule.StopTimeView.java
org.klnusbaum.linkschedule.TimeChangeReceiver.java
org.klnusbaum.linkschedule.TimeTransform.java
org.klnusbaum.linkschedule.XMLPreferencesActivity.java