This repository has been archived by the owner on Aug 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
QueryView.java
160 lines (131 loc) · 5.13 KB
/
QueryView.java
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
package net.lutzky.transportdroidil;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
public class QueryView extends LinearLayout implements View.OnClickListener {
private OnSearchButtonClickListener onSearchButtonClickListener = null;
public void setOnSearchButtonClickListener(
OnSearchButtonClickListener onSearchButtonClickListener) {
this.onSearchButtonClickListener = onSearchButtonClickListener;
}
public QueryView(final Context context, AttributeSet attrs) {
super(context, attrs);
inflate(context, R.layout.query, this);
ArrayAdapter<String> placesAdapter = new ArrayAdapter<String>(context,
R.layout.list_item);
ArrayAdapter<String> timeAdapter = new ArrayAdapter<String>(context,
R.layout.list_item);
getFromTextView().setAdapter(placesAdapter);
getToTextView().setAdapter(placesAdapter);
getTimeTextView().setAdapter(timeAdapter);
// Share the list of completion options.
getToTextView().setCompletionOptions(getFromTextView().getCompletionOptions());
final Button submit_egged = (Button) findViewById(R.id.submit_egged);
final Button submit_busgovil = (Button) findViewById(R.id.submit_busgovil);
getTimeTextView().setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int action, KeyEvent event) {
if (action == EditorInfo.IME_ACTION_SEARCH) {
if (submit_busgovil.getVisibility() == VISIBLE)
onClick(submit_busgovil);
else if (submit_egged.getVisibility() == VISIBLE)
onClick(submit_egged);
return true;
}
return false;
}
});
final AutolocationTextView queryFrom = (AutolocationTextView)findViewById(R.id.query_from);
final EnhancedTextView queryTo = (EnhancedTextView)findViewById(R.id.query_to);
ImageButton locateMe = (ImageButton)findViewById(R.id.locate_me);
locateMe.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
queryFrom.startSearch();
}
});
ImageButton reverse = (ImageButton)findViewById(R.id.reverse);
reverse.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
CharSequence temp = queryTo.getText();
queryTo.setText(queryFrom.getText());
queryFrom.setText(temp);
queryFrom.markAsCustom();
}
});
submit_egged.setOnClickListener(this);
submit_busgovil.setOnClickListener(this);
}
public void savePersistentState(SharedPreferences settings) {
getFromTextView().savePersistentState(settings);
// Not called for to because its shared with from.
getTimeTextView().savePersistentState(settings);
}
public void loadPersistentState(SharedPreferences settings) {
getFromTextView().loadPersistentState(settings);
// Not called for to because its shared with from.
getTimeTextView().loadPersistentState(settings);
}
public void clearCompletionOptions(SharedPreferences settings) {
getFromTextView().clearCompletionOptions(settings);
// Not called for to because its shared with from.
getTimeTextView().clearCompletionOptions(settings);
}
public String getQueryString() {
String from = getFromTextView().getString();
String to = getToTextView().getString();
String time = getTimeTextView().getString();
return from + " ל" + to + " " + time;
}
public void setButtonsEnabled(boolean enabled) {
Button submit_egged = (Button) findViewById(R.id.submit_egged);
Button submit_busgovil = (Button) findViewById(R.id.submit_busgovil);
submit_egged.setEnabled(enabled);
submit_busgovil.setEnabled(enabled);
}
EnhancedTextView getFromTextView() {
return (EnhancedTextView) findViewById(R.id.query_from);
}
EnhancedTextView getToTextView() {
return (EnhancedTextView) findViewById(R.id.query_to);
}
EnhancedTextView getTimeTextView() {
return (EnhancedTextView) findViewById(R.id.query_time);
}
public void setProvider(String provider) {
Button motButton = (Button) findViewById(R.id.submit_busgovil),
eggedButton = (Button) findViewById(R.id.submit_egged);
if (provider.equals("mot")) {
motButton.setVisibility(VISIBLE);
eggedButton.setVisibility(GONE);
}
else if (provider.equals("egged")) {
motButton.setVisibility(GONE);
eggedButton.setVisibility(VISIBLE);
}
}
@Override
public void onClick(View v) {
final InputMethodManager imm = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
getFromTextView().addCurrentValueAsCompletion();
getToTextView().addCurrentValueAsCompletion();
getTimeTextView().addCurrentValueAsCompletion();
if (onSearchButtonClickListener != null) {
imm.hideSoftInputFromWindow(getFromTextView().getWindowToken(), 0);
onSearchButtonClickListener.onSearchButtonClick(QueryView.this, v.getId());
}
}
}
interface OnSearchButtonClickListener {
void onSearchButtonClick(View source, int provider);
}