Merge branch 'develop' into login_toggle_password_icon
authorDavid A. Velasco <dvelasco@solidgear.es>
Fri, 24 May 2013 08:36:21 +0000 (10:36 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Fri, 24 May 2013 08:36:21 +0000 (10:36 +0200)
1  2 
res/layout-land/account_setup.xml
res/layout/account_setup.xml
src/com/owncloud/android/authentication/AuthenticatorActivity.java

                            android:id="@+id/LinearLayout1"\r
                            android:layout_width="match_parent"\r
                            android:layout_height="wrap_content"\r
-                           android:layout_margin="8dp"\r
                            android:focusable="true"\r
                            android:gravity="center"\r
-                           android:orientation="vertical" >\r
+                           android:orientation="vertical"\r
+                           android:padding="8dp" >\r
                \r
                                <EditText\r
                                        android:id="@+id/hostUrlInput"\r
                                        android:hint="@string/auth_username"\r
                                        android:inputType="textNoSuggestions" />\r
                \r
 -                              <FrameLayout\r
 +                              <EditText\r
 +                                  android:id="@+id/account_password"\r
                                        android:layout_width="match_parent"\r
                                        android:layout_height="wrap_content"\r
 -                                      >\r
 -                                      <EditText\r
 -                                              android:id="@+id/account_password"\r
 -                                              android:layout_width="match_parent"\r
 -                                              android:layout_height="wrap_content"\r
 -                                              android:ems="10"\r
 -                                              android:hint="@string/auth_password"\r
 -                                              android:inputType="textPassword"/>\r
 -                                      \r
 -                                      <ImageView\r
 -                                              android:id="@+id/viewPasswordButton"\r
 -                                              android:layout_width="wrap_content"\r
 -                                              android:layout_height="wrap_content"\r
 -                                              android:layout_gravity="right|center_vertical"\r
 -                                              android:src="@android:drawable/ic_menu_view"\r
 -                                              android:onClick="onViewPasswordClick"\r
 -                                              android:visibility="invisible" />\r
 -                              </FrameLayout>\r
 -                   \r
 +                                      android:ems="10"\r
 +                                      android:hint="@string/auth_password"\r
 +                                      android:inputType="textPassword"\r
 +                                      android:drawablePadding="5dp"\r
 +                                      />\r
 +                      \r
                                <TextView\r
                                        android:id="@+id/auth_status_text"\r
                                        android:layout_width="match_parent"\r
    You should have received a copy of the GNU General Public License\r
    along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
  -->\r
\r
  <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"\r
      android:layout_width="match_parent"\r
      android:layout_height="match_parent"\r
      android:layout_gravity="center"\r
-       android:padding="8dip"\r
      android:fillViewport="true"\r
-     android:orientation="vertical"\r
-     >\r
+     android:orientation="vertical" >\r
  \r
      <LinearLayout\r
          android:layout_width="match_parent"\r
          android:layout_height="wrap_content"\r
-               android:layout_margin="8dip"\r
-         android:gravity="center"\r
-         android:orientation="vertical" \r
          android:focusable="true"\r
-         >\r
+         android:gravity="center"\r
+         android:orientation="vertical"\r
+         android:padding="8dp" >\r
  \r
          <ImageView\r
              android:id="@+id/imageView1"\r
              android:hint="@string/auth_username"\r
              android:inputType="textNoSuggestions" />\r
  \r
 -        <FrameLayout\r
 -            android:layout_width="match_parent"\r
 -            android:layout_height="wrap_content" >\r
 -\r
 -            <EditText\r
 -                android:id="@+id/account_password"\r
 -                android:layout_width="match_parent"\r
 -                android:layout_height="wrap_content"\r
 -                android:ems="10"\r
 -                android:hint="@string/auth_password"\r
 -                android:inputType="textPassword" />\r
 -\r
 -            <ImageView\r
 -                android:id="@+id/viewPasswordButton"\r
 -                android:layout_width="wrap_content"\r
 -                android:layout_height="wrap_content"\r
 -                android:layout_gravity="right|center_vertical"\r
 -                android:onClick="onViewPasswordClick"\r
 -                android:src="@android:drawable/ic_menu_view"\r
 -                android:visibility="invisible" />\r
 -        </FrameLayout>\r
 -\r
 +              <EditText\r
 +                  android:id="@+id/account_password"\r
 +                      android:layout_width="match_parent"\r
 +                      android:layout_height="wrap_content"\r
 +                      android:ems="10"\r
 +                      android:hint="@string/auth_password"\r
 +                      android:inputType="textPassword"\r
 +                      android:drawablePadding="5dp"\r
 +                      />\r
 +        \r
          <TextView\r
              android:id="@+id/auth_status_text"\r
              android:layout_width="match_parent"\r
              android:enabled="false"\r
              android:onClick="onOkClick"\r
              android:text="@string/setup_btn_connect"\r
-             android:textColor="@android:color/black" />\r
+             />\r
  \r
          <Button\r
              android:id="@+id/account_register"\r
@@@ -48,7 -48,9 +48,9 @@@ import android.net.Uri
  import android.os.Bundle;\r
  import android.os.Handler;\r
  import android.preference.PreferenceManager;\r
+ import android.text.Editable;\r
  import android.text.InputType;\r
+ import android.text.TextWatcher;\r
  import android.view.KeyEvent;\r
  import android.view.MotionEvent;\r
  import android.view.View;\r
@@@ -59,6 -61,7 +61,6 @@@ import android.view.inputmethod.EditorI
  import android.widget.CheckBox;\r
  import android.widget.EditText;\r
  import android.widget.Button;\r
 -import android.widget.ImageView;\r
  import android.widget.TextView;\r
  import android.widget.Toast;\r
  import android.widget.TextView.OnEditorActionListener;\r
@@@ -92,7 -95,6 +94,7 @@@ public class AuthenticatorActivity exte
      private static final String KEY_SERVER_STATUS_TEXT = "SERVER_STATUS_TEXT";\r
      private static final String KEY_SERVER_STATUS_ICON = "SERVER_STATUS_ICON";\r
      private static final String KEY_IS_SSL_CONN = "IS_SSL_CONN";\r
 +    private static final String KEY_PASSWORD_VISIBLE = "PASSWORD_VISIBLE";\r
      private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT";\r
      private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
      \r
      private byte mAction;\r
      private Account mAccount;\r
      \r
 -    private ImageView mViewPasswordButton;\r
      private EditText mHostUrlInput;\r
      private EditText mUsernameInput;\r
      private EditText mPasswordInput;\r
          \r
          /// set view and get references to view elements\r
          setContentView(R.layout.account_setup);\r
 -        mViewPasswordButton = (ImageView) findViewById(R.id.viewPasswordButton);\r
          mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput);\r
          mUsernameInput = (EditText) findViewById(R.id.account_username);\r
          mPasswordInput = (EditText) findViewById(R.id.account_password);\r
              mIsSslConn = savedInstanceState.getBoolean(KEY_IS_SSL_CONN);\r
              mAuthStatusText = savedInstanceState.getInt(KEY_AUTH_STATUS_TEXT);\r
              mAuthStatusIcon = savedInstanceState.getInt(KEY_AUTH_STATUS_ICON);\r
 +            if (savedInstanceState.getBoolean(KEY_PASSWORD_VISIBLE, false)) {\r
 +                showPassword();\r
 +            }\r
              \r
              /// server data\r
              String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);\r
          mHostUrlInput.setOnTouchListener(new RightDrawableOnTouchListener() {\r
              @Override\r
              public boolean onDrawableTouch(final MotionEvent event) {\r
 -                AuthenticatorActivity.this.onRefreshClick(mHostUrlInput);\r
 +                if (event.getAction() == MotionEvent.ACTION_UP) {\r
 +                    AuthenticatorActivity.this.onRefreshClick();\r
 +                }\r
                  return true;\r
              }\r
          });\r
+         mHostUrlInput.addTextChangedListener(new TextWatcher() {\r
\r
+             @Override\r
+             public void afterTextChanged(Editable s) {\r
+                 if (!mHostBaseUrl.equals(normalizeUrl(mHostUrlInput.getText().toString()))) {\r
+                     mOkButton.setEnabled(false);\r
+                 }\r
+             }\r
\r
+             @Override\r
+             public void beforeTextChanged(CharSequence s, int start, int count, int after) {}\r
\r
+             @Override\r
+             public void onTextChanged(CharSequence s, int start, int before, int count) {}\r
+             \r
+         });\r
          mPasswordInput.setOnFocusChangeListener(this);\r
          mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE);\r
          mPasswordInput.setOnEditorActionListener(this);\r
 +        mPasswordInput.setOnTouchListener(new RightDrawableOnTouchListener() {\r
 +            @Override\r
 +            public boolean onDrawableTouch(final MotionEvent event) {\r
 +                if (event.getAction() == MotionEvent.ACTION_UP) {\r
 +                    AuthenticatorActivity.this.onViewPasswordClick();\r
 +                }\r
 +                return true;\r
 +            }\r
 +        });\r
      }\r
      \r
      /**\r
          outState.putBoolean(KEY_SERVER_CHECKED, mServerIsChecked);\r
          outState.putBoolean(KEY_SERVER_CHECK_IN_PROGRESS, (!mServerIsValid && mOcServerChkOperation != null));\r
          outState.putBoolean(KEY_IS_SSL_CONN, mIsSslConn);\r
 +        outState.putBoolean(KEY_PASSWORD_VISIBLE, isPasswordVisible());\r
          outState.putInt(KEY_AUTH_STATUS_ICON, mAuthStatusIcon);\r
          outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText);\r
          \r
      private void onUrlInputFocusLost(TextView hostInput) {\r
          if (!mHostBaseUrl.equals(normalizeUrl(mHostUrlInput.getText().toString()))) {\r
              checkOcServer();\r
+         } else {\r
+             mOkButton.setEnabled(mServerIsValid);\r
          }\r
      }\r
  \r
       */\r
      private void onPasswordFocusChanged(TextView passwordInput, boolean hasFocus) {\r
          if (hasFocus) {\r
 -            mViewPasswordButton.setVisibility(View.VISIBLE);\r
 +            showViewPasswordButton();\r
          } else {\r
 -            int input_type = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;\r
 -            passwordInput.setInputType(input_type);\r
 -            mViewPasswordButton.setVisibility(View.INVISIBLE);\r
 +            hidePassword();\r
 +            hidePasswordButton();\r
          }\r
      }\r
  \r
  \r
 +    private void showViewPasswordButton() {\r
 +        int drawable = android.R.drawable.ic_menu_view;\r
 +        if (isPasswordVisible()) {\r
 +            drawable = android.R.drawable.ic_secure;\r
 +        }\r
 +        mPasswordInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable, 0);\r
 +    }\r
 +\r
 +    private boolean isPasswordVisible() {\r
 +        return ((mPasswordInput.getInputType() & InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);\r
 +    }\r
 +    \r
 +    private void hidePasswordButton() {\r
 +        mPasswordInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
 +    }\r
 +\r
 +    private void showPassword() {\r
 +        mPasswordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);\r
 +        showViewPasswordButton();\r
 +    }\r
 +    \r
 +    private void hidePassword() {\r
 +        mPasswordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);\r
 +        showViewPasswordButton();\r
 +    }\r
 +    \r
      \r
      /**\r
       * Cancels the authenticator activity\r
                  url = url.substring(0, url.length() - 1);\r
              }\r
          }\r
-         return url;\r
+         return (url != null ? url : "");\r
      }\r
  \r
      /**\r
       * \r
       * @param view      Refresh 'button'\r
       */\r
 -    public void onRefreshClick(View view) {\r
 +    public void onRefreshClick() {\r
          checkOcServer();\r
      }\r
      \r
      \r
 +    \r
      /**\r
       * Called when the eye icon in the password field is clicked.\r
       * \r
       * Toggles the visibility of the password in the field. \r
 -     * \r
 -     * @param view      'View password' 'button'\r
       */\r
 -    public void onViewPasswordClick(View view) {\r
 +    public void onViewPasswordClick() {\r
          int selectionStart = mPasswordInput.getSelectionStart();\r
          int selectionEnd = mPasswordInput.getSelectionEnd();\r
 -        int input_type = mPasswordInput.getInputType();\r
 -        if ((input_type & InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {\r
 -            input_type = InputType.TYPE_CLASS_TEXT\r
 -                    | InputType.TYPE_TEXT_VARIATION_PASSWORD;\r
 +        if (isPasswordVisible()) {\r
 +            hidePassword();\r
          } else {\r
 -            input_type = InputType.TYPE_CLASS_TEXT\r
 -                    | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;\r
 +            showPassword();\r
          }\r
 -        mPasswordInput.setInputType(input_type);\r
          mPasswordInput.setSelection(selectionStart, selectionEnd);\r
      }    \r
      \r
              mOAuthTokenEndpointText.setVisibility(View.VISIBLE);\r
              mUsernameInput.setVisibility(View.GONE);\r
              mPasswordInput.setVisibility(View.GONE);\r
 -            mViewPasswordButton.setVisibility(View.GONE);\r
          } else {\r
              mOAuthAuthEndpointText.setVisibility(View.GONE);\r
              mOAuthTokenEndpointText.setVisibility(View.GONE);\r
              mUsernameInput.setVisibility(View.VISIBLE);\r
              mPasswordInput.setVisibility(View.VISIBLE);\r
 -            mViewPasswordButton.setVisibility(View.INVISIBLE);\r
          }     \r
  \r
      }    \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
 +            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
 -                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
 +            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
              return false;\r