@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 init() { LayoutInflater lif = (LayoutInflater) mCon.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = lif.inflate(R.layout.home_operation_bar, null); mNewsLo = (LinearLayout) view.findViewById(R.id.home_oper_xuanwen); mNewsIv = (ImageView) view.findViewById(R.id.home_oper_xuanwen_iv); mNewsTv = (TextView) view.findViewById(R.id.home_oper_xuanwen_tv); mSMsgLo = (LinearLayout) view.findViewById(R.id.home_oper_enterprise); mEnterpriseLogoIv = (ImageView) view.findViewById(R.id.enterprise_iv); menterpriseNameTv = (TextView) view.findViewById(R.id.enterprise_tv); mBBSLo = (LinearLayout) view.findViewById(R.id.home_oper_app_center); mAppIv = (ImageView) view.findViewById(R.id.home_oper_app_iv); mAppeTv = (TextView) view.findViewById(R.id.home_oper_app_tv); mPersonalCenterLo = (LinearLayout) view.findViewById(R.id.home_oper_personnal_center); mPersonalIv = (ImageView) view.findViewById(R.id.home_oper_personal_iv); mPersonalTv = (TextView) view.findViewById(R.id.home_oper_personal_tv); mMsgCountTv = (TextView) view.findViewById(R.id.home_oper_personal_msgcount_iv); mMsgEnterprise = (TextView) view.findViewById(R.id.tv_enterprise_msg); mMsgHomeOperApp = (TextView) view.findViewById(R.id.tv_home_oper_app_msg); mNewsLo.setOnClickListener(this); mSMsgLo.setOnClickListener(this); mBBSLo.setOnClickListener(this); mPersonalCenterLo.setOnClickListener(this); LinearLayout.LayoutParams lllp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); addView(view, lllp); mNormalLP = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1); mNormalLP.topMargin = 12; mSelectedLP = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1); setSelectedBtnBackground(mSelectedType); }
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); }
@Override protected void measureChildWithMargins( View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) { final int index = indexOfChild(child); final int orientation = getOrientation(); final LayoutParams params = (LayoutParams) child.getLayoutParams(); if (hasDividerBeforeChildAt(index)) { if (orientation == VERTICAL) { // Account for the divider by pushing everything up params.topMargin = mDividerHeight; } else { // Account for the divider by pushing everything left params.leftMargin = mDividerWidth; } } final int count = getChildCount(); if (index == count - 1) { if (hasDividerBeforeChildAt(count)) { if (orientation == VERTICAL) { params.bottomMargin = mDividerHeight; } else { params.rightMargin = mDividerWidth; } } } super.measureChildWithMargins( child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed); }
private void setUpCardView() { LayoutParams params = new LayoutParams(mCardView.getLayoutParams()); params.topMargin = mMarginTop; params.bottomMargin = mMarginBottom; params.leftMargin = mMarginLeft; params.rightMargin = mMarginRight; mCardView.setLayoutParams(params); }
void setHorizontalMode(int horizontalSpacing, int startMargin, int endMargin) { isStacked = false; for (int i = 0; i < views.length; i++) { LayoutParams lp = (LayoutParams) views[i].getLayoutParams(); lp.startMargin = i == 0 ? startMargin : horizontalSpacing; lp.topMargin = 0; lp.endMargin = i == views.length - 1 ? endMargin : 0; lp.bottomMargin = 0; } }
void setVerticalMode(int verticalSpacing, int bottomMargin) { isStacked = true; for (int i = 0; i < views.length; i++) { LayoutParams lp = (LayoutParams) views[i].getLayoutParams(); lp.startMargin = 0; lp.topMargin = i == 0 ? 0 : verticalSpacing; lp.endMargin = 0; lp.bottomMargin = i == views.length - 1 ? bottomMargin : 0; } }
/** Setup the tab host and create all necessary tabs. */ @Override protected void onFinishInflate() { // Setup the tab host setup(); final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container); final TabWidget tabs = getTabWidget(); final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView) findViewById(R.id.apps_customize_pane_content); mTabs = tabs; mTabsContainer = tabsContainer; mAppsCustomizePane = appsCustomizePane; mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer); mContent = (LinearLayout) findViewById(R.id.apps_customize_content); LayoutParams params = (LayoutParams) mContent.getLayoutParams(); params.topMargin += Utils.getStatusBarSize(getResources()); mContent.setLayoutParams(params); if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException(); // Configure the tabs content factory to return the same paged view (that we change the // content filter on) TabContentFactory contentFactory = new TabContentFactory() { public View createTabContent(String tag) { return appsCustomizePane; } }; // Create the tabs TextView tabView; String label; label = getContext().getString(R.string.all_apps_button_label); tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false); tabView.setText(label); tabView.setContentDescription(label); addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory)); label = getContext().getString(R.string.widgets_tab_label); tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false); tabView.setText(label); tabView.setContentDescription(label); addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory)); setOnTabChangedListener(this); // Setup the key listener to jump between the last tab view and the market icon AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener(); View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1); lastTab.setOnKeyListener(keyListener); View shopButton = findViewById(R.id.market_button); shopButton.setOnKeyListener(keyListener); // Hide the tab bar until we measure mTabsContainer.setAlpha(0f); }
private void startAnim() { int tem = -topRefreshView.getHeight(); int tem2 = footerRefreshView.getHeight(); LayoutParams lp = (LayoutParams) topRefreshView.getLayoutParams(); if (lp.topMargin > tem) { lp.topMargin -= 20; if (refreshing) { if (lp.topMargin < 0) { lp.topMargin = 0; } } else { if (lp.topMargin <= tem) { lp.topMargin = tem; } } } else if (lp.topMargin < tem) { lp.topMargin += 20; if (refreshing) { if (lp.topMargin >= (tem - tem2)) { lp.topMargin = tem - tem2; } } else { if (lp.topMargin >= tem) { lp.topMargin = tem; } } } topRefreshView.setLayoutParams(lp); if (lp.topMargin != tem) { invalidate(); } else { animIsOver = false; } }
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (isFrist && topRefreshView.getHeight() > 0) { LayoutParams lp = (LayoutParams) topRefreshView.getLayoutParams(); lp.topMargin = -topRefreshView.getHeight(); topRefreshView.setLayoutParams(lp); isFrist = false; } if (animIsOver) { startAnim(); } }
@Override public boolean onResourceReady( GlideDrawable resource, Object model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { if (resource instanceof GlideBitmapDrawable) { Log.w(TAG, "onResourceReady() for a Bitmap. Saving."); part.setThumbnail(((GlideBitmapDrawable) resource).getBitmap()); } LayoutParams layoutParams = (LayoutParams) getRemoveButton().getLayoutParams(); if (resource.getIntrinsicWidth() < getWidth()) { layoutParams.topMargin = 0; layoutParams.rightMargin = Math.max(0, (getWidth() - image.getPaddingRight() - resource.getIntrinsicWidth()) / 2); } else { layoutParams.topMargin = Math.max(0, (getHeight() - image.getPaddingTop() - resource.getIntrinsicHeight()) / 2); layoutParams.rightMargin = 0; } getRemoveButton().setLayoutParams(layoutParams); return false; }
private void initFocus() { if (null == focusView) { LayoutParams params = new LayoutParams( width / (getItemCount() == 0 ? 1 : getItemCount()), LayoutParams.MATCH_PARENT); params.topMargin = DisplayUtil.dip2px(this.getContext(), 2); params.bottomMargin = DisplayUtil.dip2px(this.getContext(), 2); focusView = initFocusUI(); focusView.setLayoutParams(params); focusView.setBackgroundResource(focusBg); focusView.setVisibility(View.INVISIBLE); this.addView(focusView, layer); } else { focusView.getLayoutParams().width = width / (getItemCount() == 0 ? 1 : getItemCount()); } focusView.setVisibility(tags.size() > 0 ? View.VISIBLE : View.GONE); }
private void addTopRefreshView() { topRefreshView = new LinearLayout(con); topRefreshView.setGravity(Gravity.CENTER); topRefreshView.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); View v = inflate(con, R.layout.view_pull_to_refresh, null); progressBarTop = (ProgressBar) v.findViewById(R.id.progressBar); imgArrawTop = (ImageView) v.findViewById(R.id.imgArraw); textRefreshTop = (TextView) v.findViewById(R.id.textRefresh); textRefreshTimeTop = (TextView) v.findViewById(R.id.textRefreshTime); textRefreshTimeTop.setVisibility(View.VISIBLE); topRefreshView.addView(v); addView(topRefreshView, 0); measureView(topRefreshView); LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, topRefreshView.getMeasuredHeight()); lp.topMargin = -topRefreshView.getMeasuredHeight(); topRefreshView.setLayoutParams(lp); }
@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); }
@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 initViewAttribute() { mTextView = new TextView(this.getContext()); // 设置属性 mTextView.setText(text); mTextView.setTextColor(textColor); mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); int textHeight = mTextView.getLineHeight() * maxLine; LayoutParams mParams_txt = new LayoutParams(LayoutParams.MATCH_PARENT, textHeight); addView(mTextView, mParams_txt); mImageView = new ImageView(this.getContext()); mImageView.setImageDrawable(mIcon); LayoutParams mParams_img = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); mParams_img.topMargin = dp2px(DEFAULT_MARGIN_TOP); addView(mImageView, mParams_img); mImageView.setOnClickListener(this); this.setOnClickListener(this); this.post( new Runnable() { @Override public void run() { contentLine = mTextView.getLineCount(); if (contentLine <= maxLine) { mImageView.setVisibility(View.GONE); LayoutParams mParam = (LayoutParams) mTextView.getLayoutParams(); mParam.height = LayoutParams.WRAP_CONTENT; mTextView.setLayoutParams(mParam); ExpandTextView.this.setOnClickListener(null); } else { // 默认是非展开模式,那么设置最大行为maxLine mTextView.setMaxLines(maxLine); mTextView.setEllipsize(TruncateAt.END); mImageView.setVisibility(View.VISIBLE); } } }); }
private LayoutParams initParams(View view, int left, int top) { int[] loc = new int[2]; getLocationOnScreen(loc); final LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); left -= loc[0]; top -= loc[1]; layoutParams.leftMargin = left; layoutParams.topMargin = top; view.setLeft(left); view.setTop(top); if (view.getMeasuredWidth() != 0) { layoutParams.width = view.getMeasuredWidth(); view.setRight(left + layoutParams.width); } if (view.getMeasuredHeight() != 0) { layoutParams.height = view.getMeasuredHeight(); view.setBottom(top + layoutParams.height); } return layoutParams; }
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); }
@SuppressWarnings("static-access") private void init() { this.setBackgroundResource(R.drawable.cs_recommend_bg); this.setOrientation(LinearLayout.VERTICAL); RelativeLayout contentLayout = new RelativeLayout(context); LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); contentLayout.setLayoutParams(layoutParams); this.addView(contentLayout); TextView titleTextView = new TextView(context); titleTextView.setText(R.string.download_manager); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize + 3); titleTextView.setTextColor(Color.WHITE); int titleMargin = 20; RelativeLayout.LayoutParams titleParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); titleParams.leftMargin = titleMargin; titleParams.rightMargin = titleMargin; titleParams.topMargin = titleMargin; titleParams.bottomMargin = titleMargin; titleTextView.setLayoutParams(titleParams); contentLayout.addView(titleTextView); LinearLayout managerLayout = new LinearLayout(context); managerLayout.setId(MANAGERLAYOUT_ID); managerLayout.setOrientation(LinearLayout.VERTICAL); int managerPad = 10; managerLayout.setPadding(managerPad, managerPad, managerPad, managerPad); int height = DisplayManager.getInstance(context).getScreenHeight() - 150; int width = DisplayManager.getInstance(context).getScreenWidth() - 200; RelativeLayout.LayoutParams managerLayoutParams = new RelativeLayout.LayoutParams(width, height); managerLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); managerLayout.setLayoutParams(managerLayoutParams); managerLayout.setBackgroundResource(R.drawable.bg_downmanger_content); // managerLayout.setBackgroundColor(Color.parseColor("#99000000")); contentLayout.addView(managerLayout); LinearLayout managerPathLayout = new LinearLayout(context); managerPathLayout.setOrientation(LinearLayout.HORIZONTAL); LayoutParams managerPathParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, textSize + 50); managerPathLayout.setLayoutParams(managerPathParams); managerPathLayout.setPadding(managerPad, 0, managerPad, managerPad); TextView pathText = new TextView(context); pathText.setText(R.string.present_path); pathText.setGravity(Gravity.CENTER); pathText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize - 3); LayoutParams pathTextParams = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 3); pathText.setTextColor(Color.parseColor("#ffffff")); pathTextParams.setMargins(0, 0, 0, 0); pathTextParams.gravity = Gravity.CENTER; pathText.setLayoutParams(pathTextParams); managerPathLayout.addView(pathText); final CheckDownDialogView checkDialog = new CheckDownDialogView(context); String present_edit = ""; if (checkDialog.DetectionDisk() != null) { present_edit = checkDialog.getDownPathname(); } pathEdit = new EditText(context); pathEdit.setText(present_edit); pathEdit.setFocusable(false); pathEdit.setGravity(Gravity.CENTER_VERTICAL); pathEdit.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize - 3); LayoutParams pathEditParams = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 12); pathEdit.setTextColor(Color.parseColor("#ffffff")); pathEdit.setBackgroundResource(R.drawable.present_path); pathEditParams.gravity = Gravity.CENTER_VERTICAL; pathEdit.setLayoutParams(pathEditParams); managerPathLayout.addView(pathEdit); Button pathButton = new FocusAbleButton(context); pathButton.setText(R.string.present_sele); pathButton.setTextColor(Color.parseColor("#ffffff")); pathButton.setGravity(Gravity.CENTER); pathButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize - 3); LayoutParams pathButtonViewParams = new LinearLayout.LayoutParams(0, layoutParams.WRAP_CONTENT, 2); pathButtonViewParams.gravity = Gravity.CENTER; pathButtonViewParams.setMargins(35, 0, 0, 0); pathButton.setLayoutParams(pathButtonViewParams); managerPathLayout.addView(pathButton); pathButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // Map<String, String> labMap = checkDialog.DetectionDisk(); List<String> pathsStr = DownloadResourceManager.getInstance().getFileDir(); if (pathsStr != null) { checkDialog.choiceUsbDialog(); checkDialog.setListener( new PathChoiceClickListener() { @Override public void onClick(View v) { // 下载进度保存 LinkedHashMap<String, FilmDownLoad4k> downStatus = DownloadResourceManager.getInstance().getDLStatus(); if (downStatus != null) { DownloadResourceManager.getInstance().writeDownStatus(downStatus); } DownloadResourceManager.getInstance().clearDLData(); String path = (String) v.getTag(); DownloadResourceManager.getInstance().initDownPath(path); // Log.e(dlStatus +" "+dlStatus.size()); if (context instanceof DownManagerActivity) { ((DownManagerActivity) context).setData(true); } String present_edit = checkDialog.getDownPathname(); pathEdit.setText(present_edit); // 初始化新路径后 检测U盘下载 更新UI // LinkedHashMap<String, FilmDownLoad4k> downStatu = // DownloadResourceManager.getInstance().getDLStatus(); // String path_dir = // DownloadResourceManager.getInstance().getDownLoadPath(); // if(downStatu != null){ // if((path+"/voole_video").equalsIgnoreCase(path_dir)){ // File downPath = new File(path_dir); // if (TextUtils.isEmpty(DownloadResourceManager.getInstance() // .getDownLoadPath()) // || !downPath.getParentFile().exists() || !downPath.exists()){ // if(clickNum == 0){ // managerAct.updateDownItem(); // } // clickNum ++; // } if (context instanceof DownManagerActivity) { if (!((DownManagerActivity) context).isAlive) { // 如果下载线程停止 ((DownManagerActivity) context).setData(true); // 存放数据 ((DownManagerActivity) context).updateDownItem(); // 启动下载线程 } } } }); } else { // 没插入U盘 TVAlertDialog tvDialog = new TVAlertDialog(context); tvDialog.showInspectDialog(context); } } }); LayoutParams parmsPath = new LayoutParams(LayoutParams.MATCH_PARENT, 0); parmsPath.weight = 1; parmsPath.topMargin = 20; parmsPath.leftMargin = 40; parmsPath.rightMargin = 90; managerLayout.addView(managerPathLayout, parmsPath); LinearLayout managerTitleLayout = new LinearLayout(context); managerTitleLayout.setOrientation(LinearLayout.HORIZONTAL); managerTitleLayout.setBackgroundResource(R.drawable.bg_down_title); LayoutParams managerTitleLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, textSize + 50); managerTitleLayout.setLayoutParams(managerTitleLayoutParams); managerTitleLayout.setPadding(managerPad, managerPad - 4, managerPad, managerPad + 4); TextView nameText = new TextView(context); nameText.setText(R.string.filename); nameText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); LayoutParams nameTextParams = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 3); nameText.setTextColor(Color.parseColor("#d5ac84")); nameText.setGravity(Gravity.CENTER); nameText.setLayoutParams(nameTextParams); managerTitleLayout.addView(nameText); TextView progressText = new TextView(context); LayoutParams progressTextParams = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 4); progressText.setText(R.string.progress); progressText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); progressText.setTextColor(Color.parseColor("#d5ac84")); progressText.setGravity(Gravity.CENTER); progressText.setLayoutParams(progressTextParams); managerTitleLayout.addView(progressText); TextView speedText = new TextView(context); speedText.setText(R.string.speed); speedText.setTextColor(Color.parseColor("#d5ac84")); speedText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); LayoutParams speedTextParams = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2); speedText.setGravity(Gravity.CENTER); speedText.setLayoutParams(speedTextParams); managerTitleLayout.addView(speedText); TextView sizeText = new TextView(context); sizeText.setText(R.string.size); sizeText.setTextColor(Color.parseColor("#d5ac84")); sizeText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); LayoutParams sizeTextParams = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1); sizeText.setGravity(Gravity.CENTER); sizeText.setLayoutParams(sizeTextParams); managerTitleLayout.addView(sizeText); TextView handleText = new TextView(context); handleText.setText(R.string.operation); handleText.setTextColor(Color.parseColor("#d5ac84")); handleText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); LayoutParams handleTextParams = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2); handleText.setGravity(Gravity.CENTER); handleText.setLayoutParams(handleTextParams); managerTitleLayout.addView(handleText); LayoutParams parms = new LayoutParams(LayoutParams.MATCH_PARENT, 0); parms.weight = 1; parms.leftMargin = 30; parms.rightMargin = 30; parms.topMargin = managerPad - 5; managerLayout.addView(managerTitleLayout, parms); adapterLinearLayout = new FilmLinearLayout(context); LayoutParams adapterLinearLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, 0); adapterLinearLayoutParams.weight = 6; managerLayout.addView(adapterLinearLayout, adapterLinearLayoutParams); adapterLinearLayout.setId(FilmLinearLayout.ADAPTERLINEARLAYOUT_ID); int pading = 20; LinearLayout pageIndexLayout = new LinearLayout(context); pageIndexLayout.setOrientation(LinearLayout.HORIZONTAL); LayoutParams pageIndexLayoutLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); pageIndexLayout.setLayoutParams(pageIndexLayoutLayoutParams); pageIndexLayoutLayoutParams.setMargins(0, pading, 0, 0); pageIndexLayout.setGravity(Gravity.CENTER); Button preButton = new FocusAbleButton(context); preButton.setText(R.string.pre_page); preButton.setTextColor(Color.WHITE); preButton.setGravity(Gravity.CENTER); preButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); LayoutParams preButtonViewParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); preButton.setLayoutParams(preButtonViewParams); pageIndexLayout.addView(preButton); preButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { adapterLinearLayout.showPrePage(); pageIndexTextview.setText( adapterLinearLayout.getCurrentPage() + "/" + adapterLinearLayout.getTotalPage()); } }); preButton.setPadding(pading, 0, pading, 0); Button nextButton = new FocusAbleButton(context); nextButton.setText(R.string.next_page); nextButton.setTextColor(Color.WHITE); nextButton.setGravity(Gravity.CENTER); nextButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); LayoutParams nextButtonViewParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); nextButtonViewParams.leftMargin = textSize - 5; nextButton.setLayoutParams(nextButtonViewParams); pageIndexLayout.addView(nextButton); nextButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { adapterLinearLayout.showNextPage(); pageIndexTextview.setText( adapterLinearLayout.getCurrentPage() + "/" + adapterLinearLayout.getTotalPage()); } }); nextButton.setPadding(pading, 0, pading, 0); pageIndexTextview = new TextView(context); pageIndexTextview.setText( adapterLinearLayout.getCurrentPage() + "/" + adapterLinearLayout.getTotalPage()); pageIndexTextview.setTextColor(Color.WHITE); pageIndexTextview.setGravity(Gravity.CENTER); pageIndexTextview.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); LayoutParams pageIndexTextviewParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); pageIndexTextviewParams.leftMargin = textSize - 5; pageIndexTextview.setLayoutParams(pageIndexTextviewParams); pageIndexLayout.addView(pageIndexTextview); LayoutParams pageIndexLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, 0); pageIndexLayoutParams.weight = 1; managerLayout.addView(pageIndexLayout, pageIndexLayoutParams); TextView warnInfoTextView = new TextView(getContext()); warnInfoTextView.setText(R.string.down_manager_warn_info); warnInfoTextView.setTextColor(Color.WHITE); warnInfoTextView.setGravity(Gravity.CENTER); warnInfoTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); android.widget.RelativeLayout.LayoutParams warnInfoLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); warnInfoLayoutParams.addRule(RelativeLayout.BELOW, MANAGERLAYOUT_ID); warnInfoLayoutParams.addRule(RelativeLayout.ALIGN_LEFT, MANAGERLAYOUT_ID); warnInfoLayoutParams.topMargin = textSize - 10; contentLayout.addView(warnInfoTextView, warnInfoLayoutParams); }
private void init() { calendarGesture = new GestureDetector(context, new GestureListener()); cal = Calendar.getInstance(); base = new RelativeLayout(context); base.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); base.setMinimumHeight(40); base.setId(baseId); LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.leftMargin = 16; params.topMargin = 40; params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); params.addRule(RelativeLayout.CENTER_VERTICAL); prev = new ImageView(context); prev.setId(preId); prev.setLayoutParams(params); prev.setImageResource(R.drawable.navigation_previous_item); prev.setOnClickListener(this); base.addView(prev); params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(RelativeLayout.CENTER_VERTICAL); month = new TextView(context); month.setId(monthId); month.setLayoutParams(params); // month.setTextAppearance(context, android.R.attr.textAppearanceLarge); month.setText( cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()) + " " + cal.get(Calendar.YEAR)); month.setTextSize(25); base.addView(month); params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.rightMargin = 16; params.topMargin = 40; params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); params.addRule(RelativeLayout.CENTER_VERTICAL); next = new ImageView(context); next.setImageResource(R.drawable.navigation_next_item); next.setLayoutParams(params); next.setId(nextId); next.setOnClickListener(this); base.addView(next); addView(base); params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.bottomMargin = 20; params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); params.addRule(RelativeLayout.BELOW, base.getId()); calendar = new GridView(context); calendar.setLayoutParams(params); calendar.setVerticalSpacing(4); calendar.setHorizontalSpacing(4); calendar.setNumColumns(7); calendar.setChoiceMode(GridView.CHOICE_MODE_SINGLE); calendar.setDrawSelectorOnTop(true); mAdapter = new CalendarAdapter(context, cal); calendar.setAdapter(mAdapter); calendar.setOnTouchListener( new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return calendarGesture.onTouchEvent(event); } }); addView(calendar); }
private LayoutParams makeDividerLayoutParams() { LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); params.topMargin = (int) mDividerPadding; params.bottomMargin = (int) mDividerPadding; return params; }
@SuppressWarnings("deprecation") private void init(Context context, int initialColor) { setPadding(UI.dialogMargin, UI.dialogMargin, UI.dialogMargin, UI.dialogMargin); final int eachW = (UI._18sp * 7) >> 1; final boolean smallScreen = (UI.isLowDpiScreen && !UI.isLargeScreen); initialColor = 0xff000000 | (initialColor & 0x00ffffff); hsv = new HSV(); hsv.fromRGB(initialColor); hsvTmp = new HSV(); bmpRect = new Rect(0, 0, 1, 1); this.initialColor = initialColor; currentColor = initialColor; sliderColor = (UI.isAndroidThemeLight() ? 0xff000000 : 0xffffffff); final LinearLayout l = new LinearLayout(context); l.setId(1); l.setWeightSum(2); LayoutParams p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); p.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); p.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); addView(l, p); final TextView lbl = new TextView(context); lbl.setBackgroundDrawable(new ColorDrawable(initialColor)); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, smallScreen ? (UI.defaultControlSize) >> 1 : UI.defaultControlSize); lp.weight = 1; lp.rightMargin = UI.controlSmallMargin; l.addView(lbl, lp); bgCurrent = new ColorDrawable(initialColor); lblCurrent = new TextView(context); lblCurrent.setBackgroundDrawable(bgCurrent); lp = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, smallScreen ? (UI.defaultControlSize) >> 1 : UI.defaultControlSize); lp.weight = 1; lp.leftMargin = UI.controlSmallMargin; l.addView(lblCurrent, lp); final int textSize = (smallScreen ? UI._14sp : UI._18sp); TextView lblTit = new TextView(context); lblTit.setId(2); lblTit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); lblTit.setSingleLine(); lblTit.setGravity(Gravity.CENTER); lblTit.setText("H"); p = new LayoutParams(eachW, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); p.addRule(RelativeLayout.BELOW, 1); addView(lblTit, p); lblTit = new TextView(context); lblTit.setId(3); lblTit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); lblTit.setSingleLine(); lblTit.setGravity(Gravity.CENTER); lblTit.setText("S"); p = new LayoutParams(eachW, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); p.addRule(RelativeLayout.BELOW, 1); addView(lblTit, p); lblTit = new TextView(context); lblTit.setId(4); lblTit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); lblTit.setSingleLine(); lblTit.setGravity(Gravity.CENTER); lblTit.setText("V"); p = new LayoutParams(eachW, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); p.addRule(RelativeLayout.BELOW, 1); addView(lblTit, p); barH = new BgSeekBar(context); barH.setId(5); barH.setMax(360); barH.setValue((int) (hsv.h * 360.0)); barH.setSliderMode(true); barH.setVertical(true); p = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.leftMargin = ((eachW - UI.defaultControlSize) >> 1); p.addRule(RelativeLayout.ALIGN_LEFT, 2); p.addRule(RelativeLayout.BELOW, 2); p.addRule(RelativeLayout.ABOVE, 6); addView(barH, p); barS = new BgSeekBar(context); barS.setMax(100); barS.setValue((int) (hsv.s * 100.0)); barS.setSliderMode(true); barS.setVertical(true); p = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.leftMargin = ((eachW - UI.defaultControlSize) >> 1); p.addRule(RelativeLayout.ALIGN_LEFT, 3); p.addRule(RelativeLayout.BELOW, 3); p.addRule(RelativeLayout.ABOVE, 6); addView(barS, p); barV = new BgSeekBar(context); barV.setMax(100); barV.setValue((int) (hsv.v * 100.0)); barV.setSliderMode(true); barV.setVertical(true); p = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.leftMargin = ((eachW - UI.defaultControlSize) >> 1); p.addRule(RelativeLayout.ALIGN_LEFT, 4); p.addRule(RelativeLayout.BELOW, 4); p.addRule(RelativeLayout.ABOVE, 6); addView(barV, p); txtH = new EditText(context); txtH.setId(6); txtH.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); txtH.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); txtH.setSingleLine(); txtH.setGravity(Gravity.CENTER); txtH.setText(Integer.toString((int) (hsv.h * 360.0))); p = new LayoutParams(eachW, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); p.addRule(RelativeLayout.ABOVE, 7); addView(txtH, p); txtS = new EditText(context); txtS.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); txtS.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); txtS.setSingleLine(); txtS.setGravity(Gravity.CENTER); txtS.setText(Integer.toString((int) (hsv.s * 100.0))); p = new LayoutParams(eachW, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); p.addRule(RelativeLayout.ABOVE, 7); addView(txtS, p); txtV = new EditText(context); txtV.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); txtV.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); txtV.setSingleLine(); txtV.setGravity(Gravity.CENTER); txtV.setText(Integer.toString((int) (hsv.v * 100.0))); p = new LayoutParams(eachW, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); p.addRule(RelativeLayout.ABOVE, 7); addView(txtV, p); txt = new EditText(context); txt.setId(7); txt.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); txt.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); txt.setSingleLine(); txt.setGravity(Gravity.CENTER); txt.setText(ColorUtils.toHexColor(initialColor)); p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); p.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); addView(txt, p); lbl.setOnClickListener(this); barH.setOnBgSeekBarChangeListener(this); barH.setOnBgSeekBarDrawListener(this); barS.setOnBgSeekBarChangeListener(this); barS.setOnBgSeekBarDrawListener(this); barV.setOnBgSeekBarChangeListener(this); barV.setOnBgSeekBarDrawListener(this); txtH.addTextChangedListener(this); txtS.addTextChangedListener(this); txtV.addTextChangedListener(this); txt.addTextChangedListener(this); }
@Override public void onScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (mExternalOnScrollListener != null) { mExternalOnScrollListener.onScroll( view, firstVisibleItem, visibleItemCount, totalItemCount); } if (!didScroll) { return; } firstVisibleItem -= mListView.getHeaderViewsCount(); if (firstVisibleItem < 0) { mHeader.removeAllViews(); return; } updateScrollBar(); if (visibleItemCount > 0 && firstVisibleItem == 0 && mHeader.getChildAt(0) == null) { addSectionHeader(0); lastResetSection = 0; } int realFirstVisibleItem = getRealFirstVisibleItem(firstVisibleItem, visibleItemCount); if (totalItemCount > 0 && previousFirstVisibleItem != realFirstVisibleItem) { direction = realFirstVisibleItem - previousFirstVisibleItem; actualSection = mAdapter.getSection(realFirstVisibleItem); boolean currIsHeader = mAdapter.isSectionHeader(realFirstVisibleItem); boolean prevHasHeader = mAdapter.hasSectionHeaderView(actualSection - 1); boolean nextHasHeader = mAdapter.hasSectionHeaderView(actualSection + 1); boolean currHasHeader = mAdapter.hasSectionHeaderView(actualSection); boolean currIsLast = mAdapter.getRowInSection(realFirstVisibleItem) == mAdapter.numberOfRows(actualSection) - 1; boolean prevHasRows = mAdapter.numberOfRows(actualSection - 1) > 0; boolean currIsFirst = mAdapter.getRowInSection(realFirstVisibleItem) == 0; boolean needScrolling = currIsFirst && !currHasHeader && prevHasHeader && realFirstVisibleItem != firstVisibleItem; boolean needNoHeaderUpToHeader = currIsLast && currHasHeader && !nextHasHeader && realFirstVisibleItem == firstVisibleItem && Math.abs(mListView.getChildAt(0).getTop()) >= mListView.getChildAt(0).getHeight() / 2; noHeaderUpToHeader = false; if (currIsHeader && !prevHasHeader && firstVisibleItem >= 0) { resetHeader(direction < 0 ? actualSection - 1 : actualSection); } else if ((currIsHeader && firstVisibleItem > 0) || needScrolling) { if (!prevHasRows) { resetHeader(actualSection - 1); } startScrolling(); } else if (needNoHeaderUpToHeader) { noHeaderUpToHeader = true; } else if (lastResetSection != actualSection) { resetHeader(actualSection); } previousFirstVisibleItem = realFirstVisibleItem; } if (scrollingStart) { int scrolled = realFirstVisibleItem >= firstVisibleItem ? mListView.getChildAt(realFirstVisibleItem - firstVisibleItem).getTop() : 0; if (!doneMeasuring) { setMeasurements(realFirstVisibleItem, firstVisibleItem); } int headerH = doneMeasuring ? (prevH - nextH) * direction * Math.abs(scrolled) / (direction < 0 ? nextH : prevH) + (direction > 0 ? nextH : prevH) : 0; mHeader.scrollTo(0, -Math.min(0, scrolled - headerH)); if (doneMeasuring && headerH != mHeader.getLayoutParams().height) { LayoutParams p = (LayoutParams) (direction < 0 ? next.getLayoutParams() : previous.getLayoutParams()); p.topMargin = headerH - p.height; mHeader.getLayoutParams().height = headerH; mHeader.requestLayout(); } } if (noHeaderUpToHeader) { if (lastResetSection != actualSection) { addSectionHeader(actualSection); lastResetSection = actualSection + 1; } mHeader.scrollTo( 0, mHeader.getLayoutParams().height - (mListView.getChildAt(0).getHeight() + mListView.getChildAt(0).getTop())); } }