• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.music;
18 
19 import android.app.Activity;
20 import android.media.AudioManager;
21 import android.os.Bundle;
22 import android.view.View;
23 import android.view.Window;
24 import android.view.WindowManager;
25 import android.widget.Button;
26 
27 public class WeekSelector extends Activity {
28     VerticalTextSpinner mWeeks;
29 
30     @Override
onCreate(Bundle icicle)31     public void onCreate(Bundle icicle) {
32         super.onCreate(icicle);
33         setVolumeControlStream(AudioManager.STREAM_MUSIC);
34 
35         requestWindowFeature(Window.FEATURE_NO_TITLE);
36         setContentView(R.layout.weekpicker);
37         getWindow().setLayout(
38                 WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
39 
40         mWeeks = (VerticalTextSpinner) findViewById(R.id.weeks);
41         mWeeks.setItems(getResources().getStringArray(R.array.weeklist));
42         mWeeks.setWrapAround(false);
43         mWeeks.setScrollInterval(200);
44 
45         int def = MusicUtils.getIntPref(this, "numweeks", 2);
46         int pos = icicle != null ? icicle.getInt("numweeks", def - 1) : def - 1;
47         mWeeks.setSelectedPos(pos);
48 
49         ((Button) findViewById(R.id.set)).setOnClickListener(mListener);
50 
51         ((Button) findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
52             public void onClick(View v) {
53                 setResult(RESULT_CANCELED);
54                 finish();
55             }
56         });
57     }
58 
59     @Override
onSaveInstanceState(Bundle outcicle)60     public void onSaveInstanceState(Bundle outcicle) {
61         outcicle.putInt("numweeks", mWeeks.getCurrentSelectedPos());
62     }
63 
64     @Override
onResume()65     public void onResume() {
66         super.onResume();
67     }
68 
69     private View.OnClickListener mListener = new View.OnClickListener() {
70         public void onClick(View v) {
71             int numweeks = mWeeks.getCurrentSelectedPos() + 1;
72             MusicUtils.setIntPref(WeekSelector.this, "numweeks", numweeks);
73             setResult(RESULT_OK);
74             finish();
75         }
76     };
77 }
78