コード例 #1
0
  private void autofit() {
    float oldTextSize = mTextView.getTextSize();
    float textSize;

    mIsAutofitting = true;
    autofit(mTextView, mPaint, mMinTextSize, mMaxTextSize, mMaxLines, mPrecision);
    mIsAutofitting = false;

    textSize = mTextView.getTextSize();
    if (textSize != oldTextSize) {
      sendTextSizeChange(textSize, oldTextSize);
    }
  }
コード例 #2
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   View v = super.getView(position, convertView, parent);
   try {
     // TODO create a theme for the whole app so we don't have to do this
     TextView tv = (TextView) v;
     tv.setTypeface(tv.getTypeface(), Typeface.ITALIC);
     if (size == 0.0f) size = tv.getTextSize() * SCALE_FACTOR;
     tv.setTextSize(size);
     v = tv;
   } catch (Exception e) {
     Util.e(null, TAG, "Can't set italic type: " + e);
   }
   if (pics[position] != null) {
     BitmapDrawable pic = new BitmapDrawable(v.getContext().getResources(), pics[position]);
     if (!unscaledBackground) {
       v.setBackgroundDrawable(pic);
     } else {
       TextView tv;
       try {
         tv = (TextView) v;
       } catch (Exception e) {
         Util.w(null, TAG, "Returned view does not " + "support unscaled background images");
         unscaledBackground = true;
         v.setBackgroundDrawable(pic);
         return v;
       }
       tv.setCompoundDrawablesWithIntrinsicBounds(pic, null, null, null);
       return tv;
     }
   }
   return v;
 }
コード例 #3
0
 private float a(TextView paramTextView, float paramFloat, String paramString)
 {
   float f3 = paramTextView.getTextSize();
   label23:
   Object localObject;
   if ((paramTextView == null) || (paramFloat <= 0.0F) || (paramString == null))
   {
     return f3;
     paramTextView.setTextSize(0, localObject);
   }
   for (;;)
   {
     float f2 = localObject;
     if (paramString != TextUtils.ellipsize(paramString, paramTextView.getPaint(), paramFloat, TextUtils.TruncateAt.END))
     {
       localObject -= 1.0F;
       if (f1 >= 0.0F) {
         break label23;
       }
       f2 = f1;
     }
     if (f2 < 0.0F) {
       break;
     }
     return f2;
     float f1 = f3;
   }
 }
コード例 #4
0
  private void prepare() {
    // Remember current state
    final float diff1 = mText1Difference;

    // Measure
    mPaint.setTextSize(mTextField1.getTextSize());
    mPaint.setTypeface(mTextField1.getTypeface());
    mText1TextWidth = mPaint.measureText(mTextField1.getText().toString());

    // See how much functions are needed at all
    mIsText1MarqueeNeeded = mText1TextWidth > mWidth;

    mText1Difference = Math.abs((mText1TextWidth - mWidth)) + 5;

    if (DEBUG) {
      Log.d(TAG, "mText1TextWidth: " + mText1TextWidth);
      Log.d(TAG, "getMeasuredWidth: " + mWidth);

      Log.d(TAG, "mIsText1MarqueeNeeded: " + mIsText1MarqueeNeeded);

      Log.d(TAG, "mText1Difference: " + mText1Difference);
    }

    if (diff1 != mText1Difference) {
      setupText1Marquee();
    }
  }
コード例 #5
0
  @Override
  public void onTextSizeChanged(final TextView textView, float oldSize) {
    if (mCurrentState != CalculatorState.INPUT) { // TODO dont animate when showing graph
      // Only animate text changes that occur from user input.
      return;
    }

    // Calculate the values needed to perform the scale and translation animations,
    // maintaining the same apparent baseline for the displayed text.
    final float textScale = oldSize / textView.getTextSize();
    final float translationX;
    if (android.os.Build.VERSION.SDK_INT >= 17) {
      translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingEnd());
    } else {
      translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingRight());
    }
    final float translationY =
        (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom());
    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
        ObjectAnimator.ofFloat(textView, View.SCALE_X, textScale, 1.0f),
        ObjectAnimator.ofFloat(textView, View.SCALE_Y, textScale, 1.0f),
        ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, translationX, 0.0f),
        ObjectAnimator.ofFloat(textView, View.TRANSLATION_Y, translationY, 0.0f));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.start();
  }
コード例 #6
0
 public StatusItemLayout(Context context, AttributeSet attrs) {
   super(context, attrs);
   LayoutInflater inflater =
       (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   inflater.inflate(R.layout.status_item, this);
   tvType = (TextView) findViewById(R.id.tvType);
   tvUnit = (TextView) findViewById(R.id.tvUnit);
   tvNumber = (TextView) findViewById(R.id.tvNumber);
   if (tvNumber != null) tvNumber.setTextSize(tvNumber.getTextSize() * 1.25f);
 }
コード例 #7
0
  public static void SetTextviewSize(TextView textView, float scale) {
    float size = textView.getTextSize(); // lineSpacingExtra
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size * scale);
    float spacingExtra = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      try {
        spacingExtra = textView.getLineSpacingExtra();
      } catch (NoSuchMethodError e) {

      }
    }
    textView.setLineSpacing(spacingExtra * scale, 1f);
  }
コード例 #8
0
  private AutofitHelper(TextView view) {
    final Context context = view.getContext();
    float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;

    mTextView = view;
    mPaint = new TextPaint();
    setRawTextSize(view.getTextSize());

    mMaxLines = getMaxLines(view);
    mMinTextSize = scaledDensity * DEFAULT_MIN_TEXT_SIZE;
    mMaxTextSize = mTextSize;
    mPrecision = DEFAULT_PRECISION;
  }
コード例 #9
0
ファイル: WindowUtil.java プロジェクト: xh2015/TimePicker
 /**
  * 重新计算TextView中文本的大小
  *
  * @param view
  * @return
  */
 public static boolean resizeText(TextView view) {
   if (view == null) return false;
   Object tag = view.getTag();
   if (tag instanceof String) {
     String tagString = (String) tag;
     if ("ignoreSize".equals(tagString)) {
       return true;
     }
   }
   float textSize = view.getTextSize();
   float ratio = SCALE_RATIO;
   view.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize * ratio);
   return true;
 }
コード例 #10
0
  public int captureBitmapCache(String in) {
    TextView tv = (TextView) MyApp.context.findViewById(R.id.ocrTextview);
    String tvText = tv.getText().toString();
    float tvTextSize = tv.getTextSize();
    int tvColor = tv.getCurrentTextColor();
    Bitmap bitmap = null;

    tv.setTextSize(36);
    tv.setTextColor(Color.CYAN);
    tv.setTypeface(Typeface.SANS_SERIF);

    tv.setText(in);

    while (bitmap == null) {
      // http://stackoverflow.com/questions/2339429/android-view-getdrawingcache-returns-null-only-null
      tv.measure(
          MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
          MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
      tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

      tv.setDrawingCacheEnabled(true);
      tv.buildDrawingCache(true);
      bitmap = Bitmap.createBitmap(tv.getDrawingCache());
      tv.destroyDrawingCache();
      tv.setDrawingCacheEnabled(false);
    }

    FileOutputStream fos = null;
    int res = -1;
    try {
      fos = new FileOutputStream(currentDirectory() + "/files/" + MyApp.SCREENSHOT_FILENAME);
      if (fos != null) {
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
        fos.close();
        res = 0;
      }
    } catch (Throwable e) {
      Log.i(MyApp.TAG, e.getMessage().toString());
      res = -1;
    }

    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvTextSize);
    tv.setTypeface(Typeface.MONOSPACE);
    tv.setText(tvText);
    tv.setTextColor(tvColor);
    return res;
  }
コード例 #11
0
 private void doZoom(MotionEvent event) {
   float newDist = spacing(event);
   if (newDist > 10f) {
     float scale = newDist / oldDist;
     if (scale > 1) {
       scale = 1.1f;
     } else if (scale < 1) {
       scale = 0.95f;
     }
     float currSize = textView.getTextSize() * scale;
     if ((currSize < MAX_FONT_SIZE && currSize > MIN_FONT_SIZE)
         || (currSize >= MAX_FONT_SIZE && scale < 1)
         || (currSize <= MIN_FONT_SIZE && scale > 1)) {
       textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, currSize);
     }
   }
 }
コード例 #12
0
  @Override
  public void afterTextChanged(Editable s) {
    if (start >= 0) {
      float textSize = textView.getTextSize();
      int pos = start;

      start = -2;
      EmojiconHandler.addEmojis(
          textView.getContext(),
          s,
          (int) textSize,
          DynamicDrawableSpan.ALIGN_BASELINE,
          (int) textSize,
          pos,
          count);
      start = -1;
    }
  }
コード例 #13
0
  @Override
  protected void onResume() {
    super.onResume();
    Log.d(TAG, "ArticleActivity OnResume");
    tvFullText = (TextView) fragment.getView().findViewById(R.id.tvFragmentFullText);
    startSize = tvFullText.getTextSize();

    tvFullText.setOnTouchListener(
        new OnScaleTouchListener(ArticleActivity.this) {
          @Override
          void resize(ScaleGestureDetector detector) {
            scale *= detector.getScaleFactor();
            scale = Math.max(0.5f, Math.min(scale, 1.2f));

            tvFullText.setTextSize(startSize * scale);
          }
        });
  }
コード例 #14
0
ファイル: TextTool.java プロジェクト: tloyd/SecondApp
  public static SpannableString getWeiboContent(
      final Context context, final TextView tv, String source) {
    String regexEmoji = "\\[[^\\[\\]]+\\]";

    String regex = regexEmoji;

    SpannableString spannableString = new SpannableString(source);
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(spannableString);

    if (matcher.find()) {
      tv.setMovementMethod(LinkMovementMethod.getInstance());
      matcher.reset();
    }

    while (matcher.find()) {
      String emojiStr = matcher.group();
      if (emojiStr != null) {
        int start = matcher.start();
        String pathName = emojiStr.substring(1, emojiStr.length() - 1);
        Uri uri = Uri.parse(pathName);
        Bitmap bitmap = null;
        try {
          bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (bitmap != null) {
          int size = (int) tv.getTextSize();
          float scale = (float) bitmap.getHeight() / bitmap.getWidth();
          int screenWidthPixels = ScreenTool.getScreenWidthPixels((Activity) context);
          int height = (int) (screenWidthPixels * scale);

          bitmap = Bitmap.createScaledBitmap(bitmap, screenWidthPixels, height, true);
          ImageSpan imageSpan = new ImageSpan(context, bitmap);
          spannableString.setSpan(
              imageSpan, start, start + emojiStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
      }
    }
    return spannableString;
  }
コード例 #15
0
  @Override
  public final void addView(View child, int index, ViewGroup.LayoutParams params) {
    if (child instanceof EditText) {
      // If we already have an EditText, throw an exception
      if (mEditText != null) {
        throw new IllegalArgumentException("We already have an EditText, can only have one");
      }

      // Update the layout params so that the EditText is at the bottom, with enough top
      // margin to show the label
      final LayoutParams lp = new LayoutParams(params);
      lp.gravity = Gravity.BOTTOM;
      lp.topMargin = (int) mLabel.getTextSize();
      params = lp;

      setEditText((EditText) child);
    }

    // Carry on adding the View...
    super.addView(child, index, params);
  }
コード例 #16
0
  public EmojixTextWatcher(TextView textView) {
    this.textView = textView;

    SpannableString s = new SpannableString(textView.getText());
    if (!TextUtils.isEmpty(s)) {
      float textSize = textView.getTextSize();

      EmojiconHandler.addEmojis(
          textView.getContext(),
          s,
          (int) textSize,
          DynamicDrawableSpan.ALIGN_BASELINE,
          (int) textSize,
          0,
          -1);

      textView.setText(s, TextView.BufferType.EDITABLE);

      if (textView instanceof EditText) {
        EditText editText = (EditText) textView;
        editText.setSelection(s.length());
      }
    }
  }
コード例 #17
0
 /**
  * Gets the text size of notation
  *
  * @return the size
  */
 public float getNotationTextSize() {
   TextView tv = (TextView) chessboard.findViewById(notationId[0]);
   return tv.getTextSize();
 }
コード例 #18
0
 public void ressetTextSize(TextView textView) {
   if (textView == null) return;
   textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textView.getTextSize() * ratio);
 }
    @Override
    protected void onPostExecute(Integer result) {
      if (result == -100) {
        if (from.equals(BookshelfFragment.fromid)) {
          Toast.makeText(
                  parentActivity,
                  getResources().getString(R.string.bookshelf_not_cached),
                  Toast.LENGTH_LONG)
              .show();

          new AlertDialog.Builder(parentActivity)
              .setTitle(getResources().getString(R.string.bookshelf_did_not_find_cache))
              .setMessage(getResources().getString(R.string.bookshelf_want_to_connect_to_Internet))
              .setPositiveButton(
                  "YES",
                  new android.content.DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      if (pDialog != null) pDialog.dismiss();

                      // connect to the Internet to load
                      from = "";
                      List<NameValuePair> targVar = new ArrayList<NameValuePair>();
                      targVar.add(
                          Wenku8Interface.getNovelContent(
                              currentAid, currentCid, GlobalConfig.getFetchLanguage()));

                      final asyncNovelContentTask ast = new asyncNovelContentTask();
                      ast.execute(targVar);
                      return;
                    }
                  })
              .setNegativeButton(
                  "NO",
                  new android.content.DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      onBackPressed();
                    }
                  })
              .show();
        } else
          Toast.makeText(
                  parentActivity,
                  getResources().getString(R.string.network_error),
                  Toast.LENGTH_LONG)
              .show();
        if (pDialog != null) pDialog.dismiss();
        return;
      }

      // generate listview to contain the texts and images
      // ListView lv = (ListView) parentActivity
      // .findViewById(R.id.content_list);
      // if (lv == null) {
      // Log.e("MewX", "NovelReaderActivity ListView == null!");
      // return;
      // }
      // lv.setDivider(null);
      // lv.setAdapter(new NovelContentAdapter(parentActivity, nc));
      // pDialog.setProgress(nc.size());

      // The abandoned way - dynamically addign textview into layout
      LinearLayout layout = (LinearLayout) parentActivity.findViewById(R.id.novel_content_layout);

      for (int i = 0; i < nc.size(); i++) {
        if (pDialog != null) pDialog.setProgress(i);

        switch (nc.get(i).type) {
          case 't':
            TextView tempTV = new TextView(parentActivity);
            if (i == 0) {
              tempTV.setTextSize(TypedValue.COMPLEX_UNIT_SP, GlobalConfig.getShowTextSize() + 6);
              Shader shader =
                  new LinearGradient(
                      0, 0, 0, tempTV.getTextSize(), 0xFF003399, 0xFF6699FF, Shader.TileMode.CLAMP);
              tempTV.getPaint().setShader(shader);
            } else {
              tempTV.setTextSize(TypedValue.COMPLEX_UNIT_SP, GlobalConfig.getShowTextSize());
            }
            tempTV.setText(nc.get(i).content);
            tempTV.setPadding(
                GlobalConfig.getShowTextPaddingLeft(),
                GlobalConfig.getShowTextPaddingTop(),
                GlobalConfig.getShowTextPaddingRight(),
                0);
            layout.addView(tempTV);
            break;

          case 'i':
            final ImageView tempIV = new ImageView(parentActivity);
            tempIV.setClickable(true);
            tempIV.setAdjustViewBounds(true);
            tempIV.setScaleType(ScaleType.FIT_CENTER); // CENTER_INSIDE
            tempIV.setPadding(0, GlobalConfig.getShowTextPaddingTop(), 0, 0);
            tempIV.setImageResource(R.drawable.empty_cover); // default

            // async loader
            final String imgFileName = GlobalConfig.generateImageFileNameByURL(nc.get(i).content);
            final String path = GlobalConfig.getAvailableNovolContentImagePath(imgFileName);

            if (path != null) {
              ImageLoader.getInstance().displayImage("file://" + path, tempIV);

              tempIV.setOnClickListener(
                  new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                      // TODO Auto-generated method stub
                      Intent intent = new Intent();
                      intent.setClass(parentActivity, NovelImageActivity.class);
                      intent.putExtra("path", path);
                      startActivity(intent);
                      parentActivity.overridePendingTransition(R.anim.in_from_right, R.anim.keep);
                    }
                  });
            } else {
              // define another asynctask to load image
              // need to access local var - tempIV
              class asyncDownloadImage extends AsyncTask<String, Integer, String> {
                @Override
                protected String doInBackground(String... params) {
                  GlobalConfig.saveNovelContentImage(params[0]);
                  String name = GlobalConfig.generateImageFileNameByURL(params[0]);
                  return GlobalConfig.getAvailableNovolContentImagePath(name);
                }

                @Override
                protected void onPostExecute(final String result) {
                  ImageLoader.getInstance().displayImage("file://" + result, tempIV);

                  tempIV.setOnClickListener(
                      new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                          Intent intent = new Intent();
                          intent.setClass(parentActivity, NovelImageActivity.class);
                          intent.putExtra("path", result);
                          startActivity(intent);
                          parentActivity.overridePendingTransition(
                              R.anim.in_from_right, R.anim.keep);
                        }
                      });

                  return;
                }
              }
              asyncDownloadImage async = new asyncDownloadImage();
              async.execute(nc.get(i).content);
            }

            layout.addView(tempIV);
            break;
        }
      }

      // end loading dialog
      if (pDialog != null) pDialog.dismiss();

      // show dialog
      if (GlobalConfig.getReadSavesRecord(
              currentCid,
              ((LinearLayout) parentActivity.findViewById(R.id.novel_content_layout))
                  .getMeasuredHeight())
          > 100) {
        new AlertDialog.Builder(parentActivity)
            .setTitle(getResources().getString(R.string.novel_load))
            .setMessage(getResources().getString(R.string.novel_load_question))
            .setPositiveButton(
                "YES",
                new android.content.DialogInterface.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    // set scroll view
                    Handler handler = new Handler();
                    handler.postDelayed(runnableScroll, 200);

                    Toast.makeText(
                            parentActivity,
                            "Scroll to = "
                                + GlobalConfig.getReadSavesRecord(
                                    currentCid,
                                    ((LinearLayout)
                                            parentActivity.findViewById(R.id.novel_content_layout))
                                        .getMeasuredHeight()),
                            Toast.LENGTH_SHORT)
                        .show();
                  }
                })
            .setNegativeButton("NO", null)
            .show();
      }

      return;
    }
コード例 #20
0
 /**
  * get Font height
  *
  * @param view
  * @return
  */
 public static int getFontHeight(TextView view) {
   Paint paint = new Paint();
   paint.setTextSize(view.getTextSize());
   FontMetrics fm = paint.getFontMetrics();
   return (int) (Math.ceil(fm.descent - fm.ascent));
 }
コード例 #21
0
  /** Returns the text size of the SuperCardToast. */
  public float getTextSize() {

    return mMessageTextView.getTextSize();
  }
コード例 #22
0
ファイル: MarqueeView.java プロジェクト: jeozey/Wisp
  private void prepareAnimation() {
    // Measure
    mPaint.setTextSize(mTextField.getTextSize());
    mPaint.setTypeface(mTextField.getTypeface());
    float mTextWidth = mPaint.measureText(mTextField.getText().toString());

    // See how much functions are needed at all
    mMarqueeNeeded = mTextWidth > getMeasuredWidth();

    mTextDifference = Math.abs((mTextWidth - getMeasuredWidth())) + 5;

    if (BuildConfig.DEBUG) {
      Log.d(TAG, "mTextWidth       : " + mTextWidth);
      Log.d(TAG, "measuredWidth    : " + getMeasuredWidth());
      Log.d(TAG, "mMarqueeNeeded   : " + mMarqueeNeeded);
      Log.d(TAG, "mTextDifference  : " + mTextDifference);
    }

    final int duration = (int) (mTextDifference * mSpeed);

    mMoveTextOut = new TranslateAnimation(0, -mTextDifference, 0, 0);
    mMoveTextOut.setDuration(duration);
    mMoveTextOut.setInterpolator(mInterpolator);
    mMoveTextOut.setFillAfter(true);

    mMoveTextIn = new TranslateAnimation(-mTextDifference, 0, 0, 0);
    mMoveTextIn.setDuration(duration);
    mMoveTextIn.setStartOffset(mAnimationPause);
    mMoveTextIn.setInterpolator(mInterpolator);
    mMoveTextIn.setFillAfter(true);

    mMoveTextOut.setAnimationListener(
        new Animation.AnimationListener() {
          public void onAnimationStart(Animation animation) {
            expandTextView();
          }

          public void onAnimationEnd(Animation animation) {
            if (mCancelled) {
              return;
            }

            mTextField.startAnimation(mMoveTextIn);
          }

          public void onAnimationRepeat(Animation animation) {}
        });

    mMoveTextIn.setAnimationListener(
        new Animation.AnimationListener() {
          public void onAnimationStart(Animation animation) {}

          public void onAnimationEnd(Animation animation) {

            cutTextView();

            if (mCancelled) {
              return;
            }
            startTextFieldAnimation();
          }

          public void onAnimationRepeat(Animation animation) {}
        });
  }
コード例 #23
0
ファイル: BookView.java プロジェクト: ryantm/PageTurner
 public float getTextSize() {
   return childView.getTextSize();
 }
コード例 #24
0
  // Please use run(...) instead
  public static void justify(TextView textView) {
    Paint paint = new Paint();

    String[] blocks;
    float spaceOffset = 0;
    float textWrapWidth = 0;

    int spacesToSpread;
    float wrappedEdgeSpace;
    String block;
    String[] lineAsWords;
    String wrappedLine;
    String smb = "";
    Object[] wrappedObj;

    // Pull widget properties
    paint.setColor(textView.getCurrentTextColor());
    paint.setTypeface(textView.getTypeface());
    paint.setTextSize(textView.getTextSize());

    textWrapWidth = textView.getWidth();
    spaceOffset = paint.measureText(" ");
    blocks = textView.getText().toString().split("((?<=\n)|(?=\n))");

    if (textWrapWidth < 20) {
      return;
    }

    for (int i = 0; i < blocks.length; i++) {
      block = blocks[i];

      if (block.length() == 0) {
        continue;
      } else if (block.equals("\n")) {
        smb += block;
        continue;
      }

      block = block.trim();

      if (block.length() == 0) continue;

      wrappedObj = TextJustifyUtils.createWrappedLine(block, paint, spaceOffset, textWrapWidth);
      wrappedLine = ((String) wrappedObj[0]);
      wrappedEdgeSpace = (Float) wrappedObj[1];
      lineAsWords = wrappedLine.split(" ");
      spacesToSpread =
          (int) (wrappedEdgeSpace != Float.MIN_VALUE ? wrappedEdgeSpace / spaceOffset : 0);

      for (String word : lineAsWords) {
        smb += word + " ";

        if (--spacesToSpread > 0) {
          smb += " ";
        }
      }

      smb = smb.trim();

      if (blocks[i].length() > 0) {
        blocks[i] = blocks[i].substring(wrappedLine.length());

        if (blocks[i].length() > 0) {
          smb += "\n";
        }

        i--;
      }
    }

    textView.setGravity(Gravity.LEFT);
    textView.setText(smb);
  }
コード例 #25
0
  @SuppressLint("DefaultLocale")
  @Override
  public void onClick(View view) {
    // TODO Auto-generated method stub
    switch (view.getId()) {
      case R.id.b_results:
        String check = input.getText().toString();
        display.setText(check);
        if (check.contentEquals("left")) {
          display.setGravity(Gravity.LEFT);
        } else if (check.contentEquals("center")) {
          display.setGravity(Gravity.CENTER);
        } else if (check.contentEquals("right")) {
          display.setGravity(Gravity.RIGHT);
        } else if (check.contentEquals("blue")) {
          display.setTextColor(Color.BLUE);
        } else if (check.toLowerCase().contains("wtf")) {
          Random crazy = new Random();
          display.setText("Where's the Fridge???");
          int max = 47;
          // Should be [1, max]
          display.setTextSize(crazy.nextInt(max) + 1);
          // display.setTextSize(max);

          display.setTextColor(
              Color.rgb(crazy.nextInt(256), crazy.nextInt(256), crazy.nextInt(256)));
          switch (crazy.nextInt(3)) {
            case 0:
              display.setGravity(Gravity.LEFT);
              break;
            case 1:
              display.setGravity(Gravity.CENTER);
              break;
            case 2:
              display.setGravity(Gravity.RIGHT);
              break;
          }
        } else {
          display.setText("Use one: left, center, right, blue, WTF");
          display.setGravity(Gravity.CENTER);
          System.out.println("Text Size: " + display.getTextSize());
          display.setTextSize(21);
        }
        break;
      case R.id.tb_pass:
        // Is the ToggleButton checked on
        if (passTog.isChecked()) {
          // TODO What is the | (pipe) ,and why is it needed?
          input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

          // FIXME Does not work, why not?
          // input.setInputType(InputType.TYPE_CLASS_TEXT);
          System.out.println("on toggle");
        } else {
          input.setInputType(InputType.TYPE_CLASS_TEXT);

          // FIXME Does not work, why?
          // input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
          System.out.println("off toggle");
        }
        break;
    }
  }
コード例 #26
0
ファイル: ImageTextView.java プロジェクト: MichaelSun/SiXin
 public float getTextSize() {
   return mText.getTextSize();
 }