示例#1
0
  public void parse(TimeLineModel data) {
    this.mData = data;
    if (data.hasPics || data.hasRepostPics) {
      mPic.setVisibility(GONE);
      mGridView.setVisibility(VISIBLE);
      mGridView.setAdapter(new GridPicsAdapter(getContext(), data.pics));
      LayoutParams lp = (LayoutParams) mCommentCount.getLayoutParams();
      lp.addRule(BELOW, R.id.timeline_listitem_picgrid);
      mCommentCount.setLayoutParams(lp);
    } else {
      mGridView.setVisibility(GONE);
      LayoutParams lp = (LayoutParams) mCommentCount.getLayoutParams();
      lp.addRule(BELOW, R.id.timeline_listitem_pic);
      mCommentCount.setLayoutParams(lp);
      if (data.hasPic || data.hasRepostPic) {
        mPic.setVisibility(VISIBLE);
        mPic.setGif(TextUtils.isGifLink(data.pics.get(0)));
        if (NetworkUtils.isWifi(getContext())) {
          ImageLoader.getInstance()
              .displayImage(data.pics.get(0).replace("thumbnail", "bmiddle"), mPic);
        } else {
          ImageLoader.getInstance().displayImage(data.pics.get(0), mPic);
        }
      } else {
        mPic.setVisibility(GONE);
      }
    }
    if (data.topics.size() == 0) {
      mTopic.setVisibility(INVISIBLE);
    } else {
      mTopic.setVisibility(VISIBLE);
      mTopic.setText(data.topics.get(0));
    }
    if (data.hasRepost) {
      mLine.setVisibility(VISIBLE);
      mRepostName.setVisibility(VISIBLE);
      mRepostText.setVisibility(VISIBLE);
      mRepostName.setText(data.repostName);
      mRepostText.setText(data.repostText);
    } else {
      mLine.setVisibility(GONE);
      mRepostName.setVisibility(GONE);
      mRepostText.setVisibility(GONE);
    }
    if (data.commentCount != 0) {
      mCommentCount.setText(data.commentCount + "");
    } else {
      mCommentCount.setText("评论");
    }
    if (data.repostCount != 0) {
      mRepostCount.setText(data.repostCount + "");
    } else {
      mRepostCount.setText("转发");
    }

    mText.setText(data.text);
    mName.setText(data.name);
    mTime.setText(data.time);
    ImageLoader.getInstance().displayImage(data.headUrl, mHead, mOptions);
  }
  void updateHeader() {
    if (taskListAdapter.isEmpty()) {
      header.getLayoutParams().height = 0;
      header.setVisibility(View.GONE);

    } else {
      header.getLayoutParams().height = 60;
      header.setVisibility(View.VISIBLE);
    }
  }
示例#3
0
  @Override
  public void onStateChange(View view, HideablePartBehavior.State state) {
    switch (state) {
      case COLLAPSED:
        if (collapsed) return;
        if (getView() == null) return;
        collapsed = true;
        ((RelativeLayout.LayoutParams) send.getLayoutParams())
                .getRules()[RelativeLayout.ALIGN_BOTTOM] =
            R.id.text;
        ((RelativeLayout.LayoutParams) target.getLayoutParams())
                .getRules()[RelativeLayout.ALIGN_BOTTOM] =
            0;
        ((RelativeLayout.LayoutParams) text.getLayoutParams()).getRules()[RelativeLayout.LEFT_OF] =
            R.id.send;

        ((CoordinatorLayout.LayoutParams) commentFrame.getLayoutParams()).rightMargin =
            (int) (getView().getResources().getDisplayMetrics().density * 59);

        root.invalidate();
        text.clearFocus();
        text.setSingleLine(true);
        text.setVerticalScrollBarEnabled(false);

      case HIDDEN:
        hideKeyboard();
        break;

      case EXPANDED:
        if (!collapsed) return;
        if (getView() == null) return;
        collapsed = false;
        ((RelativeLayout.LayoutParams) send.getLayoutParams())
                .getRules()[RelativeLayout.ALIGN_BOTTOM] =
            0;
        ((RelativeLayout.LayoutParams) target.getLayoutParams())
                .getRules()[RelativeLayout.ALIGN_BOTTOM] =
            R.id.send;
        ((RelativeLayout.LayoutParams) text.getLayoutParams()).getRules()[RelativeLayout.LEFT_OF] =
            0;

        ((CoordinatorLayout.LayoutParams) commentFrame.getLayoutParams()).rightMargin = 0;
        root.invalidate();
        text.setVerticalScrollBarEnabled(true);
        text.setSingleLine(false);
        text.setMaxLines(9);

        showKeyboard();
        break;
    }
  }
示例#4
0
  protected void updateMargins() {
    //noinspection ConstantConditions
    final int margin = getResources().getDimensionPixelSize(R.dimen.space_normal);

    final boolean titleVisible = title_TV.getVisibility() == VISIBLE;
    final boolean secondaryTitleVisible = secondaryTitle_TV.getVisibility() == VISIBLE;
    final boolean subTitleVisible = subTitle_TV.getVisibility() == VISIBLE;
    final boolean contentVisible = content_FL.getVisibility() == VISIBLE;
    final boolean iconVisible = icon_IV.getVisibility() == VISIBLE;

    MarginLayoutParams lp = (MarginLayoutParams) subTitle_TV.getLayoutParams();
    //noinspection ConstantConditions
    lp.topMargin = titleVisible || secondaryTitleVisible ? margin : 0;

    lp = (MarginLayoutParams) content_FL.getLayoutParams();
    //noinspection ConstantConditions
    lp.topMargin = titleVisible || secondaryTitleVisible || subTitleVisible ? margin : 0;

    lp = (MarginLayoutParams) icon_IV.getLayoutParams();
    //noinspection ConstantConditions
    lp.topMargin = titleVisible || secondaryTitleVisible || subTitleVisible ? margin : 0;

    lp = (MarginLayoutParams) listContainer_LL.getLayoutParams();
    //noinspection ConstantConditions
    lp.topMargin =
        titleVisible || secondaryTitleVisible || subTitleVisible || contentVisible || iconVisible
            ? margin
            : 0;
  }
 private void cutTextView(TextView textView) {
   if (textView.getWidth() != mWidth) {
     ViewGroup.LayoutParams lp = textView.getLayoutParams();
     lp.width = mWidth;
     textView.setLayoutParams(lp);
   }
 }
  private void init() {
    setOrientation(LinearLayout.VERTICAL);

    textView = new TextView(getContext());
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    textView.setTextColor(0xff3b84c0);
    addView(textView);
    LayoutParams layoutParams = (LayoutParams) textView.getLayoutParams();
    layoutParams.width = LayoutParams.WRAP_CONTENT;
    layoutParams.height = LayoutParams.WRAP_CONTENT;
    layoutParams.leftMargin = AndroidUtilities.dp(8);
    layoutParams.rightMargin = AndroidUtilities.dp(8);
    layoutParams.topMargin = AndroidUtilities.dp(6);
    layoutParams.bottomMargin = AndroidUtilities.dp(4);
    if (LocaleController.isRTL) {
      textView.setGravity(Gravity.RIGHT);
      layoutParams.gravity = Gravity.RIGHT;
    }
    textView.setLayoutParams(layoutParams);

    View view = new View(getContext());
    view.setBackgroundColor(0xff6caae4);
    addView(view);
    layoutParams = (LayoutParams) view.getLayoutParams();
    layoutParams.weight = LayoutParams.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(1);
    view.setLayoutParams(layoutParams);
  }
示例#7
0
 private void cutTextView() {
   if (mTextField.getWidth() != getMeasuredWidth()) {
     ViewGroup.LayoutParams lp = mTextField.getLayoutParams();
     lp.width = getMeasuredWidth();
     mTextField.setLayoutParams(lp);
   }
 }
示例#8
0
  @Override
  protected void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    int indicationBottomMargin =
        getResources().getDimensionPixelSize(R.dimen.keyguard_indication_margin_bottom);
    MarginLayoutParams mlp = (MarginLayoutParams) mIndicationText.getLayoutParams();

    /// M: Since we need to add a ECC button below Indication Text,
    ///   we remove this part code due to it will make a significant/weird space between Indication
    // Text & ECC Button.
    /*
    if (mlp.bottomMargin != indicationBottomMargin) {
        mlp.bottomMargin = indicationBottomMargin;
        mIndicationText.setLayoutParams(mlp);
    }*/

    // Respect font size setting.
    mIndicationText.setTextSize(
        TypedValue.COMPLEX_UNIT_PX,
        getResources()
            .getDimensionPixelSize(com.android.internal.R.dimen.text_size_small_material));

    /// M: Fix ALPS01868023, reload resources when locale changed.
    getCameraView()
        .setContentDescription(getResources().getString(R.string.accessibility_camera_button));
    getLockIcon()
        .setContentDescription(getResources().getString(R.string.accessibility_unlock_button));
    getPhoneView()
        .setContentDescription(getResources().getString(R.string.accessibility_phone_button));
  }
  /**
   * @param textview
   * @return
   */
  private String adjustTextLength(TextView tv) {
    if (tv == null) {
      return "";
    }
    String input = tv.getText().toString();
    String result = input;
    String newtext = input;
    int lastSpaceIndex = 0;
    ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) tv.getLayoutParams();
    Paint p = tv.getPaint();
    Rect bound = new Rect();
    p.getTextBounds(input, 0, input.length() - 1, bound);
    float textHeight = p.getTextSize();
    float multiLine = (((lp.height - tv.getPaddingTop() - tv.getPaddingBottom()) / textHeight));
    float availableW = (lp.width - tv.getPaddingLeft() - tv.getPaddingRight()) * (multiLine + 0.2f);

    do {

      newtext = (String) TextUtils.ellipsize(result, tv.getPaint(), availableW, TruncateAt.END);
      if (!newtext.equals(result)) {
        lastSpaceIndex = newtext.lastIndexOf(" ");
        if (lastSpaceIndex > 0) {
          result = newtext.substring(0, lastSpaceIndex) + "...";
        } else {
          break;
        }
      } else {
        break;
      }
    } while (false);

    GKIMLog.lf(null, 0, TAG + "=>adjust title from: " + input + " to: " + result);
    tv.setText(result);
    return result;
  }
示例#10
0
  private void moveToolbar(boolean moveTop) {
    if (toolbarOnTop == moveTop) {
      return;
    }
    toolbarOnTop = moveTop;
    if (toolbarOnTop) {
      offsetDueToToolBarPosition = toolbarHeight;
    } else {
      offsetDueToToolBarPosition = 0;
    }

    RelativeLayout.LayoutParams p = (RelativeLayout.LayoutParams) zoomedImageView.getLayoutParams();
    RelativeLayout.LayoutParams pChangeZoomFactorButton =
        (RelativeLayout.LayoutParams) changeZoomFactorButton.getLayoutParams();
    RelativeLayout.LayoutParams pCloseButton =
        (RelativeLayout.LayoutParams) closeButton.getLayoutParams();

    if (moveTop) {
      p.addRule(RelativeLayout.BELOW, R.id.change_zoom_factor);
      pChangeZoomFactorButton.addRule(RelativeLayout.BELOW, 0);
      pCloseButton.addRule(RelativeLayout.BELOW, 0);
    } else {
      p.addRule(RelativeLayout.BELOW, 0);
      pChangeZoomFactorButton.addRule(RelativeLayout.BELOW, R.id.zoomed_image_view);
      pCloseButton.addRule(RelativeLayout.BELOW, R.id.zoomed_image_view);
    }
    pChangeZoomFactorButton.addRule(RelativeLayout.ALIGN_LEFT, R.id.zoomed_image_view);
    pCloseButton.addRule(RelativeLayout.ALIGN_RIGHT, R.id.zoomed_image_view);
    zoomedImageView.setLayoutParams(p);
    changeZoomFactorButton.setLayoutParams(pChangeZoomFactorButton);
    closeButton.setLayoutParams(pCloseButton);
  }
示例#11
0
  public static void tryFlowText(
      SpannableStringBuilder ss, View thumbnailView, TextView messageView, Display display) {
    // There is nothing I can do for older versions, so just return
    if (!mNewClassAvailable) return;

    // Get height and width of the image and height of the text line
    thumbnailView.measure(display.getWidth(), display.getHeight());
    int height = thumbnailView.getMeasuredHeight();
    int width = thumbnailView.getMeasuredWidth();
    float textLineHeight = messageView.getPaint().getTextSize();

    // Set the span according to the number of lines and width of the image
    int lines = (int) Math.round(height / textLineHeight);
    // For an html text you can use this line: SpannableStringBuilder ss =
    // (SpannableStringBuilder)Html.fromHtml(text);
    ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(), 0);
    messageView.setText(ss);

    // Align the text with the image by removing the rule that the text is
    // to the right of the image
    RelativeLayout.LayoutParams params =
        (RelativeLayout.LayoutParams) messageView.getLayoutParams();
    int[] rules = params.getRules();
    rules[RelativeLayout.RIGHT_OF] = 0;
  }
  private void addIconTabBådeTekstOgBillede(
      final int position, int resId, Bitmap res, String title) {
    FrameLayout tabfl = new FrameLayout(getContext());
    if (Build.VERSION.SDK_INT > 11) tabfl.setLayoutTransition(new LayoutTransition());
    ImageView tabi = new ImageView(getContext());
    tabi.setContentDescription(title);
    if (res != null) {
      tabi.setImageBitmap(res);
      tabi.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
      tabi.setAdjustViewBounds(true);
    } else {
      tabi.setImageResource(resId);
    }
    tabi.setVisibility(View.GONE);
    TextView tabt = new TextView(getContext());
    tabt.setText(title);
    tabt.setTypeface(App.skrift_gibson);
    tabt.setGravity(Gravity.CENTER);
    tabt.setSingleLine();

    tabfl.addView(tabi);
    tabfl.addView(tabt);

    LayoutParams lp = (LayoutParams) tabi.getLayoutParams();
    lp.gravity = Gravity.CENTER;
    lp = (LayoutParams) tabt.getLayoutParams();
    lp.width = lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
    lp.gravity = Gravity.CENTER;

    addTab(position, tabfl);
  }
示例#13
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    final View c = getChildAt(0);

    if (c != null) {
      final TextView tab = (TextView) c;
      LayoutParams layoutParams = (LayoutParams) tab.getLayoutParams();
      final int widthSpec = MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.EXACTLY);
      final int heightSpec = MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY);
      tab.measure(widthSpec, heightSpec);

      setMeasuredDimension(
          resolveSize(0, widthMeasureSpec),
          resolveSize(
              tab.getMeasuredHeight() + this.getPaddingTop() + this.getPaddingBottom(),
              heightMeasureSpec));

    } else {
      setMeasuredDimension(
          resolveSize(0, widthMeasureSpec),
          resolveSize(this.getPaddingTop() + this.getPaddingBottom(), heightMeasureSpec));
    }

    // first time measuring, set outside offset (if not set manually),
    // measure children and calculate initial positions
    if (isFirstMeasurement) {
      isFirstMeasurement = false;
      if (mOutsideOffset < 0) mOutsideOffset = getMeasuredWidth();

      measureChildren();

      calculateNewPositions(true);
    }
  }
示例#14
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);

    int length = width > height ? height : width;

    view.getLayoutParams().width = length;
    view.getLayoutParams().height = length;

    length = (int) (length / 1.41f);

    mFloatFrame.getLayoutParams().height = length;
    mFloatFrame.getLayoutParams().width = length;

    //        mEditText.getLayoutParams().height = length;
    //        mEditText.getLayoutParams().width = length;
    mTextView.getLayoutParams().height = length;
    mTextView.getLayoutParams().width = length;

    //        mEditText.getLayoutParams().height = height / 2;
    //        mEditText.getLayoutParams().width = width / 3 * 2;
    //        mTextView.getLayoutParams().height = height / 2;
    //        mTextView.getLayoutParams().width = width / 3 * 2;
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    this.innerView.measure(widthMeasureSpec, heightMeasureSpec);
    ImageView iv1 = (ImageView) this.innerView.findViewById(R.id.top_item_1);
    LayoutParams lp = iv1.getLayoutParams();
    lp.height = iv1.getMeasuredWidth();
    iv1.setLayoutParams(lp);

    ImageView iv2 = (ImageView) this.innerView.findViewById(R.id.top_item_2);
    lp = iv2.getLayoutParams();
    lp.height = iv2.getMeasuredWidth();
    iv2.setLayoutParams(lp);

    ImageView iv3 = (ImageView) this.innerView.findViewById(R.id.top_item_3);
    lp = iv3.getLayoutParams();
    lp.height = iv3.getMeasuredWidth();
    iv3.setLayoutParams(lp);

    TextView tv = (TextView) this.innerView.findViewById(R.id.top_item_others);
    lp = tv.getLayoutParams();
    lp.height = iv3.getMeasuredWidth();
    tv.setLayoutParams(lp);

    this.innerView.measure(widthMeasureSpec, heightMeasureSpec);

    this.setMeasuredDimension(
        this.innerView.getMeasuredWidth(), this.innerView.getMeasuredHeight());
  }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   FrameLayout frameLayout = new FrameLayout(MainActivity.this);
   TextView textView = new TextView(MainActivity.this);
   textView.setText(strs.get(position));
   frameLayout.addView(textView);
   textView.getLayoutParams().height = (int) dp2px(30);
   return frameLayout;
 }
  protected TextView buttonClear(View topView) {
    TextView v = getNumberButton(R.string.other_calculater_button_clear, -1);
    LayoutParams params = (LayoutParams) v.getLayoutParams();
    params.addRule(BELOW, topView.getId());
    params.addRule(ALIGN_PARENT_RIGHT);
    v.setLayoutParams(params);

    return v;
  }
  private TextView getRightOfCenterNumber(int resourceText, View centerView, int number) {
    TextView v = getNumberButton(resourceText, number);
    LayoutParams params = (LayoutParams) v.getLayoutParams();
    params.addRule(RIGHT_OF, centerView.getId());
    params.addRule(ALIGN_TOP, centerView.getId());
    params.addRule(ALIGN_PARENT_RIGHT);
    v.setLayoutParams(params);

    return v;
  }
示例#19
0
 @Override
 public void handleMessage(Message msg) {
   Paint p = logv.getPaint();
   float width = p.measureText(MemoryLog.longedsLine());
   if (width > maxWidth) {
     maxWidth = width;
     logv.getLayoutParams().width = (int) maxWidth;
   }
   logv.setText(MemoryLog.allLog());
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_measure_reaction);

    arrowImageView = (ImageView) findViewById(R.id.arrowImageView);
    timeCounterTextView = (TextView) findViewById(R.id.timeCounterTextView);
    LinearLayout cameraPreviewLinLayout = (LinearLayout) findViewById(R.id.cameraPreviewLinLayout);

    secondsLeft = 5;
    timeCounterTextView.setText(String.valueOf(secondsLeft));

    dbTopValue =
        getSharedPreferences(Constants.SHARED_PREF_FILENAME, Context.MODE_PRIVATE)
            .getInt(Constants.SHARED_PREF_TOP_DB_VALUE, -1);
    isDbLevelReached = false;
    lastMeterDegree = 0f;
    moveMeterArrow(lastMeterDegree);

    soundLevelValue = new int[7];
    isApplicationInterrupted = false;

    // Create our Preview view and set it as the content of our activity.
    preview = new CameraPreview(this);
    List<Camera.Size> tmpList = preview.getCamera().getParameters().getSupportedPreviewSizes();
    RelativeLayout.LayoutParams cameraLP =
        (RelativeLayout.LayoutParams) cameraPreviewLinLayout.getLayoutParams();
    int maxWidthResolution = tmpList.get(0).width;
    int maxHeightResolution = tmpList.get(0).height;

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int screenWidth = metrics.widthPixels;
    int screenHeight = metrics.heightPixels;

    // calculation of the best height and shift to the left
    float scale = (float) screenHeight / (float) maxHeightResolution;
    cameraLP.height = (int) (maxHeightResolution * scale);
    cameraLP.width = (int) (maxWidthResolution * scale);
    // shift to the left (center camera)
    int halfScreenWidth = screenWidth / 2;
    int shiftPx = cameraLP.width - halfScreenWidth;
    int leftShiftPx = shiftPx / 2; // make right and left invisible area equal size

    cameraLP.leftMargin = (leftShiftPx * -1);

    cameraPreviewLinLayout.setLayoutParams(cameraLP);
    cameraPreviewLinLayout.addView(preview); // add camera

    // center time counter
    RelativeLayout.LayoutParams counterLP =
        (RelativeLayout.LayoutParams) timeCounterTextView.getLayoutParams();
    counterLP.topMargin = (screenHeight / 10) - (counterLP.height / 2);
    counterLP.leftMargin = (screenWidth / 4) - (counterLP.width / 2);
  }
  protected TextView numberZero(View rightView) {
    TextView v = getNumberButton(R.string.other_calculater_number_zero, 0);
    LayoutParams params = (LayoutParams) v.getLayoutParams();
    params.addRule(CENTER_HORIZONTAL);
    params.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params.addRule(ALIGN_TOP, rightView.getId());
    params.addRule(LEFT_OF, rightView.getId());
    params.addRule(ALIGN_PARENT_LEFT);

    return v;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_guzhizhengsheng);
    // 获取Activity中的TabHost组件
    TabHost tabHost = getTabHost();
    // 创建第一个Tab页
    TabSpec tab1 =
        tabHost
            .newTabSpec("tab1")
            .setIndicator("症状及措施") // 设置标题
            .setContent(R.id.tab01); // 设置内容
    // 添加第二个标签页
    tabHost.addTab(tab1);

    TabSpec tab2 =
        tabHost
            .newTabSpec("tab2")
            .setIndicator("推荐药品") // 设置标题
            .setContent(R.id.tab02); // 设置内容
    // 添加第二个标签页
    tabHost.addTab(tab2);
    // 修改选项卡标签格式
    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
      TextView textView =
          (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
      textView.setTextSize(25);
      textView.setGravity(Gravity.CENTER);
      textView.getLayoutParams().height = LayoutParams.MATCH_PARENT;
      textView.getLayoutParams().width = LayoutParams.MATCH_PARENT;
    }
    List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();
    for (int i = 0; i < names.length; i++) {
      Map<String, Object> listItem = new HashMap<String, Object>();
      listItem.put("header", imageIds[i]);
      listItem.put("personName", names[i]);
      listItem.put("desc", descs[i]);
      listItems.add(listItem);
    }
    //        创建一个simpleAdapter
    SimpleAdapter simpleAdapter =
        new SimpleAdapter(
            this,
            listItems,
            R.layout.medicine_item,
            new String[] {"personName", "header", "desc"},
            // new String[] {"personName","header"},
            new int[] {R.id.name, R.id.header, R.id.desc});
    // new int[] {R.id.name,R.id.header});
    ListView list = (ListView) findViewById(R.id.lv_guzhizengsheng_items);
    //        为ListView设置Adapter
    list.setAdapter(simpleAdapter);
  }
  // return a group view with a custom layout
  public View getGroupView(
      int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    if (convertView == null) {
      LayoutInflater infl =
          (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView =
          infl.inflate(R.layout.row_custom_expandable_listview_adapter_group_layout, null);
    }

    TextView tv1 = (TextView) convertView.findViewById(R.id.tv1);
    TextView tv2 = (TextView) convertView.findViewById(R.id.tv2);
    TextView tv3 = (TextView) convertView.findViewById(R.id.tv3);
    TextView tv4 = (TextView) convertView.findViewById(R.id.tv4);

    // used to set the right hight for the fontsize so the text wont go off
    // screen
    TextView tvHeigth = (TextView) convertView.findViewById(R.id.textViewHeight);

    LinearLayout ll = (LinearLayout) convertView.findViewById(R.id.LinearLayoutInsuline);

    tv1.setTextSize(fontSize);
    tv2.setTextSize(fontSize - 7);

    tv3.setTextSize(fontSize);
    tv4.setTextSize(fontSize - 7);

    LayoutParams params = tvHeigth.getLayoutParams();
    switch (displayMetrics) {
      case DisplayMetrics.DENSITY_HIGH:
        params.height = (5 * fontSize);
        break;
      default:
        params.height = (4 * fontSize);
        break;
    }
    tvHeigth.setLayoutParams(params);

    if (calculatedInsuline.equals("")) {
      ll.setVisibility(View.GONE);
    } else {
      ll.setVisibility(View.VISIBLE);
      tv1.setText(calculatedInsuline);
      tv2.setText(insulineRatio);
    }

    tv3.setText(defaultCalculated);
    tv4.setText(defaultCalculatedText);

    tv3.setBackgroundColor(getRightColor(defaultValue));

    return convertView;
  }
  private void initLettersRows(final View view) {
    int max = getScreenMaxHeight();

    DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics();
    int dpMax = (int) ((max / displayMetrics.density) + 0.5);

    if (dpMax > 480) {
      LinearLayout lastNumbersContainer =
          (LinearLayout) view.findViewById(R.id.housenumber_container);

      LinearLayout.LayoutParams params =
          (LinearLayout.LayoutParams) lastNumbersContainer.getLayoutParams();
      // Changes the height and width to the specified *pixels*
      params.height = params.height * 3 / 2;
      lastNumbersContainer.setLayoutParams(params);
      textlastHouseNumbers3.setVisibility(View.VISIBLE);
      FrameLayout.LayoutParams number2Params =
          (FrameLayout.LayoutParams) textlastHouseNumbers2.getLayoutParams();
      number2Params.gravity = Gravity.CENTER_VERTICAL;

    } else {
      textlastHouseNumbers3.setVisibility(View.GONE);
    }

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
        || dpMax >= 580) {
      // do nothing
    } else if (dpMax > 480) {
      // remove one line
      // view.findViewById(R.id.keysRow3).setVisibility(View.GONE);
      ((Button) view.findViewById(R.id.buttonJ)).setText(localizer.getString("buttonSep1"));
      ((Button) view.findViewById(R.id.buttonK)).setText(localizer.getString("buttonSep2"));
      ((Button) view.findViewById(R.id.buttonL)).setText(localizer.getString("buttonSep3"));
    } else {
      // remove two lines
      view.findViewById(R.id.keysRow2).setVisibility(View.GONE);
      view.findViewById(R.id.keysRow3).setVisibility(View.GONE);
      ((Button) view.findViewById(R.id.buttonD)).setText(localizer.getString("buttonSep1"));
      ((Button) view.findViewById(R.id.buttonE)).setText(localizer.getString("buttonSep2"));
      ((Button) view.findViewById(R.id.buttonF)).setText(localizer.getString("buttonSep3"));
      if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        View lfrRow = view.findViewById(R.id.lfrRow);
        LayoutParams params = (LayoutParams) lfrRow.getLayoutParams();
        if (KeypadMapperApplication.getInstance().getSettings().isLayoutOptimizationEnabled()) {
          params.weight = 1.55f;
        } else {
          params.weight = 1.4f;
        }
        lfrRow.setLayoutParams(params);
      }
    }
  }
 /** Center the action bar */
 protected void centerActionBarTitle() {
   int titleId;
   titleId = getResources().getIdentifier("action_bar_title", "id", "android");
   TextView titleTextView = (TextView) findViewById(titleId);
   DisplayMetrics metrics = getResources().getDisplayMetrics();
   // Fetch layout parameters of titleTextView (LinearLayout.LayoutParams : Info from
   // HierarchyViewer)
   LinearLayout.LayoutParams txvPars = (LinearLayout.LayoutParams) titleTextView.getLayoutParams();
   txvPars.gravity = Gravity.CENTER_HORIZONTAL;
   txvPars.width = metrics.widthPixels;
   titleTextView.setLayoutParams(txvPars);
   titleTextView.setGravity(Gravity.CENTER);
 }
  @Override
  public void initView(Bundle savedInstanceState) {

    RegisterActivity.this.setSupportActionBar(toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_icon);

    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) toolbarTitleTv.getLayoutParams();
    params.rightMargin = DensityUtil.getActionBarSize(RegisterActivity.this);
    toolbarTitleTv.setVisibility(View.VISIBLE);
    toolbarTitleTv.setText("注 册");

    RegisterActivity.this.combineLatestEvents();
  }
  private TextView getCenterNumber(int resourceText, View topView, int number) {
    TextView v = getNumberButton(resourceText, number);
    LayoutParams params = (LayoutParams) v.getLayoutParams();
    params.addRule(CENTER_HORIZONTAL);
    if (topView == null) {
      params.addRule(ALIGN_PARENT_TOP);
    } else {
      params.addRule(BELOW, topView.getId());
    }
    v.setLayoutParams(params);

    return v;
  }
  public void bindData(String header, boolean withTopMargin) {
    mText.setText(header);

    int topMargin;
    if (withTopMargin) {
      topMargin = mLargeTopMargin;
    } else {
      topMargin = mSmallTopMargin;
    }

    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mText.getLayoutParams();
    layoutParams.setMargins(0, topMargin, 0, 0);
  }
示例#29
0
  /** Initialize necessary items such as database(helper), lists etc. */
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.home_layout, container, false);

    // Retrieve databasehelper
    recipesHelper = ((MainActivity) this.getActivity()).getDatabaseHelper();

    // Initialize textview with introduction
    TextView tv = (TextView) v.findViewById(R.id.text);
    tv.setText(
        "Welcome to the Hotmeals App!"
            + '\n'
            + "You can search for recipes by pressing the search tab,"
            + '\n'
            + "or view recipes that you've marked as a favorite by pressing the favorites tab!"
            + '\n'
            + "Or if you like, browse the recipes you've recently viewed down below.");

    // Set top margins so that no overlap occurs
    MarginLayoutParams margins = (MarginLayoutParams) tv.getLayoutParams();
    margins.topMargin = ((MainActivity) this.getActivity()).getTabBarHeight();
    tv.setLayoutParams(margins);
    recipesReadableDatabase = recipesHelper.getReadableDatabase();

    // Init database list
    Cursor cursor = getRecentRecipes();
    recentRecipes = getRecipesFromCursor(cursor);
    cursor.close();

    // Done with database
    recipesReadableDatabase.close();

    // Populate list
    final ListView recentsList = (ListView) v.findViewById(R.id.recentsList);
    RecipeListViewAdapter adapter =
        new RecipeListViewAdapter(getActivity(), recipeArrayListToArray(recentRecipes));
    recentsList.setAdapter(adapter);

    // When recipe in list clicked, go to recipe
    recentsList.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Recipe recipe = (Recipe) recentsList.getItemAtPosition(position);
            goToRecipe(recipe);
          }
        });

    return v;
  }
示例#30
0
 public void setupStatusBar() {
   RelativeLayout.LayoutParams layoutParams =
       (RelativeLayout.LayoutParams) headerText1.getLayoutParams();
   layoutParams.topMargin += getStatusBarHeight(getApplicationContext());
   headerText1.setLayoutParams(layoutParams);
   SystemBarTintManager tintManager = new SystemBarTintManager(this);
   // enable status bar tint
   tintManager.setStatusBarTintEnabled(true);
   // enable navigation bar tint
   tintManager.setNavigationBarTintEnabled(true);
   tintManager.setStatusBarAlpha(0.2f);
   tintManager.setNavigationBarAlpha(0.2f);
   tintManager.setTintAlpha(0.2f);
   tintManager.setTintColor(Color.parseColor("#0069FF"));
 }