mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 13:23:58 +01:00
Add list item animations and layout
This commit is contained in:
parent
cfae4feb4a
commit
a9a03e2036
5 changed files with 198 additions and 13 deletions
|
|
@ -104,8 +104,8 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
this.getView().setFocusableInTouchMode(true);
|
||||
this.getView().requestFocus();
|
||||
this.getView().setOnKeyListener( new View.OnKeyListener()
|
||||
{
|
||||
this.getView().setOnKeyListener( new View.OnKeyListener() {
|
||||
|
||||
@Override
|
||||
public boolean onKey( View v, int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
|
|
|
|||
|
|
@ -1,27 +1,40 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import android.os.CountDownTimer;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.pedrogomez.renderers.Renderer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import fr.free.nrw.commons.R;
|
||||
|
||||
class PlaceRenderer extends Renderer<Place> {
|
||||
|
||||
@BindView(R.id.tvName) TextView tvName;
|
||||
@BindView(R.id.tvDesc) TextView tvDesc;
|
||||
@BindView(R.id.distance) TextView distance;
|
||||
@BindView(R.id.icon) ImageView icon;
|
||||
private final PlaceClickedListener listener;
|
||||
@BindView(R.id.buttonLayout)
|
||||
LinearLayout buttonLayout;
|
||||
private Animation animationUp;
|
||||
private Animation animationDown;
|
||||
private final int COUNTDOWN_RUNNING_TIME = 300;
|
||||
private static ArrayList<LinearLayout> openedItems;
|
||||
|
||||
PlaceRenderer(@NonNull PlaceClickedListener listener) {
|
||||
this.listener = listener;
|
||||
|
||||
PlaceRenderer(){
|
||||
openedItems = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -32,11 +45,57 @@ class PlaceRenderer extends Renderer<Place> {
|
|||
@Override
|
||||
protected void setUpView(View view) {
|
||||
ButterKnife.bind(this, view);
|
||||
animationUp = AnimationUtils.loadAnimation(getContext(),R.anim.slide_up);
|
||||
animationDown = AnimationUtils.loadAnimation(getContext(),R.anim.slide_down);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void hookListeners(View view) {
|
||||
view.setOnClickListener(v -> listener.placeClicked(getContent()));
|
||||
final View.OnClickListener listener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if(buttonLayout.isShown()){
|
||||
closeLayout(buttonLayout);
|
||||
}else {
|
||||
openLayout(buttonLayout);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
view.setOnClickListener(listener);
|
||||
view.requestFocus();
|
||||
view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View view, boolean hasFocus) {
|
||||
if(!hasFocus && buttonLayout.isShown()){
|
||||
closeLayout(buttonLayout);
|
||||
}else if(hasFocus && !buttonLayout.isShown()) {
|
||||
listener.onClick(view);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void closeLayout(LinearLayout buttonLayout) {
|
||||
|
||||
buttonLayout.startAnimation(animationUp);
|
||||
CountDownTimer countDownTimerStatic = new CountDownTimer(COUNTDOWN_RUNNING_TIME
|
||||
, 16) {
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
buttonLayout.setVisibility(View.GONE);
|
||||
}
|
||||
};
|
||||
countDownTimerStatic.start();
|
||||
}
|
||||
|
||||
private void openLayout(LinearLayout buttonLayout){
|
||||
buttonLayout.setVisibility(View.VISIBLE);
|
||||
buttonLayout.startAnimation(animationDown);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -51,8 +110,4 @@ class PlaceRenderer extends Renderer<Place> {
|
|||
distance.setText(place.distance);
|
||||
icon.setImageResource(place.getLabel().getIcon());
|
||||
}
|
||||
|
||||
interface PlaceClickedListener {
|
||||
void placeClicked(Place place);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue