Skip to content

Commit

Permalink
Version 2.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jguerinet committed Jun 28, 2017
1 parent 696184f commit 6b1569b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## Version 2.0.5 (2017-06-28)
* `util`:
* Added method to open a Url within a Chrome custom tab

## Version 2.0.4 (2017-05-31)
* `log`:
* Made the abstract methods protected within the `ProductionTree`
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# org.gradle.parallel=true

# Project properties
suitcase_version=2.0.4
suitcase_version=2.0.5
group=com.guerinet

# Android specific properties
Expand Down
1 change: 1 addition & 0 deletions util/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@

dependencies {
compile "com.android.support:support-v4:$android_support_version"
compile "com.android.support:customtabs:$android_support_version"
}
31 changes: 31 additions & 0 deletions util/src/main/java/com/guerinet/suitcase/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.BitmapFactory
import android.net.ConnectivityManager
import android.net.Uri
import android.support.annotation.ColorRes
import android.support.annotation.DrawableRes
import android.support.annotation.StringRes
import android.support.customtabs.CustomTabsIntent
import android.support.v4.content.ContextCompat
import android.widget.Toast
import java.io.File
import java.util.*
Expand Down Expand Up @@ -74,6 +79,32 @@ object Utils {
context.startActivity(Intent(Intent.ACTION_VIEW).setData(Uri.parse(fullUrl)))
}

/**
* Opens a Chrome custom tab when opening a [url] using the app [context] with a default share
* option. Optionally sets the [toolbarColor] (it's a light grey if none supplied) and uses the
* Drawable [closeButtonId] to set a custom close button (it's a black cross if none supplied)
*/
@JvmStatic
fun openCustomTab(context: Context, url: String, @ColorRes toolbarColor: Int? = null,
@DrawableRes closeButtonId: Int? = null) {
val builder = CustomTabsIntent.Builder()
.addDefaultShareMenuItem()

if (toolbarColor != null) {
// Set the custom toolbar color if there is one
builder.setToolbarColor(ContextCompat.getColor(context, toolbarColor))
}

if (closeButtonId != null) {
// Set the custom close button icon if there is one
builder.setCloseButtonIcon(BitmapFactory.decodeResource(context.resources,
closeButtonId))
}

// Build and launch
builder.build().launchUrl(context, Uri.parse(url))
}

/**
* Attempts to open the Pdf at the given [path] using the app [context]
* @throws ActivityNotFoundException if no app to open the pdf is found
Expand Down

0 comments on commit 6b1569b

Please sign in to comment.