Android Open Source - android-gskbyte-utils Dialog Seek Bar Preference






From Project

Back to project page android-gskbyte-utils.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project android-gskbyte-utils 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

/*******************************************************************************
 * Copyright (c) 2013 Jose Alcal Correa.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 * /*ww w.  j  a  v a 2  s  .c  om*/
 * Contributors:
 *     Jose Alcal Correa - initial API and implementation
 ******************************************************************************/
package org.gskbyte.preferences;

import org.gskbyte.R;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;

public class DialogSeekBarPreference extends DialogPreference implements
        SeekBar.OnSeekBarChangeListener
{
    private static final String NS_ANDROID = "http://schemas.android.com/apk/res/android";

    private SeekBar seekBar;
    private TextView splashText, mValueText;
    private Context context;

    private String dialogMessage, suffix;
    private int minValue, maxValue, defaultValue;
    
    private int currentValue = 0;

    public DialogSeekBarPreference(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        this.context = context;
        
        suffix = attrs.getAttributeValue(NS_ANDROID, "text");
        defaultValue = attrs.getAttributeIntValue(NS_ANDROID, "defaultValue", 0);
        maxValue = attrs.getAttributeIntValue(NS_ANDROID, "max", 100);
         
        TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.DialogSeekBarPreference);
        
        minValue = ta.getInteger(0, 0);
        dialogMessage = ta.getString(1);
    }

    @Override
    protected View onCreateDialogView()
    {
        LinearLayout.LayoutParams params;
        LinearLayout layout = new LinearLayout(context);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setPadding(6, 6, 6, 6);

        splashText = new TextView(context);
        if (dialogMessage != null)
            splashText.setText(dialogMessage);
        layout.addView(splashText);

        mValueText = new TextView(context);
        mValueText.setGravity(Gravity.CENTER_HORIZONTAL);
        mValueText.setTextSize(32);
        params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        layout.addView(mValueText, params);

        seekBar = new SeekBar(context);
        layout.addView(seekBar, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        if (shouldPersist())
            currentValue = getPersistedInt(defaultValue);

        seekBar.setMax(maxValue-minValue);
        seekBar.setProgress(currentValue-minValue);
        
        updateText();
        seekBar.setOnSeekBarChangeListener(this);
        return layout;
    }

    @Override
    protected void onBindDialogView(View v)
    {
        super.onBindDialogView(v);
        seekBar.setMax(maxValue-minValue);
        seekBar.setProgress(currentValue-minValue);
    }

    @Override
    protected void onSetInitialValue(boolean restore, Object defaultValueObj)
    {
        super.onSetInitialValue(restore, defaultValueObj);
        
        int defVal = 0; 
        if(defaultValueObj instanceof Integer)
            defVal = ((Integer)defaultValueObj).intValue();
        
        if (restore)
            currentValue = shouldPersist() ? minValue+getPersistedInt(defVal) : 0;
        else
            currentValue = (Integer) defaultValue;
    }

    public void onClick(DialogInterface dialog, int which)
    {
        super.onClick(dialog, which);
        if(which == Dialog.BUTTON_POSITIVE) {
            persistInt(currentValue);
        }
    }
    
    private void updateText()
    {
        String t = String.valueOf(currentValue);
        mValueText.setText(suffix == null ? t : t.concat(suffix));

    }
    
    public void onProgressChanged(SeekBar seek, int value, boolean fromTouch)
    {
        currentValue = value + minValue;
        updateText();
        callChangeListener(Integer.valueOf(currentValue));
    }

    public void onStartTrackingTouch(SeekBar seek)
    {
    }

    public void onStopTrackingTouch(SeekBar seek)
    {
    }
}




Java Source Code List

com.woozzu.android.widget.IndexScroller.java
com.woozzu.android.widget.IndexableListView.java
org.gskbyte.FragmentWrapperActivity.java
org.gskbyte.animation.ExpandAnimation.java
org.gskbyte.bitmap.AbstractBitmapManager.java
org.gskbyte.bitmap.BitmapColorizer.java
org.gskbyte.bitmap.BitmapManager.java
org.gskbyte.bitmap.CachedBitmapColorizer.java
org.gskbyte.bitmap.IndexedBitmaps.java
org.gskbyte.bitmap.LRUBitmapCache.java
org.gskbyte.bitmap.LRUBitmapManager.java
org.gskbyte.bitmap.PrivateBitmapManager.java
org.gskbyte.bitmap.ReferencedBitmaps.java
org.gskbyte.collection.ArrayHashMap.java
org.gskbyte.collection.DoubleSparseArray.java
org.gskbyte.collection.ListHashMap.java
org.gskbyte.dialog.DownloadDialogFragment.java
org.gskbyte.dialog.LoadDialogFragment.java
org.gskbyte.dialog.OpenLinkDialogBuilder.java
org.gskbyte.dialog.PickerDialogFragment.java
org.gskbyte.download.DiskDownload.java
org.gskbyte.download.DownloadManager.java
org.gskbyte.download.Download.java
org.gskbyte.download.MemoryDownload.java
org.gskbyte.drawable.AutoBackgroundButtonDrawable.java
org.gskbyte.listener.IListenable.java
org.gskbyte.listener.ListenableNG.java
org.gskbyte.listener.Listenable.java
org.gskbyte.preferences.DialogSeekBarPreference.java
org.gskbyte.preferences.InlineSeekBarPreference.java
org.gskbyte.remote.AsyncURLRequest.java
org.gskbyte.remote.URLRequest.java
org.gskbyte.tasks.QueuedTaskExecutor.java
org.gskbyte.tasks.TaskStep.java
org.gskbyte.tasks.Task.java
org.gskbyte.ui.ArrayAdapterWithDefaultValue.java
org.gskbyte.ui.ListAdapter.java
org.gskbyte.ui.ColorDialog.ColorDialog.java
org.gskbyte.ui.ColorDialog.ColorPreference.java
org.gskbyte.ui.iconifiedMainMenuList.EntryView.java
org.gskbyte.ui.iconifiedMainMenuList.MainMenuAdapter.java
org.gskbyte.ui.iconifiedMainMenuList.MenuEntry.java
org.gskbyte.util.FrequentIntents.java
org.gskbyte.util.IOUtils.java
org.gskbyte.util.Logger.java
org.gskbyte.util.OpenFileHandlerFactory.java
org.gskbyte.util.OpenFileHandler.java
org.gskbyte.util.XmlUtils.java
org.gskbyte.view.AsyncImageView.java
org.gskbyte.view.AutoBackgroundButton.java
org.gskbyte.view.AutoBackgroundImageButton.java
org.gskbyte.view.AutoHeightImageView.java
org.gskbyte.view.ExpandedGridView.java
org.gskbyte.view.ExpandedListView.java
org.gskbyte.view.FontUtil.java
org.gskbyte.view.FontableButton.java
org.gskbyte.view.FontableCheckBox.java
org.gskbyte.view.FontableEditText.java
org.gskbyte.view.FontableTextView.java
org.gskbyte.view.FullWidthImageView.java
org.gskbyte.view.ProportionalHeightLayout.java
org.gskbyte.view.PullToRefreshListView.java
org.gskbyte.view.SquaredLayout.java
org.gskbyte.view.StepSeekBar.java
org.gskbyte.view.TextViewUtil.java
org.gskbyte.view.ViewUtils.java