Grant that 'refresh' button embedded in the URL input field does not hide the text...
authorDavid A. Velasco <dvelasco@solidgear.es>
Tue, 14 May 2013 13:19:43 +0000 (15:19 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Tue, 14 May 2013 13:19:43 +0000 (15:19 +0200)
res/layout-land/account_setup.xml
res/layout/account_setup.xml
src/com/owncloud/android/authentication/AuthenticatorActivity.java

index 0427dfd..41fa06e 100644 (file)
                                android:orientation="vertical" \r
                                >\r
                \r
-                               <FrameLayout\r
+                               <EditText\r
+                                       android:id="@+id/hostUrlInput"\r
                                        android:layout_width="match_parent"\r
                                        android:layout_height="wrap_content"\r
-                               >\r
-               \r
-                                       <EditText\r
-                                               android:id="@+id/hostUrlInput"\r
-                                               android:layout_width="match_parent"\r
-                                               android:layout_height="wrap_content"\r
-                                               android:ems="10"\r
-                                               android:hint="@string/auth_host_url"\r
-                                               android:inputType="textUri"\r
-                                               >\r
-                                               <requestFocus />\r
-                                       </EditText>\r
-               \r
-                                       <ImageView\r
-                                               android:id="@+id/refreshButton"\r
-                                               android:layout_width="wrap_content"\r
-                                               android:layout_height="wrap_content"\r
-                                               android:layout_gravity="right|center_vertical"\r
-                                               android:src="@drawable/ic_action_refresh_black"\r
-                                               android:onClick="onRefreshClick"\r
-                                               android:visibility="invisible" />\r
-                                       \r
-                               </FrameLayout>\r
+                                       android:ems="10"\r
+                                       android:hint="@string/auth_host_url"\r
+                                       android:inputType="textUri"\r
+                                       android:drawablePadding="5dp"\r
+                                       >\r
+                                       <requestFocus />\r
+                               </EditText>\r
                \r
                                <TextView\r
                                        android:id="@+id/server_status_text"\r
index 2258304..65237a8 100644 (file)
             android:layout_marginTop="10dp"\r
             android:src="@drawable/logo" />\r
 \r
-        <FrameLayout\r
-            android:layout_width="match_parent"\r
-            android:layout_height="wrap_content" >\r
-\r
-            <EditText\r
-                android:id="@+id/hostUrlInput"\r
-                android:layout_width="match_parent"\r
-                android:layout_height="wrap_content"\r
-                android:ems="10"\r
-                android:hint="@string/auth_host_url"\r
-                android:inputType="textUri" >\r
-\r
-                <requestFocus />\r
-            </EditText>\r
-\r
-            <ImageView\r
-                android:id="@+id/refreshButton"\r
-                android:layout_width="wrap_content"\r
-                android:layout_height="wrap_content"\r
-                android:layout_gravity="right|center_vertical"\r
-                android:src="@drawable/ic_action_refresh_black"\r
-               android:onClick="onRefreshClick"\r
-                android:visibility="invisible" />\r
-        </FrameLayout>\r
+               <EditText\r
+                       android:id="@+id/hostUrlInput"\r
+                       android:layout_width="match_parent"\r
+                       android:layout_height="wrap_content"\r
+                       android:ems="10"\r
+                       android:hint="@string/auth_host_url"\r
+                       android:inputType="textUri"\r
+                       android:drawablePadding="5dp"\r
+                       >\r
+                       <requestFocus />\r
+               </EditText>\r
 \r
         <TextView\r
             android:id="@+id/server_status_text"\r
index ca2c1a8..141cd54 100644 (file)
@@ -42,14 +42,18 @@ import android.content.ContentResolver;
 import android.content.DialogInterface;\r
 import android.content.Intent;\r
 import android.content.SharedPreferences;\r
+import android.graphics.Rect;\r
+import android.graphics.drawable.Drawable;\r
 import android.net.Uri;\r
 import android.os.Bundle;\r
 import android.os.Handler;\r
 import android.preference.PreferenceManager;\r
 import android.text.InputType;\r
 import android.view.KeyEvent;\r
+import android.view.MotionEvent;\r
 import android.view.View;\r
 import android.view.View.OnFocusChangeListener;\r
+import android.view.View.OnTouchListener;\r
 import android.view.Window;\r
 import android.view.inputmethod.EditorInfo;\r
 import android.widget.CheckBox;\r
@@ -123,7 +127,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     private byte mAction;\r
     private Account mAccount;\r
     \r
-    private ImageView mRefreshButton;\r
     private ImageView mViewPasswordButton;\r
     private EditText mHostUrlInput;\r
     private EditText mUsernameInput;\r
@@ -149,7 +152,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         \r
         /// set view and get references to view elements\r
         setContentView(R.layout.account_setup);\r
-        mRefreshButton = (ImageView) findViewById(R.id.refreshButton);\r
         mViewPasswordButton = (ImageView) findViewById(R.id.viewPasswordButton);\r
         mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput);\r
         mUsernameInput = (EditText) findViewById(R.id.account_username);\r
@@ -168,6 +170,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 \r
         /// bind view elements to listeners\r
         mHostUrlInput.setOnFocusChangeListener(this);\r
+        mHostUrlInput.setOnTouchListener(new RightDrawableOnTouchListener() {\r
+            @Override\r
+            public boolean onDrawableTouch(final MotionEvent event) {\r
+                AuthenticatorActivity.this.onRefreshClick(mHostUrlInput);\r
+                return true;\r
+            }\r
+        });\r
         mPasswordInput.setOnFocusChangeListener(this);\r
         mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE);\r
         mPasswordInput.setOnEditorActionListener(this);\r
@@ -278,10 +287,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         \r
         /// UI settings depending upon connection\r
         mOkButton.setEnabled(mStatusCorrect);  \r
-        if (!mStatusCorrect)\r
-            mRefreshButton.setVisibility(View.VISIBLE); // seems that setting visibility is necessary\r
-        else\r
-            mRefreshButton.setVisibility(View.INVISIBLE);\r
+        if (!mStatusCorrect) {\r
+            mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0);\r
+        } else {\r
+            mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
+        }\r
         \r
         /// server data\r
         String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);\r
@@ -416,7 +426,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             mDiscoveredVersion = null;\r
             mOperationThread = mOcServerChkOperation.execute(client, this, mHandler);\r
         } else {\r
-            mRefreshButton.setVisibility(View.INVISIBLE);\r
+            mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
             mStatusText = 0;\r
             mStatusIcon = 0;\r
             updateConnStatus();\r
@@ -589,10 +599,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         }\r
         \r
         /// update the visibility of the 'retry connection' button\r
-        if (!mStatusCorrect)\r
-            mRefreshButton.setVisibility(View.VISIBLE);\r
-        else\r
-            mRefreshButton.setVisibility(View.INVISIBLE);\r
+        if (!mStatusCorrect) {\r
+            mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0);\r
+        } else {\r
+            mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
+        }\r
         \r
         /// retrieve discovered version and normalize server URL\r
         mDiscoveredVersion = operation.getDiscoveredVersion();\r
@@ -1103,4 +1114,39 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         return false;   // always return false to grant that the software keyboard is hidden anyway\r
     }\r
 \r
+    \r
+    private abstract static class RightDrawableOnTouchListener implements OnTouchListener  {\r
+\r
+        private int fuzz = 10;\r
+        \r
+        /**\r
+         * {@inheritDoc}\r
+         */\r
+        @Override\r
+        public boolean onTouch(View view, MotionEvent event) {\r
+            if (event.getAction() == MotionEvent.ACTION_DOWN) {\r
+                Drawable rightDrawable = null;\r
+                if (view instanceof TextView) {\r
+                    Drawable[] drawables = ((TextView)view).getCompoundDrawables();\r
+                    if (drawables.length > 2) {\r
+                        rightDrawable = drawables[2];\r
+                    }\r
+                }\r
+                if (rightDrawable != null) {\r
+                    final int x = (int) event.getX();\r
+                    final int y = (int) event.getY();\r
+                    final Rect bounds = rightDrawable.getBounds();\r
+                    if (x >= (view.getRight() - bounds.width() - fuzz) && x <= (view.getRight() - view.getPaddingRight() + fuzz)\r
+                        && y >= (view.getPaddingTop() - fuzz) && y <= (view.getHeight() - view.getPaddingBottom()) + fuzz) {\r
+                        \r
+                        return onDrawableTouch(event);\r
+                    }\r
+                }\r
+            }\r
+            return false;\r
+        }\r
+        \r
+        public abstract boolean onDrawableTouch(final MotionEvent event);\r
+    }\r
+    \r
 }\r