WeekSelector.java revision 6cb8bc92e0ca524a76a6fa3f6814b43ea9a3b30d
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
65    @Override
66    public void onSaveInstanceState(Bundle outcicle) {
67        outcicle.putInt("numweeks", mWeeks.getCurrentSelectedPos());
68    }
69
70    @Override
71    public void onResume() {
72        super.onResume();
73    }
74
75    private View.OnClickListener mListener = new View.OnClickListener() {
76        public void onClick(View v) {
77            int numweeks = mWeeks.getCurrentSelectedPos() + 1;
78            MusicUtils.setIntPref(WeekSelector.this, "numweeks", numweeks);
79            setResult(RESULT_OK);
80            finish();
81        }
82    };
83}
84