コード例 #1
0
ファイル: Ticket.java プロジェクト: irhabi/eclipse
  public Ticket(String name, Double cena) {
    this.name = name;
    this.cena = cena;

    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
    Date aktDate = new Date();
    aktDate.setHours(aktDate.getHours() - 2);
    aktDate.setMinutes(aktDate.getMinutes() - 15);
    this.zakupiony = sdf.format(aktDate);
    Date waznyDo = aktDate;
    waznyDo.setHours(waznyDo.getHours() + 24);
    this.wazny = sdf.format(waznyDo);
    Random r = new Random();
    this.nrKontrolny = this.nrKontrolny + String.format("%03d%n", r.nextInt(999)).trim();
    this.nrTrn = this.nrTrn + this.nrTrnMod + String.format("%03d%n", r.nextInt(999)).trim();

    this.url = this.url + getNrTrn();

    /* utworzenie QR Code i konwersja do bitmapy */
    QRCodeEncoder qrCodeEncoder =
        new QRCodeEncoder(url, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), 600);
    try {
      this.bitmap = qrCodeEncoder.encodeAsBitmap();
    } catch (WriterException e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
 private void generateQR(String userKey) {
   String qrData = "tox://" + userKey;
   int qrCodeSize = 400;
   QRCodeEncode qrCodeEncoder =
       new QRCodeEncode(
           qrData, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeSize);
   FileOutputStream out;
   try {
     Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
     out =
         new FileOutputStream(
             Environment.getExternalStorageDirectory().getPath()
                 + "/Antox/"
                 + friendName
                 + ".png");
     bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
     out.close();
   } catch (WriterException e) {
     e.printStackTrace();
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
コード例 #3
0
ファイル: GetFragment.java プロジェクト: Neuschi/Master
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_get, container, false);

    // set qr
    ImageView imageView = (ImageView) rootView.findViewById(R.id.qrcode_show);

    String qrData = User.adresse + "-=" + "0";

    int qrCodeDimention = 500;

    QRCodeEncoder qrCodeEncoder =
        new QRCodeEncoder(
            qrData, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimention);

    int color1 = Color.parseColor("#000000");
    int color2 = Color.parseColor("#951F40");

    try {
      Bitmap bm = replaceColor(qrCodeEncoder.encodeAsBitmap(), color1, color2);
      imageView.setImageBitmap(bm);
    } catch (WriterException e) {
      e.printStackTrace();
    }
    //		try {
    //			Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
    //			imageView.setImageBitmap(bitmap);
    //		} catch (WriterException e) {
    //			e.printStackTrace();
    //		}

    // Button

    Button gen = (Button) rootView.findViewById(R.id.Button_gen);
    gen.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            updateQR();
          }
        });

    EditText etb = (EditText) rootView.findViewById(R.id.betrag_et);
    etb.clearComposingText();
    etb.setHint("0.00");

    // button
    // Button cb = (Button) rootView.findViewById(R.id.Button_betrag);
    // cb.setOnClickListener(new View.OnClickListener() {
    // @Override
    // public void onClick(View v) {
    // updateDetail();
    // }
    // });

    return rootView;
  }
コード例 #4
0
ファイル: ShareActivity.java プロジェクト: linxuping/qrcode
 private void launchSearch(String text) {
   Intent intent = new Intent(Intents.Encode.ACTION);
   intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
   intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
   intent.putExtra(Intents.Encode.DATA, text);
   intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());
   startActivity(intent);
 }
コード例 #5
0
ファイル: ShareActivity.java プロジェクト: linxuping/qrcode
 private void showTextAsBarcode(String text) {
   Log.i(TAG, "Showing text as barcode: " + text);
   if (text == null) {
     return; // Show error?
   }
   Intent intent = new Intent(Intents.Encode.ACTION);
   intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
   intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
   intent.putExtra(Intents.Encode.DATA, text);
   intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());
   startActivity(intent);
 }
コード例 #6
0
ファイル: GetFragment.java プロジェクト: Neuschi/Master
  public void updateQR() {
    View v = getView();
    DecimalFormat f = new DecimalFormat("#0.00");
    EditText etb = (EditText) v.findViewById(R.id.betrag_et);
    TextView btv = (TextView) v.findViewById(R.id.hint_tv);
    String value = "0.00";
    value = etb.getText().toString();
    ImageView imageView = (ImageView) getView().findViewById(R.id.qrcode_show);

    String qrData = User.adresse + "-=" + value;

    double c = 0.0;

    c = Double.valueOf(value);
    String showv = (f.format(c) + " €");
    if (!(c == 0)) {
      // btv.setText(value + " €");
      btv.setText(showv);
    } else {
      btv.setText("Der Zahlende kann nun den Betrag angeben.");
    }

    int qrCodeDimention = 500;

    QRCodeEncoder qrCodeEncoder =
        new QRCodeEncoder(
            qrData, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimention);

    int color1 = Color.parseColor("#000000");
    int color2 = Color.parseColor("#951F40");

    try {
      Bitmap bm = replaceColor(qrCodeEncoder.encodeAsBitmap(), color1, color2);
      imageView.setImageBitmap(bm);
    } catch (WriterException e) {
      e.printStackTrace();
    }

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    Date myDate = new Date();
    User.guthaben += c;
    Transactions.sum[Transactions.i] = String.valueOf(c);
    Transactions.adresse[Transactions.i] = "no adress";
    Transactions.date[Transactions.i] = sdf.format(myDate.getTime());
    Transactions.i = Transactions.i + 1;

    //			try {
    //				Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
    //				imageView.setImageBitmap(bitmap);
    //			} catch (WriterException e) {
    //				e.printStackTrace();
    //			}
  }
コード例 #7
0
  @Override
  protected void afterViews() {
    txvNomeEvento.setText("Bruno e Barreto");
    txvDataEvento.setText(TreatDate.formatString("dd/MM/yyyy", new Date()));
    txvLocalEvento.setText("Santarena");

    // ImageView to display the QR code in.  This should be defined in
    // your Activity's XML layout file
    ImageView imageView = (ImageView) findViewById(R.id.img_qrcode);

    String qrData = "Data I want to encode in QR code";
    int qrCodeDimention = 500;

    QRCodeEncoder qrCodeEncoder =
        new QRCodeEncoder(
            qrData, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimention);

    try {
      Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
      imageView.setImageBitmap(bitmap);
    } catch (WriterException e) {
      e.printStackTrace();
    }
  }
コード例 #8
0
ファイル: ShareActivity.java プロジェクト: linxuping/qrcode
  /**
   * Takes a contact Uri and does the necessary database lookups to retrieve that person's info,
   * then sends an Encode intent to render it as a QR Code.
   *
   * @param contactUri A Uri of the form content://contacts/people/17
   */
  private void showContactAsBarcode(Uri contactUri) {
    Log.i(TAG, "Showing contact URI as barcode: " + contactUri);
    if (contactUri == null) {
      return; // Show error?
    }
    ContentResolver resolver = getContentResolver();

    Cursor cursor;
    try {
      // We're seeing about six reports a week of this exception although I don't understand why.
      cursor = resolver.query(contactUri, null, null, null, null);
    } catch (IllegalArgumentException ignored) {
      return;
    }
    if (cursor == null) {
      return;
    }

    String id;
    String name;
    boolean hasPhone;
    try {
      if (!cursor.moveToFirst()) {
        return;
      }

      id = cursor.getString(cursor.getColumnIndex(BaseColumns._ID));
      name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
      hasPhone =
          cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0;

    } finally {
      cursor.close();
    }

    // Don't require a name to be present, this contact might be just a phone number.
    Bundle bundle = new Bundle();
    if (name != null && name.length() > 0) {
      bundle.putString(ContactsContract.Intents.Insert.NAME, massageContactData(name));
    }

    if (hasPhone) {
      Cursor phonesCursor =
          resolver.query(
              ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
              null,
              ContactsContract.CommonDataKinds.Phone.CONTACT_ID + '=' + id,
              null,
              null);
      if (phonesCursor != null) {
        try {
          int foundPhone = 0;
          int phonesNumberColumn =
              phonesCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
          while (phonesCursor.moveToNext() && foundPhone < Contents.PHONE_KEYS.length) {
            String number = phonesCursor.getString(phonesNumberColumn);
            if (number != null && number.length() > 0) {
              bundle.putString(Contents.PHONE_KEYS[foundPhone], massageContactData(number));
            }
            foundPhone++;
          }
        } finally {
          phonesCursor.close();
        }
      }
    }

    Cursor methodsCursor =
        resolver.query(
            ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI,
            null,
            ContactsContract.CommonDataKinds.StructuredPostal.CONTACT_ID + '=' + id,
            null,
            null);
    if (methodsCursor != null) {
      try {
        if (methodsCursor.moveToNext()) {
          String data =
              methodsCursor.getString(
                  methodsCursor.getColumnIndex(
                      ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS));
          if (data != null && data.length() > 0) {
            bundle.putString(ContactsContract.Intents.Insert.POSTAL, massageContactData(data));
          }
        }
      } finally {
        methodsCursor.close();
      }
    }

    Cursor emailCursor =
        resolver.query(
            ContactsContract.CommonDataKinds.Email.CONTENT_URI,
            null,
            ContactsContract.CommonDataKinds.Email.CONTACT_ID + '=' + id,
            null,
            null);
    if (emailCursor != null) {
      try {
        int foundEmail = 0;
        int emailColumn = emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA);
        while (emailCursor.moveToNext() && foundEmail < Contents.EMAIL_KEYS.length) {
          String email = emailCursor.getString(emailColumn);
          if (email != null && email.length() > 0) {
            bundle.putString(Contents.EMAIL_KEYS[foundEmail], massageContactData(email));
          }
          foundEmail++;
        }
      } finally {
        emailCursor.close();
      }
    }

    Intent intent = new Intent(Intents.Encode.ACTION);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra(Intents.Encode.TYPE, Contents.Type.CONTACT);
    intent.putExtra(Intents.Encode.DATA, bundle);
    intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());

    Log.i(TAG, "Sending bundle for encoding: " + bundle);
    startActivity(intent);
  }