Example #1
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();
 }
  /**
   * 亮度框
   *
   * @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();
  }
Example #3
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 #4
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 #5
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();
  }
Example #7
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 #8
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());
      }
    }