/** * 向指定平台分享内容 * * <p><b>注意:</b><br> * 参数data的键值需要严格按照{@link ShareParams}不同子类具体字段来命名, 否则无法反射此字段,也无法设置其值。 */ public boolean share(Platform plat, HashMap<String, Object> data) { if (plat == null || data == null) { return false; } try { String imagePath = (String) data.get("imagePath"); Bitmap viewToShare = (Bitmap) data.get("viewToShare"); if (TextUtils.isEmpty(imagePath) && viewToShare != null && !viewToShare.isRecycled()) { String path = R.getCachePath(plat.getContext(), "screenshot"); File ss = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg"); FileOutputStream fos = new FileOutputStream(ss); viewToShare.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); data.put("imagePath", ss.getAbsolutePath()); } } catch (Throwable t) { t.printStackTrace(); return false; } ShareParams sp = new ShareParams(data); if (customizeCallback != null) { customizeCallback.onShare(plat, sp); } plat.share(sp); return true; }
// initializes the girdview of platforms public void afterPlatformListGot() { PlatformAdapter adapter = new PlatformAdapter(this); pager.setAdapter(adapter); int pageCount = 0; if (platformList != null) { int cusSize = customers == null ? 0 : customers.size(); int platSize = platformList == null ? 0 : platformList.length; int hideSize = hiddenPlatforms == null ? 0 : hiddenPlatforms.size(); platSize = platSize - hideSize; int size = platSize + cusSize; pageCount = size / PAGE_SIZE; if (size % PAGE_SIZE > 0) { pageCount++; } } points = new ImageView[pageCount]; if (points.length <= 0) { return; } Context context = getContext(); LinearLayout llPoints = new LinearLayout(context); // if the total number of pages exceeds 1, we set the page indicators llPoints.setVisibility(pageCount > 1 ? View.VISIBLE : View.GONE); LayoutParams lpLl = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpLl.gravity = Gravity.CENTER_HORIZONTAL; llPoints.setLayoutParams(lpLl); addView(llPoints); int dp_5 = com.mob.tools.utils.R.dipToPx(context, 5); int resId = getBitmapRes(getContext(), "light_blue_point"); if (resId > 0) { grayPoint = BitmapFactory.decodeResource(getResources(), resId); } resId = getBitmapRes(getContext(), "blue_point"); if (resId > 0) { bluePoint = BitmapFactory.decodeResource(getResources(), resId); } for (int i = 0; i < pageCount; i++) { points[i] = new ImageView(context); points[i].setScaleType(ScaleType.CENTER_INSIDE); points[i].setImageBitmap(grayPoint); LayoutParams lpIv = new LayoutParams(dp_5, dp_5); lpIv.setMargins(dp_5, dp_5, dp_5, 0); points[i].setLayoutParams(lpIv); llPoints.addView(points[i]); } int curPage = pager.getCurrentScreen(); points[curPage].setImageBitmap(bluePoint); }
protected void calculateSize(Context context, ArrayList<Object> plats) { int screenWidth = R.getScreenWidth(context); float ratio = ((float) screenWidth) / DESIGN_SCREEN_WIDTH_L; int cellWidth = (int) (DESIGN_CELL_WIDTH_L * ratio); lineSize = screenWidth / cellWidth; sepLineWidth = (int) (DESIGN_SEP_LINE_WIDTH * ratio); sepLineWidth = sepLineWidth < 1 ? 1 : sepLineWidth; logoHeight = (int) (DESIGN_LOGO_HEIGHT * ratio); paddingTop = (int) (DESIGN_PADDING_TOP * ratio); bottomHeight = (int) (DESIGN_BOTTOM_HEIGHT * ratio); cellHeight = (screenWidth - sepLineWidth * 3) / (lineSize - 1); panelHeight = cellHeight + sepLineWidth; }
private void calPageSize() { float scrW = com.mob.tools.utils.R.getScreenWidth(getContext()); float scrH = com.mob.tools.utils.R.getScreenHeight(getContext()); float whR = scrW / scrH; if (whR < 0.63) { COLUMN_PER_LINE = 3; LINE_PER_PAGE = 3; } else if (whR < 0.75) { COLUMN_PER_LINE = 3; LINE_PER_PAGE = 2; } else { LINE_PER_PAGE = 1; if (whR >= 1.75) { COLUMN_PER_LINE = 6; } else if (whR >= 1.5) { COLUMN_PER_LINE = 5; } else if (whR >= 1.3) { COLUMN_PER_LINE = 4; } else { COLUMN_PER_LINE = 3; } } PAGE_SIZE = COLUMN_PER_LINE * LINE_PER_PAGE; }
private String getName(Platform plat) { if (plat == null) { return ""; } String name = plat.getName(); if (name == null) { return ""; } int resId = com.mob.tools.utils.R.getStringRes(getContext(), plat.getName().toLowerCase()); if (resId > 0) { return getContext().getString(resId); } return null; }
private LinearLayout getView(int position, OnClickListener ocL, Context context) { Bitmap logo; String label; OnClickListener listener; if (beans[position] instanceof Platform) { logo = getIcon((Platform) beans[position]); label = getName((Platform) beans[position]); listener = ocL; } else { logo = ((CustomerLogo) beans[position]).enableLogo; label = ((CustomerLogo) beans[position]).label; listener = ocL; } LinearLayout ll = new LinearLayout(context); ll.setOrientation(LinearLayout.VERTICAL); ImageView iv = new ImageView(context); int dp_5 = com.mob.tools.utils.R.dipToPx(context, 5); iv.setPadding(dp_5, dp_5, dp_5, dp_5); iv.setScaleType(ScaleType.CENTER_INSIDE); LayoutParams lpIv = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpIv.setMargins(dp_5, dp_5, dp_5, dp_5); lpIv.gravity = Gravity.CENTER_HORIZONTAL; iv.setLayoutParams(lpIv); iv.setImageBitmap(logo); ll.addView(iv); TextView tv = new TextView(context); tv.setTextColor(0xff000000); tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); tv.setSingleLine(); tv.setIncludeFontPadding(false); LayoutParams lpTv = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpTv.gravity = Gravity.CENTER_HORIZONTAL; lpTv.weight = 1; lpTv.setMargins(dp_5, 0, dp_5, dp_5); tv.setLayoutParams(lpTv); tv.setText(label); ll.addView(tv); ll.setOnClickListener(listener); return ll; }
private void init() { int dp_5 = com.mob.tools.utils.R.dipToPx(getContext(), 5); setPadding(0, dp_5, 0, dp_5); setOrientation(VERTICAL); int size = beans == null ? 0 : beans.length; int COLUMN_PER_LINE = platformAdapter.platformGridView.COLUMN_PER_LINE; int lineSize = size / COLUMN_PER_LINE; if (size % COLUMN_PER_LINE > 0) { lineSize++; } LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); lp.weight = 1; for (int i = 0; i < lines; i++) { LinearLayout llLine = new LinearLayout(getContext()); llLine.setLayoutParams(lp); llLine.setPadding(dp_5, 0, dp_5, 0); addView(llLine); if (i >= lineSize) { continue; } for (int j = 0; j < COLUMN_PER_LINE; j++) { final int index = i * COLUMN_PER_LINE + j; if (index >= size) { LinearLayout llItem = new LinearLayout(getContext()); llItem.setLayoutParams(lp); llLine.addView(llItem); continue; } final LinearLayout llItem = getView(index, callback, getContext()); llItem.setTag(beans[index]); llItem.setLayoutParams(lp); llLine.addView(llItem); } } }
protected void onCreateContent(LinearLayout parent) { SizeHelper.prepare(context); LinearLayout rlCountry = new LinearLayout(context); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, SizeHelper.fromPxWidth(96)); params.setMargins( SizeHelper.fromPx(26), SizeHelper.fromPxWidth(32), SizeHelper.fromPxWidth(26), 0); rlCountry.setLayoutParams(params); rlCountry.setId(Res.id.rl_country); TextView tv = new TextView(context); LinearLayout.LayoutParams tvParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tvParams.gravity = Gravity.CENTER_VERTICAL; tv.setLayoutParams(tvParams); tv.setPadding(SizeHelper.fromPxWidth(14), 0, SizeHelper.fromPxWidth(14), 0); int resid = R.getStringRes(context, "smssdk_country"); tv.setText(resid); tv.setTextColor(0xff000000); tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); rlCountry.addView(tv); TextView tvCountry = new TextView(context); tvCountry.setId(Res.id.tv_country); LinearLayout.LayoutParams tvCountryParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tvCountryParams.gravity = Gravity.CENTER_VERTICAL; tvCountryParams.weight = 1; tvCountryParams.rightMargin = SizeHelper.fromPxWidth(14); tvCountry.setLayoutParams(tvCountryParams); tvCountry.setGravity(Gravity.RIGHT); tvCountry.setPadding(SizeHelper.fromPxWidth(14), 0, SizeHelper.fromPxWidth(14), 0); tvCountry.setTextColor(0xff45c01a); tvCountry.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); rlCountry.addView(tvCountry); parent.addView(rlCountry); View line = new View(context); LinearLayout.LayoutParams lineParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, SizeHelper.fromPxWidth(1)); lineParams.leftMargin = SizeHelper.fromPxWidth(26); lineParams.rightMargin = SizeHelper.fromPxWidth(26); line.setLayoutParams(lineParams); line.setBackgroundColor(Res.color.smssdk_gray_press); parent.addView(line); LinearLayout phoneLayout = new LinearLayout(context); LinearLayout.LayoutParams phoneParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, SizeHelper.fromPxWidth(70)); phoneParams.setMargins( SizeHelper.fromPxWidth(26), SizeHelper.fromPxWidth(30), SizeHelper.fromPxWidth(26), 0); phoneLayout.setLayoutParams(phoneParams); TextView countryNum = new TextView(context); countryNum.setId(Res.id.tv_country_num); LinearLayout.LayoutParams countryNumParams = new LinearLayout.LayoutParams( SizeHelper.fromPxWidth(104), LinearLayout.LayoutParams.MATCH_PARENT); countryNum.setLayoutParams(countryNumParams); countryNum.setGravity(Gravity.CENTER); countryNum.setTextColor(0xff353535); countryNum.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); resid = R.getBitmapRes(context, "smssdk_input_bg_focus"); countryNum.setBackgroundResource(resid); phoneLayout.addView(countryNum); LinearLayout wrapperLayout = new LinearLayout(context); LinearLayout.LayoutParams wrapperParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT); wrapperParams.weight = 1; wrapperLayout.setLayoutParams(wrapperParams); resid = R.getBitmapRes(context, "smssdk_input_bg_special_focus"); wrapperLayout.setBackgroundResource(resid); EditText writePhone = new EditText(context); writePhone.setId(Res.id.et_write_phone); LinearLayout.LayoutParams writePhoneParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT); writePhoneParams.gravity = Gravity.CENTER_VERTICAL; writePhoneParams.setMargins(SizeHelper.fromPxWidth(10), 0, SizeHelper.fromPxWidth(10), 0); writePhoneParams.weight = 1; writePhone.setLayoutParams(writePhoneParams); writePhone.setBackgroundDrawable(null); resid = R.getStringRes(context, "smssdk_write_mobile_phone"); writePhone.setHint(resid); writePhone.setInputType(InputType.TYPE_CLASS_PHONE); writePhone.setTextColor(0xff353535); writePhone.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); wrapperLayout.addView(writePhone); ImageView image = new ImageView(context); image.setId(Res.id.iv_clear); LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams(SizeHelper.fromPxWidth(24), SizeHelper.fromPxWidth(24)); imageParams.gravity = Gravity.CENTER_VERTICAL; imageParams.rightMargin = SizeHelper.fromPxWidth(20); image.setLayoutParams(imageParams); resid = R.getBitmapRes(context, "smssdk_clear_search"); image.setBackgroundResource(resid); image.setScaleType(ScaleType.CENTER_INSIDE); image.setVisibility(View.GONE); wrapperLayout.addView(image); phoneLayout.addView(wrapperLayout); parent.addView(phoneLayout); Button nextBtn = new Button(context); nextBtn.setId(Res.id.btn_next); LinearLayout.LayoutParams nextParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, SizeHelper.fromPxWidth(72)); nextParams.setMargins( SizeHelper.fromPxWidth(26), SizeHelper.fromPxWidth(36), SizeHelper.fromPxWidth(26), 0); nextBtn.setLayoutParams(nextParams); resid = R.getBitmapRes(context, "smssdk_btn_disenable"); nextBtn.setBackgroundResource(resid); resid = R.getStringRes(context, "smssdk_next"); nextBtn.setText(resid); nextBtn.setTextColor(0xffffffff); nextBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); nextBtn.setPadding(0, 0, 0, 0); parent.addView(nextBtn); }