Exemple #1
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();
 }
Exemple #2
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();
  }
Exemple #3
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);
    }
  }
Exemple #4
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());
      }
    }