WeekSelector.java revision 51f94bf279c71350e932cd139cf8d769c40030c3
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.music; 18 19import android.app.Activity; 20import android.content.ContentResolver; 21import android.content.ContentValues; 22import android.database.Cursor; 23import android.media.AudioManager; 24import android.net.Uri; 25import android.os.Bundle; 26import android.provider.MediaStore; 27import android.text.TextWatcher; 28import android.util.Log; 29import android.view.KeyEvent; 30import android.view.View; 31import android.view.Window; 32import android.view.WindowManager; 33import android.widget.Button; 34import android.widget.EditText; 35import android.widget.TextView; 36 37public class WeekSelector extends Activity 38{ 39 VerticalTextSpinner mWeeks; 40 41 @Override 42 public void onCreate(Bundle icicle) { 43 super.onCreate(icicle); 44 setVolumeControlStream(AudioManager.STREAM_MUSIC); 45 46 requestWindowFeature(Window.FEATURE_NO_TITLE); 47 setContentView(R.layout.weekpicker); 48 getWindow().setLayout(WindowManager.LayoutParams.FILL_PARENT, 49 WindowManager.LayoutParams.WRAP_CONTENT); 50 51 mWeeks = (VerticalTextSpinner)findViewById(R.id.weeks); 52 mWeeks.setItems(getResources().getStringArray(R.array.weeklist)); 53 mWeeks.setWrapAround(false); 54 mWeeks.setScrollInterval(200); 55 56 int def = MusicUtils.getIntPref(this, "numweeks", 2); 57 int pos = icicle != null ? icicle.getInt("numweeks", def - 1) : def - 1; 58 mWeeks.setSelectedPos(pos); 59 60 ((Button) findViewById(R.id.set)).setOnClickListener(mListener); 61 62 ((Button) findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() { 63 public void onClick(View v) { 64 setResult(RESULT_CANCELED); 65 finish(); 66 } 67 }); 68 } 69 70 @Override 71 public void onSaveInstanceState(Bundle outcicle) { 72 outcicle.putInt("numweeks", mWeeks.getCurrentSelectedPos()); 73 } 74 75 @Override 76 public void onResume() { 77 super.onResume(); 78 } 79 80 private View.OnClickListener mListener = new View.OnClickListener() { 81 public void onClick(View v) { 82 int numweeks = mWeeks.getCurrentSelectedPos() + 1; 83 MusicUtils.setIntPref(WeekSelector.this, "numweeks", numweeks); 84 setResult(RESULT_OK); 85 finish(); 86 } 87 }; 88} 89