Skip to content
Snippets Groups Projects
Commit cce0c8bc authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Allow changing text size

parent 9eba1ca4
Branches
Tags 1.5.3
No related merge requests found
Showing
with 328 additions and 18 deletions
package com.robobunny
import android.content.Context
import android.content.res.TypedArray
import android.support.v7.preference.Preference
import android.support.v7.preference.PreferenceViewHolder
import android.support.v7.widget.AppCompatSeekBar
import android.util.AttributeSet
import android.util.Log
import android.widget.SeekBar
import android.widget.TextView
import butterknife.BindView
import butterknife.ButterKnife
import de.kuschku.quasseldroid_ng.R
/*
* Copyright (c) 2015 IRCCloud, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class SeekBarPreference : Preference, SeekBar.OnSeekBarChangeListener {
private val TAG = javaClass.name
private var maxValue = 100
private var minValue = 0
private var interval = 1
private var currentValue: Int = 0
private var unitsLeftText = ""
private var unitsRightText = ""
@BindView(R.id.seekBarPrefSeekBar)
@JvmField
var seekBar: AppCompatSeekBar? = null
@BindView(R.id.seekBarPrefValue)
@JvmField
var statusText: TextView? = null
@BindView(R.id.seekBarPrefUnitsLeft)
@JvmField
var unitsLeft: TextView? = null
@BindView(R.id.seekBarPrefUnitsRight)
@JvmField
var unitsRight: TextView? = null
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) :
super(context, attrs, defStyleAttr) {
initPreference(context, attrs)
}
constructor(context: Context, attrs: AttributeSet) :
super(context, attrs) {
initPreference(context, attrs)
}
private fun initPreference(context: Context, attrs: AttributeSet) {
setValuesFromXml(attrs)
layoutResource = R.layout.preference_vertical
widgetLayoutResource = R.layout.preference_seekbar
}
private fun setValuesFromXml(attrs: AttributeSet) {
maxValue = attrs.getAttributeIntValue(NAMESPACE_ANDROID, "max", 100)
minValue = attrs.getAttributeIntValue(NAMESPACE_ROBOBUNNY, "min", 0)
unitsLeftText = getAttributeStringValue(attrs, NAMESPACE_ROBOBUNNY, "unitsLeft", "")
val units = getAttributeStringValue(attrs, NAMESPACE_ROBOBUNNY, "units", "")
unitsRightText = getAttributeStringValue(attrs, NAMESPACE_ROBOBUNNY, "unitsRight", units)
try {
val newInterval = attrs.getAttributeValue(NAMESPACE_ROBOBUNNY, "interval")
if (newInterval != null)
interval = Integer.parseInt(newInterval)
} catch (e: Exception) {
Log.e(TAG, "Invalid interval value", e)
}
}
private fun getAttributeStringValue(attrs: AttributeSet, namespace: String, name: String,
defaultValue: String) =
attrs.getAttributeValue(namespace, name) ?: defaultValue
override fun onBindViewHolder(holder: PreferenceViewHolder?) {
super.onBindViewHolder(holder)
holder?.itemView?.let { view ->
ButterKnife.bind(this, view)
seekBar?.max = maxValue - minValue
seekBar?.setOnSeekBarChangeListener(this)
statusText?.text = currentValue.toString()
statusText?.minimumWidth = 30
seekBar?.progress = currentValue - minValue
unitsRight?.text = this.unitsRightText
unitsLeft?.text = this.unitsLeftText
}
}
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
var newValue = progress + minValue
if (newValue > maxValue)
newValue = maxValue
else if (newValue < minValue)
newValue = minValue
else if (interval != 1 && newValue % interval != 0)
newValue = Math.round(newValue.toFloat() / interval) * interval
// change rejected, revert to the previous value
if (!callChangeListener(newValue)) {
seekBar.progress = currentValue - minValue
return
}
// change accepted, store it
currentValue = newValue
statusText?.text = newValue.toString()
persistInt(newValue)
}
override fun onStartTrackingTouch(seekBar: SeekBar) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar) = notifyChanged()
override fun onGetDefaultValue(ta: TypedArray, index: Int) = ta.getInt(index, DEFAULT_VALUE)
override fun onSetInitialValue(restoreValue: Boolean, defaultValue: Any?) {
if (restoreValue) {
currentValue = getPersistedInt(currentValue)
} else {
var temp = 0
try {
temp = defaultValue as Int
} catch (ex: Exception) {
Log.e(TAG, "Invalid default value: " + defaultValue.toString())
}
persistInt(temp)
currentValue = temp
}
}
/**
* make sure that the seekbar is disabled if the preference is disabled
*/
override fun setEnabled(enabled: Boolean) {
super.setEnabled(enabled)
seekBar?.isEnabled = enabled
}
override fun onDependencyChanged(dependency: Preference, disableDependent: Boolean) {
super.onDependencyChanged(dependency, disableDependent)
//Disable movement of seek bar when dependency is false
seekBar?.isEnabled = !disableDependent
}
companion object {
private const val NAMESPACE_ANDROID = "http://schemas.android.com/apk/res/android"
private const val NAMESPACE_ROBOBUNNY = "http://robobunny.com"
private const val DEFAULT_VALUE = 50
}
}
\ No newline at end of file
...@@ -9,6 +9,7 @@ data class AppearanceSettings( ...@@ -9,6 +9,7 @@ data class AppearanceSettings(
val inputEnter: InputEnterMode = InputEnterMode.EMOJI, val inputEnter: InputEnterMode = InputEnterMode.EMOJI,
val colorizeMirc: Boolean = true, val colorizeMirc: Boolean = true,
val useMonospace: Boolean = false, val useMonospace: Boolean = false,
val textSize: Int = 14,
val showSeconds: Boolean = false, val showSeconds: Boolean = false,
val use24hClock: Boolean = true, val use24hClock: Boolean = true,
val showAutocomplete: Boolean = true, val showAutocomplete: Boolean = true,
......
...@@ -18,6 +18,10 @@ object Settings { ...@@ -18,6 +18,10 @@ object Settings {
context.getString(R.string.preference_monospace_key), context.getString(R.string.preference_monospace_key),
AppearanceSettings.DEFAULT.useMonospace AppearanceSettings.DEFAULT.useMonospace
), ),
textSize = getInt(
context.getString(R.string.preference_textsize_key),
AppearanceSettings.DEFAULT.textSize
),
showSeconds = getBoolean( showSeconds = getBoolean(
context.getString(R.string.preference_show_seconds_key), context.getString(R.string.preference_show_seconds_key),
AppearanceSettings.DEFAULT.showSeconds AppearanceSettings.DEFAULT.showSeconds
......
...@@ -8,6 +8,7 @@ import android.text.TextPaint ...@@ -8,6 +8,7 @@ import android.text.TextPaint
import android.text.style.ForegroundColorSpan import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan import android.text.style.StyleSpan
import android.text.style.URLSpan import android.text.style.URLSpan
import android.util.TypedValue
import de.kuschku.libquassel.protocol.Message.MessageType.* import de.kuschku.libquassel.protocol.Message.MessageType.*
import de.kuschku.libquassel.protocol.Message_Flag import de.kuschku.libquassel.protocol.Message_Flag
import de.kuschku.libquassel.protocol.Message_Type import de.kuschku.libquassel.protocol.Message_Type
...@@ -89,6 +90,9 @@ class QuasselMessageRenderer( ...@@ -89,6 +90,9 @@ class QuasselMessageRenderer(
if (appearanceSettings.useMonospace) { if (appearanceSettings.useMonospace) {
viewHolder.content.typeface = Typeface.MONOSPACE viewHolder.content.typeface = Typeface.MONOSPACE
} }
val textSize = appearanceSettings.textSize.toFloat()
viewHolder.time.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize)
viewHolder.content.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize)
} }
override fun bind(holder: QuasselMessageViewHolder, message: FormattedMessage) { override fun bind(holder: QuasselMessageViewHolder, message: FormattedMessage) {
......
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2015 IRCCloud, Ltd.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/widget_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingEnd="10dp"
android:paddingLeft="15dp"
android:paddingRight="10dp"
android:paddingStart="15dp"
android:paddingTop="5dp">
<android.support.v7.widget.AppCompatSeekBar
android:id="@+id/seekBarPrefSeekBar"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1" />
<TextView
android:id="@+id/seekBarPrefUnitsRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="%" />
<TextView
android:id="@+id/seekBarPrefValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="100" />
<TextView
android:id="@+id/seekBarPrefUnitsLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="$" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2015 IRCCloud, Ltd.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clipToPadding="false"
android:focusable="true"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingEnd="?android:attr/listPreferredItemPaddingRight"
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
android:paddingStart="?android:attr/listPreferredItemPaddingLeft">
<FrameLayout
android:id="@+id/icon_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-4dp"
android:layout_marginStart="-4dp"
android:gravity="start|center_vertical"
android:minWidth="60dp"
android:orientation="horizontal"
android:paddingBottom="4dp"
android:paddingEnd="12dp"
android:paddingRight="12dp"
android:paddingTop="4dp">
<android.support.v7.internal.widget.PreferenceImageView
android:id="@android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:maxHeight="48dp"
app:maxWidth="48dp" />
</FrameLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="16sp"
tools:text="Font Size" />
<TextView
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="10"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary" />
<LinearLayout
android:id="@android:id/widget_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
app/src/main/res/mipmap-hdpi/ic_launcher.png

3.2 KiB | W: | H:

app/src/main/res/mipmap-hdpi/ic_launcher.png

3.89 KiB | W: | H:

app/src/main/res/mipmap-hdpi/ic_launcher.png
app/src/main/res/mipmap-hdpi/ic_launcher.png
app/src/main/res/mipmap-hdpi/ic_launcher.png
app/src/main/res/mipmap-hdpi/ic_launcher.png
  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/mipmap-hdpi/ic_launcher_recents.png

4.02 KiB | W: | H:

app/src/main/res/mipmap-hdpi/ic_launcher_recents.png

3.94 KiB | W: | H:

app/src/main/res/mipmap-hdpi/ic_launcher_recents.png
app/src/main/res/mipmap-hdpi/ic_launcher_recents.png
app/src/main/res/mipmap-hdpi/ic_launcher_recents.png
app/src/main/res/mipmap-hdpi/ic_launcher_recents.png
  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/mipmap-mdpi/ic_launcher.png

2.28 KiB | W: | H:

app/src/main/res/mipmap-mdpi/ic_launcher.png

2.31 KiB | W: | H:

app/src/main/res/mipmap-mdpi/ic_launcher.png
app/src/main/res/mipmap-mdpi/ic_launcher.png
app/src/main/res/mipmap-mdpi/ic_launcher.png
app/src/main/res/mipmap-mdpi/ic_launcher.png
  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png

2.84 KiB | W: | H:

app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png

2.5 KiB | W: | H:

app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/mipmap-mdpi/ic_launcher_recents.png

2.73 KiB | W: | H:

app/src/main/res/mipmap-mdpi/ic_launcher_recents.png

2.31 KiB | W: | H:

app/src/main/res/mipmap-mdpi/ic_launcher_recents.png
app/src/main/res/mipmap-mdpi/ic_launcher_recents.png
app/src/main/res/mipmap-mdpi/ic_launcher_recents.png
app/src/main/res/mipmap-mdpi/ic_launcher_recents.png
  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/mipmap-xhdpi/ic_launcher.png

4.53 KiB | W: | H:

app/src/main/res/mipmap-xhdpi/ic_launcher.png

5.68 KiB | W: | H:

app/src/main/res/mipmap-xhdpi/ic_launcher.png
app/src/main/res/mipmap-xhdpi/ic_launcher.png
app/src/main/res/mipmap-xhdpi/ic_launcher.png
app/src/main/res/mipmap-xhdpi/ic_launcher.png
  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/mipmap-xhdpi/ic_launcher_recents.png

6.03 KiB | W: | H:

app/src/main/res/mipmap-xhdpi/ic_launcher_recents.png

5.94 KiB | W: | H:

app/src/main/res/mipmap-xhdpi/ic_launcher_recents.png
app/src/main/res/mipmap-xhdpi/ic_launcher_recents.png
app/src/main/res/mipmap-xhdpi/ic_launcher_recents.png
app/src/main/res/mipmap-xhdpi/ic_launcher_recents.png
  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/mipmap-xxhdpi/ic_launcher.png

7.34 KiB | W: | H:

app/src/main/res/mipmap-xxhdpi/ic_launcher.png

9.84 KiB | W: | H:

app/src/main/res/mipmap-xxhdpi/ic_launcher.png
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/mipmap-xxhdpi/ic_launcher_recents.png

11.5 KiB | W: | H:

app/src/main/res/mipmap-xxhdpi/ic_launcher_recents.png

10.6 KiB | W: | H:

app/src/main/res/mipmap-xxhdpi/ic_launcher_recents.png
app/src/main/res/mipmap-xxhdpi/ic_launcher_recents.png
app/src/main/res/mipmap-xxhdpi/ic_launcher_recents.png
app/src/main/res/mipmap-xxhdpi/ic_launcher_recents.png
  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png

10.6 KiB | W: | H:

app/src/main/res/mipmap-xxxhdpi/ic_launcher.png

14.2 KiB | W: | H:

app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/mipmap-xxxhdpi/ic_launcher_recents.png

17.9 KiB | W: | H:

app/src/main/res/mipmap-xxxhdpi/ic_launcher_recents.png

15.9 KiB | W: | H:

app/src/main/res/mipmap-xxxhdpi/ic_launcher_recents.png
app/src/main/res/mipmap-xxxhdpi/ic_launcher_recents.png
app/src/main/res/mipmap-xxxhdpi/ic_launcher_recents.png
app/src/main/res/mipmap-xxxhdpi/ic_launcher_recents.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
<string name="preference_monospace_key" translatable="false">monospace</string> <string name="preference_monospace_key" translatable="false">monospace</string>
<string name="preference_monospace_title">Use Monospace Font</string> <string name="preference_monospace_title">Use Monospace Font</string>
<string name="preference_textsize_key" translatable="false">fontsize</string>
<string name="preference_textsize_title">Text Size</string>
<string name="preference_show_seconds_key" translatable="false">show_seconds</string> <string name="preference_show_seconds_key" translatable="false">show_seconds</string>
<string name="preference_show_seconds_title">Show Seconds</string> <string name="preference_show_seconds_title">Show Seconds</string>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:robobunny="http://robobunny.com">
<PreferenceCategory android:title="@string/preference_appearance_title"> <PreferenceCategory android:title="@string/preference_appearance_title">
<ListPreference <ListPreference
android:defaultValue="QUASSEL_LIGHT" android:defaultValue="QUASSEL_LIGHT"
...@@ -13,6 +14,13 @@ ...@@ -13,6 +14,13 @@
android:key="@string/preference_monospace_key" android:key="@string/preference_monospace_key"
android:title="@string/preference_monospace_title" /> android:title="@string/preference_monospace_title" />
<com.robobunny.SeekBarPreference
android:defaultValue="14"
android:key="@string/preference_textsize_key"
android:max="24"
android:title="@string/preference_textsize_title"
robobunny:min="12" />
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/preference_show_seconds_key" android:key="@string/preference_show_seconds_key"
......
...@@ -14,26 +14,15 @@ class QVariant<T>(val data: T?, val type: MetaType<T>) { ...@@ -14,26 +14,15 @@ class QVariant<T>(val data: T?, val type: MetaType<T>) {
} }
} }
@PublishedApi
internal inline fun <reified U> QVariant_?.coerce(): QVariant<U>? {
return if (this?.data is U) {
this as QVariant<U>
} else {
null
}
}
inline fun <reified U> QVariant_?.value(): U? inline fun <reified U> QVariant_?.value(): U?
= this?.value<U?>(null) = this?.value<U?>(null)
inline fun <reified U> QVariant_?.value(defValue: U): U inline fun <reified U> QVariant_?.value(defValue: U): U = this?.data as? U ?: defValue
= this.coerce<U>()?.data ?: defValue
inline fun <reified U> QVariant_?.valueOr(f: () -> U): U inline fun <reified U> QVariant_?.valueOr(f: () -> U): U = this?.data as? U ?: f()
= this.coerce<U>()?.data ?: f()
inline fun <reified U> QVariant_?.valueOrThrow(e: Throwable = NullPointerException()): U inline fun <reified U> QVariant_?.valueOrThrow(e: Throwable = NullPointerException()): U =
= this.coerce<U>()?.data ?: throw e this?.data as? U ?: throw e
inline fun <reified U> QVariant_?.valueOrThrow(e: () -> Throwable): U inline fun <reified U> QVariant_?.valueOrThrow(e: () -> Throwable): U =
= this.coerce<U>()?.data ?: throw e() this?.data as? U ?: throw e()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment