Skip to content

Commit

Permalink
Merge pull request #1 from jt-gilkeson/feature/add_full_brightness
Browse files Browse the repository at this point in the history
Added full brightness option for gallery (useful for barcodes)
  • Loading branch information
jt-gilkeson authored Jun 12, 2019
2 parents 6b1ab3c + 69513b3 commit c81bf86
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 70 deletions.
29 changes: 0 additions & 29 deletions .idea/codeStyles/Project.xml

This file was deleted.

12 changes: 9 additions & 3 deletions .idea/misc.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/modules.xml

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

6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.71'
ext.supportLibVer = '27.1.1'
ext.kotlin_version = '1.3.31'
ext.supportLibVer = '28.0.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
9 changes: 3 additions & 6 deletions gallery/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'


android {
compileSdkVersion 27


compileSdkVersion 28

defaultConfig {
minSdkVersion 19
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"

Expand All @@ -33,7 +30,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:support-v4:$supportLibVer"
implementation "com.android.support:appcompat-v7:$supportLibVer"
implementation 'com.github.bumptech.glide:glide:4.7.1'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.github.chrisbanes.photoview:library:1.2.4'

testImplementation 'junit:junit:4.12'
Expand Down
53 changes: 37 additions & 16 deletions gallery/src/main/java/com/jt/gallery/GalleryActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.view.WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL
import kotlinx.android.synthetic.main.activity_gallery.*
import java.util.*
import kotlin.collections.ArrayList

class GalleryActivity : AppCompatActivity(), FullScreenView {
private const val PAGER_OFFSCREEN_LIMIT = 10

companion object {
private const val PAGER_OFFSCREEN_LIMIT = 10
private const val IMAGE_LIST = "imageList"
private const val POSITION = "position"
private const val FULL_BRIGHTNESS = "fullBrightness"

private const val IMAGE_LIST = "imageList"
private const val POSITION = "position"
class GalleryActivity : AppCompatActivity(), FullScreenView {

@JvmStatic @JvmOverloads
fun newIntent(context: Context, imageList: List<String>, currentImage: Int = 0) =
companion object {
@JvmStatic
@JvmOverloads
fun newIntent(context: Context, imageList: List<String>, currentImage: Int = 0, useFullBrightness: Boolean = false) =
Intent(context, GalleryActivity::class.java).apply {
putExtra(IMAGE_LIST, ArrayList(imageList))
putExtra(POSITION, currentImage)
putExtra(FULL_BRIGHTNESS, useFullBrightness)
}
}

Expand All @@ -33,13 +37,16 @@ class GalleryActivity : AppCompatActivity(), FullScreenView {
setContentView(R.layout.activity_gallery)

val currentImage: Int
val adjustBrightness: Boolean

if (savedInstanceState != null) {
imageList = savedInstanceState.getStringArrayList(IMAGE_LIST)
imageList = savedInstanceState.getStringArrayList(IMAGE_LIST) ?: arrayListOf()
currentImage = savedInstanceState.getInt(POSITION)
adjustBrightness = intent.getBooleanExtra(FULL_BRIGHTNESS, false)
} else {
imageList = intent.getStringArrayListExtra(IMAGE_LIST)
currentImage = intent.getIntExtra(POSITION, 0)
adjustBrightness = intent.getBooleanExtra(FULL_BRIGHTNESS, false)
}

val galleryAdapter = GalleryAdapter(this, imageList)
Expand All @@ -49,6 +56,10 @@ class GalleryActivity : AppCompatActivity(), FullScreenView {
adapter = galleryAdapter
currentItem = currentImage
}

if (adjustBrightness) {
setScreenBrightnessTo(BRIGHTNESS_OVERRIDE_FULL)
}
}

override fun onSaveInstanceState(outState: Bundle?) {
Expand All @@ -68,19 +79,29 @@ class GalleryActivity : AppCompatActivity(), FullScreenView {

override fun showSystemUI() {
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
}

override fun hideSystemUI() {
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_IMMERSIVE)
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_IMMERSIVE)
}

override fun isNavigationVisible(): Boolean =
window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_HIDE_NAVIGATION == 0

private fun setScreenBrightnessTo(brightness: Float) {
val lp = window.attributes
if (lp.screenBrightness == brightness) {
return
}

lp.screenBrightness = brightness
window.attributes = lp
}
}
28 changes: 17 additions & 11 deletions gallery/src/main/java/com/jt/gallery/GalleryAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import com.bumptech.glide.request.target.Target
import kotlinx.android.synthetic.main.view_image_gallery.view.*
import uk.co.senab.photoview.PhotoViewAttacher

class GalleryAdapter(private val view: FullScreenView,
private val images: ArrayList<String>) : PagerAdapter() {
class GalleryAdapter(
private val view: FullScreenView,
private val images: ArrayList<String>
) : PagerAdapter() {
private val views: SparseArray<View> = SparseArray()

override fun instantiateItem(container: ViewGroup, position: Int): Any {
Expand All @@ -30,21 +32,25 @@ class GalleryAdapter(private val view: FullScreenView,
Glide.with(rootView.context)
.load(image)
.listener(object : RequestListener<Drawable> {
override fun onResourceReady(resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean): Boolean {
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
val photoView = PhotoViewAttacher(rootView.galleryImage)
photoView.onViewTapListener = tapListener
photoView.scaleType = ImageView.ScaleType.FIT_CENTER
return false
}

override fun onLoadFailed(e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean) = false
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
) = false
})
.into(rootView.galleryImage)

Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Tue Jun 11 15:14:14 PDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

0 comments on commit c81bf86

Please sign in to comment.