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);
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int itemWidth;
    if (AndroidUtilities.isTablet()) {
      itemWidth =
          (AndroidUtilities.dp(490) - ((albumsCount + 1) * AndroidUtilities.dp(4))) / albumsCount;
    } else {
      itemWidth =
          (AndroidUtilities.displaySize.x - ((albumsCount + 1) * AndroidUtilities.dp(4)))
              / albumsCount;
    }

    for (int a = 0; a < albumsCount; a++) {
      LayoutParams layoutParams = (LayoutParams) albumViews[a].getLayoutParams();
      layoutParams.topMargin = AndroidUtilities.dp(4);
      layoutParams.leftMargin = (itemWidth + AndroidUtilities.dp(4)) * a;
      layoutParams.width = itemWidth;
      layoutParams.height = itemWidth;
      layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
      albumViews[a].setLayoutParams(layoutParams);
    }

    super.onMeasure(
        widthMeasureSpec,
        MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(4) + itemWidth, MeasureSpec.EXACTLY));
  }
  private void addDivider(boolean iOSStylable) {
    ImageView divider = new ImageView(mContext);
    divider.setScaleType(ScaleType.FIT_XY);
    divider.setBackgroundColor(getResources().getColor(R.color.setting_view_item_bg_normal));
    divider.setImageResource(R.drawable.divider);

    LayoutParams lps = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    lps.gravity = Gravity.RIGHT;

    if (iOSStyleable) {
      int paddingLeft =
          (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_PX,
                      getResources().getDimensionPixelSize(R.dimen.setting_view_min_height),
                      getResources().getDisplayMetrics())
              + (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_PX,
                      getResources().getDimensionPixelSize(R.dimen.setting_view_lr_padding),
                      getResources().getDisplayMetrics());
      divider.setPadding(paddingLeft, 0, 0, 0);
    }

    addView(divider, lps);
  }
  @Override
  protected void onFinishInflate() {
    super.onFinishInflate();

    View view = LayoutInflater.from(getContext()).inflate(R.layout.load_view, null);

    mDistance = dip2px(54f);

    LayoutParams layoutParams =
        new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    layoutParams.gravity = Gravity.CENTER;

    shapeLoadingView = (ShapeLoadingView) view.findViewById(R.id.shapeLoadingView);

    indicationIm = (ImageView) view.findViewById(R.id.indication);
    loadTextView = (TextView) view.findViewById(R.id.promptTV);

    setLoadingText(loadText);

    addView(view, layoutParams);

    this.postDelayed(
        new Runnable() {
          @Override
          public void run() {
            freeFall();
          }
        },
        900);
  }
  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);
  }
 public void updateResources() {
   if (mContentHolder != null) {
     final LayoutParams lp = (LayoutParams) mContentHolder.getLayoutParams();
     lp.width = getResources().getDimensionPixelSize(R.dimen.notification_panel_width);
     lp.gravity = getResources().getInteger(R.integer.notification_panel_layout_gravity);
     mContentHolder.setLayoutParams(lp);
   }
 }
示例#7
0
    private LinearLayout getView(int position, OnClickListener ocL, Context context) {
      Bitmap logo;
      String label;
      OnClickListener listener;
      if (beans[position] instanceof Platform) {
        logo = getIcon((Platform) beans[position]);
        label = getName((Platform) beans[position]);
        listener = ocL;
      } else {
        logo = ((CustomerLogo) beans[position]).enableLogo;
        label = ((CustomerLogo) beans[position]).label;
        listener = ocL;
      }

      LinearLayout ll = new LinearLayout(context);
      ll.setOrientation(LinearLayout.VERTICAL);

      ImageView iv = new ImageView(context);
      int dp_5 = com.mob.tools.utils.R.dipToPx(context, 5);
      iv.setPadding(dp_5, dp_5, dp_5, dp_5);
      iv.setScaleType(ScaleType.CENTER_INSIDE);
      LayoutParams lpIv = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
      lpIv.setMargins(dp_5, dp_5, dp_5, dp_5);
      lpIv.gravity = Gravity.CENTER_HORIZONTAL;
      iv.setLayoutParams(lpIv);
      iv.setImageBitmap(logo);
      ll.addView(iv);

      TextView tv = new TextView(context);
      tv.setTextColor(0xff000000);
      tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
      tv.setSingleLine();
      tv.setIncludeFontPadding(false);
      LayoutParams lpTv = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
      lpTv.gravity = Gravity.CENTER_HORIZONTAL;
      lpTv.weight = 1;
      lpTv.setMargins(dp_5, 0, dp_5, dp_5);
      tv.setLayoutParams(lpTv);
      tv.setText(label);
      ll.addView(tv);
      ll.setOnClickListener(listener);

      return ll;
    }
 // Sets the properties of the drawer, after the navigationView has been set.
 /* package */ void setDrawerProperties() {
   if (this.getChildCount() == 2) {
     View drawerView = this.getChildAt(1);
     LayoutParams layoutParams = (LayoutParams) drawerView.getLayoutParams();
     layoutParams.gravity = mDrawerPosition;
     layoutParams.width = mDrawerWidth;
     drawerView.setLayoutParams(layoutParams);
     drawerView.setClickable(true);
   }
 }
  /**
   * Bind an instance of the <code>Chat</code> class to our view. This method is called by <code>
   * FirebaseListAdapter</code> when there is a data change, and we are given an instance of a View
   * that corresponds to the layout that we passed to the constructor, as well as a single <code>
   * Chat</code> instance that represents the current data to bind.
   *
   * @param view A view instance corresponding to the layout we passed to the constructor.
   * @param chat An instance representing the current state of a chat message
   */
  @Override
  protected void populateView(View view, Chat chat) {
    // Map a Chat object to an entry in our listview
    String author = chat.getAuthor();

    TextView messageText = ((TextView) view.findViewById(R.id.message));
    messageText.setText(chat.getMessage());

    LayoutParams layoutParams = (LayoutParams) messageText.getLayoutParams();

    // If the message was sent by this user, color it differently
    if (author.equals(username)) {
      messageText.setBackgroundResource(R.drawable.minichat1);
      layoutParams.gravity = Gravity.RIGHT;
    } else {
      messageText.setBackgroundResource(R.drawable.minichat2);
      layoutParams.gravity = Gravity.LEFT;
    }
    messageText.setLayoutParams(layoutParams);
  }
示例#10
0
 @Override
 protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
   if (p instanceof LayoutParams) {
     LayoutParams result = new LayoutParams((LayoutParams) p);
     if (result.gravity <= Gravity.NO_GRAVITY) {
       result.gravity = Gravity.CENTER_VERTICAL;
     }
     return result;
   }
   return generateDefaultLayoutParams();
 }
 public void setLoadingProgressBar(boolean flag) {
   if (flag) {
     mProgressBar = new ProgressBar(mContext);
     LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
     params.gravity = Gravity.CENTER;
     mProgressBar.setLayoutParams(params);
     addView(mProgressBar);
   } else {
     removeView(mProgressBar);
   }
 }
  @Override
  public void addView(View child) {
    mHeaderView = new EBounceViewHeader(mContext, EViewEntry.F_BOUNCE_TYPE_TOP);
    LayoutParams hlp = new LinearLayout.LayoutParams(Compat.FILL, mBounceViewHeight);
    hlp.topMargin = -mBounceViewHeight;
    hlp.gravity = Gravity.CENTER;
    addView(mHeaderView, hlp);
    mHeaderView.setVisibility(GONE);

    mBrwView = (EBrowserView) child;
    LayoutParams wlp = new LinearLayout.LayoutParams(Compat.FILL, Compat.FILL);
    wlp.weight = 1.0f;
    addView(mBrwView, wlp);

    mTailView = new EBounceViewHeader(mContext, EViewEntry.F_BOUNCE_TYPE_BOTTOM);
    LayoutParams tlp = new LinearLayout.LayoutParams(Compat.FILL, mBounceViewHeight);
    tlp.bottomMargin = -mBounceViewHeight;
    tlp.gravity = Gravity.CENTER;
    addView(mTailView, tlp);
    mTailView.setVisibility(GONE);
  }
 public void setEmptyView(boolean flag) {
   if (flag) {
     mImageView = new ImageView(mContext);
     LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
     params.gravity = Gravity.CENTER;
     mImageView.setLayoutParams(params);
     mImageView.setImageResource(R.mipmap.ic_launcher);
     addView(mImageView);
   } else {
     removeView(mImageView);
   }
 }
示例#14
0
 protected LayoutParams generateLayoutParams(android.view.ViewGroup.LayoutParams p) {
   if (p == null) {
     return generateDefaultLayoutParams();
   }
   LayoutParams result =
       p instanceof LayoutParams ? new LayoutParams((LayoutParams) p) : new LayoutParams(p);
   if (result.gravity > 0) {
     return result;
   }
   result.gravity = 16;
   return result;
 }
示例#15
0
  /** 初始化宫格列表ui */
  public void afterPlatformListGot() {
    Context context = getContext();

    // 为了更好的ui效果,开启子线程获取平台列表
    int pageSize = platformList.length > PAGE_SIZE ? PAGE_SIZE : platformList.length;
    int lines = pageSize / 3;
    if (pageSize % 3 > 0) {
      lines++;
    }
    ViewGroup.LayoutParams lp = pager.getLayoutParams();
    int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(context, 10);
    int scrW = getResources().getDisplayMetrics().widthPixels;
    lp.height = (scrW - dp_10 * 2) * lines / 3;
    pager.setLayoutParams(lp);
    PlatformAdapter adapter = new PlatformAdapter(platformList, this);
    pager.setAdapter(adapter);
    int pageCount = 0;
    if (platformList != null) {
      int size = platformList.length;
      pageCount = size / PAGE_SIZE;
      if (size % PAGE_SIZE > 0) {
        pageCount++;
      }
    }
    points = new ImageView[pageCount];
    if (points.length <= 0) {
      return;
    }

    LinearLayout llPoints = new LinearLayout(context);
    // 如果页面总是超过1,则设置页面指示器
    llPoints.setVisibility(pageCount > 1 ? View.VISIBLE : View.GONE);
    LayoutParams lpLl = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lpLl.gravity = Gravity.CENTER_HORIZONTAL;
    llPoints.setLayoutParams(lpLl);
    addView(llPoints);

    int dp_5 = cn.sharesdk.framework.utils.R.dipToPx(context, 5);
    grayPoint = BitmapFactory.decodeResource(getResources(), R.drawable.gray_point);
    whitePoint = BitmapFactory.decodeResource(getResources(), R.drawable.white_point);
    for (int i = 0; i < pageCount; i++) {
      points[i] = new ImageView(context);
      points[i].setScaleType(ScaleType.CENTER_INSIDE);
      points[i].setImageBitmap(grayPoint);
      LayoutParams lpIv = new LayoutParams(dp_5, dp_5);
      lpIv.setMargins(dp_5, dp_5, dp_5, 0);
      points[i].setLayoutParams(lpIv);
      llPoints.addView(points[i]);
    }
    int curPage = pager.getCurrentItem();
    points[curPage].setImageBitmap(whitePoint);
  }
  /** Config UI just one time */
  private void configUI() {
    setOrientation(LinearLayout.VERTICAL);
    setPadding(8, 8, 8, 8);

    TextView titleView = new TextView(ctx);
    titleView.setText(TEXT_TITLE);
    titleView.setTextColor(Color.LTGRAY);
    addView(titleView);

    LinearLayout subLayout = new LinearLayout(ctx);
    subLayout.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams subLayoutParams =
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    // configuring the iconView
    iconView.setImageDrawable(icon);
    LayoutParams icParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    icParams.gravity = Gravity.CENTER_VERTICAL;

    // configuring the msgView
    msgView.setText(msg);
    msgView.setPadding(10, 0, 0, 0);
    msgView.setTextSize(20);
    msgView.setTextColor(Color.WHITE);
    msgView.setGravity(Gravity.CENTER_VERTICAL);
    msgView.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    msgView.setMaxLines(1);
    LayoutParams tvParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    subLayout.addView(iconView, icParams);
    subLayout.addView(msgView, tvParams);

    addView(subLayout, subLayoutParams);

    actionBtn.setText(TEXT_DELETE);
    actionBtn.setTextColor(Color.WHITE);
    addView(actionBtn, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    undoRedoLayout.setOrientation(LinearLayout.HORIZONTAL);
    undoView = new ImageView(ctx);
    redoView = new ImageView(ctx);
    undoView.setImageDrawable(DrawableFactory.build(ctx, DrawableFactory.ICON_UNDO));
    redoView.setImageDrawable(DrawableFactory.build(ctx, DrawableFactory.ICON_REDO));
    undoView.setClickable(true);
    redoView.setClickable(true);
    LayoutParams undoRedoParams =
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    undoRedoParams.weight = 1;
    undoRedoLayout.addView(undoView, undoRedoParams);
    undoRedoLayout.addView(redoView, undoRedoParams);
    addView(undoRedoLayout);
  }
示例#17
0
  /**
   * Show this SnackBar. Make sure it already attached to a parent view or this method will do
   * nothing.
   */
  public void show() {
    ViewGroup parent = (ViewGroup) getParent();
    if (parent == null || mState == STATE_SHOWING || mState == STATE_DISMISSING) return;

    if (parent instanceof FrameLayout) {
      LayoutParams params = (LayoutParams) getLayoutParams();

      params.width = mWidth;
      params.height = mHeight;
      params.gravity = Gravity.START | Gravity.BOTTOM;
      if (mIsRtl) params.rightMargin = mMarginStart;
      else params.leftMargin = mMarginStart;
      params.bottomMargin = mMarginBottom;
    } else if (parent instanceof RelativeLayout) {
      RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();

      params.width = mWidth;
      params.height = mHeight;
      params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
      params.addRule(RelativeLayout.ALIGN_PARENT_START);
      if (mIsRtl) params.rightMargin = mMarginStart;
      else params.leftMargin = mMarginStart;
      params.bottomMargin = mMarginBottom;
    }

    if (mInAnimationId != 0 && mState != STATE_SHOWN) {
      Animation anim = AnimationUtils.loadAnimation(getContext(), mInAnimationId);
      anim.setAnimationListener(
          new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
              setState(STATE_SHOWING);
              setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {}

            @Override
            public void onAnimationEnd(Animation animation) {
              setState(STATE_SHOWN);
              startTimer();
            }
          });
      startAnimation(anim);
    } else {
      setVisibility(View.VISIBLE);
      setState(STATE_SHOWN);
      startTimer();
    }
  }
示例#18
0
  private void init() {

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;

    cameraSurfaceView = new CameraSurfaceView(getContext());
    cameraSurfaceView.setLayoutParams(params);

    this.supportCamera = cameraSurfaceView.getSupportCamera();
    this.supportCamera.addCameraListener(this);

    addView(cameraSurfaceView);
  }
示例#19
0
  // initializes the girdview of platforms
  public void afterPlatformListGot() {
    PlatformAdapter adapter = new PlatformAdapter(this);
    pager.setAdapter(adapter);
    int pageCount = 0;
    if (platformList != null) {
      int cusSize = customers == null ? 0 : customers.size();
      int platSize = platformList == null ? 0 : platformList.length;
      int hideSize = hiddenPlatforms == null ? 0 : hiddenPlatforms.size();
      platSize = platSize - hideSize;
      int size = platSize + cusSize;
      pageCount = size / PAGE_SIZE;
      if (size % PAGE_SIZE > 0) {
        pageCount++;
      }
    }
    points = new ImageView[pageCount];
    if (points.length <= 0) {
      return;
    }

    Context context = getContext();
    LinearLayout llPoints = new LinearLayout(context);
    // if the total number of pages exceeds 1, we set the page indicators
    llPoints.setVisibility(pageCount > 1 ? View.VISIBLE : View.GONE);
    LayoutParams lpLl = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lpLl.gravity = Gravity.CENTER_HORIZONTAL;
    llPoints.setLayoutParams(lpLl);
    addView(llPoints);

    int dp_5 = com.mob.tools.utils.R.dipToPx(context, 5);
    int resId = getBitmapRes(getContext(), "light_blue_point");
    if (resId > 0) {
      grayPoint = BitmapFactory.decodeResource(getResources(), resId);
    }
    resId = getBitmapRes(getContext(), "blue_point");
    if (resId > 0) {
      bluePoint = BitmapFactory.decodeResource(getResources(), resId);
    }
    for (int i = 0; i < pageCount; i++) {
      points[i] = new ImageView(context);
      points[i].setScaleType(ScaleType.CENTER_INSIDE);
      points[i].setImageBitmap(grayPoint);
      LayoutParams lpIv = new LayoutParams(dp_5, dp_5);
      lpIv.setMargins(dp_5, dp_5, dp_5, 0);
      points[i].setLayoutParams(lpIv);
      llPoints.addView(points[i]);
    }
    int curPage = pager.getCurrentScreen();
    points[curPage].setImageBitmap(bluePoint);
  }
示例#20
0
  private void initView(Context context) {
    // Scroll View
    LayoutParams sv1lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    sv1lp.gravity = Gravity.CENTER_HORIZONTAL;
    mScrollView = new ScrollView(context);

    // Scroll View 1 - Text Field
    mTextField = (TextView) getChildAt(0);
    removeView(mTextField);

    mScrollView.addView(
        mTextField, new ScrollView.LayoutParams(TEXTVIEW_VIRTUAL_WIDTH, LayoutParams.WRAP_CONTENT));

    mTextField.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

          @Override
          public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

          @Override
          public void afterTextChanged(Editable editable) {
            final boolean continueAnimation = mStarted;

            reset();
            prepareAnimation();

            cutTextView();

            post(
                new Runnable() {
                  @Override
                  public void run() {
                    if (continueAnimation) {
                      startMarquee();
                    }
                  }
                });
          }
        });

    addView(mScrollView, sv1lp);
  }
  private void init() {
    progress = new SweetProgress(getContext());
    final int edges = UIUtils.dip2px(getContext(), 32);
    LayoutParams params = new LayoutParams(edges, edges);
    params.gravity = Gravity.CENTER;
    final int margin = UIUtils.dip2px(getContext(), 8);
    params.setMargins(0, margin, 0, margin);
    addView(progress, params);

    getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                moveTo(0);
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
              }
            });
  }
示例#22
0
  private void initTabs(int currentTab) {

    for (int index = 0; index < mTabCount; index++) {
      TextView tvTab = new TextView(mContext);
      tvTab.setId(BASE_ID + index);
      tvTab.setOnClickListener(this);
      tvTab.setGravity(Gravity.CENTER);

      if (null != mViewPager.getAdapter().getPageTitle(index)) {
        tvTab.setTextColor(mTextColor);
        tvTab.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSizeNormal);
        tvTab.setText(mViewPager.getAdapter().getPageTitle(index));
      }

      if (mTabIcons != null && mTabIcons.size() > index) {
        StateListDrawable drawable = mTabIcons.get(index);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tvTab.setCompoundDrawables(null, drawable, null, null);
        tvTab.setCompoundDrawablePadding(0);
        tvTab.setPadding(0, 10, 0, 0);
      }

      LayoutParams tabLp = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
      tabLp.gravity = Gravity.CENTER;
      tvTab.setLayoutParams(tabLp);
      tvTab.setPadding(0, mTabPaddingTop, 0, mTabPaddingBottom);
      this.addView(tvTab);

      if (index == 0) {
        resetTab(tvTab, true);
      }

      if (index != mTabCount - 1 && mHasDivider) {
        LayoutParams dividerLp = new LayoutParams(mDividerWidth, LayoutParams.MATCH_PARENT);
        dividerLp.setMargins(0, mDividerVerticalMargin, 0, mDividerVerticalMargin);
        View vLine = new View(getContext());
        vLine.setBackgroundColor(mDividerColor);
        vLine.setLayoutParams(dividerLp);
        this.addView(vLine);
      }
    }
    setCurrentTab(currentTab);
  }
  @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);
  }
  private void initView(Context context) {
    setOrientation(LinearLayout.VERTICAL);
    setLayoutParams(
        new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.LEFT));
    setPadding(5, 0, 0, 0);

    // Scroll View 1
    LayoutParams sv1lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    sv1lp.gravity = Gravity.CENTER_HORIZONTAL;
    mScrollView1 = new ScrollView(context);

    // Scroll View 1 - Text Field
    mTextField1 = new TextView(context);
    mTextField1.setSingleLine(true);
    mTextField1.setTextColor(Color.WHITE);
    mTextField1.setEllipsize(TextUtils.TruncateAt.END);
    mTextField1.setTypeface(null, Typeface.BOLD);
    mScrollView1.addView(
        mTextField1,
        new ScrollView.LayoutParams(TEXTVIEW_VIRTUAL_WIDTH, LayoutParams.WRAP_CONTENT));

    addView(mScrollView1, sv1lp);
  }
  public void handleCompletion() {
    removeAllViews();

    TextView label = new TextView(this.getContext());
    label.setText("Great work!!");
    getVocabBlasterActivity().formatHandwritingOnAChalkboard(label);
    addView(label);

    label = new TextView(this.getContext());
    label.setText("You have these words pretty well mastered.");
    getVocabBlasterActivity().formatHandwritingOnAChalkboard(label);

    Button button = new Button(this.getContext());
    button.setText("Start Over");
    button.setTextColor(Color.BLACK);

    LayoutParams layoutParams = new LayoutParams();
    layoutParams.weight = 1.0f;
    float density = getResources().getDisplayMetrics().density;
    layoutParams.width = (int) (150 * density);
    layoutParams.topMargin = 60;
    layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
    layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
    button.setLayoutParams(layoutParams);

    final AdministerTestActivity vocabBlaster = (AdministerTestActivity) this.getContext();
    button.setOnClickListener(
        new OnClickListener() {
          public void onClick(View view) {
            vocabBlaster.reset();
          }
        });

    addView(label);
    addView(button);
  }
示例#26
0
  public LoadingLayout(
      Context context, final Mode mode, final Orientation scrollDirection, TypedArray attrs) {
    super(context);
    mMode = mode;
    mScrollDirection = scrollDirection;

    switch (scrollDirection) {
      case HORIZONTAL:
        LayoutInflater.from(context).inflate(R.layout.pull_to_refresh_header_horizontal, this);
        break;
      case VERTICAL:
      default:
        LayoutInflater.from(context).inflate(R.layout.pull_to_refresh_header_vertical, this);
        break;
    }

    mInnerLayout = (FrameLayout) findViewById(R.id.fl_inner);
    mHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_text);
    mHeaderProgress = (ProgressBar) mInnerLayout.findViewById(R.id.pull_to_refresh_progress);
    mSubHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_sub_text);
    mHeaderImage = (ImageView) mInnerLayout.findViewById(R.id.pull_to_refresh_image);

    LayoutParams lp = (LayoutParams) mInnerLayout.getLayoutParams();

    switch (mode) {
      case PULL_FROM_END:
        lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.TOP : Gravity.LEFT;

        // Load in labels
        mPullLabel = context.getString(R.string.pull_to_refresh_from_bottom_pull_label);
        mRefreshingLabel = context.getString(R.string.pull_to_refresh_from_bottom_refreshing_label);
        mReleaseLabel = context.getString(R.string.pull_to_refresh_from_bottom_release_label);
        break;

      case PULL_FROM_START:
      default:
        lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.BOTTOM : Gravity.RIGHT;

        // Load in labels
        mPullLabel = context.getString(R.string.pull_to_refresh_pull_label);
        mRefreshingLabel = context.getString(R.string.pull_to_refresh_refreshing_label);
        mReleaseLabel = context.getString(R.string.pull_to_refresh_release_label);
        break;
    }

    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderBackground)) {
      Drawable background = attrs.getDrawable(R.styleable.PullToRefresh_ptrHeaderBackground);
      if (null != background) {
        ViewCompat.setBackground(this, background);
      }
    }

    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance)) {
      TypedValue styleID = new TypedValue();
      attrs.getValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance, styleID);
      setTextAppearance(styleID.data);
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance)) {
      TypedValue styleID = new TypedValue();
      attrs.getValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID);
      setSubTextAppearance(styleID.data);
    }

    // Text Color attrs need to be set after TextAppearance attrs
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextColor)) {
      ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderTextColor);
      if (null != colors) {
        setTextColor(colors);
      }
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderSubTextColor)) {
      ColorStateList colors =
          attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderSubTextColor);
      if (null != colors) {
        setSubTextColor(colors);
      }
    }

    // Try and get defined drawable from Attrs
    Drawable imageDrawable = null;
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawable)) {
      imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawable);
    }

    // Check Specific Drawable from Attrs, these overrite the generic
    // drawable attr above
    switch (mode) {
      case PULL_FROM_START:
      default:
        if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableStart)) {
          imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableStart);
        } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableTop)) {
          Utils.warnDeprecation("ptrDrawableTop", "ptrDrawableStart");
          imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableTop);
        }
        break;

      case PULL_FROM_END:
        if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableEnd)) {
          imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableEnd);
        } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableBottom)) {
          Utils.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd");
          imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableBottom);
        }
        break;
    }

    // If we don't have a user defined drawable, load the default
    if (null == imageDrawable) {
      imageDrawable = context.getResources().getDrawable(getDefaultDrawableResId());
    }

    // Set Drawable, and save width/height
    setLoadingDrawable(imageDrawable);

    reset();
  }
示例#27
0
  public BottomBar(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.BottomBar);
    image1 = ta.getDrawable(R.styleable.BottomBar_ImageView1);
    image2 = ta.getDrawable(R.styleable.BottomBar_ImageView2);
    image3 = ta.getDrawable(R.styleable.BottomBar_ImageView3);
    image4 = ta.getDrawable(R.styleable.BottomBar_ImageView4);
    image1Height = ta.getDimension(R.styleable.BottomBar_ImageView1Height, 50);
    image2Height = ta.getDimension(R.styleable.BottomBar_ImageView2Height, 0);
    image3Height = ta.getDimension(R.styleable.BottomBar_ImageView3Height, 0);
    image4Height = ta.getDimension(R.styleable.BottomBar_ImageView4Height, 0);

    image1Width = ta.getDimension(R.styleable.BottomBar_ImageView1Width, 50);
    image2Width = ta.getDimension(R.styleable.BottomBar_ImageView2Width, 0);
    image3Width = ta.getDimension(R.styleable.BottomBar_ImageView3Width, 0);
    image4Width = ta.getDimension(R.styleable.BottomBar_ImageView4Width, 0);

    ta.recycle();

    imageView1 = new ImageView(context);
    imageView2 = new ImageView(context);
    imageView3 = new ImageView(context);
    imageView4 = new ImageView(context);

    imageView1.setImageDrawable(image1);
    imageView1.setAdjustViewBounds(true);
    imageView1.setMaxHeight((int) image1Height);
    imageView1.setMaxWidth((int) image1Width);

    imageView2.setImageDrawable(image2);
    imageView2.setAdjustViewBounds(true);
    imageView2.setMaxHeight((int) image2Height);
    imageView2.setMaxWidth((int) image2Width);

    imageView3.setImageDrawable(image3);
    imageView3.setAdjustViewBounds(true);
    imageView3.setMaxHeight((int) image3Height);
    imageView3.setMaxWidth((int) image3Width);

    imageView4.setImageDrawable(image4);
    imageView4.setAdjustViewBounds(true);
    imageView4.setMaxHeight((int) image4Height);
    imageView4.setMaxWidth((int) image4Width);

    setOrientation(LinearLayout.HORIZONTAL);
    setBackgroundColor(0x8800CCCC);

    param1 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    param1.gravity = Gravity.CENTER_VERTICAL;
    param1.weight = 1;
    addView(imageView1, param1);

    param2 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    param2.gravity = Gravity.CENTER_VERTICAL;
    param2.weight = 1;
    addView(imageView2, param2);

    param3 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    param3.gravity = Gravity.CENTER_VERTICAL;
    param3.weight = 1;
    addView(imageView3, param3);

    param4 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    param4.gravity = Gravity.CENTER_VERTICAL;
    param4.weight = 1;
    addView(imageView4, param4);

    imageView1.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            listener.Click1();
          }
        });
    imageView2.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            listener.Click2();
          }
        });
    imageView3.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            listener.Click3();
          }
        });
    imageView4.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            listener.Click4();
          }
        });
  }
  @SuppressWarnings("deprecation")
  public CreditCardEntry(
      Context context,
      boolean includeExp,
      boolean includeSecurity,
      boolean includeZip,
      AttributeSet attrs,
      int style) {
    super(context);

    this.context = context;

    TypedArray typedArray =
        context.getTheme().obtainStyledAttributes(attrs, R.styleable.CreditCardForm, 0, 0);
    textColor = typedArray.getColor(R.styleable.CreditCardForm_text_color, Color.BLACK);
    typedArray.recycle();

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    int width;

    if (android.os.Build.VERSION.SDK_INT < 13) {
      width = display.getWidth(); // deprecated
    } else {
      Point size = new Point();
      display.getSize(size);
      width = size.x;
    }

    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER_VERTICAL;
    setLayoutParams(params);
    this.setHorizontalScrollBarEnabled(false);
    this.setOnTouchListener(this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      container = new LinearLayout(context);
    } else {
      container = new LinearLayout(context);
    }
    container.setId(R.id.cc_entry_internal);
    container.setLayoutParams(
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    container.setOrientation(LinearLayout.HORIZONTAL);

    creditCardText = new CreditCardText(context, attrs);
    creditCardText.setId(R.id.cc_card);
    creditCardText.setDelegate(this);
    creditCardText.setWidth(width);
    container.addView(creditCardText);
    includedFields.add(creditCardText);
    CreditEntryFieldBase currentField = creditCardText;

    textFourDigits = new TextView(context);
    textFourDigits.setTextSize(20);
    textFourDigits.setTextColor(textColor);
    container.addView(textFourDigits);

    expDateText = new ExpDateText(context, attrs);
    expDateText.setId(R.id.cc_exp);
    if (includeExp) {
      expDateText.setDelegate(this);
      container.addView(expDateText);
      nextFocusField.put(currentField, expDateText);
      prevFocusField.put(expDateText, currentField);
      currentField = expDateText;
      includedFields.add(currentField);
    }

    securityCodeText = new SecurityCodeText(context, attrs);
    securityCodeText.setId(R.id.cc_ccv);
    if (includeSecurity) {
      securityCodeText.setDelegate(this);
      if (!includeZip) {
        securityCodeText.setImeActionLabel("Done", EditorInfo.IME_ACTION_DONE);
      }

      securityCodeText.setOnEditorActionListener(
          new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              if (EditorInfo.IME_ACTION_DONE == actionId) {
                onSecurityCodeValid();
                return true;
              }
              return false;
            }
          });
      container.addView(securityCodeText);
      nextFocusField.put(currentField, securityCodeText);
      prevFocusField.put(securityCodeText, currentField);
      currentField = securityCodeText;
      includedFields.add(currentField);
    }

    zipCodeText = new ZipCodeText(context, attrs);
    zipCodeText.setId(R.id.cc_zip);
    if (includeZip) {
      zipCodeText.setDelegate(this);
      container.addView(zipCodeText);
      zipCodeText.setImeActionLabel("DONE", EditorInfo.IME_ACTION_DONE);
      zipCodeText.setOnEditorActionListener(
          new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              if (EditorInfo.IME_ACTION_DONE == actionId) {
                onZipCodeValid();
                return true;
              }
              return false;
            }
          });
      nextFocusField.put(currentField, zipCodeText);
      prevFocusField.put(zipCodeText, currentField);
      currentField = zipCodeText;
      includedFields.add(currentField);
    }

    nextFocusField.put(currentField, null);

    this.addView(container);

    // when the user taps the last 4 digits of the card, they probably want to edit it
    textFourDigits.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            focusOnField(creditCardText);
          }
        });
  }
 @Override
 protected LayoutParams generateDefaultLayoutParams() {
   LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
   params.gravity = Gravity.CENTER_VERTICAL;
   return params;
 }
  /**
   * Present a sheet view to the user. If another sheet is currently presented, it will be
   * dismissed, and the new sheet will be shown after that
   *
   * @param sheetView The sheet to be presented.
   * @param viewTransformer The view transformer to use when presenting the sheet.
   */
  public void showWithSheetView(final View sheetView, final ViewTransformer viewTransformer) {
    if (state != State.HIDDEN) {
      Runnable runAfterDismissThis =
          new Runnable() {
            @Override
            public void run() {
              showWithSheetView(sheetView, viewTransformer);
            }
          };
      dismissSheet(runAfterDismissThis);
      return;
    }
    setState(State.PREPARING);

    LayoutParams params = (LayoutParams) sheetView.getLayoutParams();
    if (params == null) {
      params =
          new LayoutParams(
              isTablet ? LayoutParams.WRAP_CONTENT : LayoutParams.MATCH_PARENT,
              LayoutParams.WRAP_CONTENT,
              Gravity.CENTER_HORIZONTAL);
    }

    if (isTablet && params.width == FrameLayout.LayoutParams.WRAP_CONTENT) {

      // Center by default if they didn't specify anything
      if (params.gravity == -1) {
        params.gravity = Gravity.CENTER_HORIZONTAL;
      }

      params.width = defaultSheetWidth;

      // Update start and end coordinates for touch reference
      int horizontalSpacing = screenWidth - defaultSheetWidth;
      sheetStartX = horizontalSpacing / 2;
      sheetEndX = screenWidth - sheetStartX;
    }

    super.addView(sheetView, -1, params);
    initializeSheetValues();
    this.viewTransformer = viewTransformer;

    // Don't start animating until the sheet has been drawn once. This ensures that we don't do
    // layout while animating and that
    // the drawing cache for the view has been warmed up. tl;dr it reduces lag.
    getViewTreeObserver()
        .addOnPreDrawListener(
            new ViewTreeObserver.OnPreDrawListener() {
              @Override
              public boolean onPreDraw() {
                getViewTreeObserver().removeOnPreDrawListener(this);
                post(
                    new Runnable() {
                      @Override
                      public void run() {
                        // Make sure sheet view is still here when first draw happens.
                        // In the case of a large lag it could be that the view is dismissed before
                        // it is drawn resulting in sheet view being null here.
                        if (getSheetView() != null) {
                          peekSheet();
                        }
                      }
                    });
                return true;
              }
            });

    // sheetView should always be anchored to the bottom of the screen
    currentSheetViewHeight = sheetView.getMeasuredHeight();
    sheetViewOnLayoutChangeListener =
        new OnLayoutChangeListener() {
          @Override
          public void onLayoutChange(
              View sheetView,
              int left,
              int top,
              int right,
              int bottom,
              int oldLeft,
              int oldTop,
              int oldRight,
              int oldBottom) {
            int newSheetViewHeight = sheetView.getMeasuredHeight();
            if (state != State.HIDDEN && newSheetViewHeight < currentSheetViewHeight) {
              // The sheet can no longer be in the expanded state if it has shrunk
              if (state == State.EXPANDED) {
                setState(State.PEEKED);
              }
              setSheetTranslation(newSheetViewHeight);
            }
            currentSheetViewHeight = newSheetViewHeight;
          }
        };
    sheetView.addOnLayoutChangeListener(sheetViewOnLayoutChangeListener);
  }