Files
podlite/src/com/miniabs/LoginActivity.java
T
xockoandClaude Opus 5.5 275bee3c11 MiniABS 1.2: Galician interface, larger text and touch targets
- Translate the interface to Galician (tools/translate_gl.py), including
  Galician month abbreviations for dates, which Android 2.3 lacks
- Resize for the Galaxy Mini's 240x320 screen: larger text, rows, tabs and
  buttons; all sizes now live in res/values/dimens.xml
- Redraw play/pause/refresh icons for every density; slightly brighter
  secondary text colours

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 21:29:17 +02:00

122 lines
4.5 KiB
Java

package com.miniabs;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
public class LoginActivity extends Activity {
private EditText server, user, pass;
private CheckBox useKey;
private TextView status, userLabel, passLabel;
private Button connect;
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_login);
server = (EditText) findViewById(R.id.server);
user = (EditText) findViewById(R.id.user);
pass = (EditText) findViewById(R.id.pass);
useKey = (CheckBox) findViewById(R.id.use_key);
status = (TextView) findViewById(R.id.status);
userLabel = (TextView) findViewById(R.id.user_label);
passLabel = (TextView) findViewById(R.id.pass_label);
connect = (Button) findViewById(R.id.connect);
Prefs p = Prefs.get(this);
server.setText(p.server());
user.setText(p.username());
String msg = getIntent().getStringExtra("message");
if (msg != null) status.setText(msg);
useKey.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton v, boolean on) {
int vis = on ? View.GONE : View.VISIBLE;
user.setVisibility(vis);
userLabel.setVisibility(vis);
passLabel.setText(on ? "Chave da API" : "Contrasinal");
pass.setInputType(on ? InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
: InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
pass.setText("");
}
});
connect.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
go();
}
});
}
static String normalize(String s) {
s = s.trim();
while (s.endsWith("/")) s = s.substring(0, s.length() - 1);
if (s.endsWith("/login")) s = s.substring(0, s.length() - 6);
if (s.length() > 0 && !s.startsWith("http://") && !s.startsWith("https://")) s = "http://" + s;
return s;
}
private void go() {
final String srv = normalize(server.getText().toString());
final String u = user.getText().toString().trim();
final String pw = pass.getText().toString();
final boolean key = useKey.isChecked();
if (srv.length() == 0) {
status.setText("Escribe o enderezo do servidor.");
return;
}
if (key ? pw.trim().length() == 0 : u.length() == 0) {
status.setText(key ? "Pega a túa chave da API." : "Escribe o teu usuario.");
return;
}
server.setText(srv);
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(pass.getWindowToken(), 0);
connect.setEnabled(false);
status.setText("Conectando…");
final Prefs p = Prefs.get(this);
p.logout();
App.clear();
HomeActivity.clearCache();
p.setServer(srv);
Trust.lastRejected = null;
new Job<String>() {
String work() throws Exception {
String version = Api.status(LoginActivity.this, srv);
String lib;
if (key) {
Api.loginWithKey(LoginActivity.this, pw.trim());
lib = "";
} else {
lib = Api.login(LoginActivity.this, srv, u, pw);
}
if (lib.length() > 0) p.setLibrary(lib, "");
return version;
}
void done(String version) {
startActivity(new Intent(LoginActivity.this, HomeActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
finish();
}
void failed(Exception e) {
connect.setEnabled(true);
status.setText(Util.describe(e));
TrustPrompt.offer(LoginActivity.this, new Runnable() {
public void run() {
go();
}
});
}
}.start();
}
}