public void setIndeterminate(boolean z) {
   if (this.mProgressBar.isIndeterminate() != z) {
     LayoutParams layoutParams = (LayoutParams) this.mProgressBar.getLayoutParams();
     if (z) {
       layoutParams.width = -2;
       layoutParams.height = -2;
       layoutParams.gravity = 17;
     } else {
       layoutParams.width = -1;
       layoutParams.height =
           (int) TypedValue.applyDimension(1, 1.0f, getResources().getDisplayMetrics());
       layoutParams.gravity = 48;
     }
     this.mProgressBar.setLayoutParams(layoutParams);
     this.mProgressBar.setIndeterminate(z);
   }
 }
示例#2
0
 private EditText addPlayerEdittext(int playerNumber, LayoutInflater inflater) {
   EditText playerText = (EditText) new EditText(getActivity());
   LayoutParams params = (LayoutParams) mPlayerNameContainer.getLayoutParams();
   params.height = LayoutParams.WRAP_CONTENT;
   params.width = LayoutParams.MATCH_PARENT;
   playerText.setLayoutParams(params);
   playerText.setHint(getResources().getString(R.string.player) + " " + playerNumber);
   mPlayerNameContainer.addView(playerText);
   return playerText;
 }
示例#3
0
        @Override
        public void handleMessage(Message msg) {
          if (msg.what == WEATHER_IS_READY) { // 利用handler发送延时消息,根据用户指定更新时间,更新天气
            if (mWeatherContainer.getChildCount() != 0) {
              mWeatherContainer.removeAllViews();
            }
            // String cityCode = config.getCityCode();
            String temperature = config.getShowType() > 0 ? "f" : "c";
            // showWeatherInfos("2161853", temperature);
            showWeatherInfos(temperature);
            handler.sendEmptyMessageDelayed(
                WEATHER_IS_READY, config.getUpdateFrequency() * 60 * 60);
          } else if (msg.what == GET_WEATHER_SUCCESS) {
            List<WeatherInfo> infos;
            SAXParserFactory factory = null;
            SAXParser saxParser = null;
            XMLReader xmlReader = null;
            GetYahooWeatherSaxTools tools = null;
            try {
              factory = SAXParserFactory.newInstance();
              saxParser = factory.newSAXParser();
              xmlReader = saxParser.getXMLReader();
              infos = new ArrayList<WeatherInfo>();
              tools = new GetYahooWeatherSaxTools(infos);

              xmlReader.setContentHandler(tools);
              xmlReader.parse(new InputSource(new StringReader((String) msg.obj)));
              // 获取当前是周几,用数字表示
              int currentDay = mWeekList.indexOf(infos.get(0).getDay());
              int forecastDay = 0;
              // 将得到的list天气数据,展示到屏幕上
              for (int i = 0; i < config.getForecastDays(); i++) {
                view = View.inflate(context, R.layout.weather_item, null);
                TextView tvDay = (TextView) view.findViewById(R.id.tv_day);
                TextView tvLow = (TextView) view.findViewById(R.id.tv_temperature_low);
                TextView tvHigh = (TextView) view.findViewById(R.id.tv_temperature_high);
                TextView tvWeather = (TextView) view.findViewById(R.id.tv_weather);
                ImageView ivWeatherIcon = (ImageView) view.findViewById(R.id.iv_weather_icon);
                forecastDay = currentDay + i;
                if (forecastDay >= 7) {
                  forecastDay = forecastDay % 7;
                }
                tvDay.setText(
                    context.getResources()
                        .getStringArray(R.array.weather_day_normalform)[forecastDay]);
                tvLow.setText(infos.get(i).getLow() + mShowTypeOfTemperature[config.getShowType()]);
                tvHigh.setText(
                    infos.get(i).getHigh() + mShowTypeOfTemperature[config.getShowType()]);
                tvWeather.setText(
                    context.getResources()
                        .getStringArray(R.array.weather_condition)[infos.get(i).getCode()]);
                ivWeatherIcon.setImageResource(R.drawable.w0);

                int width = config.getWidth() / config.getForecastDays();
                int height = config.getHeight();
                float wScale = width / 100f;
                float hScale = height / 100f;
                float squarScale = width * height / (100 * 100);

                LayoutParams viewChildParams = (LayoutParams) tvDay.getLayoutParams();
                viewChildParams.height *= hScale;
                viewChildParams.width *= wScale;
                tvDay.setLayoutParams(viewChildParams);

                viewChildParams = (LayoutParams) tvLow.getLayoutParams();
                viewChildParams.height *= hScale;
                viewChildParams.width *= wScale;
                tvLow.setLayoutParams(viewChildParams);
                tvHigh.setLayoutParams(viewChildParams);

                viewChildParams = (LayoutParams) tvWeather.getLayoutParams();
                viewChildParams.height *= hScale;
                viewChildParams.width *= wScale;
                tvWeather.setLayoutParams(viewChildParams);

                viewChildParams = (LayoutParams) ivWeatherIcon.getLayoutParams();
                viewChildParams.height *= hScale;
                viewChildParams.width *= wScale;
                ivWeatherIcon.setLayoutParams(viewChildParams);

                tvDay.setTextSize(DensityUtil.dip2px(context, 14 * squarScale));
                tvLow.setTextSize(DensityUtil.dip2px(context, 14 * squarScale));
                tvHigh.setTextSize(DensityUtil.dip2px(context, 14 * squarScale));
                tvWeather.setTextSize(DensityUtil.dip2px(context, 14 * squarScale));

                LinearLayout.LayoutParams viewParams =
                    new LinearLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
                viewParams.weight = 1;

                mWeatherContainer.addView(view, viewParams);
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
          super.handleMessage(msg);
        }
示例#4
0
  private void addPic(Intent data) {
    if (null != data) {
      Uri selectedImage = data.getData();
      String[] filePathColumn = {MediaStore.Images.Media.DATA};

      Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
      cursor.moveToFirst();

      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
      String picturePath = cursor.getString(columnIndex);
      cursor.close();

      // 获取图片
      BitmapFactory.Options opts = new BitmapFactory.Options();
      opts.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(picturePath, opts);
      opts.inSampleSize = computeSampleSize(opts, -1, 1080 * 700);
      opts.inJustDecodeBounds = false;
      final Bitmap bmp;
      try {
        bmp = BitmapFactory.decodeFile(picturePath, opts);
      } catch (OutOfMemoryError err) {
        showNotification(2, "图片太大!", R.id.root);
        return;
      }
      if (null == picsList) {
        picsList = new ArrayList<Bitmap>(4);
      }
      picsList.add(bmp);

      final ImageView image = new ImageView(PostActivity.this);
      LayoutParams params = (LayoutParams) btn_pic.getLayoutParams();
      params.width = btn_pic.getWidth();
      params.height = btn_pic.getHeight();
      image.setScaleType(ScaleType.CENTER_CROP);
      image.setLayoutParams(params);
      image.setImageBitmap(bmp);
      image.setClickable(true);
      image.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              if (null != mpics && mpics.getChildCount() > 0) {
                mpics.removeView(image);
                picsList.remove(bmp);
                mpics.postInvalidate();
                if (mpics.getChildCount() < 5) {
                  btn_pic.setVisibility(View.VISIBLE);
                }
                return true;
              }
              return false;
            }
          });
      int count = mpics.getChildCount();
      if (4 == count) {
        btn_pic.setVisibility(View.GONE);
      }
      mpics.addView(image, count - 1);
      mpics.postInvalidate();
    }
  }