RectF getDefaultRect(String strImagePath) { // Rect Region : Consider image real size BitmapFactory.Options opts = SPenSDKUtils.getBitmapSize(strImagePath); int nImageWidth = opts.outWidth; int nImageHeight = opts.outHeight; int nScreenWidth = mSCanvas.getWidth(); int nScreenHeight = mSCanvas.getHeight(); int nBoxRadius = (nScreenWidth > nScreenHeight) ? nScreenHeight / 4 : nScreenWidth / 4; int nCenterX = nScreenWidth / 2; int nCenterY = nScreenHeight / 2; if (nImageWidth > nImageHeight) return new RectF( nCenterX - nBoxRadius, nCenterY - (nBoxRadius * nImageHeight / nImageWidth), nCenterX + nBoxRadius, nCenterY + (nBoxRadius * nImageHeight / nImageWidth)); else return new RectF( nCenterX - (nBoxRadius * nImageWidth / nImageHeight), nCenterY - nBoxRadius, nCenterX + (nBoxRadius * nImageWidth / nImageHeight), nCenterY + nBoxRadius); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.editor_settingview); mContext = this; // ------------------------------------ // UI Setting // ------------------------------------ mPenBtn = (ImageView) findViewById(R.id.penBtn); mPenBtn.setOnClickListener(mBtnClickListener); mPenBtn.setOnLongClickListener(mBtnLongClickListener); mEraserBtn = (ImageView) findViewById(R.id.eraseBtn); mEraserBtn.setOnClickListener(mBtnClickListener); mEraserBtn.setOnLongClickListener(mBtnLongClickListener); mTextBtn = (ImageView) findViewById(R.id.textBtn); mTextBtn.setOnClickListener(mBtnClickListener); mTextBtn.setOnLongClickListener(mBtnLongClickListener); mFillingBtn = (ImageView) findViewById(R.id.fillingBtn); mFillingBtn.setOnClickListener(mBtnClickListener); mFillingBtn.setOnLongClickListener(mBtnLongClickListener); mColorPickerBtn = (ImageView) findViewById(R.id.colorPickerBtn); mColorPickerBtn.setOnClickListener(mColorPickerListener); mUndoBtn = (ImageView) findViewById(R.id.undoBtn); mUndoBtn.setOnClickListener(undoNredoBtnClickListener); mRedoBtn = (ImageView) findViewById(R.id.redoBtn); mRedoBtn.setOnClickListener(undoNredoBtnClickListener); mSettingInfo = (TextView) findViewById(R.id.settingInfo); mColorSettingInfo = (ImageView) findViewById(R.id.colorsettingInfo); // ------------------------------------ // Create SCanvasView // ------------------------------------ mLayoutContainer = (FrameLayout) findViewById(R.id.layout_container); mCanvasContainer = (RelativeLayout) findViewById(R.id.canvas_container); mSCanvas = new SCanvasView(mContext); mCanvasContainer.addView(mSCanvas); // ------------------------------------ // SettingView Setting // ------------------------------------ // Resource Map for Layout & Locale HashMap<String, Integer> settingResourceMapInt = SPenSDKUtils.getSettingLayoutLocaleResourceMap(true, true, true, true); // Resource Map for Custom font path HashMap<String, String> settingResourceMapString = SPenSDKUtils.getSettingLayoutStringResourceMap(true, true, true, true); // Create Setting View mSCanvas.createSettingView(mLayoutContainer, settingResourceMapInt, settingResourceMapString); // ==================================================================================== // // Set Callback Listener(Interface) // // ==================================================================================== // ------------------------------------------------ // SCanvas Listener // ------------------------------------------------ mSCanvas.setSCanvasInitializeListener( 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(); // Set Title if (!mSCanvas.setTitle("SPen-SDK Test")) Toast.makeText(mContext, "Fail to set Title.", Toast.LENGTH_LONG).show(); // Update button state mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_PEN); mSCanvas.setSettingViewSizeOption( SCanvasConstants.SCANVAS_SETTINGVIEW_PEN, SCanvasConstants.SCANVAS_SETTINGVIEW_SIZE_EXT); mSCanvas.showSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_PEN, true); updateModeState(); } }); // ------------------------------------------------ // History Change Listener // ------------------------------------------------ mSCanvas.setHistoryUpdateListener( new HistoryUpdateListener() { @Override public void onHistoryChanged(boolean undoable, boolean redoable) { mUndoBtn.setEnabled(undoable); mRedoBtn.setEnabled(redoable); } }); // ------------------------------------------------ // SCanvas Mode Changed Listener // ------------------------------------------------ mSCanvas.setSCanvasModeChangedListener( new SCanvasModeChangedListener() { @Override public void onModeChanged(int mode) { updateModeState(); } }); // ------------------------------------------------ // Color Picker Listener // ------------------------------------------------ mSCanvas.setColorPickerColorChangeListener( new ColorPickerColorChangeListener() { @Override public void onColorPickerColorChanged(int nColor) { int nCurMode = mSCanvas.getCanvasMode(); if (nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_PEN) { SettingStrokeInfo strokeInfo = mSCanvas.getSettingViewStrokeInfo(); if (strokeInfo != null) { strokeInfo.setStrokeColor(nColor); mSCanvas.setSettingViewStrokeInfo(strokeInfo); } } else if (nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_ERASER) { // do nothing } else if (nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_TEXT) { SettingTextInfo textInfo = mSCanvas.getSettingViewTextInfo(); if (textInfo != null) { textInfo.setTextColor(nColor); mSCanvas.setSettingViewTextInfo(textInfo); } } else if (nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_FILLING) { SettingFillingInfo fillingInfo = mSCanvas.getSettingViewFillingInfo(); if (fillingInfo != null) { fillingInfo.setFillingColor(nColor); mSCanvas.setSettingViewFillingInfo(fillingInfo); } } } }); // ------------------------------------------------ // SettingView Show Listener : Optional // ------------------------------------------------ mSCanvas.setSettingViewShowListener( new SettingViewShowListener() { @Override public void onEraserSettingViewShow(boolean bVisible) { if (SHOW_LOG) { if (bVisible) Log.i(TAG, "Eraser setting view is shown"); else Log.i(TAG, "Eraser setting view is closed"); } } @Override public void onPenSettingViewShow(boolean bVisible) { if (SHOW_LOG) { if (bVisible) Log.i(TAG, "Pen setting view is shown"); else Log.i(TAG, "Pen setting view is closed"); } if (bVisible) { SettingStrokeInfo strokeInfo = mSCanvas.getSettingViewStrokeInfo(); if (strokeInfo != null) { updateColor(strokeInfo.getStrokeColor()); } } } @Override public void onTextSettingViewShow(boolean bVisible) { if (SHOW_LOG) { if (bVisible) Log.i(TAG, "Text setting view is shown"); else Log.i(TAG, "Text setting view is closed"); } if (bVisible) { SettingTextInfo textInfo = mSCanvas.getSettingViewTextInfo(); if (textInfo != null) { updateColor(textInfo.getTextColor()); } } } @Override public void onFillingSettingViewShow(boolean bVisible) { if (SHOW_LOG) { if (bVisible) Log.i(TAG, "Text setting view is shown"); else Log.i(TAG, "Text setting view is closed"); } if (bVisible) { SettingFillingInfo fillingInfo = mSCanvas.getSettingViewFillingInfo(); if (fillingInfo != null) { updateColor(fillingInfo.getFillingColor()); } } } }); // ------------------------------------------------ // SettingStrokeChangeListener Listener // ------------------------------------------------ mSCanvas.setSettingStrokeChangeListener( new SettingStrokeChangeListener() { @Override public void onClearAll(boolean bClearAllCompleted) { if (bClearAllCompleted) updateSetting("Clear All is completed"); } @Override public void onEraserWidthChanged(int eraserWidth) { updateSetting("Eraser width is changed : " + eraserWidth); } @Override public void onStrokeColorChanged(int strokeColor) { updateColor(strokeColor); } @Override public void onStrokeStyleChanged(int strokeStyle) { if (strokeStyle == SObjectStroke.SAMM_STROKE_STYLE_PENCIL) updateSetting("Stroke Style = Pen"); else if (strokeStyle == SObjectStroke.SAMM_STROKE_STYLE_BRUSH) updateSetting("Stroke Style = Brush"); else if (strokeStyle == SObjectStroke.SAMM_STROKE_STYLE_CHINESE_BRUSH) updateSetting("Stroke Style = Chinese Brush"); else if (strokeStyle == SObjectStroke.SAMM_STROKE_STYLE_CRAYON) updateSetting("Stroke Style = Pencil Crayon"); else if (strokeStyle == SObjectStroke.SAMM_STROKE_STYLE_MARKER) updateSetting("Stroke Style = Marker"); else if (strokeStyle == SObjectStroke.SAMM_STROKE_STYLE_ERASER) updateSetting("Stroke Style = Eraser"); } @Override public void onStrokeWidthChanged(int strokeWidth) { updateSetting("Stroke width is changed : " + strokeWidth); } @Override public void onStrokeAlphaChanged(int strokeAlpha) { updateSetting("Alpha is changed : " + strokeAlpha); } }); // ------------------------------------------------ // OnSettingTextChangeListener Listener // ------------------------------------------------ mSCanvas.setSettingTextChangeListener( new SettingTextChangeListener() { @Override public void onTextColorChanged(int textColor) { updateColor(textColor); } @Override public void onTextFontChanged(String fontName) { updateSetting("Font is changed : " + fontName); } @Override public void onTextSizeChanged(int textSize) { updateSetting("Text size is changed : " + textSize); } @Override public void onTextStyleChanged(int textStyle) { StringBuilder textStyleString = new StringBuilder(); boolean bDefault = (textStyle == SObjectText.SAMM_TEXT_STYLE_NONE); if (bDefault) textStyleString.append("Default "); boolean bBold = ((textStyle & SObjectText.SAMM_TEXT_STYLE_BOLD) != 0); if (bBold) textStyleString.append("Bold "); boolean bItalic = ((textStyle & SObjectText.SAMM_TEXT_STYLE_ITALIC) != 0); if (bItalic) textStyleString.append("Italic "); boolean bUnderline = ((textStyle & SObjectText.SAMM_TEXT_STYLE_UNDERLINE) != 0); if (bUnderline) textStyleString.append("Underline "); updateSetting("Text style is changed : " + textStyleString); } @Override public void onTextAlignmentChanged(int textHorizAlignment) { switch (textHorizAlignment) { case SAMMLibConstants.SAMM_ALIGN_NORMAL: updateSetting("Text alignment is changed as Left alignment"); break; case SAMMLibConstants.SAMM_ALIGN_CENTER: updateSetting("Text alignment is changed as Center alignment"); break; case SAMMLibConstants.SAMM_ALIGN_OPPOSITE: updateSetting("Text alignment is changed as Right alignment"); break; } } }); // ------------------------------------------------ // SettingFillingChangeListener Listener // ------------------------------------------------ mSCanvas.setSettingFillingChangeListener( new SettingFillingChangeListener() { @Override public void onFillingColorChanged(int fillingColor) { updateColor(fillingColor); } }); mUndoBtn.setEnabled(false); mRedoBtn.setEnabled(false); mPenBtn.setSelected(true); // 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 }
@Override public void onBackPressed() { SPenSDKUtils.alertActivityFinish(this, "Exit"); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.sdk_example_mini_edit); mContext = this; mSCanvas = (SCanvasView) findViewById(R.id.canvas_view); // Create Setting View RelativeLayout settingViewContainer = (RelativeLayout) findViewById(R.id.canvas_container); // ------------------------------------ // SettingView Setting // ------------------------------------ // Resource Map for Layout & Locale HashMap<String, Integer> settingResourceMapInt = SPenSDKUtils.getSettingLayoutLocaleResourceMap(true, true, false, false); // Resource Map for Custom font path HashMap<String, String> settingResourceMapString = SPenSDKUtils.getSettingLayoutStringResourceMap(true, true, false, false); // Create Setting View mSCanvas.createSettingView( settingViewContainer, settingResourceMapInt, settingResourceMapString); // ------------------------------------------------ // Set SCanvas Initialize Listener // ------------------------------------------------ mSCanvas.setSCanvasInitializeListener( new SCanvasInitializeListener() { @Override public void onInitialized() { // Set Background as bright yellow if (!mSCanvas.setBGColor(0xFFFFFFBB)) Toast.makeText(mContext, "Fail to set Background color.", Toast.LENGTH_LONG).show(); } }); // ------------------------------------------------ // History Change Listener // ------------------------------------------------ mSCanvas.setHistoryUpdateListener( new HistoryUpdateListener() { @Override public void onHistoryChanged(boolean undoable, boolean redoable) { mUndoBtn.setEnabled(undoable); mRedoBtn.setEnabled(redoable); } }); // ------------------------------------------------ // SCanvas Mode Changed Listener // ------------------------------------------------ mSCanvas.setSCanvasModeChangedListener( new SCanvasModeChangedListener() { @Override public void onModeChanged(int mode) { updateModeState(); } }); mPenBtn = (ImageView) findViewById(R.id.penSetting_btn); mEraserBtn = (ImageView) findViewById(R.id.eraserSetting_btn); mPenBtn.setOnClickListener(toolClickListener); mEraserBtn.setOnClickListener(toolClickListener); mPenBtn.setSelected(true); mUndoBtn = (ImageView) findViewById(R.id.undo_btn); mRedoBtn = (ImageView) findViewById(R.id.redo_btn); mUndoBtn.setOnClickListener(undoRedoClickListener); mRedoBtn.setOnClickListener(undoRedoClickListener); mUndoBtn.setEnabled(false); mRedoBtn.setEnabled(false); mDoneBtn = (Button) findViewById(R.id.done_btn); mCancelBtn = (Button) findViewById(R.id.cancel_btn); mDoneBtn.setOnClickListener(doneClickListener); mCancelBtn.setOnClickListener(doneClickListener); }
@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 }