private void setTabSelected(int position, boolean isSelected) {
   if (getChildCount() > 0 && mCurrentSelectedPos != position) {
     // 设置点击前一个的
     if (mCurrentSelectedPos != -1) {
       ImageView icon = mIcons.get(mCurrentSelectedPos);
       TextView titile = mTitles.get(mCurrentSelectedPos);
       if (icon != null) {
         icon.setSelected(false);
       }
       if (titile != null) {
         titile.setTextColor(unSelectedTextColor);
       }
     }
     // 设置点击后的
     ImageView icon = mIcons.get(position);
     TextView titile = mTitles.get(position);
     if (icon != null) {
       icon.setSelected(isSelected);
     }
     if (titile != null) {
       titile.setTextColor(isSelected ? SelectedTextColor : unSelectedTextColor);
     }
     mViewPage.setCurrentItem(position, false);
     mCurrentSelectedPos = position;
   }
 }
Example #2
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
      LayoutInflater vi =
          (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      v = vi.inflate(mListItemLayoutId, null);
    }

    ImageView image = (ImageView) v.findViewById(R.id.icon);
    TextView text = (TextView) v.findViewById(R.id.text1);

    RWListItem q = getItem(position);
    if (q != null) {
      if (text != null) {
        text.setText(q.getText());
      }
    }

    if (q.isOn()) {
      image.setSelected(true);
      text.setSelected(true);
    } else {
      image.setSelected(false);
      text.setSelected(false);
    }

    return v;
  }
  private void setTabSelectState() {
    switch (tabIndex) {
      case 0:
        title.setText("下拉刷新");
        txt1.setSelected(true);
        txt2.setSelected(false);
        txt3.setSelected(false);

        img1.setSelected(true);
        img2.setSelected(false);
        img3.setSelected(false);
        break;
      case 1:
        title.setText("双列下拉刷新");
        txt1.setSelected(false);
        txt2.setSelected(true);
        txt3.setSelected(false);

        img1.setSelected(false);
        img2.setSelected(true);
        img3.setSelected(false);
        break;
      case 2:
        title.setText("瀑布流下拉刷新");
        txt1.setSelected(false);
        txt2.setSelected(false);
        txt3.setSelected(true);

        img1.setSelected(false);
        img2.setSelected(false);
        img3.setSelected(true);
        break;
    }
  }
  // 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());
  }
  @Override
  public void onClick(View v) {
    int id = v.getId();
    resetSelection();

    if (id == R.id.history) {
      changeCurrentFragment(FragmentsAvailable.HISTORY, null);
      history.setSelected(true);
      LinphoneManager.getLc().resetMissedCallsCount();
      displayMissedCalls(0);
    } else if (id == R.id.contacts) {
      changeCurrentFragment(FragmentsAvailable.CONTACTS, null);
      contacts.setSelected(true);
    } else if (id == R.id.dialer) {
      changeCurrentFragment(FragmentsAvailable.DIALER, null);
      dialer.setSelected(true);
    } else if (id == R.id.settings) {
      changeCurrentFragment(FragmentsAvailable.SETTINGS, null);
      settings.setSelected(true);
    } else if (id == R.id.about_chat) {
      Bundle b = new Bundle();
      b.putSerializable("About", FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT);
      changeCurrentFragment(FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT, b);
      aboutChat.setSelected(true);
    } else if (id == R.id.about_settings) {
      Bundle b = new Bundle();
      b.putSerializable("About", FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS);
      changeCurrentFragment(FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS, b);
      aboutSettings.setSelected(true);
    } else if (id == R.id.chat) {
      changeCurrentFragment(FragmentsAvailable.CHATLIST, null);
      chat.setSelected(true);
    }
  }
  @SuppressWarnings("incomplete-switch")
  public void selectMenu(FragmentsAvailable menuToSelect) {
    currentFragment = menuToSelect;
    resetSelection();

    switch (menuToSelect) {
      case HISTORY:
      case HISTORY_DETAIL:
        history.setSelected(true);
        break;
      case CONTACTS:
      case CONTACT:
      case EDIT_CONTACT:
        contacts.setSelected(true);
        break;
      case DIALER:
        dialer.setSelected(true);
        break;
      case SETTINGS:
      case ACCOUNT_SETTINGS:
        settings.setSelected(true);
        break;
      case ABOUT_INSTEAD_OF_CHAT:
        aboutChat.setSelected(true);
        break;
      case ABOUT_INSTEAD_OF_SETTINGS:
        aboutSettings.setSelected(true);
        break;
      case CHATLIST:
      case CHAT:
        chat.setSelected(true);
        break;
    }
  }
Example #7
0
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Test {@link ImageView#setSelected(boolean)}",
        method = "setSelected",
        args = {boolean.class}
    )
    public void testSetSelected() {
        mImageView = new ImageView(mActivity);
        assertFalse(mImageView.isSelected());

        mImageView.setSelected(true);
        assertTrue(mImageView.isSelected());

        mImageView.setSelected(false);
        assertFalse(mImageView.isSelected());
    }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    int type = getItemViewType(position);
    if (convertView == null) {
      if (type == 0) {
        convertView = mInflater.inflate(R.layout.item_op, null);
      } else if (type == MediaEntity.IMAGE) {
        convertView = mInflater.inflate(R.layout.item_grid, null);
      } else if (type == MediaEntity.AUDIO) {
        convertView = mInflater.inflate(R.layout.item_grid, null);
      } else if (type == MediaEntity.VIDEO) {
        convertView = mInflater.inflate(R.layout.item_grid_video, null);
      } else {
        throw new IllegalArgumentException("no this kind of viewType");
      }
    }

    int folderType = mDataFolder.getType();
    if (position == 0) {
      ImageView img = (ImageView) convertView;
      if (folderType == MediaEntity.IMAGE) {
        img.setImageResource(R.mipmap.img_op_camera);
        img.setOnClickListener(v -> mActivity.toTakePhoto());
      } else if (type == MediaEntity.VIDEO) {
        img.setImageResource(R.mipmap.img_op_video);
        img.setOnClickListener(v -> mActivity.toMakeVideo());
      }
    } else {
      ImageView imgCover = (ImageView) convertView.findViewById(R.id.img);
      ImageView imgCheck = (ImageView) convertView.findViewById(R.id.img_check_box);
      int realPosition = position - 1;
      MediaEntity en = mDada.get(realPosition);
      imgCheck.setSelected(mediaManager.isSelected(en));
      imgCheck.setOnClickListener(v1 -> mediaManager.toggle(en));

      Glide.with(mActivity).load(en.getPath()).crossFade().into(imgCover);
      if (type == MediaEntity.IMAGE) {
        imgCover.setOnClickListener(
            v -> {
              if (mOnMediaClickListener == null) {
                ActivityImageShower.startActivity(mActivity, mDataFolder, realPosition);
              } else {
                mOnMediaClickListener.onMediaClick(en, realPosition);
              }
            });
      } else if (type == MediaEntity.VIDEO) {
        TextView txtTime = (TextView) convertView.findViewById(R.id.txt_time);
        txtTime.setText(getSecond(en.getDuration()));
        imgCover.setOnClickListener(
            v -> {
              if (mOnMediaClickListener == null) {
                ActivityVideoShower.startActivity(mActivity, en);
              } else {
                mOnMediaClickListener.onMediaClick(en, realPosition);
              }
            });
      }
    }
    return convertView;
  }
 @Override
 public void onFilterChanged(int filterType, int position) {
   // TODO Auto-generated method stub
   int Type = filterInfos.get(position).getFilterType(); // 获取类型
   FilterLayoutUtils.this.position = position;
   mMagicDisplay.setFilter(filterType);
   if (position != 0) btn_Favourite.setVisibility(View.VISIBLE);
   else btn_Favourite.setVisibility(View.INVISIBLE);
   btn_Favourite.setSelected(filterInfos.get(position).isFavourite());
   if (position <= favouriteFilterInfos.size()) { // 点击Favourite列表
     for (int i = favouriteFilterInfos.size() + 2; i < filterInfos.size(); i++) {
       if (filterInfos.get(i).getFilterType() == Type) {
         filterInfos.get(i).setSelected(true);
         mAdapter.setLastSelected(i);
         FilterLayoutUtils.this.position = i;
         mAdapter.notifyItemChanged(i);
       } else if (filterInfos.get(i).isSelected()) {
         filterInfos.get(i).setSelected(false);
         mAdapter.notifyItemChanged(i);
       }
     }
   }
   for (int i = 1; i < favouriteFilterInfos.size() + 1; i++) {
     if (filterInfos.get(i).getFilterType() == Type) {
       filterInfos.get(i).setSelected(true);
       mAdapter.notifyItemChanged(i);
     } else if (filterInfos.get(i).isSelected()) {
       filterInfos.get(i).setSelected(false);
       mAdapter.notifyItemChanged(i);
     }
   }
 }
 @Override
 public void onReceive(Context context, Intent intent) {
   // Get extra data included in the Intent
   String message = intent.getAction();
   //            Log.d(TAG, message.equals(Constants.ACTION_SHOW_PAUSE)+" Got message: " +
   // message);
   playPause.setSelected(message.equals(Constants.ACTION_SHOW_PAUSE));
 }
 @Override
 public void onClick(View v) {
   if (v.equals(mColorPickerBtn)) {
     // Toggle
     boolean bIsColorPickerMode = !mSCanvas.isColorPickerMode();
     mSCanvas.setColorPickerMode(bIsColorPickerMode);
     mColorPickerBtn.setSelected(bIsColorPickerMode);
   }
 }
 private void resetSelection() {
   history.setSelected(false);
   contacts.setSelected(false);
   dialer.setSelected(false);
   settings.setSelected(false);
   chat.setSelected(false);
   aboutChat.setSelected(false);
   aboutSettings.setSelected(false);
 }
        @Override
        public void onClick(View v) {
          if (position != 0 && filterInfos.get(position).getFilterType() != -1) {
            int Type = filterInfos.get(position).getFilterType(); // 获取类型
            if (filterInfos.get(position).isFavourite()) {
              // 取消Favourite------------------------------------
              btn_Favourite.setSelected(false);
              filterInfos.get(position).setFavourite(false);
              mAdapter.notifyItemChanged(position);
              int i = 0;
              for (i = 0; i < favouriteFilterInfos.size(); i++) {
                if (Type == favouriteFilterInfos.get(i).getFilterType()) { // 取消对应Favourite列表中元素
                  favouriteFilterInfos.remove(i);
                  filterInfos.remove(i + 1); // 从filterInfos去除
                  mAdapter.notifyItemRemoved(i + 1);
                  mAdapter.setLastSelected(mAdapter.getLastSelected() - 1);
                  break;
                }
              }
              position--;
              mAdapter.notifyItemRangeChanged(i + 1, filterInfos.size() - i - 1);
            } else { // 增加favourite
              btn_Favourite.setSelected(true); // 更改状态
              filterInfos.get(position).setFavourite(true);
              mAdapter.notifyItemChanged(position);

              FilterInfo filterInfo = new FilterInfo();
              filterInfo.setFilterType(Type);
              filterInfo.setSelected(true);
              filterInfo.setFavourite(true);
              filterInfos.add(favouriteFilterInfos.size() + 1, filterInfo);
              position++;
              mAdapter.notifyItemInserted(favouriteFilterInfos.size() + 1);
              mAdapter.notifyItemRangeChanged(
                  favouriteFilterInfos.size() + 1,
                  filterInfos.size() - favouriteFilterInfos.size() - 1);
              favouriteFilterInfos.add(filterInfo);
              mAdapter.setLastSelected(mAdapter.getLastSelected() + 1);
            }
            saveFavourite();
          }
        }
Example #14
0
  /** 点击了“更多”按钮 */
  public static void clickMoreBtn() {
    // 实例化Fragment页面
    fragmentPage4 = new FragmentPage4();
    // 得到Fragment事务管理器
    FragmentTransaction fragmentTransaction = act.getSupportFragmentManager().beginTransaction();
    // 替换当前的页面
    fragmentTransaction.replace(R.id.frame_content, fragmentPage4);
    // 事务管理提交
    fragmentTransaction.commit();

    friendfeedFl.setSelected(false);
    friendfeedIv.setSelected(false);

    myfeedFl.setSelected(false);
    myfeedIv.setSelected(false);

    homeFl.setSelected(false);
    homeIv.setSelected(false);

    moreFl.setSelected(true);
    moreIv.setSelected(true);
  }
 private void addIconTab(final int position, int resId) {
   ImageView tab = new ImageView(getContext());
   tab.setFocusable(true);
   tab.setImageResource(resId);
   tab.setScaleType(ImageView.ScaleType.CENTER);
   tab.setOnClickListener(
       new OnClickListener() {
         @Override
         public void onClick(View v) {
           pager.setCurrentItem(position);
         }
       });
   tabsContainer.addView(tab);
   tab.setSelected(position == currentPosition);
 }
 private void selectButtons(int selected) {
   shareEmail.setSelected(false);
   shareTw.setSelected(false);
   shareVk.setSelected(false);
   shareFb.setSelected(false);
   switch (selected) {
     case Share.FACEBOOK:
       shareFb.setSelected(true);
       break;
     case Share.VK:
       shareVk.setSelected(true);
       break;
     case Share.TWITTER:
       shareTw.setSelected(true);
       break;
     case Share.EMAIL:
       shareEmail.setSelected(true);
       break;
   }
 }
Example #17
0
  @Click(R.id.actionbar_more)
  void moreClicked() {
    mActionbarMore.setSelected(true);
    LinearLayout moreContentView =
        (LinearLayout) mInflater.inflate(R.layout.main_more_content, null);

    moreContentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    final PopupWindow popupWindow = new PopupWindow(this);
    popupWindow.setBackgroundDrawable(
        new ColorDrawable(getResources().getColor(R.color.red_dark_washedout)));
    popupWindow.setContentView(moreContentView);
    popupWindow.showAsDropDown(mActionbarMore);
    popupWindow.setTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setOnDismissListener(
        new OnDismissListener() {
          public void onDismiss() {
            mActionbarMore.setSelected(false);
          }
        });

    Button settingsButton = (Button) moreContentView.findViewById(R.id.main_more_content_settings);
    settingsButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, SettingsActivity.class));
            popupWindow.dismiss();
          }
        });

    Button aboutButton = (Button) moreContentView.findViewById(R.id.main_more_content_about);
    aboutButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, AboutActivity_.class));
            popupWindow.dismiss();
          }
        });

    popupWindow.update(moreContentView.getMeasuredWidth(), moreContentView.getMeasuredHeight());
  }
  @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
  }
Example #19
0
 /**
  * 对应被选中的点的图片
  *
  * @param index
  */
 private void dian_select(int index) {
   ImageView img = (ImageView) mView.findViewById(mPointIds[index]);
   img.setSelected(true);
 }
Example #20
0
 /**
  * 对应未被选中的点的图片
  *
  * @param id
  */
 private void dian_unselect(int id) {
   ImageView img = (ImageView) mView.findViewById(mPointIds[id]);
   img.setSelected(false);
 }
  @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);
  }
 private void updateModeState() {
   int nCurMode = mSCanvas.getCanvasMode();
   mPenBtn.setSelected(nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
   mEraserBtn.setSelected(nCurMode == SCanvasConstants.SCANVAS_MODE_INPUT_ERASER);
 }
Example #23
0
 private void changeUIshow(StarType type) {
   if (lastStarType == type) {
     return;
   }
   lastStarType = type;
   switch (type) {
     case star0:
       ivStar1.setSelected(false);
       ivStar2.setSelected(false);
       ivStar3.setSelected(false);
       ivStar4.setSelected(false);
       ivStar5.setSelected(false);
       break;
     case star1:
       ivStar1.setSelected(true);
       ivStar2.setSelected(false);
       ivStar3.setSelected(false);
       ivStar4.setSelected(false);
       ivStar5.setSelected(false);
       break;
     case star2:
       ivStar1.setSelected(true);
       ivStar2.setSelected(true);
       ivStar3.setSelected(false);
       ivStar4.setSelected(false);
       ivStar5.setSelected(false);
       break;
     case star3:
       ivStar1.setSelected(true);
       ivStar2.setSelected(true);
       ivStar3.setSelected(true);
       ivStar4.setSelected(false);
       ivStar5.setSelected(false);
       break;
     case star4:
       ivStar1.setSelected(true);
       ivStar2.setSelected(true);
       ivStar3.setSelected(true);
       ivStar4.setSelected(true);
       ivStar5.setSelected(false);
       break;
     case star5:
       ivStar1.setSelected(true);
       ivStar2.setSelected(true);
       ivStar3.setSelected(true);
       ivStar4.setSelected(true);
       ivStar5.setSelected(true);
       break;
   }
 }
  /** Create a default view to be used for tabs. */
  private View createDefaultTabView(int position) {
    final PagerAdapter adapter = mViewPager.getAdapter();
    View view;

    switch (mTabMode) {
      case TITLE_ONLY:
        {
          TextView textView = new TextView(getContext());
          textView.setGravity(Gravity.CENTER);
          textView.setText(adapter.getPageTitle(position));
          textView.setTextColor(mTabColorize.getDefaultTabColor(position));
          textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
          textView.setTypeface(null, mTextStyle);
          textView.setLayoutParams(
              new ViewGroup.LayoutParams(
                  ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));

          if (mTabBackground != NO_ID) {
            textView.setBackgroundResource(mTabBackground);
          } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            TypedValue outValue = new TypedValue();
            getContext()
                .getTheme()
                .resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
            textView.setBackgroundResource(outValue.resourceId);
          }

          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            textView.setAllCaps(mTextAllCaps);
          }

          textView.setPadding(mTabPaddingLeft, mTabPaddingTop, mTabPaddingRight, mTabPaddingBottom);

          if (position == mViewPager.getCurrentItem()) {
            textView.setTextColor(mTabColorize.getSelectedTabColor(position));
            textView.setSelected(true);
          }

          view = textView;
          break;
        }
      case ICON_ONLY:
        {
          ImageView imageView = new ImageView(getContext());
          imageView.setScaleType(ImageView.ScaleType.CENTER);
          imageView.setLayoutParams(
              new ViewGroup.LayoutParams(
                  ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));

          if (mTabBackground != NO_ID) {
            imageView.setBackgroundResource(mTabBackground);
          } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            TypedValue outValue = new TypedValue();
            getContext()
                .getTheme()
                .resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
            imageView.setBackgroundResource(outValue.resourceId);
          }

          //                Drawable drawable = ContextCompat.getDrawable(getContext(),
          // ((IconTabProvider) adapter).getPageIconResId(position)).mutate();
          Drawable drawable =
              ContextCompat.getDrawable(
                  getContext(), ((IconTabProvider) adapter).getPageIconResId(position));

          if (mIconCrossFade && drawable instanceof StateListDrawable) {
            try {
              StateListDrawable stateListDrawable = (StateListDrawable) drawable;
              int fadingIndex =
                  StateListDrawableHelper.getStateDrawableIndex(
                      stateListDrawable, new int[] {android.R.attr.state_selected});
              Drawable fading =
                  StateListDrawableHelper.getStateDrawable(stateListDrawable, fadingIndex);
              int baseIndex =
                  StateListDrawableHelper.getStateDrawableIndex(stateListDrawable, new int[] {0});
              Drawable base =
                  StateListDrawableHelper.getStateDrawable(stateListDrawable, baseIndex);
              CrossFadeDrawable cd = new CrossFadeDrawable();
              cd.setFading(fading);
              //                        tintDrawable(cd.getFading().mutate(),
              // mTabColorize.getSelectedTabColor(position));
              tintDrawable(cd.getFading(), mTabColorize.getSelectedTabColor(position));
              cd.setBase(base);
              //                        tintDrawable(cd.getBase().mutate(),
              // mTabColorize.getDefaultTabColor(position));
              tintDrawable(cd.getBase(), mTabColorize.getDefaultTabColor(position));
              imageView.setImageDrawable(cd);
            } catch (Exception e) {
              imageView.setImageDrawable(drawable);
            }
          } else {
            imageView.setImageDrawable(drawable);
          }

          imageView.setPadding(
              mTabPaddingLeft, mTabPaddingTop, mTabPaddingRight, mTabPaddingBottom);

          if (position == mViewPager.getCurrentItem()) {
            Drawable d = imageView.getDrawable();
            if (d instanceof CrossFadeDrawable) {
              crossFadeDrawable(d, 1);
            } else {
              tintDrawable(d, mTabColorize.getSelectedTabColor(position));
            }
            imageView.setSelected(true);
          } else {
            tintDrawable(imageView.getDrawable(), mTabColorize.getDefaultTabColor(position));
          }

          view = imageView;
          break;
        }
      case BOTH:
        {
          TextView textView = new TextView(getContext());
          textView.setGravity(Gravity.CENTER);
          textView.setText(adapter.getPageTitle(position));
          textView.setTextColor(mTabColorize.getDefaultTabColor(position));
          textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
          textView.setTypeface(null, mTextStyle);
          textView.setLayoutParams(
              new ViewGroup.LayoutParams(
                  ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));

          if (mTabBackground != NO_ID) {
            textView.setBackgroundResource(mTabBackground);
          } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            TypedValue outValue = new TypedValue();
            getContext()
                .getTheme()
                .resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
            textView.setBackgroundResource(outValue.resourceId);
          }

          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            textView.setAllCaps(mTextAllCaps);
          }

          textView.setPadding(mTabPaddingLeft, mTabPaddingTop, mTabPaddingRight, mTabPaddingBottom);

          //                Drawable drawable = ContextCompat.getDrawable(getContext(),
          // ((IconTabProvider) adapter).getPageIconResId(position)).mutate();
          Drawable drawable =
              ContextCompat.getDrawable(
                  getContext(), ((IconTabProvider) adapter).getPageIconResId(position));

          if (mIconCrossFade && drawable instanceof StateListDrawable) {
            try {
              StateListDrawable stateListDrawable = (StateListDrawable) drawable;
              int fadingIndex =
                  StateListDrawableHelper.getStateDrawableIndex(
                      stateListDrawable, new int[] {android.R.attr.state_selected});
              Drawable fading =
                  StateListDrawableHelper.getStateDrawable(stateListDrawable, fadingIndex);
              int baseIndex =
                  StateListDrawableHelper.getStateDrawableIndex(stateListDrawable, new int[] {0});
              Drawable base =
                  StateListDrawableHelper.getStateDrawable(stateListDrawable, baseIndex);
              CrossFadeDrawable cd = new CrossFadeDrawable();
              cd.setFading(fading);
              cd.setFading(fading);
              //                        tintDrawable(cd.getFading().mutate(),
              // mTabColorize.getSelectedTabColor(position));
              tintDrawable(cd.getFading(), mTabColorize.getSelectedTabColor(position));
              cd.setBase(base);
              //                        tintDrawable(cd.getBase().mutate(),
              // mTabColorize.getDefaultTabColor(position));
              tintDrawable(cd.getBase(), mTabColorize.getDefaultTabColor(position));
              textView.setCompoundDrawablesWithIntrinsicBounds(null, cd, null, null);
            } catch (Exception e) {
              textView.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
            }
          } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
          }

          textView.setCompoundDrawablePadding(mDrawablePadding);

          if (position == mViewPager.getCurrentItem()) {
            textView.setTextColor(mTabColorize.getSelectedTabColor(position));

            Drawable d = textView.getCompoundDrawables()[1];
            if (d instanceof CrossFadeDrawable) {
              crossFadeDrawable(d, 1);
            } else {
              tintDrawable(d, mTabColorize.getSelectedTabColor(position));
            }
            textView.setSelected(true);
          } else {
            Drawable d = textView.getCompoundDrawables()[1];
            if (!(d instanceof CrossFadeDrawable)) {
              tintDrawable(d, mTabColorize.getDefaultTabColor(position));
            }
          }

          view = textView;
          break;
        }
      default:
        {
          throw new IllegalStateException("Invalid tab mode: " + mTabMode);
        }
    }

    return view;
  }
  @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
  }