Example #1
0
 private void showConfirmSendMessage() {
   final MaterialDialog materialDialog = new MaterialDialog(this);
   materialDialog
       .setTitle(getString(R.string.dialog_title_confirm_send))
       .setMessage(getString(R.string.dialog_msg_confirm_send))
       .setPositiveButton(
           getString(R.string.dialog_btn_positive_confirm_send),
           new View.OnClickListener() {
             @Override
             public void onClick(View v) {
               sendWebmail();
               materialDialog.dismiss();
             }
           })
       .setNegativeButton(
           getString(R.string.dialog_btn_negative_confirm_send),
           new View.OnClickListener() {
             @Override
             public void onClick(View v) {
               materialDialog.dismiss();
             }
           })
       .setCanceledOnTouchOutside(true);
   materialDialog.show();
 }
Example #2
0
 private void showBackDialog() {
   final MaterialDialog materialDialog = new MaterialDialog(this);
   materialDialog
       .setTitle(getString(R.string.dialog_title_save_draft))
       .setMessage(getString(R.string.dialog_msg_save_draft))
       .setPositiveButton(
           getString(R.string.dialog_btn_positive_save_draft),
           new View.OnClickListener() {
             @Override
             public void onClick(View v) {
               onBackPressed = true;
               onBackPressed();
               materialDialog.dismiss();
             }
           })
       .setNegativeButton(
           getString(R.string.dialog_btn_negative_save_draft),
           new View.OnClickListener() {
             @Override
             public void onClick(View v) {
               materialDialog.dismiss();
             }
           })
       .setCanceledOnTouchOutside(true);
   materialDialog.show();
 }
  /** 图片截图框 */
  protected void showDialogPicSelect() {
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.item_text);
    arrayAdapter.add("分享图片");
    arrayAdapter.add("保存图片至图册");
    arrayAdapter.add("保存图片至文件夹");
    ListView listView = new ListView(this);
    float scale = getResources().getDisplayMetrics().density;
    int dpAsPixels = (int) (8 * scale + 0.5f);
    listView.setPadding(0, dpAsPixels, 0, dpAsPixels);
    listView.setDividerHeight(0);
    listView.setAdapter(arrayAdapter);

    final MaterialDialog alert = new MaterialDialog(this).setContentView(listView);

    listView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            alert.dismiss();
            switch (position) {
              case 0:
                sharePic();
                break;
              case 1:
                savePicInGarrery();
                break;
              case 2:
                savePicInSdCard();
                break;
            }
          }
        });
    alert.show();
  }
Example #4
0
    @Override
    public void onClick(View v) {
      String label = ((Button) v).getText().toString();
      String positive = activity.getString(R.string.alert_pos);
      if (label.equals(positive)) {
        String recipient = activity.getString(R.string.email);
        String subject = activity.getString(R.string.subject);
        String type = activity.getString(R.string.type);

        // get stacktrace as string
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String body = sw.toString();

        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType(type);
        i.putExtra(Intent.EXTRA_EMAIL, new String[] {recipient});
        i.putExtra(Intent.EXTRA_SUBJECT, subject);
        i.putExtra(Intent.EXTRA_TEXT, body);

        try {
          activity.startActivity(Intent.createChooser(i, "Send email"));
        } catch (android.content.ActivityNotFoundException ex) {
        }
      }

      dialog.dismiss();
    }
Example #5
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);
 }
  /**
   * 亮度框
   *
   * @param string
   */
  protected void showDialogLightSeeting(String string) {
    final MaterialDialog dialog = new MaterialDialog(this);
    dialog.setTitle(string);
    dialog.setPositiveButton(
        "确定",
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            dialog.dismiss();
            old_brightness = brightness;
            SettingUtils.setSetting(ComicImageViewActivity.this, "light", brightness);
          }
        });
    dialog.setNegativeButton(
        "取消",
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            dialog.dismiss();
            LayoutParams layoutpars = getWindow().getAttributes();
            // set the brightness of this window
            layoutpars.screenBrightness = old_brightness / (float) 255;
            // apply attribute changes to this window
            getWindow().setAttributes(layoutpars);
          }
        });
    View customView = getLayoutInflater().inflate(R.layout.seekbar_light, null);
    createSeekBar(customView);
    dialog.setContentView(customView);
    dialog.show();
  }
  public void show(Context context, final AlertDialogListener listener) {
    this.mContext = context;
    this.listener = listener;
    View contentView = LayoutInflater.from(mContext).inflate(R.layout.view_my_alertdialog, null);
    TextView tvMessage = (TextView) contentView.findViewById(R.id.message);
    Button positive = (Button) contentView.findViewById(R.id.positive);
    Button negative = (Button) contentView.findViewById(R.id.negative);

    // tvMessage.setText(message);
    tvMessage.setText(Html.fromHtml(message));
    tvMessage.setMovementMethod(new ScrollingMovementMethod());

    positive.setText(positiveContent);
    negative.setText(negativeContent);

    final MaterialDialog mMaterialDialog = new MaterialDialog(mContext);
    mMaterialDialog.setView(contentView).setCanceledOnTouchOutside(canceledOnTouchOutside);

    mMaterialDialog.show();

    positive.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mMaterialDialog.dismiss();
            listener.confirmUpdate();
          }
        });

    negative.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mMaterialDialog.dismiss();
          }
        });
  }
Example #8
0
 void showDialog() {
   MaterialDialog materialDialog = new MaterialDialog(Main_Nav.this);
   materialDialog.setTitle("Hello, " + username);
   materialDialog.setCanceledOnTouchOutside(true);
   if (ScrappingMachine.checkIfLoggedIn()) {
     materialDialog.setMessage("You are currently online.");
   } else {
     materialDialog.setMessage("You are currently offline.");
   }
   materialDialog.show();
 }
Example #9
0
  public void logout() {
    // if logged in, then make logout available.
    final MaterialDialog materialDialog = new MaterialDialog(Main_Nav.this);
    materialDialog.setCanceledOnTouchOutside(true);
    materialDialog.setTitle("Log Out?");
    materialDialog.setMessage("Saying bye bye?");
    materialDialog.setNegativeButton(
        "",
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            materialDialog.dismiss();
          }
        });
    materialDialog.setPositiveButton(
        "Log out",
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            SharedPreferences prefs =
                getSharedPreferences(Constants.USER_PREFERENCES, MODE_PRIVATE);
            SharedPreferences.Editor editor = prefs.edit();
            Toast.makeText(getApplicationContext(), "Logging Out.", Toast.LENGTH_SHORT).show();
            editor.putString(Constants.bundle_username, "none");
            editor.putString(Constants.bundle_pwd, "none");
            editor.commit();
            EmailMessage.deleteAll(EmailMessage.class);

            editor.putBoolean("toggle_wifi", false);
            editor.putBoolean("toggle_mobiledata", false);

            NetworkChangeBroadcastReceiver.cancelNotification(getApplicationContext());
            materialDialog.dismiss();
            new Handler()
                .postDelayed(
                    new Runnable() {
                      @Override
                      public void run() {
                        System.exit(0);
                        finish();
                      }
                    },
                    2000);
          }
        });

    materialDialog.show();
  }
  public void show() {
    mDialog = new MaterialDialog(this.mContext);
    View contentView =
        LayoutInflater.from(this.mContext).inflate(R.layout.item_homeworkmaker_dialog, null);
    final EditText homeworkTitle = (EditText) contentView.findViewById(R.id.edittxt_homework_title);
    final EditText homeworkContent =
        (EditText) contentView.findViewById(R.id.edittxt_homework_content);
    WheelDatePicker datePicker =
        (WheelDatePicker) contentView.findViewById(R.id.datepicker_homework_deadline);
    final HTextView deadlineTxt = (HTextView) contentView.findViewById(R.id.txt_homework_deadline);

    deadlineTxt.animateText(
        year
            + "年"
            + month
            + "月"
            + day_of_month
            + "日"
            + " "
            + DateUtil.getWeekStrByDateStr(
                DateUtil.getDateStr(year, month, day_of_month, "yyyyMMdd"), "yyyyMMdd"));

    datePicker.setOnWheelChangeListener(
        new AbstractWheelPicker.OnWheelChangeListener() {
          @Override
          public void onWheelScrolling(float deltaX, float deltaY) {}

          @Override
          public void onWheelSelected(int index, String data) {
            String[] date = data.split("-");
            deadlineTxt.animateText(
                date[0]
                    + "年"
                    + date[1]
                    + "月"
                    + date[2]
                    + "日"
                    + " "
                    + DateUtil.getWeekStrByDateStr(data, "yyyy-MM-dd"));
            year = Integer.valueOf(date[0]);
            month = Integer.valueOf(date[1]);
            day_of_month = Integer.valueOf(date[2]);
          }

          @Override
          public void onWheelScrollStateChanged(int state) {}
        });

    mDialog
        .setTitle("发布作业")
        .setContentView(contentView)
        .setPositiveButton(
            "发布",
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                String title = homeworkTitle.getText().toString();
                if (title.isEmpty()) {
                  homeworkTitle.setError("Title不能为空");
                  return;
                }
                String content = homeworkContent.getText().toString();
                if (content.isEmpty()) {
                  homeworkContent.setError("内容不能为空");
                  return;
                }
                if (mHomeworkEditedListener != null) {
                  mHomeworkEditedListener.onHomeworkEdited(
                      title, content, DateUtil.getDateStr(year, month, day_of_month, "yyyyMMdd"));
                }
                dismiss();
              }
            })
        .show();
  }
 public void dismiss() {
   mDialog.dismiss();
 }
Example #12
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Pass the event to ActionBarDrawerToggle, if it returns
    // true, then it has handled the app icon touch event
    if (mDrawerToggle.onOptionsItemSelected(item)) {
      return true;
    }
    switch (item.getItemId()) {
      case R.id.action_composemail:
        SplashDialog1 splashDialog1 = new SplashDialog1(Main_Nav.this, 0);
        splashDialog1.setCancelable(false);
        splashDialog1.show();

        invalidateOptionsMenu();
        return true;
      case R.id.action_settings:
        getFragmentManager()
            .beginTransaction()
            .replace(R.id.content_frame, new SettingsFragment(username, pwd))
            .commit();
        return true;
      case R.id.action_aboutme:
        startActivity(new Intent(Main_Nav.this, AboutFrag.class));
        return true;
      case R.id.action_logout:
        logout();
        return true;
      case R.id.action_masterrefresh:
        final MaterialDialog materialDialog = new MaterialDialog(Main_Nav.this);
        materialDialog.setCanceledOnTouchOutside(true);
        materialDialog.setTitle("Master Refresh");
        materialDialog.setMessage("Is the app faulty somewhere? Go ahead and master refresh.");
        materialDialog.setPositiveButton(
            "Refresh",
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                if (((ConnectivityManager)
                            getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE))
                        .getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
                        .isConnectedOrConnecting()
                    || ((ConnectivityManager)
                            getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE))
                        .getNetworkInfo(ConnectivityManager.TYPE_WIFI)
                        .isConnectedOrConnecting()) {
                  new async_MasterRefresh().execute("");
                  materialDialog.dismiss();
                } else {
                  Toast.makeText(
                          getApplicationContext(),
                          "Connect to the net for master refresh",
                          Toast.LENGTH_SHORT)
                      .show();
                  materialDialog.dismiss();
                }
              }
            });
        materialDialog.setNegativeButton(
            "No!",
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                materialDialog.dismiss();
              }
            });
        materialDialog.show();
        return true;
      case R.id.action_search:
        if (mSearchOpened) {
          closeSearchBar();
        } else {
          openSearchBar(mSearchQuery);
        }
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }
Example #13
0
    @Override
    protected void onPostExecute(Exception e) {
      if (e != null) {
        // error case
        MaterialDialog dialog = new MaterialDialog(activity);
        View.OnClickListener listener = new DialogButtonListener(activity, dialog, e);
        dialog.setTitle(R.string.alert_title);
        dialog.setMessage(R.string.alert_desc);
        dialog.setPositiveButton(R.string.alert_pos, listener);
        dialog.setNegativeButton(R.string.alert_neg, listener);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

      } else {
        // refresh gallery
        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.DATA, file.getAbsolutePath());
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
        activity.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

        // create notification
        Uri uri = Uri.parse("file://" + root + name);

        Intent viewIntent = new Intent();
        viewIntent.setAction(Intent.ACTION_VIEW);
        viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        viewIntent.setDataAndType(uri, "image/*");
        PendingIntent viewPending =
            PendingIntent.getActivity(activity, 0, viewIntent, PendingIntent.FLAG_ONE_SHOT);

        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        shareIntent.setType("image/jpeg");
        Intent i = Intent.createChooser(shareIntent, "Share");
        PendingIntent sharePending =
            PendingIntent.getActivity(activity, 0, i, PendingIntent.FLAG_ONE_SHOT);

        String title = activity.getString(R.string.notification_title);
        String desc = activity.getString(R.string.notification_desc);
        Bitmap icon =
            BitmapFactory.decodeResource(
                activity.getResources(), android.R.drawable.ic_menu_gallery);

        NotificationCompat.Builder builder =
            new NotificationCompat.Builder(activity)
                .setContentTitle(title)
                .setTicker(title)
                .setContentText(desc)
                .setSmallIcon(R.drawable.notification_icon)
                .setAutoCancel(true)
                .setLargeIcon(icon)
                .setContentIntent(viewPending)
                .addAction(android.R.drawable.ic_menu_share, "Share", sharePending);

        NotificationManager nm =
            (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(NOTIFICATION_ID); // remove old notification
        nm.notify(NOTIFICATION_ID, builder.build());
      }
    }