From 1a073ca45455dcf46bb4d8bcaa962030a65c435a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 19 Apr 2016 18:03:24 +0200 Subject: added magic create welcome screen --- art/render.rb | 1 + src/main/AndroidManifest.xml | 16 ++- src/main/java/eu/siacs/conversations/Config.java | 1 + .../services/XmppConnectionService.java | 12 +++ .../conversations/ui/ConversationActivity.java | 13 ++- .../conversations/ui/EditAccountActivity.java | 4 +- .../conversations/ui/MagicCreateActivity.java | 113 +++++++++++++++++++++ .../eu/siacs/conversations/ui/WelcomeActivity.java | 37 +++++++ src/main/res/drawable-hdpi/main_logo.png | Bin 0 -> 23970 bytes src/main/res/drawable-mdpi/main_logo.png | Bin 0 -> 15297 bytes src/main/res/drawable-xhdpi/main_logo.png | Bin 0 -> 33485 bytes src/main/res/drawable-xxhdpi/main_logo.png | Bin 0 -> 52847 bytes src/main/res/drawable-xxxhdpi/main_logo.png | Bin 0 -> 74122 bytes src/main/res/layout/magic_create.xml | 83 +++++++++++++++ src/main/res/layout/welcome.xml | 69 +++++++++++++ src/main/res/values/strings.xml | 7 ++ 16 files changed, 349 insertions(+), 7 deletions(-) create mode 100644 src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java create mode 100644 src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java create mode 100644 src/main/res/drawable-hdpi/main_logo.png create mode 100644 src/main/res/drawable-mdpi/main_logo.png create mode 100644 src/main/res/drawable-xhdpi/main_logo.png create mode 100644 src/main/res/drawable-xxhdpi/main_logo.png create mode 100644 src/main/res/drawable-xxxhdpi/main_logo.png create mode 100644 src/main/res/layout/magic_create.xml create mode 100644 src/main/res/layout/welcome.xml diff --git a/art/render.rb b/art/render.rb index b4f84769..06100c5a 100755 --- a/art/render.rb +++ b/art/render.rb @@ -12,6 +12,7 @@ resolutions = { images = { 'conversations_baloon.svg' => ['ic_launcher', 48], + 'conversations_baloon.svg' => ['main_logo', 200], 'conversations_mono.svg' => ['ic_notification', 24], 'ic_received_indicator.svg' => ['ic_received_indicator', 12], 'ic_send_text_offline.svg' => ['ic_send_text_offline', 36], diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index dda0fbe9..83f1c517 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -77,6 +77,16 @@ + + @@ -139,7 +149,7 @@ + android:value=".services.ContactChooserTargetService"/> - + - + diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index bfbf9a7f..2b12474c 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -38,6 +38,7 @@ public final class Config { public static final String DOMAIN_LOCK = null; //only allow account creation for this domain + public static final String MAGIC_CREATE_DOMAIN = null; public static final String CONFERENCE_DOMAIN_LOCK = null; //only allow conference creation for this domain public static final boolean LOCK_DOMAINS_IN_CONVERSATIONS = false; //only add contacts and conferences for own domains diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index dbfb818d..5040664a 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -3217,6 +3217,18 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa return mPushManagementService; } + public Account getPendingAccount() { + Account pending = null; + for(Account account : getAccounts()) { + if (account.isOptionSet(Account.OPTION_REGISTER)) { + pending = account; + } else { + return null; + } + } + return pending; + } + public interface OnMamPreferencesFetched { void onPreferencesFetched(Element prefs); void onPreferencesFetchFailed(); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 920c07af..dbd3139f 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -1125,6 +1125,8 @@ public class ConversationActivity extends XmppActivity if (mRedirected.compareAndSet(false, true)) { if (Config.X509_VERIFICATION) { startActivity(new Intent(this, ManageAccountActivity.class)); + } else if (Config.MAGIC_CREATE_DOMAIN != null) { + startActivity(new Intent(this, WelcomeActivity.class)); } else { startActivity(new Intent(this, EditAccountActivity.class)); } @@ -1132,9 +1134,14 @@ public class ConversationActivity extends XmppActivity } } else if (conversationList.size() <= 0) { if (mRedirected.compareAndSet(false, true)) { - Intent intent = new Intent(this, StartConversationActivity.class); - intent.putExtra("init", true); - startActivity(intent); + Account pendingAccount = xmppConnectionService.getPendingAccount(); + if (pendingAccount == null) { + Intent intent = new Intent(this, StartConversationActivity.class); + intent.putExtra("init", true); + startActivity(intent); + } else { + switchToAccount(pendingAccount, true); + } finish(); } } else if (getIntent() != null && VIEW_CONVERSATION.equals(getIntent().getType())) { diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 48ccb9f0..b2c7f1a9 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -546,7 +546,9 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } updateAccountInformation(true); } - } else if (this.xmppConnectionService.getAccounts().size() == 0) { + } + if (this.xmppConnectionService.getAccounts().size() == 0 + || this.mAccount == xmppConnectionService.getPendingAccount()) { if (getActionBar() != null) { getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setDisplayShowHomeEnabled(false); diff --git a/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java b/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java new file mode 100644 index 00000000..6b32bdc2 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java @@ -0,0 +1,113 @@ +package eu.siacs.conversations.ui; + +import android.content.Intent; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +import java.security.SecureRandom; + +import eu.siacs.conversations.Config; +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.xmpp.jid.InvalidJidException; +import eu.siacs.conversations.xmpp.jid.Jid; + +public class MagicCreateActivity extends XmppActivity implements TextWatcher { + + private TextView mFullJidDisplay; + private EditText mUsername; + private SecureRandom mRandom; + + private static final String CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456780+-/#$!?"; + private static final int PW_LENGTH = 10; + + @Override + protected void refreshUiReal() { + + } + + @Override + void onBackendConnected() { + + } + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.magic_create); + mFullJidDisplay = (TextView) findViewById(R.id.full_jid); + mUsername = (EditText) findViewById(R.id.username); + mRandom = new SecureRandom(); + Button next = (Button) findViewById(R.id.create_account); + next.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String username = mUsername.getText().toString(); + if (username.contains("@") || username.length() < 3) { + mUsername.setError(getString(R.string.invalid_username)); + mUsername.requestFocus(); + } else { + mUsername.setError(null); + try { + Jid jid = Jid.fromParts(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); + Account account = xmppConnectionService.findAccountByJid(jid); + if (account == null) { + account = new Account(jid, createPassword()); + account.setOption(Account.OPTION_REGISTER, true); + account.setOption(Account.OPTION_DISABLED, true); + xmppConnectionService.createAccount(account); + } + Intent intent = new Intent(MagicCreateActivity.this, EditAccountActivity.class); + intent.putExtra("jid", account.getJid().toBareJid().toString()); + intent.putExtra("init", true); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(intent); + } catch (InvalidJidException e) { + mUsername.setError(getString(R.string.invalid_username)); + mUsername.requestFocus(); + } + } + } + }); + mUsername.addTextChangedListener(this); + } + + private String createPassword() { + StringBuilder builder = new StringBuilder(PW_LENGTH); + for(int i = 0; i < PW_LENGTH; ++i) { + builder.append(CHARS.charAt(mRandom.nextInt(CHARS.length() - 1))); + } + return builder.toString(); + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + if (s.toString().trim().length() > 0) { + try { + mFullJidDisplay.setVisibility(View.VISIBLE); + Jid jid = Jid.fromParts(s.toString().toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); + mFullJidDisplay.setText(getString(R.string.your_full_jid_will_be, jid.toString())); + } catch (InvalidJidException e) { + mFullJidDisplay.setVisibility(View.INVISIBLE); + } + + } else { + mFullJidDisplay.setVisibility(View.INVISIBLE); + } + } +} diff --git a/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java b/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java new file mode 100644 index 00000000..5818ffd5 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java @@ -0,0 +1,37 @@ +package eu.siacs.conversations.ui; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; + +import eu.siacs.conversations.R; + +public class WelcomeActivity extends Activity { + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.welcome); + final Button createAccount = (Button) findViewById(R.id.create_account); + createAccount.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(WelcomeActivity.this, MagicCreateActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + startActivity(intent); + } + }); + final Button useOwnProvider = (Button) findViewById(R.id.use_own_provider); + useOwnProvider.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(new Intent(WelcomeActivity.this, EditAccountActivity.class)); + finish(); + } + }); + + } + +} diff --git a/src/main/res/drawable-hdpi/main_logo.png b/src/main/res/drawable-hdpi/main_logo.png new file mode 100644 index 00000000..e3d6b5ed Binary files /dev/null and b/src/main/res/drawable-hdpi/main_logo.png differ diff --git a/src/main/res/drawable-mdpi/main_logo.png b/src/main/res/drawable-mdpi/main_logo.png new file mode 100644 index 00000000..efeb80fa Binary files /dev/null and b/src/main/res/drawable-mdpi/main_logo.png differ diff --git a/src/main/res/drawable-xhdpi/main_logo.png b/src/main/res/drawable-xhdpi/main_logo.png new file mode 100644 index 00000000..da7dc86f Binary files /dev/null and b/src/main/res/drawable-xhdpi/main_logo.png differ diff --git a/src/main/res/drawable-xxhdpi/main_logo.png b/src/main/res/drawable-xxhdpi/main_logo.png new file mode 100644 index 00000000..3a3fc6ee Binary files /dev/null and b/src/main/res/drawable-xxhdpi/main_logo.png differ diff --git a/src/main/res/drawable-xxxhdpi/main_logo.png b/src/main/res/drawable-xxxhdpi/main_logo.png new file mode 100644 index 00000000..51054090 Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/main_logo.png differ diff --git a/src/main/res/layout/magic_create.xml b/src/main/res/layout/magic_create.xml new file mode 100644 index 00000000..c4adc029 --- /dev/null +++ b/src/main/res/layout/magic_create.xml @@ -0,0 +1,83 @@ + + + + + + + + + + +