-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a new welcome activity that shows our goodbye message to the community. Co-authored-by: Maria Kozinska <[email protected]> Co-authored-by: Mauro Piccotti <[email protected]> Closes: #362 Updates: #360
- Loading branch information
1 parent
990c7ee
commit 6da8785
Showing
9 changed files
with
560 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
app/src/main/java/fi/bitrite/android/ws/ui/ActivityMovingOut.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package fi.bitrite.android.ws.ui; | ||
|
||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.text.Html; | ||
import android.text.Spanned; | ||
import android.text.method.LinkMovementMethod; | ||
import android.view.View; | ||
import android.view.animation.Animation; | ||
import android.view.animation.Transformation; | ||
import android.widget.ImageButton; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
import fi.bitrite.android.ws.R; | ||
|
||
/** | ||
* The activity displays Goodbye Warmshowers message to the user. | ||
*/ | ||
public class ActivityMovingOut extends AppCompatActivity { | ||
@Override | ||
protected void onCreate(Bundle icicle) { | ||
super.onCreate(icicle); | ||
setContentView(R.layout.activity_moving_out); | ||
|
||
TextView message = findViewById(R.id.moving_out_message); | ||
message.setText(getFormattedText(getString(R.string.moving_out_message))); | ||
message.setMovementMethod(LinkMovementMethod.getInstance()); | ||
|
||
TextView backstoryBody = findViewById(R.id.moving_out_backstory_body); | ||
backstoryBody.setText(getFormattedText(getString(R.string.moving_out_backstory_body))); | ||
backstoryBody.setMovementMethod(LinkMovementMethod.getInstance()); | ||
makeExpandable(backstoryBody, | ||
findViewById(R.id.moving_out_backstory_title), | ||
findViewById(R.id.moving_out_backstory_head), | ||
findViewById(R.id.moving_out_backstory_expand_collapse)); | ||
|
||
TextView whatToDoBody = findViewById(R.id.moving_out_what_to_do_body); | ||
whatToDoBody.setText(getFormattedText(getString(R.string.moving_out_what_to_do_body))); | ||
whatToDoBody.setMovementMethod(LinkMovementMethod.getInstance()); | ||
makeExpandable(whatToDoBody, | ||
findViewById(R.id.moving_out_what_to_do_title), | ||
findViewById(R.id.moving_out_what_to_do_head), | ||
findViewById(R.id.moving_out_what_to_do_expand_collapse)); | ||
} | ||
|
||
private void makeExpandable(TextView body, TextView title, LinearLayout head, ImageButton expand) { | ||
View.OnClickListener onClickListener = new ExpandableViewOnClickListener(body, expand); | ||
head.setOnClickListener(onClickListener); | ||
title.setOnClickListener(onClickListener); | ||
expand.setOnClickListener(onClickListener); | ||
} | ||
|
||
private static class ExpandableViewOnClickListener implements View.OnClickListener { | ||
private final View body; | ||
private final View expandIcon; | ||
private final int bodyHeight; | ||
private final int duration = 600; | ||
private boolean isExpanded = false; | ||
|
||
ExpandableViewOnClickListener(View body, View expandIcon) { | ||
this.body = body; | ||
this.expandIcon = expandIcon; | ||
|
||
// Calculate the expanded size of the backstory body. | ||
int matchParentMeasureSpec = View.MeasureSpec.makeMeasureSpec( | ||
((View) body.getParent()).getWidth(), | ||
View.MeasureSpec.EXACTLY); | ||
int wrapContentMeasureSpec = View.MeasureSpec.makeMeasureSpec( | ||
0, | ||
View.MeasureSpec.UNSPECIFIED); | ||
body.measure(matchParentMeasureSpec, wrapContentMeasureSpec); | ||
bodyHeight = body.getMeasuredHeight(); | ||
} | ||
|
||
@Override | ||
public void onClick(View view) { | ||
if (!isExpanded) { | ||
// Expand. | ||
isExpanded = true; | ||
Animation a = new Animation() { | ||
@Override | ||
protected void applyTransformation(float interpolatedTime, Transformation t) { | ||
body.getLayoutParams().height = interpolatedTime == 1 | ||
? LinearLayout.LayoutParams.WRAP_CONTENT | ||
: (int)(bodyHeight * interpolatedTime); | ||
body.requestLayout(); | ||
} | ||
|
||
@Override | ||
public boolean willChangeBounds() { | ||
return true; | ||
} | ||
}; | ||
a.setDuration(duration); | ||
|
||
// Older versions of android (pre API 21) cancel animations for views with a height of 0. | ||
body.getLayoutParams().height = 1; | ||
body.setVisibility(View.VISIBLE); | ||
body.startAnimation(a); | ||
|
||
expandIcon.animate() | ||
.rotation(180f) | ||
.setDuration(duration) | ||
.start(); | ||
} else { | ||
// Collapse. | ||
isExpanded = false; | ||
Animation a = new Animation() { | ||
@Override | ||
protected void applyTransformation(float interpolatedTime, Transformation t) { | ||
if(interpolatedTime == 1){ | ||
body.setVisibility(View.GONE); | ||
}else{ | ||
body.getLayoutParams().height = | ||
(int)((1 - interpolatedTime) * bodyHeight); | ||
body.requestLayout(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean willChangeBounds() { | ||
return true; | ||
} | ||
}; | ||
a.setDuration(duration); | ||
body.startAnimation(a); | ||
|
||
expandIcon.animate() | ||
.rotation(0f) | ||
.setDuration(duration) | ||
.start(); | ||
} | ||
} | ||
} | ||
|
||
private Spanned getFormattedText(String text) { | ||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? | ||
Html.fromHtml(text, Html.FROM_HTML_MODE_COMPACT) : | ||
Html.fromHtml(text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<group android:scaleX="2.208" | ||
android:scaleY="2.208" | ||
android:translateX="-14.496" | ||
android:translateY="-15.6"> | ||
<path | ||
android:fillColor="#FF757575" | ||
android:pathData="M7,10l5,5 5,-5z"/> | ||
</group> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/backgroundLightGrey" | ||
android:orientation="vertical" | ||
android:scrollbars="vertical"> | ||
|
||
<androidx.core.widget.NestedScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.cardview.widget.CardView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginHorizontal="16dp" | ||
android:layout_marginVertical="28dp" | ||
app:cardCornerRadius="4dp"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
android:paddingHorizontal="20dp" | ||
android:paddingVertical="28dp"> | ||
|
||
<TextView | ||
android:id="@+id/moving_out_title" | ||
style="@style/TextAppearance.AppCompat.Title" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_horizontal" | ||
android:text="@string/moving_out_title" | ||
android:textColor="@color/primaryColorAccent" | ||
android:textSize="22sp" /> | ||
|
||
<TextView | ||
android:id="@+id/moving_out_subtitle" | ||
style="@style/TextAppearance.AppCompat.Subhead" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_horizontal" | ||
android:text="@string/moving_out_subtitle" | ||
android:textColor="@color/primaryColorAccent" /> | ||
|
||
<TextView | ||
android:id="@+id/moving_out_message" | ||
style="@style/TextAppearance.AppCompat.Body1" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="25dp" | ||
android:gravity="start" | ||
android:lineSpacingExtra="2dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="2dp" | ||
android:layout_marginVertical="20dp" | ||
android:background="?android:attr/listDivider" /> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
<LinearLayout | ||
android:id="@+id/moving_out_backstory_head" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
<TextView | ||
android:id="@+id/moving_out_backstory_title" | ||
style="@style/TextAppearance.AppCompat.Body1" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_vertical" | ||
android:layout_weight="1" | ||
android:text="@string/moving_out_backstory_title" | ||
android:textStyle="bold" /> | ||
|
||
<ImageButton | ||
android:id="@+id/moving_out_backstory_expand_collapse" | ||
android:layout_width="24dp" | ||
android:layout_height="24dp" | ||
android:background="@android:color/transparent" | ||
android:padding="4dp" | ||
android:scaleType="fitCenter" | ||
app:srcCompat="@drawable/ic_arrow_down_grey600_24dp" /> | ||
</LinearLayout> | ||
|
||
<TextView | ||
android:id="@+id/moving_out_backstory_body" | ||
style="@style/TextAppearance.AppCompat.Body1" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="start" | ||
android:lineSpacingExtra="2dp" | ||
android:paddingTop="12dp" | ||
android:paddingBottom="12dp" | ||
android:visibility="gone" /> | ||
</LinearLayout> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="10dp" | ||
android:orientation="vertical"> | ||
<LinearLayout | ||
android:id="@+id/moving_out_what_to_do_head" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
<TextView | ||
android:id="@+id/moving_out_what_to_do_title" | ||
style="@style/TextAppearance.AppCompat.Body1" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_vertical" | ||
android:layout_weight="1" | ||
android:text="@string/moving_out_what_to_do_title" | ||
android:textStyle="bold" /> | ||
|
||
<ImageButton | ||
android:id="@+id/moving_out_what_to_do_expand_collapse" | ||
android:layout_width="24dp" | ||
android:layout_height="24dp" | ||
android:background="@android:color/transparent" | ||
android:padding="4dp" | ||
android:scaleType="fitCenter" | ||
app:srcCompat="@drawable/ic_arrow_down_grey600_24dp" /> | ||
</LinearLayout> | ||
|
||
<TextView | ||
android:id="@+id/moving_out_what_to_do_body" | ||
style="@style/TextAppearance.AppCompat.Body1" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="start" | ||
android:lineSpacingExtra="2dp" | ||
android:paddingTop="12dp" | ||
android:paddingBottom="12dp" | ||
android:visibility="gone" /> | ||
</LinearLayout> | ||
</LinearLayout> | ||
</androidx.cardview.widget.CardView> | ||
</androidx.core.widget.NestedScrollView> | ||
</LinearLayout> |
Oops, something went wrong.