Ejemplo n.º 1
0
  private void processUserVariables() {
    mSwipeRefreshLayout.setRefreshing(true);

    mDomoticz.getUserVariables(
        new UserVariablesReceiver() {
          @Override
          public void onReceiveUserVariables(ArrayList<UserVariableInfo> mVarInfos) {
            UserVariables.this.mUserVariableInfos = mVarInfos;
            successHandling(mUserVariableInfos.toString(), false);
            adapter = new UserVariablesAdapter(mContext, mUserVariableInfos);
            createListView();
          }

          @Override
          public void onError(Exception error) {
            errorHandling(error);
          }
        });
  }
Ejemplo n.º 2
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    int layoutResourceId;

    WeatherInfo mWeatherInfo = filteredData.get(position);

    // if (convertView == null) {
    holder = new ViewHolder();

    layoutResourceId = R.layout.weather_row_default;
    LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    convertView = inflater.inflate(layoutResourceId, parent, false);

    holder.isProtected = mWeatherInfo.isProtected();
    holder.name = (TextView) convertView.findViewById(R.id.weather_name);
    holder.iconRow = (ImageView) convertView.findViewById(R.id.rowIcon);
    holder.data = (TextView) convertView.findViewById(R.id.weather_data);
    holder.hardware = (TextView) convertView.findViewById(R.id.weather_hardware);
    holder.dayButton = (Button) convertView.findViewById(R.id.day_button);
    holder.monthButton = (Button) convertView.findViewById(R.id.month_button);
    holder.yearButton = (Button) convertView.findViewById(R.id.year_button);

    holder.name.setText(mWeatherInfo.getName());
    holder.hardware.append(mWeatherInfo.getHardwareName());

    holder.data.setEllipsize(TextUtils.TruncateAt.END);
    holder.data.setMaxLines(3);
    holder.data.append(mWeatherInfo.getData());

    if (!UsefulBits.isEmpty(mWeatherInfo.getRain()))
      holder.data.setText(context.getString(R.string.rain) + ": " + mWeatherInfo.getRain());
    if (!UsefulBits.isEmpty(mWeatherInfo.getRainRate()))
      holder.data.append(
          ", " + context.getString(R.string.rainrate) + ": " + mWeatherInfo.getRainRate());

    if (!UsefulBits.isEmpty(mWeatherInfo.getForecastStr()))
      holder.data.append(", " + mWeatherInfo.getForecastStr());
    if (!UsefulBits.isEmpty(mWeatherInfo.getSpeed()))
      holder.data.append(", " + context.getString(R.string.speed) + ": " + mWeatherInfo.getSpeed());
    if (mWeatherInfo.getDewPoint() > 0)
      holder.data.append(
          ", " + context.getString(R.string.dewPoint) + ": " + mWeatherInfo.getDewPoint());
    if (mWeatherInfo.getTemp() > 0)
      holder.data.append(", " + context.getString(R.string.temp) + ": " + mWeatherInfo.getTemp());
    if (mWeatherInfo.getBarometer() > 0)
      holder.data.append(
          ", " + context.getString(R.string.pressure) + ": " + mWeatherInfo.getBarometer());
    if (!UsefulBits.isEmpty(mWeatherInfo.getChill()))
      holder.data.append(", " + context.getString(R.string.chill) + ": " + mWeatherInfo.getChill());
    if (!UsefulBits.isEmpty(mWeatherInfo.getDirectionStr()))
      holder.data.append(
          ", " + context.getString(R.string.direction) + ": " + mWeatherInfo.getDirectionStr());
    if (!UsefulBits.isEmpty(mWeatherInfo.getHumidityStatus()))
      holder.data.append(
          ", " + context.getString(R.string.humidity) + ": " + mWeatherInfo.getHumidityStatus());

    holder.dayButton.setId(mWeatherInfo.getIdx());
    holder.dayButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            for (WeatherInfo t : filteredData) {
              if (t.getIdx() == v.getId()) listener.onLogClick(t, Domoticz.Graph.Range.DAY);
            }
          }
        });

    holder.monthButton.setId(mWeatherInfo.getIdx());
    holder.monthButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            for (WeatherInfo t : filteredData) {
              if (t.getIdx() == v.getId()) listener.onLogClick(t, Domoticz.Graph.Range.MONTH);
            }
          }
        });

    holder.yearButton.setId(mWeatherInfo.getIdx());
    holder.yearButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            for (WeatherInfo t : filteredData) {
              if (t.getIdx() == v.getId()) listener.onLogClick(t, Domoticz.Graph.Range.YEAR);
            }
          }
        });

    convertView.setTag(holder);
    Picasso.with(context)
        .load(
            domoticz.getDrawableIcon(
                mWeatherInfo.getTypeImg(), mWeatherInfo.getType(), null, false, false, null))
        .into(holder.iconRow);
    return convertView;
  }