فهرست منبع

Merge pull request #753 from nextcloud/login-branding

Login branding
Andy Scherzinger 8 سال پیش
والد
کامیت
7a899b0737

+ 21 - 7
src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -85,6 +85,7 @@ import com.owncloud.android.operations.GetServerInfoOperation;
 import com.owncloud.android.operations.OAuth2GetAccessToken;
 import com.owncloud.android.services.OperationsService;
 import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
+import com.owncloud.android.ui.components.CustomEditText;
 import com.owncloud.android.ui.dialog.CredentialsDialogFragment;
 import com.owncloud.android.ui.dialog.IndeterminateProgressDialog;
 import com.owncloud.android.ui.dialog.SamlWebViewDialog;
@@ -146,8 +147,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     private static final String KEY_ASYNC_TASK_IN_PROGRESS = "AUTH_IN_PROGRESS";
     public static final String PROTOCOL_SUFFIX = "://";
     public static final String LOGIN_URL_DATA_KEY_VALUE_SEPARATOR = ":";
-    private static final String HTTPS_PROTOCOL = "https://";
-    private static final String HTTP_PROTOCOL = "http://";
+    public static final String HTTPS_PROTOCOL = "https://";
+    public static final String HTTP_PROTOCOL = "http://";
+
+    public static final String REGULAR_SERVER_INPUT_TYPE = "regular";
+    public static final String SUBDOMAIN_SERVER_INPUT_TYPE = "prefix";
+    public static final String DIRECTORY_SERVER_INPUT_TYPE = "suffix";
 
     /// parameters from EXTRAs in starter Intent
     private byte mAction;
@@ -164,7 +169,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
 
     /// Server PRE-Fragment elements 
-    private EditText mHostUrlInput;
+    private CustomEditText mHostUrlInput;
     private View mRefreshButton;
     private TextView mServerStatusView;
 
@@ -438,7 +443,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         }
 
         /// step 2 - set properties of UI elements (text, visibility, enabled...)
-        mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput);
+        mHostUrlInput = (CustomEditText) findViewById(R.id.hostUrlInput);
         // Convert IDN to Unicode
         mHostUrlInput.setText(DisplayUtils.convertIdn(mServerInfo.mBaseUrl, false));
         if (mAction != ACTION_CREATE) {
@@ -446,12 +451,21 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             mHostUrlInput.setEnabled(false);
             mHostUrlInput.setFocusable(false);
         }
+
+        String serverInputType = getResources().getString(R.string.server_input_type);
+
         if (isUrlInputAllowed) {
             mRefreshButton = findViewById(R.id.embeddedRefreshButton);
+            if (mAction == ACTION_CREATE &&
+                    (serverInputType.equals(DIRECTORY_SERVER_INPUT_TYPE) ||
+                    serverInputType.equals(SUBDOMAIN_SERVER_INPUT_TYPE))) {
+                mHostUrlInput.setText("");
+            }
         } else {
             findViewById(R.id.hostUrlFrame).setVisibility(View.GONE);
             mRefreshButton = findViewById(R.id.centeredRefreshButton);
         }
+
         showRefreshButton(mServerIsChecked && !mServerIsValid &&
                 mWaitingForOpId > Integer.MAX_VALUE);
         mServerStatusView = (TextView) findViewById(R.id.server_status_text);
@@ -468,7 +482,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             public void afterTextChanged(Editable s) {
                 if (mOkButton.isEnabled() &&
                         !mServerInfo.mBaseUrl.equals(
-                                normalizeUrl(s.toString(), mServerInfo.mIsSslConn))) {
+                                normalizeUrl(mHostUrlInput.getFullServerUrl(), mServerInfo.mIsSslConn))) {
                     mOkButton.setEnabled(false);
                 }
             }
@@ -849,7 +863,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
 
     private void checkOcServer() {
-        String uri = mHostUrlInput.getText().toString().trim();
+        String uri = mHostUrlInput.getFullServerUrl().trim();
         mServerIsValid = false;
         mServerIsChecked = false;
         mOkButton.setEnabled(false);
@@ -1781,7 +1795,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 inputField.equals(mHostUrlInput) &&
                 AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).
                         equals(mAuthTokenType)) {
-                checkOcServer();
+            checkOcServer();
         }
         return false;   // always return false to grant that the software keyboard is hidden anyway
     }

+ 104 - 0
src/main/java/com/owncloud/android/ui/components/CustomEditText.java

@@ -0,0 +1,104 @@
+/**
+ * Nextcloud Android client application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017 Mario Danic
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.owncloud.android.ui.components;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Rect;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+
+import com.owncloud.android.R;
+import com.owncloud.android.authentication.AuthenticatorActivity;
+
+/**
+ * Custom edit text to support fixed suffix or prefix
+ */
+public class CustomEditText extends android.support.v7.widget.AppCompatEditText {
+    private Rect fixedRect = new Rect();
+    private String fixedText = "";
+    private boolean isPrefixFixed;
+
+    public CustomEditText(Context context, AttributeSet attrs) {
+        super(context, attrs);
+
+        String serverInputType = getResources().getString(R.string.server_input_type);
+
+        if (serverInputType.equals(AuthenticatorActivity.DIRECTORY_SERVER_INPUT_TYPE)) {
+            isPrefixFixed = true;
+            fixedText = getResources().getString(R.string.server_url) + "/";
+        } else if (serverInputType.equals(AuthenticatorActivity.SUBDOMAIN_SERVER_INPUT_TYPE)) {
+            isPrefixFixed = false;
+            fixedText = "." + getResources().getString(R.string.server_url);
+        }
+
+        if (TextUtils.isEmpty(fixedText)) {
+            setHint(R.string.auth_host_url);
+        }
+    }
+
+    public String getFullServerUrl() {
+        if (TextUtils.isEmpty(fixedText)
+                || getText().toString().startsWith(AuthenticatorActivity.HTTP_PROTOCOL)
+                || getText().toString().startsWith(AuthenticatorActivity.HTTPS_PROTOCOL)) {
+            return getText().toString();
+        } else if (isPrefixFixed) {
+            return (getResources().getString(R.string.server_url) + "/" + getText().toString());
+        } else {
+            return (getText().toString() + "." + getResources().getString(R.string.server_url));
+        }
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        if (!TextUtils.isEmpty(fixedText)) {
+            getPaint().getTextBounds(fixedText, 0, fixedText.length(), fixedRect);
+        }
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+    }
+
+    @Override
+    protected void onDraw(Canvas canvas) {
+        super.onDraw(canvas);
+        if (!getText().toString().startsWith(AuthenticatorActivity.HTTP_PROTOCOL)
+                && !getText().toString().startsWith(AuthenticatorActivity.HTTPS_PROTOCOL)
+                && !TextUtils.isEmpty(fixedText)) {
+            if (isPrefixFixed) {
+                canvas.drawText(fixedText,
+                        super.getCompoundPaddingLeft(),
+                        getBaseline(),
+                        getPaint());
+            } else {
+                canvas.drawText(fixedText, super.getCompoundPaddingLeft()
+                        + getPaint().measureText(getText().toString()), getBaseline(), getPaint());
+            }
+        }
+    }
+
+    @Override
+    public int getCompoundPaddingLeft() {
+        if (!TextUtils.isEmpty(fixedText) && isPrefixFixed) {
+            return super.getCompoundPaddingLeft() + fixedRect.width();
+        } else {
+            return super.getCompoundPaddingLeft();
+        }
+    }
+}

+ 2 - 3
src/main/res/layout-land/account_setup.xml

@@ -90,14 +90,13 @@
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content">
 
-                        <EditText
+                        <com.owncloud.android.ui.components.CustomEditText
                             android:id="@+id/hostUrlInput"
                             android:layout_width="match_parent"
                             android:layout_height="wrap_content"
                             android:layout_gravity="bottom"
                             android:contentDescription="@string/auth_host_address"
                             android:drawablePadding="@dimen/alternate_half_padding"
-                            android:hint="@string/auth_host_url"
                             android:inputType="textUri"
                             android:paddingRight="@dimen/alternate_padding_right"
                             android:textColor="@color/login_text_color"
@@ -105,7 +104,7 @@
                             >
 
                             <requestFocus/>
-                        </EditText>
+                        </com.owncloud.android.ui.components.CustomEditText>
 
                     </android.support.design.widget.TextInputLayout>
 

+ 2 - 3
src/main/res/layout/account_setup.xml

@@ -83,21 +83,20 @@
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content">
 
-                <EditText
+                <com.owncloud.android.ui.components.CustomEditText
                     android:id="@+id/hostUrlInput"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_gravity="bottom"
                     android:contentDescription="@string/auth_host_address"
                     android:drawablePadding="@dimen/alternate_half_padding"
-                    android:hint="@string/auth_host_url"
                     android:inputType="textUri"
                     android:paddingRight="@dimen/alternate_padding_right"
                     android:textColor="@color/login_text_color"
                     android:textColorHint="@color/login_text_color">
 
                     <requestFocus/>
-                </EditText>
+                </com.owncloud.android.ui.components.CustomEditText>
 
             </android.support.design.widget.TextInputLayout>
 

+ 3 - 0
src/main/res/values/setup.xml

@@ -21,6 +21,9 @@
     <!-- URLs and flags related -->
     <string name="server_url"></string>
     <bool name="show_server_url_input">true</bool>
+    <!-- Can be regular (full input), prefix (subdomain input) and suffix (directory input) -->
+    <!-- Requires server url to be set -->
+    <string name="server_input_type">regular</string>
     <bool name="show_welcome_link">true</bool>
 	<string name="welcome_link_url">"https://nextcloud.com/providers"</string>
 	<string name="share_api_link"></string>