From 95820c34b460a8893df4f8581941e894ddfbbefc Mon Sep 17 00:00:00 2001 From: Boloutare Doubeni Date: Sun, 21 Feb 2016 20:51:46 -0500 Subject: [PATCH] Boloutare Doubeni - Animation Lab with bonus (Long press) --- .../startercode/MainActivity.java | 73 ++++++++++++++++++- .../app/src/main/res/anim/animation.xml | 15 ++-- .../app/src/main/res/layout/activity_main.xml | 31 ++++++++ 3 files changed, 110 insertions(+), 9 deletions(-) diff --git a/starter-code/app/src/main/java/generalassembly/yuliyakaleda/startercode/MainActivity.java b/starter-code/app/src/main/java/generalassembly/yuliyakaleda/startercode/MainActivity.java index 55d1d3a..78ec156 100644 --- a/starter-code/app/src/main/java/generalassembly/yuliyakaleda/startercode/MainActivity.java +++ b/starter-code/app/src/main/java/generalassembly/yuliyakaleda/startercode/MainActivity.java @@ -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 mWishList; + private ArrayAdapter 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 @@ -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); } } diff --git a/starter-code/app/src/main/res/anim/animation.xml b/starter-code/app/src/main/res/anim/animation.xml index 88c2c7c..ebe2a34 100644 --- a/starter-code/app/src/main/res/anim/animation.xml +++ b/starter-code/app/src/main/res/anim/animation.xml @@ -1,11 +1,14 @@ + android:shareInterpolator="false" + android:fillAfter="false"> - /> + android:fromAlpha="1" + android:toAlpha="0" + android:duration="2000"/> - /> + android:fromDegrees="0" + android:toDegrees="720" + android:interpolator="@android:anim/linear_interpolator" + android:duration="2000"/> \ No newline at end of file diff --git a/starter-code/app/src/main/res/layout/activity_main.xml b/starter-code/app/src/main/res/layout/activity_main.xml index b326849..fb7b5d1 100644 --- a/starter-code/app/src/main/res/layout/activity_main.xml +++ b/starter-code/app/src/main/res/layout/activity_main.xml @@ -11,4 +11,35 @@ tools:context="generalassembly.yuliyakaleda.startercode.MainActivity"> + + +