下面列出了android.widget.Button#setPadding ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void setSecondaryMicroBlogHeader(View headerView) {
if (headerView == null) {
return;
}
Theme theme = ThemeUtil.createTheme(headerView.getContext());
LinearLayout llHeaderBase = (LinearLayout)headerView.findViewById(R.id.llHeaderBase);
Button btnBack = (Button)headerView.findViewById(R.id.btnBack);
Button btnPrevious = (Button)headerView.findViewById(R.id.btnPrevious);
Button btnNext = (Button)headerView.findViewById(R.id.btnNext);
Button btnOperate = (Button) headerView.findViewById(R.id.btnOperate);
TextView tvTitle = (TextView) headerView.findViewById(R.id.tvTitle);
llHeaderBase.setBackgroundDrawable(theme.getDrawable("bg_header"));
llHeaderBase.setGravity(Gravity.CENTER);
int padding8 = theme.dip2px(8);
llHeaderBase.setPadding(padding8, 0, padding8, 0);
btnBack.setBackgroundDrawable(theme.getDrawable("selector_btn_action_back"));
btnBack.setTextColor(theme.getColorStateList("selector_btn_header_action"));
tvTitle.setTextColor(theme.getColorStateList("selector_header_title"));
btnPrevious.setBackgroundDrawable(theme.getDrawable("selector_btn_action_previous"));
btnNext.setBackgroundDrawable(theme.getDrawable("selector_btn_action_next"));
btnOperate.setBackgroundDrawable(theme.getDrawable("selector_btn_action_additional"));
int padding12 = theme.dip2px(12);
btnOperate.setPadding(padding12, 0, padding12, 0);
btnOperate.setTextColor(theme.getColor("selector_btn_header_action"));
}
public static void setSecondaryImageHeader(View headerView) {
if (headerView == null) {
return;
}
Theme theme = ThemeUtil.createTheme(headerView.getContext());
LinearLayout llHeaderBase = (LinearLayout)headerView.findViewById(R.id.llHeaderBase);
Button btnBack = (Button)headerView.findViewById(R.id.btnBack);
Button btnOperate = (Button) headerView.findViewById(R.id.btnOperate);
TextView tvTitle = (TextView) headerView.findViewById(R.id.tvTitle);
llHeaderBase.setBackgroundDrawable(theme.getDrawable("bg_header_image"));
llHeaderBase.setGravity(Gravity.CENTER);
int padding8 = theme.dip2px(8);
llHeaderBase.setPadding(padding8, 0, padding8, 0);
btnBack.setBackgroundDrawable(theme.getDrawable("selector_btn_action_back"));
btnBack.setTextColor(theme.getColorStateList("selector_btn_header_action"));
tvTitle.setTextColor(theme.getColorStateList("selector_header_title"));
btnOperate.setBackgroundDrawable(theme.getDrawable("selector_btn_action_additional"));
int padding12 = theme.dip2px(12);
btnOperate.setPadding(padding12, 0, padding12, 0);
btnOperate.setTextColor(theme.getColor("selector_btn_header_action"));
}
private void populateButtons() {
TableLayout table = (TableLayout) findViewById(R.id.tableForButtons);
for (int row = 0; row < NUM_ROWS; row++) {
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.MATCH_PARENT,
1.0f));
table.addView(tableRow);
for (int col = 0; col < NUM_COLS; col++){
final int FINAL_COL = col;
final int FINAL_ROW = row;
Button button = new Button(this);
button.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT,
1.0f));
button.setText("" + col + "," + row);
// Make text not clip on small buttons
button.setPadding(0, 0, 0, 0);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gridButtonClicked(FINAL_COL, FINAL_ROW);
}
});
tableRow.addView(button);
buttons[row][col] = button;
}
}
}
private void setButtonStyle(Button button) {
if (Build.VERSION.SDK_INT >= 21) {
button.setPadding(dpToPx(14),0, dpToPx(14),0);
} else {
button.setPadding(dpToPx(12),0, dpToPx(12),0);
}
button.setTypeface(Typeface.createFromAsset(activity.getAssets(), "medium.ttf"));
}
private void initButton(Button button, String text) {
button.setText(text);
button.setTextSize(22);
button.setPadding(0, 0, 0, 0);
button.setWidth((int)(30 * density));
button.setHeight((int)(30 * density));
button.setSingleLine();
button.setGravity(Gravity.CENTER);
}
public void withItems(View view) {
final String[] items = {"Apple", "Banana", "Orange", "Grapes"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("List of Items")
.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), items[which] + " is clicked", Toast.LENGTH_SHORT).show();
}
});
builder.setPositiveButton("OK", null);
builder.setNegativeButton("CANCEL", null);
builder.setNeutralButton("NEUTRAL", null);
builder.setPositiveButtonIcon(getResources().getDrawable(android.R.drawable.ic_menu_call, getTheme()));
builder.setIcon(getResources().getDrawable(R.drawable.jd, getTheme()));
AlertDialog alertDialog = builder.create();
alertDialog.show();
Button button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
button.setBackgroundColor(Color.BLACK);
button.setPadding(0, 0, 20, 0);
button.setTextColor(Color.WHITE);
}
/**
* set positive button
*
* @param text the name of button
*/
public void setPositiveButton(String text, final View.OnClickListener listener) {
Button button = new Button(mContext);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
button.setLayoutParams(params);
button.setBackgroundResource(R.drawable.material_card);
button.setTextColor(Color.argb(255, 35, 159, 242));
button.setText(text);
button.setGravity(Gravity.CENTER);
button.setTextSize(14);
button.setPadding(dip2px(12), 0, dip2px(32), dip2px(BUTTON_BOTTOM));
button.setOnClickListener(listener);
mButtonLayout.addView(button);
}
private Button getButton(Context context, String text, View.OnClickListener listener) {
int padding = (int) (8 * mDensity + .5f);
Button button = new Button(context);
button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15.f);
button.setTextColor(0xFF333333);
button.setText(text);
button.setBackgroundResource(R.drawable.item_highlight_bkg);
button.setPadding(0, padding, 0, padding);
button.setOnClickListener(listener);
return button;
}
private void initComponents() {
LinearLayout llRoot = (LinearLayout)this.findViewById(R.id.llRoot);
LinearLayout llHeaderBase = (LinearLayout)findViewById(R.id.llHeaderBase);
LinearLayout llHeaderSearch = (LinearLayout)findViewById(R.id.llHeaderSearch);
EditText etKeyWord = (EditText) findViewById(R.id.etKeyWord);
Button btnSearch = (Button) findViewById(R.id.btnSearch);
btnSearchStatus = (Button) findViewById(R.id.btnSearchStatus);
btnSearchUser = (Button) findViewById(R.id.btnSearchUser);
lvSearchResult = (ListView) findViewById(R.id.lvSearchResult);
lvSearchResult.setFastScrollEnabled(sheJiaoMao.isSliderEnabled());
lvSearchResult.setOnScrollListener(new StatusScrollListener());
ThemeUtil.setRootBackground(llRoot);
ThemeUtil.setSecondaryHeader(llHeaderBase);
llHeaderSearch.setBackgroundDrawable(theme.getDrawable("bg_header_corner_search"));
int padding6 = theme.dip2px(6);
int padding8 = theme.dip2px(8);
llHeaderSearch.setPadding(padding6, padding8, padding6, padding8);
ThemeUtil.setListViewStyle(lvSearchResult);
etKeyWord.setBackgroundDrawable(theme.getDrawable("bg_input_frame_left_half"));
btnSearch.setBackgroundDrawable(theme.getDrawable("selector_btn_search"));
btnSearchStatus.setBackgroundDrawable(theme.getDrawable("selector_tab_toggle_left"));
btnSearchStatus.setPadding(0, 0, 0, 0);
ColorStateList selectorBtnTab = theme.getColorStateList("selector_btn_tab");
btnSearchStatus.setTextColor(selectorBtnTab);
btnSearchStatus.setGravity(Gravity.CENTER);
btnSearchUser.setBackgroundDrawable(theme.getDrawable("selector_tab_toggle_right"));
btnSearchUser.setPadding(0, 0, 0, 0);
btnSearchUser.setTextColor(selectorBtnTab);
btnSearchUser.setGravity(Gravity.CENTER);
}
private void initPageView() {
flPage = new FrameLayout(getContext());
flPage.setOnClickListener(this);
// 宫格列表的容器,为了“下对齐”,在外部包含了一个FrameLayout
LinearLayout llPage = new LinearLayout(getContext()) {
public boolean onTouchEvent(MotionEvent event) {
return true;
}
};
llPage.setOrientation(LinearLayout.VERTICAL);
int resId = getBitmapRes(getContext(), "share_vp_back");
if (resId > 0) {
llPage.setBackgroundResource(resId);
}
FrameLayout.LayoutParams lpLl = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lpLl.gravity = Gravity.BOTTOM;
llPage.setLayoutParams(lpLl);
flPage.addView(llPage);
// 宫格列表
grid = new PlatformGridView(getContext());
grid.setEditPageBackground(bgView);
LinearLayout.LayoutParams lpWg = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
grid.setLayoutParams(lpWg);
llPage.addView(grid);
// 取消按钮
btnCancel = new Button(getContext());
btnCancel.setTextColor(0xffffffff);
btnCancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
resId = getStringRes(getContext(), "cancel");
if (resId > 0) {
btnCancel.setText(resId);
}
btnCancel.setPadding(0, 0, 0, cn.sharesdk.framework.utils.R.dipToPx(getContext(), 5));
resId = getBitmapRes(getContext(), "btn_cancel_back");
if (resId > 0) {
btnCancel.setBackgroundResource(resId);
}
LinearLayout.LayoutParams lpBtn = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, cn.sharesdk.framework.utils.R.dipToPx(getContext(), 45));
int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 10);
lpBtn.setMargins(dp_10, dp_10, dp_10, dp_10);
btnCancel.setLayoutParams(lpBtn);
llPage.addView(btnCancel);
}
private void init(Context context, int style) {
mContentPadding = ThemeUtil.dpToPx(context, 24);
mActionMinWidth = ThemeUtil.dpToPx(context, 64);
mActionHeight = ThemeUtil.dpToPx(context, 36);
mActionOuterHeight = ThemeUtil.dpToPx(context, 48);
mActionPadding_h = ThemeUtil.dpToPx(context, 8);
mActionPadding_w = ThemeUtil.dpToPx(context, 8);
mActionOuterPadding = ThemeUtil.dpToPx(context, 8);
mDialogHorizontalPadding = ThemeUtil.dpToPx(context, 40);
mDialogVerticalPadding = ThemeUtil.dpToPx(context, 24);
mCardView = new DialogCardView(context);
mContainer = new ContainerFrameLayout(context);
mTitle = new TextView(context);
mPositiveAction = new Button(context);
mNegativeAction = new Button(context);
mNeutralAction = new Button(context);
mCardView.setPreventCornerOverlap(false);
mCardView.setUseCompatPadding(true);
mTitle.setId(TITLE);
mTitle.setGravity(Gravity.START);
// mTitle.setPadding(mContentPadding, mContentPadding, mContentPadding, mContentPadding - mActionPadding);
mTitle.setPadding(mContentPadding, mContentPadding, 0, mContentPadding / 2);
mPositiveAction.setId(ACTION_POSITIVE);
mPositiveAction.setPadding(mActionPadding_w, mActionPadding_h, mActionPadding_w, mActionPadding_h);
//设置背景
mPositiveAction.setBackgroundResource(R.drawable.button_white_stroke_green);
mNegativeAction.setId(ACTION_NEGATIVE);
mNegativeAction.setPadding(mActionPadding_w, mActionPadding_h, mActionPadding_w, mActionPadding_h);
mNegativeAction.setBackgroundResource(0);
mNeutralAction.setId(ACTION_NEUTRAL);
mNeutralAction.setPadding(mActionPadding_w, mActionPadding_h, mActionPadding_w, mActionPadding_h);
mNeutralAction.setBackgroundResource(0);
mContainer.addView(mCardView);
mCardView.addView(mTitle);
mCardView.addView(mPositiveAction);
mCardView.addView(mNegativeAction);
mCardView.addView(mNeutralAction);
backgroundColor(ThemeUtil.windowBackground(context, 0xFFFFFFFF));
elevation(ThemeUtil.dpToPx(context, 4));
cornerRadius(ThemeUtil.dpToPx(context, 2));
dimAmount(0.5f);
layoutDirection(View.LAYOUT_DIRECTION_LOCALE);
titleTextAppearance(R.style.TextAppearance_AppCompat_Title);
actionTextAppearance(R.style.TextAppearance_AppCompat_Button);
dividerColor(0x1E000000);
dividerHeight(ThemeUtil.dpToPx(context, 1));
cancelable(true);
canceledOnTouchOutside(true);
clearContent();
onCreate();
applyStyle(style);
super.setContentView(mContainer);
}
private void initComponents() {
LinearLayout llHeaderBase = (LinearLayout)findViewById(R.id.llHeaderBase);
LinearLayout llContentPanel = (LinearLayout)findViewById(R.id.llContentPanel);
LinearLayout llEditText = (LinearLayout)findViewById(R.id.llEditText);
MultiAutoCompleteTextView etText = (MultiAutoCompleteTextView)findViewById(R.id.etText);
Button btnEmotion = (Button)this.findViewById(R.id.btnEmotion);
Button btnMention = (Button)this.findViewById(R.id.btnMention);
Button btnTopic = (Button)this.findViewById(R.id.btnTopic);
Button btnTextCount = (Button)this.findViewById(R.id.btnTextCount);
cbComment = (CheckBox) this.findViewById(R.id.cbComment);
cbCommentToOrigin = (CheckBox)this.findViewById(R.id.cbCommentToOrigin);
tvText = (TextView)this.findViewById(R.id.tvText);
ThemeUtil.setSecondaryHeader(llHeaderBase);
ThemeUtil.setContentBackground(llContentPanel);
int padding6 = theme.dip2px(6);
int padding8 = theme.dip2px(8);
llContentPanel.setPadding(padding6, padding8, padding6, 0);
llEditText.setBackgroundDrawable(theme.getDrawable("bg_input_frame_normal"));
etText.setTextColor(theme.getColor("content"));
btnEmotion.setBackgroundDrawable(theme.getDrawable("selector_btn_emotion"));
btnMention.setBackgroundDrawable(theme.getDrawable("selector_btn_mention"));
btnTopic.setBackgroundDrawable(theme.getDrawable("selector_btn_topic"));
btnTextCount.setBackgroundDrawable(theme.getDrawable("selector_btn_text_count"));
btnTextCount.setPadding(padding6, 0, theme.dip2px(20), 0);
btnTextCount.setTextColor(theme.getColor("status_capability"));
cbComment.setButtonDrawable(theme.getDrawable("selector_checkbox"));
cbComment.setTextColor(theme.getColor("content"));
cbCommentToOrigin.setButtonDrawable(theme.getDrawable("selector_checkbox"));
cbCommentToOrigin.setTextColor(theme.getColor("content"));
tvText.setTextColor(theme.getColor("quote"));
TextView tvTitle = (TextView)this.findViewById(R.id.tvTitle);
tvTitle.setText(R.string.title_retweet);
MicroBlogTextWatcher textWatcher = new MicroBlogTextWatcher(this);
etText.addTextChangedListener(textWatcher);
etText.setHint(R.string.hint_retweet);
etText.requestFocus();
etText.setAdapter(new UserSuggestAdapter(this));
etText.setTokenizer(new EditMicroBlogTokenizer());
retweetedStatus = status;
if (status.getServiceProvider() != ServiceProvider.Sohu) {
if (status.getServiceProvider() == ServiceProvider.Fanfou
|| status.getRetweetedStatus() != null) {
etText.setText(
String.format(
FeaturePatternUtils.getRetweetFormat(status.getServiceProvider()),
FeaturePatternUtils.getRetweetSeparator(status.getServiceProvider()),
status.getUser().getMentionName(),
status.getText()
)
);
}
if (!(status.getServiceProvider() == ServiceProvider.Fanfou
|| status.getRetweetedStatus() == null)) {
retweetedStatus = status.getRetweetedStatus();
}
etText.setSelection(0);
}
int length = StringUtil.getLengthByByte(etText.getText().toString());
int leavings = (int) Math.floor((double) (Constants.STATUS_TEXT_MAX_LENGTH * 2 - length) / 2);
btnTextCount.setText((leavings < 0 ? "-" : "") + Math.abs(leavings));
String lableComment = this.getString(R.string.label_retweet_with_comment,
status.getUser().getScreenName());
cbComment.setText(lableComment);
if (isComment2OriginVisible()) {
String lableCommentToOrigin = this.getString(
R.string.label_retweet_with_comment_to_origin,
retweetedStatus.getUser().getScreenName());
cbCommentToOrigin.setText(lableCommentToOrigin);
cbCommentToOrigin.setVisibility(View.VISIBLE);
}
String promptText = retweetedStatus.getUser().getMentionTitleName()
+ ":" + retweetedStatus.getText();
tvText.setText(promptText);
}
/**
* @param context the context to use.
* @param attrs attributes.
* @param parentView parent
* @param label label
* @param value value
* @param type the text type.
* @param constraintDescription constraints
* @param readonly if <code>false</code>, the item is disabled for editing.
*/
public GDynamicEditTextView(final Context context, AttributeSet attrs, LinearLayout parentView, String label, String value, final int type,
String constraintDescription, final boolean readonly) {
super(context, attrs);
editViewList = new ArrayList<>();
mainLayout = new LinearLayout(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(10, 10, 10, 10);
mainLayout.setLayoutParams(layoutParams);
mainLayout.setOrientation(LinearLayout.VERTICAL);
parentView.addView(mainLayout);
TextView textView = new TextView(context);
textView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
textView.setPadding(2, 2, 2, 2);
textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
textView.setTextColor(Compat.getColor(context, R.color.formcolor));
mainLayout.addView(textView);
String[] valuesSplit = value.trim().split(";");
if (valuesSplit.length == 0) {
valuesSplit = new String[]{" "};
}
for (String singleValue : valuesSplit) {
addSingleEditText(context, mainLayout, singleValue.trim(), readonly, type);
}
float minTouch = context.getResources().getDimension(R.dimen.min_touch_size);
addTextButton = new Button(context);
addTextButton.setLayoutParams(new LinearLayout.LayoutParams((int) minTouch, (int) minTouch));
addTextButton.setPadding(5, 5, 5, 5);
// addTextButton.setText("+");
addTextButton.setBackground(Compat.getDrawable(context, R.drawable.ic_add_primary_24dp));
mainLayout.addView(addTextButton);
addTextButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mainLayout.removeView(addTextButton);
addSingleEditText(context, mainLayout, "", readonly, type);
// add the button back
mainLayout.addView(addTextButton);
}
});
}
private void initPageView() {
flPage = new FrameLayout(getContext());
flPage.setOnClickListener(this);
// 宫格列表的容器,为了“下对齐”,在外部包含了一个FrameLayout
LinearLayout llPage = new LinearLayout(getContext()) {
public boolean onTouchEvent(MotionEvent event) {
return true;
}
};
llPage.setOrientation(LinearLayout.VERTICAL);
int resId = getBitmapRes(getContext(), "share_vp_back");
if (resId > 0) {
llPage.setBackgroundResource(resId);
}
FrameLayout.LayoutParams lpLl = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lpLl.gravity = Gravity.BOTTOM;
llPage.setLayoutParams(lpLl);
flPage.addView(llPage);
// 宫格列表
grid = new PlatformGridView(getContext());
grid.setEditPageBackground(bgView);
LinearLayout.LayoutParams lpWg = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
grid.setLayoutParams(lpWg);
llPage.addView(grid);
// 取消按钮
btnCancel = new Button(getContext());
btnCancel.setTextColor(0xffffffff);
btnCancel.setBackgroundResource(R.drawable.btn_1_selector);
btnCancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
resId = getStringRes(getContext(), "cancel");
if (resId > 0) {
btnCancel.setText(resId);
}
btnCancel.setPadding(0, 0, 0, cn.sharesdk.framework.utils.R.dipToPx(getContext(), 5));
resId = getBitmapRes(getContext(), "btn_cancel_back");
// if (resId > 0) {
// btnCancel.setBackgroundResource(resId);
// }
LinearLayout.LayoutParams lpBtn = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, cn.sharesdk.framework.utils.R.dipToPx(getContext(), 45));
int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 10);
lpBtn.setMargins(dp_10, dp_10, dp_10, dp_10);
btnCancel.setLayoutParams(lpBtn);
llPage.addView(btnCancel);
}
private void initPageView() {
flPage = new FrameLayout(getContext());
flPage.setOnClickListener(this);
// container of the platform gridview
LinearLayout llPage = new LinearLayout(getContext()) {
public boolean onTouchEvent(MotionEvent event) {
return true;
}
};
llPage.setOrientation(LinearLayout.VERTICAL);
int resId = getBitmapRes(getContext(), "share_vp_back");
if (resId > 0) {
llPage.setBackgroundResource(resId);
}
FrameLayout.LayoutParams lpLl = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lpLl.gravity = Gravity.BOTTOM;
llPage.setLayoutParams(lpLl);
flPage.addView(llPage);
// gridview
grid = new PlatformGridView(getContext());
LinearLayout.LayoutParams lpWg = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
grid.setLayoutParams(lpWg);
llPage.addView(grid);
// cancel button
btnCancel = new Button(getContext());
btnCancel.setTextColor(0xffffffff);
btnCancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
resId = getStringRes(getContext(), "cancel");
if (resId > 0) {
btnCancel.setText(resId);
}
btnCancel.setPadding(0, 0, 0, cn.sharesdk.framework.utils.R.dipToPx(getContext(), 5));
resId = getBitmapRes(getContext(), "btn_cancel_back");
if (resId > 0) {
btnCancel.setBackgroundResource(resId);
}
LinearLayout.LayoutParams lpBtn = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, cn.sharesdk.framework.utils.R.dipToPx(getContext(), 45));
int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 10);
lpBtn.setMargins(dp_10, dp_10, dp_10, dp_10);
btnCancel.setLayoutParams(lpBtn);
llPage.addView(btnCancel);
}
private void initPageView() {
flPage = new FrameLayout(getContext());
flPage.setOnClickListener(this);
flPage.setBackgroundDrawable(new ColorDrawable(0x55000000));
// container of the platform gridview
llPage = new LinearLayout(getContext()) {
public boolean onTouchEvent(MotionEvent event) {
return true;
}
};
llPage.setOrientation(LinearLayout.VERTICAL);
llPage.setBackgroundDrawable(new ColorDrawable(0xffffffff));
FrameLayout.LayoutParams lpLl = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
lpLl.gravity = Gravity.BOTTOM;
llPage.setLayoutParams(lpLl);
flPage.addView(llPage);
// gridview
grid = new PlatformGridView(getContext());
grid.setEditPageBackground(getBackgroundView());
LinearLayout.LayoutParams lpWg = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
grid.setLayoutParams(lpWg);
llPage.addView(grid);
// cancel button
btnCancel = new Button(getContext());
btnCancel.setTextColor(0xff3a65ff);
btnCancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
int resId = getStringRes(getContext(), "cancel");
if (resId > 0) {
btnCancel.setText(resId);
}
btnCancel.setPadding(0, 0, 0, com.mob.tools.utils.R.dipToPx(getContext(), 5));
resId = getBitmapRes(getContext(), "classic_platform_corners_bg");
if(resId > 0){
btnCancel.setBackgroundResource(resId);
}else {
btnCancel.setBackgroundDrawable(new ColorDrawable(0xffffffff));
}
LinearLayout.LayoutParams lpBtn = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, com.mob.tools.utils.R.dipToPx(getContext(), 45));
int dp_10 = com.mob.tools.utils.R.dipToPx(getContext(), 10);
lpBtn.setMargins(dp_10, dp_10, dp_10, dp_10);
btnCancel.setLayoutParams(lpBtn);
llPage.addView(btnCancel);
}
private void initPageView() {
flPage = new FrameLayout(getContext());
flPage.setOnClickListener(this);
// 宫格列表的容器,为了“下对齐”,在外部包含了一个FrameLayout
LinearLayout llPage = new LinearLayout(getContext()) {
public boolean onTouchEvent(MotionEvent event) {
return true;
}
};
llPage.setOrientation(LinearLayout.VERTICAL);
int resId = getBitmapRes(getContext(), "share_vp_back");
if (resId > 0) {
llPage.setBackgroundResource(resId);
}
FrameLayout.LayoutParams lpLl = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lpLl.gravity = Gravity.BOTTOM;
llPage.setLayoutParams(lpLl);
flPage.addView(llPage);
// 宫格列表
grid = new PlatformGridView(getContext());
grid.setEditPageBackground(bgView);
LinearLayout.LayoutParams lpWg = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
grid.setLayoutParams(lpWg);
llPage.addView(grid);
// 取消按钮
btnCancel = new Button(getContext());
btnCancel.setTextColor(0xffffffff);
btnCancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
resId = getStringRes(getContext(), "cancel");
if (resId > 0) {
btnCancel.setText(resId);
}
btnCancel.setPadding(0, 0, 0, cn.sharesdk.framework.utils.R.dipToPx(getContext(), 5));
resId = getBitmapRes(getContext(), "btn_cancel_back");
if (resId > 0) {
btnCancel.setBackgroundResource(resId);
}
LinearLayout.LayoutParams lpBtn = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, cn.sharesdk.framework.utils.R.dipToPx(getContext(), 45));
int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 10);
lpBtn.setMargins(dp_10, dp_10, dp_10, dp_10);
btnCancel.setLayoutParams(lpBtn);
llPage.addView(btnCancel);
}
private void initPageView() {
flPage = new FrameLayout(getContext());
flPage.setOnClickListener(this);
flPage.setBackgroundDrawable(new ColorDrawable(0x55000000));
// container of the platform gridview
llPage = new LinearLayout(getContext()) {
public boolean onTouchEvent(MotionEvent event) {
return true;
}
};
llPage.setOrientation(LinearLayout.VERTICAL);
llPage.setBackgroundDrawable(new ColorDrawable(0xffffffff));
FrameLayout.LayoutParams lpLl = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
lpLl.gravity = Gravity.BOTTOM;
llPage.setLayoutParams(lpLl);
flPage.addView(llPage);
// gridview
grid = new PlatformGridView(getContext());
grid.setEditPageBackground(getBackgroundView());
LinearLayout.LayoutParams lpWg = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
grid.setLayoutParams(lpWg);
llPage.addView(grid);
View line_view = new View(getContext());
line_view.setBackgroundDrawable(new ColorDrawable(0xffd5d5d5));
int lineHeight = (int)((float)0.5 * getContext().getResources().getDisplayMetrics().density + 0.5F);
LinearLayout.LayoutParams lpLine = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, lineHeight);
int dp_10 = com.mob.tools.utils.R.dipToPx(getContext(), 10);
lpLine.setMargins(0, dp_10, 0, 0);
line_view.setLayoutParams(lpLine);
llPage.addView(line_view);
// cancel button
btnCancel = new Button(getContext());
ColorStateList csl=(ColorStateList)activity.getResources().getColorStateList(R.color.z_txt_input);
btnCancel.setTextColor(csl);
btnCancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
int resId = getStringRes(getContext(), "cancel");
if (resId > 0) {
btnCancel.setText(resId);
}
btnCancel.setPadding(0, 0, 0, 0);
resId = getBitmapRes(getContext(), "classic_platform_corners_bg");
if(resId > 0){
btnCancel.setBackgroundResource(resId);
}else {
btnCancel.setBackgroundDrawable(new ColorDrawable(0xffffffff));
}
btnCancel.setBackgroundColor(0x00ffffff);
LinearLayout.LayoutParams lpBtn = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, com.mob.tools.utils.R.dipToPx(getContext(), 45));
// int dp_10 = com.mob.tools.utils.R.dipToPx(getContext(), 10);
lpBtn.setMargins(0, 0, 0, 0);
btnCancel.setLayoutParams(lpBtn);
llPage.addView(btnCancel);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.QuantityView, defStyle, 0);
addButtonText = getResources().getString(R.string.qv_add);
if (a.hasValue(R.styleable.QuantityView_qv_addButtonText)) {
addButtonText = a.getString(R.styleable.QuantityView_qv_addButtonText);
}
addButtonBackground = ContextCompat.getDrawable(getContext(), R.drawable.qv_btn_selector);
if (a.hasValue(R.styleable.QuantityView_qv_addButtonBackground)) {
addButtonBackground = a.getDrawable(R.styleable.QuantityView_qv_addButtonBackground);
}
addButtonTextColor = a.getColor(R.styleable.QuantityView_qv_addButtonTextColor, Color.BLACK);
removeButtonText = getResources().getString(R.string.qv_remove);
if (a.hasValue(R.styleable.QuantityView_qv_removeButtonText)) {
removeButtonText = a.getString(R.styleable.QuantityView_qv_removeButtonText);
}
removeButtonBackground = ContextCompat.getDrawable(getContext(), R.drawable.qv_btn_selector);
if (a.hasValue(R.styleable.QuantityView_qv_removeButtonBackground)) {
removeButtonBackground = a.getDrawable(R.styleable.QuantityView_qv_removeButtonBackground);
}
removeButtonTextColor = a.getColor(R.styleable.QuantityView_qv_removeButtonTextColor, Color.BLACK);
quantity = a.getInt(R.styleable.QuantityView_qv_quantity, 0);
maxQuantity = a.getInt(R.styleable.QuantityView_qv_maxQuantity, Integer.MAX_VALUE);
minQuantity = a.getInt(R.styleable.QuantityView_qv_minQuantity, 0);
quantityPadding = (int) a.getDimension(R.styleable.QuantityView_qv_quantityPadding, pxFromDp(24));
quantityTextColor = a.getColor(R.styleable.QuantityView_qv_quantityTextColor, Color.BLACK);
quantityBackground = ContextCompat.getDrawable(getContext(), R.drawable.qv_bg_selector);
if (a.hasValue(R.styleable.QuantityView_qv_quantityBackground)) {
quantityBackground = a.getDrawable(R.styleable.QuantityView_qv_quantityBackground);
}
quantityDialog = a.getBoolean(R.styleable.QuantityView_qv_quantityDialog, true);
a.recycle();
int dp10 = pxFromDp(10);
mButtonAdd = new Button(getContext());
mButtonAdd.setGravity(Gravity.CENTER);
mButtonAdd.setPadding(dp10, dp10, dp10, dp10);
mButtonAdd.setMinimumHeight(0);
mButtonAdd.setMinimumWidth(0);
mButtonAdd.setMinHeight(0);
mButtonAdd.setMinWidth(0);
setAddButtonBackground(addButtonBackground);
setAddButtonText(addButtonText);
setAddButtonTextColor(addButtonTextColor);
mButtonRemove = new Button(getContext());
mButtonRemove.setGravity(Gravity.CENTER);
mButtonRemove.setPadding(dp10, dp10, dp10, dp10);
mButtonRemove.setMinimumHeight(0);
mButtonRemove.setMinimumWidth(0);
mButtonRemove.setMinHeight(0);
mButtonRemove.setMinWidth(0);
setRemoveButtonBackground(removeButtonBackground);
setRemoveButtonText(removeButtonText);
setRemoveButtonTextColor(removeButtonTextColor);
mTextViewQuantity = new TextView(getContext());
mTextViewQuantity.setGravity(Gravity.CENTER);
setQuantityTextColor(quantityTextColor);
setQuantity(quantity);
setQuantityBackground(quantityBackground);
setQuantityPadding(quantityPadding);
setOrientation(HORIZONTAL);
addView(mButtonRemove, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
addView(mTextViewQuantity, LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
addView(mButtonAdd, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mButtonAdd.setOnClickListener(this);
mButtonRemove.setOnClickListener(this);
mTextViewQuantity.setOnClickListener(this);
}
/**
* Set up the character inserts tray.
*/
public void reloadCharInserts() {
if (!keyboardVisible) {
return;
}
if (message == -1) {
message = findViewById(R.id.buffer).getHeight();
}
//Get a reference to the button container
LinearLayout container = ((LinearLayout) findViewById(R.id.char_insert_tray_list));
//Clear any buttons from before
container.removeAllViews();
//The (temporary) list of character inserts TODO make this list configurable
//"\u2192" is Unicode for the right arrow (like "->") - this is a graphical representation of the TAB key
String[] chars;
//This branch isn't very elegant... but it will work for now...
if(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("char_inserts_include_numbers", true))
chars = new String[] {"\u2192", ";", ".", ",", "{", "}", "(", ")", "=", "*", "/", "+", "-", "&", "|", "!", "[", "]", "<", ">", "\"", "'", "\\", "_", "?", ":", "%", "@", "#", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
else
chars = new String[] {"\u2192", ";", ".", ",", "{", "}", "(", ")", "=", "*", "/", "+", "-", "&", "|", "!", "[", "]", "<", ">", "\"", "'", "\\", "_", "?", ":", "%", "@", "#"};
//This works for now... as far as I can tell
final int keyboardID = 0;
//Add each button to the container
for(final String c : chars) {
Button button = (Button) LayoutInflater.from(this).inflate(R.layout.char_insert_button, null);
button.setText(c);
button.setTextColor(getResources().getColor(messageType != MessageType.MESSAGE ? R.color.char_insert_button_light : R.color.char_insert_button));
button.setLayoutParams(new LinearLayout.LayoutParams((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, getResources().getDisplayMetrics()), message));
button.setPadding(0, 0, 0, 0);
// Disable key press sounds if the user wants them disabled
button.setSoundEffectsEnabled(getGlobalState().getPref("char_inserts_key_press_sound", false));
//Maybe we'll want these at some point in time... but for now, they just cause more problems...
//...and the user won't be dragging the divider around if the keyboard is open (which it really should be)
// //Still let the user drag the message area
// button.setOnLongClickListener(messageListener);
// button.setOnTouchListener(messageListener);
container.addView(button);
button.setOnClickListener(view -> {
// A special check for the tab key... making special exceptions aren't exactly ideal, but this is probably the most concise solution (for now)...
KeyEvent event = c.equals("\u2192") ? new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TAB) : new KeyEvent(SystemClock.uptimeMillis(), c, keyboardID, 0);
boolean dispatched = false;
if (extraHeaderView != null) {
// If the find/replace toolbar is open
EditText findTextField = extraHeaderView.findViewById(R.id.find_replace_find_text);
EditText replaceTextField = extraHeaderView.findViewById(R.id.find_replace_replace_text);
if (findTextField != null) {
if (findTextField.hasFocus()) {
findTextField.dispatchKeyEvent(event);
dispatched = true;
} else {
if (replaceTextField != null && replaceTextField.hasFocus()) {
replaceTextField.dispatchKeyEvent(event);
dispatched = true;
}
}
}
}
if (!dispatched) {
getSelectedCodeArea().dispatchKeyEvent(event);
}
// Provide haptic feedback (if the user has vibrations enabled)
if(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("pref_vibrate", true))
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(10); //10 millis
});
}
}