Esempio n. 1
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_message);
   mQRCodeImage = (ImageView) findViewById(R.id.qrcode_image);
   final WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
   final Display display = manager.getDefaultDisplay();
   Point displaySize = new Point();
   display.getSize(displaySize);
   final int width = displaySize.x;
   final int height = displaySize.y;
   final int dimension = width < height ? width : height;
   mEncoder =
       new QRCodeEncode.Builder()
           .setBackgroundColor(0xFFFFFF)
           .setCodeColor(0XFF3F51B5)
           .setOutputBitmapPadding(2)
           .setOutputBitmapWidth(dimension)
           .setOutputBitmapHeight(dimension)
           .build();
   mDecodeTask = new DecodeTask();
   if (SpUtils.contains(this, "name")) {
     sendMessage();
   } else {
     Toast.makeText(this, "未输入名字", Toast.LENGTH_SHORT).show();
     View view = View.inflate(this, R.layout.input_time, null);
     EditText editText = (EditText) view.findViewById(R.id.input_name);
     materialDialog =
         new MaterialDialog(this)
             .setTitle("设定名字")
             .setContentView(view)
             .setPositiveButton(
                 "确定",
                 v -> {
                   if (!editText.getText().toString().equals("")) {
                     SpUtils.put(this, "name", editText.getText().toString());
                     Toast.makeText(
                             this, "设定名字为" + editText.getText().toString(), Toast.LENGTH_SHORT)
                         .show();
                   }
                   materialDialog.dismiss();
                 });
     materialDialog.show();
   }
   findViewById(R.id.button_start).setOnClickListener(this);
   findViewById(R.id.button_share).setOnClickListener(this);
 }
Esempio n. 2
0
  private void sendMessage() {
    Draw draw = new Draw((String) SpUtils.get(this, "name", "ha"), "", true);
    draw.save(
        this,
        new SaveListener() {
          @Override
          public void onSuccess() {
            Log.e("message", "success");
            Toast.makeText(MessageActivity.this, "新建行成功", Toast.LENGTH_SHORT).show();
            SpUtils.put(MessageActivity.this, "key", draw.getObjectId());
            key = draw.getObjectId();
            Log.e("key", key);
            open = true;
            if (key != null) mDecodeTask.execute("key:" + key);
          }

          @Override
          public void onFailure(int i, String s) {
            if (SpUtils.contains(MessageActivity.this, "key")) {
              mDecodeTask.execute("key:" + SpUtils.get(MessageActivity.this, "key", "defaultkey"));
            }
          }
        });
  }