com.mstar.tv.tvplayer.philips.option.OptionThirdFragment.java Source code

Java tutorial

Introduction

Here is the source code for com.mstar.tv.tvplayer.philips.option.OptionThirdFragment.java

Source

/*
 * 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.option;

import com.mstar.tv.tvplayer.kangguan.tvapi.K_Constants;
import com.mstar.tv.tvplayer.kangguan.tvapi.K_TvCommonManager;
import com.mstar.tv.tvplayer.kangguan.tvapi.K_TvPictureManager;
import com.mstar.tv.tvplayer.philips.setting.Philips_Setting_VerticalSeekBar;
import com.mstar.tv.tvplayer.ui.R;

import android.app.Activity;
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 OptionThirdFragment 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;
    private String TAG = "ThreeFragment";

    public interface ThreeFragmentSelectedListener {
        public void onThreeSelectedData(int dataPositon);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        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.option_vseekbar_progress_bg));
        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 onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mCallback = (ThreeFragmentSelectedListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString() + " must implement OnHeadlineSelectedListener");
        }
    }

    public void updateView(String data, int dataPositon) {
        vseekbar_title.setText(data);
        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;
        }
        seekBar.setProgress(currentIndex);
        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:
                        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:
                        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;
            }
        });
    }

    public void updateSeekbarData(int flag, Philips_Setting_VerticalSeekBar seekBar) {
        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;
        }

    }
}