package com.basic.security.fragment; import android.content.Context; import android.os.Bundle; import android.os.SystemClock; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Adapter; import android.widget.FrameLayout; import android.widget.ListView; import com.basic.security.base.BaseApplication; import com.basic.security.base.BaseFragment; import com.basic.security.manager.OrgManager; import com.basic.security.model.ModelAdapter; import com.basic.security.utils.ResolutionAdaptation; import com.basic.security.utils.SocketUtil; import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.EFragment; import org.androidannotations.annotations.UiThread; import org.androidannotations.annotations.ViewById; @EFragment public class OrgFragment extends BaseFragment { public static TreeAdapter treeAdapter = new TreeAdapter(); @ViewById public ListView orgs; public static int getWidestView(Context context, Adapter adapter) { int maxWidth = 0; View view = null; FrameLayout fakeParent = new FrameLayout(context); for (int i = 0, count = adapter.getCount(); i < count; i++) { view = adapter.getView(i, view, fakeParent); view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); int width = view.getMeasuredWidth(); if (width > maxWidth) { maxWidth = width; } } return maxWidth; } public void findTreeNodeList(TreeAdapter treeAdapter, boolean clearSelectedState, boolean isDialog) { afterFindTreeNodeList(treeAdapter); } @UiThread public void afterFindTreeNodeList(TreeAdapter treeAdapter) { treeAdapter.notifyDataSetChanged(); ((OrgFragment) this).setOrgWidthInBackground(); } public void updateOrgName(String orgId, String orgName) { BaseApplication.getApplication().executorService.execute(() -> { OrgManager.updateOrgName(orgId, orgName); OrgManager.initTreeNodeList(treeAdapter); SocketUtil.rpcCallInitTreeNodeList(); ((OrgFragment) this).setOrgWidthInBackground(); }); } public void deleteOrgById(String orgId) { BaseApplication.getApplication().executorService.execute(() -> { if (OrgManager.deleteOrgById(orgId)) { OrgManager.initTreeNodeList(treeAdapter); SocketUtil.rpcCallInitTreeNodeList(); ((OrgFragment) this).setOrgWidthInBackground(); } }); } public void addChildOrg(ModelAdapter parentOrg) { BaseApplication.getApplication().executorService.execute(() -> { OrgManager.addChildOrg(parentOrg, ""); OrgManager.initTreeNodeList(treeAdapter); SocketUtil.rpcCallInitTreeNodeList(); ((OrgFragment) this).setOrgWidthInBackground(); }); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(ResolutionAdaptation.fragment_org(), container, false); } @UiThread public void show() { super.show(); treeAdapter.notifyDataSetChanged(); setOrgWidthInBackground(); } public void setOrgWidthInBackground() { if (1 == 1) { return; } BaseApplication.getApplication().executorService.execute(() -> { SystemClock.sleep(100); setOrgWidth(); }); } @UiThread public void setOrgWidth() { orgs.getLayoutParams().width = (int) (getWidestView(BaseApplication.getApplication().activity, treeAdapter) * 1.05); System1.out.println("OrgFragment.setOrgWidth " + orgs.getLayoutParams().width); } @AfterViews public void afterViews() { orgs.setAdapter(treeAdapter); } }