Skip to content

Commit 6d96691

Browse files
feat: Re-add color variant and add samples
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent 4bf917f commit 6d96691

3 files changed

Lines changed: 75 additions & 13 deletions

File tree

sample/src/main/java/com/nextcloud/android/common/sample/MainActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ class MainActivity : AppCompatActivity() {
109109
material.themeChipInput(binding.inputChip)
110110
material.themeChipSuggestion(binding.suggestionChip)
111111
material.themeChipFilter(binding.filterChip)
112+
material.colorProgressBar(binding.circularProgressBar)
113+
material.colorProgressBar(binding.linearProgressBar)
112114
material.colorMaterialButtonPrimaryFilled(binding.dialogBtn)
113115
}
114116
}

sample/src/main/res/layout/activity_main.xml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,39 @@
159159

160160
</com.google.android.material.chip.ChipGroup>
161161

162+
<com.google.android.material.progressindicator.CircularProgressIndicator
163+
android:id="@+id/circular_progress_bar"
164+
android:layout_width="200dp"
165+
android:layout_height="200dp"
166+
android:indeterminate="false"
167+
android:indeterminateOnly="false"
168+
android:progress="35"
169+
app:layout_constraintStart_toStartOf="parent"
170+
app:layout_constraintTop_toBottomOf="@id/chipGroup"
171+
app:trackCornerRadius="5dp"
172+
app:trackThickness="5dp" />
173+
174+
<com.google.android.material.progressindicator.LinearProgressIndicator
175+
android:id="@+id/linear_progress_bar"
176+
android:layout_width="200dp"
177+
android:layout_height="wrap_content"
178+
android:layout_margin="20dp"
179+
android:indeterminate="false"
180+
android:indeterminateOnly="false"
181+
android:progress="35"
182+
app:layout_constraintStart_toEndOf="@+id/circular_progress_bar"
183+
app:layout_constraintTop_toBottomOf="@id/chipGroup"
184+
app:trackCornerRadius="5dp"
185+
app:trackStopIndicatorSize="0dp"
186+
app:trackThickness="5dp" />
187+
162188
<com.google.android.material.button.MaterialButton
163189
android:id="@+id/dialogBtn"
164190
android:layout_width="wrap_content"
165191
android:layout_height="wrap_content"
166192
android:text="@string/open_dialog"
167-
android:layout_marginTop="@dimen/standard_half_margin"
168-
android:layout_marginBottom="@dimen/standard_half_margin"
169-
app:layout_constraintTop_toBottomOf="@id/chipGroup"
170-
app:layout_constraintStart_toStartOf="parent" />
193+
app:layout_constraintStart_toStartOf="parent"
194+
app:layout_constraintTop_toBottomOf="@+id/circular_progress_bar" />
171195

172196
</androidx.constraintlayout.widget.ConstraintLayout>
173197
</FrameLayout>

ui/src/main/java/com/nextcloud/android/common/ui/theme/utils/MaterialViewThemeUtils.kt

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,29 +378,65 @@ class MaterialViewThemeUtils
378378
/**
379379
* Themes a [LinearProgressIndicator] using the provided [ColorRole].
380380
*
381-
* @param progressIndicator The progress indicator to theme.
381+
* @param linearProgressIndicator The progress indicator to theme.
382382
* @param colorRole The color role to be used for the active indicator part. Defaults to [ColorRole.PRIMARY].
383383
*/
384384
fun colorProgressBar(
385-
progressIndicator: LinearProgressIndicator,
385+
linearProgressIndicator: LinearProgressIndicator,
386386
colorRole: ColorRole = ColorRole.PRIMARY
387387
) {
388-
withScheme(progressIndicator) { scheme ->
389-
progressIndicator.setIndicatorColor(colorRole.select(scheme))
390-
progressIndicator.trackColor = dynamicColor.secondaryContainer().getArgb(scheme)
388+
withScheme(linearProgressIndicator) { scheme ->
389+
colorProgressBar(linearProgressIndicator, colorRole.select(scheme))
391390
}
392391
}
393392

393+
/**
394+
* Themes a [LinearProgressIndicator] using the provided color [Int].
395+
*
396+
* @param linearProgressIndicator The progress indicator to theme.
397+
* @param color The color to be used for the active indicator part.
398+
*/
399+
fun colorProgressBar(
400+
linearProgressIndicator: LinearProgressIndicator,
401+
@ColorInt color: Int
402+
) {
403+
withScheme(linearProgressIndicator) { scheme ->
404+
linearProgressIndicator.setIndicatorColor(color)
405+
linearProgressIndicator.trackColor = dynamicColor.secondaryContainer().getArgb(scheme)
406+
}
407+
}
408+
409+
/**
410+
* Themes a [CircularProgressIndicator] using the provided [ColorRole].
411+
*
412+
* @param circularProgressIndicator The progress indicator to theme.
413+
* @param colorRole The color role to be used for the active indicator part. Defaults to [ColorRole.PRIMARY].
414+
*/
394415
fun colorProgressBar(
395-
progressIndicator: CircularProgressIndicator,
416+
circularProgressIndicator: CircularProgressIndicator,
396417
colorRole: ColorRole = ColorRole.PRIMARY
397418
) {
398-
withScheme(progressIndicator) { scheme ->
399-
progressIndicator.setIndicatorColor(colorRole.select(scheme))
400-
progressIndicator.trackColor = dynamicColor.secondaryContainer().getArgb(scheme)
419+
withScheme(circularProgressIndicator) { scheme ->
420+
colorProgressBar(circularProgressIndicator, colorRole.select(scheme))
401421
}
402422
}
403423

424+
/**
425+
* Themes a [CircularProgressIndicator] using the provided color [Int].
426+
*
427+
* @param circularProgressIndicator The progress indicator to theme.
428+
* @param color The color to be used for the active indicator part.
429+
*/
430+
fun colorProgressBar(
431+
circularProgressIndicator: CircularProgressIndicator,
432+
@ColorInt color: Int
433+
) {
434+
withScheme(circularProgressIndicator) { scheme ->
435+
circularProgressIndicator.setIndicatorColor(color)
436+
circularProgressIndicator.trackColor = dynamicColor.secondaryContainer().getArgb(scheme)
437+
}
438+
}
439+
404440
fun colorTextInputLayout(textInputLayout: TextInputLayout) {
405441
withScheme(textInputLayout) { scheme ->
406442
val errorColor = dynamicColor.error().getArgb(scheme)

0 commit comments

Comments
 (0)