@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { DisplayMetrics metrics = getResources().getDisplayMetrics(); int inch = (int) (metrics.density * 160); final ExtendedFrameLayout layout = new ExtendedFrameLayout(getActivity()); layout.setId(BaseActivity.generateViewId()); layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); buttonSize = (int) (inch / 3.0f); HorizontalScrollView scrollView = new HorizontalScrollView(getActivity()); scrollView.setHorizontalScrollBarEnabled(false); layout.addView(scrollView); scrollView.setLayoutParams( new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); if (menu == null) { // load and build menu if necessary menu = new LaTeXMenu(); EquationEditorPlugin plugin = EquationEditorPlugin.getPlugin(); menu.setButtonBackgroundResource(R.drawable.menu_item); menu.setSpecialButtonBackgroundResource(R.drawable.menu_item_special); int pixelsValue = 4; float d = layout.getContext().getResources().getDisplayMetrics().density; menu.setMarginButton((int) (pixelsValue * d)); File assets = new File(EquationEditorPlugin.getPluginDirectoryStatic(getActivity()), "assets"); assets.mkdir(); File out = new File(assets, "mathMenu.xml"); plugin.loadAsset(getActivity(), out, "mathMenu.xml"); FileReader reader = null; try { reader = new FileReader(out); // Creates items in menu menu.loadData(getActivity(), reader); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (reader != null) try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } menu.setFragmentPluginListener(listener.getFragmentPluginListener()); // set context for menu RelativeLayout menuLayout = menu.createLayout( getActivity(), buttonSize, buttonSize, buttonSize * 4, (int) (inch * 1.5f)); scrollView.addView(menuLayout); menuLayout.setLayoutParams( new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); if (lines == null) // Creates a board for the first time board = new EditorBoard(this, menu, menu.getLatexMap(), menu.getUnicodeLatex()); else { // Creates a board with already parsed objects. It is typically used after a rotation. For // faster reaction time. board = new EditorBoard(this, menu, menu.getLatexMap(), menu.getUnicodeLatex(), lines, content); board.setEditorScrollX(editorScrollX); board.setEditorScrollY(editorScrollY); if (isChanged) board.makeDirty(); } board.setId(BaseActivity.generateViewId()); board.setOnContentChangedListener(listener); board.setScreen(metrics.widthPixels, metrics.heightPixels); layout.addView(board, 0); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) board.getLayoutParams(); params.width = LayoutParams.MATCH_PARENT; params.height = LayoutParams.MATCH_PARENT; params.topMargin = buttonSize; // Place equations drawing below the menu board.setLayoutParams(params); menu.setOnItemClickListener( new LaTeXMenu.OnItemMenuClickListener() { @Override public void onClick(LaTeXMenu menu, LaTeXMenuButton menuButton, LaTeXButton button) { board.addObject(button.getDataObject(), button.getAddon(), button.isNormal()); if (mode != null) mode.finish(); } }); board.setOnContentChangedListener( new OnContentChangedListener() { @Override public Task requestPDF() { if (EditorFragment.this.listener != null) return EditorFragment.this.listener.requestPDF(); return null; } @Override public void onContentChanged() { isChanged = true; if (listener != null) listener.onContentChanged(); } @Override public AbstractPluginFragment getParentFragment() { return listener.getParentFragment(); } @Override public FragmentPluginListener getFragmentPluginListener() { if (listener != null) return listener.getFragmentPluginListener(); return null; } @Override public ActionMode startActionMode(Callback textSelector) { if (listener != null) return listener.startActionMode(textSelector); return null; } @Override public void openFile(String path) {} @Override public void openData(EditorPlugin plugin, String data, int start, int end) {} @Override public void requestInsert() {} }); textSelector = new ObjectSelector(board); textSelector.setOnMovingHandle( new ObjectSelector.OnMovingHandle() { @Override public void handleStartedMoving() { layout.stopLongPressed(); } }); textSelector.setOnSelecting( new ObjectSelector.OnSelecting() { @Override public void selectingStopped() { board.setFocusable(false); board.setFocusableInTouchMode(false); } @Override public void selectingStarted() { board.setFocusable(true); board.setFocusableInTouchMode(true); } }); if (selectorBegin != null && selectorEnd != null) { textSelector.setSelection(selectorBegin, selectorEnd, selectorNoBegin, selectorNoEnd); mode = listener.startActionMode(textSelector); } return layout; }
public SlidingPaneView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); final Resources res = getResources(); setClipChildren(false); setClipToPadding(false); // reading attributes final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionsContentView); final int spacingLeftDefault = res.getDimensionPixelSize(R.dimen.default_slidepane_spacing_left); mLeftSpacing = a.getDimensionPixelSize(R.styleable.ActionsContentView_spacingLeft, spacingLeftDefault); final int spacingRightDefault = res.getDimensionPixelSize(R.dimen.default_slidepane_spacing_right); mRightSpacing = a.getDimensionPixelSize(R.styleable.ActionsContentView_spacingRight, spacingRightDefault); final int leftPaneLayout = a.getResourceId(R.styleable.ActionsContentView_layoutLeft, 0); if (leftPaneLayout == 0) throw new IllegalArgumentException("The layoutLeft attribute is required"); final int rightPaneLayout = a.getResourceId(R.styleable.ActionsContentView_layoutRight, 0); if (rightPaneLayout == leftPaneLayout || rightPaneLayout == 0) throw new IllegalArgumentException("The layoutRight attribute is required"); final boolean shadowSlidableDefault = res.getBoolean(R.bool.default_shadow_slidable); final boolean shadowSlidable = a.getBoolean(R.styleable.ActionsContentView_shadowSlidable, shadowSlidableDefault); mShadowWidth = a.getDimensionPixelSize(R.styleable.ActionsContentView_shadowWidth, 0); final int shadowDrawableRes = a.getResourceId(R.styleable.ActionsContentView_shadowDrawable, 0); mFadeType = a.getInteger(R.styleable.ActionsContentView_fadeType, FADE_NONE); final int fadeValueDefault = res.getInteger(R.integer.default_sliding_pane_fade_max); mFadeMax = a.getDimensionPixelSize(R.styleable.ActionsContentView_fadeMax, fadeValueDefault); final int flingDurationDefault = res.getInteger(R.integer.default_sliding_pane_fling_duration); mFlingDuration = a.getInteger(R.styleable.ActionsContentView_flingDuration, flingDurationDefault); a.recycle(); mController = new ContentScrollController(new Scroller(context)); mTouchInterceptor = new ScrollTouchInterceptor(this); mShadowTouchListener = new ShadowTouchListener(this); mLeftPaneLayout = new LeftPaneLayout(this); mRightPaneLayout = new RightPaneLayout(this); mRightPaneContainer = new ExtendedFrameLayout(context); mFadingRightPaneContainer = new FadingRightPaneContainer(this); mViewShadow = new View(context); mRightPaneBackgroundView = new RightPaneBackgroundView(context); final LayoutInflater inflater = LayoutInflater.from(context); if (leftPaneLayout == 0) throw new IllegalArgumentException(); mLeftPaneView = inflater.inflate(leftPaneLayout, mLeftPaneLayout, true); if (rightPaneLayout == 0) throw new IllegalArgumentException(); mRightPaneView = inflater.inflate(rightPaneLayout, mFadingRightPaneContainer, true); addView( mLeftPaneLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(mRightPaneLayout, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mViewShadow.setBackgroundResource(shadowDrawableRes); if (mShadowWidth <= 0 || shadowDrawableRes == 0) { mViewShadow.setVisibility(GONE); } mRightPaneLayout.addView(mViewShadow, mShadowWidth, LinearLayout.LayoutParams.MATCH_PARENT); mRightPaneLayout.addView( mRightPaneContainer, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mRightPaneContainer.addView( mRightPaneBackgroundView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mRightPaneContainer.addView( mFadingRightPaneContainer, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mRightPaneContainer.setTouchInterceptor(mTouchInterceptor); mRightPaneLayout.setOnSwipeListener(new SwipeFadeListener()); mViewShadow.setOnTouchListener(mShadowTouchListener); setShadowSlidable(shadowSlidable); }