/******************************************************************************* * Copyright (c) 2011 Michel DAVID mimah35-at-gmail.com * * This program 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 3 of the License. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ package fr.gotorennes; import android.app.Activity; import android.appwidget.AppWidgetManager; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.Button; public class ClockActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.clock_popup); final SharedPreferences prefs = getSharedPreferences("fr.gotorennes.BikeWidget", 0); final int appWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0); Button reinit = (Button) findViewById(R.id.buttonInit); reinit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { prefs.edit().putInt("timeLeft" + appWidgetId, 30).commit(); resetWidgetAlarm(appWidgetId); finish(); } }); Button stop = (Button) findViewById(R.id.buttonStop); stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { prefs.edit().putInt("timeLeft" + appWidgetId, -1).commit(); resetWidgetAlarm(appWidgetId); finish(); } }); } protected void resetWidgetAlarm(int widgetId) { Intent intent = new Intent(this, BikeWidgetProvider.class); intent.setAction(BikeWidgetProvider.RESET); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId); sendBroadcast(intent); } }