initial commit of editbox with badge
authorBartek Przybylski <bart.p.pl@gmail.com>
Tue, 1 May 2012 21:37:37 +0000 (23:37 +0200)
committerBartek Przybylski <bart.p.pl@gmail.com>
Tue, 1 May 2012 21:37:37 +0000 (23:37 +0200)
res/layout/account_setup.xml
res/values/attrs.xml [new file with mode: 0644]
src/eu/alefzero/owncloud/widgets/ActionEditText.java [new file with mode: 0644]

index 9868b27..3a9cb4e 100644 (file)
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>\r
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+    xmlns:oc="http://schemas.android.com/apk/res/eu.alefzero.owncloud"\r
     android:layout_width="fill_parent"\r
     android:layout_height="fill_parent"\r
     android:background="#F7F7F7"\r
@@ -67,7 +68,7 @@
                 android:gravity="center_horizontal"\r
                 android:weightSum="1.0" >\r
 \r\r\r
-                <EditText\r
+                <eu.alefzero.owncloud.widgets.ActionEditText\r
                     android:id="@+id/host_URL"\r
                     android:layout_width="fill_parent"\r
                     android:layout_height="wrap_content"\r
                     android:hint="@string/setup_hint_address"\r
                     android:inputType="textUri"\r
                     android:textColor="@android:color/black"\r
-                    android:singleLine="true" >\r
+                    android:singleLine="true"\r
+                    oc:optionOneString="SSL"\r
+                    oc:optionTwoString="NO SSL"\r
+                    oc:optionOneColor="#00ff00"\r
+                    oc:optionTwoColor="#ff0000"\r
+                    oc:onBadgeClick="sslBadgeClick">\r
 \r
                     <requestFocus>\r
                     </requestFocus>\r
-                </EditText>\r
+                </eu.alefzero.owncloud.widgets.ActionEditText>\r
             </TableRow>\r
 \r
             <TableRow\r
                 android:gravity="center_horizontal"\r
                 android:weightSum="1.0" >\r
 \r\r
-                <EditText\r
+                <eu.alefzero.owncloud.widgets.ActionEditText\r
                     android:id="@+id/account_password"\r
                     android:layout_width="fill_parent"\r
                     android:layout_height="wrap_content"\r
                     android:hint="@string/setup_hint_password"\r
                     android:inputType="textPassword"\r
                     android:singleLine="true"\r
-                    android:textColor="@android:color/black" >\r
+                    android:textColor="@android:color/black" \r
+                    oc:optionOneString="Show"\r
+                    oc:optionTwoString="Hide"\r
+                    oc:optionOneColor="#00ff00"\r
+                    oc:optionTwoColor="#ff0000"\r
+                    oc:onBadgeClick="passwordBadgeClick">\r
 \r
-                </EditText>\r
+                </eu.alefzero.owncloud.widgets.ActionEditText>\r
             </TableRow>\r
             <TableRow android:id="@+id/tableRow5"\r
                 android:layout_width="fill_parent"\r
             android:layout_width="fill_parent"\r
             android:layout_height="wrap_content"\r
             android:gravity="center_horizontal"\r
-            android:orientation="horizontal"\r
+            android:orientation="vertical"\r
             android:weightSum="1.0" >\r
 \r
             <Button\r
                 android:textColor="@android:color/black"\r
                 android:text="@string/setup_btn_connect" >\r
             </Button>\r
+\r
+            <Button\r
+                android:id="@+id/buttonNotUser"\r
+                android:layout_width="wrap_content"\r
+                android:layout_height="wrap_content"\r
+                android:layout_weight=".50"\r
+                android:onClick="onNotUserClick"\r
+                android:textColor="@android:color/black"\r
+                android:text="Get started!" >\r
+            </Button>\r
+            \r
         </LinearLayout>\r
     </LinearLayout>\r
 \r
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
new file mode 100644 (file)
index 0000000..22c082c
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+       <declare-styleable name="ActionEditText">
+
+               <attr name="optionOneString" format="string" />
+               <attr name="optionOneColor" format="color" />
+    <attr name="optionTwoString" format="string" />
+               <attr name="optionTwoColor" format="color" />
+               <attr name="onBadgeClick" format="string" />
+
+       </declare-styleable>
+
+</resources>
\ No newline at end of file
diff --git a/src/eu/alefzero/owncloud/widgets/ActionEditText.java b/src/eu/alefzero/owncloud/widgets/ActionEditText.java
new file mode 100644 (file)
index 0000000..adc1845
--- /dev/null
@@ -0,0 +1,133 @@
+package eu.alefzero.owncloud.widgets;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import eu.alefzero.owncloud.R;
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.text.InputType;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import android.widget.TextView;
+
+public class ActionEditText extends EditText {
+  private String s;
+  private String optionOneString;
+  private int optionOneColor; 
+  private String optionTwoString;
+  private int optionTwoColor;
+  
+  private String badgeClickCallback;
+  private Rect btn_rect;
+  
+  public ActionEditText(Context context, AttributeSet attrs) {
+    super(context, attrs);
+    getAttrs(attrs);
+    s = optionOneString;
+  }
+  
+  public ActionEditText(Context context, AttributeSet attrs, int defStyle) {
+    super(context, attrs, defStyle);
+    getAttrs(attrs);
+    s = optionOneString;
+  }
+  
+  @Override
+  protected void onDraw(Canvas canvas) {
+    super.onDraw(canvas);
+    Rect r = new Rect();
+    
+    Paint p = getPaint();
+    Rect text_bounds = new Rect();
+    
+    p.getTextBounds(s, 0, s.length(), text_bounds);
+    
+    getDrawingRect(r);
+    r.top += 10;
+    r.bottom -= 10;
+    r.left = (int)(getWidth() - text_bounds.width() - 18);
+    r.right = getWidth() - 10;
+    btn_rect = r;
+    
+    if (s.equals(optionOneString))
+      p.setColor(optionOneColor);
+    else
+      p.setColor(optionTwoColor);
+    canvas.drawRect(r, p);
+    p.setColor(Color.GRAY);
+    
+    canvas.drawText(s, r.left + 3, r.bottom - (text_bounds.height()/2), p);
+    
+    invalidate();
+  }
+
+  @Override
+  public boolean onTouchEvent(MotionEvent event) {
+    int touchX = (int) event.getX();
+    int touchY = (int) event.getY();
+    boolean r = super.onTouchEvent(event);
+    if (event.getAction() == MotionEvent.ACTION_UP) {
+      if (btn_rect.contains(touchX, touchY)) {
+        if (s.equals(optionTwoString)) s = optionOneString;
+        else s = optionTwoString;
+        if (badgeClickCallback != null) {
+          Class[] paramtypes = new Class[2];
+          paramtypes[0] = android.view.View.class;
+          paramtypes[1] = String.class;
+          Method method;
+          try {
+            method = this.getClass().getMethod(badgeClickCallback, paramtypes);
+            method.invoke(this, this, s);
+          } catch (NoSuchMethodException e) {
+            e.printStackTrace();
+          } catch (IllegalArgumentException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+          } catch (IllegalAccessException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+          } catch (InvocationTargetException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+          }
+          
+        }
+        invalidate();
+      }
+    }
+    return r;
+  }
+
+  private void getAttrs(AttributeSet attr) {
+    TypedArray a = getContext().obtainStyledAttributes(attr, R.styleable.ActionEditText);
+    optionOneString = a.getString(R.styleable.ActionEditText_optionOneString);
+    optionTwoString = a.getString(R.styleable.ActionEditText_optionTwoString);
+    optionOneColor = a.getColor(R.styleable.ActionEditText_optionOneColor, 0x00ff00);
+    optionTwoColor = a.getColor(R.styleable.ActionEditText_optionTwoColor, 0xff0000);
+    badgeClickCallback = a.getString(R.styleable.ActionEditText_onBadgeClick);
+  }
+  
+  public void sslBadgeClick(View view, String val) {
+    Log.d("ASD", val);
+  }
+  
+  public void passwordBadgeClick(View view, String val) {
+    
+    if(val.equals("Hide")) {
+      ((TextView)view).setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
+    } else {
+      ((TextView)view).setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+    }
+  }
+  
+}