@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);

    switch (item.getItemId()) {
      case MENU_BG1:
        {
          // set BG Image
          Bitmap bg = BitmapFactory.decodeResource(getResources(), R.drawable.gradient_color1);
          if (bg != null) mSCanvas.setBackgroundImage(bg);
        }
        break;
      case MENU_BG2:
        {
          // set BG Image
          Bitmap bg = BitmapFactory.decodeResource(getResources(), R.drawable.gradient_color2);
          if (bg != null) mSCanvas.setBackgroundImage(bg);
        }
        break;
      case MENU_BG3:
        {
          // set BG Image
          Bitmap bg = BitmapFactory.decodeResource(getResources(), R.drawable.gradient_color3);
          if (bg != null) mSCanvas.setBackgroundImage(bg);
        }
        break;
      case MENU_CLEARALL:
        {
          mSCanvas.clearScreen();
        }
        break;
    }
    return true;
  }
  boolean loadSAMMFile(String strFileName) {
    if (mSCanvas.isAnimationMode()) {
      // It must be not animation mode.
    } else {
      // canvas option setting
      SOptionSCanvas canvasOption = mSCanvas.getOption();
      if (canvasOption == null) return false;
      canvasOption.mSAMMOption.setConvertCanvasSizeOption(
          PreferencesOfSAMMOption.getPreferenceLoadCanvasSize(mContext));
      canvasOption.mSAMMOption.setConvertCanvasHorizontalAlignOption(
          PreferencesOfSAMMOption.getPreferenceLoadCanvasHAlign(mContext));
      canvasOption.mSAMMOption.setConvertCanvasVerticalAlignOption(
          PreferencesOfSAMMOption.getPreferenceLoadCanvasVAlign(mContext));
      canvasOption.mSAMMOption.setDecodePriorityFGData(
          PreferencesOfSAMMOption.getPreferenceDecodePriorityFGData(mContext));
      // option setting
      mSCanvas.setOption(canvasOption);

      // show progress for loading data
      if (mSCanvas.loadSAMMFile(strFileName, true, false, false)) {
        // Loading Result can be get by callback function
      } else {
        Toast.makeText(this, "Load AMS File(" + strFileName + ") Fail!", Toast.LENGTH_LONG).show();
        return false;
      }
    }
    return true;
  }
 @Override
 public void onClick(View v) {
   if (v.equals(mUndoBtn)) {
     mSCanvas.undo();
   } else if (v.equals(mRedoBtn)) {
     mSCanvas.redo();
   }
 }
 @Override
 public void onClick(View v) {
   if (v.equals(mColorPickerBtn)) {
     // Toggle
     boolean bIsColorPickerMode = !mSCanvas.isColorPickerMode();
     mSCanvas.setColorPickerMode(bIsColorPickerMode);
     mColorPickerBtn.setSelected(bIsColorPickerMode);
   }
 }
 @Override
 public void onClick(View v) {
   if (v.equals(mUndoBtn)) {
     mSCanvas.undo();
   } else if (v.equals(mRedoBtn)) {
     mSCanvas.redo();
   }
   mUndoBtn.setEnabled(mSCanvas.isUndoable());
   mRedoBtn.setEnabled(mSCanvas.isRedoable());
 }
  // Update tool button
  private void updateModeState() {
    int nCurMode = mSCanvas.getCanvasMode();
    mPenBtn.setSelected(nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
    mEraserBtn.setSelected(nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_ERASER);
    mTextBtn.setSelected(nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_TEXT);
    mFillingBtn.setSelected(nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_FILLING);

    // Reset color picker tool when Eraser Mode
    if (nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_ERASER) mSCanvas.setColorPickerMode(false);
    mColorPickerBtn.setEnabled(nCurMode != SCanvasConstants.SCANVAS_MODE_INPUT_ERASER);
    mColorPickerBtn.setSelected(mSCanvas.isColorPickerMode());
  }
  private void setInitialBG() {
    // set BG Image
    Bitmap bg = BitmapFactory.decodeResource(getResources(), R.drawable.gradient_color1);
    if (bg == null) return;
    mSCanvas.setBackgroundImage(bg);

    // set FG as Black
    int[] nColors = new int[1];
    nColors[0] = 0xff000000; // black
    Bitmap fg = Bitmap.createBitmap(nColors, 1, 1, Bitmap.Config.ARGB_8888);
    if (fg == null) return;
    mSCanvas.setClearImageBitmap(
        fg, SPenImageFilterConstants.FILTER_ORIGINAL, SPenImageFilterConstants.FILTER_LEVEL_MEDIUM);
  }
 @Override
 public void onClick(View v) {
   int nBtnID = v.getId();
   // If the mode is not changed, open the setting view. If the mode is same, close the
   // setting view.
   if (nBtnID == mPenBtn.getId()) {
     mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_ERASER);
     mSCanvas.setSettingViewStrokeInfo(mStrokeInfoScratch);
     updateModeState();
   } else if (nBtnID == mEraserBtn.getId()) {
     mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
     mSCanvas.setSettingViewStrokeInfo(mStrokeInfoEraser);
     updateModeState();
   }
 }
Exemple #9
0
  /**
   * Start activity for hidden folder
   *
   * @param context - {@link Context}
   * @param resultCode - result code
   */
  public static void startShowHiddenFolder(Context context, int resultCode) {

    if (SCanvasView.isSignatureExist(context)) {
      Intent intent = new Intent(context, HiddenFolderActivity.class);
      ((Activity) context).startActivityForResult(intent, resultCode);
    } else {
      startSignatureRegistrationActivity(context);
    }
  }
Exemple #10
0
  /**
   * Signature verification
   *
   * @param context - {@link Context}
   * @param resultCode - result code
   */
  public static void signatureVerification(Context context, int resultCode) {

    if (!SDrawLibrary.isSupportedModel()) {
      sToastS(context, context.getResources().getString(R.string.not_support_this_feature));
      return;
    }
    if (SCanvasView.isSignatureExist(context)) {
      Intent intent = new Intent(context, PhotoDeskSignatureVerification.class);
      ((Activity) context).startActivityForResult(intent, resultCode);
    } else {
      sToastS(context, context.getResources().getString(R.string.signature_start_check_failure));
    }
  }
 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);
 }
  private boolean saveSAMMFile() {
    String savePath =
        mFolder.getPath()
            + '/'
            + ExampleUtils.getUniqueFilename(mFolder, APPLICATION_ID_NAME, SAVED_FILE_EXTENSION);
    Log.d(TAG, "Save Path = " + savePath);

    // canvas option setting
    SOptionSCanvas canvasOption = mSCanvas.getOption();
    if (canvasOption == null) return false;
    canvasOption.mSAMMOption.setSaveImageSize(SOptionSAMM.SAMM_SAVE_OPTION_ORIGINAL_SIZE);
    mSCanvas.setOption(canvasOption);
    if (mSCanvas.saveSAMMFile(savePath)) {
      Toast.makeText(
              mContext,
              APPLICATION_ID_NAME + " is saved as \"" + savePath + "\"",
              Toast.LENGTH_LONG)
          .show();
      return true;
    } else {
      Toast.makeText(mContext, "Fail to save : \"" + savePath + "\"", Toast.LENGTH_LONG).show();
      return false;
    }
  }
  private File saveCanvasImage() {
    byte[] imgData = mSCanvas.getSCanvasBitmapData();
    if (imgData == null) return null;

    String fileName = "tempImg.jpg";
    OutputStream out = null;
    try {
      File imgFile = new File(getFilesDir(), fileName);
      out = openFileOutput(imgFile.getName(), MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);
      out.write(imgData);
      return imgFile;
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    } finally {
      try {
        if (out != null) out.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
        @Override
        public void onClick(View v) {

          int nBtnID = v.getId();
          // If the mode is not changed, open the setting view. If the mode is same, close the
          // setting view.
          if (nBtnID == mPenBtn.getId()) {
            if (mSCanvas.getCanvasMode() == SCanvasConstants.SCANVAS_MODE_INPUT_PEN) {
              mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_PEN);
            } else {
              mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
              mSCanvas.showSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_PEN, false);
              updateModeState();
            }
          } else if (nBtnID == mEraserBtn.getId()) {
            if (mSCanvas.getCanvasMode() == SCanvasConstants.SCANVAS_MODE_INPUT_ERASER) {
              mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER);
            } else {
              mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_ERASER);
              mSCanvas.showSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER, false);
              updateModeState();
            }
          }
        }
        @Override
        public boolean onLongClick(View v) {

          int nBtnID = v.getId();
          // If the mode is not changed, open the setting view. If the mode is same, close the
          // setting view.
          if (nBtnID == mPenBtn.getId()) {
            mSCanvas.setSettingViewSizeOption(
                SCanvasConstants.SCANVAS_SETTINGVIEW_PEN,
                SCanvasConstants.SCANVAS_SETTINGVIEW_SIZE_MINI);
            if (mSCanvas.getCanvasMode() == SCanvasConstants.SCANVAS_MODE_INPUT_PEN) {
              mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_PEN);
            } else {
              mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
              mSCanvas.showSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_PEN, true);
              updateModeState();
            }
            return true;
          } else if (nBtnID == mEraserBtn.getId()) {
            mSCanvas.setSettingViewSizeOption(
                SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER,
                SCanvasConstants.SCANVAS_SETTINGVIEW_SIZE_MINI);
            if (mSCanvas.getCanvasMode() == SCanvasConstants.SCANVAS_MODE_INPUT_ERASER) {
              mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER);
            } else {
              mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_ERASER);
              mSCanvas.showSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER, true);
              updateModeState();
            }
            return true;
          } else if (nBtnID == mTextBtn.getId()) {
            mSCanvas.setSettingViewSizeOption(
                SCanvasConstants.SCANVAS_SETTINGVIEW_TEXT,
                SCanvasConstants.SCANVAS_SETTINGVIEW_SIZE_MINI);
            if (mSCanvas.getCanvasMode() == SCanvasConstants.SCANVAS_MODE_INPUT_TEXT) {
              mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_TEXT);
            } else {
              mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_TEXT);
              mSCanvas.showSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_TEXT, true);
              updateModeState();
              Toast.makeText(mContext, "Tap Canvas to insert Text", Toast.LENGTH_SHORT).show();
            }
            return true;
          } else if (nBtnID == mFillingBtn.getId()) {
            mSCanvas.setSettingViewSizeOption(
                SCanvasConstants.SCANVAS_SETTINGVIEW_FILLING,
                SCanvasConstants.SCANVAS_SETTINGVIEW_SIZE_MINI);
            if (mSCanvas.getCanvasMode() == SCanvasConstants.SCANVAS_MODE_INPUT_FILLING) {
              mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_FILLING);
            } else {
              mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_FILLING);
              mSCanvas.showSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_FILLING, true);
              updateModeState();
              Toast.makeText(mContext, "Tap Canvas to fill color", Toast.LENGTH_SHORT).show();
            }
            return true;
          }

          return false;
        }
 @Override
 protected void onDestroy() {
   super.onDestroy();
   // Release SCanvasView resources
   if (!mSCanvas.closeSCanvasView()) Log.e(TAG, "Fail to close SCanvasView");
 }
  @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
  }
  @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
  }
 private void updateModeState() {
   int nCurMode = mSCanvas.getCanvasMode();
   mPenBtn.setSelected(nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
   mEraserBtn.setSelected(nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_ERASER);
 }