android.widget.LinearLayout#setPadding ( )源码实例Demo

下面列出了android.widget.LinearLayout#setPadding ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: facebooklogin   文件: WebDialog.java
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView(int margin) {
    LinearLayout webViewContainer = new LinearLayout(getContext());
    webView = new WebView(getContext());
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(new DialogWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    webView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                                         ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setVisibility(View.INVISIBLE);
    webView.getSettings().setSavePassword(false);

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(webView);
    contentFrameLayout.addView(webViewContainer);
}
 
public void setPreviewColor() {
    if (this.mView == null) {
        return;
    }
    final ImageView iView = new ImageView(getContext());
    final LinearLayout widgetFrameView = ((LinearLayout) this.mView
            .findViewById(android.R.id.widget_frame));
    if (widgetFrameView == null) {
        return;
    }
    widgetFrameView.setPadding(widgetFrameView.getPaddingLeft(),
            widgetFrameView.getPaddingTop(), (int) (this.mDensity * 8),
            widgetFrameView.getPaddingBottom());
    // remove already create preview image
    final int count = widgetFrameView.getChildCount();
    if (count > 0) {
        widgetFrameView.removeViews(0, count);
    }
    widgetFrameView.addView(iView);
    iView.setBackgroundDrawable(new AlphaPatternDrawable(
            (int) (5 * this.mDensity)));
    iView.setImageBitmap(getPreviewBitmap());
}
 
源代码3 项目: BottomDialog   文件: BottomDialog.java
public CustomDialog(Context context) {
    super(context);
    items = new ArrayList<>();
    icon = getContext().getResources().getDimensionPixelSize(R.dimen.dimen_32_dp);
    padding = getContext().getResources().getDimensionPixelSize(R.dimen.dimen_8_dp);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    container = new LinearLayout(getContext());
    container.setLayoutParams(params);
    container.setBackgroundColor(Color.WHITE);
    container.setOrientation(LinearLayout.VERTICAL);
    container.setPadding(0, padding, 0, padding);
    ScrollView scrollView = new ScrollView(getContext());
    scrollView.addView(container);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(scrollView, params);
    setCancelable(true);
    setCanceledOnTouchOutside(true);
    getWindow().setGravity(Gravity.BOTTOM);
    getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
    getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
}
 
源代码4 项目: openlauncher   文件: ColorPickerDialogBuilder.java
private ColorPickerDialogBuilder(Context context, int theme) {
	defaultMargin = getDimensionAsPx(context, R.dimen.default_slider_margin);
	defaultMarginTop = getDimensionAsPx(context, R.dimen.default_margin_top);

	builder = new AlertDialog.Builder(context, theme);
	pickerContainer = new LinearLayout(context);
	pickerContainer.setOrientation(LinearLayout.VERTICAL);
	pickerContainer.setGravity(Gravity.CENTER_HORIZONTAL);
	pickerContainer.setPadding(defaultMargin, defaultMarginTop, defaultMargin, 0);

	LinearLayout.LayoutParams layoutParamsForColorPickerView = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
	layoutParamsForColorPickerView.weight = 1;
	colorPickerView = new ColorPickerView(context);

	pickerContainer.addView(colorPickerView, layoutParamsForColorPickerView);

	builder.setView(pickerContainer);
}
 
源代码5 项目: AndroidStudyDemo   文件: CustomListView.java
/**
 * 添加下拉刷新的HeadView 
 * @date 2013-11-11 下午9:48:26
 * @change JohnWatson
 * @version 1.0
 */
private void addHeadView() {
	mHeadView = (LinearLayout) mInflater.inflate(R.layout.head, null);

	mArrowImageView = (ImageView) mHeadView
			.findViewById(R.id.head_arrowImageView);
	mArrowImageView.setMinimumWidth(70);
	mArrowImageView.setMinimumHeight(50);
	mProgressBar = (ProgressBar) mHeadView
			.findViewById(R.id.head_progressBar);
	mTipsTextView = (TextView) mHeadView.findViewById(
			R.id.head_tipsTextView);
	mLastUpdatedTextView = (TextView) mHeadView
			.findViewById(R.id.head_lastUpdatedTextView);

	measureView(mHeadView);
	mHeadViewHeight = mHeadView.getMeasuredHeight();
	mHeadViewWidth = mHeadView.getMeasuredWidth();
	
	mHeadView.setPadding(0, -1 * mHeadViewHeight, 0, 0);
	mHeadView.invalidate();

	Log.v("size", "width:" + mHeadViewWidth + " height:"
			+ mHeadViewHeight);

	addHeaderView(mHeadView, null, false);
	
	mHeadState = DONE;
}
 
源代码6 项目: fingerpoetry-android   文件: EditPagePort.java
private void initBottom(LinearLayout llBottom, float ratio) {
	LinearLayout llAt = new LinearLayout(activity);
	llAt.setPadding(0, 0, 0, 5);
	llAt.setBackgroundColor(0xffffffff);
	int bottomHeight = (int) (DESIGN_BOTTOM_HEIGHT * ratio);
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, bottomHeight);
	llBottom.addView(llAt, lp);

	tvAt = new TextView(activity);
	tvAt.setTextColor(0xff3b3b3b);
	tvAt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
	tvAt.setGravity(Gravity.BOTTOM);
	tvAt.setText("@");
	int padding = (int) (DESIGN_LEFT_PADDING * ratio);
	tvAt.setPadding(padding, 0, padding, 0);
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	llAt.addView(tvAt, lp);
	tvAt.setOnClickListener(this);
	if (isShowAtUserLayout(platform.getName())) {
		tvAt.setVisibility(View.VISIBLE);
	} else {
		tvAt.setVisibility(View.INVISIBLE);
	}

	tvTextCouter = new TextView(activity);
	tvTextCouter.setTextColor(0xff3b3b3b);
	tvTextCouter.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
	tvTextCouter.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
	onTextChanged(etContent.getText(), 0, 0, 0);
	tvTextCouter.setPadding(padding, 0, padding, 0);
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	lp.weight = 1;
	llAt.addView(tvTextCouter, lp);

	View v = new View(activity);
	v.setBackgroundColor(0xffcccccc);
	int px_1 = ratio > 1 ? ((int) ratio) : 1;
	lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, px_1);
	llBottom.addView(v, lp);
}
 
private void init() {
    LayoutInflater.from(mContext).inflate(R.layout.grouped_checkbox, this, true);

    mRootLinearLayout = (LinearLayout) findViewById(R.id.rootLinearLayout);
    mParentCheckbox = (EnhancedCheckbox) findViewById(R.id.parentCheckbox);
    mChildGridView = (ExpandableHeightGridView) findViewById(R.id.childPickGridView);

    mRootLinearLayout.setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom());

    childItemList = new ArrayList<String>();

    getAttributesAndStore();
    initView();
}
 
源代码8 项目: gcm   文件: GroupsFragment.java
@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> senders = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < senders.size(); i++) {
        Sender sender = senders.valueAt(i);
        if (sender.groups.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderText = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderText.setText(getString(R.string.groups_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (DeviceGroup deviceGroup : sender.groups.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.group_grey600);
                label.setText(deviceGroup.notificationKeyName);
                label.setBackgroundResource(selectableBackgroundResource);
                label.setTag(R.id.tag_action, ACTION_OPEN_GROUP);
                label.setTag(R.id.tag_senderid, sender.senderId);
                label.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                label.setOnClickListener(this);

                button.setText(R.string.groups_delete);
                button.setTag(R.id.tag_action, ACTION_DELETE_GROUP);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.groups_no_groups_available));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.groups_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}
 
源代码9 项目: YiBo   文件: ImageViewer4GifActivity.java
private void initComponent() {
	LinearLayout llHeaderBase = (LinearLayout)findViewById(R.id.llHeaderBase);
	LinearLayout llToolbar = (LinearLayout)findViewById(R.id.llToolbar);
	ivRotateLeft = (ImageView) findViewById(R.id.ivRotateLeft);
	ivRotateRight = (ImageView) findViewById(R.id.ivRotateRight);
	ivZoomIn = (ImageView) findViewById(R.id.ivZoomIn);
	ivZoomOut = (ImageView) findViewById(R.id.ivZoomOut);
	
	ThemeUtil.setSecondaryImageHeader(llHeaderBase);
	llToolbar.setBackgroundDrawable(theme.getDrawable("bg_toolbar"));
	int padding8 = theme.dip2px(8);
	llToolbar.setPadding(padding8, padding8, padding8, padding8);
	ivRotateLeft.setBackgroundDrawable(theme.getDrawable("selector_btn_image_rotate_left"));
	ivRotateRight.setBackgroundDrawable(theme.getDrawable("selector_btn_image_rotate_right"));
	ivZoomIn.setBackgroundDrawable(theme.getDrawable("selector_btn_image_zoom_in"));
	ivZoomOut.setBackgroundDrawable(theme.getDrawable("selector_btn_image_zoom_out"));
	
	TextView tvTitle = (TextView) this.findViewById(R.id.tvTitle);
	tvTitle.setText(R.string.title_image_viewer);

	btnOperate = (Button) findViewById(R.id.btnOperate);

	ivImageViewer = (ImageViewTouchBase) findViewById(R.id.ivImageViewer);
	ivImageViewer.setRecycler(new ImageViewTouchBase.Recycler() {
		@Override
		public void recycle(Bitmap b) {
			if (!(b == null || b.isRecycled())) {
				if (Logger.isDebug()) {
					Log.d(TAG, "Recycle Bitmap : " + b);
				}
				b.recycle();
			}
		}
	});

	ivImageViewer.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			if (mode == Mode.View) {
				updateView();
			}
		}
	});
}
 
源代码10 项目: iGap-Android   文件: ViewMaker.java
static View getVideoItem(boolean withText) {

        LinearLayout mainContainer = new LinearLayout(G.context);
        mainContainer.setId(R.id.mainContainer);
        mainContainer.setOrientation(HORIZONTAL);
        LinearLayout.LayoutParams layout_882 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        mainContainer.setLayoutParams(layout_882);

        LinearLayout linearLayout_223 = new LinearLayout(G.context);
        linearLayout_223.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_509 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        linearLayout_223.setLayoutParams(layout_509);

        LinearLayout contentContainer = new LinearLayout(G.context);
        LinearLayout.LayoutParams layout_5095 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        contentContainer.setPadding(i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4));
        contentContainer.setLayoutParams(layout_5095);
        contentContainer.setId(R.id.contentContainer);

        LinearLayout m_container = new LinearLayout(G.context);
        m_container.setId(R.id.m_container);
        m_container.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_518 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        m_container.setLayoutParams(layout_518);

        FrameLayout frameLayout_642 = new FrameLayout(G.context);
        LinearLayout.LayoutParams layout_535 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        frameLayout_642.setLayoutParams(layout_535);

        ReserveSpaceRoundedImageView thumbnail = new ReserveSpaceRoundedImageView(G.context);
        thumbnail.setId(R.id.thumbnail);
        FrameLayout.LayoutParams layout_679 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        thumbnail.setLayoutParams(layout_679);
        thumbnail.setScaleType(ImageView.ScaleType.FIT_XY);
        thumbnail.setCornerRadius((int) G.context.getResources().getDimension(R.dimen.messageBox_cornerRadius));
        frameLayout_642.addView(thumbnail);

        TextView duration = new TextView(G.context);
        duration.setId(R.id.duration);
        duration.setBackgroundResource(R.drawable.bg_message_image_time);
        duration.setGravity(Gravity.CENTER_VERTICAL);
        duration.setSingleLine(true);
        duration.setPadding(i_Dp(R.dimen.dp4), dpToPixel(1), i_Dp(R.dimen.dp4), dpToPixel(1));
        duration.setText("3:48 (4.5 MB)");
        duration.setAllCaps(TRUE);
        duration.setTextColor(G.context.getResources().getColor(R.color.gray10));
        setTextSize(duration, R.dimen.dp10);
        setTypeFace(duration);
        FrameLayout.LayoutParams layout_49 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layout_49.gravity = Gravity.LEFT | Gravity.TOP;
        layout_49.bottomMargin = -dpToPixel(2);
        layout_49.leftMargin = dpToPixel(5);
        layout_49.topMargin = dpToPixel(7);
        duration.setLayoutParams(layout_49);
        frameLayout_642.addView(duration);

        frameLayout_642.addView(getProgressBar(0), new FrameLayout.LayoutParams(i_Dp(R.dimen.dp48), i_Dp(R.dimen.dp48), Gravity.CENTER));

        m_container.addView(frameLayout_642);

        if (withText) {
            m_container.addView(getTextView());
        }

        contentContainer.addView(m_container);
        linearLayout_223.addView(contentContainer);
        mainContainer.addView(linearLayout_223);

        return mainContainer;
    }
 
源代码11 项目: AndroidLinkup   文件: FollowList.java
public View getView(int position, View convertView, ViewGroup parent) {
	FollowListItem item = null;
	if (convertView == null) {
		LinearLayout llItem = new LinearLayout(parent.getContext());
		item = new FollowListItem();
		llItem.setTag(item);
		convertView = llItem;

		item.aivIcon = new AsyncImageView(getContext());
		int dp_52 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 52);
		int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(parent.getContext(), 10);
		int dp_5 = cn.sharesdk.framework.utils.R.dipToPx(parent.getContext(), 5);
		LinearLayout.LayoutParams lpIcon = new LinearLayout.LayoutParams(dp_52, dp_52);
		lpIcon.gravity = Gravity.CENTER_VERTICAL;
		lpIcon.setMargins(dp_10, dp_5, dp_10, dp_5);
		item.aivIcon.setLayoutParams(lpIcon);
		llItem.addView(item.aivIcon);

		LinearLayout llText = new LinearLayout(parent.getContext());
		llText.setPadding(0, dp_10, dp_10, dp_10);
		llText.setOrientation(LinearLayout.VERTICAL);
		LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		lpText.gravity = Gravity.CENTER_VERTICAL;
		lpText.weight = 1;
		llText.setLayoutParams(lpText);
		llItem.addView(llText);

		item.tvName = new TextView(parent.getContext());
		item.tvName.setTextColor(0xff000000);
		item.tvName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
		item.tvName.setSingleLine();
		llText.addView(item.tvName);

		item.tvSign = new TextView(parent.getContext());
		item.tvSign.setTextColor(0x7f000000);
		item.tvSign.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
		item.tvSign.setSingleLine();
		llText.addView(item.tvSign);

		item.ivCheck = new ImageView(parent.getContext());
		item.ivCheck.setPadding(0, 0, dp_10, 0);
		LinearLayout.LayoutParams lpCheck = new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		lpCheck.gravity = Gravity.CENTER_VERTICAL;
		item.ivCheck.setLayoutParams(lpCheck);
		llItem.addView(item.ivCheck);
	} else {
		item = (FollowListItem) convertView.getTag();
	}

	Following following = getItem(position);
	item.tvName.setText(following.screeName);
	item.tvSign.setText(following.description);
	item.ivCheck.setImageBitmap(following.checked ? bmChd : bmUnch);
	if (isFling()) {
		Bitmap bm = BitmapProcessor.getBitmapFromCache(following.icon);
		if (bm != null && !bm.isRecycled()) {
			item.aivIcon.setImageBitmap(bm);
		} else {
			item.aivIcon.execute(null, AsyncImageView.DEFAULT_TRANSPARENT);
		}
	} else {
		item.aivIcon.execute(following.icon);
	}

	if (position == getCount() - 1) {
		next();
	}
	return convertView;
}
 
源代码12 项目: UltimateAndroid   文件: RoundCornerProgressBar.java
@SuppressLint("NewApi")
private void setup(Context context, AttributeSet attrs) {
	int color;
	TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerProgress);

       DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
	radius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, metrics);
	radius = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundRadius, radius);
	
	layoutBackground = (LinearLayout) findViewById(R.id.round_corner_progress_background);
	padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, padding, metrics);
	padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundPadding, padding);
	layoutBackground.setPadding(padding, padding, padding, padding);
	if(!isBackgroundColorSetBeforeDraw) {
		color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_backgroundColor, backgroundColor);
		setBackgroundColor(color);
	}
	ViewTreeObserver observer = layoutBackground.getViewTreeObserver(); 
	observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
	    @Override 
	    public void onGlobalLayout() { 
	    	layoutBackground.getViewTreeObserver().removeOnGlobalLayoutListener(this); 
	    	int height = 0;
	    	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
	    		backgroundWidth = layoutBackground.getMeasuredWidth();
	    		height = layoutBackground.getMeasuredHeight();
	    	} else {
		    	backgroundWidth = layoutBackground.getWidth();
	    		height = layoutBackground.getHeight();
	    	}
    		backgroundHeight = (height == 0) ? (int) dp2px(DEFAULT_PROGRESS_BAR_HEIGHT) : height ;
			LayoutParams params = (LayoutParams)layoutBackground.getLayoutParams();
               params.height = backgroundHeight;
			layoutBackground.setLayoutParams(params);
			setProgress(progress);
	    } 
	});

	layoutProgress = (LinearLayout) findViewById(R.id.round_corner_progress_progress);
	if(!isProgressColorSetBeforeDraw) {
		color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_progressColor, progressColor);
		setProgressColor(color);
	}

	if(!isMaxProgressSetBeforeDraw) {
		max = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_max, 0);
	}
	if(!isProgressSetBeforeDraw) {
		progress = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_progress, 0);
	}

	typedArray.recycle();
}
 
源代码13 项目: gcm   文件: InstanceIdFragment.java
@Override
public void refresh() {
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            final String instanceId = mInstanceIdHelper.getInstanceId();
            final String creationTime = DateFormat.getDateTimeInstance()
                    .format(new Date(mInstanceIdHelper.getCreationTime()));
            final Activity activity = getActivity();
            if (activity != null) {
                Handler handler = new Handler(activity.getMainLooper());
                handler.post(new Runnable() {
                    public void run() {
                        setValue(activity.findViewById(R.id.iid_instance_id), instanceId);
                        setValue(activity.findViewById(R.id.iid_creation_time), creationTime);
                    }
                });
            }
            return null;
        }
    }.execute();
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        if (sender.appTokens.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Token token : sender.appTokens.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.smartphone_grey600);
                label.setText(token.scope + " - "
                        + AbstractFragment.truncateToMediumString(token.token));
                button.setText(R.string.iid_delete_token);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_scope, token.scope);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.iid_no_tokens));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout tokensView = (FrameLayout) getActivity().findViewById(R.id.iid_tokens_wrapper);
    tokensView.removeAllViews();
    tokensView.addView(sendersList);
}
 
private void editPasswordDialog(final String oldPass) {
    mOldPassword = oldPass;

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    int padding = Math.round(getResources().getDimension(R.dimen.dialog_padding));
    linearLayout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText oldPassword = new AppCompatEditText(getActivity());
    if (!oldPass.isEmpty()) {
        oldPassword.setInputType(InputType.TYPE_CLASS_TEXT
                | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        oldPassword.setHint(getString(R.string.old_password));
        linearLayout.addView(oldPassword);
    }

    final AppCompatEditText newPassword = new AppCompatEditText(getActivity());
    newPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    newPassword.setHint(getString(R.string.new_password));
    linearLayout.addView(newPassword);

    final AppCompatEditText confirmNewPassword = new AppCompatEditText(getActivity());
    confirmNewPassword.setInputType(InputType.TYPE_CLASS_TEXT
            | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    confirmNewPassword.setHint(getString(R.string.confirm_new_password));
    linearLayout.addView(confirmNewPassword);

    new Dialog(getActivity()).setView(linearLayout)
            .setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
            })
            .setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
                if (!oldPass.isEmpty() && !oldPassword.getText().toString().equals(Utils
                        .decodeString(oldPass))) {
                    Utils.toast(getString(R.string.old_password_wrong), getActivity());
                    return;
                }

                if (newPassword.getText().toString().isEmpty()) {
                    Utils.toast(getString(R.string.password_empty), getActivity());
                    return;
                }

                if (!newPassword.getText().toString().equals(confirmNewPassword.getText()
                        .toString())) {
                    Utils.toast(getString(R.string.password_not_match), getActivity());
                    return;
                }

                if (newPassword.getText().toString().length() > 32) {
                    Utils.toast(getString(R.string.password_too_long), getActivity());
                    return;
                }

                AppSettings.savePassword(Utils.encodeString(newPassword.getText()
                        .toString()), getActivity());
                if (mFingerprint != null) {
                    mFingerprint.setEnabled(true);
                }
            })
            .setOnDismissListener(dialogInterface -> mOldPassword = null).show();
}
 
源代码15 项目: iGap-Android   文件: ViewMaker.java
static View getViewVote() {

        LinearLayout lyt_vote = new LinearLayout(context);
        lyt_vote.setId(R.id.lyt_vote);
        lyt_vote.setGravity(BOTTOM);
        setLayoutDirection(lyt_vote, View.LAYOUT_DIRECTION_LTR);
        lyt_vote.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_356 = new LinearLayout.LayoutParams(i_Dp(R.dimen.dp48), ViewGroup.LayoutParams.MATCH_PARENT);
        layout_356.gravity = BOTTOM;
        lyt_vote.setLayoutParams(layout_356);

        LinearLayout lyt_vote_sub = new LinearLayout(context);
        lyt_vote_sub.setOrientation(VERTICAL);
        lyt_vote_sub.setId(R.id.lyt_vote_sub);

        lyt_vote_sub.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.rectangel_white_round));


        GradientDrawable circleDarkColor = (GradientDrawable) lyt_vote_sub.getBackground();
        circleDarkColor.setColor(Color.parseColor(G.appBarColor));

        LinearLayout.LayoutParams layout_35644 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layout_35644.leftMargin = i_Dp(R.dimen.dp2);
        lyt_vote_sub.setLayoutParams(layout_35644);

        LinearLayout lyt_vote_up = new LinearLayout(context);
        lyt_vote_up.setId(R.id.lyt_vote_up);
        lyt_vote_up.setGravity(CENTER);
        lyt_vote_up.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_799 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lyt_vote_up.setPadding(0, 0, 0, i_Dp(R.dimen.dp6));
        layout_799.bottomMargin = i_Dp(dp4);
        lyt_vote_up.setLayoutParams(layout_799);

        TextView txt_vote_up = new TextView(context);
        txt_vote_up.setId(R.id.txt_vote_up);
        txt_vote_up.setText("0");
        txt_vote_up.setTextAppearance(context, R.style.ChatMessages_Time);
        txt_vote_up.setSingleLine(true);
        setTypeFace(txt_vote_up);

        txt_vote_up.setTextColor(Color.parseColor(G.voteIconTheme));
        LinearLayout.LayoutParams layout_713 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dpToPixel(16));
        txt_vote_up.setLayoutParams(layout_713);
        lyt_vote_up.addView(txt_vote_up);

        MaterialDesignTextView img_vote_up = new MaterialDesignTextView(context);
        img_vote_up.setId(R.id.img_vote_up);
        img_vote_up.setText(context.getResources().getString(R.string.md_thumb_up));
        img_vote_up.setTextColor(Color.parseColor(G.voteIconTheme));
        setTextSize(img_vote_up, R.dimen.dp16);
        LinearLayout.LayoutParams layout_216 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        img_vote_up.setLayoutParams(layout_216);
        lyt_vote_up.addView(img_vote_up);
        lyt_vote_sub.addView(lyt_vote_up);

        LinearLayout lyt_vote_down = new LinearLayout(context);

        lyt_vote_down.setBackgroundDrawable(G.context.getResources().getDrawable(R.drawable.rectangel_white_round));

        GradientDrawable circleDarkColor_2 = (GradientDrawable) lyt_vote_down.getBackground();
        circleDarkColor_2.setColor(Color.parseColor(G.appBarColor));

        lyt_vote_down.setId(R.id.lyt_vote_down);
        lyt_vote_down.setPadding(0, i_Dp(R.dimen.dp6), 0, 0);
        lyt_vote_down.setGravity(CENTER);
        lyt_vote_down.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_221 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lyt_vote_down.setLayoutParams(layout_221);

        MaterialDesignTextView img_vote_down = new MaterialDesignTextView(context);
        img_vote_down.setId(R.id.img_vote_down);
        img_vote_down.setText(context.getResources().getString(R.string.md_thumb_down));
        img_vote_down.setTextColor(Color.parseColor(G.voteIconTheme));
        setTextSize(img_vote_down, R.dimen.dp16);
        LinearLayout.LayoutParams layout_877 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        img_vote_down.setLayoutParams(layout_877);
        lyt_vote_down.addView(img_vote_down);

        TextView txt_vote_down = new TextView(context);
        txt_vote_down.setId(R.id.txt_vote_down);
        txt_vote_down.setText("0");
        txt_vote_down.setTextAppearance(context, R.style.ChatMessages_Time);
        setTypeFace(txt_vote_down);
        txt_vote_down.setSingleLine(true);
        txt_vote_down.setTextColor(Color.parseColor(G.voteIconTheme));
        LinearLayout.LayoutParams layout_856 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dpToPixel(16));
        txt_vote_down.setLayoutParams(layout_856);

        lyt_vote_down.addView(txt_vote_down);
        lyt_vote_sub.addView(lyt_vote_down);
        lyt_vote.addView(lyt_vote_sub);
        lyt_vote.addView(getForwardButton());

        return lyt_vote;
    }
 
源代码16 项目: iGap-Android   文件: ViewMaker.java
static View getLocationItem() {

        LinearLayout mainContainer = new LinearLayout(G.context);
        mainContainer.setId(R.id.mainContainer);
        LinearLayout.LayoutParams layout_761 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        mainContainer.setLayoutParams(layout_761);

        LinearLayout linearLayout_532 = new LinearLayout(G.context);
        linearLayout_532.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_639 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        linearLayout_532.setLayoutParams(layout_639);

        LinearLayout contentContainer = new LinearLayout(G.context);
        contentContainer.setId(R.id.contentContainer);
        LinearLayout.LayoutParams layoutParamsContentContainer = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        contentContainer.setPadding(i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4));
        contentContainer.setLayoutParams(layoutParamsContentContainer);

        LinearLayout m_container = new LinearLayout(G.context);
        m_container.setId(R.id.m_container);
        m_container.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_788 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        m_container.setLayoutParams(layout_788);

        FrameLayout frameLayout = new FrameLayout(G.context);
        frameLayout.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT));

        ReserveSpaceRoundedImageView reserveSpaceRoundedImageView = new ReserveSpaceRoundedImageView(G.context);
        reserveSpaceRoundedImageView.setId(R.id.thumbnail);
        reserveSpaceRoundedImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        reserveSpaceRoundedImageView.setCornerRadius((int) G.context.getResources().getDimension(R.dimen.messageBox_cornerRadius));
        LinearLayout.LayoutParams layout_758 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        reserveSpaceRoundedImageView.setLayoutParams(layout_758);

        mainContainer.addView(linearLayout_532);
        linearLayout_532.addView(contentContainer);
        contentContainer.addView(m_container);
        m_container.addView(frameLayout);

        frameLayout.addView(reserveSpaceRoundedImageView);

        return mainContainer;
    }
 
源代码17 项目: coolreader   文件: FileBrowser.java
public View getView(int position, View convertView, ViewGroup parent)
{
	LinearLayout fileLayout = new LinearLayout(context);
	fileLayout.setLayoutParams(new LayoutParams(
			LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
	fileLayout.setOrientation(LinearLayout.HORIZONTAL);
	fileLayout.setPadding(5, 10, 0, 10);
	fileLayout.setBackgroundResource(R.drawable.bg_filebrowser);
	
	ImageView ivFile = new ImageView(context);
	ivFile.setLayoutParams(new LayoutParams(48, 48));
	
	TextView tvFile = new TextView(context);
	tvFile.setTextColor(android.graphics.Color.BLACK);


	tvFile.setPadding(5, 5, 0, 0);
	if (fileList.get(position) == null)
	{

		if (folderImageResId > 0)
			ivFile.setImageResource(folderImageResId);
		tvFile.setText(". .");
	}
	else if (fileList.get(position).isDirectory())
	{
		if (folderImageResId > 0)
			ivFile.setImageResource(folderImageResId);
		tvFile.setText(fileList.get(position).getName());
	}
	else
	{
		tvFile.setText(fileList.get(position).getName());
		Integer resId = fileImageResIdMap.get(getExtName(fileList.get(
				position).getName()));
		int fileImageResId = 0;
		if (resId != null)
		{
			if (resId > 0)
			{
				fileImageResId = resId;
			}

		}
		if (fileImageResId > 0)
			ivFile.setImageResource(fileImageResId);
		else if (otherFileImageResId > 0)
			ivFile.setImageResource(otherFileImageResId);
	}

	tvFile.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
			LayoutParams.WRAP_CONTENT));
	fileLayout.addView(ivFile);
	fileLayout.addView(tvFile);
	return fileLayout;
}
 
源代码18 项目: iGap-Android   文件: ViewMaker.java
static View getFileItem() {

        LinearLayout mainContainer = new LinearLayout(G.context);
        mainContainer.setId(R.id.mainContainer);
        mainContainer.setOrientation(HORIZONTAL);
        LinearLayout.LayoutParams layout_106 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        mainContainer.setLayoutParams(layout_106);

        LinearLayout linearLayout_768 = new LinearLayout(G.context);
        linearLayout_768.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_577 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        linearLayout_768.setLayoutParams(layout_577);

        LinearLayout contentContainer = new LinearLayout(G.context);
        LinearLayout.LayoutParams layoutParamsContentContainer = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        contentContainer.setId(R.id.contentContainer);
        contentContainer.setLayoutParams(layoutParamsContentContainer);
        contentContainer.setPadding(i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4));
        contentContainer.setLayoutParams(layoutParamsContentContainer);

        LinearLayout m_container = new LinearLayout(G.context);
        m_container.setId(R.id.m_container);
        m_container.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_346 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        m_container.setLayoutParams(layout_346);

        LinearLayout linearLayout_784 = new LinearLayout(G.context);
        linearLayout_784.setGravity(Gravity.CENTER_VERTICAL);
        setLayoutDirection(linearLayout_784, View.LAYOUT_DIRECTION_LTR);
        linearLayout_784.setOrientation(HORIZONTAL);
        linearLayout_784.setPadding(0, 0, (int) G.context.getResources().getDimension(R.dimen.messageContainerPadding), 0);
        LinearLayout.LayoutParams layout_419 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layout_419.gravity = CENTER;
        linearLayout_784.setLayoutParams(layout_419);

        FrameLayout frameLayout = new FrameLayout(G.context);
        FrameLayout.LayoutParams layoutParamsFrameLayout = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        layoutParamsFrameLayout.gravity = CENTER;
        frameLayout.setPadding(10, 10, 10, 10);
        frameLayout.setLayoutParams(layoutParamsFrameLayout);

        ImageView imgThumbnail = new ImageView(G.context);
        imgThumbnail.setId(R.id.thumbnail);
        LinearLayout.LayoutParams thumbnailParams = new LinearLayout.LayoutParams((int) G.context.getResources().getDimension(R.dimen.dp48), (int) G.context.getResources().getDimension(R.dimen.dp48));
        thumbnailParams.gravity = CENTER;
        imgThumbnail.setBackgroundColor(Color.TRANSPARENT);
        imgThumbnail.setScaleType(ImageView.ScaleType.FIT_CENTER);
        AppUtils.setImageDrawable(imgThumbnail, R.drawable.file_icon);
        imgThumbnail.setLayoutParams(thumbnailParams);

        LinearLayout linearLayout_780 = new LinearLayout(G.context);
        linearLayout_780.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_752 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layout_752.gravity = CENTER;
        linearLayout_780.setLayoutParams(layout_752);

        TextView songArtist = new TextView(G.context);
        songArtist.setId(R.id.songArtist);
        songArtist.setEllipsize(TextUtils.TruncateAt.MIDDLE);
        songArtist.setSingleLine(true);

        songArtist.setMaxWidth((int) G.context.getResources().getDimension(R.dimen.dp180));
        songArtist.setText("file_name.ext");
        songArtist.setTextColor(Color.parseColor(G.textBubble));
        setTextSize(songArtist, R.dimen.dp14);
        songArtist.setTypeface(G.typeface_IRANSansMobile_Bold, BOLD);
        LinearLayout.LayoutParams layout_1000 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        songArtist.setLayoutParams(layout_1000);
        linearLayout_780.addView(songArtist);

        TextView fileSize = new TextView(G.context);
        fileSize.setId(R.id.fileSize);
        fileSize.setSingleLine(true);
        fileSize.setText("3.2 mb");
        fileSize.setAllCaps(TRUE);
        fileSize.setTextColor(Color.parseColor(G.textBubble));
        setTextSize(fileSize, R.dimen.dp10);
        setTypeFace(fileSize);
        LinearLayout.LayoutParams layout_958 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layout_958.topMargin = 3;
        fileSize.setLayoutParams(layout_958);
        linearLayout_780.addView(fileSize);
        linearLayout_784.addView(frameLayout);
        linearLayout_784.addView(linearLayout_780);
        m_container.addView(linearLayout_784);

        LinearLayout csliwt_layout_container_message = new LinearLayout(G.context);
        csliwt_layout_container_message.setId(R.id.csliwt_layout_container_message);
        csliwt_layout_container_message.setOrientation(HORIZONTAL);
        LinearLayout.LayoutParams layout_312 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        csliwt_layout_container_message.setLayoutParams(layout_312);
        m_container.addView(csliwt_layout_container_message);
        contentContainer.addView(m_container);
        linearLayout_768.addView(contentContainer);

        frameLayout.addView(imgThumbnail);
        frameLayout.addView(getProgressBar(R.dimen.dp52));
        mainContainer.addView(linearLayout_768);

        return mainContainer;
    }
 
/**
 * SHOW CHARACTERISTIC PROPERTIES IN UI: READ, WRITE
 ************************************/
private void addPropertiesToCharacteristic(BluetoothGattCharacteristic bluetoothGattCharacteristic,
                                           LinearLayout propsContainer) {
    String propertiesString = Common.getProperties(DeviceServicesActivity.this, bluetoothGattCharacteristic.getProperties());
    String[] propsExploded = propertiesString.split(",");


    if (Arrays.toString(propsExploded).toLowerCase().contains("write no response")) {
        ArrayList<String> temp = new ArrayList<>();
        boolean writeAdded = false;

        for (String s : propsExploded) {
            if (s.toLowerCase().contains("write no response") && !writeAdded) {
                temp.add("Write");
                writeAdded = true;
            } else if (!s.toLowerCase().contains("write")) {
                temp.add(s);
            }
        }

        propsExploded = new String[temp.size()];

        for (int i = 0; i < temp.size(); i++) {
            propsExploded[i] = temp.get(i);
        }
    }

    for (String propertyValue : propsExploded) {
        TextView propertyView = new TextView(this);

        String propertyValueTrimmed = propertyValue.trim();
        propertyValueTrimmed = propertyValue.length() > 13 ? propertyValue.substring(0, 13) : propertyValueTrimmed;
        propertyView.setText(propertyValueTrimmed);
        propertyView.setBackgroundColor(ContextCompat.getColor(DeviceServicesActivity.this, R.color.silabs_white));
        propertyView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.characteristic_property_text_size));
        propertyView.setTextColor(ContextCompat.getColor(DeviceServicesActivity.this, R.color.silabs_inactive));
        propertyView.setTypeface(Typeface.DEFAULT_BOLD);
        propertyView.setGravity(Gravity.CENTER_VERTICAL);

        LinearLayout propertyContainer = new LinearLayout(DeviceServicesActivity.this);
        propertyContainer.setOrientation(LinearLayout.HORIZONTAL);

        ImageView propertyIcon = new ImageView(DeviceServicesActivity.this);
        int iconId;
        if (propertyValue.trim().toUpperCase().equals(Common.PROPERTY_VALUE_BROADCAST)) {
            iconId = R.drawable.debug_prop_broadcast;
        } else if (propertyValue.trim().toUpperCase().equals(Common.PROPERTY_VALUE_READ)) {
            iconId = R.drawable.ic_icon_read_off;
        } else if (propertyValue.trim().toUpperCase().equals(Common.PROPERTY_VALUE_WRITE)) {
            iconId = R.drawable.ic_icon_edit_off;
        } else if (propertyValue.trim().toUpperCase().equals(Common.PROPERTY_VALUE_NOTIFY)) {
            iconId = R.drawable.ic_icon_notify_off;
        } else if (propertyValue.trim().toUpperCase().equals(Common.PROPERTY_VALUE_INDICATE)) {
            iconId = R.drawable.ic_icon_indicate_off;
        } else if (propertyValue.trim().toUpperCase().equals(Common.PROPERTY_VALUE_SIGNED_WRITE)) {
            iconId = R.drawable.debug_prop_signed_write;
        } else if (propertyValue.trim().toUpperCase().equals(Common.PROPERTY_VALUE_EXTENDED_PROPS)) {
            iconId = R.drawable.debug_prop_ext;
        } else {
            iconId = R.drawable.debug_prop_ext;
        }
        propertyIcon.setBackgroundResource(iconId);
        propertyIcon.setTag(PROPERTY_ICON_TAG);
        propertyView.setTag(PROPERTY_NAME_TAG);

        LinearLayout.LayoutParams paramsText = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        paramsText.gravity = Gravity.CENTER_VERTICAL;

        //int propIconEdgeLength = getResources().getDimensionPixelSize(R.dimen.prop_icon_edge_length);
        LinearLayout.LayoutParams paramsIcon = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        float d = getResources().getDisplayMetrics().density;
        paramsIcon.setMarginEnd((int) (8 * d));
        paramsIcon.gravity = Gravity.CENTER_VERTICAL;

        propertyContainer.addView(propertyIcon, paramsIcon);
        propertyContainer.addView(propertyView, paramsText);

        propertyContainer.setTag(propertyValue);

        LinearLayout.LayoutParams paramsTextAndIconContainer = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
        paramsTextAndIconContainer.setMargins(0, (int) (4 * d), (int) (10 * d), 0);
        propertyContainer.setPadding((int) (2 * d), (int) (8 * d), (int) (6 * d), (int) (6 * d));
        propsContainer.addView(propertyContainer, paramsTextAndIconContainer);
    }
}
 
源代码20 项目: iGap-Android   文件: CardsFragment.java
private void addMyCardsTitle() {
    Context context = getContext();
    int dp8 = RaadCommonUtils.getPx(8, context);
    int dp16 = RaadCommonUtils.getPx(16, context);
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams titleLayoutParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    layout.setLayoutParams(titleLayoutParams);
    layout.setGravity(Gravity.CENTER_VERTICAL);
    layout.setPadding(dp16, dp8, dp16, dp16);
    cardsLayout.addView(layout);

    TextView title2 = new TextView(context);
    LinearLayout.LayoutParams title2Params = new LinearLayout.LayoutParams(
            0, LinearLayout.LayoutParams.WRAP_CONTENT);
    title2Params.weight = 1.0f;
    title2.setLayoutParams(title2Params);
    title2.setTextColor(Color.parseColor(WalletActivity.textTitleTheme));
    title2.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
    title2.setTypeface(Typefaces.get(context, Typefaces.IRAN_YEKAN_BOLD));
    title2.setText(R.string.my_cards);
    layout.addView(title2);


    FrameLayout addCardLayout = new FrameLayout(context);
    int dp40 = RaadCommonUtils.getPx(40, context);
    addCardLayout.setLayoutParams(new LinearLayout.LayoutParams(dp40, dp40));
    addCardLayout.setPadding(dp8, dp8, dp8, dp8);
    layout.addView(addCardLayout);

    ImageView addCard = new ImageView(context);
    addCard.setLayoutParams(new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    ViewCompat.setBackground(addCard, RaadCommonUtils.getRectShape(context, R.color.add_card_plus_back, 12, 0));
    addCard.getBackground().setColorFilter(new PorterDuffColorFilter(Color.parseColor(WalletActivity.primaryColor), PorterDuff.Mode.SRC_IN));

    addCard.setImageResource(R.drawable.ic_action_add_white);
    int dp4 = RaadCommonUtils.getPx(4, context);
    //addCard.setPadding(dp4, dp4, dp4, dp4);
    addCardLayout.addView(addCard);
    addCardLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ((NavigationBarActivity) getActivity()).pushFullFragment(
                    new AddCardFragment(), "AddCardFragment");
        }
    });
}