You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by mi...@apache.org on 2018/03/15 06:11:25 UTC

[1/2] incubator-weex git commit: *[android] fix selection error in picker

Repository: incubator-weex
Updated Branches:
  refs/heads/master f77db8fe5 -> a7b912361


*[android] fix selection error in picker


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/a7b91236
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/a7b91236
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/a7b91236

Branch: refs/heads/master
Commit: a7b912361f1f31b7baabc4512b450b296ba3b0bc
Parents: 4d06e61
Author: misakuo <mi...@apache.org>
Authored: Tue Mar 13 18:11:49 2018 +0800
Committer: misakuo <mi...@apache.org>
Committed: Thu Mar 15 14:11:06 2018 +0800

----------------------------------------------------------------------
 .../weex/appfram/pickers/WXPickersModule.java   | 68 +++++++++-----------
 1 file changed, 29 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/a7b91236/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java b/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
index 426412f..ef46f8f 100644
--- a/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
+++ b/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
@@ -32,7 +32,6 @@ import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.Checkable;
-import android.widget.CheckedTextView;
 import android.widget.ListView;
 import android.widget.TextView;
 
@@ -185,29 +184,36 @@ public class WXPickersModule extends WXModule {
     private void performSinglePick(final List<String> items, final Map<String, Object> options, final JSCallback callback) {
         selected = getOption(options, KEY_INDEX, 0);
         final int textColor = getColor(options, KEY_TEXT_COLOR, Color.TRANSPARENT);
+        final int selectionColor = getColor(options, KEY_SELECTION_COLOR, Color.TRANSPARENT);
+        final ArrayAdapter adapter = new ArrayAdapter<String>(
+            mWXSDKInstance.getContext(),
+            android.R.layout.simple_list_item_single_choice,
+            items) {
+            @NonNull
+            @Override
+            public View getView(int position, View convertView, @Nullable ViewGroup parent) {
+                View itemView =  super.getView(position, convertView, parent);
+
+                if (itemView != null && itemView instanceof Checkable) {
+                    boolean needSelected = position == selected;
+                    ((Checkable) itemView).setChecked(needSelected);
+
+                    if (needSelected) {
+                        itemView.setBackgroundColor(selectionColor);
+                    } else {
+                        itemView.setBackgroundColor(Color.TRANSPARENT);
+                    }
+                }
+
+                if (itemView instanceof TextView && textColor != Color.TRANSPARENT) {
+                    ((TextView) itemView).setTextColor(textColor);
+                }
 
+                return itemView;
+            }
+        };
         final AlertDialog dialog =  new AlertDialog.Builder(mWXSDKInstance.getContext())
-                .setAdapter(
-                        new ArrayAdapter<String>(
-                                mWXSDKInstance.getContext(),
-                                android.R.layout.simple_list_item_single_choice,
-                                items) {
-                            @NonNull
-                            @Override
-                            public View getView(int position, View convertView, @Nullable ViewGroup parent) {
-                                View itemView =  super.getView(position, convertView, parent);
-
-                                if (itemView != null && itemView instanceof CheckedTextView) {
-                                    ((CheckedTextView) itemView).setChecked(position == selected);
-                                }
-
-                                if (itemView instanceof TextView && textColor != Color.TRANSPARENT) {
-                                    ((TextView) itemView).setTextColor(textColor);
-                                }
-
-                                return itemView;
-                            }
-                        } , null)
+                .setAdapter(adapter, null)
                 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialog, int which) {
@@ -239,26 +245,10 @@ public class WXPickersModule extends WXModule {
 
         final ListView listView = dialog.getListView();
         listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
-            private View previousView;
-            private int selectionColor = getColor(options, KEY_SELECTION_COLOR, Color.TRANSPARENT);
-
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                 selected = position;
-                if (previousView == view) {
-                    return;
-                }
-                if (previousView != null) {
-                    previousView.setBackgroundColor(Color.TRANSPARENT);
-                    if (previousView instanceof Checkable) {
-                        ((Checkable) previousView).toggle();
-                    }
-                }
-                if (view instanceof Checkable) {
-                    ((Checkable) view).toggle();
-                }
-                view.setBackgroundColor(selectionColor);
-                previousView = view;
+                adapter.notifyDataSetChanged();
             }
         });
 


[2/2] incubator-weex git commit: *[android] fix selection error in picker

Posted by mi...@apache.org.
*[android] fix selection error in picker


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/4d06e619
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/4d06e619
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/4d06e619

Branch: refs/heads/master
Commit: 4d06e6199a875060c0af9bc76d126fef01d66820
Parents: f77db8f
Author: misakuo <mi...@apache.org>
Authored: Tue Mar 13 17:41:01 2018 +0800
Committer: misakuo <mi...@apache.org>
Committed: Thu Mar 15 14:11:06 2018 +0800

----------------------------------------------------------------------
 .../weex/appfram/pickers/WXPickersModule.java     | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/4d06e619/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java b/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
index 889f611..426412f 100644
--- a/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
+++ b/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
@@ -32,6 +32,7 @@ import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.Checkable;
+import android.widget.CheckedTextView;
 import android.widget.ListView;
 import android.widget.TextView;
 
@@ -77,7 +78,6 @@ public class WXPickersModule extends WXModule {
     private static final String KEY_SELECTION_COLOR = "selectionColor";
 
     private int selected;
-    private View selectedView;
 
     @JSMethod
     public void pick(Map<String, Object> options, JSCallback callback) {
@@ -182,7 +182,7 @@ public class WXPickersModule extends WXModule {
 
     }
 
-    private void performSinglePick(List<String> items, final Map<String, Object> options, final JSCallback callback) {
+    private void performSinglePick(final List<String> items, final Map<String, Object> options, final JSCallback callback) {
         selected = getOption(options, KEY_INDEX, 0);
         final int textColor = getColor(options, KEY_TEXT_COLOR, Color.TRANSPARENT);
 
@@ -196,8 +196,9 @@ public class WXPickersModule extends WXModule {
                             @Override
                             public View getView(int position, View convertView, @Nullable ViewGroup parent) {
                                 View itemView =  super.getView(position, convertView, parent);
-                                if (position == selected) {
-                                    selectedView = itemView;
+
+                                if (itemView != null && itemView instanceof CheckedTextView) {
+                                    ((CheckedTextView) itemView).setChecked(position == selected);
                                 }
 
                                 if (itemView instanceof TextView && textColor != Color.TRANSPARENT) {
@@ -261,15 +262,6 @@ public class WXPickersModule extends WXModule {
             }
         });
 
-        listView.post(WXThread.secure(new Runnable() {
-            @Override
-            public void run() {
-                if (selectedView != null) {
-                    listView.performItemClick(selectedView, selected, selectedView.getId());
-                }
-            }
-        }));
-
         dialog.getWindow().getDecorView().post(WXThread.secure(new Runnable() {
             @Override
             public void run() {