@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.example_scratchboard); mContext = this; // ------------------------------------ // UI Setting // ------------------------------------ mOpenBtn = (ImageView) findViewById(R.id.openBtn); mOpenBtn.setOnClickListener(openBtnClickListener); mSaveBtn = (ImageView) findViewById(R.id.saveBtn); mSaveBtn.setOnClickListener(saveBtnClickListener); mPenBtn = (ImageView) findViewById(R.id.penBtn); mPenBtn.setOnClickListener(mBtnClickListener); mEraserBtn = (ImageView) findViewById(R.id.eraseBtn); mEraserBtn.setOnClickListener(mBtnClickListener); mUndoBtn = (ImageView) findViewById(R.id.undoBtn); mUndoBtn.setOnClickListener(undoNredoBtnClickListener); mRedoBtn = (ImageView) findViewById(R.id.redoBtn); mRedoBtn.setOnClickListener(undoNredoBtnClickListener); // ------------------------------------ // Create SCanvasView // ------------------------------------ mLayoutContainer = (FrameLayout) findViewById(R.id.layout_container); mCanvasContainer = (RelativeLayout) findViewById(R.id.canvas_container); mSCanvas = new SCanvasView(mContext); mCanvasContainer.addView(mSCanvas); // Set canvas size // setSCanvasViewLayout(); // ------------------------------------ // SettingView Setting // ------------------------------------ // Resource Map for Layout & Locale HashMap<String, Integer> settingResourceMapInt = SPenSDKUtils.getSettingLayoutLocaleResourceMap(true, true, true, false); // Talk & Description Setting by Locale SPenSDKUtils.addTalkbackAndDescriptionStringResourceMap(settingResourceMapInt); // Resource Map for Custom font path HashMap<String, String> settingResourceMapString = SPenSDKUtils.getSettingLayoutStringResourceMap(true, true, true, false); // Create Setting View mSCanvas.createSettingView(mLayoutContainer, settingResourceMapInt, settingResourceMapString); // Initialize Stroke Setting mStrokeInfoScratch = new SettingStrokeInfo(); mStrokeInfoScratch.setStrokeStyle(SObjectStroke.SAMM_STROKE_STYLE_ERASER); mStrokeInfoScratch.setStrokeWidth(3); // small scratch mStrokeInfoEraser = new SettingStrokeInfo(); mStrokeInfoEraser.setStrokeStyle(SObjectStroke.SAMM_STROKE_STYLE_SOLID); mStrokeInfoEraser.setStrokeColor(Color.BLACK); // assume that the foreground is black mStrokeInfoEraser.setStrokeWidth(50); // // ==================================================================================== // // Set Callback Listener(Interface) // // ==================================================================================== // ------------------------------------------------ // SCanvas Listener // ------------------------------------------------ SCanvasInitializeListener mSCanvasInitializeListener = new SCanvasInitializeListener() { @Override public void onInitialized() { // -------------------------------------------- // Start SCanvasView/CanvasView Task Here // -------------------------------------------- // Application Identifier Setting if (!mSCanvas.setAppID( APPLICATION_ID_NAME, APPLICATION_ID_VERSION_MAJOR, APPLICATION_ID_VERSION_MINOR, APPLICATION_ID_VERSION_PATCHNAME)) Toast.makeText(mContext, "Fail to set App ID.", Toast.LENGTH_LONG).show(); // Initial setting mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_ERASER); mSCanvas.setSettingViewStrokeInfo(mStrokeInfoScratch); mSCanvas.setStrokeLongClickSelectOption(false); // Set Pen Only Mode with Finger Control mSCanvas.setFingerControlPenDrawing(true); // Update button state updateModeState(); // Set BG setInitialBG(); Toast toast = Toast.makeText(mContext, "Scratch on the black board", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } }; // ------------------------------------------------ // History Change // ------------------------------------------------ HistoryUpdateListener mHistoryUpdateListener = new HistoryUpdateListener() { @Override public void onHistoryChanged(boolean undoable, boolean redoable) { mUndoBtn.setEnabled(undoable); mRedoBtn.setEnabled(redoable); } }; // Register Application Listener mSCanvas.setSCanvasInitializeListener(mSCanvasInitializeListener); mSCanvas.setHistoryUpdateListener(mHistoryUpdateListener); mUndoBtn.setEnabled(false); mRedoBtn.setEnabled(false); mPenBtn.setSelected(true); // create basic save/road file path File sdcard_path = Environment.getExternalStorageDirectory(); mFolder = new File(sdcard_path, DEFAULT_APP_IMAGEDATA_DIRECTORY); if (!mFolder.exists()) { if (!mFolder.mkdirs()) { Log.e(TAG, "Default Save Path Creation Error"); return; } } mScratchBoardFolderPath = mFolder.getAbsolutePath(); // Caution: // Do NOT load file or start animation here because we don't know canvas size here. // Start such SCanvasView Task at onInitialized() of SCanvasInitializeListener }