Skip to content

Commit

Permalink
Merge pull request #48 from saschpe/saschpe.updates2
Browse files Browse the repository at this point in the history
Various updates
  • Loading branch information
saschpe authored Sep 12, 2024
2 parents 91375cc + 9aae4d1 commit 953c19b
Show file tree
Hide file tree
Showing 22 changed files with 401 additions and 343 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: https://EditorConfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# noinspection EditorConfigKeyCorrectness
[*.{kt,kts}]
ktlint_code_style = intellij_idea
ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = unset
ktlint_standard_no-wildcard-imports = disabled
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
java-version: 21
- name: Run Spotless
run: ./gradlew spotlessCheck

build:
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
java-version: 21
- name: Setup Android problem matchers
uses: jonasb/android-problem-matchers-action@v1
- name: Build with Gradle
Expand Down
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ repositories {
}

dependencies {
implementation("de.peilicke.sascha:android-customtabs:3.0.3")
implementation("de.peilicke.sascha:android-customtabs:3.1.0")
}
```

Expand Down
32 changes: 7 additions & 25 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,24 @@
* limitations under the License.
*/

buildscript {
repositories {
google()
}
dependencies {
classpath("com.android.tools.build:gradle:8.5.2")
}
}

plugins {
id("com.diffplug.spotless") version "5.12.4"
id("com.github.ben-manes.versions") version "0.38.0"
kotlin("jvm") version "1.6.20"
}

repositories {
mavenCentral()
id("com.android.application") version "8.5.2" apply false
id("com.diffplug.spotless") version "6.25.0"
id("com.github.ben-manes.versions") version "0.51.0"
kotlin("android") version "2.0.20" apply false
}

spotless {
format("misc") {
target("**/*.gradle", "**/*.md", "**/.gitignore")
trimTrailingWhitespace()
endWithNewline()
}
freshmark {
target("**/*.md")
propertiesFile("gradle.properties")
}
kotlin {
target("*/src/**/*.kt")
ktlint().userData(mapOf("disabled_rules" to "no-wildcard-imports"))
target("**/*.kt")
ktlint().setEditorConfigPath("${project.rootDir}/.editorconfig")
}
kotlinGradle {
target("**/*.gradle.kts")
ktlint()
ktlint().setEditorConfigPath("${project.rootDir}/.editorconfig")
}
}

Expand Down
48 changes: 22 additions & 26 deletions customtabs-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,45 @@
plugins {
id("com.android.application")
kotlin("android")
kotlin("android.extensions")
}

repositories {
google()
mavenCentral()
dependencies {
implementation(project(":customtabs"))
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.vectordrawable:vectordrawable-animated:1.2.0")
implementation("com.google.android.material:material:1.12.0")
}

java.toolchain.languageVersion.set(JavaLanguageVersion.of(21))

android {
namespace = "com.example.saschpe.customtabs"

defaultConfig {
applicationId = "com.example.saschpe.customtabs"
compileSdk = 33
minSdk = 17
targetSdk = 33
versionCode = 170030003
versionName = "3.0.3"
base.archivesBaseName = "$applicationId-$versionName"
compileSdk = 34
minSdk = 21
targetSdk = 34
versionCode = 210030100
versionName = "3.1.0"
base.archivesName = "$applicationId-$versionName"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}

buildFeatures {
viewBinding = true
}

buildTypes {
named("release") {
debug {
applicationIdSuffix = ".debug"
}
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
proguardFiles(getDefaultProguardFile("proguard-android.txt"))
signingConfig = signingConfigs.getByName("debug")
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions.jvmTarget = "1.8"
}

dependencies {
implementation(project(":customtabs"))
implementation("androidx.constraintlayout:constraintlayout:2.0.4")
implementation("androidx.vectordrawable:vectordrawable-animated:1.1.0")
implementation("com.google.android.material:material:1.3.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ package com.example.saschpe.customtabs.activity
import android.graphics.Bitmap
import android.graphics.Canvas
import android.net.Uri
import android.os.Build
import android.os.Bundle
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.DrawableCompat
import com.example.saschpe.customtabs.R
import kotlinx.android.synthetic.main.activity_main.fab
import kotlinx.android.synthetic.main.activity_main.toolbar
import com.example.saschpe.customtabs.databinding.ActivityMainBinding
import saschpe.android.customtabs.CustomTabsHelper
import saschpe.android.customtabs.WebViewFallback

class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding

/**
* Apply some sensible defaults across a single app.
* Not strictly necessary but simplifies code when having many different
Expand All @@ -44,8 +44,12 @@ class MainActivity : AppCompatActivity() {
private val defaultCustomTabsIntentBuilder: CustomTabsIntent.Builder
get() {
val builder = CustomTabsIntent.Builder()
.addDefaultShareMenuItem()
.setToolbarColor(ResourcesCompat.getColor(resources, R.color.colorPrimary, null))
.setShareState(CustomTabsIntent.SHARE_STATE_ON)
.setDefaultColorSchemeParams(
CustomTabColorSchemeParams.Builder()
.setToolbarColor(ResourcesCompat.getColor(resources, R.color.colorPrimary, null))
.build(),
)
.setShowTitle(true)
getBitmapFromVectorDrawable(R.drawable.ic_arrow_back_white_24dp)?.let {
builder.setCloseButtonIcon(it)
Expand All @@ -55,10 +59,11 @@ class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.toolbar)

fab.setOnClickListener { startGitHubProjectCustomTab() }
binding.fab.setOnClickListener { startGitHubProjectCustomTab() }
}

/**
Expand All @@ -80,7 +85,7 @@ class MainActivity : AppCompatActivity() {
this,
customTabsIntent,
Uri.parse(GITHUB_PAGE),
WebViewFallback()
WebViewFallback(),
)
}

Expand All @@ -90,16 +95,9 @@ class MainActivity : AppCompatActivity() {
* @param drawableId The drawable ID
* @return Bitmap equivalent
*/
private fun getBitmapFromVectorDrawable(@DrawableRes drawableId: Int): Bitmap? {
var drawable = AppCompatResources.getDrawable(this, drawableId) ?: return null
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable = DrawableCompat.wrap(drawable).mutate()
}

val bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth,
drawable.intrinsicHeight, Bitmap.Config.ARGB_8888
)
private fun getBitmapFromVectorDrawable(@Suppress("SameParameterValue") @DrawableRes drawableId: Int): Bitmap? {
val drawable = AppCompatResources.getDrawable(this, drawableId) ?: return null
val bitmap = Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
Expand Down
Loading

0 comments on commit 953c19b

Please sign in to comment.