forked from HMBSbige/ShadowsocksR-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
32/40
- Loading branch information
Showing
4 changed files
with
108 additions
and
247 deletions.
There are no files selected for viewing
168 changes: 0 additions & 168 deletions
168
app/src/main/java/com/github/shadowsocks/preferences/NumberPickerPreference.java
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
app/src/main/java/com/github/shadowsocks/preferences/NumberPickerPreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.github.shadowsocks.preferences | ||
|
||
import android.content.* | ||
import android.content.res.* | ||
import android.os.* | ||
import android.util.* | ||
import android.view.* | ||
import android.widget.* | ||
import com.github.shadowsocks.* | ||
|
||
class NumberPickerPreference(context: Context, attrs: AttributeSet) : SummaryDialogPreference(context, attrs) | ||
{ | ||
private val picker: NumberPicker = NumberPicker(context) | ||
|
||
var value: Int = 0 | ||
set(i) | ||
{ | ||
if (i == value) | ||
{ | ||
return | ||
} | ||
picker.value = i | ||
field = picker.value | ||
persistInt(this.value) | ||
notifyChanged() | ||
} | ||
|
||
var min: Int | ||
get() = picker.minValue | ||
set(value) | ||
{ | ||
picker.minValue = value | ||
} | ||
|
||
init | ||
{ | ||
val a = context.obtainStyledAttributes(attrs, R.styleable.NumberPickerPreference) | ||
min = a.getInt(R.styleable.NumberPickerPreference_min, 0) | ||
setMax(a.getInt(R.styleable.NumberPickerPreference_max, Integer.MAX_VALUE - 1)) | ||
a.recycle() | ||
} | ||
|
||
private fun setMax(value: Int) | ||
{ | ||
picker.maxValue = value | ||
} | ||
|
||
override fun showDialog(state: Bundle?) | ||
{ | ||
super.showDialog(state) | ||
val window = dialog.window | ||
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) | ||
} | ||
|
||
override fun onCreateDialogView(): View | ||
{ | ||
val parent = picker.parent as ViewGroup? | ||
parent?.removeView(picker) | ||
return picker | ||
} | ||
|
||
override fun onDialogClosed(positiveResult: Boolean) | ||
{ | ||
picker.clearFocus() | ||
super.onDialogClosed(positiveResult) | ||
|
||
if (positiveResult) | ||
{ | ||
val value = picker.value | ||
if (callChangeListener(value)) | ||
{ | ||
this.value = value | ||
return | ||
} | ||
} | ||
picker.value = this.value | ||
} | ||
|
||
override fun onGetDefaultValue(a: TypedArray, index: Int): Any | ||
{ | ||
return a.getInt(index, min) | ||
} | ||
|
||
override fun onSetInitialValue(restorePersistedValue: Boolean, defaultValue: Any) | ||
{ | ||
val defValue = defaultValue as Int | ||
this.value = if (restorePersistedValue) getPersistedInt(defValue) else defValue | ||
} | ||
|
||
override val summaryValue: Any? | ||
get() = value | ||
} |
79 changes: 0 additions & 79 deletions
79
app/src/main/java/com/github/shadowsocks/preferences/SummaryDialogPreference.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/github/shadowsocks/preferences/SummaryDialogPreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.github.shadowsocks.preferences | ||
|
||
import android.content.* | ||
import android.preference.* | ||
import android.util.* | ||
import java.util.* | ||
|
||
abstract class SummaryDialogPreference internal constructor(context: Context, attrs: AttributeSet) : DialogPreference(context, attrs) | ||
{ | ||
abstract val summaryValue: Any? | ||
|
||
override fun getSummary(): CharSequence | ||
{ | ||
return String.format(Locale.ENGLISH, super.getSummary().toString(), summaryValue) | ||
} | ||
} |