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 2017/08/15 09:51:30 UTC

[05/16] incubator-weex git commit: * [android] add PerformanceActivity

* [android] add PerformanceActivity


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

Branch: refs/heads/0.16-dev
Commit: e2d8a7b1e6a42a7191b23def69b10a572e48280e
Parents: afeedd9
Author: misakuo <mi...@apache.org>
Authored: Tue Jul 25 16:08:58 2017 +0800
Committer: misakuo <mi...@apache.org>
Committed: Tue Jul 25 16:08:58 2017 +0800

----------------------------------------------------------------------
 .../com/alibaba/weex/PerformanceActivity.java   | 121 +++++++++++++++++++
 1 file changed, 121 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/e2d8a7b1/android/playground/app/src/main/java/com/alibaba/weex/PerformanceActivity.java
----------------------------------------------------------------------
diff --git a/android/playground/app/src/main/java/com/alibaba/weex/PerformanceActivity.java b/android/playground/app/src/main/java/com/alibaba/weex/PerformanceActivity.java
new file mode 100644
index 0000000..ad88546
--- /dev/null
+++ b/android/playground/app/src/main/java/com/alibaba/weex/PerformanceActivity.java
@@ -0,0 +1,121 @@
+package com.alibaba.weex;
+
+
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.alibaba.weex.performance.EnvironmentFragment;
+import com.alibaba.weex.performance.EventOverviewFragment;
+
+public class PerformanceActivity extends WXBaseActivity {
+
+  private LinearLayout segmentHost;
+
+  public static void start(Context context, int instanceId) {
+    Intent intent = new Intent(context, PerformanceActivity.class);
+    intent.putExtra("instanceId", instanceId);
+    context.startActivity(intent);
+  }
+
+  @Override
+  protected void onCreate(Bundle savedInstanceState) {
+    super.onCreate(savedInstanceState);
+    setContentView(R.layout.activity_performance);
+    segmentHost = (LinearLayout) findViewById(R.id.segment_control);
+    addTab("页面性能", true, new View.OnClickListener() {
+      @Override
+      public void onClick(View v) {
+        switchFragment(EventOverviewFragment.getInstance(getIntent().getIntExtra("instanceId", -1)));
+      }
+    });
+
+    addTab("DOM树", false, new View.OnClickListener() {
+      @Override
+      public void onClick(View v) {
+
+      }
+    });
+
+    addTab("JS LOG", false, new View.OnClickListener() {
+      @Override
+      public void onClick(View v) {
+
+      }
+    });
+
+    addTab("环境变量", false, new View.OnClickListener() {
+      @Override
+      public void onClick(View v) {
+        switchFragment(new EnvironmentFragment());
+      }
+    });
+  }
+
+  private void switchFragment(Fragment fragment) {
+    getSupportFragmentManager()
+        .beginTransaction()
+        .replace(R.id.fragment_container, fragment)
+        .commitAllowingStateLoss();
+  }
+
+  @Override
+  protected void onResumeFragments() {
+    super.onResumeFragments();
+    FragmentManager fragmentManager = getSupportFragmentManager();
+
+    Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_container);
+    if (fragment == null) {
+      fragmentManager
+          .beginTransaction()
+          .add(R.id.fragment_container, EventOverviewFragment.getInstance(getIntent().getIntExtra("instanceId", -1)))
+          .commitAllowingStateLoss();
+    }
+  }
+
+  private void addTab(String title, final boolean selected, final View.OnClickListener listener) {
+    final TextView textView = new TextView(this);
+    textView.setText(title);
+    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
+    lp.weight = 1;
+    lp.setMargins(1, 1, 1, 1);
+    if (selected) {
+      textView.setBackgroundColor(Color.TRANSPARENT);
+    } else {
+      textView.setBackgroundColor(Color.WHITE);
+    }
+    textView.setGravity(Gravity.CENTER);
+    textView.setLayoutParams(lp);
+    textView.setOnClickListener(new View.OnClickListener() {
+      @Override
+      public void onClick(View v) {
+        if (!v.isSelected() && v instanceof TextView) {
+          listener.onClick(v);
+          for (int i = 0; i < segmentHost.getChildCount(); i++) {
+            segmentHost.getChildAt(i).setSelected(false);
+            segmentHost.getChildAt(i).setBackgroundColor(Color.WHITE);
+            ((TextView) segmentHost.getChildAt(i)).setTextColor(Color.parseColor("#1E90FF"));
+          }
+          v.setSelected(true);
+          v.setBackgroundColor(Color.TRANSPARENT);
+          ((TextView) v).setTextColor(Color.WHITE);
+        }
+      }
+    });
+    textView.setSelected(selected);
+    if (selected) {
+      textView.setTextColor(Color.WHITE);
+    } else {
+      textView.setTextColor(Color.parseColor("#1E90FF"));
+    }
+    segmentHost.addView(textView);
+  }
+}