package com.gm.profile.activity;
import java.util.Date;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TimePicker;
public class ProfileActivity extends TabActivity {
private static final String TAG="ProfileActivity";
private RadioGroup mRadioGroup01 = null;
private RadioGroup mRadioGroup02 = null;
private TabHost mTabHost = null;
private int mTab = 0; //标记当前标签卡的索引号
private boolean isRadioButtonChecked = false; //标记RadioButton有没有被选择
private AlarmManager mAlarmManager = null;
private TimePicker mTimePicker = null;
private ImageView myImageView;
private ImageButton downButton;
private ImageButton upButton;
private ImageButton normalButton;
private ImageButton muteButton;
private ImageButton vibrateButton;
private ProgressBar myProgress;
private AudioManager audioMa;
private int volume = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mRadioGroup01 = (RadioGroup)findViewById(R.id.RadioGroup01);
mRadioGroup02 = (RadioGroup)findViewById(R.id.RadioGroup02);
//初始化,取得AudioManager
audioMa = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
myImageView = (ImageView)findViewById(R.id.myImage);
myProgress = (ProgressBar)findViewById(R.id.myProgress);
downButton = (ImageButton)findViewById(R.id.downButton);
upButton = (ImageButton)findViewById(R.id.upButton);
normalButton = (ImageButton)findViewById(R.id.normalButton);
muteButton = (ImageButton)findViewById(R.id.muteButton);
vibrateButton = (ImageButton)findViewById(R.id.vibrateButton);
//取得TabHost对象
mTabHost = getTabHost();
//设置TabHost的背景图片资源
mTabHost.setBackgroundResource(R.drawable.bg);
/**
* 为TabHost添加标签
* 首先新建一个newTabSpec
* 设置其标签和图标 setIndicator
* 设置内容 setContent
*/
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setContent(R.id.RadioGroup01).setIndicator("普通情景模式", getResources().getDrawable(R.drawable.icon)));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setContent(R.id.RadioGroup02).setIndicator("定时情景模式", getResources().getDrawable(R.drawable.timeprofile)));
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setContent(R.id.AbsoluteLayout03).setIndicator("自定义情景模式", getResources().getDrawable(R.drawable.addprofile)));
//设置TabHost默认显示哪个标签
mTabHost.setCurrentTab(0);
//更新情景模式
updateRadioGroup();
//标签切换事件处理
mTabHost.setOnTabChangedListener(new OnTabChangeListener(){
@Override
public void onTabChanged(String tabId) {
Log.i(TAG, "----标签切换事件处理 mTabHost.setOnTabChangedListener---");
if(tabId.equals("tab_test1")){
mTab = 0;
mAlarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
mTimePicker = (TimePicker)findViewById(R.id.timePkr);
mTimePicker.setIs24HourView(true);
updateRadioGroup();
}else if(tabId.equals("tab_test2")){
mTab = 1;
mAlarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
mTimePicker = (TimePicker)findViewById(R.id.timePkr);
mTimePicker.setIs24HourView(true);
updateRadioGroup();
}
}
});
//设置RadioGroup的事件监听器
mRadioGroup01.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Log.i(TAG, "----RadioGroup的事件监听器-- mRadioGroup01.setOnCheckedChangeListener--");
if(isRadioButtonChecked){
return ;
}
Log.i(TAG, "----你点击是的是第 "+checkedId+" RadioButton");
switch(checkedId){
case R.id.ring_and_vibrate01:
ringAndVibrate();
break;
case R.id.ring01:
ring();
break;
case R.id.vibrate01:
vibrate();
break;
case R.id.silent01:
silent();
break;
}
RadioButton radioButton = (RadioButton)findViewById(checkedId);
if(radioButton != null ){
radioButton.setTextSize(30);
}
}
});
//RadioButton添加监听器
for(int i = 0 ,l= mRadioGroup01.getChildCount(); i < l;i++){
RadioButton radioButton = (RadioButton)mRadioGroup01.getChildAt(i);
radioButton.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
RadioButton radioButton = (RadioButton)v;
if(!radioButton.isChecked()){
return false;
}else{
Log.i(TAG, "----我被选中了---");
radioButton.setTextSize(30);
return true; //对结果无影响
}
}
});
}
//添加onChangeListener
mRadioGroup02.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Log.i(TAG, "----RadioGroup的事件监听器-- mRadioGroup02.setOnCheckedChangeListener--");
if(isRadioButtonChecked){
return ;
}
Log.i(TAG, "----你点击是的是第 "+checkedId+" RadioButton");
switch(checkedId){
case R.id.ring_and_vibrate02:
ringAndVibrate();
break;
case R.id.ring02:
ring();
break;
case R.id.vibrate02:
vibrate();
break;
case R.id.silent02:
silent();
break;
}
RadioButton radioButton = (RadioButton)findViewById(checkedId);
if(radioButton != null){
radioButton.setTextSize(30);
}
}
});
//RadioButton 添加监听器
for(int i = 0 ,l= mRadioGroup02.getChildCount(); i < l;i++){
RadioButton radioButton = (RadioButton)mRadioGroup02.getChildAt(i);
radioButton.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
RadioButton radioButton01 = (RadioButton)v;
if(!radioButton01.isChecked()){
return false;
}else{
Log.i(TAG, "-----RadioButton 添加监听器---我被选中了---");
radioButton01.setTextSize(30);
return true;
}
}
});
}
//第三个切换卡的设置
//取得手机的初始音量
volume = audioMa.getStreamVolume(AudioManager.STREAM_RING);
//设置音量进度条
myProgress.setProgress(volume);
//取得初始模式,并分别设置图标
int mode = audioMa.getRingerMode();
if(mode == AudioManager.RINGER_MODE_NORMAL){
myImageView.setImageDrawable(getResources().getDrawable(R.drawable.icon));
}else if(mode == AudioManager.RINGER_MODE_SILENT){
myImageView.setImageDrawable(getResources().getDrawable(R.drawable.mute));
}else if(mode == AudioManager.RINGER_MODE_VIBRATE){
myImageView.setImageDrawable(getResources().getDrawable(R.drawable.vibrate));
}
//降低音量按键事件监听器
downButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
//adjustVolume可以增加和降低音量AD