예제 #1
0
 /*package*/ void onPrepareDialog(int id, Dialog d, Bundle options) {
   switch (id) {
     case DIALOG_PROGRESS:
       d.setCancelable(options.getBoolean(KEY_DIALOG_PROGRESS_CANCELABLE, true));
       d.setOnCancelListener(null);
   }
 }
예제 #2
0
  private Dialog showZoomDialog() {
    Dialog zoomedDialog = new Dialog(SyncResultsActivity.this);
    zoomedDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    zoomedDialog.setContentView(R.layout.zoomedpic);
    zoomedDialog.setCancelable(true);

    final ImageView image = (ImageView) zoomedDialog.findViewById(R.id.image);

    final int padding = 15;

    final int width = mContactImage.getWidth();
    final int height = mContactImage.getHeight();

    int newWidth = width;
    int newHeight = height;

    final int windowHeight = getWindowManager().getDefaultDisplay().getHeight();
    final int windowWidth = getWindowManager().getDefaultDisplay().getWidth();

    boolean scale = false;
    float ratio;

    if (newHeight >= windowHeight) {
      ratio = (float) newWidth / (float) newHeight;
      newHeight = windowHeight - padding;
      newWidth = Math.round(ratio * (float) newHeight);

      scale = true;
    }

    if (newWidth >= windowWidth) {
      ratio = (float) newHeight / (float) newWidth;
      newWidth = windowWidth - padding;
      newHeight = Math.round(ratio * (float) newWidth);

      scale = true;
    }

    image.setImageBitmap(mContactImage);

    if (scale) {
      Matrix m = new Matrix();
      m.postScale((float) newWidth / (float) width, (float) newHeight / (float) height);
      image.setImageMatrix(m);

      zoomedDialog.getWindow().setLayout(newWidth, newHeight);
    }

    zoomedDialog.setOnCancelListener(
        new OnCancelListener() {
          public void onCancel(DialogInterface dialog) {
            removeDialog(ZOOM_PIC);
          }
        });

    return zoomedDialog;
  }
예제 #3
0
 public static c a(
     Dialog dialog, android.content.DialogInterface.OnCancelListener oncancellistener) {
   c c1 = new c();
   dialog = (Dialog) am.a(dialog, "Cannot display null dialog");
   dialog.setOnCancelListener(null);
   dialog.setOnDismissListener(null);
   c1.a = dialog;
   if (oncancellistener != null) {
     c1.b = oncancellistener;
   }
   return c1;
 }
예제 #4
0
  public void setOnCancelListener(DialogInterface.OnCancelListener listener) {
    mOnCancelListener = listener;
    mDialog.setOnCancelListener(
        new android.content.DialogInterface.OnCancelListener() {

          @Override
          public void onCancel(android.content.DialogInterface dialog) {
            if (mOnCancelListener != null) {
              mOnCancelListener.onCancel(DropDownDialog.this);
            }
          }
        });
  }
예제 #5
0
  /**
   * @param context Context.
   * @param title The title of this AlertDialog can be null .
   * @param items button name list.
   * @param alertDo methods call Id:Button + cancel_Button.
   * @param exit Name can be null.It will be Red Color
   * @return A AlertDialog
   */
  public static Dialog showAlert(
      final Context context,
      final String title,
      final String[] items,
      String exit,
      final OnAlertSelectId alertDo,
      OnCancelListener cancelListener) {
    String cancel = context.getString(R.string.app_cancel);
    final Dialog dlg = new Dialog(context, R.style.MMTheme_DataSheet);
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.alert_dialog_menu_layout, null);
    final int cFullFillWidth = 10000;
    layout.setMinimumWidth(cFullFillWidth);
    final ListView list = (ListView) layout.findViewById(R.id.content_list);
    AlertAdapter adapter = new AlertAdapter(context, title, items, exit, cancel);
    list.setAdapter(adapter);
    list.setDividerHeight(0);

    list.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!(title == null || title.equals("")) && position - 1 >= 0) {
              alertDo.onClick(position - 1);
              dlg.dismiss();
              list.requestFocus();
            } else {
              alertDo.onClick(position);
              dlg.dismiss();
              list.requestFocus();
            }
          }
        });
    // set a large value put it in bottom
    Window w = dlg.getWindow();
    WindowManager.LayoutParams lp = w.getAttributes();
    lp.x = 0;
    final int cMakeBottom = -1000;
    lp.y = cMakeBottom;
    lp.gravity = Gravity.BOTTOM;
    dlg.onWindowAttributesChanged(lp);
    dlg.setCanceledOnTouchOutside(true);
    if (cancelListener != null) {
      dlg.setOnCancelListener(cancelListener);
    }
    dlg.setContentView(layout);
    dlg.show();
    return dlg;
  }
예제 #6
0
  /** @hide */
  public boolean takeCancelAndDismissListeners(
      String msg, final OnCancelListener cancel, final OnDismissListener dismiss) {
    if (mCancelAndDismissTaken != null) {
      mCancelAndDismissTaken = null;
    } else if (mCancelMessage != null || mDismissMessage != null) {
      return false;
    }

    setOnCancelListener(cancel);
    setOnDismissListener(dismiss);
    mCancelAndDismissTaken = msg;

    return true;
  }
예제 #7
0
 public void showNetLoadingDialog() {
   if (mNetLoadingDialog == null) {
     mNetLoadingDialog = new Dialog(this, R.style.laoding_progress_dialog_style);
     mNetLoadingDialog.setContentView(R.layout.loading_progress_bar_layout);
     mNetLoadingDialog.setCancelable(true);
     mNetLoadingDialog.setOnCancelListener(
         new DialogInterface.OnCancelListener() {
           @Override
           public void onCancel(DialogInterface dialog) {
             Globe.sNetClient.getmRequestTemp().clear();
           }
         });
   }
   mNetLoadingDialog.show();
 }
예제 #8
0
  public GetJsonRequest(
      String url,
      Map<String, String> mHeaders,
      Dialog mDialog,
      Listener<String> mListener,
      ErrorListener mErrorListener) {
    super(Method.GET, url, mErrorListener);
    this.mDialog = mDialog;
    this.mHeaders = mHeaders;
    this.mErrorListener = mErrorListener;
    this.mListener = mListener;

    if (mDialog != null) {
      mDialog.show();
      mDialog.setOnCancelListener(this);
    }
  }
    @Override
    protected void onPreExecute() {
      // TODO Auto-generated method stub
      super.onPreExecute();
      dataArray = new ArrayList<String>();
      dialog = new Dialog(myContext);
      dialog.setOnCancelListener(
          new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
              // TODO Auto-generated method stub
              myTask.cancel(true);
            }
          });
      dialog.show();
      dialog.setCancelable(true);
      dialog.setTitle(R.string.toast_proses);
    }
예제 #10
0
  protected Dialog onCreateDialog(int id) {
    Dialog dialog;
    switch (id) {
      case DIALOG_PREPARING:
        dialog = new ProgressDialog(this);

        ((ProgressDialog) dialog).setMessage(getString(R.string.title_waiting));
        dialog.setOnCancelListener(
            new Dialog.OnCancelListener() {
              @Override
              public void onCancel(DialogInterface dialog) {
                finish();
              }
            });
        break;
      default:
        dialog = null;
    }
    return dialog;
  }
예제 #11
0
  @Override
  public void onCreate(Bundle b) {
    super.onCreate(b);
    getSupportActionBar().hide();
    Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.about_textview);
    dialog.setCancelable(true);
    dialog.setCanceledOnTouchOutside(true);
    dialog.setTitle("about dialog");
    TextView text = (TextView) dialog.findViewById(R.id.tv);
    // text.setText(  );

    dialog.show();
    //
    dialog.setOnCancelListener(
        new DialogInterface.OnCancelListener() {

          public void onCancel(DialogInterface arg0) {
            finish();
          }
        });
  }
예제 #12
0
 public Dialog onCreateDialog(int id) {
   switch (id) {
     case WAITING_DIALOG:
       Dialog dlg =
           ProgressDialog.show(
               (Context) this,
               this.getString(R.string.main_dlginit_title),
               this.getString(R.string.main_dlginit_content),
               true,
               true);
       dlg.setOnCancelListener(this);
       return dlg;
     case TASK_ERROR_DIALOG:
       return new AlertDialog.Builder(this)
           .setTitle(R.string.market_title)
           .setPositiveButton(
               R.string.dlg_httptask_retry,
               new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int which) {
                   Log.i(TAG, "retry http task");
                   onTaskRetry();
                 }
               })
           .setNegativeButton(
               R.string.dlg_httptask_exit,
               new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int which) {
                   Log.i(TAG, "exit this activity");
                   finish();
                 }
               })
           .setMessage(R.string.dlg_httptask_error_hint)
           .setOnCancelListener(this)
           .create();
     default:
       break;
   }
   return null;
 }
예제 #13
0
 /**
  * Initiate the group chat and open a progress dialog waiting for the session to start
  *
  * @return True if successful
  */
 private boolean initiateGroupChat(boolean firstLoad) {
   /* Initiate the group chat session in background */
   try {
     mGroupChat = mChatService.initiateGroupChat(new HashSet<>(mParticipants), mSubject);
     mChatId = mGroupChat.getChatId();
     setCursorLoader(firstLoad);
     sChatIdOnForeground = mChatId;
   } catch (RcsServiceException e) {
     showExceptionThenExit(e);
     return false;
   }
   /* Display a progress dialog waiting for the session to start */
   mProgressDialog = showProgressDialog(getString(R.string.label_command_in_progress));
   mProgressDialog.setOnCancelListener(
       new OnCancelListener() {
         public void onCancel(DialogInterface dialog) {
           Utils.displayToast(
               GroupChatView.this, getString(R.string.label_chat_initiation_canceled));
           quitSession();
         }
       });
   return true;
 }
예제 #14
0
  private void initiateTransfer(ContactId remote) {
    /* Get thumbnail option */
    CheckBox ftThumb = (CheckBox) findViewById(R.id.ft_thumb);
    boolean tryToSendFileicon = ftThumb.isChecked();
    String mimeType = getContentResolver().getType(mFile);
    if (tryToSendFileicon && mimeType != null && !mimeType.startsWith("image")) {
      tryToSendFileicon = false;
    }
    try {
      /* Only take persistable permission for content Uris */
      takePersistableContentUriPermission(this, mFile);
      /* Initiate transfer */
      mFileTransfer = mFileTransferService.transferFile(remote, mFile, tryToSendFileicon);
      mFileTransferId = mFileTransfer.getTransferId();
      mProgressDialog = showProgressDialog(getString(R.string.label_command_in_progress));
      mProgressDialog.setOnCancelListener(
          new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
              Toast.makeText(
                      InitiateFileTransfer.this,
                      getString(R.string.label_transfer_cancelled),
                      Toast.LENGTH_SHORT)
                  .show();
              quitSession();
            }
          });
      /* Disable UI */
      mSpinner.setEnabled(false);
      /* Hide buttons */
      mInviteBtn.setVisibility(View.INVISIBLE);
      mSelectBtn.setVisibility(View.INVISIBLE);
      ftThumb.setVisibility(View.INVISIBLE);

    } catch (RcsServiceException e) {
      showExceptionThenExit(e);
    }
  }
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    // url=getIntent().getStringExtra("img");
    // new ServerRead().execute("");
    dialog = new Dialog(this);
    dialog.getWindow();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.push_image);

    // set the custom dialog components - text, image and button

    dialog.setOnCancelListener(
        new DialogInterface.OnCancelListener() {

          @Override
          public void onCancel(DialogInterface dialog) {
            finish();
          }
        });

    dialog.setOnDismissListener(
        new DialogInterface.OnDismissListener() {

          @Override
          public void onDismiss(DialogInterface dialog) {
            // TODO Auto-generated method stub
            finish();
          }
        });

    // set the custom dialog components - text, image and button
    // splash.setImageBitmap(splashbitmap);

    setView();
  }
예제 #16
0
 private void startGooglePlayService() {
   GoogleApiAvailability api = GoogleApiAvailability.getInstance();
   int resultCode = api.isGooglePlayServicesAvailable(this);
   if (resultCode != ConnectionResult.SUCCESS) {
     if (api.isUserResolvableError(resultCode)) {
       Dialog dialog = api.getErrorDialog(this, resultCode, REQUEST_PLAY_SERVICES);
       dialog.setOnCancelListener(
           new DialogInterface.OnCancelListener() {
             @Override
             public void onCancel(DialogInterface dialogInterface) {
               finish();
             }
           });
       dialog.show();
     } else {
       Toast.makeText(this, R.string.gcm_nao_suportado, Toast.LENGTH_SHORT).show();
       finish();
     }
   } else {
     Intent it = new Intent(this, UfmsListenerService.class);
     it.putExtra(UfmsListenerService.EXTRA_REGISTRAR, true);
     startService(it);
   }
 }
예제 #17
0
  private boolean checkPlayServices() {
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
      if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
        Dialog dialog =
            GooglePlayServicesUtil.getErrorDialog(
                resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST);
        dialog.setOnCancelListener(
            new DialogInterface.OnCancelListener() {

              @Override
              public void onCancel(DialogInterface dialog) {
                finish();
              }
            });
        dialog.show();
      } else {
        // To Do...
        finish();
      }
      return false;
    }
    return true;
  }
  @Override
  public void onClick(final View v) {
    switch (v.getId()) {
      case R.id.add_to_cart:
        final Helpers helpers = new Helpers();
        int pos = Integer.parseInt(String.valueOf(v.getTag()));
        int product_id = Integer.parseInt(products_items.get(pos).get("product_id"));
        int productQty = 1, check = 0, old_qty = 0;
        String server_id = null;

        int is_required = Integer.parseInt(products_items.get(pos).get("prescription_required"));

        final ProgressDialog pdialog = new ProgressDialog(context);
        pdialog.setCancelable(false);
        pdialog.setMessage("Please wait...");

        for (int x = 0; x < ProductsActivity.basket_items.size(); x++) {
          if (ProductsActivity.basket_items
              .get(x)
              .get("product_id")
              .equals(String.valueOf(product_id))) {
            check += 1;
            old_qty = Integer.parseInt(ProductsActivity.basket_items.get(x).get("quantity"));
            server_id = ProductsActivity.basket_items.get(x).get("server_id");
          }
        }

        if (check > 0) { // EXISTING ITEM IN YOUR BASKET (UPDATE ONLY)
          final HashMap<String, String> hashMap = new HashMap<>();
          hashMap.put("patient_id", String.valueOf(SidebarActivity.getUserID()));
          hashMap.put("table", "baskets");
          hashMap.put("request", "crud");
          hashMap.put("action", "update");
          hashMap.put("id", server_id);
          int new_qty = old_qty + productQty;
          hashMap.put("quantity", String.valueOf(new_qty));

          pdialog.show();
          PostRequest.send(
              context,
              hashMap,
              new RespondListener<JSONObject>() {
                @Override
                public void getResult(JSONObject response) {
                  try {
                    int success = response.getInt("success");

                    if (success == 1) {
                      if (response.getBoolean("has_contents")) {
                        ProductsActivity.transferHashMap(hashMap);
                        Snackbar.make(v, "Your cart has been updated", Snackbar.LENGTH_SHORT)
                            .show();
                      }
                    }
                  } catch (JSONException e) {
                    d("prod_adapter6", e + "");
                    Snackbar.make(v, "Networ error", Snackbar.LENGTH_SHORT).show();
                  }
                  pdialog.dismiss();
                }
              },
              new ErrorListener<VolleyError>() {
                public void getError(VolleyError error) {
                  pdialog.dismiss();
                  d("prod_adapter5", error + "");
                  Snackbar.make(v, "Network error", Snackbar.LENGTH_SHORT).show();
                }
              });
        } else { // ADD NEW SA BASKET
          final HashMap<String, String> hashMap = new HashMap<>();
          hashMap.put("product_id", String.valueOf(product_id));
          hashMap.put("quantity", String.valueOf(productQty));
          hashMap.put("patient_id", String.valueOf(SidebarActivity.getUserID()));
          hashMap.put("table", "baskets");
          hashMap.put("request", "crud");
          hashMap.put("action", "insert");

          if (is_required == 1) { // IF PRESCRIPTION IS REQUIRED
            GridView gridView;
            final Dialog builder;
            HashMap<GridView, Dialog> map;
            map = helpers.showPrescriptionDialog(context);

            if (map.size() > 0) { // IF NAA NAY UPLOADED NGA PRESCRIPTION
              Map.Entry<GridView, Dialog> entry = map.entrySet().iterator().next();
              gridView = entry.getKey();
              builder = entry.getValue();

              gridView.setOnItemClickListener(
                  new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(
                        AdapterView<?> parent, View view, int position, long id) {
                      pdialog.show();
                      int prescriptionId = (int) id;
                      hashMap.put("prescription_id", prescriptionId + "");
                      hashMap.put("is_approved", "0");

                      PostRequest.send(
                          context,
                          hashMap,
                          new RespondListener<JSONObject>() {
                            @Override
                            public void getResult(JSONObject response) {
                              try {
                                int success = response.getInt("success");

                                if (success == 1) {
                                  if (response.getBoolean("has_contents")) {
                                    hashMap.put(
                                        "server_id",
                                        String.valueOf(response.getInt("last_inserted_id")));
                                    ProductsActivity.transferHashMap(hashMap);
                                    Snackbar.make(
                                            v,
                                            "New item has been added to your cart",
                                            Snackbar.LENGTH_SHORT)
                                        .show();
                                  }
                                }
                              } catch (JSONException e) {
                                d("prod_adapter4", e + "");
                                Snackbar.make(v, "Server error occurred", Snackbar.LENGTH_SHORT)
                                    .show();
                              }
                              pdialog.dismiss();
                            }
                          },
                          new ErrorListener<VolleyError>() {
                            public void getError(VolleyError error) {
                              pdialog.dismiss();
                              d("prod_adapter3", error + "");
                              Snackbar.make(v, "Network error", Snackbar.LENGTH_SHORT).show();
                            }
                          });
                      builder.dismiss();
                    }
                  });
              builder.setOnCancelListener(
                  new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                      pdialog.dismiss();
                    }
                  });
            } else { // IF EMPTY ANG PRESCRIPTIONS NGA TAB
              AlertDialog.Builder confirmationDialog = new AlertDialog.Builder(context);
              confirmationDialog.setTitle("Attention!");
              confirmationDialog.setMessage(
                  "This product requires you to upload a prescription, do you wish to continue ?");
              confirmationDialog.setNegativeButton("No", null);
              confirmationDialog.setPositiveButton(
                  "Yes",
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      AddToCart(hashMap);
                      context.startActivity(new Intent(context, ShowPrescriptionDialog.class));
                    }
                  });
              confirmationDialog.show();
            }
          } else { // IF PRESCRIPTION IS NOT REQUIRED
            pdialog.show();

            hashMap.put("prescription_id", "0");
            hashMap.put("is_approved", "1");

            d("params_pa", hashMap + "");

            PostRequest.send(
                context,
                hashMap,
                new RespondListener<JSONObject>() {
                  @Override
                  public void getResult(JSONObject response) {
                    try {
                      int success = response.getInt("success");

                      if (success == 1) {
                        if (response.getBoolean("has_contents")) {
                          hashMap.put(
                              "server_id", String.valueOf(response.getInt("last_inserted_id")));
                          ProductsActivity.transferHashMap(hashMap);
                          Snackbar.make(
                                  v, "New item has been added to your cart", Snackbar.LENGTH_SHORT)
                              .show();
                        }
                      }
                    } catch (Exception e) {
                      d("prod_adapter2", e + "");
                      Snackbar.make(v, "Server error occurred" + "", Snackbar.LENGTH_SHORT).show();
                    }
                    pdialog.dismiss();
                  }
                },
                new ErrorListener<VolleyError>() {
                  public void getError(VolleyError error) {
                    pdialog.dismiss();
                    d("prod_adapter1", error + "");
                    Snackbar.make(v, "Network error", Snackbar.LENGTH_SHORT).show();
                  }
                });
          }
        }
        break;
    }
  }
예제 #19
0
파일: MMAlert.java 프로젝트: TsaoChiyen/-
  /** 底部弹出的九宫格 */
  public static Dialog showNiceAler(
      final Context context,
      final String buttonTitle,
      final List<GridViewMenuItem> list,
      final int width,
      final OnAlertSelectId alertDo,
      OnCancelListener cancelListener) {
    final Dialog dlg = new Dialog(context, R.style.MMThem_DataSheet);
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final LinearLayout layout =
        (LinearLayout) inflater.inflate(R.layout.bottom_gridview_menu, null);
    LinearLayout parentLayout = (LinearLayout) layout.findViewById(R.id.control);

    final int cFullFillWidth = 10000;
    layout.setMinimumWidth(cFullFillWidth);

    int count = list.size() % 3 == 0 ? list.size() / 3 : list.size() / 3 + 1;
    int index = 0;
    for (int i = 0; i < count; i++) {
      LinearLayout childLayout = new LinearLayout(context);
      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
      childLayout.setLayoutParams(params);
      childLayout.setOrientation(LinearLayout.HORIZONTAL);

      for (int j = index; j < list.size(); j++) {
        LinearLayout view = (LinearLayout) inflater.inflate(R.layout.gridview_menu_item, null);
        LinearLayout.LayoutParams itemParams = new LayoutParams(width, LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(itemParams);

        ImageView menuIcon = (ImageView) view.findViewById(R.id.menu_icon);
        menuIcon.setImageResource(list.get(j).resource_id);
        TextView menuText = (TextView) view.findViewById(R.id.menu_text);
        menuText.setText(list.get(j).menu_name);
        childLayout.addView(view);

        final int id = j;
        view.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                alertDo.onClick(id);
                dlg.dismiss();
                layout.requestFocus();
              }
            });

        if ((j + 1) % 3 == 0) {
          index = j;
          break;
        }
      }
      parentLayout.addView(childLayout);
    }

    final TextView cancleBtn = (TextView) layout.findViewById(R.id.popup_text);
    cancleBtn.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // alertDo.onClick(v.getId());
            dlg.dismiss();
            cancleBtn.requestFocus();
          }
        });

    // set a large value put it in bottom
    Window w = dlg.getWindow();
    WindowManager.LayoutParams lp = w.getAttributes();
    lp.x = 0;
    final int cMakeBottom = -100 /*0*/;
    lp.y = cMakeBottom;
    lp.gravity = Gravity.BOTTOM;
    dlg.onWindowAttributesChanged(lp);
    dlg.setCanceledOnTouchOutside(true);
    if (cancelListener != null) dlg.setOnCancelListener(cancelListener);

    dlg.setContentView(layout);
    dlg.show();

    return dlg;
  }
예제 #20
0
package com.example.Bama.widget.photo;
예제 #21
0
 @Override
 protected void onPostExecute(HttpResponse response) {
   if (null != response) {
     String responseStatus = response.getStatusLine().toString();
     int responseCode = response.getStatusLine().getStatusCode();
     if (responseCode == UNAUTHORIZED_USER) {
       getContext()
           .getSharedPreferences(SUBSCRIPTION_PREF, MODE_PRIVATE)
           .edit()
           .remove(PARAM_USERNAME)
           .commit();
       getContext()
           .getSharedPreferences(SUBSCRIPTION_PREF, MODE_PRIVATE)
           .edit()
           .remove(PARAM_PASSWORD)
           .commit();
       showUsernamePasswordLoginDialog(true);
     } else if (responseCode == UNAUTHORIZED_ISSUE) {
       AlertDialog.Builder builder = new AlertDialog.Builder(BillingActivity.this);
       builder.setMessage(getString(R.string.unauthorized_issue));
       builder.setPositiveButton(
           R.string.buy,
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
               setupDialogView();
             }
           });
       Dialog dialog = builder.create();
       dialog.setOnCancelListener(
           new OnCancelListener() {
             @Override
             public void onCancel(DialogInterface dialog) {
               finish();
             }
           });
       dialog.setCanceledOnTouchOutside(true);
       dialog.show();
     } else if (responseCode == UNAUTHORIZED_DEVICE) {
       AlertDialog.Builder builder = new AlertDialog.Builder(BillingActivity.this);
       builder.setMessage(getString(R.string.unauthorized_device));
       builder.setPositiveButton(
           R.string.ok,
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
               finish();
             }
           });
       Dialog dialog = builder.create();
       dialog.setOnCancelListener(
           new OnCancelListener() {
             @Override
             public void onCancel(DialogInterface dialog) {
               finish();
             }
           });
       dialog.setCanceledOnTouchOutside(true);
       dialog.show();
     } else {
       String prefUsername =
           getContext()
               .getSharedPreferences(SUBSCRIPTION_PREF, MODE_PRIVATE)
               .getString(PARAM_USERNAME, null);
       if (prefUsername == null) {
         getContext()
             .getSharedPreferences(SUBSCRIPTION_PREF, MODE_PRIVATE)
             .edit()
             .putString(PARAM_USERNAME, username)
             .commit();
         getContext()
             .getSharedPreferences(SUBSCRIPTION_PREF, MODE_PRIVATE)
             .edit()
             .putString(PARAM_PASSWORD, password)
             .commit();
       }
       startDownloadOfMagazineFromResponse(response);
     }
   }
 }
예제 #22
0
 protected Dialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
   this(context);
   mCancelable = cancelable;
   setOnCancelListener(cancelListener);
 }
예제 #23
0
  public static Dialog show(
      Activity activity, final DialogOptions options, final IDialogResponse response) {

    final Dialog dialog = new Dialog(activity);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_base);

    FontManager.handleFontTags(dialog.findViewById(R.id.dialog_container));

    final ArrayList<EditText> editTexts = new ArrayList<EditText>();
    final IDialogAdapter<?> adapter = options.getDialogAdapter();
    final ListView list = (ListView) dialog.findViewById(R.id.dialog_list);

    if (adapter == null) {
      Utils.remove(list);
    } else {
      list.setAdapter(new DialogInternalAdapter(adapter));
    }

    // give scrollable view a max height
    ViewGroup.LayoutParams scrollWrapParams = list.getLayoutParams();
    list.measure(list.getWidth(), list.getHeight());
    Utils.d("Ok " + list.getWidth() + " ; " + list.getHeight());
    Utils.d("Ok " + list.getMeasuredWidth() + " ; " + list.getMeasuredHeight());

    //		if (scroll.getMeasuredHeight() < scrollWrapParams.height) {
    //			scrollWrapParams.height = scroll.getMeasuredHeight();
    //			scrollWrap.setLayoutParams(scrollWrapParams);
    //		}

    final TextView title = (TextView) dialog.findViewById(R.id.dialog_title);
    title.setText(options.getTitle());

    final TextView description = (TextView) dialog.findViewById(R.id.dialog_description);
    description.setText(options.getDescription());

    Button negative = (Button) dialog.findViewById(R.id.dialog_negative);
    if (!options.isNegativeButtonEnabled()) {
      Utils.remove(negative);
    } else {
      negative.setText(options.getNegative());
      if (options.isReverseColors()) {
        negative.setTextColor(Utils.color(R.color.positive));
      }
      negative.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              if (response != null) {
                response.onNegative();
              }
              dialog.dismiss();
            }
          });
    }

    Button positive = (Button) dialog.findViewById(R.id.dialog_positive);
    if (!options.isPositiveButtonEnabled()) {
      Utils.remove(positive);
    } else {
      positive.setText(options.getPositive());
      if (options.isReverseColors()) {
        positive.setTextColor(Utils.color(R.color.negative));
      }
      positive.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              if (response != null) {
                response.onPositive();
              }
              dialog.dismiss();
            }
          });
    }

    dialog.setOnCancelListener(
        new DialogInterface.OnCancelListener() {
          @Override
          public void onCancel(DialogInterface dialogInterface) {
            if (response != null) {
              response.onCancel();
            }
          }
        });
    dialog.show();
    return dialog;
  }
  /**
   * @param context
   * @param actionSheetSelected
   * @param cancelListener
   * @param type 1.上传照片 2.预览下载
   * @return
   */
  public static Dialog showSheet(
      Context context,
      final OnActionSheetSelected actionSheetSelected,
      OnCancelListener cancelListener,
      String type) {
    final Dialog dlg = new Dialog(context, R.style.ActionSheet);
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.actionsharesheet, null);
    final int cFullFillWidth = 10000;
    layout.setMinimumWidth(cFullFillWidth);

    final TextView savepic_tv = (TextView) layout.findViewById(R.id.savepic_tv);
    final TextView share_tv = (TextView) layout.findViewById(R.id.share_tv);
    final TextView cancel = (TextView) layout.findViewById(R.id.cancel);
    savepic_tv.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            // 拍照
            actionSheetSelected.onClick(1);
            dlg.dismiss();
          }
        });

    share_tv.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            // 选择本地照片
            actionSheetSelected.onClick(2);
            dlg.dismiss();
          }
        });

    cancel.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            dlg.dismiss();
          }
        });

    Window w = dlg.getWindow();
    WindowManager.LayoutParams lp = w.getAttributes();
    lp.x = 0;
    final int cMakeBottom = -1000;
    lp.y = cMakeBottom;
    lp.gravity = Gravity.BOTTOM;
    dlg.onWindowAttributesChanged(lp);
    dlg.setCanceledOnTouchOutside(true);
    if (cancelListener != null) dlg.setOnCancelListener(cancelListener);

    dlg.setContentView(layout);
    dlg.show();

    return dlg;
  }
예제 #25
0
  /**
   * Shows a dialog with info about an event.
   *
   * @param id The id of the event
   */
  private void showDialog(int id) {

    // Create the dialog
    final Dialog dialog = new Dialog(getActivity());

    // Set window
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_around);

    // Date formatters
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
    SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd-", Locale.US);
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.US);

    // Set the custom dialog components - text, image and button
    TextView tvTitle = (TextView) dialog.findViewById(R.id.tv_dialog_around_title);
    TextView tvDescription = (TextView) dialog.findViewById(R.id.tv_dialog_around_description);
    TextView tvDate = (TextView) dialog.findViewById(R.id.tv_dialog_around_date);
    TextView tvTime = (TextView) dialog.findViewById(R.id.tv_dialog_around_time);
    TextView tvPlace = (TextView) dialog.findViewById(R.id.tv_dialog_around_place);
    TextView tvAddress = (TextView) dialog.findViewById(R.id.tv_dialog_around_address);
    Button btClose = (Button) dialog.findViewById(R.id.bt_around_close);

    // Get info about the event
    SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB_NAME, Context.MODE_PRIVATE, null);
    Cursor cursor =
        db.rawQuery(
            "SELECT event.id, event.name, description, start, end, place.name, address, lat, lon FROM event, place WHERE place.id = event.place AND event.id = "
                + id
                + ";",
            null);
    if (cursor.getCount() > 0) {
      cursor.moveToNext();

      // Set title
      tvTitle.setText(cursor.getString(1));
      markerName = cursor.getString(1);

      // Set description
      tvDescription.setText(cursor.getString(2));

      // Set date
      try {
        Date day = dateFormat.parse(cursor.getString(3));
        Date date = new Date();

        // If the event is today, show "Today" instead of the date.
        if (dayFormat.format(day).equals(dayFormat.format(date))) {
          tvDate.setText(dialog.getContext().getString(R.string.today));
        } else {
          Calendar cal = Calendar.getInstance();
          cal.setTime(date);
          cal.add(Calendar.HOUR_OF_DAY, 24);

          // If the event is tomorrow, show "Tomorrow" instead of the date.
          if (dayFormat.format(cal.getTime()).equals(dayFormat.format(date))) {
            tvDate.setText(dialog.getContext().getString(R.string.tomorrow));
          }

          // Else, show the date
          else {
            SimpleDateFormat printFormat = new SimpleDateFormat("dd MMMM", Locale.US);
            tvDate.setText(printFormat.format(day));
          }
        }
      } catch (Exception ex) {
        Log.e("Error parsing around event date", ex.toString());
      }

      // Set time
      try {
        if (cursor.getString(4) == null)
          tvTime.setText(timeFormat.format(dateFormat.parse(cursor.getString(3))));
        else
          tvTime.setText(
              timeFormat.format(dateFormat.parse(cursor.getString(3)))
                  + " - "
                  + timeFormat.format(timeFormat.parse(cursor.getString(4))));
      } catch (ParseException ex) {
        Log.e("Error parsing around event time", ex.toString());
      }

      // Set place
      tvPlace.setText(cursor.getString(5));
      tvAddress.setText(cursor.getString(6));

      // Set up map
      location =
          new LatLng(
              Double.parseDouble(cursor.getString(7)), Double.parseDouble(cursor.getString(8)));
      mapView = (MapView) dialog.findViewById(R.id.mv_dialog_around_map);
      mapView.onCreate(bund);

      // Close db connection
      cursor.close();
      db.close();

      // Set close button
      btClose.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              dialog.dismiss();
            }
          });

      // Actions to take when the dialog is cancelled
      dialog.setOnCancelListener(
          new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
              if (map != null) map.setMyLocationEnabled(false);
              if (mapView != null) {
                mapView.onResume();
                mapView.onDestroy();
              }
            }
          });

      // Show the dialog
      WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
      lp.dimAmount = 0.0f;
      dialog.show();

      // Start the map
      startMap();
      mapView.onResume();
      dialog.setOnShowListener(
          new OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
              // Gets to GoogleMap from the MapView and does initialization stuff
              startMap();
            }
          });
    }
  }
예제 #26
0
  private void showDialogEditSummary(final int itemPosition) {
    final OrderItemDetail orderItemDetail = preOrderItemDetails.get(itemPosition);

    final Dialog dialogEditSummary = new Dialog(SummaryActivity.this);
    dialogEditSummary.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialogEditSummary.setCancelable(true);
    dialogEditSummary.setContentView(R.layout.dialog_edit_summary);
    // show detail of food by menu code
    MenuItem menuItem = databaseDao.getMenuByCode(orderItemDetail.getMenuCode());

    TextView tvName = (TextView) dialogEditSummary.findViewById(R.id.tvName);
    AppPreference appPreference = new AppPreference(SummaryActivity.this);
    if (appPreference.getAppLanguage().equals("th")) {
      tvName.setText(menuItem.getNameThai());
    } else {
      tvName.setText(menuItem.getNameEng());
    }

    TextView tvPrice = (TextView) dialogEditSummary.findViewById(R.id.tvPrice);
    tvPrice.setText(Double.toString(menuItem.getPrice()));

    final EditText etOption = (EditText) dialogEditSummary.findViewById(R.id.editTextOption);
    etOption.setText(orderItemDetail.getOption());

    ImageView ivImgFood = (ImageView) dialogEditSummary.findViewById(R.id.ivImgFood);
    Picture picture = databaseDao.getMenuPicture(menuItem.getPictureId());
    ivImgFood.setImageBitmap(picture.getBitmapPicture());

    dialogEditSummary.show();

    final EditText etAmount = (EditText) dialogEditSummary.findViewById(R.id.etAmount);
    etAmount.setText(String.valueOf(orderItemDetail.getQuantity()));
    Button btnOK = (Button) dialogEditSummary.findViewById(R.id.btnOK);
    btnOK.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            int amount = Integer.parseInt(etAmount.getText().toString());
            String option = etOption.getText().toString();
            // In case the user entering zero or negative, skip updating.
            if (amount > 0) {
              orderItemDetail.setQuantity(amount);
              orderItemDetail.setOption(option);
              // update data in database
              ContentValues values = new ContentValues();
              values.put(PreOrderTable.Columns._QUANTITY, amount);
              values.put(PreOrderTable.Columns._OPTION, option);
              databaseDao.updatePreOrderByValues(orderItemDetail.getPreOderId(), values);
            }
            // Remove from item list. However, it will add back later.
            preOrderItemDetails.remove(itemPosition);
            // Re-add to item list.
            preOrderItemDetails.add(itemPosition, orderItemDetail);
            dialogEditSummary.dismiss();
            orderItemListAdapter.notifyDataSetChanged();
            // calculate new total price.
            tvTotalPrice.setText(String.valueOf(findTotalPrice(preOrderItemDetails)));
          }
        });

    dialogEditSummary.setOnCancelListener(
        new DialogInterface.OnCancelListener() {
          @Override
          public void onCancel(DialogInterface dialog) {
            // do not anything.
          }
        });
  }
  @Override
  public void onResume() {
    super.onResume();

    ContactsSync app = ContactsSync.getInstance();

    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancelAll();

    // TODO: use current/selected account (not the first one)
    Account account = ContactsSync.getInstance().getAccount();

    if (account != null) {
      if (mAuthDialog != null) {
        mAuthDialog.dismiss();
      }

      // Log.d("pref-bundle", icicle != null ? icicle.toString() : "null");
      mFragment.setAccount(account);
      if (ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY)) {
        if (app.getSyncFrequency() == 0) {
          app.setSyncFrequency(Preferences.DEFAULT_SYNC_FREQUENCY);
          app.savePreferences();
          ContentResolver.addPeriodicSync(
              account,
              ContactsContract.AUTHORITY,
              new Bundle(),
              Preferences.DEFAULT_SYNC_FREQUENCY * 3600);
        }
      } else {
        if (app.getSyncFrequency() > 0) {
          app.setSyncFrequency(0);
          app.savePreferences();
        }
      }
      updateStatusMessage(account, 0);
      final int mask =
          ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE | ContentResolver.SYNC_OBSERVER_TYPE_PENDING;
      mSyncObserverHandler = ContentResolver.addStatusChangeListener(mask, mSyncObserver);
    } else {
      if (mAuthDialog != null) {
        mAuthDialog.dismiss();
      }

      mAuthDialog = new Dialog(this);
      mAuthDialog.setContentView(R.layout.not_account_actions);
      mAuthDialog.setTitle("Select option");
      ((Button) mAuthDialog.findViewById(R.id.add_account_button))
          .setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  mAuthDialog.dismiss();
                  Intent intent = new Intent(Preferences.this, AuthenticatorActivity.class);
                  startActivity(intent);
                }
              });
      ((Button) mAuthDialog.findViewById(R.id.exit_button))
          .setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  mAuthDialog.dismiss();
                  Preferences.this.finish();
                }
              });
      mAuthDialog.setOnCancelListener(
          new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
              mAuthDialog.dismiss();
              Preferences.this.finish();
            }
          });
      mAuthDialog.show();
    }
  }
예제 #28
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test1);

    mDialog = new ProgressDialog(this);
    mDialog.setTitle("请稍等...");
    mDialog.setCanceledOnTouchOutside(false);

    mSubscription =
        JObservable.create(
                new JObservable.OnSubscribe<List<Bitmap>>() {
                  @Override
                  public void call(SubscribeManager<List<Bitmap>> mSubscriber) {
                    try {
                      getImage();
                      List<String> strings = subGroupOfImage(mGruopMap);
                      List<Bitmap> bitmaps = new ArrayList<>();
                      for (int i = 0; i < strings.size(); i++) {
                        bitmaps.add(Utils.getSmallBitmap(strings.get(i)));
                      }
                      mSubscriber.notifyData(bitmaps);
                    } catch (Exception e) {
                      mSubscriber.error(e);
                    }
                  }
                })
            .workedOn(Schedules.background())
            .subscribeOn(Schedules.mainThread())
            .subscribe(
                new Subscriber<List<Bitmap>>() {

                  @Override
                  public void onStart() {
                    super.onStart();
                    mDialog.show();
                  }

                  @Override
                  public void onAfter() {
                    super.onAfter();
                    mDialog.dismiss();
                  }

                  @Override
                  public void notifyData(List<Bitmap> strings) {

                    showToast("数据获取成功");
                    initRecyclerView(strings);
                  }

                  @Override
                  public void error(Throwable t) {

                    showToast(t.toString());
                  }
                });

    mDialog.setOnCancelListener(
        new DialogInterface.OnCancelListener() {
          @Override
          public void onCancel(DialogInterface dialog) {
            mSubscription.unsubscribe();
            showToast("已取消任务");
          }
        });
  }