Android: add doric panel list
This commit is contained in:
parent
75aec7f78d
commit
598634e0dc
@ -28,6 +28,10 @@
|
||||
<activity
|
||||
android:name=".DoricDebugTimingActivity"
|
||||
android:theme="@style/Theme.Design.Light.NoActionBar" />
|
||||
|
||||
<activity
|
||||
android:name=".DoricPanelListActivity"
|
||||
android:theme="@style/Theme.Design.Light.NoActionBar" />
|
||||
</application>
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
@ -0,0 +1,137 @@
|
||||
package pub.doric.demo;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricPanel;
|
||||
import pub.doric.DoricSingleton;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.navigator.IDoricNavigator;
|
||||
import pub.doric.performance.DoricPerformanceProfile;
|
||||
import pub.doric.utils.DoricLog;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
|
||||
public class DoricPanelListActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_doric_panel_list);
|
||||
|
||||
RecyclerView recyclerView = findViewById(R.id.doric_panel_rv);
|
||||
recyclerView.setBackgroundColor(Color.WHITE);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
recyclerView.setNestedScrollingEnabled(true);
|
||||
recyclerView.setAdapter(new MyAdapter(new String[]{
|
||||
"Counter.js",
|
||||
"EffectsDemo.js",
|
||||
"FlowLayoutDemo.js",
|
||||
"Gobang.js",
|
||||
"HelloDoric.js",
|
||||
"LayoutDemo.js",
|
||||
"TextAnimationDemo.js",
|
||||
}));
|
||||
}
|
||||
|
||||
public static class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private final String[] data;
|
||||
private final Map<Integer, DoricPanel> panels = new HashMap<>();
|
||||
private static final int PANEL_HEIGHT = 300;
|
||||
final long pefStart = System.currentTimeMillis();
|
||||
|
||||
public MyAdapter(String[] demos) {
|
||||
this.data = demos;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
DoricPanel doricPanel = new DoricPanel(parent.getContext());
|
||||
doricPanel.setLayoutParams(new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
DoricUtils.dp2px(PANEL_HEIGHT)));
|
||||
return new RecyclerView.ViewHolder(doricPanel) {
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, @SuppressLint("RecyclerView") final int position) {
|
||||
if (panels.containsKey(position)) {
|
||||
//TODO at here to handle on bind
|
||||
} else {
|
||||
panels.put(position, (DoricPanel) holder.itemView);
|
||||
String source = "assets://src/" + data[position];
|
||||
final String alias = "__dev__";
|
||||
final String extra = "{}";
|
||||
|
||||
final DoricPanel doricPanel = (DoricPanel) holder.itemView;
|
||||
DoricSingleton.getInstance().getJSLoaderManager().loadJSBundle(source).setCallback(new AsyncResult.Callback<String>() {
|
||||
@Override
|
||||
public void onResult(String result) {
|
||||
doricPanel.config(result, alias, extra);
|
||||
DoricContext context = doricPanel.getDoricContext();
|
||||
context.setDoricNavigator(new IDoricNavigator() {
|
||||
@Override
|
||||
public void push(String source, String alias, String extra) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pop() {
|
||||
|
||||
}
|
||||
});
|
||||
doricPanel.getDoricContext().getPerformanceProfile().addAnchorHook(new DoricPerformanceProfile.AnchorHook() {
|
||||
@Override
|
||||
public void onAnchor(String name, long prepare, long start, long end) {
|
||||
if (name.equals(DoricPerformanceProfile.STEP_RENDER)) {
|
||||
long cost = end - pefStart;
|
||||
Log.d("Timing", "Cost " + cost + "ms");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
DoricLog.e("Doric load JS error:" + t.getLocalizedMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return data.length;
|
||||
}
|
||||
}
|
||||
}
|
@ -34,13 +34,13 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import pub.doric.DoricActivity;
|
||||
import pub.doric.devkit.DoricDev;
|
||||
import pub.doric.refresh.DoricSwipeLayout;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -77,7 +77,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
public static class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private final String[] data;
|
||||
|
||||
@ -95,6 +95,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
DoricUtils.dp2px(50)));
|
||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
||||
return new RecyclerView.ViewHolder(textView) {
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
@ -102,6 +103,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, @SuppressLint("RecyclerView") final int position) {
|
||||
final TextView tv = (TextView) holder.itemView;
|
||||
@ -113,13 +115,22 @@ public class MainActivity extends AppCompatActivity {
|
||||
DoricDev.getInstance().openDevMode();
|
||||
}
|
||||
});
|
||||
} else if (position == 1) {
|
||||
tv.setText("Doric Panel List");
|
||||
tv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(tv.getContext(), DoricPanelListActivity.class);
|
||||
tv.getContext().startActivity(intent);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
tv.setText(data[position - 1]);
|
||||
tv.setText(data[position - 2]);
|
||||
tv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(tv.getContext(), DoricDebugTimingActivity.class);
|
||||
intent.putExtra("source", "assets://src/" + data[position - 1]);
|
||||
intent.putExtra("source", "assets://src/" + data[position - 2]);
|
||||
//intent.putExtra("alias", data[position - 1].replace(".js", ""));
|
||||
intent.putExtra("alias", "__dev__");
|
||||
tv.getContext().startActivity(intent);
|
||||
@ -130,7 +141,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return data.length + 1;
|
||||
return data.length + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/doric_panel_rv"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
Reference in New Issue
Block a user