use of android.widget.TableRow in project smoke by textbrowser.
the class Chat method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
m_connectionStatusScheduler = Executors.newSingleThreadScheduledExecutor();
m_connectionStatusScheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
if (Thread.currentThread().isInterrupted())
return;
final boolean state = Kernel.getInstance().isConnected();
Chat.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Button button1 = (Button) findViewById(R.id.call);
button1.setEnabled(State.getInstance().chatCheckedParticipants() > 0 && state);
button1 = (Button) findViewById(R.id.send_chat_message);
if (state)
button1.setCompoundDrawablesWithIntrinsicBounds(R.drawable.network_up, 0, 0, 0);
else
button1.setCompoundDrawablesWithIntrinsicBounds(R.drawable.network_down, 0, 0, 0);
}
});
} catch (Exception exception) {
}
}
}, 1500, CONNECTION_STATUS_INTERVAL, TimeUnit.MILLISECONDS);
m_databaseHelper = Database.getInstance(getApplicationContext());
m_receiver = new ChatBroadcastReceiver();
m_statusScheduler = Executors.newSingleThreadScheduledExecutor();
m_statusScheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
if (!m_databaseHelper.readSetting(null, "show_chat_icons").equals("true"))
return;
ArrayList<String> arrayList = m_databaseHelper.readSipHashIdStrings(s_cryptography);
if (arrayList == null || arrayList.size() == 0)
return;
for (String string : arrayList) {
if (Thread.currentThread().isInterrupted())
return;
final String sipHashId = string;
Chat.this.runOnUiThread(new Runnable() {
@Override
public void run() {
refreshCheckBox(sipHashId);
}
});
}
arrayList.clear();
} catch (Exception exception) {
}
}
}, 1500, STATUS_INTERVAL, TimeUnit.MILLISECONDS);
setContentView(R.layout.activity_chat);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
Button button1 = (Button) findViewById(R.id.clear_chat_messages);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
TextView textView1 = (TextView) findViewById(R.id.chat_messages);
textView1.setText("");
}
});
button1 = (Button) findViewById(R.id.send_chat_message);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final TextView textView1 = (TextView) findViewById(R.id.chat_message);
if (textView1.getText().toString().trim().isEmpty())
return;
String str = textView1.getText().toString().trim();
StringBuilder stringBuilder = new StringBuilder();
TableLayout tableLayout = (TableLayout) findViewById(R.id.participants);
TextView textView2 = (TextView) findViewById(R.id.chat_messages);
textView2.append("[");
textView2.append(m_simpleDateFormat.format(new Date()));
textView2.append("] ");
{
Spannable spannable = new SpannableStringBuilder("me");
spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView2.append(spannable);
}
stringBuilder.append(": ");
stringBuilder.append(str);
stringBuilder.append("\n\n");
textView2.append(stringBuilder);
textView1.setText("");
int size = CHAT_MESSAGE_PREFERRED_SIZE * (int) Math.ceil((1.0 * str.length()) / (1.0 * CHAT_MESSAGE_PREFERRED_SIZE));
if (size > str.length()) {
char[] a = new char[size - str.length()];
Arrays.fill(a, ' ');
str += new String(a);
} else if (str.length() > 0) {
char[] a = new char[1024 + str.length() % 2];
Arrays.fill(a, ' ');
str += new String(a);
}
for (int i = 0; i < tableLayout.getChildCount(); i++) {
TableRow row = (TableRow) tableLayout.getChildAt(i);
if (row == null)
continue;
CheckBox checkBox1 = (CheckBox) row.getChildAt(0);
if (checkBox1 == null || checkBox1.getTag() == null || !checkBox1.isChecked())
continue;
String sipHashId = checkBox1.getTag().toString();
byte[] keyStream = m_databaseHelper.participantKeyStream(s_cryptography, sipHashId);
if (keyStream == null || keyStream.length != 96)
continue;
Kernel.getInstance().enqueueChatMessage(str, sipHashId, keyStream);
}
scrollMessagesView();
textView1.post(new Runnable() {
@Override
public void run() {
textView1.requestFocus();
}
});
}
});
TextView textView1 = (TextView) findViewById(R.id.chat_message);
textView1.requestFocus();
if (State.getInstance().isAuthenticated())
populateParticipants();
findViewById(R.id.view).setBackgroundColor(Color.rgb(108, 121, 137));
/*
** Preparse some event listeners.
*/
prepareListeners();
try {
textView1 = (TextView) findViewById(R.id.chat_message);
textView1.setText(State.getInstance().getCharSequence("chat.message"));
textView1 = (TextView) findViewById(R.id.chat_messages);
textView1.setText(State.getInstance().getCharSequence("chat.messages"));
} catch (Exception exception) {
}
populateChat();
}
use of android.widget.TableRow in project smoke by textbrowser.
the class Settings method populateParticipants.
private void populateParticipants() {
ArrayList<SipHashIdElement> arrayList = m_databaseHelper.readSipHashIds("", s_cryptography);
TableLayout tableLayout = (TableLayout) findViewById(R.id.participants);
tableLayout.removeAllViews();
if (arrayList == null || arrayList.size() == 0)
return;
int i = 0;
for (SipHashIdElement sipHashIdElement : arrayList) {
if (sipHashIdElement == null)
continue;
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
TableRow row = new TableRow(Settings.this);
row.setLayoutParams(layoutParams);
for (int j = 0; j < 2; j++) {
TextView textView1 = new TextView(Settings.this);
textView1.setGravity(Gravity.CENTER_VERTICAL);
textView1.setId(sipHashIdElement.m_oid);
textView1.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
if (j == 0)
textView1.setText(sipHashIdElement.m_name);
else if (j == 1) {
if (sipHashIdElement.m_epksCompleted)
textView1.setCompoundDrawablesWithIntrinsicBounds(R.drawable.lock, 0, 0, 0);
else
textView1.setCompoundDrawablesWithIntrinsicBounds(R.drawable.lockless, 0, 0, 0);
textView1.setCompoundDrawablePadding(5);
textView1.setText(Miscellaneous.delimitString(sipHashIdElement.m_sipHashId.replace(":", ""), '-', 4).toUpperCase());
}
textView1.setTag(R.id.participants, textView1.getText());
textView1.setTag(R.id.refresh_participants, sipHashIdElement.m_epksCompleted);
textView1.setTextSize(TEXTVIEW_TEXT_SIZE);
registerForContextMenu(textView1);
row.addView(textView1);
}
if (i % 2 == 0)
row.setBackgroundColor(Color.argb(100, 179, 230, 255));
tableLayout.addView(row, i);
i += 1;
}
arrayList.clear();
}
use of android.widget.TableRow in project smoke by textbrowser.
the class Settings method populateNeighbors.
private void populateNeighbors(ArrayList<NeighborElement> arrayList) {
if (arrayList == null)
arrayList = m_databaseHelper.readNeighbors(s_cryptography);
final TableLayout tableLayout = (TableLayout) findViewById(R.id.neighbors);
if (arrayList == null || arrayList.size() == 0) {
tableLayout.removeAllViews();
return;
}
StringBuilder stringBuilder = new StringBuilder();
int i = 0;
for (i = tableLayout.getChildCount() - 1; i >= 0; i--) {
TableRow row = (TableRow) tableLayout.getChildAt(i);
if (row == null)
continue;
TextView textView1 = (TextView) row.getChildAt(1);
if (textView1 == null) {
tableLayout.removeView(row);
continue;
}
boolean found = false;
for (NeighborElement neighborElement : arrayList) {
stringBuilder.setLength(0);
stringBuilder.append(neighborElement.m_remoteIpAddress);
if (neighborElement.m_ipVersion.equals("IPv6"))
if (!neighborElement.m_remoteScopeId.isEmpty()) {
stringBuilder.append("-");
stringBuilder.append(neighborElement.m_remoteScopeId);
}
stringBuilder.append(":");
stringBuilder.append(neighborElement.m_remotePort);
stringBuilder.append(":");
stringBuilder.append(neighborElement.m_transport);
if (textView1.getText().toString().contains(stringBuilder.toString())) {
found = true;
break;
}
}
if (!found)
tableLayout.removeView(row);
}
CheckBox checkBox1 = (CheckBox) findViewById(R.id.neighbor_details);
i = 0;
for (NeighborElement neighborElement : arrayList) {
if (neighborElement == null)
continue;
Spinner spinner = null;
TableRow row = null;
TextView textView1 = null;
for (int j = 0; j < tableLayout.getChildCount(); j++) {
TableRow r = (TableRow) tableLayout.getChildAt(j);
if (r == null)
continue;
TextView t = (TextView) r.getChildAt(1);
if (t == null)
continue;
stringBuilder.setLength(0);
stringBuilder.append(neighborElement.m_remoteIpAddress);
if (neighborElement.m_ipVersion.equals("IPv6"))
if (!neighborElement.m_remoteScopeId.isEmpty()) {
stringBuilder.append("-");
stringBuilder.append(neighborElement.m_remoteScopeId);
}
stringBuilder.append(":");
stringBuilder.append(neighborElement.m_remotePort);
stringBuilder.append(":");
stringBuilder.append(neighborElement.m_transport);
if (t.getText().toString().contains(stringBuilder.toString())) {
textView1 = t;
break;
}
}
if (textView1 == null) {
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
row = new TableRow(Settings.this);
row.setId(neighborElement.m_oid);
row.setLayoutParams(layoutParams);
spinner = new Spinner(Settings.this);
ArrayAdapter<String> arrayAdapter = null;
String[] array = null;
final String ipAndPort = neighborElement.m_remoteIpAddress + ":" + neighborElement.m_remotePort;
if (neighborElement.m_transport.equals("TCP"))
array = new String[] { "Action", "Connect", "Delete", "Disconnect", "Purge Queue", "Reset SSL/TLS Credentials" };
else
array = new String[] { "Action", "Connect", "Delete", "Disconnect", "Purge Queue" };
arrayAdapter = new ArrayAdapter<>(Settings.this, android.R.layout.simple_spinner_item, array);
spinner.setAdapter(arrayAdapter);
spinner.setId(neighborElement.m_oid);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (// Connect
position == 1)
m_databaseHelper.neighborControlStatus(s_cryptography, "connect", String.valueOf(parent.getId()));
else if (// Delete
position == 2)
deleteNeighbor(ipAndPort, parent.getId());
else if (// Disconnect
position == 3)
m_databaseHelper.neighborControlStatus(s_cryptography, "disconnect", String.valueOf(parent.getId()));
else if (// Purge Queue
position == 4)
m_databaseHelper.purgeNeighborQueue(String.valueOf(parent.getId()));
else if (// Reset SSL/TLS Credentials
position == 5) {
m_databaseHelper.neighborRecordCertificate(s_cryptography, String.valueOf(parent.getId()), null);
m_databaseHelper.neighborControlStatus(s_cryptography, "disconnect", String.valueOf(parent.getId()));
}
parent.setSelection(0);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
textView1 = new TextView(Settings.this);
}
switch(neighborElement.m_status) {
case "connected":
// Dark Green
textView1.setTextColor(Color.rgb(0, 100, 0));
break;
case "connecting":
// Dark Orange
textView1.setTextColor(Color.rgb(255, 140, 0));
break;
default:
// Dark Red
textView1.setTextColor(Color.rgb(139, 0, 0));
break;
}
stringBuilder.setLength(0);
stringBuilder.append("Control: ");
try {
stringBuilder.append(neighborElement.m_statusControl.substring(0, 1).toUpperCase());
stringBuilder.append(neighborElement.m_statusControl.substring(1));
} catch (Exception exception) {
stringBuilder.append("Disconnect");
}
stringBuilder.append("\n");
stringBuilder.append("Status: ");
try {
stringBuilder.append(neighborElement.m_status.substring(0, 1).toUpperCase());
stringBuilder.append(neighborElement.m_status.substring(1));
} catch (Exception exception) {
stringBuilder.append("Disconnected");
}
stringBuilder.append("\n");
if (!neighborElement.m_error.isEmpty()) {
stringBuilder.append("Error: ");
stringBuilder.append(neighborElement.m_error);
stringBuilder.append("\n");
}
stringBuilder.append(neighborElement.m_remoteIpAddress);
if (neighborElement.m_ipVersion.equals("IPv6"))
if (!neighborElement.m_remoteScopeId.isEmpty()) {
stringBuilder.append("-");
stringBuilder.append(neighborElement.m_remoteScopeId);
}
stringBuilder.append(":");
stringBuilder.append(neighborElement.m_remotePort);
stringBuilder.append(":");
stringBuilder.append(neighborElement.m_transport);
if (!neighborElement.m_localIpAddress.isEmpty() && !neighborElement.m_localPort.isEmpty()) {
stringBuilder.append("\n");
stringBuilder.append(neighborElement.m_localIpAddress);
stringBuilder.append(":");
stringBuilder.append(neighborElement.m_localPort);
}
stringBuilder.append("\nProxy: ");
if (!neighborElement.m_proxyIpAddress.isEmpty() && !neighborElement.m_proxyPort.isEmpty()) {
stringBuilder.append(neighborElement.m_proxyIpAddress);
stringBuilder.append(":");
stringBuilder.append(neighborElement.m_proxyPort);
stringBuilder.append(":");
stringBuilder.append(neighborElement.m_proxyType);
}
if (checkBox1.isChecked()) {
if (neighborElement.m_remoteCertificate != null && neighborElement.m_remoteCertificate.length > 0) {
stringBuilder.append("\n");
stringBuilder.append("Remote Certificate's Fingerprint: ");
stringBuilder.append(Cryptography.fingerPrint(neighborElement.m_remoteCertificate));
}
if (!neighborElement.m_sessionCipher.isEmpty()) {
stringBuilder.append("\n");
stringBuilder.append("Session Cipher: ");
stringBuilder.append(neighborElement.m_sessionCipher);
}
}
stringBuilder.append("\n");
stringBuilder.append("Temp. Queued: ");
stringBuilder.append(neighborElement.m_echoQueueSize);
stringBuilder.append(" / ");
stringBuilder.append(Neighbor.MAXIMUM_QUEUED_ECHO_PACKETS);
stringBuilder.append("\n");
stringBuilder.append("In: ");
stringBuilder.append(Miscellaneous.formattedDigitalInformation(neighborElement.m_bytesRead));
stringBuilder.append("\n");
stringBuilder.append("Out: ");
stringBuilder.append(Miscellaneous.formattedDigitalInformation(neighborElement.m_bytesWritten));
stringBuilder.append("\n");
stringBuilder.append("Outbound Queued: ");
stringBuilder.append(neighborElement.m_outboundQueued);
stringBuilder.append("\n");
stringBuilder.append("Uptime: ");
try {
long uptime = Long.parseLong(neighborElement.m_uptime);
stringBuilder.append(String.format("%d:%02d", TimeUnit.NANOSECONDS.toMinutes(uptime), TimeUnit.NANOSECONDS.toSeconds(uptime) - TimeUnit.MINUTES.toSeconds(TimeUnit.NANOSECONDS.toMinutes(uptime))));
} catch (Exception exception) {
stringBuilder.append("0:00");
}
stringBuilder.append(" Min.\n");
textView1.setGravity(Gravity.CENTER_VERTICAL);
textView1.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
textView1.setText(stringBuilder);
textView1.setTextSize(TEXTVIEW_TEXT_SIZE);
textView1.setWidth(TEXTVIEW_WIDTH);
if (row != null) {
row.addView(spinner);
row.addView(textView1);
tableLayout.addView(row, i);
}
i += 1;
}
arrayList.clear();
}
use of android.widget.TableRow in project android-diplicity by zond.
the class MemberTable method setMembers.
public void setMembers(final RetrofitActivity retrofitActivity, Game game, final List<Member> members) {
removeAllViews();
for (final Member member : members) {
boolean rowOK = true;
TableRow tableRow = new TableRow(retrofitActivity);
TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
tableRow.setLayoutParams(rowParams);
UserView userView = new UserView(retrofitActivity, attributeSet);
TableRow.LayoutParams userParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1.0f);
setMargins(userParams);
userView.setLayoutParams(userParams);
userView.setMember(retrofitActivity, game, member, member.User, this.phaseStates == null);
tableRow.addView(userView);
if (member.Nation != null && !member.Nation.equals("")) {
TextView nation = new TextView(retrofitActivity);
nation.setLayoutParams(wrapContentParams);
nation.setText(member.Nation);
tableRow.addView(nation);
}
if (this.scores != null) {
GameScore foundScore = null;
for (GameScore score : scores) {
if (score.UserId.equals(member.User.Id)) {
foundScore = score;
break;
}
}
if (foundScore != null) {
TextView scs = new TextView(retrofitActivity);
scs.setLayoutParams(wrapContentParams);
scs.setText(getResources().getString(R.string._scs, foundScore.SCs));
tableRow.addView(scs);
TextView points = new TextView(retrofitActivity);
points.setLayoutParams(wrapContentParams);
points.setText(getResources().getString(R.string._points, retrofitActivity.toString(foundScore.Score)));
tableRow.addView(points);
}
}
if (this.phaseStates != null) {
PhaseState foundState = null;
for (PhaseState state : phaseStates) {
if (state.Nation.equals(member.Nation)) {
foundState = state;
break;
}
}
if (foundState != null) {
final PhaseState finalFoundState = foundState;
final CheckBox onProbation = new CheckBox(retrofitActivity);
final CheckBox readyToResolve = new CheckBox(retrofitActivity);
readyToResolve.setText(R.string.rdy);
readyToResolve.setLayoutParams(wrapContentParams);
readyToResolve.setChecked(finalFoundState.ReadyToResolve);
if (!foundState.NoOrders && !phaseMeta.Resolved && retrofitActivity.getLoggedInUser().Id.equals(member.User.Id)) {
final Game finalGame = game;
readyToResolve.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
finalFoundState.ReadyToResolve = b;
retrofitActivity.handleReq(retrofitActivity.phaseStateService.PhaseStateUpdate(finalFoundState, MemberTable.this.game.ID, phaseMeta.PhaseOrdinal.toString(), member.Nation), new Sendable<SingleContainer<PhaseState>>() {
@Override
public void send(SingleContainer<PhaseState> phaseStateSingleContainer) {
if (readyToResolve.isChecked()) {
Alarm.Alert.fromGame(finalGame, member).turnOff(retrofitActivity);
}
onProbation.setChecked(false);
}
}, getResources().getString(R.string.updating_phase_state));
}
});
readyToResolve.setEnabled(true);
} else {
readyToResolve.setEnabled(false);
}
tableRow.addView(readyToResolve);
CheckBox wantsDIAS = new CheckBox(retrofitActivity);
wantsDIAS.setText(R.string.DRAW);
wantsDIAS.setLayoutParams(wrapContentParams);
wantsDIAS.setChecked(finalFoundState.WantsDIAS);
if (!foundState.Eliminated && !phaseMeta.Resolved && retrofitActivity.getLoggedInUser().Id.equals(member.User.Id)) {
wantsDIAS.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
finalFoundState.WantsDIAS = b;
retrofitActivity.handleReq(retrofitActivity.phaseStateService.PhaseStateUpdate(finalFoundState, MemberTable.this.game.ID, phaseMeta.PhaseOrdinal.toString(), member.Nation), new Sendable<SingleContainer<PhaseState>>() {
@Override
public void send(SingleContainer<PhaseState> phaseStateSingleContainer) {
onProbation.setChecked(false);
}
}, getResources().getString(R.string.updating_phase_state));
}
});
} else {
wantsDIAS.setEnabled(false);
}
tableRow.addView(wantsDIAS);
onProbation.setText(R.string.nmr);
onProbation.setLayoutParams(wrapContentParams);
onProbation.setChecked(finalFoundState.OnProbation);
onProbation.setEnabled(false);
tableRow.addView(onProbation);
} else {
rowOK = false;
}
}
if (rowOK) {
addView(tableRow);
}
}
}
use of android.widget.TableRow in project android-diplicity by zond.
the class ChannelTable method setChannels.
public void setChannels(final RetrofitActivity retrofitActivity, final Game game, final Member member, List<ChannelService.Channel> channels) {
removeAllViews();
for (final ChannelService.Channel channel : channels) {
TableRow tableRow = new TableRow(retrofitActivity);
TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
tableRow.setLayoutParams(rowParams);
TextView name = new TextView(retrofitActivity);
TableRow.LayoutParams nameParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
setMargins(nameParams);
name.setLayoutParams(nameParams);
name.setText(TextUtils.join(", ", channel.Members));
tableRow.addView(name);
TextView messages = new TextView(retrofitActivity);
messages.setLayoutParams(wrapContentParams);
messages.setText(getResources().getQuantityString(R.plurals.message, channel.NMessages, channel.NMessages));
tableRow.addView(messages);
if (member != null) {
TextView unread = new TextView(retrofitActivity);
unread.setLayoutParams(wrapContentParams);
unread.setText(getResources().getString(R.string._unread, channel.NMessagesSince.NMessages));
tableRow.addView(unread);
}
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FloatingActionButton button = (FloatingActionButton) inflater.inflate(R.layout.expand_button, null);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(retrofitActivity, PressActivity.class);
intent.putExtra(PressActivity.SERIALIZED_CHANNEL_KEY, RetrofitActivity.serialize(channel));
intent.putExtra(PressActivity.SERIALIZED_GAME_KEY, RetrofitActivity.serialize(game));
if (member != null) {
intent.putExtra(PressActivity.SERIALIZED_MEMBER_KEY, RetrofitActivity.serialize(member));
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
retrofitActivity.startActivity(intent);
}
});
button.setLayoutParams(wrapContentParams);
tableRow.addView(button);
addView(tableRow);
}
}
Aggregations