Android Open Source - GuiLib Seek Bar Ex






From Project

Back to project page GuiLib.

License

The source code is released under:

Apache License

If you think the Android project GuiLib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gandulf.guilib.view;
//w  w  w . jav  a2s.  c o m
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.SeekBar;
import android.widget.TextView;

import com.gandulf.guilib.R;
import com.gandulf.guilib.view.ViewScroller.ScrollingListener;

public class SeekBarEx extends SeekBar {

  public interface SeekBarLabelRenderer {
    public String render(int value);
  }

  private class OnSeekBarChangeListenerWrapper implements OnSeekBarChangeListener, ScrollingListener {

    private OnSeekBarChangeListener wrapped;
    private ViewScroller scroller;

    private int currentOffsetX = 0;

    public OnSeekBarChangeListenerWrapper(OnSeekBarChangeListener wrapped) {
      this.wrapped = wrapped;
      scroller = new ViewScroller(getContext(), this, LinearLayout.HORIZONTAL);
    }

    public OnSeekBarChangeListener getWrapped() {
      return wrapped;
    }

    public void setWrapped(OnSeekBarChangeListener wrapped) {
      this.wrapped = wrapped;
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
      if (popupWindow != null && popupWindow.isShowing()) {
        ((TextView) popupWindow.getContentView()).setText(String.valueOf(progress + getMin()));
        int offsetX = (int) (seekBar.getWidth() * (seekBar.getProgress() / (float) getMax()));
        offsetX -= popupWindow.getContentView().getWidth() / 2;
        int distance = currentOffsetX - offsetX;

        scroller.scroll(distance, 0);
      }

      if (label != null) {
        if (labelRenderer != null) {
          label.setText(labelRenderer.render(getValue()));
        } else {
          label.setText(Integer.toString(getValue()));
        }
      }
      if (wrapped != null) {
        wrapped.onProgressChanged(seekBar, progress, fromUser);
      }

    }

    private void initPopupwindow() {
      if (popupWindow == null) {
        TextView textView = (TextView) inflate(getContext(), R.layout.popup_text, null);
        popupWindow = new PopupWindow(textView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        popupWindow.setContentView(textView);
        textView.measure(0, 0);
        popupWindow.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.popup_background));
      }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
      initPopupwindow();

      currentOffsetX = (int) (seekBar.getWidth() * (seekBar.getProgress() / (float) getMax()));
      currentOffsetX -= popupWindow.getContentView().getMeasuredWidth() / 2;

      popupWindow.showAsDropDown(seekBar, currentOffsetX, 0);

      if (wrapped != null) {
        wrapped.onStartTrackingTouch(seekBar);
      }

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
      if (popupWindow != null) {
        popupWindow.dismiss();
      }

      if (label != null) {
        if (labelRenderer != null) {
          label.setText(labelRenderer.render(getValue()));
        } else {
          label.setText(Integer.toString(getValue()));
        }
      }

      if (wrapped != null) {
        wrapped.onStopTrackingTouch(seekBar);
      }
    }

    @Override
    public void onFinished() {

    }

    @Override
    public void onJustify() {

    }

    @Override
    public void onScroll(int distance) {
      if (popupWindow != null) {
        currentOffsetX += distance;
        popupWindow.update(SeekBarEx.this, currentOffsetX, 0, -1, -1);
      }
    }

    @Override
    public void onStarted() {

    }

  }

  private PopupWindow popupWindow;

  private OnSeekBarChangeListenerWrapper wrapper;

  private SeekBarLabelRenderer labelRenderer;

  private int min = 0;
  private int stepSize = 1;

  private TextView label;

  public SeekBarEx(Context context) {
    super(context);
    init();
  }

  public SeekBarEx(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  public SeekBarEx(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
  }

  public int getMin() {
    return min;
  }

  public void setMin(int min) {
    int diff = this.min - min;

    super.setMax(getMax() + diff);
    super.setProgress(getProgress() + diff);
    this.min = min;
    invalidate();
  }

  @Override
  public synchronized void setMax(int max) {
    super.setMax(max - getMin());
    invalidate();
  }

  public int getValue() {
    return getProgress() + min;
  }

  public void setValue(int v) {
    setProgress(v - min);
  }

  public TextView getLabel() {
    return label;
  }

  public void setLabel(TextView label) {
    this.label = label;
  }

  private void init() {
    wrapper = new OnSeekBarChangeListenerWrapper(null);
    super.setOnSeekBarChangeListener(wrapper);
  }

  @Override
  public void setOnSeekBarChangeListener(OnSeekBarChangeListener l) {
    wrapper.setWrapped(l);
  }

  public SeekBarLabelRenderer getLabelRenderer() {
    return labelRenderer;
  }

  public void setLabelRenderer(SeekBarLabelRenderer labelRenderer) {
    this.labelRenderer = labelRenderer;
  }

}




Java Source Code List

au.com.bytecode.opencsv.CSVReader.java
com.ecloud.pulltozoomview.PullToZoomScrollView.java
com.gandulf.guilib.data.OpenArrayAdapter.java
com.gandulf.guilib.data.OpenFilter.java
com.gandulf.guilib.download.AbstractDownloader.java
com.gandulf.guilib.download.DownloadBroadcastReceiver.java
com.gandulf.guilib.download.DownloaderGinger.java
com.gandulf.guilib.download.DownloaderWrapper.java
com.gandulf.guilib.download.Downloader.java
com.gandulf.guilib.download.MediaScannerWrapper.java
com.gandulf.guilib.download.UnzipIntentService.java
com.gandulf.guilib.listener.CheckableListenable.java
com.gandulf.guilib.listener.OnCheckedChangeListener.java
com.gandulf.guilib.util.ColorUtil.java
com.gandulf.guilib.util.Debug.java
com.gandulf.guilib.util.DefaultTextWatcher.java
com.gandulf.guilib.util.DirectoryFileFilter.java
com.gandulf.guilib.util.FileFileFilter.java
com.gandulf.guilib.util.ListViewCompat.java
com.gandulf.guilib.util.MathUtil.java
com.gandulf.guilib.util.ResUtil.java
com.gandulf.guilib.view.ColorPickerDialog.java
com.gandulf.guilib.view.DynamicListViewEx.java
com.gandulf.guilib.view.HackeyDrawerLayout.java
com.gandulf.guilib.view.SeekBarEx.java
com.gandulf.guilib.view.VersionInfoDialog.java
com.gandulf.guilib.view.ViewScroller.java
com.gandulf.guilib.view.adapter.MultiFragmentPagerAdapter.java
com.getbase.floatingactionbutton.AddFloatingActionButton.java
com.getbase.floatingactionbutton.FloatingActionButton.java
com.getbase.floatingactionbutton.FloatingActionsMenu.java
com.github.amlcurran.showcaseview.AnimationFactory.java
com.github.amlcurran.showcaseview.AnimatorAnimationFactory.java
com.github.amlcurran.showcaseview.ApiUtils.java
com.github.amlcurran.showcaseview.Calculator.java
com.github.amlcurran.showcaseview.NewShowcaseDrawer.java
com.github.amlcurran.showcaseview.OnShowcaseEventListener.java
com.github.amlcurran.showcaseview.ShotStateStore.java
com.github.amlcurran.showcaseview.ShowcaseAreaCalculator.java
com.github.amlcurran.showcaseview.ShowcaseDrawer.java
com.github.amlcurran.showcaseview.ShowcaseView.java
com.github.amlcurran.showcaseview.StandardShowcaseDrawer.java
com.github.amlcurran.showcaseview.TextDrawer.java
com.github.amlcurran.showcaseview.targets.ActionBarReflector.java
com.github.amlcurran.showcaseview.targets.ActionBarViewWrapper.java
com.github.amlcurran.showcaseview.targets.ActionItemTarget.java
com.github.amlcurran.showcaseview.targets.ActionViewTarget.java
com.github.amlcurran.showcaseview.targets.AppCompatReflector.java
com.github.amlcurran.showcaseview.targets.PointTarget.java
com.github.amlcurran.showcaseview.targets.ReflectorFactory.java
com.github.amlcurran.showcaseview.targets.Reflector.java
com.github.amlcurran.showcaseview.targets.SherlockReflector.java
com.github.amlcurran.showcaseview.targets.Target.java
com.github.amlcurran.showcaseview.targets.ViewTarget.java
com.sothree.slidinguppanel.SlidingUpPanelLayout.java
com.sothree.slidinguppanel.ViewDragHelper.java
com.thebnich.floatinghintedittext.FloatingHintEditText.java
com.thebnich.floatinghintedittext.FloatingHintTextView.java
com.wefika.flowlayout.FlowLayout.java
de.hdodenhof.circleimageview.CircleImageView.java
uk.co.senab.photoview.Compat.java
uk.co.senab.photoview.PhotoViewAttacher.java
uk.co.senab.photoview.PhotoView.java
uk.co.senab.photoview.SDK16.java
uk.co.senab.photoview.ScrollerProxy.java
uk.co.senab.photoview.VersionedGestureDetector.java
uk.me.lewisdeane.ldialogs.BaseDialog.java
uk.me.lewisdeane.ldialogs.CustomDialog.java
uk.me.lewisdeane.ldialogs.CustomListAdapter.java