private void listAll() {
    ViewGroup root = mList;
    root.removeAllViews();

    // 列出所有已经安装的插件
    Collection<PluginDescriptor> plugins = PluginLoader.getPlugins();
    Iterator<PluginDescriptor> itr = plugins.iterator();
    while (itr.hasNext()) {
      final PluginDescriptor pluginDescriptor = itr.next();
      Button button = new Button(this);
      button.setPadding(10, 10, 10, 10);
      button.setText("插件id:" + pluginDescriptor.getPackageName() + ",点击查看");
      button.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              Intent intent = new Intent(PluginListActivity.this, PluginDetailActivity.class);
              intent.putExtra("plugin_id", pluginDescriptor.getPackageName());
              startActivity(intent);
            }
          });

      LayoutParams layoutParam =
          new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
      layoutParam.topMargin = 10;
      layoutParam.bottomMargin = 10;
      layoutParam.gravity = Gravity.LEFT;
      root.addView(button, layoutParam);
    }
  }
Ejemplo n.º 2
0
  private void init() {
    // TODO Auto-generated method stub
    // 滑动对象,
    LastRefreshTime = Calendar.getInstance();
    scroller = new Scroller(mContext);

    // 刷新视图顶端的的view,也就是下拉之后显示在的顶端的那部分布局
    refreshView = LayoutInflater.from(mContext).inflate(R.layout.refresh_top_item, null);
    // 指示器view
    refreshIndicatorView = (ImageView) refreshView.findViewById(R.id.indicator);
    // 刷新bar
    bar = (ProgressBar) refreshView.findViewById(R.id.progress);
    // 下拉显示text
    downTextView = (TextView) refreshView.findViewById(R.id.refresh_hint);
    // 下来显示时间
    timeTextView = (TextView) refreshView.findViewById(R.id.refresh_time);
    reFreshTimeLayout = (LinearLayout) refreshView.findViewById(R.id.refresh_time_layout);

    LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, -refreshTargetTop);
    lp.topMargin = refreshTargetTop; // 将刷新区域大小赋予布局参数的顶部margin
    lp.gravity = Gravity.CENTER; // 居中显示
    addView(refreshView, lp); // 此部分布局是加载在生成参数1的上下文所在的布局中
    downTextString = mContext.getResources().getString(R.string.refresh_down_text);
    releaseTextString = mContext.getResources().getString(R.string.refresh_release_text);
  }
  @Override
  public View onCreateView() {

    LinearLayout ll_container = new LinearLayout(context);
    ll_container.setOrientation(LinearLayout.VERTICAL);
    ll_container.setBackgroundColor(Color.TRANSPARENT);

    /** title */
    tv_title = new TextView(context);
    tv_title.setGravity(Gravity.CENTER);
    tv_title.setPadding(dp2px(10), dp2px(5), dp2px(10), dp2px(5));

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.topMargin = dp2px(20);

    ll_container.addView(tv_title, params);

    /** title underline */
    v_line_title = new View(context);
    ll_container.addView(v_line_title);

    /** listview */
    lv = new ListView(context);
    lv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1));
    lv.setCacheColorHint(Color.TRANSPARENT);
    lv.setFadingEdgeLength(0);
    lv.setVerticalScrollBarEnabled(false);
    lv.setSelector(new ColorDrawable(Color.TRANSPARENT));

    ll_container.addView(lv);

    /** cancel btn */
    tv_cancel = new TextView(context);
    tv_cancel.setGravity(Gravity.CENTER);
    LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    lp.topMargin = dp2px(7);
    lp.bottomMargin = dp2px(7);
    tv_cancel.setLayoutParams(lp);

    ll_container.addView(tv_cancel);

    /** LayoutAnimation */
    TranslateAnimation animation =
        new TranslateAnimation(
            Animation.RELATIVE_TO_SELF,
            0f,
            Animation.RELATIVE_TO_SELF,
            0f,
            Animation.RELATIVE_TO_SELF,
            6f,
            Animation.RELATIVE_TO_SELF,
            0);
    animation.setInterpolator(new DecelerateInterpolator());
    animation.setDuration(350);
    animation.setStartOffset(150);

    lac = new LayoutAnimationController(animation, 0.12f);
    lac.setInterpolator(new DecelerateInterpolator());

    return ll_container;
  }
    @SuppressWarnings("deprecation")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      Message message1 = (Message) this.getItem(position);

      ViewHolder holder;
      if (convertView == null) {
        holder = new ViewHolder();
        convertView = LayoutInflater.from(mContext).inflate(R.layout.sms_row, parent, false);
        holder.message = (EmojiconTextView) convertView.findViewById(R.id.message_text);
        holder.thumb = (FetchableImageView) convertView.findViewById(R.id.thumb);
        holder.message.setPadding(10, 10, 10, 10);
        convertView.setTag(holder);
      } else holder = (ViewHolder) convertView.getTag();
      if (message1.getMsgtype().equalsIgnoreCase("text")) {
        holder.message.setVisibility(View.VISIBLE);
        holder.thumb.setVisibility(View.GONE);

        holder.message.setText(message1.getMessage());
        LayoutParams lp = (LayoutParams) holder.message.getLayoutParams();
        if (message1.getIsmine().equals("yes")) {
          holder.message.setBackgroundResource(R.drawable.message_you);
          holder.message.setPadding(15, 15, 15, 15);
          lp.gravity = Gravity.RIGHT;
          lp.leftMargin = 50;
          lp.rightMargin = 20;
        }
        // If not mine then it is from sender to show orange background and
        // align to left
        else {
          holder.message.setBackgroundResource(R.drawable.message_from);
          holder.message.setPadding(15, 15, 15, 15);
          lp.gravity = Gravity.LEFT;
          lp.rightMargin = 50;
          lp.leftMargin = 20;
        }
        holder.message.setLayoutParams(lp);
        holder.message.setTextColor(mContext.getResources().getColor(R.color.Black));
      } else {
        LayoutParams lp1 = (LayoutParams) holder.thumb.getLayoutParams();
        holder.message.setVisibility(View.GONE);
        holder.thumb.setVisibility(View.VISIBLE);
        holder.thumb.setPadding(15, 15, 15, 15);
        if (message1.getMsgtype().equals("video")) {

          holder.thumb.setImage(message1.getMessage(), R.drawable.placeholder_video);
          final String url = DataManager.FILE_PATH + message1.getMessage().toString();
          holder.thumb.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(Intent.ACTION_VIEW);
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  intent.setDataAndType(Uri.parse(url), "video/*");
                  mContext.startActivity(intent);
                }
              });
        } else if (message1.getMsgtype().equals("audio")) {
          holder.thumb.setImage(message1.getMessage(), R.drawable.placeholder_audio);
          final String url = DataManager.FILE_PATH + message1.getMessage();
          holder.thumb.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Uri myUri = Uri.parse(url);
                  Intent intent = new Intent(Intent.ACTION_VIEW);
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  intent.setDataAndType(myUri, "audio/*");
                  mContext.startActivity(intent);
                }
              });
        } else if (message1.getMsgtype().equals("photo")) {
          holder.thumb.setImage(
              DataManager.FILE_PATH + message1.getMessage(), R.drawable.placeholder_image);
          final String url = DataManager.FILE_PATH + message1.getMessage();
          holder.thumb.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(Intent.ACTION_VIEW);
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  intent.setDataAndType(Uri.parse(url), "image/*");
                  mContext.startActivity(intent);
                }
              });
        }
        if (message1.getIsmine().equals("yes")) {
          holder.thumb.setBackgroundResource(R.drawable.message_you);
          holder.thumb.setPadding(15, 15, 15, 15);
          lp1.gravity = Gravity.RIGHT;
          lp1.topMargin = 10;
          lp1.bottomMargin = 10;
          lp1.leftMargin = 50;
          lp1.rightMargin = 20;
        }
        // If not mine then it is from sender to show orange background and
        // align to left
        else {
          holder.thumb.setBackgroundResource(R.drawable.message_from);
          holder.thumb.setPadding(15, 15, 15, 15);
          lp1.gravity = Gravity.LEFT;
          lp1.topMargin = 10;
          lp1.bottomMargin = 10;
          lp1.rightMargin = 50;
          lp1.leftMargin = 20;
        }
        holder.thumb.setLayoutParams(lp1);
      }
      return convertView;
    }
  /** 设置button的 宽度 以及监听 */
  private void setButton() {
    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    int width0 = 2; // 边框宽度
    int width1 = 10; // 外部边框距左右边界距离
    int hight0 = 70; // 外部边框高度
    LinearLayout a_layout = (LinearLayout) findViewById(R.id.a_layout);
    LayoutParams param = (LayoutParams) a_layout.getLayoutParams();
    param.topMargin = 10;
    param.bottomMargin = 10;
    param.leftMargin = width1;
    param.rightMargin = width1;
    if (height == 1280 && width == 720) {
      hight0 = 70;
      width = width + 4;
      param.leftMargin = width1;
      param.rightMargin = width1 + 1;
    } else if (height == 854 && width == 480) {
      hight0 = 45;
      width1 = 18;
      width0 = 2;
      param.leftMargin = width1;
      param.rightMargin = width1 - 1;
    } else if (height == 800 && width == 480) {
      hight0 = 45;
      width1 = 18;
      width0 = 2;
      param.leftMargin = width1;
      param.rightMargin = width1 - 1;
    } else if (height >= 1750 && height <= 1920 && width == 1080) {
      width1 = 40; // 外部边框距左右边界距离
      hight0 = 100;
      param.leftMargin = width1;
      param.rightMargin = width1;
    }
    int hight1 = hight0 - width0 * 2; // button高度
    param.height = hight0;
    // view1 = (Button) findViewById(R.id.view_1);
    // view2 = (Button) findViewById(R.id.view_2);
    // view3 = (Button) findViewById(R.id.view_3);
    // view1.setWidth(width0);
    // view2.setWidth(width0);
    // view3.setWidth(width0);
    // view1.setHeight(hight1);
    // view2.setHeight(hight1);
    // view3.setHeight(hight1);

    int button_width = (width - width1 * 2 - 7 * width0) / 4;
    button_1 = (Button) findViewById(R.id.button_1);
    button_2 = (Button) findViewById(R.id.button_2);
    button_3 = (Button) findViewById(R.id.button_3);
    button_4 = (Button) findViewById(R.id.button_4);
    button_1.setOnClickListener(this);
    button_2.setOnClickListener(this);
    button_3.setOnClickListener(this);
    button_4.setOnClickListener(this);
    btnList.add(button_1);
    btnList.add(button_2);
    btnList.add(button_3);
    btnList.add(button_4);

    for (int i = 0; i < btnList.size(); i++) {
      btnList.get(i).setWidth(button_width);
      btnList.get(i).setHeight(hight1);
    }

    if (version < 4) {
      button_1.setBackgroundResource(R.drawable.left_shape_red2);
      button_4.setBackgroundResource(R.drawable.right_shape_white2);
    }
  }