Mercurial > 510Connectbot
annotate app/src/main/java/com/five_ten_sg/connectbot/HostListActivity.java @ 528:0c031070b4ad default tip
fix vt320 delete area, incorrect parameter order
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 30 Aug 2024 12:41:52 -0600 |
parents | 775a81a78a2b |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * ConnectBot: simple, powerful, open-source SSH client for Android | |
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey | |
4 * | |
5 * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 * you may not use this file except in compliance with the License. | |
7 * You may obtain a copy of the License at | |
8 * | |
9 * http://www.apache.org/licenses/LICENSE-2.0 | |
10 * | |
11 * Unless required by applicable law or agreed to in writing, software | |
12 * distributed under the License is distributed on an "AS IS" BASIS, | |
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 * See the License for the specific language governing permissions and | |
15 * limitations under the License. | |
16 */ | |
17 | |
18 package com.five_ten_sg.connectbot; | |
19 | |
20 | |
21 import com.five_ten_sg.connectbot.bean.HostBean; | |
22 import com.five_ten_sg.connectbot.service.TerminalBridge; | |
23 import com.five_ten_sg.connectbot.service.TerminalManager; | |
24 import com.five_ten_sg.connectbot.transport.TransportFactory; | |
25 import com.five_ten_sg.connectbot.util.HostDatabase; | |
26 import com.five_ten_sg.connectbot.util.PreferenceConstants; | |
135
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
27 |
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
28 import java.io.BufferedReader; |
136
398503d13f35
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
135
diff
changeset
|
29 import java.io.FileReader; |
134
81cafbe7cd9b
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
132
diff
changeset
|
30 import java.io.File; |
195
e98ac723383f
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
194
diff
changeset
|
31 import java.util.HashMap; |
135
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
32 import java.util.List; |
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
33 |
0 | 34 import android.app.Activity; |
35 import android.app.AlertDialog; | |
36 import android.app.ListActivity; | |
37 import android.content.ComponentName; | |
135
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
38 import android.content.ContentValues; |
0 | 39 import android.content.Context; |
40 import android.content.DialogInterface; | |
41 import android.content.Intent; | |
42 import android.content.Intent.ShortcutIconResource; | |
43 import android.content.ServiceConnection; | |
44 import android.content.SharedPreferences; | |
45 import android.content.SharedPreferences.Editor; | |
46 import android.content.res.ColorStateList; | |
135
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
47 import android.database.sqlite.SQLiteDatabase; |
0 | 48 import android.net.Uri; |
49 import android.os.Build; | |
50 import android.os.Bundle; | |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
51 import android.os.Environment; |
0 | 52 import android.os.Handler; |
53 import android.os.IBinder; | |
54 import android.os.Message; | |
55 import android.preference.PreferenceManager; | |
498
3feac274a27b
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
497
diff
changeset
|
56 import android.provider.Settings; |
0 | 57 import android.util.Log; |
58 import android.view.ContextMenu; | |
59 import android.view.KeyEvent; | |
60 import android.view.LayoutInflater; | |
61 import android.view.Menu; | |
62 import android.view.MenuItem; | |
63 import android.view.MenuItem.OnMenuItemClickListener; | |
64 import android.view.View; | |
65 import android.view.View.OnKeyListener; | |
66 import android.view.ViewGroup; | |
67 import android.widget.AdapterView; | |
68 import android.widget.AdapterView.OnItemClickListener; | |
69 import android.widget.ArrayAdapter; | |
70 import android.widget.ImageView; | |
71 import android.widget.ListView; | |
72 import android.widget.Spinner; | |
73 import android.widget.TextView; | |
500
11d714165a2d
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
499
diff
changeset
|
74 import android.widget.Toast; |
465
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
75 import android.content.pm.PackageManager; |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
76 import android.os.Build; |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
77 import android.Manifest; |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
78 import android.support.v4.app.ActivityCompat; |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
79 import android.support.v4.content.ContextCompat; |
0 | 80 |
81 public class HostListActivity extends ListActivity { | |
134
81cafbe7cd9b
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
132
diff
changeset
|
82 protected static final String TAG = "ConnectBot.HostListActivity"; |
0 | 83 public final static int REQUEST_EDIT = 1; |
84 public final static int REQUEST_EULA = 2; | |
501
aee5f34cc2db
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
500
diff
changeset
|
85 public final static int REQUEST_STORAGE_MANAGER = 3; |
0 | 86 |
87 protected TerminalManager bound = null; | |
88 | |
89 protected HostDatabase hostdb; | |
90 private List<HostBean> hosts; | |
91 protected LayoutInflater inflater = null; | |
92 | |
93 protected boolean sortedByColor = false; | |
94 | |
95 private MenuItem sortcolor; | |
96 | |
97 private MenuItem sortlast; | |
98 | |
99 private Spinner transportSpinner; | |
100 private TextView quickconnect; | |
101 | |
102 private SharedPreferences prefs = null; | |
103 | |
104 protected boolean makingShortcut = false; | |
105 | |
106 protected Handler updateHandler = new Handler() { | |
107 @Override | |
108 public void handleMessage(Message msg) { | |
109 HostListActivity.this.updateList(); | |
110 } | |
111 }; | |
112 | |
113 private ServiceConnection connection = new ServiceConnection() { | |
114 public void onServiceConnected(ComponentName className, IBinder service) { | |
115 bound = ((TerminalManager.TerminalBinder) service).getService(); | |
116 // update our listview binder to find the service | |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
117 updateList(); |
0 | 118 } |
119 public void onServiceDisconnected(ComponentName className) { | |
120 bound = null; | |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
121 updateList(); |
0 | 122 } |
123 }; | |
124 | |
125 @Override | |
126 public void onStart() { | |
127 super.onStart(); | |
128 // start the terminal manager service | |
129 this.bindService(new Intent(this, TerminalManager.class), connection, Context.BIND_AUTO_CREATE); | |
130 | |
131 if (this.hostdb == null) | |
132 this.hostdb = new HostDatabase(this); | |
133 } | |
134 | |
135 @Override | |
136 public void onStop() { | |
137 super.onStop(); | |
138 this.unbindService(connection); | |
139 | |
140 if (this.hostdb != null) { | |
141 this.hostdb.close(); | |
142 this.hostdb = null; | |
143 } | |
144 } | |
145 | |
146 @Override | |
147 public void onResume() { | |
148 super.onResume(); | |
149 } | |
150 | |
151 @Override | |
152 protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
153 if (requestCode == REQUEST_EULA) { | |
154 if (resultCode == Activity.RESULT_OK) { | |
155 // yay they agreed, so store that info | |
198
a9fb5061cca3
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
197
diff
changeset
|
156 Editor editor = prefs.edit(); |
a9fb5061cca3
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
197
diff
changeset
|
157 editor.putBoolean(PreferenceConstants.EULA, true); |
a9fb5061cca3
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
197
diff
changeset
|
158 editor.commit(); |
0 | 159 } |
160 else { | |
161 // user didnt agree, so close | |
162 this.finish(); | |
163 } | |
164 } | |
165 else if (requestCode == REQUEST_EDIT) { | |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
166 updateList(); |
0 | 167 } |
500
11d714165a2d
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
499
diff
changeset
|
168 else if (requestCode == REQUEST_STORAGE_MANAGER) { |
11d714165a2d
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
499
diff
changeset
|
169 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { |
11d714165a2d
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
499
diff
changeset
|
170 if (!Environment.isExternalStorageManager()) { |
11d714165a2d
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
499
diff
changeset
|
171 Toast.makeText(this, "Allow permission for storage access!", Toast.LENGTH_SHORT).show(); |
11d714165a2d
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
499
diff
changeset
|
172 } |
11d714165a2d
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
499
diff
changeset
|
173 } |
11d714165a2d
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
499
diff
changeset
|
174 } |
0 | 175 } |
176 | |
177 @Override | |
178 public void onCreate(Bundle icicle) { | |
179 super.onCreate(icicle); | |
180 setContentView(R.layout.act_hostlist); | |
181 this.setTitle(String.format("%s: %s", | |
182 getResources().getText(R.string.app_name), | |
183 getResources().getText(R.string.title_hosts_list))); | |
184 this.prefs = PreferenceManager.getDefaultSharedPreferences(this); | |
185 | |
465
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
186 // ask for permissions, must match AndroidManifest.xml |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
187 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
499
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
188 get_permissions(new String[] {Manifest.permission.ACCESS_NETWORK_STATE, |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
189 Manifest.permission.INTERNET, |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
190 Manifest.permission.WAKE_LOCK}); |
498
3feac274a27b
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
497
diff
changeset
|
191 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { |
499
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
192 get_storage_manager(); |
498
3feac274a27b
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
497
diff
changeset
|
193 } |
3feac274a27b
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
497
diff
changeset
|
194 else { |
499
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
195 get_permissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}); |
498
3feac274a27b
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
497
diff
changeset
|
196 } |
465
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
197 } |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
198 |
0 | 199 // detect HTC Dream and apply special preferences |
200 if (Build.MANUFACTURER.equals("HTC") && Build.DEVICE.equals("dream")) { | |
201 if (!prefs.contains(PreferenceConstants.SHIFT_FKEYS) && | |
202 !prefs.contains(PreferenceConstants.CTRL_FKEYS)) { | |
199
33928f24b40d
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
198
diff
changeset
|
203 Editor editor = prefs.edit(); |
0 | 204 editor.putBoolean(PreferenceConstants.SHIFT_FKEYS, true); |
205 editor.putBoolean(PreferenceConstants.CTRL_FKEYS, true); | |
206 editor.commit(); | |
207 } | |
208 } | |
209 | |
359
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
210 makingShortcut = Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction()) |
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
211 || Intent.ACTION_PICK.equals(getIntent().getAction()); |
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
212 |
512
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
213 // connect with hosts database, read connections file, and populate list |
359
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
214 hostdb = new HostDatabase(this); |
512
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
215 // build hosts from a connections text file |
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
216 Uri launch = createHostConnections(); |
359
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
217 updateList(); |
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
218 |
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
219 // check for eula agreement, which might be set from the deployment file |
0 | 220 boolean agreed = prefs.getBoolean(PreferenceConstants.EULA, false); |
221 if (!agreed) { | |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
222 startActivityForResult(new Intent(this, WizardActivity.class), REQUEST_EULA); |
0 | 223 } |
224 | |
359
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
225 // show the list |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
226 sortedByColor = prefs.getBoolean(PreferenceConstants.SORT_BY_COLOR, false); |
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
227 registerForContextMenu(getListView()); |
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
228 getListView().setOnItemClickListener(new OnItemClickListener() { |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
35
diff
changeset
|
229 |
0 | 230 public synchronized void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
231 // launch off to console details | |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
232 HostBean host = (HostBean) getListView().getItemAtPosition(position); |
0 | 233 Uri uri = host.getUri(); |
234 Intent contents = new Intent(Intent.ACTION_VIEW, uri); | |
235 contents.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |
236 | |
237 if (makingShortcut) { | |
238 // create shortcut if requested | |
239 ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(HostListActivity.this, R.drawable.icon); | |
240 Intent intent = new Intent(); | |
241 intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, contents); | |
242 intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, host.getNickname()); | |
243 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); | |
244 setResult(RESULT_OK, intent); | |
245 finish(); | |
246 } | |
247 else { | |
248 // otherwise just launch activity to show this host | |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
249 startActivity(contents); |
0 | 250 } |
251 } | |
252 }); | |
253 quickconnect = (TextView) this.findViewById(R.id.front_quickconnect); | |
254 quickconnect.setVisibility(makingShortcut ? View.GONE : View.VISIBLE); | |
255 quickconnect.setOnKeyListener(new OnKeyListener() { | |
256 public boolean onKey(View v, int keyCode, KeyEvent event) { | |
257 if (event.getAction() == KeyEvent.ACTION_UP) return false; | |
258 | |
259 if (keyCode != KeyEvent.KEYCODE_ENTER) return false; | |
260 | |
261 return startConsoleActivity(); | |
262 } | |
263 }); | |
264 transportSpinner = (Spinner)findViewById(R.id.transport_selection); | |
265 transportSpinner.setVisibility(makingShortcut ? View.GONE : View.VISIBLE); | |
266 ArrayAdapter<String> transportSelection = new ArrayAdapter<String> (this, | |
267 android.R.layout.simple_spinner_item, TransportFactory.getTransportNames()); | |
268 transportSelection.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | |
269 transportSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
270 public void onItemSelected(AdapterView<?> arg0, View view, int position, long id) { | |
271 String formatHint = TransportFactory.getFormatHint( | |
272 (String) transportSpinner.getSelectedItem(), | |
273 HostListActivity.this); | |
274 quickconnect.setHint(formatHint); | |
275 quickconnect.setError(null); | |
276 quickconnect.requestFocus(); | |
277 } | |
278 public void onNothingSelected(AdapterView<?> arg0) { } | |
279 }); | |
280 transportSpinner.setAdapter(transportSelection); | |
281 this.inflater = LayoutInflater.from(this); | |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
282 |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
283 if (launch != null) { |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
284 Intent contents = new Intent(Intent.ACTION_VIEW, launch); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
285 contents.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
286 startActivity(contents); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
287 } |
0 | 288 } |
289 | |
499
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
290 public void get_storage_manager() { |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
291 if (!Environment.isExternalStorageManager()) { |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
292 try { |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
293 Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
294 intent.addCategory("android.intent.category.DEFAULT"); |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
295 intent.setData(Uri.parse(String.format("package:%s",getApplicationContext().getPackageName()))); |
500
11d714165a2d
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
499
diff
changeset
|
296 startActivityForResult(intent, REQUEST_STORAGE_MANAGER); |
499
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
297 } catch (Exception e) { |
501
aee5f34cc2db
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
500
diff
changeset
|
298 Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); |
500
11d714165a2d
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
499
diff
changeset
|
299 startActivityForResult(intent, REQUEST_STORAGE_MANAGER); |
499
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
300 } |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
301 } |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
302 } |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
303 |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
304 public void get_permissions(String [] perms) { |
465
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
305 boolean need = false; |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
306 for (String perm : perms) { |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
307 if (ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED) { |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
308 need = true; |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
309 } |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
310 } |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
311 if (need) ActivityCompat.requestPermissions(this, perms, 1); |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
312 } |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
313 |
0 | 314 @Override |
315 public boolean onPrepareOptionsMenu(Menu menu) { | |
316 super.onPrepareOptionsMenu(menu); | |
317 | |
318 // don't offer menus when creating shortcut | |
319 if (makingShortcut) return true; | |
320 | |
321 sortcolor.setVisible(!sortedByColor); | |
322 sortlast.setVisible(sortedByColor); | |
323 return true; | |
324 } | |
325 | |
326 @Override | |
327 public boolean onCreateOptionsMenu(Menu menu) { | |
328 super.onCreateOptionsMenu(menu); | |
329 | |
330 // don't offer menus when creating shortcut | |
331 if (makingShortcut) return true; | |
332 | |
333 // add host, ssh keys, about | |
334 sortcolor = menu.add(R.string.list_menu_sortcolor); | |
335 sortcolor.setIcon(android.R.drawable.ic_menu_share); | |
336 sortcolor.setOnMenuItemClickListener(new OnMenuItemClickListener() { | |
337 public boolean onMenuItemClick(MenuItem item) { | |
338 sortedByColor = true; | |
339 updateList(); | |
340 return true; | |
341 } | |
342 }); | |
343 sortlast = menu.add(R.string.list_menu_sortname); | |
344 sortlast.setIcon(android.R.drawable.ic_menu_share); | |
345 sortlast.setOnMenuItemClickListener(new OnMenuItemClickListener() { | |
346 public boolean onMenuItemClick(MenuItem item) { | |
347 sortedByColor = false; | |
348 updateList(); | |
349 return true; | |
350 } | |
351 }); | |
352 MenuItem keys = menu.add(R.string.list_menu_pubkeys); | |
353 keys.setIcon(android.R.drawable.ic_lock_lock); | |
354 keys.setIntent(new Intent(HostListActivity.this, PubkeyListActivity.class)); | |
355 MenuItem colors = menu.add(R.string.title_colors); | |
356 colors.setIcon(android.R.drawable.ic_menu_slideshow); | |
357 colors.setIntent(new Intent(HostListActivity.this, ColorsActivity.class)); | |
358 MenuItem settings = menu.add(R.string.list_menu_settings); | |
359 settings.setIcon(android.R.drawable.ic_menu_preferences); | |
360 settings.setIntent(new Intent(HostListActivity.this, SettingsActivity.class)); | |
361 MenuItem help = menu.add(R.string.title_help); | |
362 help.setIcon(android.R.drawable.ic_menu_help); | |
363 help.setIntent(new Intent(HostListActivity.this, HelpActivity.class)); | |
364 return true; | |
365 } | |
366 | |
367 | |
368 @Override | |
369 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { | |
370 // create menu to handle hosts | |
371 // create menu to handle deleting and sharing lists | |
372 AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; | |
373 final HostBean host = (HostBean) this.getListView().getItemAtPosition(info.position); | |
374 menu.setHeaderTitle(host.getNickname()); | |
375 // edit, disconnect, delete | |
376 MenuItem connect = menu.add(R.string.list_host_disconnect); | |
377 final TerminalBridge bridge = bound.getConnectedBridge(host); | |
378 connect.setEnabled((bridge != null)); | |
379 connect.setOnMenuItemClickListener(new OnMenuItemClickListener() { | |
380 public boolean onMenuItemClick(MenuItem item) { | |
381 bridge.dispatchDisconnect(true); | |
382 updateHandler.sendEmptyMessage(-1); | |
383 return true; | |
384 } | |
385 }); | |
386 MenuItem edit = menu.add(R.string.list_host_edit); | |
387 edit.setOnMenuItemClickListener(new OnMenuItemClickListener() { | |
388 public boolean onMenuItemClick(MenuItem item) { | |
389 Intent intent = new Intent(HostListActivity.this, HostEditorActivity.class); | |
390 intent.putExtra(Intent.EXTRA_TITLE, host.getId()); | |
391 HostListActivity.this.startActivityForResult(intent, REQUEST_EDIT); | |
392 return true; | |
393 } | |
394 }); | |
395 MenuItem portForwards = menu.add(R.string.list_host_portforwards); | |
396 portForwards.setOnMenuItemClickListener(new OnMenuItemClickListener() { | |
397 public boolean onMenuItemClick(MenuItem item) { | |
398 Intent intent = new Intent(HostListActivity.this, PortForwardListActivity.class); | |
399 intent.putExtra(Intent.EXTRA_TITLE, host.getId()); | |
400 HostListActivity.this.startActivityForResult(intent, REQUEST_EDIT); | |
401 return true; | |
402 } | |
403 }); | |
404 | |
405 if (!TransportFactory.canForwardPorts(host.getProtocol())) | |
406 portForwards.setEnabled(false); | |
407 | |
408 MenuItem delete = menu.add(R.string.list_host_delete); | |
409 delete.setOnMenuItemClickListener(new OnMenuItemClickListener() { | |
410 public boolean onMenuItemClick(MenuItem item) { | |
411 // prompt user to make sure they really want this | |
412 new AlertDialog.Builder(HostListActivity.this) | |
413 .setMessage(getString(R.string.delete_message, host.getNickname())) | |
414 .setPositiveButton(R.string.delete_pos, new DialogInterface.OnClickListener() { | |
415 public void onClick(DialogInterface dialog, int which) { | |
416 // make sure we disconnect | |
417 if (bridge != null) | |
418 bridge.dispatchDisconnect(true); | |
419 | |
420 hostdb.deleteHost(host); | |
421 updateHandler.sendEmptyMessage(-1); | |
422 } | |
423 }) | |
424 .setNegativeButton(R.string.delete_neg, null).create().show(); | |
425 return true; | |
426 } | |
427 }); | |
428 } | |
429 | |
430 /** | |
431 * @param text | |
432 * @return | |
433 */ | |
434 private boolean startConsoleActivity() { | |
435 Uri uri = TransportFactory.getUri((String) transportSpinner | |
436 .getSelectedItem(), quickconnect.getText().toString()); | |
437 | |
438 if (uri == null) { | |
439 quickconnect.setError(getString(R.string.list_format_error, | |
440 TransportFactory.getFormatHint( | |
441 (String) transportSpinner.getSelectedItem(), | |
442 HostListActivity.this))); | |
443 return false; | |
444 } | |
445 | |
446 HostBean host = TransportFactory.findHost(hostdb, uri); | |
447 | |
448 if (host == null) { | |
449 host = TransportFactory.getTransport(uri.getScheme()).createHost(uri); | |
450 host.setColor(HostDatabase.COLOR_GRAY); | |
451 host.setPubkeyId(HostDatabase.PUBKEYID_ANY); | |
452 hostdb.saveHost(host); | |
453 } | |
454 | |
455 Intent intent = new Intent(HostListActivity.this, ConsoleActivity.class); | |
456 intent.setData(uri); | |
457 startActivity(intent); | |
458 return true; | |
459 } | |
460 | |
512
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
461 private Uri createHostConnections() { |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
462 Uri launch = null; |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
463 try { |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
464 boolean del = true; |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
465 int[] c = hostdb.getGlobalDefaultColors(); |
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
466 int fg = c[0]; |
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
467 int bg = c[1]; |
512
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
468 String con = "/510Connectbot.connections"; |
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
469 String external_dir = Environment.getExternalStorageDirectory().getAbsolutePath(); |
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
470 String accuspeech = "/AccuSpeech/VoiceProjects"; |
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
471 String download_dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(); |
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
472 BufferedReader reader = null; |
513 | 473 String fn; |
512
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
474 try { |
513 | 475 fn = external_dir + accuspeech + con; |
519 | 476 Log.d(TAG, "trying to read " + fn); |
513 | 477 reader = new BufferedReader(new FileReader(fn)); |
512
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
478 } |
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
479 catch (Exception e) { |
519 | 480 try { |
481 fn = download_dir + con; | |
482 Log.d(TAG, "trying to read " + fn); | |
483 reader = new BufferedReader(new FileReader(fn)); | |
484 } | |
520 | 485 catch (Exception ee) { |
521 | 486 Log.d(TAG, ee.getMessage() + "cannot read either file"); |
520 | 487 return launch; |
519 | 488 } |
512
e1dd1fd46e18
change connections file name and look for it in the accuspeech voice projects directory, then the downloads directory
Carl Byington <carl@five-ten-sg.com>
parents:
501
diff
changeset
|
489 } |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
490 String line = null; |
307 | 491 |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
492 while ((line = reader.readLine()) != null) { |
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
493 if (line.length() == 0) continue; // empty |
307 | 494 |
495 if (line.substring(0, 1).equals("#")) continue; // comment | |
496 | |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
497 if (!line.contains("://")) continue; // invalid uri |
307 | 498 |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
499 Uri uri = Uri.parse(line); |
523 | 500 Log.d(TAG, "uri: " + uri.toString()); |
521 | 501 |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
502 ContentValues values = null; |
307 | 503 |
468
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
504 while ((line = reader.readLine()) != null) { |
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
505 if (line.length() == 0) break; // empty |
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
506 |
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
507 if (line.substring(0, 1).equals("#")) continue; // comment |
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
508 |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
509 String [] parts = line.split("="); |
307 | 510 |
135
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
511 if (parts.length != 2) continue; |
307 | 512 |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
513 if (values == null) values = new ContentValues(); |
307 | 514 |
197
e762997c3911
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
196
diff
changeset
|
515 values.put(parts[0].trim(), parts[1].trim()); |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
516 } |
307 | 517 |
468
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
518 String scheme = uri.getScheme(); |
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
519 if (scheme.equals("global")) { |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
520 String dd = "delete_deployment"; |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
521 if (values.containsKey(dd)) { |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
522 String sv = values.getAsString(dd); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
523 del = Boolean.parseBoolean(sv); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
524 } |
474
e5f8d879543f
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
473
diff
changeset
|
525 dd = "fg_color"; |
475
0fb80a0d6be9
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
474
diff
changeset
|
526 if (values.containsKey(dd)) { |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
527 String sv = values.getAsString(dd); |
476
186d340afd3b
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
475
diff
changeset
|
528 fg = Integer.parseInt(sv) - 1; |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
529 } |
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
530 dd = "bg_color"; |
475
0fb80a0d6be9
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
474
diff
changeset
|
531 if (values.containsKey(dd)) { |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
532 String sv = values.getAsString(dd); |
476
186d340afd3b
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
475
diff
changeset
|
533 bg = Integer.parseInt(sv) - 1; |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
534 } |
199
33928f24b40d
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
198
diff
changeset
|
535 Editor editor = prefs.edit(); |
307 | 536 HashMap<String, String> types = new HashMap<String, String>(); |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
537 HashMap<String, String> types2 = new HashMap<String, String>(); |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
538 types.put("memkeys", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
539 types.put("connPersist", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
540 types.put("emulation", "string"); |
364
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
541 types.put("scrollback", "string"); |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
542 types.put("rotation", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
543 types.put("shiftfkeys", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
544 types.put("ctrlfkeys", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
545 types.put("keymode", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
546 types.put("camera", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
547 types.put("volup", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
548 types.put("voldn", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
549 types.put("search", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
550 types.put("ptt", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
551 types.put("keepalive", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
552 types.put("wifilock", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
553 types.put("bumpyarrows", "boolean"); |
363
5b0636e6a910
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
359
diff
changeset
|
554 types.put("eula", "boolean"); |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
555 types.put("extended_longpress", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
556 types.put("ctrl_string", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
557 types.put("picker_string", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
558 types.put("picker_keep_open", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
559 types.put("list_custom_keymap", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
560 types.put("bell", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
561 types.put("bellVolume", "float"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
562 types.put("bellVibrate", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
563 types.put("bellNotification", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
564 types.put("screen_capture_folder", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
565 types.put("screen_capture_popup", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
566 types.put("file_dialog", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
567 types.put("download_folder", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
568 types.put("remote_upload_folder", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
569 types.put("upload_dest_prompt", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
570 types.put("background_file_transfer", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
571 types.put("debug_keycodes", "boolean"); |
307 | 572 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
573 for (String key : values.keySet()) { |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
574 if (types.containsKey(key)) { |
364
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
575 String t = types.get(key); |
202
b16288cbad37
configure hardware buttons for showing soft function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
201
diff
changeset
|
576 String sv = values.getAsString(key); |
364
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
577 if (t.equals("float")) { |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
578 editor.putFloat(key, Float.parseFloat(sv)); |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
579 } |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
580 else if (t.equals("boolean")) { |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
581 editor.putBoolean(key, Boolean.parseBoolean(sv)); |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
582 } |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
583 else if (t.equals("string")) { |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
584 editor.putString(key, sv); |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
585 } |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
586 } |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
587 } |
307 | 588 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
589 editor.commit(); |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
590 } |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
591 else { |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
592 HostBean host = TransportFactory.findHost(hostdb, uri); |
307 | 593 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
594 if (host == null) { |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
595 host = TransportFactory.getTransport(uri.getScheme()).createHost(uri); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
596 host.setColor(HostDatabase.COLOR_GRAY); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
597 host.setPubkeyId(HostDatabase.PUBKEYID_ANY); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
598 hostdb.saveHost(host); |
521 | 599 Log.d(TAG, "created new host: " + host.getId()); |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
600 } |
307 | 601 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
602 host = TransportFactory.findHost(hostdb, uri); |
307 | 603 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
604 if (host == null) continue; |
521 | 605 Log.d(TAG, "found host: " + host.getId()); |
307 | 606 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
607 if (values == null) continue; |
307 | 608 |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
609 String key = "autolaunch"; |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
610 if (values.containsKey(key)) { |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
611 String sv = values.getAsString(key); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
612 if (Boolean.parseBoolean(sv)) launch = uri; |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
613 values.remove(key); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
614 } |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
615 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
616 SQLiteDatabase db = hostdb.getWritableDatabase(); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
617 db.update(HostDatabase.TABLE_HOSTS, values, "_id = ?", new String[] { String.valueOf(host.getId()) }); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
618 db.close(); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
619 } |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
620 } |
307 | 621 |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
622 reader.close(); |
522 | 623 if (del) { |
624 Log.d(TAG, "try to delete " + fn); | |
625 (new File(fn)).delete(); | |
626 } | |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
627 hostdb.setDefaultColorsForScheme(hostdb.DEFAULT_COLOR_SCHEME, fg, bg); |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
628 } |
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
629 catch (Exception e) { |
519 | 630 Log.d(TAG, e.getMessage() + " Deployment scan failed."); |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
631 } |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
632 return launch; |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
633 } |
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
634 |
0 | 635 protected void updateList() { |
636 if (prefs.getBoolean(PreferenceConstants.SORT_BY_COLOR, false) != sortedByColor) { | |
198
a9fb5061cca3
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
197
diff
changeset
|
637 Editor editor = prefs.edit(); |
a9fb5061cca3
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
197
diff
changeset
|
638 editor.putBoolean(PreferenceConstants.SORT_BY_COLOR, sortedByColor); |
a9fb5061cca3
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
197
diff
changeset
|
639 editor.commit(); |
0 | 640 } |
641 | |
642 if (hostdb == null) | |
643 hostdb = new HostDatabase(this); | |
644 | |
645 hosts = hostdb.getHosts(sortedByColor); | |
646 | |
647 // Don't lose hosts that are connected via shortcuts but not in the database. | |
648 if (bound != null) { | |
649 for (TerminalBridge bridge : bound.bridges) { | |
650 if (!hosts.contains(bridge.host)) | |
651 hosts.add(0, bridge.host); | |
652 } | |
653 } | |
654 | |
655 HostAdapter adapter = new HostAdapter(this, hosts, bound); | |
656 this.setListAdapter(adapter); | |
657 } | |
658 | |
659 class HostAdapter extends ArrayAdapter<HostBean> { | |
660 private List<HostBean> hosts; | |
661 private final TerminalManager manager; | |
662 private final ColorStateList red, green, blue; | |
663 | |
664 public final static int STATE_UNKNOWN = 1, STATE_CONNECTED = 2, STATE_DISCONNECTED = 3; | |
665 | |
666 class ViewHolder { | |
667 public TextView nickname; | |
668 public TextView caption; | |
669 public ImageView icon; | |
670 } | |
671 | |
672 public HostAdapter(Context context, List<HostBean> hosts, TerminalManager manager) { | |
673 super(context, R.layout.item_host, hosts); | |
674 this.hosts = hosts; | |
675 this.manager = manager; | |
676 red = context.getResources().getColorStateList(R.color.red); | |
677 green = context.getResources().getColorStateList(R.color.green); | |
678 blue = context.getResources().getColorStateList(R.color.blue); | |
679 } | |
680 | |
681 /** | |
682 * Check if we're connected to a terminal with the given host. | |
683 */ | |
684 private int getConnectedState(HostBean host) { | |
685 // always disconnected if we dont have backend service | |
686 if (this.manager == null) | |
687 return STATE_UNKNOWN; | |
688 | |
689 if (manager.getConnectedBridge(host) != null) | |
690 return STATE_CONNECTED; | |
691 | |
692 if (manager.disconnected.contains(host)) | |
693 return STATE_DISCONNECTED; | |
694 | |
695 return STATE_UNKNOWN; | |
696 } | |
697 | |
698 @Override | |
699 public View getView(int position, View convertView, ViewGroup parent) { | |
700 ViewHolder holder; | |
701 | |
702 if (convertView == null) { | |
703 convertView = inflater.inflate(R.layout.item_host, null, false); | |
704 holder = new ViewHolder(); | |
705 holder.nickname = (TextView)convertView.findViewById(android.R.id.text1); | |
706 holder.caption = (TextView)convertView.findViewById(android.R.id.text2); | |
707 holder.icon = (ImageView)convertView.findViewById(android.R.id.icon); | |
708 convertView.setTag(holder); | |
709 } | |
710 else | |
711 holder = (ViewHolder) convertView.getTag(); | |
712 | |
713 HostBean host = hosts.get(position); | |
714 | |
715 if (host == null) { | |
716 // Well, something bad happened. We can't continue. | |
717 Log.e("HostAdapter", "Host bean is null!"); | |
718 holder.nickname.setText("Error during lookup"); | |
719 holder.caption.setText("see 'adb logcat' for more"); | |
720 return convertView; | |
721 } | |
722 | |
723 holder.nickname.setText(host.getNickname()); | |
724 | |
725 switch (this.getConnectedState(host)) { | |
726 case STATE_UNKNOWN: | |
727 holder.icon.setImageState(new int[] { }, true); | |
728 break; | |
729 | |
730 case STATE_CONNECTED: | |
731 holder.icon.setImageState(new int[] { android.R.attr.state_checked }, true); | |
732 break; | |
733 | |
734 case STATE_DISCONNECTED: | |
735 holder.icon.setImageState(new int[] { android.R.attr.state_expanded }, true); | |
736 break; | |
737 } | |
738 | |
739 ColorStateList chosen = null; | |
740 | |
741 if (HostDatabase.COLOR_RED.equals(host.getColor())) | |
742 chosen = this.red; | |
743 else if (HostDatabase.COLOR_GREEN.equals(host.getColor())) | |
744 chosen = this.green; | |
745 else if (HostDatabase.COLOR_BLUE.equals(host.getColor())) | |
746 chosen = this.blue; | |
747 | |
748 Context context = convertView.getContext(); | |
749 | |
750 if (chosen != null) { | |
751 // set color normally if not selected | |
752 holder.nickname.setTextColor(chosen); | |
753 holder.caption.setTextColor(chosen); | |
754 } | |
755 else { | |
756 // selected, so revert back to default black text | |
450 | 757 holder.nickname.setTextAppearance(context, android.R.style.TextAppearance_Large); |
758 holder.caption.setTextAppearance(context, android.R.style.TextAppearance_Small); | |
0 | 759 } |
760 | |
761 long now = System.currentTimeMillis() / 1000; | |
762 String nice = context.getString(R.string.bind_never); | |
763 | |
764 if (host.getLastConnect() > 0) { | |
765 int minutes = (int)((now - host.getLastConnect()) / 60); | |
766 | |
767 if (minutes >= 60) { | |
768 int hours = (minutes / 60); | |
769 | |
770 if (hours >= 24) { | |
771 int days = (hours / 24); | |
772 nice = context.getString(R.string.bind_days, days); | |
773 } | |
774 else | |
775 nice = context.getString(R.string.bind_hours, hours); | |
776 } | |
777 else | |
778 nice = context.getString(R.string.bind_minutes, minutes); | |
779 } | |
780 | |
781 holder.caption.setText(nice); | |
782 return convertView; | |
783 } | |
784 } | |
785 } |