/**
   * 判断是否已存
   *
   * @param key
   * @return
   */
  public boolean isContain(String key) {
    if (StringUtil.isNotEmpty(key, true) == false) {
      Log.e(TAG, "isContain StringUtil.isNotEmpty(key, true) == false >> return false;");
      return false;
    }

    return sp.contains(StringUtil.getTrimedString(key));
  }
  /**
   * 保存
   *
   * @param key
   * @param value
   */
  public void save(String key, T value) {
    if (StringUtil.isNotEmpty(key, true) == false || value == null) {
      Log.e(TAG, "save StringUtil.isNotEmpty(key, true) == false || value == null >> return;");
      return;
    }
    key = StringUtil.getTrimedString(key);

    sp.edit().remove(key).putString(key, Json.toJSONString(value)).commit();
  }
  /**
   * 获取
   *
   * @param key
   * @return
   */
  public T get(String key) {
    if (StringUtil.isNotEmpty(key, true) == false) {
      Log.e(
          TAG,
          "get (sp == null" + " || StringUtil.isNotEmpty(key, true) == false >> return null; ");
      return null;
    }

    return Json.parseObject(sp.getString(StringUtil.getTrimedString(key), null), clazz);
  }
  @Override
  public void initData() { // 必须调用
    super.initData();

    intent = getIntent();
    packageName = intent.getStringExtra(INTENT_PACKAGE_NAME);

    intentType = intent.getIntExtra(INTENT_TYPE, 0);
    if (StringUtil.isNotEmpty(intent.getStringExtra(INTENT_KEY), true)) {
      tvEditTextInfoTitle.setText(StringUtil.getCurrentString());
    }
    etEditTextInfo.setSingleLine(intentType != TYPE_NOTE);

    switch (intentType) {
      case TYPE_NICK:
        MaxLen = 20;
        break;
      case TYPE_PHONE:
        etEditTextInfo.setInputType(InputType.TYPE_CLASS_PHONE);
        MaxLen = 11;
        break;
      case TYPE_EMAIL:
        etEditTextInfo.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
        MaxLen = 60;
        break;
      case TYPE_WEBSITE:
        etEditTextInfo.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT);
        MaxLen = 60;
        break;
      case TYPE_MAILADDRESS:
        MaxLen = 60;
        break;
      case TYPE_PROFESSION:
        tvEditTextInfoRemind.setText("所属行业");
        MaxLen = 15;
      case TYPE_NOTE:
        MaxLen = 100;
        break;
      default:
        MaxLen = 30;
        break;
    }
    etEditTextInfo.setMaxEms(MaxLen);
    tvEditTextInfoRemind.setText("限" + MaxLen / 2 + "个字(或" + MaxLen + "个字符)");

    if (intentType == TYPE_MAILADDRESS || intentType == TYPE_USUALADDRESS) {
      tvEditTextInfoPlace.setVisibility(View.VISIBLE);
      CommonUtil.toActivity(
          context,
          PlacePickerWindow.createIntent(context, packageName, 2),
          REQUEST_TO_PLACE_PICKER,
          false);
    }
  }
  /**
   * 删除
   *
   * @param key
   */
  public void delete(String key) {
    if (StringUtil.isNotEmpty(key, true) == false) {
      Log.e(
          TAG,
          "deleteGroup  context == null "
              + " || StringUtil.isNotEmpty(groupName, true) == fal >> return;");
      return;
    }

    sp.edit().remove(StringUtil.getTrimedString(key)).commit();
  }
 private String setCuttedPicturePath() {
   // oringlePicturePath 不对
   cuttedPicturePath = intent.getStringExtra(INTENT_CUTTED_PICTURE_PATH);
   if (StringUtil.isFilePath(cuttedPicturePath) == false) {
     cuttedPicturePath = DataKeeper.fileRootPath + DataKeeper.imagePath;
   }
   cuttedPictureName = intent.getStringExtra(INTENT_CUTTED_PICTURE_NAME);
   if (StringUtil.isFilePath(cuttedPictureName) == false) {
     cuttedPictureName = "photo" + System.currentTimeMillis();
   }
   return cuttedPicturePath;
 }
 private void saveAndExit() {
   String editedValue =
       StringUtil.getTrimedString(tvEditTextInfoPlace)
           + StringUtil.getTrimedString(etEditTextInfo);
   if (editedValue.equals("" + getIntent().getStringExtra(INTENT_VALUE))) {
     CommonUtil.showShortToast(context, "内容没有改变哦~");
   } else {
     intent = new Intent();
     intent.putExtra(RESULT_TYPE, getIntent().getIntExtra(INTENT_TYPE, -1));
     intent.putExtra(RESULT_VALUE, editedValue);
     setResult(RESULT_OK, intent);
     finish();
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    intent = getIntent();

    originalPicturePath = intent.getStringExtra(INTENT_ORIGINAL_PICTURE_PATH);
    cuttedWidth = intent.getIntExtra(INTENT_CUT_WIDTH, 0);
    cuttedHeight = intent.getIntExtra(INTENT_CUT_HEIGHT, 0);
    if (cuttedWidth <= 0) {
      cuttedWidth = cuttedHeight;
    }
    if (cuttedHeight <= 0) {
      cuttedHeight = cuttedWidth;
    }

    if (StringUtil.isNotEmpty(originalPicturePath, true) == false || cuttedWidth <= 0) {
      Log.e(
          TAG,
          "onCreate  StringUtil.isNotEmpty(originalPicturePath, true)"
              + " == false || cuttedWidth <= 0 >> finish(); return;");
      showShortToast("图片不存在,请先选择图片");
      finish();
      return;
    }

    // 功能归类分区方法,必须调用<<<<<<<<<<
    initData();
    initView();
    initEvent();
    // 功能归类分区方法,必须调用>>>>>>>>>>

  }
Ejemplo n.º 9
0
  /** 编辑图片名称 */
  private void editName(boolean toWindow) {
    if (toWindow) {
      intent =
          EditTextInfoWindow.createIntent(
              context,
              EditTextInfoWindow.TYPE_NICK,
              "照片名称",
              StringUtil.getTrimedString(tvDemoMainHeadName),
              getPackageName());
    } else {
      intent =
          EditTextInfoActivity.createIntent(
              context,
              EditTextInfoActivity.TYPE_NICK,
              "照片名称",
              StringUtil.getTrimedString(tvDemoMainHeadName));
    }

    toActivity(intent, REQUEST_TO_EDIT_TEXT_INFO, !toWindow);
  }
  @Override
  public void initListener() { // 必须调用
    super.initListener();

    findViewById(R.id.tvEditTextInfoReturn).setOnClickListener(this);
    findViewById(R.id.tvEditTextInfoForward).setOnClickListener(this);
    tvEditTextInfoPlace.setOnClickListener(this);

    etEditTextInfo.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            inputedString = StringUtil.getTrimedString(s);
            if (StringUtil.isNotEmpty(inputedString, true) == false) {
              ivEditTextInfoClear.setVisibility(View.GONE);
            } else {
              ivEditTextInfoClear.setVisibility(View.VISIBLE);
            }
          }

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void afterTextChanged(Editable s) {}
        });
    ivEditTextInfoClear.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            etEditTextInfo.setText("");
          }
        });

    etEditTextInfo.setText(StringUtil.getTrimedString(getIntent().getStringExtra(INTENT_VALUE)));
    etEditTextInfo.setSelection(StringUtil.getLength(etEditTextInfo, true));
  }
Ejemplo n.º 11
0
  /**
   * 显示图片
   *
   * @param path
   */
  private void setPicture(String path) {
    if (StringUtil.isFilePath(path) == false) {
      Log.e(
          TAG, "setPicture  StringUtil.isFilePath(path) == false >> showShortToast(找不到图片);return;");
      showShortToast("找不到图片");
      return;
    }
    this.picturePath = path;

    svDemoMain.smoothScrollTo(0, 0);
    try {
      ivDemoMainHead.setImageDrawable(new BitmapDrawable(getResources(), picturePath));
    } catch (Exception e) {
      showShortToast("设置图片失败了,再试一次吧^_^");
    }
  }
Ejemplo n.º 12
0
  /**
   * 裁剪图片
   *
   * @param path
   */
  private void cutPicture(String path) {
    if (StringUtil.isFilePath(path) == false) {
      Log.e(
          TAG, "cutPicture  StringUtil.isFilePath(path) == false >> showShortToast(找不到图片);return;");
      showShortToast("找不到图片");
      return;
    }
    this.picturePath = path;

    intent = new Intent(context, CutPictureActivity.class);
    intent.putExtra(CutPictureActivity.INTENT_ORIGINAL_PICTURE_PATH, picturePath);
    intent.putExtra(
        CutPictureActivity.INTENT_CUTTED_PICTURE_PATH,
        DataKeeper.fileRootPath + DataKeeper.imagePath);
    intent.putExtra(
        CutPictureActivity.INTENT_CUTTED_PICTURE_NAME, "photo" + System.currentTimeMillis());
    intent.putExtra(CutPictureActivity.INTENT_CUT_HEIGHT, 200);
    toActivity(intent, REQUEST_TO_CUT_PICTURE);
  }
Ejemplo n.º 13
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != RESULT_OK) {
      return;
    }
    switch (requestCode) {
      case REQUEST_TO_SELECT_PICTURE:
        if (data != null) {
          cutPicture(data.getStringExtra(SelectPictureActivity.RESULT_PICTURE_PATH));
        }
        break;
      case REQUEST_TO_CUT_PICTURE: // 返回的结果
        if (data != null) {
          setPicture(data.getStringExtra(CutPictureActivity.RESULT_PICTURE_PATH));
        }
        break;
      case REQUEST_TO_EDIT_TEXT_INFO:
        if (data != null) {
          svDemoMain.smoothScrollTo(0, 0);
          tvDemoMainHeadName.setText(
              StringUtil.getTrimedString(data.getStringExtra(EditTextInfoWindow.RESULT_VALUE)));
        }
        break;
      case REQUEST_TO_SERVER_SETTING:
        if (data != null) {
          // TODO
        }
        break;
      case REQUEST_TO_TOP_MENU:
        if (data != null) {
          switch (data.getIntExtra(TopMenuWindow.RESULT_POSITION, -1)) {
            case 0:
              showItemOnlyDialog();
              break;
            case 1:
              selectPicture();
              break;
            default:
              break;
          }
        }
        break;
      case REQUEST_TO_BOTTOM_MENU:
        if (data != null) {
          int selectedPosition = data.getIntExtra(BottomMenuWindow.RESULT_ITEM_ID, -1);
          if (selectedPosition >= 0 && selectedPosition < topbarColorResIds.length) {
            rlDemoMainTopbar.setBackgroundResource(topbarColorResIds[selectedPosition]);
          }
        }
        break;
      case REQUEST_TO_DATE_PICKER:
        if (data != null) {
          //					List<Integer> selectedPositionList = data.getIntegerArrayListExtra(
          //							GridPickerWindow.RESULT_SELECTED_POSITIONS);
          //					showShortToast("selectedPositionList.size() = " + (selectedPositionList == null
          //							? "null" : selectedPositionList.size()));

          ArrayList<Integer> dateList =
              data.getIntegerArrayListExtra(DatePickerWindow.RESULT_DATE_DETAIL_LIST);
          if (dateList != null && dateList.size() >= 3) {
            showShortToast(
                "选择的日期为" + dateList.get(0) + "-" + (dateList.get(1) + 1) + "-" + dateList.get(2));
          }
        }
        break;
      case REQUEST_TO_PLACE_PICKER:
        if (data != null) {
          ArrayList<String> placeList =
              data.getStringArrayListExtra(PlacePickerWindow.RESULT_PLACE_LIST);
          if (placeList != null) {
            String place = "";
            for (String s : placeList) {
              place += StringUtil.getTrimedString(s);
            }
            showShortToast("选择的地区为: " + place);
          }
        }
        break;
      default:
        break;
    }
  }
 public ListDiskCache(Context context, Class<T> clazz, String path) {
   this(
       context,
       clazz,
       context.getSharedPreferences(StringUtil.getTrimedString(path), Context.MODE_PRIVATE));
 }