Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boloutare Doubeni - Animation Lab with bonus (Long press) #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,79 @@
package generalassembly.yuliyakaleda.startercode;

import android.support.v7.app.AppCompatActivity;
import android.animation.LayoutTransition;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private TextView mWishEdit;
private TextView mAnimText;
private Button mAddWishButton;
private RelativeLayout mLayout;
private Animation mAnimation;
private ListView mListView;
private List<String> mWishList;
private ArrayAdapter<String> mAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//TODO: set up all the view and event listeners.
mLayout = (RelativeLayout) findViewById(R.id.lin_layout);
mWishEdit = (EditText) findViewById(R.id.wish_edit);
mAnimText = (TextView) findViewById(R.id.anim_txt);
mAddWishButton = (Button)findViewById(R.id.add_wish_btn);
mAddWishButton.setOnClickListener(this);
mListView = (ListView) findViewById(R.id.wish_lst);
mWishList = new ArrayList<>();
mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mWishList);

LayoutTransition transition = new LayoutTransition();
transition.enableTransitionType(LayoutTransition.CHANGING);
mLayout.setLayoutTransition(transition);

mAnimation = AnimationUtils.loadAnimation(this, R.anim.animation);
mAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}

@Override
public void onAnimationEnd(Animation animation) {
mAnimText.setText("");
String userWish = mWishEdit.getText().toString();
mWishEdit.setText("");
mWishList.add(0, userWish);
mAdapter.notifyDataSetChanged();
}

@Override
public void onAnimationRepeat(Animation animation) {}
});

mListView.setAdapter(mAdapter);
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
// TODO: prompt the user to delete
mWishList.remove(position);
mAdapter.notifyDataSetChanged();
return false;
}
});
}

@Override
Expand All @@ -23,5 +82,13 @@ public void onClick(View v) {
// 2. animate it in the center of the screen
// 3. add it to the list wish
// 4. clear the input field
String userWish = mWishEdit.getText().toString();
if (userWish.isEmpty()) {
mWishEdit.setError("You can't wish for nothing");
return;
}

mAnimText.setText(userWish);
mAnimText.startAnimation(mAnimation);
}
}
15 changes: 9 additions & 6 deletions starter-code/app/src/main/res/anim/animation.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:fillAfter="false" >
android:shareInterpolator="false"
android:fillAfter="false">
<alpha
<!--TODO: finish fading animation-->
/>
android:fromAlpha="1"
android:toAlpha="0"
android:duration="2000"/>

<rotate
<!--TODO: finish rotating animation-->
/>
android:fromDegrees="0"
android:toDegrees="720"
android:interpolator="@android:anim/linear_interpolator"
android:duration="2000"/>
</set>
31 changes: 31 additions & 0 deletions starter-code/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,35 @@
tools:context="generalassembly.yuliyakaleda.startercode.MainActivity">

<!-- TODO: add edit text, button, text view and a view group-->
<RelativeLayout
android:id="@+id/lin_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/wish_edit"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your wish"/>
<Button
android:id="@+id/add_wish_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/wish_edit"
android:layout_centerInParent="true"
android:text="Add your wish"/>
<TextView
android:layout_centerInParent="true"
android:id="@+id/anim_txt"
android:textSize="30sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""/>
<ListView
android:id="@+id/wish_lst"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/anim_txt"
android:layout_centerInParent="true"/>
</RelativeLayout>
</RelativeLayout>