コード例 #1
0
        @Override
        public void onClick(View v) {
          int colorMode = PrefUtils.getInt(_context, R.string.pref_foreground_color, 0);
          colorMode = (colorMode + 1) % 2;
          int color;
          if (colorMode == 0) {
            color = TEXT_COLOR_DARK;
          } else {
            color = TEXT_COLOR_LIGHT;
          }

          setTextColorConfiguration(_panelView, panelTextIds, color);

          TextView text = (TextView) _panelView.findViewById(R.id.text_title);
          text.setTextColor(color);
          text = (TextView) _panelView.findViewById(R.id.text_artist);
          text.setTextColor(color);

          StickyListHeadersListView list =
              (StickyListHeadersListView) _panelView.findViewById(R.id.list_current_songs);
          OverlaySongInfoListAdapter adapter = (OverlaySongInfoListAdapter) list.getAdapter();
          if (adapter != null) {
            adapter.setTextColor(color);
            adapter.notifyDataSetChanged();
          }

          PrefUtils.setInt(_context, R.string.pref_foreground_color, colorMode);

          startTimeoutTimer();
        }
コード例 #2
0
  public OverlayViewManager(Context context) {
    _context = context;
    _windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    _timeoutHandler = new Handler();

    Resources resources = _context.getResources();
    TEXT_COLOR_DARK = resources.getColor(R.color.overlay_title_dark);
    TEXT_COLOR_LIGHT = resources.getColor(R.color.overlay_title_light);

    _panelParams =
        new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
            PixelFormat.TRANSLUCENT);
    _panelParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;

    _openParams =
        new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
            PixelFormat.TRANSLUCENT);
    _openParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;

    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final int[] panelButtonIds =
        new int[] {
          R.id.image_artwork,
          R.id.button_hide,
          R.id.button_track_down,
          R.id.button_play_or_pause,
          R.id.button_track_up,
          R.id.button_stop,
          R.id.button_open_close_list,
        };
    final View.OnClickListener[] panelListeners =
        new View.OnClickListener[] {
          _onArtworkClickListener,
          _onHideClickListener,
          _onTrackDownClickListener,
          _onPlayPauseClickListener,
          _onTrackUpClickListener,
          _onStopClickListener,
          _onOpenCloseListClickListener,
        };
    _panelView = inflater.inflate(R.layout.overlay_play_panel, null);
    setupButtonListener(_panelView, panelButtonIds, panelListeners);

    setupPlayPauseButton(_panelView, false);

    View layout = _panelView.findViewById(R.id.layout_panel);
    layout.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            startTimeoutTimer();
            return false;
          }
        });
    int defaultColor = _context.getResources().getColor(R.color.overlay_panel_background);
    int color = PrefUtils.getInt(_context, R.string.pref_background_color, defaultColor);
    layout.setBackgroundColor(color);

    StickyListHeadersListView list =
        (StickyListHeadersListView) _panelView.findViewById(R.id.list_current_songs);
    list.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            startTimeoutTimer();
            return false;
          }
        });
    list.setDrawingListUnderStickyHeader(false);

    SeekBar bar = (SeekBar) _panelView.findViewById(R.id.seekbar_position);
    bar.setTag(R.id.tag_is_dragging, false);
    bar.setOnSeekBarChangeListener(
        new SeekBar.OnSeekBarChangeListener() {
          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
            seekBar.setTag(R.id.tag_is_dragging, false);
            startTimeoutTimer();

            Intent intent = new Intent(_context, OverlayMusicPlayerService.class);
            intent.setAction(OverlayMusicPlayerService.ACTION_SEEK);
            intent.putExtra(OverlayMusicPlayerService.PRM_SEEK_TIME, seekBar.getProgress());
            _context.startService(intent);
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {
            seekBar.setTag(R.id.tag_is_dragging, true);
            stopTimeoutTimer();
          }

          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
              TextView time = (TextView) _panelView.findViewById(R.id.text_position);
              time.setText(TimecodeUtils.format(progress));
            }
          }
        });

    int colorMode = PrefUtils.getInt(_context, R.string.pref_foreground_color, 0);
    if (colorMode == 0) {
      color = TEXT_COLOR_DARK;
    } else {
      color = TEXT_COLOR_LIGHT;
    }
    setTextColorConfiguration(_panelView, panelTextIds, color);

    final int[] openButtonIds =
        new int[] {
          R.id.button_open,
        };
    final View.OnClickListener[] openlListeners =
        new View.OnClickListener[] {
          _onOpenClickListener,
        };
    _openView = inflater.inflate(R.layout.overlay_open_button, null);
    setupButtonListener(_openView, openButtonIds, openlListeners);

    layout = _openView.findViewById(R.id.layout_open);
    layout.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {

            View view = _openView.findViewById(R.id.button_open);
            int visiblity = view.getVisibility();
            if (visiblity != View.VISIBLE) {
              view.setVisibility(View.VISIBLE);
            }

            startTimeoutTimer();

            return false;
          }
        });
  }