Ejemplo n.º 1
0
 /**
  * 获取头像位图
  *
  * @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;
 }
Ejemplo n.º 2
0
 /**
  * 打开单选框
  *
  * @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);
 }