WeekSelector.java revision d72c7f5d49d1c1c1afa281459d18318390400611
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 com.android.internal.widget.VerticalTextSpinner;
20
21import android.app.Activity;
22import android.content.ContentResolver;
23import android.content.ContentValues;
24import android.database.Cursor;
25import android.media.AudioManager;
26import android.net.Uri;
27import android.os.Bundle;
28import android.provider.MediaStore;
29import android.text.TextWatcher;
30import android.util.Log;
31import android.view.KeyEvent;
32import android.view.View;
33import android.view.Window;
34import android.view.WindowManager;
35import android.widget.Button;
36import android.widget.EditText;
37import android.widget.TextView;
38
39public class WeekSelector extends Activity
40{
41    VerticalTextSpinner mWeeks;
42
43    @Override
44    public void onCreate(Bundle icicle) {
45        super.onCreate(icicle);
46        setVolumeControlStream(AudioManager.STREAM_MUSIC);
47
48        requestWindowFeature(Window.FEATURE_NO_TITLE);
49        setContentView(R.layout.weekpicker);
50        getWindow().setLayout(WindowManager.LayoutParams.FILL_PARENT,
51                                    WindowManager.LayoutParams.WRAP_CONTENT);
52
53        mWeeks = (VerticalTextSpinner)findViewById(R.id.weeks);
54        mWeeks.setItems(getResources().getStringArray(R.array.weeklist));
55        mWeeks.setWrapAround(false);
56        mWeeks.setScrollInterval(200);
57
58        int def = MusicUtils.getIntPref(this, "numweeks", 2);
59        int pos = icicle != null ? icicle.getInt("numweeks", def - 1) : def - 1;
60        mWeeks.setSelectedPos(pos);
61
62        ((Button) findViewById(R.id.set)).setOnClickListener(mListener);
63
64        ((Button) findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
65            public void onClick(View v) {
66                setResult(RESULT_CANCELED);
67                finish();
68            }
69        });
70    }
71
72    @Override
73    public void onSaveInstanceState(Bundle outcicle) {
74        outcicle.putInt("numweeks", mWeeks.getCurrentSelectedPos());
75    }
76
77    @Override
78    public void onResume() {
79        super.onResume();
80    }
81
82    private View.OnClickListener mListener = new View.OnClickListener() {
83        public void onClick(View v) {
84            int numweeks = mWeeks.getCurrentSelectedPos() + 1;
85            MusicUtils.setIntPref(WeekSelector.this, "numweeks", numweeks);
86            setResult(RESULT_OK);
87            finish();
88        }
89    };
90}
91