Skip to content

Commit

Permalink
0.8 release!
Browse files Browse the repository at this point in the history
- added support for negative values;
- getValue and setValue public methods;
- fixed default seekbar value indication;
  • Loading branch information
MrBIMC committed Jul 27, 2015
1 parent 916cacf commit 13ce64f
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 36 deletions.
8 changes: 4 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 22
versionCode 3
versionName "0.7"
versionCode 4
versionName "0.8"
}
}

dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.1'
}

ext {
PUBLISH_GROUP_ID = 'com.pavelsikun'
PUBLISH_ARTIFACT_ID = 'material-seekbar-preference'
PUBLISH_VERSION = '0.7'
PUBLISH_VERSION = '0.8'
}

apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle'
10 changes: 5 additions & 5 deletions library/library.iml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
Expand All @@ -91,8 +91,8 @@
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.1" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pavelsikun.seekbarpreference;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
Expand All @@ -9,6 +10,7 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Build;
import android.preference.Preference;
import android.support.annotation.NonNull;
import android.text.Editable;
Expand Down Expand Up @@ -60,6 +62,13 @@ public SeekBarPreference(Context context, AttributeSet attrs, int defStyle) {
setLayoutResource(R.layout.seekbar_preference);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
setValuesFromXml(attrs);
setLayoutResource(R.layout.seekbar_preference);
}

private void setValuesFromXml(AttributeSet attrs) {
if(attrs == null) {
mCurrentValue = DEFAULT_CURRENT_VALUE;
Expand Down Expand Up @@ -87,7 +96,7 @@ private void setValuesFromXml(AttributeSet attrs) {
public void onBindView(@NonNull View view) {
super.onBindView(view);

mSeekBar = (SeekBar)view.findViewById(R.id.seekbar);
mSeekBar = (SeekBar) view.findViewById(R.id.seekbar);
mSeekBar.setMax(mMaxValue - mMinValue);
mSeekBar.setOnSeekBarChangeListener(this);

Expand Down Expand Up @@ -133,12 +142,12 @@ void setSeekBarTintOnPreLollipop() { //TMP: I hope google will introduce native
}

@Override
protected Object onGetDefaultValue(TypedArray ta, int index){
protected Object onGetDefaultValue(@NonNull TypedArray ta, int index){
return ta.getInt(index, mCurrentValue);
}

@Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
protected void onSetInitialValue(boolean restoreValue, @NonNull Object defaultValue) {
if(restoreValue) mCurrentValue = getPersistedInt(mCurrentValue);
else {
int temp = 0;
Expand All @@ -157,8 +166,13 @@ public void setEnabled(boolean enabled) {
if(mSeekBarValue != null) mSeekBarValue.setEnabled(enabled);
}

@Override
public boolean persistInt(int value) { return super.persistInt(value); }
public boolean setValue(int value) {
boolean isSuccess = super.persistInt(value);
notifyChanged();
return isSuccess;
}

public int getValue() { return mCurrentValue; }

@Override
public void onDependencyChanged(Preference dependency, boolean disableDependent) {
Expand All @@ -169,7 +183,7 @@ public void onDependencyChanged(Preference dependency, boolean disableDependent)

//SeekBarListener:
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
public void onProgressChanged(@NonNull SeekBar seekBar, int progress, boolean fromUser) {
int newValue = progress + mMinValue;

if(newValue > mMaxValue) newValue = mMaxValue;
Expand All @@ -196,20 +210,20 @@ public void onStartTrackingTouch(SeekBar seekBar) {
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
public void onStopTrackingTouch(@NonNull SeekBar seekBar) {
notifyChanged();
persistInt(mCurrentValue);
mSeekBarValue.addTextChangedListener(this);
}

//TextWatcher:
//TextWatcher
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
mSeekBar.setOnSeekBarChangeListener(null);
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
public void onTextChanged(@NonNull CharSequence s, int start, int before, int count) {}

@Override
public void afterTextChanged(Editable s) {
Expand All @@ -224,9 +238,8 @@ public void afterTextChanged(Editable s) {

mCurrentValue = value;

persistInt(mCurrentValue);
setValue(mCurrentValue);
mSeekBar.setProgress(mCurrentValue - mMinValue);

mSeekBar.setOnSeekBarChangeListener(this);
}
}
10 changes: 5 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.pavelsikun.seekbarpreference.sample"
minSdkVersion 11
targetSdkVersion 22
versionCode 2
versionName "2.0"
versionCode 3
versionName "3.0"
}
buildTypes {
release {
Expand All @@ -20,9 +20,9 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.1'
compile project(':library')

// for your projects use:
// compile 'com.pavelsikun:material-seekbar-preference:0.6+'
// for your projects use:
// compile 'com.pavelsikun:material-seekbar-preference:0.8+'
}
6 changes: 3 additions & 3 deletions sample/sample.iml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.1" level="project" />
<orderEntry type="module" module-name="library" exported="" />
</component>
</module>
8 changes: 4 additions & 4 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:theme="@style/Theme.Application"
android:label="Sample">
android:label="Sample"
android:theme="@style/Theme.Application" >
<activity
android:name=".SettingsActivity"
android:label="Sample">
android:label="Sample" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
6 changes: 6 additions & 0 deletions sample/src/main/res/values-w820dp/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
5 changes: 5 additions & 0 deletions sample/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
4 changes: 4 additions & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
</resources>
8 changes: 4 additions & 4 deletions sample/src/main/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
android:summary="This one is disabled!"
android:enabled="false"
android:defaultValue="5000"
sample:minValue="100"
sample:maxValue="10000"
sample:minValue="10000"
sample:maxValue="0"
sample:interval="200"
sample:measurementUnit="points"/>

Expand All @@ -33,8 +33,8 @@
android:key="seekbar4"
android:title="SeekbarPreference 4"
android:summary="Press on number to input value using keyboard"
sample:minValue="0"
sample:maxValue="8888888"
sample:minValue="-1000"
sample:maxValue="-500"
sample:measurementUnit="$"/>

</PreferenceScreen>

0 comments on commit 13ce64f

Please sign in to comment.