Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BookmarkBackupView.java « widget « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b00e3d91b5e76a15f5ca94969a395809c18ec009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package com.mapswithme.maps.widget;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mapswithme.maps.R;
import com.mapswithme.util.Graphics;
import com.mapswithme.util.UiUtils;

public class BookmarkBackupView extends LinearLayout
{
  private final static int ANIMATION_DURATION = 300;

  @SuppressWarnings("NullableProblems")
  @NonNull
  private View mHeader;
  @SuppressWarnings("NullableProblems")
  @NonNull
  private View mContentLayout;
  @SuppressWarnings("NullableProblems")
  @NonNull
  private TextView mTitle;

  @NonNull
  private final OnClickListener mHeaderClickListener = v -> onHeaderClick();

  private boolean mExpanded = true;

  public BookmarkBackupView(Context context)
  {
    super(context);
    init();
  }

  public BookmarkBackupView(Context context, @Nullable AttributeSet attrs)
  {
    super(context, attrs);
    init();
  }

  public BookmarkBackupView(Context context, @Nullable AttributeSet attrs, int defStyleAttr)
  {
    super(context, attrs, defStyleAttr);
    init();
  }

  private void init()
  {
    LayoutInflater.from(getContext()).inflate(R.layout.item_bookmark_backup, this);
    mHeader = findViewById(R.id.header);
    mContentLayout = findViewById(R.id.content);
    UiUtils.showIf(mExpanded, mContentLayout);

    mTitle = mHeader.findViewById(R.id.title);
    mTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, getToggle(), null);
    mHeader.setOnClickListener(mHeaderClickListener);
  }

  private void onHeaderClick()
  {
    mExpanded = !mExpanded;
    Animator animator = mExpanded ? createFadeInAnimator() : createFadeOutAnimator();
    animator.setDuration(ANIMATION_DURATION);
    animator.start();
    mTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, getToggle(), null);
  }

  @NonNull
  private Animator createFadeInAnimator()
  {
    ObjectAnimator animator = ObjectAnimator.ofFloat(mContentLayout, "alpha", 0, 1f);
    animator.addListener(new AnimatorListenerAdapter()
    {
      @Override
      public void onAnimationStart(Animator animation)
      {
        UiUtils.show(mContentLayout);
        mHeader.setEnabled(false);
      }

      @Override
      public void onAnimationEnd(Animator animation)
      {
        mHeader.setEnabled(true);
      }
    });
    return animator;
  }

  @NonNull
  private Animator createFadeOutAnimator()
  {
    ObjectAnimator animator = ObjectAnimator.ofFloat(mContentLayout, "alpha", 1f, 0);
    animator.addListener(new AnimatorListenerAdapter()
    {
      @Override
      public void onAnimationStart(Animator animation)
      {
        mHeader.setEnabled(false);
      }

      @Override
      public void onAnimationEnd(Animator animation)
      {
        UiUtils.hide(mContentLayout);
        mHeader.setEnabled(true);
      }
    });
    return animator;
  }

  @NonNull
  private Drawable getToggle()
  {
    return Graphics.tint(getContext(),
                         mExpanded ? R.drawable.ic_expand_less : R.drawable.ic_expand_more,
                         R.attr.secondary);
  }

  public void setExpanded(boolean expanded)
  {
    if (mExpanded == expanded)
      return;

    mExpanded = expanded;
    UiUtils.showIf(mExpanded, mContentLayout);
    mTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, getToggle(), null);
  }

  public boolean getExpanded()
  {
    return mExpanded;
  }

  public void setMessage(@NonNull String msg)
  {
    TextView message = mContentLayout.findViewById(R.id.message);
    message.setText(msg);
  }

  public void setBackupButtonLabel(@NonNull String label)
  {
    TextView button = mContentLayout.findViewById(R.id.backup_button);
    button.setText(label);
  }

  public void hideBackupButton()
  {
    UiUtils.hide(mContentLayout, R.id.backup_button);
  }

  public void showBackupButton()
  {
    UiUtils.show(mContentLayout, R.id.backup_button);
  }

  public void hideRestoreButton()
  {
    UiUtils.hide(mContentLayout, R.id.restore_button);
  }

  public void showRestoreButton()
  {
    UiUtils.show(mContentLayout, R.id.restore_button);
  }

  public void hideProgressBar()
  {
    UiUtils.hide(mContentLayout, R.id.progress);
  }

  public void showProgressBar()
  {
    UiUtils.show(mContentLayout, R.id.progress);
  }

  public void setBackupClickListener(@Nullable OnClickListener listener)
  {
    mContentLayout.findViewById(R.id.backup_button).setOnClickListener(listener);
  }

  public void setRestoreClickListener(@Nullable OnClickListener listener)
  {
    mContentLayout.findViewById(R.id.restore_button).setOnClickListener(listener);
  }
}