Skip to content
This repository has been archived by the owner on Sep 11, 2021. It is now read-only.

Commit

Permalink
Fix some lint warnings (google#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
thagikura authored Sep 11, 2017
1 parent fb2b633 commit d1994f5
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ internal class FlexItemEditFragment : DialogFragment() {
super.onCreate(savedInstanceState)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Material_Light_Dialog)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Holo_Light_Dialog)
} else {
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Dialog)
}
arguments.let {
flexItem = it.getParcelable<FlexItem>(FLEX_ITEM_KEY)
flexItem = it.getParcelable(FLEX_ITEM_KEY)
viewIndex = it.getInt(VIEW_INDEX_KEY)
}
flexItemInEdit = createNewFlexItem(flexItem)
Expand Down Expand Up @@ -241,16 +239,15 @@ internal class FlexItemEditFragment : DialogFragment() {
// devices,
// doing it programmatically.
for (i in textViews.indices) {
val index = i
textViews[index].setOnEditorActionListener { v, actionId, event ->
textViews[i].setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_NEXT ||
actionId == EditorInfo.IME_ACTION_DONE ||
actionId == EditorInfo.IME_NULL
&& event.action == KeyEvent.ACTION_DOWN
&& event.keyCode == KeyEvent.KEYCODE_ENTER) {
if (index + 1 < textViews.size) {
textViews[index + 1].requestFocus()
} else if (index == textViews.size - 1) {
if (i + 1 < textViews.size) {
textViews[i + 1].requestFocus()
} else if (i == textViews.size - 1) {
val inputMethodManager = activity
.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(v.windowToken, 0)
Expand All @@ -260,20 +257,20 @@ internal class FlexItemEditFragment : DialogFragment() {
}

// Suppress the key focus change by KeyEvent.ACTION_UP of the enter key
textViews[index].setOnKeyListener { _, keyCode, event -> keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP }
textViews[i].setOnKeyListener { _, keyCode, event -> keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP }
}

}

private fun alignSelfAsString(alignSelf: Int): String {
when (alignSelf) {
AlignSelf.AUTO -> return ALIGN_SELF_AUTO
AlignItems.FLEX_START -> return ALIGN_SELF_FLEX_START
AlignItems.FLEX_END -> return ALIGN_SELF_FLEX_END
AlignItems.CENTER -> return ALIGN_SELF_CENTER
AlignItems.BASELINE -> return ALIGN_SELF_BASELINE
AlignItems.STRETCH -> return ALIGN_SELF_STRETCH
else -> return ALIGN_SELF_AUTO
return when (alignSelf) {
AlignSelf.AUTO -> ALIGN_SELF_AUTO
AlignItems.FLEX_START -> ALIGN_SELF_FLEX_START
AlignItems.FLEX_END -> ALIGN_SELF_FLEX_END
AlignItems.CENTER -> ALIGN_SELF_CENTER
AlignItems.BASELINE -> ALIGN_SELF_BASELINE
AlignItems.STRETCH -> ALIGN_SELF_STRETCH
else -> ALIGN_SELF_AUTO
}
}

Expand All @@ -297,7 +294,7 @@ internal class FlexItemEditFragment : DialogFragment() {
}

override fun afterTextChanged(editable: Editable) {
if (textInputLayout.isErrorEnabled || editable.isNullOrEmpty() ||
if (textInputLayout.isErrorEnabled || editable.isEmpty() ||
!inputValidator.isValidInput(editable.toString())) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class FlexboxLayoutFragment : Fragment() {

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
val flexItems = (0..flexContainer.flexItemCount - 1)
val flexItems = (0 until flexContainer.flexItemCount)
.map { flexContainer.getFlexItemAt(it) }
.mapTo(ArrayList<FlexItem>()) { it.layoutParams as FlexItem }
.mapTo(ArrayList()) { it.layoutParams as FlexItem }
outState.putParcelableArrayList(FLEX_ITEMS_KEY, flexItems)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.google.android.flexbox

import android.content.SharedPreferences
import android.support.design.widget.NavigationView
import android.support.v4.view.MenuItemCompat
import android.support.v7.preference.PreferenceManager
import android.view.Menu
import android.view.View
Expand Down Expand Up @@ -136,8 +135,7 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
private fun initializeSpinner(currentValue: Int, menuItemId: Int, navigationMenu: Menu,
arrayResourceId: Int, listener: AdapterView.OnItemSelectedListener,
converter: ValueToStringConverter) {
val spinner = MenuItemCompat
.getActionView(navigationMenu.findItem(menuItemId)) as Spinner
val spinner = navigationMenu.findItem(menuItemId).actionView as Spinner
val adapter = ArrayAdapter.createFromResource(activity,
arrayResourceId, R.layout.spinner_item)
spinner.adapter = adapter
Expand Down Expand Up @@ -167,12 +165,12 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
}
}, object : ValueToStringConverter {
override fun asString(value: Int): String {
when (value) {
FlexDirection.ROW -> return ROW
FlexDirection.ROW_REVERSE -> return ROW_REVERSE
FlexDirection.COLUMN -> return COLUMN
FlexDirection.COLUMN_REVERSE -> return COLUMN_REVERSE
else -> return ROW
return when (value) {
FlexDirection.ROW -> ROW
FlexDirection.ROW_REVERSE -> ROW_REVERSE
FlexDirection.COLUMN -> COLUMN
FlexDirection.COLUMN_REVERSE -> COLUMN_REVERSE
else -> ROW
}
}
})
Expand Down Expand Up @@ -204,11 +202,11 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
}
}, object : ValueToStringConverter {
override fun asString(value: Int): String {
when (value) {
FlexWrap.NOWRAP -> return NOWRAP
FlexWrap.WRAP -> return WRAP
FlexWrap.WRAP_REVERSE -> return WRAP_REVERSE
else -> return NOWRAP
return when (value) {
FlexWrap.NOWRAP -> NOWRAP
FlexWrap.WRAP -> WRAP
FlexWrap.WRAP_REVERSE -> WRAP_REVERSE
else -> NOWRAP
}
}
})
Expand All @@ -235,13 +233,13 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
}
}, object : ValueToStringConverter {
override fun asString(value: Int): String {
when (value) {
JustifyContent.FLEX_START -> return FLEX_START
JustifyContent.FLEX_END -> return FLEX_END
JustifyContent.CENTER -> return CENTER
JustifyContent.SPACE_AROUND -> return SPACE_AROUND
JustifyContent.SPACE_BETWEEN -> return SPACE_BETWEEN
else -> return FLEX_START
return when (value) {
JustifyContent.FLEX_START -> FLEX_START
JustifyContent.FLEX_END -> FLEX_END
JustifyContent.CENTER -> CENTER
JustifyContent.SPACE_AROUND -> SPACE_AROUND
JustifyContent.SPACE_BETWEEN -> SPACE_BETWEEN
else -> FLEX_START
}
}
})
Expand All @@ -268,13 +266,13 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
}
}, object : ValueToStringConverter {
override fun asString(value: Int): String {
when (value) {
AlignItems.FLEX_START -> return FLEX_START
AlignItems.FLEX_END -> return FLEX_END
AlignItems.CENTER -> return CENTER
AlignItems.BASELINE -> return BASELINE
AlignItems.STRETCH -> return STRETCH
else -> return STRETCH
return when (value) {
AlignItems.FLEX_START -> FLEX_START
AlignItems.FLEX_END -> FLEX_END
AlignItems.CENTER -> CENTER
AlignItems.BASELINE -> BASELINE
AlignItems.STRETCH -> STRETCH
else -> STRETCH
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal class RecyclerViewFragment : Fragment() {
recyclerView.adapter = adapter
if (savedInstanceState != null) {
val layoutParams : List<FlexboxLayoutManager.LayoutParams>? = savedInstanceState
.getParcelableArrayList<FlexboxLayoutManager.LayoutParams>(FLEX_ITEMS_KEY)
.getParcelableArrayList(FLEX_ITEMS_KEY)
layoutParams?.let {
for (i in layoutParams.indices) {
adapter.addItem(layoutParams[i])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DimensionInputValidator : InputValidator {

override fun isValidInput(charSequence: CharSequence): Boolean {
// -1 represents match_parent, -2 represents wrap_content
return !charSequence.isNullOrEmpty() && (TextUtils.isDigitsOnly(charSequence) ||
return !charSequence.isEmpty() && (TextUtils.isDigitsOnly(charSequence) ||
charSequence.toString() == "-1" ||
charSequence.toString() == "-2")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ import android.text.TextUtils
class FixedDimensionInputValidator : InputValidator {

override fun isValidInput(charSequence: CharSequence): Boolean {
return !charSequence.isNullOrEmpty() && TextUtils.isDigitsOnly(charSequence)
return !charSequence.isEmpty() && TextUtils.isDigitsOnly(charSequence)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class FlexBasisPercentInputValidator : InputValidator {

override fun isValidInput(charSequence: CharSequence): Boolean {
// -1 represents not set
return !charSequence.isNullOrEmpty() && (TextUtils.isDigitsOnly(charSequence) || charSequence.toString() == "-1")
return !charSequence.isEmpty() && (TextUtils.isDigitsOnly(charSequence) || charSequence.toString() == "-1")
}
}

0 comments on commit d1994f5

Please sign in to comment.