@Override public void stopPlay() { final BaseViewAdapter adapter = internalAdapter(); if (adapter != null) { adapter.stopRecord(false); } }
@Override public int insertImageFromFile(String filename) { final BaseViewAdapter adapter = internalAdapter(); if (adapter == null || filename == null) return 0; String name = filename.substring(filename.lastIndexOf('/') + 1).toLowerCase(Locale.US); Drawable d; if (name.endsWith(".svg")) { d = mView.getImageCache().addSVGFile(filename, name); } else { d = mView.getImageCache().addBitmapFile(getContext().getResources(), filename, name); } if (d != null) { final String destPath = adapter.getRecordPath(); if (destPath != null) { ImageCache.copyFileTo(filename, destPath); } synchronized (mView.coreView()) { int w = ImageCache.getWidth(d); int h = ImageCache.getHeight(d); return mView.coreView().addImageShape(name, w, h); } } return 0; }
@Override public void stopUndoRecord() { final BaseViewAdapter adapter = internalAdapter(); if (adapter != null) { adapter.stopRecord(true); } }
@Override public void redo() { final BaseViewAdapter adapter = internalAdapter(); if (adapter != null) { adapter.redo(); } }
@Override public boolean startPlay(String path) { final BaseViewAdapter adapter = internalAdapter(); if (adapter == null || adapter.getSavedState() != null || mView.coreView().isPlaying() || !new File(path).exists()) { return false; } return adapter.startPlay(path); }
@Override public boolean startRecord(String path) { final BaseViewAdapter adapter = internalAdapter(); if (adapter == null || adapter.getSavedState() != null || mView.coreView().isRecording() || !deleteDirectory(new File(path)) || !createDirectory(path, true)) { return false; } return adapter.startRecord(path); }
@Override public boolean onPause() { if (mViewAdapter != null) { mViewAdapter.hideContextActions(); return mCoreView.onPause(BaseViewAdapter.getTick()); } return false; }
@Override public void onRestoreInstanceState(Bundle savedState) { final BaseViewAdapter adapter = internalAdapter(); final Bundle state = savedState.getBundle("vg"); if (adapter != null && state != null) { final LogHelper log = new LogHelper(); final String filename = state.getString("bakFile"); boolean readOnly = state.getBoolean("readOnly"); if (filename != null && loadFromFile(filename, readOnly)) { Log.d(TAG, "Auto load from " + filename); } adapter.onRestoreInstanceState(state); log.r(); } else { Log.w(TAG, "onRestoreInstanceState fail, state:" + (state != null)); } }
@Override public void onSaveInstanceState(Bundle outState, String path) { final BaseViewAdapter adapter = internalAdapter(); if (adapter == null) { Log.w(TAG, "onSaveInstanceState fail due to no view adapter"); } else { final LogHelper log = new LogHelper(); Bundle state = adapter.getSavedState(); if (state == null) { final String filename = new File(path, "resume.vg").getPath(); final String playFile = new File(path, "playresume.vg").getPath(); state = new Bundle(); adapter.onSaveInstanceState(state); if (mView.coreView().isPlaying()) { if (saveToFile(playFile)) { Log.d(TAG, "Auto save playing shapes to " + playFile); state.putString("playFile", playFile); } if (saveToFile(filename, mView.coreView().backDoc())) { Log.d(TAG, "Auto save to " + filename); state.putString("bakFile", filename); } } else { if (saveToFile(filename)) { Log.d(TAG, "Auto save to " + filename); state.putString("bakFile", filename); } } state.putBoolean("readOnly", cmdView().isReadOnly()); } outState.putBundle("vg", state); log.r(); } }
@Override public boolean onResume() { return mCoreView.onResume(BaseViewAdapter.getTick()); }
@Override public int getPlayProviderCount() { final BaseViewAdapter adapter = internalAdapter(); return adapter != null ? adapter.getPlayProviderCount() : 0; }
@Override public int getPlayTicks() { return mView.coreView().getRecordTick(false, BaseViewAdapter.getTick()); }
@Override public boolean playResume() { return mView != null && mView.coreView().onResume(BaseViewAdapter.getTick()); }
public void createDummyView(Context context, int width, int height) { final StdGraphView view = new StdGraphView(context, (BaseGraphView) null); view.layout(0, 0, width, height); mView = view; mView.coreView().onSize(BaseViewAdapter.getMainAdapter(mView), width, height); }
@Override public boolean addPlayProvider(PlayProvider p, int tag, Object extra) { final BaseViewAdapter adapter = internalAdapter(); return adapter != null && p != null && adapter.addPlayProvider(p, tag, extra); }
public BaseViewAdapter getMainAdapter() { return BaseViewAdapter.getMainAdapter(mView); }
@Override public String getCommand() { final BaseViewAdapter adapter = internalAdapter(); return adapter != null ? adapter.getCommand() : ""; }