下面列出了android.widget.LinearLayout#setBackgroundResource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initView() {
setOrientation(VERTICAL);
setGravity(Gravity.LEFT);
mTriangleUpIndicatorView = new TriangleIndicatorView(getContext());
mTriangleUpIndicatorView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT
, LayoutParams.WRAP_CONTENT));
addView(mTriangleUpIndicatorView);
mContainerLayout = new LinearLayout(getContext());
mContainerLayout.setOrientation(VERTICAL);
mContainerLayout.setBackgroundResource(mBackgroundResource);
addView(mContainerLayout);
mTriangleDownIndicatorView = new TriangleIndicatorView(getContext());
mTriangleDownIndicatorView.setOrientation(false);
mTriangleUpIndicatorView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT
, LayoutParams.WRAP_CONTENT));
addView(mTriangleDownIndicatorView);
mTriangleDownIndicatorView.setVisibility(GONE);
}
protected void showWarnToast(String toastText) {
Toast toast = new Toast(BaseMessageActivity.this);
LinearLayout linearLayout = new LinearLayout(BaseMessageActivity.this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setPadding(20, 20, 20, 20);
ImageView imageView = new ImageView(BaseMessageActivity.this);
imageView.setImageResource(R.drawable.voice_to_short);
TextView mTv = new TextView(BaseMessageActivity.this);
mTv.setText(toastText);
mTv.setTextSize(14);
mTv.setTextColor(Color.WHITE);
// 将ImageView和ToastView合并到Layout中
linearLayout.addView(imageView);
linearLayout.addView(mTv);
linearLayout.setGravity(Gravity.CENTER);
linearLayout.setBackgroundResource(R.drawable.record_bg);
toast.setView(linearLayout);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
private LinearLayout getPageBody() {
llBody = new LinearLayout(getContext());
llBody.setId(2);
int resId = getBitmapRes(activity, "edittext_back");
if (resId > 0) {
llBody.setBackgroundResource(resId);
}
llBody.setOrientation(LinearLayout.VERTICAL);
RelativeLayout.LayoutParams lpBody = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpBody.addRule(RelativeLayout.ALIGN_LEFT, llTitle.getId());
lpBody.addRule(RelativeLayout.BELOW, llTitle.getId());
lpBody.addRule(RelativeLayout.ALIGN_RIGHT, llTitle.getId());
if (!dialogMode) {
lpBody.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
}
int dp_3 = dipToPx(getContext(), 3);
lpBody.setMargins(dp_3, dp_3, dp_3, dp_3);
llBody.setLayoutParams(lpBody);
llBody.addView(getMainBody());
llBody.addView(getSep());
llBody.addView(getPlatformList());
return llBody;
}
private LinearLayout getPageBody() {
llBody = new LinearLayout(getContext());
llBody.setId(2);
int resId = getBitmapRes(activity, "edittext_back");
if (resId > 0) {
llBody.setBackgroundResource(resId);
}
llBody.setOrientation(LinearLayout.VERTICAL);
RelativeLayout.LayoutParams lpBody = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpBody.addRule(RelativeLayout.ALIGN_LEFT, llTitle.getId());
lpBody.addRule(RelativeLayout.BELOW, llTitle.getId());
lpBody.addRule(RelativeLayout.ALIGN_RIGHT, llTitle.getId());
if (!dialogMode) {
lpBody.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
}
int dp_3 = dipToPx(getContext(), 3);
lpBody.setMargins(dp_3, dp_3, dp_3, dp_3);
llBody.setLayoutParams(lpBody);
llBody.addView(getMainBody());
llBody.addView(getSep());
llBody.addView(getPlatformList());
return llBody;
}
public void setStyle(String style, LinearLayout background, ImageView iconImg) {
switch (style) {
case "SUCCESS":
background.setBackgroundResource(R.drawable.success_shape);
iconImg.setImageResource(R.drawable.ic_check_black_24dp);
break;
case "FAIL":
background.setBackgroundResource(R.drawable.error_shape);
iconImg.setImageResource(R.drawable.ic_clear_black_24dp);
break;
case "WARN":
background.setBackgroundResource(R.drawable.warning_shape);
iconImg.setImageResource(R.drawable.ic_pan_tool_black_24dp);
break;
case "INFO":
background.setBackgroundResource(R.drawable.info_shape);
iconImg.setImageResource(R.drawable.ic_info_outline_black_24dp);
break;
case "CUSTOM":
background.setBackgroundColor(Color.parseColor(backgroundcolor));
iconImg.setImageResource(icon);
break;
default:
background.setBackgroundResource(R.drawable.default_shape);
iconImg.setImageResource(R.drawable.ic_info_outline_black_24dp);
break;
}
}
@Override
public void generateDialog(LinearLayout root, FragmentManager fragmentManager) {
final int padding = MainApp.dpToPx(5);
root.setPadding(padding, padding, padding, padding);
root.setBackgroundResource(R.drawable.border_automation_unit);
LinearLayout triggerListLayout = new LinearLayout(root.getContext());
triggerListLayout.setOrientation(LinearLayout.VERTICAL);
triggerListLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
root.addView(triggerListLayout);
adapter = new TriggerListAdapter(fragmentManager, root.getContext(), triggerListLayout, this);
}
public AlbumView(Context context) {
super(context);
imageView = new BackupImageView(context);
addView(imageView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setBackgroundResource(R.drawable.album_shadow);
addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 60, Gravity.LEFT | Gravity.BOTTOM));
nameTextView = new TextView(context);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
nameTextView.setTextColor(0xffffffff);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setMaxLines(1);
nameTextView.setGravity(Gravity.BOTTOM);
linearLayout.addView(nameTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 8, 0, 0, 5));
countTextView = new TextView(context);
countTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
countTextView.setTextColor(0xffffffff);
countTextView.setSingleLine(true);
countTextView.setEllipsize(TextUtils.TruncateAt.END);
countTextView.setMaxLines(1);
countTextView.setGravity(Gravity.BOTTOM);
linearLayout.addView(countTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, 4, 0, 7, 5));
selector = new View(context);
selector.setBackgroundDrawable(Theme.getSelectorDrawable(false));
addView(selector, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
}
/**
* 设置textview为选中状态
* @param textView
*/
private void setRewardCoinSelectedColor(LinearLayout linearLayout, TextView textView){
linearLayout.setBackgroundResource(R.drawable.shape_light_blue_rect_border_4dp);
textView.setTextColor(getResources().getColor(R.color.main_blue_color));
}
/**
* Shows the splash screen over the full Activity
*/
@SuppressWarnings("deprecation")
protected void showSplashScreen(final int time) {
final CordovaActivity that = this;
Runnable runnable = new Runnable() {
public void run() {
// Get reference to display
Display display = getWindowManager().getDefaultDisplay();
// Create the layout for the dialog
LinearLayout root = new LinearLayout(that.getActivity());
root.setMinimumHeight(display.getHeight());
root.setMinimumWidth(display.getWidth());
root.setOrientation(LinearLayout.VERTICAL);
root.setBackgroundColor(preferences.getInteger("backgroundColor", Color.BLACK));
root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));
root.setBackgroundResource(that.splashscreen);
// Create and show the dialog
splashDialog = new Dialog(that, android.R.style.Theme_Translucent_NoTitleBar);
// check to see if the splash screen should be full screen
if ((getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN)
== WindowManager.LayoutParams.FLAG_FULLSCREEN) {
splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
splashDialog.setContentView(root);
splashDialog.setCancelable(false);
splashDialog.show();
// Set Runnable to remove splash screen just in case
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
removeSplashScreen();
}
}, time);
}
};
this.runOnUiThread(runnable);
}
/**
* at消息提示
*/
@SuppressLint("ObjectAnimatorBinding")
public void showAtmsgView() {
if (isFinishing()) {
return;
}
ImageView tipImage = new ImageView(PbChatActivity.this);
tipImage.setImageResource(R.drawable.atom_ui_chat_unread_tip);
final TextView textView = new TextView(PbChatActivity.this);
int padding = Utils.dipToPixels(PbChatActivity.this, 4);
int size = Utils.dipToPixels(PbChatActivity.this, 30);
int topMargin = Utils.dipToPixels(PbChatActivity.this, 70);
final LinearLayout linearLayout = new LinearLayout(PbChatActivity.this);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setGravity(Gravity.CENTER_VERTICAL);
linearLayout.setBackgroundResource(R.drawable.atom_ui_float_tab);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
size);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layoutParams.setMargins(0, topMargin, 0, 0);
linearLayout.setPadding(padding * 2, padding, padding * 2, padding);
linearLayout.setLayoutParams(layoutParams);
textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
textView.setGravity(Gravity.CENTER);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
String msg = MessageFormat.format(getString(R.string.atom_ui_tip_somebody_at_you), atMsgIndexs.size());
textView.setText(msg);
textView.setTextColor(Color.parseColor("#EB524A"));
textView.setPadding(padding * 2, 0, 0, 0);
textView.setOnClickListener(v -> {
chat_region.getRefreshableView().smoothScrollToPosition(atMsgIndex);
clearAtmsgTip();
});
linearLayout.addView(tipImage);
linearLayout.addView(textView);
linearLayout.setTag(TAG_ATMSG_VIEW);
final LayoutTransition layoutTransition = new LayoutTransition();
layoutTransition.setAnimator(LayoutTransition.APPEARING, ObjectAnimator.ofFloat(this, "scaleX", 0, 1));
getHandler().postDelayed(() -> {
if (!isFinishing()) {
chating_view.setLayoutTransition(layoutTransition);
chating_view.addView(linearLayout);
}
}, 500);
}
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);
}
public CircularButton(Context context, AttributeSet attrs) {
super(context, attrs);
final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircularButton);
setLayoutTransition(new LayoutTransition());
setRadius(getPx(DEFAULT_RADIUS));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setElevation(getPx(DEFAULT_ELEVATION));
}
mLinearLayout = new LinearLayout(context);
mLinearLayout.setOrientation(LinearLayout.VERTICAL);
// set selectable background
final TypedValue typedValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
typedValue, true);
mSelectableItemBackground = typedValue.resourceId;
mLinearLayout.setBackgroundResource(mSelectableItemBackground);
// create button
mButton = new Button(context);
mButton.setBackgroundColor(Color.TRANSPARENT);
mButton.setClickable(false);
mButton.setPadding((int)getPx(15), mButton.getPaddingTop(), (int)getPx(15),
mButton.getPaddingBottom());
final String text = typedArray.getString(R.styleable.CircularButton_text);
mButton.setText(text);
mButton.setTextColor(typedArray.getColor(R.styleable.CircularButton_textColor, Color.BLACK));
// create progressbar
mProgressBar = new ProgressBar(context);
mProgressBar.setVisibility(View.GONE);
// animation transaction
final LayoutTransition layoutTransition = getLayoutTransition();
layoutTransition.setDuration(DEFAULT_DURATION);
layoutTransition.enableTransitionType(LayoutTransition.CHANGING);
this.setOnClickListener(view -> {
if (isClickable()) {
startLoading();
}
});
// set background color animations
mBackgroundColor = typedArray.getColorStateList(R.styleable.CardView_cardBackgroundColor)
.getDefaultColor();
final ColorDrawable[] color1 = {new ColorDrawable(mBackgroundColor),
new ColorDrawable(Color.WHITE)};
mTransStartLoading = new TransitionDrawable(color1);
final ColorDrawable[] color2 = {new ColorDrawable(mSelectableItemBackground), new
ColorDrawable(mBackgroundColor)};
mTransStopLoading = new TransitionDrawable(color2);
// set progressbar for API < lollipop
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
mProgressBar.setBackgroundColor(Color.WHITE);
mProgressBar.getIndeterminateDrawable().setColorFilter(
mBackgroundColor, PorterDuff.Mode.SRC_IN);
}
typedArray.recycle();
// get the width set
final int[] width = new int[] { android.R.attr.layout_width };
final TypedArray typedArray1 = context.obtainStyledAttributes(attrs, width);
mLayoutWidth = typedArray1.getLayoutDimension(0, ViewGroup.LayoutParams.WRAP_CONTENT);
typedArray1.recycle();
mLinearLayout.addView(mButton);
mLinearLayout.addView(mProgressBar);
addView(mLinearLayout);
}
@Override
protected void onBindDialogView(View view) {
LinearLayout container = view.findViewById(R.id.layoutContainer);
linearLayouts.clear();
checkBoxes.clear();
ArrayList<Integer> results = lg.getMenuShownList();
gameOrder = lg.getOrderedGameList();
TypedValue typedValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
int padding = (int) (getContext().getResources().getDimension(R.dimen.dialog_menu_layout_padding));
int margin = (int) (getContext().getResources().getDimension(R.dimen.dialog_menu_button_margin));
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(margin, 0, margin, 0);
ArrayList<String> sortedGameList = lg.getOrderedGameNameList(getContext().getResources());
for (int i = 0; i < lg.getGameCount(); i++) {
LinearLayout entry = new LinearLayout(getContext());
entry.setBackgroundResource(typedValue.resourceId);
entry.setPadding(padding, padding, padding, padding);
entry.setOnClickListener(this);
CheckBox checkBox = new CheckBox(getContext());
checkBox.setLayoutParams(layoutParams);
int index = gameOrder.indexOf(i);
checkBox.setChecked(results.get(index) == 1);
TextView textView = new TextView(getContext());
textView.setTypeface(null, Typeface.BOLD);
textView.setText(sortedGameList.get(i));
entry.addView(checkBox);
entry.addView(textView);
checkBoxes.add(checkBox);
linearLayouts.add(entry);
container.addView(entry);
}
super.onBindDialogView(view);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Welcome Message
TextView textview = (TextView) findViewById(R.id.text);
textview.setText("Welcome to SocialAuth Demo. Connect any provider and then press Update button to Share Update.");
LinearLayout bar = (LinearLayout) findViewById(R.id.linearbar);
bar.setBackgroundResource(R.drawable.bar_gradient);
// Add Bar to library
adapter = new SocialAuthAdapter(new ResponseListener());
// Please note : Update status functionality is only supported by
// Facebook, Twitter, Linkedin, MySpace, Yahoo and Yammer.
// Add providers
adapter.addProvider(Provider.FACEBOOK, R.drawable.facebook);
adapter.addProvider(Provider.TWITTER, R.drawable.twitter);
adapter.addProvider(Provider.LINKEDIN, R.drawable.linkedin);
// Add email and mms providers
adapter.addProvider(Provider.EMAIL, R.drawable.email);
adapter.addProvider(Provider.MMS, R.drawable.mms);
// For twitter use add callback method. Put your own callback url here.
adapter.addCallBack(Provider.TWITTER, "http://socialauth.in/socialauthdemo/socialAuthSuccessAction.do");
// Add keys and Secrets
try {
adapter.addConfig(Provider.FACEBOOK, "297841130364674", "dc9c59d0c72d4f2533580e80ba4c2a59", null);
adapter.addConfig(Provider.TWITTER, "5jwyYJia583EEczmdAmlOA", "j0rQkJjTjwVdv7HFiE4zz2qKJKzqjksR2aviVU8fSc",
null);
adapter.addConfig(Provider.LINKEDIN, "bh82t52rdos6", "zQ1LLrGbhDZ36fH8", null);
} catch (Exception e) {
e.printStackTrace();
}
adapter.enable(bar);
}
/**
* Shows the splash screen over the full Activity
*/
@SuppressWarnings("deprecation")
protected void showSplashScreen(final int time) {
final CordovaActivity that = this;
Runnable runnable = new Runnable() {
public void run() {
// Get reference to display
Display display = getWindowManager().getDefaultDisplay();
// Create the layout for the dialog
LinearLayout root = new LinearLayout(that.getActivity());
root.setMinimumHeight(display.getHeight());
root.setMinimumWidth(display.getWidth());
root.setOrientation(LinearLayout.VERTICAL);
root.setBackgroundColor(that.getIntegerProperty("backgroundColor", Color.BLACK));
root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));
root.setBackgroundResource(that.splashscreen);
// Create and show the dialog
splashDialog = new Dialog(that, android.R.style.Theme_Translucent_NoTitleBar);
// check to see if the splash screen should be full screen
if ((getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN)
== WindowManager.LayoutParams.FLAG_FULLSCREEN) {
splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
splashDialog.setContentView(root);
splashDialog.setCancelable(false);
splashDialog.show();
// Set Runnable to remove splash screen just in case
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
removeSplashScreen();
}
}, time);
}
};
this.runOnUiThread(runnable);
}
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);
}
/**
* build the MiniDrawer
*
* @param ctx
* @return
*/
public View build(Context ctx) {
mContainer = new LinearLayout(ctx);
if (mInnerShadow) {
if (!mInRTL) {
mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_left);
} else {
mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_right);
}
}
//create and append recyclerView
mRecyclerView = new RecyclerView(ctx);
mContainer.addView(mRecyclerView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//set the itemAnimator
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
//some style improvements on older devices
mRecyclerView.setFadingEdgeLength(0);
//set the drawing cache background to the same color as the slider to improve performance
//mRecyclerView.setDrawingCacheBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity, R.attr.material_drawer_background, R.color.material_drawer_background));
mRecyclerView.setClipToPadding(false);
//additional stuff
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
//adapter
mDrawerAdapter = new DrawerAdapter();
mRecyclerView.setAdapter(mDrawerAdapter);
//if the activity with the drawer should be fullscreen add the padding for the statusbar
if (mDrawer != null && mDrawer.mDrawerBuilder != null && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentStatusBar)) {
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), UIUtils.getStatusBarHeight(ctx), mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom());
}
//if the activity with the drawer should be fullscreen add the padding for the navigationBar
if (mDrawer != null && mDrawer.mDrawerBuilder != null && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentNavigationBar)) {
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(), mRecyclerView.getPaddingRight(), UIUtils.getNavigationBarHeight(ctx));
}
//set the adapter with the items
createItems();
return mContainer;
}
@SuppressWarnings("WrongThread")
@Override
protected Bitmap doInBackground(Feature... params) {
Log.d(TAG, "GenerateInfoWindowTask start");
Thread.currentThread().setName(GenerateInfoWindowTask.class.getName());
Bitmap bitmap = null;
try {
LayoutInflater inflater = LayoutInflater.from(callbackRef.get().getContext());
Feature feature = params[0];
Log.d(TAG, "GenerateInfoWindowTask: feature " + feature.id());
LinearLayout bubbleLayout = (LinearLayout)
inflater.inflate(R.layout.map_bubble_layout, null);
bubbleLayout.setBackgroundResource(R.drawable.message_bubble_background_received_alone);
EmojiTextView conversationItemBody = bubbleLayout.findViewById(R.id.conversation_item_body);
Locale locale = DynamicLanguage.getSelectedLocale(callbackRef.get().getContext());
int messageId = (int) feature.getNumberProperty(MESSAGE_ID);
int contactId = (int) feature.getNumberProperty(CONTACT_ID);
DcContact contact = DcHelper.getContext(callbackRef.get().getContext()).getContact(contactId);
TextView contactTextView = bubbleLayout.findViewById(R.id.message_sender);
contactTextView.setText(contact.getFirstName());
String msgText;
if (messageId != 0) {
DcContext dcContext = DcHelper.getContext(callbackRef.get().getContext());
DcMsg msg = dcContext.getMsg(messageId);
if (hasImgThumbnail(msg)) {
ImageView thumbnailView = bubbleLayout.findViewById(R.id.map_bubble_img_thumbnail);
thumbnailView.setImageURI(getThumbnailUri(msg));
thumbnailView.setVisibility(View.VISIBLE);
msgText = msg.getText();
} else {
msgText = msg.getSummarytext(75);
}
ConversationItemFooter footer = bubbleLayout.findViewById(R.id.conversation_item_footer);
footer.setVisibility(View.VISIBLE);
footer.setMessageRecord(msg, locale);
} else {
msgText = "Reported: " + DateUtils.getExtendedRelativeTimeSpanString(callbackRef.get().getContext(), locale, (long) feature.getNumberProperty(TIMESTAMP));
}
if (msgText.length() == 0) {
conversationItemBody.setVisibility(GONE);
} else {
conversationItemBody.setText(msgText);
}
bitmap = BitmapUtil.generate(bubbleLayout);
} catch (NullPointerException npe) {
npe.printStackTrace();
Log.e(TAG, "Callback was GC'ed before task finished.");
}
Log.d(TAG, "GenerateInfoWindowTask finished");
return bitmap;
}
@Override
public View getView(Context context, final HintCase hintCase, ViewGroup parent) {
this.hintCase = hintCase;
this.parent = parent;
calculateDataToPutTheArroW(hintCase);
setArrow(context);
FrameLayout.LayoutParams frameLayoutParamsBlock = getParentLayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
gravity, marginLeft, marginTop, marginRight, marginBottom);
RelativeLayout fullBlockLayout = new RelativeLayout(context);
fullBlockLayout.setLayoutParams(frameLayoutParamsBlock);
RelativeLayout.LayoutParams relativeLayoutParamsLinear =
new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
for (int rule : alignBlockRules) {
relativeLayoutParamsLinear.addRule(rule);
}
relativeLayoutParamsLinear.topMargin = contentTopMargin;
relativeLayoutParamsLinear.bottomMargin = contentBottomMargin;
relativeLayoutParamsLinear.rightMargin = contentRightMargin;
relativeLayoutParamsLinear.leftMargin = contentLeftMargin;
contentLinearLayout = new LinearLayout(context);
contentLinearLayout.setBackgroundResource(R.drawable.bubble_border_background);
LayerDrawable layerDrawable = (LayerDrawable) contentLinearLayout.getBackground().getCurrent();
GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable.getDrawable(layerDrawable.getNumberOfLayers() - 1);
gradientDrawable.setColor(backgroundColor);
if (useBorder) {
gradientDrawable.setStroke(borderSize, borderColor);
}
contentLinearLayout.setLayoutParams(relativeLayoutParamsLinear);
contentLinearLayout.setGravity(Gravity.CENTER);
int padding = borderSize + shadowSize;
contentLinearLayout.setPadding(padding + contentLeftPadding,
padding + contentTopPadding,
padding + contentRightPadding,
padding + contentBottomPadding);
contentLinearLayout.setOrientation(LinearLayout.VERTICAL);
if (contentTitle != null) {
contentLinearLayout.addView(getTextViewTitle(context));
}
if (existImage()) {
contentLinearLayout.addView(getImage(context, imageView, imageResourceId));
}
if (contentText != null) {
contentLinearLayout.addView(getTextViewDescription(context));
}
fullBlockLayout.addView(contentLinearLayout);
fullBlockLayout.addView(arrow);
return fullBlockLayout;
}
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);
}