Browse Source

Partly works

Mario Danic 8 years ago
parent
commit
bd16eb7146

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

@@ -0,0 +1,92 @@
+/**
+ * Nextcloud Android client application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017 Mario Danic
+ * <p>
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ * <p>
+ * 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.
+ * <p>
+ * 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 mFixedRect = 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);
+        }
+
+    }
+
+    public String getFullServerUrl() {
+        if (TextUtils.isEmpty(fixedText)) {
+            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(), mFixedRect);
+
+            if (isPrefixFixed) {
+                mFixedRect.right += getPaint().measureText(fixedText);
+            } else {
+                mFixedRect.right += getPaint().measureText(fixedText);
+            }
+        }
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+    }
+
+    @Override
+    protected void onDraw(Canvas canvas) {
+        super.onDraw(canvas);
+        if (!TextUtils.isEmpty(fixedText)) {
+            if (isPrefixFixed) {
+                canvas.drawText(fixedText, super.getCompoundPaddingLeft() + getPaint().measureText(fixedText),
+                        getBaseline(), getPaint());
+            } else {
+                canvas.drawText(fixedText, super.getCompoundPaddingLeft() + getPaint().measureText(getText().toString()),
+                        getBaseline(), getPaint());
+            }
+        }
+    }
+}

+ 20 - 2
src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -43,7 +43,9 @@ import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
 import android.text.Editable;
+import android.text.InputFilter;
 import android.text.InputType;
+import android.text.Spanned;
 import android.text.TextWatcher;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
@@ -85,6 +87,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;
@@ -97,6 +100,8 @@ import java.util.Map;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 
+import static android.provider.ContactsContract.CommonDataKinds.StructuredName.PREFIX;
+
 /**
  * This Activity is used to add an ownCloud account to the App
  */
@@ -149,6 +154,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     private static final String HTTPS_PROTOCOL = "https://";
     private 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;
     private Account mAccount;
@@ -164,7 +173,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
 
     /// Server PRE-Fragment elements 
-    private EditText mHostUrlInput;
+    private CustomEditText mHostUrlInput;
     private View mRefreshButton;
     private TextView mServerStatusView;
 
@@ -438,7 +447,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 +455,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 (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);

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

@@ -90,8 +90,7 @@
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content">
 
-                        <EditText
-                            android:id="@+id/hostUrlInput"
+						<com.owncloud.android.ui.components.CustomEditText
                             android:layout_width="match_parent"
                             android:layout_height="wrap_content"
                             android:layout_gravity="bottom"
@@ -105,7 +104,7 @@
                             >
 
                             <requestFocus/>
-                        </EditText>
+                        </com.owncloud.android.ui.components.CustomEditText>
 
                     </android.support.design.widget.TextInputLayout>
 

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

@@ -83,7 +83,7 @@
                 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"
@@ -97,7 +97,7 @@
                     android:textColorHint="@color/login_text_color">
 
                     <requestFocus/>
-                </EditText>
+                </com.owncloud.android.ui.components.CustomEditText>
 
             </android.support.design.widget.TextInputLayout>
 

+ 4 - 1
src/main/res/values/setup.xml

@@ -19,8 +19,11 @@
     <string name ="user_agent">Mozilla/5.0 (Android) ownCloud-android/%1$s</string>
     
     <!-- URLs and flags related -->
-    <string name="server_url"></string>
+    <string name="server_url">nextcloud.com</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">prefix</string>
     <bool name="show_welcome_link">true</bool>
 	<string name="welcome_link_url">"https://nextcloud.com/providers"</string>
 	<string name="share_api_link"></string>