Exemple #1
0
 @POST
 @Produces(MediaType.APPLICATION_JSON)
 public Response createItem(Item item) {
   Item newItem =
       items.createItem(item.getTitle(), item.getCoorX(), item.getCoorY(), item.getDirection());
   return Response.status(Response.Status.CREATED).entity(newItem).build();
 }
 public void addItem(Item item) {
   int size = icon + padding + padding;
   ViewGroup.LayoutParams params =
       new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, size);
   TextView row = new TextView(getContext());
   row.setId(item.getId());
   row.setLayoutParams(params);
   row.setMaxLines(1);
   row.setEllipsize(TextUtils.TruncateAt.END);
   row.setGravity(Gravity.CENTER_VERTICAL);
   row.setText(item.getTitle());
   row.setTypeface(Typeface.DEFAULT_BOLD);
   row.setOnClickListener(this);
   row.setTextColor(BottomUtils.colorStateListText(getContext()));
   TypedValue typedValue = new TypedValue();
   getContext()
       .getTheme()
       .resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
   row.setBackgroundResource(typedValue.resourceId);
   if (item.getIcon() != null) {
     row.setCompoundDrawablesWithIntrinsicBounds(icon(item.getIcon()), null, null, null);
     row.setCompoundDrawablePadding(padding);
     row.setPadding(padding, padding, padding, padding);
   } else {
     row.setPadding(size, padding, padding, padding);
   }
   container.addView(row);
 }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_item);

        processViews();

        // 取得Intent物件
        Intent intent = getIntent();
        // 讀取Action名稱
        String action = intent.getAction();

        // 如果是修改記事
        if (action.equals("net.macdidi.myandroidtutorial.EDIT_ITEM")) {
            // 接收記事物件與設定標題、內容
            item = (Item) intent.getExtras().getSerializable(
                    "net.macdidi.myandroidtutorial.Item");
            title_text.setText(item.getTitle());
            content_text.setText(item.getContent());
        }
        // 新增記事
        else {
            item = new Item();
        }
    }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_item, container, false);
    mTitle = (EditText) v.findViewById(R.id.item_title);
    mTitle.setText(mItem.getTitle());

    mDetails = (EditText) v.findViewById(R.id.item_details);
    mDetails.setText(mItem.getDetails());

    mDate = (Button) v.findViewById(R.id.item_date);
    mDate.setText(mItem.getLocalizedDate());

    mAutoDelete = (CheckBox) v.findViewById(R.id.item_autodelete);
    mAutoDelete.setChecked(mItem.isAutodelete());

    mCancel = (Button) v.findViewById(R.id.btn_cancel);
    mSave = (Button) v.findViewById(R.id.btn_save);
    mDelete = (Button) v.findViewById(R.id.btn_delete);
    mDelete.setVisibility(mItem.isNew() ? View.GONE : View.VISIBLE);

    mCancel.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mCallbacks.onCancel(mItem);
          }
        });

    mSave.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            saveItem();
            mCallbacks.onSaveItem(mItem);
          }
        });

    mDelete.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            confirmDelete();
          }
        });

    mDate.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            DatePickerFragment f =
                DatePickerFragment.newInstance(mItem.getDate(), ItemFragment.this);
            f.show(getActivity().getSupportFragmentManager(), "datePicker");
          }
        });

    return v;
  }
  private void itemSelected(java.awt.event.MouseEvent evt) { // GEN-FIRST:event_itemSelected
    int currentSelectedItemIndex = itemList.getSelectedIndex();

    if (currentSelectedItemIndex >= 0) {
      Item tmp = listModel.getElementAt(currentSelectedItemIndex);
      itemTitleTextField.setText(tmp.getTitle());
      itemDescriptionTextArea.setText(tmp.getDescription());
      createItemButton.setText("Update");
    }
  } // GEN-LAST:event_itemSelected
  public ArrayList<Feedback> readFeedbacks(long idPost) {
    RssParser parser = null;
    Rss rss = null;
    // System.out.println("right? "+post);
    try {
      parser = RssParserFactory.createDefault();
      rss = parser.parse(new URL(boardAddress + "feedbacks?action=READ&FeedbackName=" + idPost));
    } catch (RssParserException e) {
      System.out.println(boardAddress + "feedbacks?action=READ&FeedbackName=" + idPost);
      System.out.println("RssParserException");
      return null;
    } catch (MalformedURLException e) {
      System.out.println("MalformedURLException");
      return null;
    } catch (IOException e) {
      System.out.println("IOException");
      return null;
    }

    Channel c = rss.getChannel();
    if (c.getItems() == null) {
      System.out.println("Non ci sono Feedback");
      return new ArrayList<Feedback>();
    }
    ArrayList<Item> items = new ArrayList<Item>(c.getItems());
    Iterator<Item> iter = items.iterator();
    ArrayList<Feedback> lista = new ArrayList<Feedback>();
    while (iter.hasNext()) {
      Item x = iter.next();
      String description = "";
      String feed = "";
      Title titolo = Title.AGREE;
      try {
        description = x.getDescription().getText();
      } catch (NullPointerException e) {
      }
      try {
        feed = x.getTitle().getText();
      } catch (NullPointerException e) {
      }
      if (feed != null) {
        if (!feed.isEmpty()) {
          if (feed.equals("AGREE")) titolo = Title.AGREE;
          else if (feed.equals("DISAGREE")) titolo = Title.DISAGREE;
          else if (feed.equals("PARTIALLY_AGREE")) titolo = Title.PARTIALLY_AGREE;
          else if (feed.equals("DETRACTOR")) titolo = Title.DETRACTOR;
          else continue;
        }
      } else continue;
      Date data = getPubDate(x);
      lista.add(new Feedback(description, titolo, data));
    }
    return lista;
  }
Exemple #7
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    Item item = getItem(position);
    if (convertView == null) {
      convertView =
          LayoutInflater.from(getContext()).inflate(R.layout.listitem_item, parent, false);
    }
    TextView tvTitle = (TextView) convertView.findViewById(R.id.LblListItemTitle);
    TextView tvPubDateParsed = (TextView) convertView.findViewById(R.id.LblListItemPubDateParsed);
    // TextView tvDescription = (TextView) convertView.findViewById(R.id.LblListItemDescription);

    tvTitle.setText(item.getTitle());
    tvPubDateParsed.setText(item.getPubDateParsed());
    // tvDescription.setText(item.getDescription());

    new DownloadImageTask((ImageView) convertView.findViewById(R.id.ImgListItemEnclosureUrl))
        .execute(item.getEnclosureUrl());

    return convertView;
  }
  static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {

    // 讀取小工具儲存的記事編號
    long id = ItemAppWidgetConfigureActivity.loadItemPref(context, appWidgetId);
    // 建立小工具畫面元件
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.item_app_widget);
    // 讀取指定編號的記事物件
    ItemDAO itemDAO = new ItemDAO(context.getApplicationContext());
    Item item = itemDAO.get(id);

    // 設定小工具畫面顯示記事標題
    views.setTextViewText(R.id.appwidget_text, item != null ? item.getTitle() : "NA");

    // 點選小工具畫面的記事標題後,啟動記事應用程式
    Intent intent = new Intent(context, MainActivity.class);
    PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0);
    views.setOnClickPendingIntent(R.id.appwidget_text, pending);

    // 更新小工具
    appWidgetManager.updateAppWidget(appWidgetId, views);
  }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View view = convertView;
      Holder holder = null;

      if (view == null) {
        view = View.inflate(RssfeedActivity.this, R.layout.list_item_simple, null);

        holder = new Holder();
        holder.cityTextView = (TextView) view.findViewById(R.id.item);
        view.setTag(holder);
      } else {
        holder = (Holder) view.getTag();
      }

      // Set properties
      Item item = items.get(position);
      holder.cityTextView.setText(item.getTitle());

      return view;
    }
  /** 1行ごとのビューを生成する */
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;

    if (convertView == null) {
      view = _inflater.inflate(R.layout.listrow, null);
    }

    // 現在参照しているリストの位置からItemを取得する
    Item item = this.getItem(position);
    if (item != null) {
      // Itemから必要なデータを取り出し、それぞれTextViewにセット
      String title = item.getTitle();
      _title = (TextView) view.findViewById(R.id.rowitem);
      _title.setText(title);
      String value = item.getValue();
      _value = (TextView) view.findViewById(R.id.rowvalue);
      _value.setText(value);
    }

    return view;
  }
  public void testWrite() throws Exception {
    FileWriter fw = null;
    File outFile = null;

    try {
      outFile = File.createTempFile("FeedTest", "tmp");
      filesToDelete.add(outFile);
      fw = new FileWriter(outFile);
      Feed feed = new Feed(tempFile);
      feed.write(fw);
      fw.close();

      // Feed feed2 = new Feed(outFile);
      assertEquals("CruiseControl Build Results", feed.getTitle());
      assertEquals("http://MyMachine.MyDomain.com/cruisecontrol/", feed.getLink());
      assertEquals(
          "Automated build results for CruiseControl project(s) VERSION_10", feed.getDescription());

      // validate the number of items and the contents of the first item.
      assertEquals(11, feed.getItems().size());
      Item item = (Item) feed.getItems().get(0);
      assertEquals("VERSION_10 build.7 Build Successful", item.getTitle());
      assertEquals(
          "http://MyMachine.MyDomain.com/cruisecontrol/buildresults/"
              + "VERSION_10?log=log20050817084109Lbuild.7",
          item.getLink());
      assertEquals(
          "<em>Build Time:</em> Wed Aug 17 08:41:09 MDT 2005<br/>"
              + "<em>Label:</em> build.7<br/><em>Modifications: </em>1<br/>"
              + "\n<ul><li>//depot/MyProduct/VERSION_10/dev/main/src/datacenter/"
              + "ApplicationServer/PlayTime/default.build"
              + "  by jefferson (deploy the mock object dll)</li></ul>",
          item.getDescription());
    } finally {
      IO.close(fw);
    }
  }
  public void testConstructors() {
    Feed feed = new Feed(tempFile);

    assertEquals("CruiseControl Build Results", feed.getTitle());
    assertEquals("http://MyMachine.MyDomain.com/cruisecontrol/", feed.getLink());
    assertEquals(
        "Automated build results for CruiseControl project(s) VERSION_10", feed.getDescription());

    // validate the number of items and the contents of the first item.
    assertEquals(11, feed.getItems().size());
    Item item = (Item) feed.getItems().get(0);
    assertEquals("VERSION_10 build.7 Build Successful", item.getTitle());
    assertEquals(
        "http://MyMachine.MyDomain.com/cruisecontrol/buildresults/"
            + "VERSION_10?log=log20050817084109Lbuild.7",
        item.getLink());
    assertEquals(
        "<em>Build Time:</em> Wed Aug 17 08:41:09 MDT 2005<br/>"
            + "<em>Label:</em> build.7<br/><em>Modifications: </em>1<br/>"
            + "\n<ul><li>//depot/MyProduct/VERSION_10/dev/main/src/datacenter/"
            + "ApplicationServer/PlayTime/default.build"
            + "  by jefferson (deploy the mock object dll)</li></ul>",
        item.getDescription());
  }
  @Override
  public int compare(Item o1, Item o2) {
    int c = Double.compare(o1.getCost(), o2.getCost());

    return c != 0 ? c : o1.getTitle().compareTo(o2.getTitle());
  }
Exemple #14
0
  public ArrayList<Post> readPosts(boolean advanced) {
    RssParser parser = null;
    Rss rss = null;
    try {
      parser = RssParserFactory.createDefault();
      System.out.println(boardAddress);
      rss = parser.parse(new URL(boardAddress + "postboard?action=READ"));

    } catch (RssParserException e) {
      System.out.println("RssParserException");
      return null;
    } catch (MalformedURLException e) {
      System.out.println("MalformedURLException");
      return null;
    } catch (IOException e) {
      System.out.println("IOException");
      return null;
    }
    Channel c = rss.getChannel();
    if (c.getItems() == null) {
      System.out.println("Non ci sono Post");
      return new ArrayList<Post>();
    }
    ArrayList<Item> items = new ArrayList<Item>(c.getItems());
    Iterator<Item> iter = items.iterator();
    ArrayList<Post> res = new ArrayList<Post>();
    while (iter.hasNext()) {
      Item i = (Item) iter.next();
      if (advanced) if ((!bannished.equals("")) && (i.getText().indexOf(bannished) != -1)) continue;
      long id = getFeedbackName(i); // id sempre presente
      String titolo = "";
      String link = "";
      String description = "";
      ArrayList<String> categories = new ArrayList<String>();
      String enclosure = "";
      String source = "";
      Date date = getPubDate(i); // data sempre presente
      try {
        titolo = i.getTitle().getText();
      } catch (NullPointerException e) {
      }
      try {
        link = i.getLink().getText();
      } catch (NullPointerException e) {
      }
      try {
        description = i.getDescription().getText();
      } catch (NullPointerException e) {
      }
      try {
        categories = getCategories(i);
      } catch (NullPointerException e) {
      }
      try {
        enclosure = i.getEnclosure().getText();
      } catch (NullPointerException e) {
      }
      try {
        source = i.getSource().getText();
      } catch (NullPointerException e) {
      }
      if (advanced) if (!(match(categories) && timestamp.before(date))) continue;
      Post p =
          new Post(
              id,
              titolo,
              link,
              description,
              "",
              categories,
              enclosure,
              source,
              date,
              readFeedbacks(id));
      res.add(p);
    }
    if (advanced) if (res.size() > 0) timestamp = res.get(res.size() - 1).getPubDate();
    return res;
  }
  public void drawItem(final Canvas c, final MapView osmv, Item item) {
    Drawable markerFocusedBase = item.getMarker(OverlayItem.ITEM_STATE_FOCUSED_MASK);
    if (markerFocusedBase == null) {
      markerFocusedBase = this.mMarkerFocusedBase;
    }

    /* Calculate and set the bounds of the marker. */
    osmv.getProjection().toPixels(item.getPoint(), mFocusedScreenCoords);

    markerFocusedBase.copyBounds(mRect);
    mRect.offset(mFocusedScreenCoords.x, mFocusedScreenCoords.y);

    /* Strings of the OverlayItem, we need. */
    final String itemTitle = (item.getTitle() == null) ? UNKNOWN : item.getTitle();
    final String itemDescription = (item.getSnippet() == null) ? UNKNOWN : item.getSnippet();

    /*
     * Store the width needed for each char in the description to a float array. This is pretty
     * efficient.
     */
    final float[] widths = new float[itemDescription.length()];
    this.descriptionPaint.getTextWidths(itemDescription, widths);

    final StringBuilder sb = new StringBuilder();
    int maxWidth = 0;
    int curLineWidth = 0;
    int lastStop = 0;
    int i;
    int lastwhitespace = 0;
    /*
     * Loop through the charwidth array and harshly insert a linebreak, when the width gets
     * bigger than DESCRIPTION_MAXWIDTH.
     */
    for (i = 0; i < widths.length; i++) {
      if (!Character.isLetter(itemDescription.charAt(i))) {
        lastwhitespace = i;
      }

      final float charwidth = widths[i];

      if (curLineWidth + charwidth > DESCRIPTION_MAXWIDTH) {
        if (lastStop == lastwhitespace) {
          i--;
        } else {
          i = lastwhitespace;
        }

        sb.append(itemDescription.subSequence(lastStop, i));
        sb.append('\n');

        lastStop = i;
        maxWidth = Math.max(maxWidth, curLineWidth);
        curLineWidth = 0;
      }

      curLineWidth += charwidth;
    }
    /* Add the last line to the rest to the buffer. */
    if (i != lastStop) {
      final String rest = itemDescription.substring(lastStop, i);
      maxWidth = Math.max(maxWidth, (int) this.descriptionPaint.measureText(rest));
      sb.append(rest);
    }
    final String[] lines = sb.toString().split("\n");

    /*
     * The title also needs to be taken into consideration for the width calculation.
     */
    final int titleWidth = (int) this.descriptionPaint.measureText(itemTitle);

    maxWidth = Math.max(maxWidth, titleWidth);
    final int descWidth = Math.min(maxWidth, DESCRIPTION_MAXWIDTH);

    /* Calculate the bounds of the Description box that needs to be drawn. */
    final int descBoxLeft =
        mRect.left - descWidth / 2 - DESCRIPTION_BOX_PADDING + mRect.width() / 2;
    final int descBoxRight = descBoxLeft + descWidth + 2 * DESCRIPTION_BOX_PADDING;
    final int descBoxBottom = mRect.top;
    final int descBoxTop =
        descBoxBottom
            - DESCRIPTION_TITLE_EXTRA_LINE_HEIGHT
            - (lines.length + 1) * DESCRIPTION_LINE_HEIGHT /* +1 because of the title. */
            - 2 * DESCRIPTION_BOX_PADDING;

    /* Twice draw a RoundRect, once in black with 1px as a small border. */
    this.mMarkerBackgroundPaint.setColor(Color.BLACK);
    c.drawRoundRect(
        new RectF(descBoxLeft - 1, descBoxTop - 1, descBoxRight + 1, descBoxBottom + 1),
        DESCRIPTION_BOX_CORNERWIDTH,
        DESCRIPTION_BOX_CORNERWIDTH,
        this.descriptionPaint);
    this.mMarkerBackgroundPaint.setColor(this.mMarkerFocusedBackgroundColor);
    c.drawRoundRect(
        new RectF(descBoxLeft, descBoxTop, descBoxRight, descBoxBottom),
        DESCRIPTION_BOX_CORNERWIDTH,
        DESCRIPTION_BOX_CORNERWIDTH,
        this.mMarkerBackgroundPaint);

    final int descLeft = descBoxLeft + DESCRIPTION_BOX_PADDING;
    int descTextLineBottom = descBoxBottom - DESCRIPTION_BOX_PADDING;

    /* Draw all the lines of the description. */
    for (int j = lines.length - 1; j >= 0; j--) {
      c.drawText(lines[j].trim(), descLeft, descTextLineBottom, this.descriptionPaint);
      descTextLineBottom -= DESCRIPTION_LINE_HEIGHT;
    }
    /* Draw the title. */
    c.drawText(
        itemTitle,
        descLeft,
        descTextLineBottom - DESCRIPTION_TITLE_EXTRA_LINE_HEIGHT,
        this.titlePaint);
    c.drawLine(descBoxLeft, descTextLineBottom, descBoxRight, descTextLineBottom, descriptionPaint);

    /*
     * Finally draw the marker base. This is done in the end to make it look better.
     */
    Overlay.drawAt(
        c, markerFocusedBase, mFocusedScreenCoords.x, mFocusedScreenCoords.y, false, 0.0f);
  }
 public void setData(Item item) {
   this.item = item;
   imageView.setImageResource(item.getDrawableResource());
   textView.setText(item.getTitle());
 }