annotate app/src/main/java/com/five_ten_sg/connectbot/HostListActivity.java @ 514:947ea334735d default tip

update copyrights
author Carl Byington <carl@five-ten-sg.com>
date Fri, 10 Feb 2023 19:13:58 -0700
parents 13a922d1fc5c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
1 /*
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
2 * ConnectBot: simple, powerful, open-source SSH client for Android
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
4 *
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
5 * Licensed under the Apache License, Version 2.0 (the "License");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
6 * you may not use this file except in compliance with the License.
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
7 * You may obtain a copy of the License at
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8 *
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
9 * http://www.apache.org/licenses/LICENSE-2.0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
10 *
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 * Unless required by applicable law or agreed to in writing, software
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
12 * distributed under the License is distributed on an "AS IS" BASIS,
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
14 * See the License for the specific language governing permissions and
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
15 * limitations under the License.
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16 */
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18 package com.five_ten_sg.connectbot;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21 import com.five_ten_sg.connectbot.bean.HostBean;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 import com.five_ten_sg.connectbot.service.TerminalBridge;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 import com.five_ten_sg.connectbot.service.TerminalManager;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 import com.five_ten_sg.connectbot.transport.TransportFactory;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
25 import com.five_ten_sg.connectbot.util.HostDatabase;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
34 import android.app.Activity;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
35 import android.app.AlertDialog;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
36 import android.app.ListActivity;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
39 import android.content.Context;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
40 import android.content.DialogInterface;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
41 import android.content.Intent;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 import android.content.Intent.ShortcutIconResource;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
43 import android.content.ServiceConnection;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44 import android.content.SharedPreferences;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45 import android.content.SharedPreferences.Editor;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
48 import android.net.Uri;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 import android.os.Build;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 import android.os.Handler;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 import android.os.IBinder;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54 import android.os.Message;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
57 import android.util.Log;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
58 import android.view.ContextMenu;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
59 import android.view.KeyEvent;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60 import android.view.LayoutInflater;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
61 import android.view.Menu;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
62 import android.view.MenuItem;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
63 import android.view.MenuItem.OnMenuItemClickListener;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
64 import android.view.View;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
65 import android.view.View.OnKeyListener;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
66 import android.view.ViewGroup;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 import android.widget.AdapterView;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
68 import android.widget.AdapterView.OnItemClickListener;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
69 import android.widget.ArrayAdapter;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
70 import android.widget.ImageView;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
71 import android.widget.ListView;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
72 import android.widget.Spinner;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
80
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
83 public final static int REQUEST_EDIT = 1;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
86
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
87 protected TerminalManager bound = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
88
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
89 protected HostDatabase hostdb;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
90 private List<HostBean> hosts;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
91 protected LayoutInflater inflater = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
92
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
93 protected boolean sortedByColor = false;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
94
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
95 private MenuItem sortcolor;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
96
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
97 private MenuItem sortlast;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
98
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
99 private Spinner transportSpinner;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
100 private TextView quickconnect;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
101
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
102 private SharedPreferences prefs = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
103
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
104 protected boolean makingShortcut = false;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
105
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
106 protected Handler updateHandler = new Handler() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
107 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
108 public void handleMessage(Message msg) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
109 HostListActivity.this.updateList();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
110 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
111 };
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
112
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
113 private ServiceConnection connection = new ServiceConnection() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
114 public void onServiceConnected(ComponentName className, IBinder service) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
115 bound = ((TerminalManager.TerminalBinder) service).getService();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
118 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
119 public void onServiceDisconnected(ComponentName className) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
120 bound = null;
34
75d86b7fd3f0 make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
121 updateList();
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
122 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
123 };
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
124
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
125 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
126 public void onStart() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
127 super.onStart();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
128 // start the terminal manager service
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
129 this.bindService(new Intent(this, TerminalManager.class), connection, Context.BIND_AUTO_CREATE);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
130
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
131 if (this.hostdb == null)
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
132 this.hostdb = new HostDatabase(this);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
133 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
134
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
135 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
136 public void onStop() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
137 super.onStop();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
138 this.unbindService(connection);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
139
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
140 if (this.hostdb != null) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
141 this.hostdb.close();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
142 this.hostdb = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
143 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
144 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
145
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
146 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
147 public void onResume() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
148 super.onResume();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
149 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
150
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
151 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
152 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
153 if (requestCode == REQUEST_EULA) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
154 if (resultCode == Activity.RESULT_OK) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
159 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
160 else {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
161 // user didnt agree, so close
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
162 this.finish();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
163 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
164 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
175 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
176
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
177 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
178 public void onCreate(Bundle icicle) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
179 super.onCreate(icicle);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
180 setContentView(R.layout.act_hostlist);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
181 this.setTitle(String.format("%s: %s",
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
182 getResources().getText(R.string.app_name),
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
183 getResources().getText(R.string.title_hosts_list)));
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
184 this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
199 // detect HTC Dream and apply special preferences
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
200 if (Build.MANUFACTURER.equals("HTC") && Build.DEVICE.equals("dream")) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
201 if (!prefs.contains(PreferenceConstants.SHIFT_FKEYS) &&
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
204 editor.putBoolean(PreferenceConstants.SHIFT_FKEYS, true);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
205 editor.putBoolean(PreferenceConstants.CTRL_FKEYS, true);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
206 editor.commit();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
207 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
208 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
220 boolean agreed = prefs.getBoolean(PreferenceConstants.EULA, false);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
223 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
230 public synchronized void onItemClick(AdapterView<?> parent, View view, int position, long id) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
233 Uri uri = host.getUri();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
234 Intent contents = new Intent(Intent.ACTION_VIEW, uri);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
235 contents.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
236
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
237 if (makingShortcut) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
238 // create shortcut if requested
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
239 ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(HostListActivity.this, R.drawable.icon);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
240 Intent intent = new Intent();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
241 intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, contents);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
242 intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, host.getNickname());
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
243 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
244 setResult(RESULT_OK, intent);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
245 finish();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
246 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
247 else {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
250 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
251 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
252 });
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
253 quickconnect = (TextView) this.findViewById(R.id.front_quickconnect);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
254 quickconnect.setVisibility(makingShortcut ? View.GONE : View.VISIBLE);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
255 quickconnect.setOnKeyListener(new OnKeyListener() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
256 public boolean onKey(View v, int keyCode, KeyEvent event) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
257 if (event.getAction() == KeyEvent.ACTION_UP) return false;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
258
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
259 if (keyCode != KeyEvent.KEYCODE_ENTER) return false;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
260
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
261 return startConsoleActivity();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
262 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
263 });
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
264 transportSpinner = (Spinner)findViewById(R.id.transport_selection);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
265 transportSpinner.setVisibility(makingShortcut ? View.GONE : View.VISIBLE);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
266 ArrayAdapter<String> transportSelection = new ArrayAdapter<String> (this,
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
267 android.R.layout.simple_spinner_item, TransportFactory.getTransportNames());
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
268 transportSelection.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
269 transportSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
270 public void onItemSelected(AdapterView<?> arg0, View view, int position, long id) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
271 String formatHint = TransportFactory.getFormatHint(
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
272 (String) transportSpinner.getSelectedItem(),
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
273 HostListActivity.this);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
274 quickconnect.setHint(formatHint);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
275 quickconnect.setError(null);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
276 quickconnect.requestFocus();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
277 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
278 public void onNothingSelected(AdapterView<?> arg0) { }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
279 });
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
280 transportSpinner.setAdapter(transportSelection);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
288 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
314 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
315 public boolean onPrepareOptionsMenu(Menu menu) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
316 super.onPrepareOptionsMenu(menu);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
317
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
318 // don't offer menus when creating shortcut
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
319 if (makingShortcut) return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
320
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
321 sortcolor.setVisible(!sortedByColor);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
322 sortlast.setVisible(sortedByColor);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
323 return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
324 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
325
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
326 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
327 public boolean onCreateOptionsMenu(Menu menu) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
328 super.onCreateOptionsMenu(menu);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
329
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
330 // don't offer menus when creating shortcut
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
331 if (makingShortcut) return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
332
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
333 // add host, ssh keys, about
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
334 sortcolor = menu.add(R.string.list_menu_sortcolor);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
335 sortcolor.setIcon(android.R.drawable.ic_menu_share);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
336 sortcolor.setOnMenuItemClickListener(new OnMenuItemClickListener() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
337 public boolean onMenuItemClick(MenuItem item) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
338 sortedByColor = true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
339 updateList();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
340 return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
341 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
342 });
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
343 sortlast = menu.add(R.string.list_menu_sortname);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
344 sortlast.setIcon(android.R.drawable.ic_menu_share);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
345 sortlast.setOnMenuItemClickListener(new OnMenuItemClickListener() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
346 public boolean onMenuItemClick(MenuItem item) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
347 sortedByColor = false;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
348 updateList();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
349 return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
350 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
351 });
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
352 MenuItem keys = menu.add(R.string.list_menu_pubkeys);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
353 keys.setIcon(android.R.drawable.ic_lock_lock);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
354 keys.setIntent(new Intent(HostListActivity.this, PubkeyListActivity.class));
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
355 MenuItem colors = menu.add(R.string.title_colors);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
356 colors.setIcon(android.R.drawable.ic_menu_slideshow);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
357 colors.setIntent(new Intent(HostListActivity.this, ColorsActivity.class));
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
358 MenuItem settings = menu.add(R.string.list_menu_settings);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
359 settings.setIcon(android.R.drawable.ic_menu_preferences);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
360 settings.setIntent(new Intent(HostListActivity.this, SettingsActivity.class));
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
361 MenuItem help = menu.add(R.string.title_help);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
362 help.setIcon(android.R.drawable.ic_menu_help);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
363 help.setIntent(new Intent(HostListActivity.this, HelpActivity.class));
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
364 return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
365 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
366
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
367
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
368 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
369 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
370 // create menu to handle hosts
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
371 // create menu to handle deleting and sharing lists
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
372 AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
373 final HostBean host = (HostBean) this.getListView().getItemAtPosition(info.position);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
374 menu.setHeaderTitle(host.getNickname());
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
375 // edit, disconnect, delete
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
376 MenuItem connect = menu.add(R.string.list_host_disconnect);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
377 final TerminalBridge bridge = bound.getConnectedBridge(host);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
378 connect.setEnabled((bridge != null));
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
379 connect.setOnMenuItemClickListener(new OnMenuItemClickListener() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
380 public boolean onMenuItemClick(MenuItem item) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
381 bridge.dispatchDisconnect(true);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
382 updateHandler.sendEmptyMessage(-1);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
383 return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
384 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
385 });
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
386 MenuItem edit = menu.add(R.string.list_host_edit);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
387 edit.setOnMenuItemClickListener(new OnMenuItemClickListener() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
388 public boolean onMenuItemClick(MenuItem item) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
389 Intent intent = new Intent(HostListActivity.this, HostEditorActivity.class);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
390 intent.putExtra(Intent.EXTRA_TITLE, host.getId());
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
391 HostListActivity.this.startActivityForResult(intent, REQUEST_EDIT);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
392 return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
393 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
394 });
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
395 MenuItem portForwards = menu.add(R.string.list_host_portforwards);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
396 portForwards.setOnMenuItemClickListener(new OnMenuItemClickListener() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
397 public boolean onMenuItemClick(MenuItem item) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
398 Intent intent = new Intent(HostListActivity.this, PortForwardListActivity.class);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
399 intent.putExtra(Intent.EXTRA_TITLE, host.getId());
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
400 HostListActivity.this.startActivityForResult(intent, REQUEST_EDIT);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
401 return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
402 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
403 });
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
404
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
405 if (!TransportFactory.canForwardPorts(host.getProtocol()))
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
406 portForwards.setEnabled(false);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
407
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
408 MenuItem delete = menu.add(R.string.list_host_delete);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
409 delete.setOnMenuItemClickListener(new OnMenuItemClickListener() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
410 public boolean onMenuItemClick(MenuItem item) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
411 // prompt user to make sure they really want this
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
412 new AlertDialog.Builder(HostListActivity.this)
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
413 .setMessage(getString(R.string.delete_message, host.getNickname()))
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
414 .setPositiveButton(R.string.delete_pos, new DialogInterface.OnClickListener() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
415 public void onClick(DialogInterface dialog, int which) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
416 // make sure we disconnect
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
417 if (bridge != null)
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
418 bridge.dispatchDisconnect(true);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
419
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
420 hostdb.deleteHost(host);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
421 updateHandler.sendEmptyMessage(-1);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
422 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
423 })
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
424 .setNegativeButton(R.string.delete_neg, null).create().show();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
425 return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
426 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
427 });
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
428 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
429
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
430 /**
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
431 * @param text
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
432 * @return
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
433 */
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
434 private boolean startConsoleActivity() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
435 Uri uri = TransportFactory.getUri((String) transportSpinner
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
436 .getSelectedItem(), quickconnect.getText().toString());
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
437
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
438 if (uri == null) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
439 quickconnect.setError(getString(R.string.list_format_error,
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
440 TransportFactory.getFormatHint(
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
441 (String) transportSpinner.getSelectedItem(),
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
442 HostListActivity.this)));
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
443 return false;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
444 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
445
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
446 HostBean host = TransportFactory.findHost(hostdb, uri);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
447
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
448 if (host == null) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
449 host = TransportFactory.getTransport(uri.getScheme()).createHost(uri);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
450 host.setColor(HostDatabase.COLOR_GRAY);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
451 host.setPubkeyId(HostDatabase.PUBKEYID_ANY);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
452 hostdb.saveHost(host);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
453 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
454
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
455 Intent intent = new Intent(HostListActivity.this, ConsoleActivity.class);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
456 intent.setData(uri);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
457 startActivity(intent);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
458 return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
459 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
13a922d1fc5c update docs
Carl Byington <carl@five-ten-sg.com>
parents: 512
diff changeset
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
13a922d1fc5c update docs
Carl Byington <carl@five-ten-sg.com>
parents: 512
diff changeset
475 fn = external_dir + accuspeech + con;
13a922d1fc5c update docs
Carl Byington <carl@five-ten-sg.com>
parents: 512
diff changeset
476 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
477 }
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 catch (Exception e) {
513
13a922d1fc5c update docs
Carl Byington <carl@five-ten-sg.com>
parents: 512
diff changeset
479 fn = download_dir + con;
13a922d1fc5c update docs
Carl Byington <carl@five-ten-sg.com>
parents: 512
diff changeset
480 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
481 }
132
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
482 String line = null;
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
483
132
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
484 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
485 if (line.length() == 0) continue; // empty
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
486
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
487 if (line.substring(0, 1).equals("#")) continue; // comment
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
488
132
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
489 if (!line.contains("://")) continue; // invalid uri
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
490
132
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
491 Uri uri = Uri.parse(line);
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
492 ContentValues values = null;
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
493
468
74b507d491c9 fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents: 466
diff changeset
494 while ((line = reader.readLine()) != null) {
74b507d491c9 fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents: 466
diff changeset
495 if (line.length() == 0) break; // empty
74b507d491c9 fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents: 466
diff changeset
496
74b507d491c9 fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents: 466
diff changeset
497 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
498
132
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
499 String [] parts = line.split("=");
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
500
135
e251b3b679c3 read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 134
diff changeset
501 if (parts.length != 2) continue;
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
502
132
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
503 if (values == null) values = new ContentValues();
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
504
197
e762997c3911 read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 196
diff changeset
505 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
506 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
507
468
74b507d491c9 fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents: 466
diff changeset
508 String scheme = uri.getScheme();
74b507d491c9 fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents: 466
diff changeset
509 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
510 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
511 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
512 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
513 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
514 }
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
515 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
516 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
517 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
518 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
519 }
ece82b571900 add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents: 468
diff changeset
520 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
521 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
522 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
523 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
524 }
199
33928f24b40d read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 198
diff changeset
525 Editor editor = prefs.edit();
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
526 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
527 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
528 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
529 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
530 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
531 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
532 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
533 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
534 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
535 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
536 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
537 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
538 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
539 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
540 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
541 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
542 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
543 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
544 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
545 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
546 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
547 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
548 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
549 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
550 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
551 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
552 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
553 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
554 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
555 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
556 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
557 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
558 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
559 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
560 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
561 types.put("debug_keycodes", "boolean");
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
562
192
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
563 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
564 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
565 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
566 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
567 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
568 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
569 }
fe0fbcf55ed9 allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents: 363
diff changeset
570 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
571 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
572 }
fe0fbcf55ed9 allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents: 363
diff changeset
573 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
574 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
575 }
192
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
576 }
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
577 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
578
192
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
579 editor.commit();
132
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
580 }
192
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
581 else {
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
582 HostBean host = TransportFactory.findHost(hostdb, uri);
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
583
192
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
584 if (host == null) {
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
585 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
586 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
587 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
588 hostdb.saveHost(host);
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
589 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
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 host = TransportFactory.findHost(hostdb, uri);
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
592
192
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
593 if (host == null) continue;
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
594
192
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
595 if (values == null) continue;
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
596
466
12e2d9dd95df add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents: 465
diff changeset
597 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
598 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
599 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
600 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
601 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
602 }
12e2d9dd95df add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents: 465
diff changeset
603
192
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
604 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
605 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
606 db.close();
f0b9ea35711a read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
607 }
132
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
608 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 244
diff changeset
609
132
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
610 reader.close();
466
12e2d9dd95df add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents: 465
diff changeset
611 if (del) (new File(fn)).delete();
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
612 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
613 }
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
614 catch (Exception e) {
457
105815cce146 minimum version android 5, target and compile version api 28
Carl Byington <carl@five-ten-sg.com>
parents: 450
diff changeset
615 Log.d(TAG, "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
616 }
466
12e2d9dd95df add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents: 465
diff changeset
617 return launch;
132
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
618 }
265a4733edcb read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
619
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
620 protected void updateList() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
621 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
622 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
623 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
624 editor.commit();
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
625 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
626
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
627 if (hostdb == null)
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
628 hostdb = new HostDatabase(this);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
629
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
630 hosts = hostdb.getHosts(sortedByColor);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
631
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
632 // Don't lose hosts that are connected via shortcuts but not in the database.
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
633 if (bound != null) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
634 for (TerminalBridge bridge : bound.bridges) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
635 if (!hosts.contains(bridge.host))
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
636 hosts.add(0, bridge.host);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
637 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
638 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
639
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
640 HostAdapter adapter = new HostAdapter(this, hosts, bound);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
641 this.setListAdapter(adapter);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
642 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
643
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
644 class HostAdapter extends ArrayAdapter<HostBean> {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
645 private List<HostBean> hosts;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
646 private final TerminalManager manager;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
647 private final ColorStateList red, green, blue;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
648
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
649 public final static int STATE_UNKNOWN = 1, STATE_CONNECTED = 2, STATE_DISCONNECTED = 3;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
650
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
651 class ViewHolder {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
652 public TextView nickname;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
653 public TextView caption;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
654 public ImageView icon;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
655 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
656
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
657 public HostAdapter(Context context, List<HostBean> hosts, TerminalManager manager) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
658 super(context, R.layout.item_host, hosts);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
659 this.hosts = hosts;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
660 this.manager = manager;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
661 red = context.getResources().getColorStateList(R.color.red);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
662 green = context.getResources().getColorStateList(R.color.green);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
663 blue = context.getResources().getColorStateList(R.color.blue);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
664 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
665
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
666 /**
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
667 * Check if we're connected to a terminal with the given host.
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
668 */
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
669 private int getConnectedState(HostBean host) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
670 // always disconnected if we dont have backend service
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
671 if (this.manager == null)
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
672 return STATE_UNKNOWN;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
673
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
674 if (manager.getConnectedBridge(host) != null)
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
675 return STATE_CONNECTED;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
676
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
677 if (manager.disconnected.contains(host))
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
678 return STATE_DISCONNECTED;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
679
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
680 return STATE_UNKNOWN;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
681 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
682
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
683 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
684 public View getView(int position, View convertView, ViewGroup parent) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
685 ViewHolder holder;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
686
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
687 if (convertView == null) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
688 convertView = inflater.inflate(R.layout.item_host, null, false);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
689 holder = new ViewHolder();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
690 holder.nickname = (TextView)convertView.findViewById(android.R.id.text1);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
691 holder.caption = (TextView)convertView.findViewById(android.R.id.text2);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
692 holder.icon = (ImageView)convertView.findViewById(android.R.id.icon);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
693 convertView.setTag(holder);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
694 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
695 else
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
696 holder = (ViewHolder) convertView.getTag();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
697
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
698 HostBean host = hosts.get(position);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
699
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
700 if (host == null) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
701 // Well, something bad happened. We can't continue.
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
702 Log.e("HostAdapter", "Host bean is null!");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
703 holder.nickname.setText("Error during lookup");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
704 holder.caption.setText("see 'adb logcat' for more");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
705 return convertView;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
706 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
707
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
708 holder.nickname.setText(host.getNickname());
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
709
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
710 switch (this.getConnectedState(host)) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
711 case STATE_UNKNOWN:
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
712 holder.icon.setImageState(new int[] { }, true);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
713 break;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
714
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
715 case STATE_CONNECTED:
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
716 holder.icon.setImageState(new int[] { android.R.attr.state_checked }, true);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
717 break;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
718
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
719 case STATE_DISCONNECTED:
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
720 holder.icon.setImageState(new int[] { android.R.attr.state_expanded }, true);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
721 break;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
722 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
723
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
724 ColorStateList chosen = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
725
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
726 if (HostDatabase.COLOR_RED.equals(host.getColor()))
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
727 chosen = this.red;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
728 else if (HostDatabase.COLOR_GREEN.equals(host.getColor()))
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
729 chosen = this.green;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
730 else if (HostDatabase.COLOR_BLUE.equals(host.getColor()))
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
731 chosen = this.blue;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
732
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
733 Context context = convertView.getContext();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
734
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
735 if (chosen != null) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
736 // set color normally if not selected
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
737 holder.nickname.setTextColor(chosen);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
738 holder.caption.setTextColor(chosen);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
739 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
740 else {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
741 // selected, so revert back to default black text
450
50d5ed32327d fix lint error
Carl Byington <carl@five-ten-sg.com>
parents: 449
diff changeset
742 holder.nickname.setTextAppearance(context, android.R.style.TextAppearance_Large);
50d5ed32327d fix lint error
Carl Byington <carl@five-ten-sg.com>
parents: 449
diff changeset
743 holder.caption.setTextAppearance(context, android.R.style.TextAppearance_Small);
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
744 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
745
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
746 long now = System.currentTimeMillis() / 1000;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
747 String nice = context.getString(R.string.bind_never);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
748
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
749 if (host.getLastConnect() > 0) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
750 int minutes = (int)((now - host.getLastConnect()) / 60);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
751
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
752 if (minutes >= 60) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
753 int hours = (minutes / 60);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
754
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
755 if (hours >= 24) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
756 int days = (hours / 24);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
757 nice = context.getString(R.string.bind_days, days);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
758 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
759 else
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
760 nice = context.getString(R.string.bind_hours, hours);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
761 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
762 else
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
763 nice = context.getString(R.string.bind_minutes, minutes);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
764 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
765
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
766 holder.caption.setText(nice);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
767 return convertView;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
768 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
769 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
770 }