Java tutorial
/* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mstar.tv.tvplayer.philips.setting; import com.mstar.tv.tvplayer.kangguan.tvapi.K_Constants; import com.mstar.tv.tvplayer.kangguan.tvapi.K_SettingModel; import com.mstar.tv.tvplayer.kangguan.tvapi.K_TvAudioManager; import com.mstar.tv.tvplayer.kangguan.tvapi.K_TvCommonManager; import com.mstar.tv.tvplayer.kangguan.tvapi.K_TvPictureManager; import com.mstar.tv.tvplayer.kangguan.tvapi.K_TvTimerManager; import com.mstar.tv.tvplayer.ui.R; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnKeyListener; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; public class SettingSliderFragment extends Fragment { // ThreeFragmentSelectedListener mCallback; private TextView vseekbar_title; private TextView progressVal; private Philips_Setting_VerticalSeekBar seekBar; private ImageView up_img; private ImageView down_img; private int currentIndex = 0; private String TAG = "ThreeFragment"; private int firstSelect; private Context mCotext; private boolean mIsPicShift = false; private TextView cursor_top; private TextView cursor_center; private TextView cursor_button; protected int sleepMode = 0; /* * public interface ThreeFragmentSelectedListener { public void * onThreeSelectedData(int dataPositon); } */ @Override public void onCreate(Bundle savedInstanceState) { mCotext = getActivity(); super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.setting_seekbar_layout, null); seekBar = (Philips_Setting_VerticalSeekBar) view.findViewById(R.id.vseekbar); seekBar.setMax(100); seekBar.setThumb(null); seekBar.setProgressDrawable(getResources().getDrawable(R.drawable.setting_vseekbar_progress_bg)); cursor_top = (TextView) view.findViewById(R.id.cursor_top); cursor_center = (TextView) view.findViewById(R.id.cursor_center); cursor_button = (TextView) view.findViewById(R.id.cursor_button); progressVal = (TextView) view.findViewById(R.id.vseekbar_text); vseekbar_title = (TextView) view.findViewById(R.id.vseekbar_title); up_img = (ImageView) view.findViewById(R.id.up_image); down_img = (ImageView) view.findViewById(R.id.down_image); return view; } @Override public void onStart() { super.onStart(); } @Override public void onHiddenChanged(boolean hidden) { super.onHiddenChanged(hidden); if (hidden) { seekBar.setFocusable(false); } else { seekBar.setFocusable(true); seekBar.requestFocus(); } } @Override public void onAttach(Activity activity) { super.onAttach(activity); } public void updateView(String data, int dataPositon, boolean isPicShift) { firstSelect = TvSettingMenuActivity.firstSelectPositon; mIsPicShift = isPicShift; if (firstSelect == SettingKarrays.SETTING_PHOTO) { if (mIsPicShift) { //??? switch (dataPositon) { case 0: currentIndex = K_TvPictureManager.getInstance().K_getPCHPos(); Log.v(TAG, "=========hpos===currentIndex=" + currentIndex); break; case 1: currentIndex = K_TvPictureManager.getInstance().K_getPCVPos(); Log.v(TAG, "=========vpos===currentIndex=" + currentIndex); break; case 2: currentIndex = K_TvPictureManager.getInstance().K_getPCClock(); Log.v(TAG, "=========clock===currentIndex=" + currentIndex); break; case 3: currentIndex = K_TvPictureManager.getInstance().K_getPCPhase(); Log.v(TAG, "=========phase===currentIndex=" + currentIndex); break; default: break; } } else { switch (dataPositon) { case 1: currentIndex = K_TvPictureManager.getInstance().K_getVideoItem(K_Constants.PICTURE_CONTRAST); break; case 2: currentIndex = K_TvPictureManager.getInstance().K_getVideoItem(K_Constants.PICTURE_BRIGHTNESS); break; case 3: currentIndex = K_TvPictureManager.getInstance().K_getVideoItem(K_Constants.PICTURE_SATURATION); break; case 4: currentIndex = K_TvPictureManager.getInstance().K_getVideoItem(K_Constants.PICTURE_SHARPNESS); break; default: break; } } } else if (firstSelect == SettingKarrays.SETTING_SOUND) { switch (dataPositon) { case 1: currentIndex = K_TvAudioManager.getInstance().K_getBass(); break; case 2: currentIndex = K_TvAudioManager.getInstance().K_getTreble(); ; break; case 3: currentIndex = K_TvAudioManager.getInstance().K_getBalance(); break; default: break; } } else if (firstSelect == SettingKarrays.SETTING_ECO) { switch (dataPositon) { case 1: currentIndex = K_SettingModel.getInstance().K_getAjustBacklightIndex(mCotext); break; default: break; } } else if (firstSelect == SettingKarrays.SETTING_TV) { switch (dataPositon) { case 4: currentIndex = getSleepModeProgressIndex(); break; default: break; } } if (firstSelect == SettingKarrays.SETTING_TV && dataPositon == 4) { vseekbar_title.setText(data + mCotext.getResources().getString(R.string.minute)); seekBar.setMax(240); cursor_top.setText(240 + ""); cursor_center.setText(120 + ""); cursor_button.setText("0"); } else if (firstSelect == SettingKarrays.SETTING_SOUND && dataPositon == 3) { vseekbar_title.setText(data); seekBar.setMax(100); cursor_top.setText("R50"); cursor_center.setText("0"); cursor_button.setText("L50"); } else { vseekbar_title.setText(data); seekBar.setMax(100); cursor_top.setText(100 + ""); cursor_center.setText(50 + ""); cursor_button.setText("0"); } seekBar.setProgress(currentIndex); if (firstSelect == SettingKarrays.SETTING_SOUND && dataPositon == 3) { if (seekBar.getProgress() < 50) { progressVal.setText("L" + (50 - seekBar.getProgress())); } else if (seekBar.getProgress() == 50) { progressVal.setText("0"); } else { progressVal.setText("R" + (seekBar.getProgress() - 50)); } } else { progressVal.setText(String.valueOf(seekBar.getProgress())); } up_img.setBackgroundResource(R.drawable.slider_arrow_up_highlighted); down_img.setBackgroundResource(R.drawable.slider_arrow_down_highlighted); final int flag = dataPositon; seekBar.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View arg0, int keyCode, KeyEvent keyevent) { if (keyevent.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (firstSelect == SettingKarrays.SETTING_SOUND && flag == 3) { seekBar.incrementProgressBy(1); if (seekBar.getProgress() < 50) { progressVal.setText("L" + (50 - seekBar.getProgress())); } else if (seekBar.getProgress() == 50) { progressVal.setText("0"); } else { progressVal.setText("R" + (seekBar.getProgress() - 50)); } } else if (firstSelect == SettingKarrays.SETTING_TV && flag == 4) { setSleepModeProgress(true); } else { seekBar.incrementProgressBy(1); progressVal.setText(String.valueOf(seekBar.getProgress())); } up_img.setBackgroundResource(R.drawable.slider_arrow_up_pressed); down_img.setBackgroundResource(R.drawable.slider_arrow_down_highlighted); updateSeekbarData(flag, seekBar); return true; case KeyEvent.KEYCODE_DPAD_DOWN: if (firstSelect == SettingKarrays.SETTING_SOUND && flag == 3) { seekBar.incrementProgressBy(-1); if (seekBar.getProgress() < 50) { progressVal.setText("L" + (50 - seekBar.getProgress())); } else if (seekBar.getProgress() == 50) { progressVal.setText("0"); } else { progressVal.setText("R" + (seekBar.getProgress() - 50)); } } else if (firstSelect == SettingKarrays.SETTING_TV && flag == 4) { setSleepModeProgress(false); } else { seekBar.incrementProgressBy(-1); progressVal.setText(String.valueOf(seekBar.getProgress())); } up_img.setBackgroundResource(R.drawable.slider_arrow_up_highlighted); down_img.setBackgroundResource(R.drawable.slider_arrow_down_pressed); updateSeekbarData(flag, seekBar); return true; case KeyEvent.KEYCODE_DPAD_LEFT: getActivity().onKeyDown(keyCode, keyevent); return true; case KeyEvent.KEYCODE_DPAD_RIGHT: return true; default: break; } } return false; } private void setSleepModeProgress(boolean up) { int progress = 0; if (up) { switch (seekBar.getProgress()) { case 0: sleepMode = K_Constants.SLEEP_TIME_10MIN; progress = 10; break; case 10: sleepMode = K_Constants.SLEEP_TIME_20MIN; progress = 20; break; case 20: sleepMode = K_Constants.SLEEP_TIME_30MIN; progress = 30; break; case 30: sleepMode = K_Constants.SLEEP_TIME_60MIN; progress = 60; break; case 60: sleepMode = K_Constants.SLEEP_TIME_90MIN; progress = 90; break; case 90: sleepMode = K_Constants.SLEEP_TIME_120MIN; progress = 120; break; case 120: sleepMode = K_Constants.SLEEP_TIME_180MIN; progress = 180; break; case 180: sleepMode = K_Constants.SLEEP_TIME_240MIN; progress = 240; break; case 240: return; default: break; } } else { switch (seekBar.getProgress()) { case 240: sleepMode = K_Constants.SLEEP_TIME_180MIN; progress = 180; break; case 180: sleepMode = K_Constants.SLEEP_TIME_120MIN; progress = 120; break; case 120: sleepMode = K_Constants.SLEEP_TIME_90MIN; progress = 90; break; case 90: sleepMode = K_Constants.SLEEP_TIME_60MIN; progress = 60; break; case 60: sleepMode = K_Constants.SLEEP_TIME_30MIN; progress = 30; break; case 30: sleepMode = K_Constants.SLEEP_TIME_20MIN; progress = 20; break; case 20: sleepMode = K_Constants.SLEEP_TIME_10MIN; progress = 10; break; case 10: sleepMode = K_Constants.SLEEP_TIME_OFF; progress = 0; break; case 0: return; default: break; } } seekBar.setProgress(progress); progressVal.setText(String.valueOf(seekBar.getProgress())); } }); } private int getSleepModeProgressIndex() { int progressIndex = 0; switch (K_TvTimerManager.getInstance().K_getSleepMode()) { case K_Constants.SLEEP_TIME_10MIN: progressIndex = 10; break; case K_Constants.SLEEP_TIME_20MIN: progressIndex = 20; break; case K_Constants.SLEEP_TIME_30MIN: progressIndex = 30; break; case K_Constants.SLEEP_TIME_60MIN: progressIndex = 60; break; case K_Constants.SLEEP_TIME_90MIN: progressIndex = 90; break; case K_Constants.SLEEP_TIME_120MIN: progressIndex = 120; break; case K_Constants.SLEEP_TIME_180MIN: progressIndex = 180; break; case K_Constants.SLEEP_TIME_240MIN: progressIndex = 240; break; default: break; } return progressIndex; } public void updateSeekbarData(int flag, Philips_Setting_VerticalSeekBar seekBar) { if (TvSettingMenuActivity.firstSelectPositon == SettingKarrays.SETTING_PHOTO) { if (mIsPicShift) { switch (flag) { case 0: if (K_TvCommonManager.getInstance() .K_getCurrentTvInputSource() == K_Constants.INPUT_SOURCE_VGA) { K_TvPictureManager.getInstance().K_setPCHPos((short) seekBar.getProgress()); } break; case 1: if (K_TvCommonManager.getInstance() .K_getCurrentTvInputSource() == K_Constants.INPUT_SOURCE_VGA) { K_TvPictureManager.getInstance().K_setPCVPos((short) seekBar.getProgress()); } break; case 2: if (K_TvCommonManager.getInstance() .K_getCurrentTvInputSource() == K_Constants.INPUT_SOURCE_VGA) { K_TvPictureManager.getInstance().K_setPCClock((short) seekBar.getProgress()); } break; case 3: if (K_TvCommonManager.getInstance() .K_getCurrentTvInputSource() == K_Constants.INPUT_SOURCE_VGA) { K_TvPictureManager.getInstance().K_setPCPhase((short) seekBar.getProgress()); } break; } } else { switch (flag) { case 1: K_TvPictureManager.getInstance().K_setVideoItem(K_Constants.PICTURE_CONTRAST, (int) seekBar.getProgress()); break; case 2: K_TvPictureManager.getInstance().K_setVideoItem(K_Constants.PICTURE_BRIGHTNESS, (int) seekBar.getProgress()); break; case 3: K_TvPictureManager.getInstance().K_setVideoItem(K_Constants.PICTURE_SATURATION, (int) seekBar.getProgress()); break; case 4: K_TvPictureManager.getInstance().K_setVideoItem(K_Constants.PICTURE_SHARPNESS, (int) seekBar.getProgress()); break; default: break; } } } else if (TvSettingMenuActivity.firstSelectPositon == SettingKarrays.SETTING_SOUND) { switch (flag) { case 1: K_TvAudioManager.getInstance().K_setBass((int) seekBar.getProgress()); break; case 2: K_TvAudioManager.getInstance().K_setTreble((int) seekBar.getProgress()); break; case 3: K_TvAudioManager.getInstance().K_setBalance((int) seekBar.getProgress()); break; default: break; } } else if (firstSelect == SettingKarrays.SETTING_ECO) { switch (flag) { case 1: K_SettingModel.getInstance().K_setAutonewBackLight(mCotext, (int) seekBar.getProgress()); break; default: break; } } else if (firstSelect == SettingKarrays.SETTING_TV) { switch (flag) { case 4: K_TvTimerManager.getInstance().K_setSleepMode(sleepMode); break; default: break; } } } }