Esempio n. 1
0
  @Override
  public void onLocationChanged(Location location) {
    if (location.hasAccuracy()) {
      SpannableString s = new SpannableString(String.format("%.0f", location.getAccuracy()) + "m");
      s.setSpan(new RelativeSizeSpan(0.75f), s.length() - 1, s.length(), 0);
      accuracy.setText(s);

      if (firstfix) {
        status.setText("");
        fab.setVisibility(View.VISIBLE);
        if (!data.isRunning() && !maxSpeed.getText().equals("")) {
          refresh.setVisibility(View.VISIBLE);
        }
        firstfix = false;
      }
    } else {
      firstfix = true;
    }

    if (location.hasSpeed()) {
      progressBarCircularIndeterminate.setVisibility(View.GONE);
      SpannableString s =
          new SpannableString(String.format("%.0f", location.getSpeed() * 3.6) + "km/h");
      s.setSpan(new RelativeSizeSpan(0.25f), s.length() - 4, s.length(), 0);
      currentSpeed.setText(s);
    }
  }
  public void clickText() {
    SpannableString ss = new SpannableString("New User? Click To Register.");
    ClickableSpan clickableSpan =
        new ClickableSpan() {
          @Override
          public void onClick(View clicktext) {
            startActivity(new Intent(SignInActivity.this, SignUpActivity.class));
          }

          @Override
          public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setUnderlineText(false);
          }
        };
    ss.setSpan(clickableSpan, 10, 15, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    ss.setSpan(
        new ForegroundColorSpan(Color.parseColor("#0E89EB")),
        10,
        15,
        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    clicktext.setText(ss);
    clicktext.setMovementMethod(LinkMovementMethod.getInstance());
    clicktext.setHighlightColor(Color.BLUE);
  }
Esempio n. 3
0
 /** 现金券显示价格样式 */
 public static SpannableString getCashPrice(Context context, double oldPrice, double newPrice) {
   StringBuilder builder = new StringBuilder();
   builder
       .append(handleDouble(newPrice))
       .append("元")
       .append(" ")
       .append(handleDouble(oldPrice))
       .append("元");
   int start = 0;
   int middle = builder.indexOf(" ") + 1;
   int end = builder.length();
   SpannableString string = new SpannableString(builder);
   /*改变文字的大小*/
   string.setSpan(
       new AbsoluteSizeSpan(sp2px(context, 20)),
       start,
       middle,
       Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
   string.setSpan(
       new AbsoluteSizeSpan(sp2px(context, 14)), middle, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
   /*给文字设置删除线*/
   string.setSpan(new StrikethroughSpan(), middle, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
   /*改变文字的颜色*/
   int textOrange = context.getResources().getColor(android.R.color.holo_red_light);
   int textGray = context.getResources().getColor(android.R.color.darker_gray);
   string.setSpan(
       new ForegroundColorSpan(textOrange), start, middle, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
   string.setSpan(
       new ForegroundColorSpan(textGray), middle, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
   return string;
 }
Esempio n. 4
0
 /**
  * 组合消息文本
  *
  * @param name
  * @param body
  * @return
  */
 public static SpannableString parsePostpan(String name, String body, String action) {
   SpannableString sp = null;
   int start = 0;
   int end = 0;
   if (StringUtils.isEmpty(action)) {
     sp = new SpannableString(name + ":" + body);
     end = name.length();
   } else {
     sp = new SpannableString(action + name + ":" + body);
     start = action.length();
     end = start + name.length();
   }
   // 设置用户名字体加粗、高亮
   sp.setSpan(
       new StyleSpan(android.graphics.Typeface.BOLD),
       start,
       end,
       Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
   sp.setSpan(
       new ForegroundColorSpan(Color.parseColor("#0e5986")),
       start,
       end,
       Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
   return sp;
 }
    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
      View item = inflater.inflate(R.layout.time_settings_dropdown_item, null);
      item.setMinimumHeight(60);

      if (position >= times.size()) {
        ((CheckedTextView) item).setText(getText(R.string.customTime));
      } else {
        SpannableString ss =
            new SpannableString(
                times.get(position)
                    + " "
                    + getString(R.string.min)
                    + " (+"
                    + increments.get(position)
                    + getString(R.string.secPerMove)
                    + ")");
        ss.setSpan(new ForegroundColorSpan(0xFF000000), 0, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(
            new ForegroundColorSpan(0xFF666666),
            6,
            ss.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ((CheckedTextView) item).setText(ss);
      }

      return item;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View item = inflater.inflate(R.layout.time_settings_item, null);

      if (position < times.size()) {
        SpannableString ss =
            new SpannableString(
                times.get(position)
                    + " "
                    + getString(R.string.min)
                    + " (+"
                    + increments.get(position)
                    + getString(R.string.secPerMove)
                    + ")");
        ss.setSpan(new ForegroundColorSpan(0xFF000000), 0, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(
            new ForegroundColorSpan(0xFF666666),
            6,
            ss.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ((TextView) item).setText(ss);
      }

      return item;
    }
  private void appendLog(String message, String targetFragment) {
    log.append(message);

    if (EXPECTED_TARGET_FRAGMENT.equals(targetFragment)) {
      SpannableString span = new SpannableString(targetFragment);
      span.setSpan(
          new ForegroundColorSpan(COLOR_OK),
          0,
          targetFragment.length(),
          Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
      log.append(span);
    } else {
      SpannableString span = new SpannableString(targetFragment);
      span.setSpan(
          new ForegroundColorSpan(COLOR_NOK),
          0,
          targetFragment.length(),
          Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
      log.append(span);
    }
    log.append("\n\n");

    if (logView != null) {
      logView.setText(log);
    }
  }
Esempio n. 8
0
	public static SpannableString getCustomFace(final Context context, 
			Bitmap bmp, String strFileName, ClickableSpan clickSpan) {
		if (null == context || null == bmp || isEmptyStr(strFileName))
			return null;
		
		String str = "/c[\"";
		str += strFileName;
		str += "\"]";
		
//		int cx = bmp.getWidth();
//		int cy = bmp.getHeight();
//		
//		Drawable drawable = new BitmapDrawable(bmp);
//		drawable.setBounds(0, 0, cx, cy);
		
//		ImageSpan imgSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
		ImageSpan imgSpan = new ImageSpan(context, bmp, ImageSpan.ALIGN_BASELINE);
		SpannableString spanStr = new SpannableString(str);
		spanStr.setSpan(imgSpan, 0, str.length(),
				Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

		if (clickSpan != null) {
//	        ClickableSpan[] click_spans = spanStr.getSpans(0, str.length(), ClickableSpan.class);
//	        if (click_spans.length != 0) {
//	        	for(ClickableSpan c_span : click_spans) {
//	            	spanStr.removeSpan(c_span);
//	            }
//	        }
			spanStr.setSpan(clickSpan, 0, str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);			
		}
        
		return spanStr;
	}
Esempio n. 9
0
 private void populateAdditionalStyles(LinkedTreeMap<String, Object> bean, SpannableString ss) {
   ArrayList<Integer> styles = (ArrayList<Integer>) bean.get("styles");
   if (styles != null && styles.size() != 0) {
     ArrayList<Integer> starts = (ArrayList<Integer>) bean.get("starts");
     ArrayList<Integer> ends = (ArrayList<Integer>) bean.get("ends");
     for (int i = 0; i < styles.size(); i++) {
       int style = gson2Int(styles.get(i));
       switch (style) {
         case ToolBar.StyleButton.HIGHLIGHT:
           ss.setSpan(
               new BackgroundColorSpan(Color.YELLOW),
               gson2Int(starts.get(i)),
               gson2Int(ends.get(i)),
               Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
           break;
         case ToolBar.StyleButton.UNDERLINE:
           ss.setSpan(
               new UnderlineSpan(),
               gson2Int(starts.get(i)),
               gson2Int(ends.get(i)),
               Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
           break;
         case ToolBar.StyleButton.STROKE:
           ss.setSpan(
               new StrikethroughSpan(),
               gson2Int(starts.get(i)),
               gson2Int(ends.get(i)),
               Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
           break;
         default:
           break;
       }
     }
   }
 }
Esempio n. 10
0
  /**
   * 根据传入的字变换大小
   *
   * @param text
   * @return
   */
  public static SpannableString spanTextStyle(String text, float firstSize, float secondSize) {

    // TODO
    if (StringUtils.isEmpty(text)) {
      text = "0.00";
    }
    double money = Double.parseDouble(text);
    DecimalFormat df = new DecimalFormat("0.00");
    text = df.format(money);

    SpannableString mspTest = new SpannableString(text);
    int dot = text.indexOf('.');
    if (dot > 0 && dot < text.length()) {
      mspTest.setSpan(
          new RelativeSizeSpan(firstSize),
          0,
          dot,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 0.5f表示默认字体大小的一半
      mspTest.setSpan(
          new RelativeSizeSpan(secondSize), dot, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
      mspTest.setSpan(
          new RelativeSizeSpan(firstSize), 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return mspTest;
  }
Esempio n. 11
0
 private SpannableString generateCenterText() {
   SpannableString s = new SpannableString("Food Waste\\ndistribution");
   s.setSpan(new RelativeSizeSpan(1.6f), 0, 14, 0);
   s.setSpan(new ForegroundColorSpan(ColorTemplate.VORDIPLOM_COLORS[0]), 0, 14, 0);
   s.setSpan(new RelativeSizeSpan(1.4f), 25, s.length(), 0);
   s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 25, s.length(), 0);
   return s;
 }
Esempio n. 12
0
  private SpannableString generateCenterSpannableText() {

    SpannableString s = new SpannableString("768\n舆情统计总数");
    s.setSpan(new ForegroundColorSpan(Color.rgb(240, 115, 126)), 0, 3, 0); // 设置前三个字符的颜色
    s.setSpan(new RelativeSizeSpan(2.2f), 0, s.length(), 0); // 设置圆环内字体大小
    // s.setSpan(new StyleSpan(Typeface.ITALIC), 9, s.length(), 0);
    // s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 9, s.length(),
    // 0);//设置后几个字符的颜色
    // s.setSpan(new RelativeSizeSpan(0.85f), 9, s.length(), 0);//设置后几个字体的大小
    return s;
  }
Esempio n. 13
0
  public boolean update() {
    if (error != null) {
      text.setText(error + "\n" + getContext().getString(R.string.thread_refresh_bar_inactive));
      return false;
    } else {
      ChanThread chanThread = callback.getChanThread();
      if (chanThread == null) {
        return false; // Recyclerview not clearing immediately or view didn't receive
        // onDetachedFromWindow
      }

      boolean update = false;

      String statusText = "";

      if (chanThread.archived) {
        statusText += getContext().getString(R.string.thread_archived) + "\n";
      } else if (chanThread.closed) {
        statusText += getContext().getString(R.string.thread_closed) + "\n";
      }

      if (!chanThread.archived && !chanThread.closed) {
        long time = callback.getTimeUntilLoadMore() / 1000L;
        if (!callback.isWatching()) {
          statusText += getContext().getString(R.string.thread_refresh_bar_inactive) + "\n";
        } else if (time <= 0) {
          statusText += getContext().getString(R.string.thread_refresh_now) + "\n";
        } else {
          statusText += getContext().getString(R.string.thread_refresh_countdown, time) + "\n";
        }
        update = true;
      }

      Post op = chanThread.op;

      Board board = Chan.getBoardManager().getBoardByValue(chanThread.loadable.board);
      if (board != null) {
        SpannableString replies = new SpannableString(op.replies + "R");
        if (op.replies >= board.bumpLimit) {
          replies.setSpan(new StyleSpan(Typeface.ITALIC), 0, replies.length(), 0);
        }
        SpannableString images = new SpannableString(op.images + "I");
        if (op.images >= board.imageLimit) {
          images.setSpan(new StyleSpan(Typeface.ITALIC), 0, images.length(), 0);
        }

        text.setText(
            TextUtils.concat(
                statusText, replies, " / ", images, " / ", String.valueOf(op.uniqueIps) + "P"));
      }

      return update;
    }
  }
Esempio n. 14
0
  protected SpannableString emphasisAdded(String sequence) {
    SpannableString spannable = new SpannableString(sequence);
    spannable.setSpan(
        new RelativeSizeSpan(0.9f), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannable.setSpan(
        new StyleSpan(android.graphics.Typeface.ITALIC),
        0,
        sequence.length(),
        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannable;
  }
Esempio n. 15
0
  void setGlucoseLevel(int num) {
    String ns = Integer.toString(num);
    int nn = ns.length();
    ns += " mg/dl";

    SpannableString ss1 = new SpannableString(ns);
    ss1.setSpan(new RelativeSizeSpan(2f), 0, nn, 0); // set size

    ss1.setSpan(new ForegroundColorSpan(col), 0, nn, 0); // set color

    bGlucose.setText(ss1);
  }
Esempio n. 16
0
  private CharSequence generateInfoCategoryText(String category, double sum) {

    SpannableString categorySpan = new SpannableString(category);
    SpannableString sumSpan = new SpannableString(String.valueOf((float) sum));

    categorySpan.setSpan(new RelativeSizeSpan(1.3f), 0, categorySpan.length(), 0);
    categorySpan.setSpan(new StyleSpan(Typeface.NORMAL), 0, categorySpan.length(), 0);

    sumSpan.setSpan(new RelativeSizeSpan(1.5f), 0, sumSpan.length(), 0);
    sumSpan.setSpan(new StyleSpan(Typeface.ITALIC), 0, sumSpan.length(), 0);

    return TextUtils.concat(categorySpan, "\n", sumSpan);
  }
Esempio n. 17
0
  private CharSequence generateCenterSpannableDefaultText() {

    SpannableString title = new SpannableString(getString(R.string.default_text_hole));
    SpannableString inTotal = new SpannableString(String.valueOf(this.inTotal));

    title.setSpan(new RelativeSizeSpan(1.5f), 0, title.length(), 0);
    title.setSpan(new StyleSpan(Typeface.NORMAL), 0, title.length(), 0);

    inTotal.setSpan(new RelativeSizeSpan(1.7f), 0, inTotal.length(), 0);
    inTotal.setSpan(new StyleSpan(Typeface.ITALIC), 0, inTotal.length(), 0);

    return TextUtils.concat(title, inTotal);
  }
    @Override
    public View getView(int position, View convertView, ViewGroup group) {
      if (convertView == null) {
        convertView = View.inflate(getActivity(), R.layout.buffer_line, null);
      }

      BufferEvent event = getItem(position);
      BufferEvent prevEvent = (position > 0) ? getItem(position - 1) : null;

      BufferEventItem firstItem = event.getFirstItem();
      BufferEventMessage firstItemMessage = firstItem.getMessage();

      boolean isNewDay = ((prevEvent != null) && (!firstItem.isSameDay(prevEvent.getFirstItem())));
      TextView dayView = (TextView) convertView.findViewById(R.id.day);
      dayView.setVisibility(isNewDay ? View.VISIBLE : View.GONE);
      if (isNewDay) {
        dayView.setText(mDateFormat.format(firstItemMessage.getDate()));
      }

      TextView timestampView = (TextView) convertView.findViewById(R.id.timestamp);
      TextView textView = (TextView) convertView.findViewById(R.id.text);

      Date date = firstItemMessage.getDate();
      if (date != null) {
        timestampView.setText(new SimpleDateFormat("h:mm aa").format(date));
        timestampView.setVisibility(View.VISIBLE);
      } else {
        timestampView.setVisibility(View.GONE);
      }
      CharSequence text = mRenderer.renderEvent(event);
      if ((!(mBuffer instanceof ConsoleBuffer)) && (!(text instanceof SpannableString))) {
        SpannableString span = new SpannableString(text);
        span.setSpan(
            new StyleSpan(Typeface.ITALIC), 0, span.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        span.setSpan(
            new ForegroundColorSpan(Color.GRAY),
            0,
            span.length(),
            Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        textView.setText(span);
      } else {
        textView.setText(text);
      }

      boolean highlight = firstItem.isHighlight() && (mBuffer instanceof ChannelBuffer);
      convertView
          .findViewById(R.id.inner)
          .setBackgroundColor(highlight ? mHighlightBgColor : Color.TRANSPARENT);

      return convertView;
    }
Esempio n. 19
0
 /**
  * 组合回复引用文本
  *
  * @param name
  * @param body
  * @return
  */
 public static SpannableString parseQuoteSpan(String name, String body) {
   SpannableString sp = new SpannableString("回复:" + name + "\n" + body);
   // 设置用户名字体加粗、高亮
   sp.setSpan(
       new StyleSpan(android.graphics.Typeface.BOLD),
       3,
       3 + name.length(),
       Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
   sp.setSpan(
       new ForegroundColorSpan(Color.parseColor("#0e5986")),
       3,
       3 + name.length(),
       Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
   return sp;
 }
Esempio n. 20
0
  public static SpannableStringBuilder generateMultiColoredString(GCSavedSet savedSet) {
    SpannableStringBuilder builder = new SpannableStringBuilder();

    String shortenedColorString = convertColorListToShortenedColorString(savedSet.getColors());

    List<String> stringParts = getParts(shortenedColorString, 3);
    int index = 0;
    for (String colorAbbrev : stringParts) {
      String colorString = colorAbbrev.substring(0, 2);
      String powerString = colorAbbrev.substring(2, 3);
      GCColor color = GCColorUtil.getColorUsingAbbrev(colorString);
      GCPowerLevel powerLevel = GCPowerLevelUtil.getPowerLevelUsingAbbrev(powerString);
      int[] rgbValues;
      if (color.getTitle().equalsIgnoreCase(GCConstants.COLOR_CUSTOM)) {
        rgbValues = convertRgbToPowerLevel(savedSet.getCustomColors().get(index), powerLevel);
      } else {
        rgbValues = convertRgbToPowerLevel(color.getRGBValues(), powerLevel);
      }

      if (colorString.equalsIgnoreCase("--")) {
        SpannableString spannableString = new SpannableString(colorString);
        spannableString.setSpan(
            new ForegroundColorSpan(Color.argb(255, 255, 255, 255)), 0, colorString.length(), 0);
        builder.append(spannableString);
      } else {
        SpannableString spannableString = new SpannableString(colorAbbrev);
        spannableString.setSpan(
            new ForegroundColorSpan(Color.argb(255, rgbValues[0], rgbValues[1], rgbValues[2])),
            0,
            3,
            0);
        spannableString.setSpan(
            new SuperscriptSpan(),
            colorAbbrev.length() - 1,
            colorAbbrev.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(
            new RelativeSizeSpan(0.75f),
            colorAbbrev.length() - 1,
            colorAbbrev.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.append(spannableString);
      }
      index++;
    }

    return builder;
  }
Esempio n. 21
0
  private static CharSequence getLinkSpan(
      final AstridActivity activity,
      UserActivity update,
      String targetName,
      String linkColor,
      String linkType) {
    if (TASK_LINK_TYPE.equals(linkType)) {
      final String taskId = update.getValue(UserActivity.TARGET_ID);
      if (RemoteModel.isValidUuid(taskId)) {
        SpannableString taskSpan = new SpannableString(targetName);
        taskSpan.setSpan(
            new ClickableSpan() {
              @Override
              public void onClick(View widget) {
                if (activity != null) // TODO: This shouldn't happen, but sometimes does
                activity.onTaskListItemClicked(taskId);
              }

              @Override
              public void updateDrawState(TextPaint ds) {
                super.updateDrawState(ds);
                ds.setUnderlineText(false);
              }
            },
            0,
            targetName.length(),
            Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return taskSpan;
      } else {
        return Html.fromHtml(linkify(targetName, linkColor));
      }
    }
    return null;
  }
  public void load(View v) {
    BufferedReader br = null;
    try {
      br = new BufferedReader(new FileReader(mFile));

      int len = Integer.parseInt(br.readLine());
      BackgroundColorSpan[] spans = new BackgroundColorSpan[len];
      int[] starts = new int[len];
      int[] ends = new int[len];
      for (int i = 0; i < len; i++) {
        String[] tokens = br.readLine().split(",");
        starts[i] = Integer.parseInt(tokens[0]);
        ends[i] = Integer.parseInt(tokens[1]);
        int color = Integer.parseInt(tokens[2]);
        spans[i] = new BackgroundColorSpan(color);
      }
      mText = br.readLine();

      SpannableString s = new SpannableString(mText);
      for (int i = 0; i < len; i++) {
        s.setSpan(spans[i], starts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
      }
      mTextView.setText(s);
    } catch (IOException e) {
      Log.e(TAG, "IO error", e);
    } finally {
      closeQuietly(br);
    }
  }
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      convertView = inflateLayout();
    }
    TextView title = (TextView) convertView.findViewById(R.id.tv_search_result_title);
    TextView net = (TextView) convertView.findViewById(R.id.tv_search_result_original_net);
    TextView time = (TextView) convertView.findViewById(R.id.tv_search_result_time);

    SpannableString s = new SpannableString(mList.get(position).getTitle());
    Pattern p = Pattern.compile(keyword);
    Matcher m = p.matcher(s);
    while (m.find()) {
      int start = m.start();
      int end = m.end();
      s.setSpan(
          new ForegroundColorSpan(mContext.getResources().getColor(R.color.orange)),
          start,
          end,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    title.setText(s);
    net.setText(mList.get(position).getSite());
    time.setText(formatTime(mList.get(position).getCreateTime()));
    return convertView;
  }
Esempio n. 24
0
  private void setupActionBar() {
    ActionBar actionBar = getActionBar();

    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);

    LayoutInflater inflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View actionBarCustomView = inflator.inflate(R.layout.white_action_bar, null);
    actionBarCustomView.findViewById(R.id.home_icon_container).setVisibility(View.VISIBLE);
    actionBar.setCustomView(actionBarCustomView);

    SpannableString s = new SpannableString(getString(R.string.redeem));
    s.setSpan(
        new TypefaceSpan(
            getApplicationContext(),
            CommonLib.BOLD_FONT_FILENAME,
            getResources().getColor(R.color.white),
            getResources().getDimension(R.dimen.size16)),
        0,
        s.length(),
        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    TextView title = (TextView) actionBarCustomView.findViewById(R.id.title);

    ((RelativeLayout.LayoutParams)
            actionBarCustomView.findViewById(R.id.back_icon).getLayoutParams())
        .setMargins(width / 40, 0, 0, 0);
    actionBarCustomView.findViewById(R.id.title).setPadding(width / 20, 0, width / 40, 0);
    title.setText(s);
  }
Esempio n. 25
0
  public static SpannableString getSpannableString(
      String str, int firstIndex, int endIndex, Object style) {
    SpannableString spannableString = new SpannableString(str);
    spannableString.setSpan(style, firstIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannableString;
  }
Esempio n. 26
0
  private void updateViews() {
    if (mTitle != null) {
      // Link the title to the entry URL
      SpannableString link = new SpannableString(mTitle);
      if (mUrl != null) {
        int start = 0;
        int end = mTitle.length();
        int flags = 0;
        link.setSpan(new URLSpan(mUrl), start, end, flags);
      }
      mTitleView.setText(link);

      // Show the content, or the summary if no content is available.
      String body =
          !TextUtils.isEmpty(mContent) ? mContent : !TextUtils.isEmpty(mSummary) ? mSummary : "";

      // Show the feed title in the window decorator.
      if (!TextUtils.isEmpty(mTitle)) {
        setTitle(mTitle);
      } else {
        Context context = getContext();
        setTitle(context.getText(R.string.atom_title_entry));
      }

      // Use loadDataWithBaseURL instead of loadData for unsanitized HTML:
      // http://code.google.com/p/android/issues/detail?id=1733
      mContentView.clearView();
      mContentView.loadDataWithBaseURL(null, body, MIME_TYPE, ENCODING, null);
    }
  }
Esempio n. 27
0
  protected static CharSequence buildTickerMessage(
      Context context, String address, String subject, String body) {
    String displayAddress = Contact.get(address, true).getName();

    StringBuilder buf =
        new StringBuilder(
            displayAddress == null ? "" : displayAddress.replace('\n', ' ').replace('\r', ' '));
    buf.append(':').append(' ');

    int offset = buf.length();
    if (!TextUtils.isEmpty(subject)) {
      subject = subject.replace('\n', ' ').replace('\r', ' ');
      buf.append(subject);
      buf.append(' ');
    }

    if (!TextUtils.isEmpty(body)) {
      body = body.replace('\n', ' ').replace('\r', ' ');
      buf.append(body);
    }

    SpannableString spanText = new SpannableString(buf.toString());
    spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, offset, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spanText;
  }
Esempio n. 28
0
 /** 对spanableString进行正则判断,如果符合要求,则以表情图片代替 */
 public static void dealExpression(
     Context context, SpannableString spannableString, Pattern patten, int start)
     throws Exception {
   Matcher matcher = patten.matcher(spannableString);
   while (matcher.find()) {
     String key = matcher.group();
     Log.d("Key", key);
     if (matcher.start() < start) {
       continue;
     }
     Field field =
         R.drawable.class.getDeclaredField(
             "emoji_" + key.substring(key.indexOf("]") + 1, key.lastIndexOf("[")));
     int resId = Integer.parseInt(field.get(null).toString());
     if (resId != 0) {
       Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resId);
       ImageSpan imageSpan = new ImageSpan(bitmap);
       int end = matcher.start() + key.length();
       spannableString.setSpan(
           imageSpan, matcher.start(), end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
       if (end < spannableString.length()) {
         dealExpression(context, spannableString, patten, end);
       }
       break;
     }
   }
 }
Esempio n. 29
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // 1. Create inflater
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // 2. Get rowView from inflater
    View rowView = inflater.inflate(R.layout.list_item, parent, false);
    // 3. Get the two text view from the rowView
    labelView = (TextView) rowView.findViewById(R.id.anchor_name);
    valueView = (TextView) rowView.findViewById(R.id.client_name);
    descView = (TextView) rowView.findViewById(R.id.campaign_id);

    labelView.setOnClickListener(
        new AnchorListener(
            itemsArrayList.get(position).getAnchorName(),
            itemsArrayList.get(position).getClientName(),
            itemsArrayList.get(position).getAnchorCreationDate(),
            itemsArrayList.get(position).getClientWebsiteAddress(),
            itemsArrayList.get(position).getClientInfo()));
    SpannableString content = new SpannableString(itemsArrayList.get(position).getAnchorName());
    content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
    labelView.setText(content);
    // 4. Set the text for textView
    valueView.setText(itemsArrayList.get(position).getClientName());
    descView.setText(itemsArrayList.get(position).getCampaignStatusDescription());
    // 5. return rowView
    return rowView;
  }
Esempio n. 30
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    SpannableString s = new SpannableString("Pregled svih ruta");
    s.setSpan(
        new TypefaceSpan(this, "Choplin.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(s);

    mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);

    LinearLayoutManager llm = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(llm);

    NavigationDrawerFragment drawerFragment =
        (NavigationDrawerFragment)
            getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
    drawerFragment.setUp(
        R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);

    initializeData();
  }