Commit cb65073d authored by Tiger Oakes's avatar Tiger Oakes Committed by Tiger Oakes
Browse files

Use deprecated annotation for pxToDp

parent a2e8e4f6
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package mozilla.components.support.ktx.android.content.res
import android.content.res.Resources
......@@ -7,7 +11,8 @@ import android.util.TypedValue
* Converts a value in density independent pixels (pxToDp) to the actual pixel values for the display.
* @deprecated use Int.dpToPx instead.
*/
// @Deprecated("Use Int.dpToPx instead",
// ReplaceWith("pixels.dpToPx(this.displayMetrics)", "mozilla.components.support.ktx.android.util.Int.dpToPx"))
@Deprecated("Use Int.dpToPx instead", ReplaceWith(
"pixels.dpToPx(this.displayMetrics)",
"mozilla.components.support.ktx.android.util.Int.dpToPx"))
fun Resources.pxToDp(pixels: Int) = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, pixels.toFloat(), displayMetrics).toInt()
......@@ -6,24 +6,22 @@ package mozilla.components.support.ktx.android.net
import android.net.Uri
private val commonPrefixes = listOf("www.", "mobile.", "m.")
/**
* Returns the host without common prefixes like "www" or "m".
*/
@Suppress("MagicNumber")
val Uri.hostWithoutCommonPrefixes: String?
get() {
val host = host ?: return null
return when {
host.startsWith("www.") -> host.substring(4)
host.startsWith("mobile.") -> host.substring(7)
host.startsWith("m.") -> host.substring(2)
else -> host
for (prefix in commonPrefixes) {
if (host.startsWith(prefix)) return host.substring(prefix.length)
}
return host
}
/**
* Returns true if the [Uri] uses the "http" or "https" protocol scheme.
*/
val Uri.isHttpOrHttps: Boolean
get() = (scheme?.equals("http") ?: false) || (scheme?.equals("https") ?: false)
get() = scheme == "http" || scheme == "https"
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package mozilla.components.support.ktx.android.util
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment