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