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
|
package com.mapswithme.maps.editor;
import android.os.Bundle;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmFragment;
import com.mapswithme.util.Constants;
import com.mapswithme.util.Graphics;
import com.mapswithme.util.InputUtils;
import com.mapswithme.util.UiUtils;
public class AdvancedTimetableFragment extends BaseMwmFragment
implements View.OnClickListener, TimetableProvider
{
private boolean mIsExampleShown;
private EditText mInput;
private WebView mExample;
private TextView mExamplesTitle;
@Nullable
private String mInitTimetables;
@Nullable
TimetableChangedListener mListener;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment_timetable_advanced, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
initViews(view);
refreshTimetables();
showExample(false);
}
@Override
public void onResume()
{
super.onResume();
refreshTimetables();
}
private void initViews(View view)
{
view.findViewById(R.id.examples).setOnClickListener(this);
mInput = (EditText) view.findViewById(R.id.et__timetable);
mExample = (WebView) view.findViewById(R.id.wv__examples);
mExample.loadUrl(Constants.Url.OPENING_HOURS_MANUAL);
mExamplesTitle = (TextView) view.findViewById(R.id.tv__examples_title);
setExampleDrawables(R.drawable.ic_type_text, R.drawable.ic_expand_more);
setTextChangedListener(mInput, mListener);
}
private void showExample(boolean show)
{
mIsExampleShown = show;
if (mIsExampleShown)
{
UiUtils.show(mExample);
setExampleDrawables(R.drawable.ic_type_text, R.drawable.ic_expand_less);
}
else
{
UiUtils.hide(mExample);
setExampleDrawables(R.drawable.ic_type_text, R.drawable.ic_expand_more);
}
}
private void setExampleDrawables(@DrawableRes int left, @DrawableRes int right)
{
mExamplesTitle.setCompoundDrawablesWithIntrinsicBounds(Graphics.tint(getActivity(), left, R.attr.colorAccent), null,
Graphics.tint(getActivity(), right, R.attr.colorAccent), null);
}
@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.examples:
showExample(!mIsExampleShown);
}
}
@Nullable
@Override
public String getTimetables()
{
return mInput.getText().toString();
}
@Override
public void setTimetables(@Nullable String timetables)
{
mInitTimetables = timetables;
refreshTimetables();
}
private void refreshTimetables()
{
if (mInput == null || mInitTimetables == null)
return;
mInput.setText(mInitTimetables);
mInput.requestFocus();
InputUtils.showKeyboard(mInput);
}
void setTimetableChangedListener(@NonNull TimetableChangedListener listener)
{
mListener = listener;
setTextChangedListener(mInput, mListener);
}
private static void setTextChangedListener(@Nullable EditText input,
@Nullable TimetableChangedListener listener)
{
if (input == null || listener == null)
return;
input.addTextChangedListener(new TextWatcher()
{
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s)
{
listener.onTimetableChanged(s.toString());
}
});
}
}
|