/** * 获取合适称呼 * * @return 合适称呼 */ public String nickname() { if (!Text.isBlank(nickname)) { return nickname; } if (!Text.isBlank(name)) { return name; } return "未知"; }
/** * 获取头像位图 * * @return 头像位图 */ public <T> void photo(T tatget, ITargetEventable<T, Bitmap> event) { if (Text.isBlank(photo)) { event.on(tatget, null); return; } Networking.doImage("image", tatget, event, photo); }
/** * 获取头像位图 * * @return 头像位图 */ public Bitmap photo() { if (Text.isBlank(photo)) { return null; } File file = new File(Networking.cache + Networking.parseFileNameWithURL(photo)); if (file.exists()) { return GraphicsHelper.makeCycleImage(GraphicsHelper.decodeFile(file), 200, 200); } return null; }
/** * 打开单选框 * * @param context 上下文 * @param parameters 参数列表 */ public static void showSelector( Context context, final IEventable<Integer> callback, String... parameters) { final AlertDialog alertDialog = new AlertDialog.Builder(context).create(); alertDialog.show(); Window window = alertDialog.getWindow(); WindowManager.LayoutParams layoutParams = window.getAttributes(); layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; window.setGravity(Gravity.BOTTOM); window.setAttributes(layoutParams); LinearLayout contentLayout = new LinearLayout(context); LinearLayout.LayoutParams contentLayoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); contentLayout.setGravity(Gravity.BOTTOM); contentLayout.setOrientation(LinearLayout.VERTICAL); contentLayout.setBackgroundColor(context.getResources().getColor(R.color.grey_bg)); boolean sentry = false; int position = -1; for (int i = 0; i < parameters.length; i++) { String parameter = parameters[i]; if (Text.isBlank(parameter)) { sentry = true; continue; } position++; TextView textView = new TextView(context); textView.setText(parameter); textView.setTag(position); textView.setGravity(Gravity.CENTER); textView.setTextColor(context.getResources().getColor(R.color.grey_text)); textView.setTextSize(18); textView.setBackgroundColor(Color.WHITE); textView.setHeight(GraphicsHelper.dip2px(context, 40)); LinearLayout.LayoutParams textLayoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); if (sentry) { textLayoutParams.topMargin = GraphicsHelper.dip2px(context, 2); } else { textLayoutParams.topMargin = GraphicsHelper.dip2px(context, 1); } contentLayout.addView(textView, textLayoutParams); textView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { callback.on((Integer) v.getTag()); alertDialog.cancel(); } }); } window.setContentView(contentLayout, contentLayoutParams); }