Skip to content

Commit

Permalink
Converted alerter view to use constraint layout, addding buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
kpmmmurphy committed Jul 11, 2018
1 parent 519e733 commit c63ddc3
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 72 deletions.
1 change: 1 addition & 0 deletions alerter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ dependencies {
implementation rootProject.ext.libs.appcompat_v7
implementation rootProject.ext.libs.support_annotations
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.0'

// Local Unit Tests - in src/test
testImplementation rootProject.ext.libs.junit
Expand Down
2 changes: 1 addition & 1 deletion alerter/src/main/java/com/tapadoo/alerter/Alert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Alert @JvmOverloads constructor(context: Context, attrs: AttributeSet? = n
* @param contentGravity Gravity of the Alert
*/
var contentGravity: Int
get() = (rlContainer!!.layoutParams as FrameLayout.LayoutParams).gravity
get() = (flAlertBackground!!.layoutParams as FrameLayout.LayoutParams).gravity
set(contentGravity) {
val paramsTitle = tvTitle?.layoutParams as LinearLayout.LayoutParams
paramsTitle.gravity = contentGravity
Expand Down
142 changes: 74 additions & 68 deletions alerter/src/main/res/layout/alerter_alert_view.xml
Original file line number Diff line number Diff line change
@@ -1,82 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/flClickShield"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:clickable="false">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/flClickShield"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:clickable="false">

<FrameLayout
<android.support.constraint.ConstraintLayout
android:id="@+id/flAlertBackground"
style="@style/AlertStyle"
android:background="@android:color/darker_gray"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
android:paddingStart="@dimen/alerter_padding_default"
android:paddingTop="64dp"
android:paddingEnd="@dimen/alerter_padding_default"
android:paddingBottom="@dimen/alerter_padding_default"
tools:visibility="visible">

<RelativeLayout
android:id="@+id/rlContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginTop="@dimen/alerter_padding_half"
android:background="@null"
android:clipChildren="false"
android:clipToPadding="false"
android:padding="@dimen/alerter_activity_horizontal_margin">

<android.support.v7.widget.AppCompatImageView
android:id="@+id/ivIcon"
android:layout_width="@dimen/alerter_alert_icn_size"
android:layout_height="@dimen/alerter_alert_icn_size"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:maxHeight="@dimen/alerter_alert_icn_size"
android:maxWidth="@dimen/alerter_alert_icn_size"
android:src="@drawable/alerter_ic_notifications"
android:tint="@color/alert_default_icon_color"/>

<LinearLayout
android:id="@+id/llAlertTextContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/alerter_activity_horizontal_margin"
android:layout_marginLeft="@dimen/alerter_activity_horizontal_margin"
android:layout_marginRight="@dimen/alerter_activity_horizontal_margin"
android:layout_marginStart="@dimen/alerter_activity_horizontal_margin"
android:layout_toEndOf="@id/ivIcon"
android:layout_toRightOf="@id/ivIcon"
android:background="@null"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/ivIcon"
android:layout_width="@dimen/alerter_alert_icn_size"
android:layout_height="@dimen/alerter_alert_icn_size"
android:maxWidth="@dimen/alerter_alert_icn_size"
android:maxHeight="@dimen/alerter_alert_icn_size"
android:src="@drawable/alerter_ic_notifications"
android:tint="@color/alert_default_icon_color"
app:layout_constraintBottom_toBottomOf="@id/tvText"
app:layout_constraintEnd_toStartOf="@id/tvTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/AlertTextAppearance.Title"
android:visibility="gone"
tools:text="Title"
tools:visibility="visible"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/alerter_padding_small"
android:layout_marginLeft="@dimen/alerter_padding_small"
android:textAppearance="@style/AlertTextAppearance.Title"
android:visibility="gone"
app:layout_constraintStart_toEndOf="@id/ivIcon"
app:layout_constraintTop_toTopOf="parent"
tools:text="Title"
tools:visibility="visible" />

<TextView
android:id="@+id/tvText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/alerter_padding_small"
android:paddingTop="@dimen/alerter_padding_small"
android:textAppearance="@style/AlertTextAppearance.Text"
android:visibility="gone"
tools:text="Text"
tools:visibility="visible"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/tvText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/alerter_padding_small"
android:layout_marginEnd="@dimen/alerter_padding_small"
android:paddingTop="@dimen/alerter_padding_small"
android:paddingBottom="@dimen/alerter_padding_small"
android:textAppearance="@style/AlertTextAppearance.Text"
android:visibility="gone"
app:layout_constraintStart_toEndOf="@id/ivIcon"
app:layout_constraintTop_toBottomOf="@id/tvTitle"
tools:text="Text"
tools:visibility="visible" />

</LinearLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/btnOne"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/alerter_activity_vertical_margin"
app:layout_constraintEnd_toStartOf="@id/btnTwo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvText"
tools:text="Button 1" />

</RelativeLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/btnTwo"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/alerter_activity_vertical_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/btnOne"
app:layout_constraintTop_toBottomOf="@id/tvText"
tools:text="Button 2" />

<ProgressBar
android:id="@+id/pbProgress"
Expand All @@ -85,8 +91,8 @@
android:layout_height="@dimen/alerter_progress_bar_size"
android:layout_gravity="bottom"
android:visibility="gone"
tools:progress="45"/>
tools:progress="45" />

</FrameLayout>
</android.support.constraint.ConstraintLayout>

</FrameLayout>
2 changes: 0 additions & 2 deletions alerter/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
<style name="AlertStyle" parent="@android:style/Widget">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:minHeight">@dimen/alerter_alert_min_height</item>
<item name="android:maxHeight">@dimen/alerter_alert_max_height</item>
<item name="android:clickable">true</item>
<item name="android:gravity">top</item>
<item name="android:paddingTop">@dimen/alerter_alert_padding</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,13 @@ public void onHide() {
.show();
}

private void showAlertWithCustomAnimations() {
Alerter.create(JavaDemoActivity.this)
.setTitle("Alert Title")
.setText("Alert text...")
.setEnterAnimation(R.anim.alerter_slide_in_from_left)
.setExitAnimation(R.anim.alerter_slide_out_to_right)
.show();
}

}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha18'
classpath 'com.android.tools.build:gradle:3.3.0-alpha02'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.17"
}
Expand Down

0 comments on commit c63ddc3

Please sign in to comment.