Esempio n. 1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TextView mTextView = new TextView(this);
    People mPerson = (People) getIntent().getSerializableExtra(ObjectTranDemo.SER_KEY);
    mTextView.setText(
        "You name is: " + mPerson.getName() + "/n" + "You age is: " + mPerson.getAge());

    setContentView(mTextView);
  }
  @Override
  public String toString() {

    for (int i = 0; i < people.getLength(); i++) {
      People cur = people.get(i);
      System.out.print(cur.getName() + " --> ");
      for (int j = 0; j < cur.getFriends().getLength(); j++) {
        System.out.print(cur.getFriends().get(j) + " ");
      }
      System.out.println();
    }

    return super.toString();
  }
 private void send() {
   SmsManager smsManager = SmsManager.getDefault();
   for (People p : this.myCircle.getEverybody()) {
     smsManager.sendTextMessage(
         p.getPhoneNumber(),
         null,
         "Cette année "
             + p.getName()
             + ", tu dois offrir un cadeau à... "
             + p.getOfferTo().getName()
             + "!",
         null,
         null);
   }
 }
Esempio n. 4
0
  public static void main(String[] args) throws ClassNotFoundException {
    // Получение объекта типа Class
    People people = new People();
    Class myClass = people.getClass();
    System.out.println("myClass = " + myClass);
    // Если у нас есть класс, для которого в момент компиляции известен тип, то получить экземпляр
    // класса ещё проще.
    Class myClass1 = People.class;
    System.out.println("myClass1 = " + myClass1);
    // Если имя класса не известно в момент компиляции, но становится известным во время выполнения
    // программы,
    // можно использовать метод forName(), чтобы получить объект Class.
    Class c = Class.forName("DZ_14.reflection_Test.Razbor.People");
    System.out.println("c = " + c);
    // Получение пакета
    Package p = People.class.getPackage();
    System.out.println("package " + p.getName() + ";");
    // Выводим интерфейсы, которые реализует класс
    Class[] interfaces = myClass.getInterfaces();
    for (int i = 0, size = interfaces.length; i < size; i++) {
      System.out.print(i == 0 ? "implements " : ", ");
      System.out.print(interfaces[i].getSimpleName());
    }
    System.out.println(" {");
    // Выводим поля класса
    Field[] fields = People.class.getDeclaredFields();
    for (Field field : fields) {
      System.out.println(
          "\t" + field.getModifiers() + field.getType() + " " + field.getName() + ";");
    }
    // Выводим методы, аннотации класса
    Method[] methods = People.class.getDeclaredMethods();
    for (Method m : methods) {
      Annotation[] annotations = m.getAnnotations();
      System.out.print("\t");
      for (Annotation a : annotations)
        System.out.print("@" + a.annotationType().getSimpleName() + " ");
      System.out.println();

      System.out.print(
          "\t" + m.getModifiers() + getType(m.getReturnType()) + " " + m.getName() + "(");
      System.out.print(m.getParameters());
      System.out.println(") { }");
    }
  }
Esempio n. 5
0
 @PrePersist
 // Executa algum código antes da persistencia do  objeto no banco de dados
 // Pode ser utilizado para fazer validações por exemplo.
 public void PrePersist(People pl) {
   if (pl.getAge() < 18) {
     throw new IllegalAccessError(
         "Idade menor que 18 anos!"); // Executa uma exceção e executa um ROLLBACK na persistencia
   } else {
     System.out.println("Persistencia permitida!");
   }
 }
Esempio n. 6
0
  public View getView(int position, View convertView, ViewGroup parent) {

    People people = (People) getItem(position);
    ViewHolder holder;
    if (convertView == null) {
      holder = new ViewHolder();
      convertView = mLayoutInflater.inflate(R.layout.item, null);
      holder.hotelImage = (ImageView) convertView.findViewById(R.id.avatar);
      holder.hotelName = (TextView) convertView.findViewById(R.id.name);
      holder.hotelId = (TextView) convertView.findViewById(R.id.id);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }
    holder.hotelName.setText(people.getName());
    holder.hotelId.setText(people.getId());

    try {
      Picasso.with(mContext).load(people.getAvatar()).resize(100, 100).into(holder.hotelImage);
    } catch (Exception e) {
      Log.d("PARSE", e.toString());
    }
    return convertView;
  }
Esempio n. 7
0
 @PostUpdate
 // Executa algum código depois da atualização do objeto no banco de dados
 // Funciona também com o State Detected.
 public void PostUpdate(People pl) {
   System.out.println(pl.getName() + " Atualizado com sucesso!");
 }
Esempio n. 8
0
 @PreUpdate
 // Executa algum código antes da atualização do objeto no banco de dados
 // Funciona também com o State Detected.
 public void PreUpdate(People pl) {
   System.out.println(pl.getName() + " Será atualizado agora!");
 }
Esempio n. 9
0
 @PostPersist
 // Executa algum código depos da persistencia do  objeto no banco de dados
 // Pode ser utilizado para fazer validações por exemplo.
 public void PostPersist(People pl) {
   System.out.println(pl.getName() + " persistido com sucesso!");
 }
Esempio n. 10
0
 /** Does this {@link View} has any associated user information recorded? */
 public final boolean hasPeople() {
   return People.isApplicable(getItems());
 }
  private void mySQLite() {
    // TODO Auto-generated method stub

    Log.i("check", "b1");
    mySQLiteOpenHelper helper = new mySQLiteOpenHelper(con, "mylist");
    SQLiteDatabase db = helper.getReadableDatabase();
    Log.i("check", "b2");
    // 查询数据库里的数据
    Cursor cursor =
        db.query("mylist", new String[] {"name", "number"}, null, null, null, null, null);
    Log.i("check", "b22");
    list = new ArrayList<Map<String, Object>>();
    Log.i("check", "b23");

    while (cursor.moveToNext()) {
      People modle = new People();
      map = new HashMap<String, Object>();
      map.put("name", modle.setName(cursor.getString(cursor.getColumnIndex("name"))).toString());
      map.put(
          "number", modle.setNumber(cursor.getString(cursor.getColumnIndex("number"))).toString());
      list.add(map);
    }
    Log.i("check", "b3");
    adapter =
        new MYSimpleAdapter(
            Lab08Activity.this,
            list,
            R.layout.main,
            new String[] {"name", "number"},
            new int[] {R.id.name, R.id.number});
    listView.setAdapter(adapter);
    db.close();

    listView.setOnItemClickListener(
        new OnItemClickListener() {

          public void onItemClick(AdapterView<?> arg0, View arg1, int positon, long arg3) {
            // TODO Auto-generated method stub
            Intent intent = new Intent();
            intent.setClass(Lab08Activity.this, Edit.class);
            Bundle bundle = new Bundle();
            // 这个地方通过名字传值来判断数据的话其实不太好,大家可以通过ID     //来判断是哪条数据的,这里传值是为了另一个类中需要删除数据
            bundle.putString("name", list.get(positon).get("name").toString());
            bundle.putString("number", list.get(positon).get("number").toString());
            intent.putExtras(bundle);
            intent.setClass(Lab08Activity.this, Edit.class);
            startActivity(intent);
          }
        });

    listView.setOnItemLongClickListener(
        new OnItemLongClickListener() {

          public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub
            String dName = list.get(arg2).get("name").toString();
            String dNumber = list.get(arg2).get("number").toString();

            mySQLiteOpenHelper helper = new mySQLiteOpenHelper(Lab08Activity.this, "mylist");
            SQLiteDatabase db = helper.getWritableDatabase();

            Cursor cursor =
                db.query(
                    "mylist",
                    new String[] {"name", "number"},
                    "name=?",
                    new String[] {dName},
                    null,
                    null,
                    null);
            db.delete("mylist", "name=?", new String[] {dName});
            list.remove(arg2);
            db.close();
            adapter.notifyDataSetChanged();
            return true;
          }
        });
  }
Esempio n. 12
0
 public People getOwner() {
   People result = new People(bookOwner);
   result.setPassword("");
   return result;
 }
Esempio n. 13
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;

    g2d.drawImage(this.imageBackground, 0, 0, null);
    g2d.drawImage(this.imageTower, 0, 0, null);

    for (int i = 0; i < this.imagesFloors.length; i++) {
      g2d.drawImage(this.imagesFloors[i], 273, 133 + i * this.imageFloorHeight, null);
    }
    for (int i = 0; i < this.people.length; i++) {
      if (this.people[i] != null) {
        People p = this.people[i];
        p.paintComponent(g2d, 273 + p.getPosition(), 171 + i * this.imageFloorHeight, null);
      }
    }

    g2d.drawImage(this.imageLiftBack, this.getCabX(), this.getCabY(), null);
    g2d.drawImage(
        this.imageLiftLeftDoor, this.getCabX() - this.doorsOverture, this.getCabY(), null);
    g2d.drawImage(
        this.imageLiftRightDoor, this.getCabX() + this.doorsOverture, this.getCabY(), null);
    g2d.drawImage(this.imageLiftFront, this.getCabX(), this.getCabY(), null);

    g2d.drawImage(this.imageCane, 240, 7, null);
    g2d.drawImage(this.imageBottom, 212, 917, null);

    /*
     * Old horrible graphics, new fancy graphics are more awsome !
     *
    //Background
    super.paintComponent(g);

    //Calculus for placing draws
    int width = this.getWidth() - 1;
    int height = this.getHeight() - 1;
    int interFloorPadding = 10;

    //Cab
    int cabX = 4 ;
    int cabY = (int) ((float) ((LiftPanel.NB_FLOORS - 1) * height / LiftPanel.NB_FLOORS) * (1 - (float) this.posX / ((float) LiftPanel.MAX_POS_X))) + interFloorPadding;
    int cabWidth = width - 8;
    int cabHeight = (height / LiftPanel.NB_FLOORS) - (2 * interFloorPadding);

    g.setColor(Color.getHSBColor(0f, 0f, .9f));
    g.fillRect(cabX, cabY, cabWidth, cabHeight);
    g.setColor(Color.BLACK);
    g.drawRect(cabX, cabY, cabWidth, cabHeight);

    //Vertical guide
    g.setColor(Color.BLACK);
    g.drawLine(0, 0, 0, height);
    g.drawLine(width, 0, width, height);

    //Cab doors
    int doorPadding = 2;
    float doorOpeningPercent = 1f - (float) this.doorsOverture / ((float) LiftPanel.MAX_DOORS_OPENING);
    int doorWidth = (width - 12) / 2 - (doorPadding + doorPadding / 2);
    int doorWidthWithOpening = (int) ((float) (doorWidth * doorOpeningPercent));
    int doorHeight = height / LiftPanel.NB_FLOORS - 2 - (2 * doorPadding) - (2 * interFloorPadding);
    int leftDoorX = 6 + doorPadding;
    int leftDoorXWithOpening = leftDoorX;
    int rightDoorX = doorWidth + 7 + (width - 12) / 2 + (doorPadding / 2);
    int rightDoorXWithOpening = rightDoorX - doorWidthWithOpening;
    int doorY = cabY + 1 + doorPadding;

    g.setColor(Color.LIGHT_GRAY);
    g.fillRect(leftDoorXWithOpening, doorY, doorWidthWithOpening, doorHeight);
    g.fillRect(rightDoorXWithOpening, doorY, doorWidthWithOpening, doorHeight);
    g.setColor(Color.BLACK);
    g.drawRect(leftDoorXWithOpening, doorY, doorWidthWithOpening, doorHeight);
    g.drawRect(rightDoorXWithOpening, doorY, doorWidthWithOpening, doorHeight);

    //Interfloor blocs
    int blockWidth = width - 1;
    int blockHeight = interFloorPadding;
    int blockX = 1;
    int blockY = 3 - (interFloorPadding / 2);

    g.setColor(Color.DARK_GRAY);
    for (int i = 0; i <= LiftPanel.NB_FLOORS; i++) {
        g.fillRect(blockX, i * (height / LiftPanel.NB_FLOORS) + blockY, blockWidth, blockHeight);
    }
    */
  }
 @MyTest
 public void testName() {
   MyAssert.myAssertEquals("name1", people.getName());
 }
 @MyTest
 public void testAge() {
   // actual age is 30
   MyAssert.myAssertEquals(10, people.getAge());
 }
 public void addPeople(People p) {
   peopleTree.add(p.getName(), people.getLength());
   people.add(p);
 }