Example #1
0
 void showProgress(int msgId) {
   progress = new ProgressDialog(this);
   progress.setMessage(getString(msgId));
   progress.setIndeterminate(true);
   progress.setCancelable(true);
   progress.setOnCancelListener(abortListener);
   final int msgId2 = msgId;
   progress.setButton(
       DialogInterface.BUTTON_POSITIVE,
       getString(R.string.background),
       new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface d, int which) {
           // Cheat slightly: just launch home screen
           startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
           // Argh, can't prevent a dismiss at this point, so re-show it
           showProgress(msgId2);
           Toast.makeText(SGTPuzzles.this, R.string.bg_unreliable_warn, Toast.LENGTH_LONG).show();
         }
       });
   progress.setButton(
       DialogInterface.BUTTON_NEGATIVE,
       getString(android.R.string.cancel),
       handler.obtainMessage(MsgType.ABORT.ordinal()));
   progress.show();
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    adView = new AdView(this, AdSize.SMART_BANNER, "a152f84b0f4f9ed");
    LinearLayout adContainer = (LinearLayout) this.findViewById(R.id.adsContainer);
    adContainer.addView(adView);

    AdRequest adRequest = new AdRequest();
    Set<String> keywordsSet = new HashSet<String>();
    keywordsSet.add("game");
    keywordsSet.add("dating");
    keywordsSet.add("money");
    keywordsSet.add("girl");
    adRequest.addKeywords(keywordsSet);
    adRequest.addTestDevice("1B91DF7A13E674202332C251084C3ADA");
    adView.loadAd(adRequest);

    imageView = (ImageView) this.findViewById(R.id.imageView1);

    progressDialog = new ProgressDialog(this);
    progressDialog.setTitle("Download Image");
    progressDialog.setMessage("Downloading in progress...");
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setProgress(0);
    progressDialog.setButton(
        DialogInterface.BUTTON_NEGATIVE, "Show Image", dialogInterfaceOnClickListener);

    Button downloadButton = (Button) findViewById(R.id.downloadButton);
    downloadButton.setOnClickListener(downloadButtonOnClickListener);
  }
    @Override
    protected void onPreExecute() {
      if (dialogShow) {
        progDialog = new ProgressDialog(RssReaderActivity.this);
        progDialog.setCancelable(false);
        progDialog.setMessage(getString(R.string.rss_fetching));
        progDialog.setButton(
            DialogInterface.BUTTON_NEGATIVE,
            getString(R.string.btn_hide_text),
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Toast.makeText(
                        RssReaderActivity.this, R.string.rss_keep_updating, Toast.LENGTH_SHORT)
                    .show();
              }
            });
        progDialog.show();
      } else
        Toast.makeText(RssReaderActivity.this, R.string.rss_start_updating, Toast.LENGTH_SHORT)
            .show();

      isTaskRunning = true;
    }
  @SuppressWarnings("deprecation")
  @Override
  protected Dialog onCreateDialog(int id) {
    switch (id) {
      case PROGRESS_DIALOG:
        mProgressDialog = new ProgressDialog(this);
        DialogInterface.OnClickListener loadingButtonListener =
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                mLoadPlaceTask.cancel(true);
                mLoadPlaceTask.setListener(null);
                finish();
              }
            };
        mProgressDialog.setTitle(getString(R.string.loading_place));

        int resourceId =
            this.getResources().getIdentifier("please_wait", "string", this.getPackageName());
        mProgressDialog.setMessage(this.getString(resourceId));
        mProgressDialog.setIndeterminate(true);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        mProgressDialog.setCancelable(false);
        mProgressDialog.setButton(getString(R.string.cancel), loadingButtonListener);
        return mProgressDialog;
    }
    return null;
  }
  protected void onPreExecute() {

    if (mSourceFile == null) return;

    // Skip the rest of this method if the user doesn't want a progress dialog.
    if (!mShowProgress) return;

    pd = new ProgressDialog(mContext);
    pd.setCancelable(false);
    pd.setIndeterminate(false);
    pd.setTitle(R.string.delete);
    pd.setMessage(
        mContext.getResources().getString(R.string.deleting) + " " + mSourceFile.getName());
    pd.setButton(
        DialogInterface.BUTTON_NEUTRAL,
        mContext.getResources().getString(R.string.run_in_background),
        new OnClickListener() {

          @Override
          public void onClick(DialogInterface arg0, int arg1) {
            pd.dismiss();
          }
        });

    pd.show();

    if (mDeleteInterface != null) mDeleteInterface.preDeleteStartSync();
  }
    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
      btDevice = getArguments().getParcelable(KEY_BLUETOOTH_DEVICE);
      getActivity()
          .getApplicationContext()
          .bindService(new Intent(getActivity(), MetaWearBleService.class), this, BIND_AUTO_CREATE);

      reconnectDialog = new ProgressDialog(getActivity());
      reconnectDialog.setTitle(getString(R.string.title_reconnect_attempt));
      reconnectDialog.setMessage(getString(R.string.message_wait));
      reconnectDialog.setCancelable(false);
      reconnectDialog.setCanceledOnTouchOutside(false);
      reconnectDialog.setIndeterminate(true);
      reconnectDialog.setButton(
          DialogInterface.BUTTON_NEGATIVE,
          getString(R.string.label_cancel),
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
              currentMwBoard.disconnect();
              getActivity().finish();
            }
          });

      return reconnectDialog;
    }
 @Override
 protected void onPreExecute() {
   progressDialog = new ProgressDialog(this.context);
   progressDialog.setMessage("正在上传照片,请稍候...");
   progressDialog.setIndeterminate(false);
   progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
   progressDialog.setCanceledOnTouchOutside(false);
   progressDialog.setCancelable(true);
   progressDialog.setOnCancelListener(
       new DialogInterface.OnCancelListener() {
         @Override
         public void onCancel(DialogInterface dialogInterface) {
           alertUser();
         }
       });
   progressDialog.setButton(
       DialogInterface.BUTTON_POSITIVE,
       "取消",
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialogInterface, int i) {
           alertUser();
         }
       });
   progressDialog.setMax(total);
   progressDialog.show();
 }
 /**
  * this method show the dialog when its is enabled
  *
  * @param id ID of the Dialog box
  * @return Dialog Returns the Dialog box based on the ID
  */
 protected Dialog onCreateDialog(int id) {
   switch (id) {
     case L10NConstants.DIALOG_WPS:
       dialWPS = plaindialogCreater("Applying Changes to softAP...");
       return dialWPS;
     case L10NConstants.DIALOG_WPS_SESSION:
       dialWPSsession = plaindialogCreater(L10NConstants.WPS_SESSION_MSG);
       dialWPSsession.setTitle("WPS Session is On");
       dialWPSsession.setButton(ProgressDialog.BUTTON_POSITIVE, "OK", this);
       return dialWPSsession;
     case L10NConstants.DIALOG_WPS_PINENTRY:
       dialWPSpinentry = plaindialogCreater(sPinEntryMsg);
       dialWPSpinentry.setTitle("WPS Session is On");
       dialWPSpinentry.setButton(ProgressDialog.BUTTON_POSITIVE, "OK", this);
       return dialWPSpinentry;
   }
   return null;
 }
  /** Sets up the look and actions for the progress dialog while the GPS is searching. */
  private void setupLocationDialog() {
    Collect.getInstance()
        .getActivityLogger()
        .logInstanceAction(this, "setupLocationDialog", "show");
    // dialog displayed while fetching gps location
    mLocationDialog = new ProgressDialog(this);
    DialogInterface.OnClickListener geopointButtonListener =
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            switch (which) {
              case DialogInterface.BUTTON_POSITIVE:
                Collect.getInstance()
                    .getActivityLogger()
                    .logInstanceAction(this, "acceptLocation", "OK");
                returnLocation();
                break;
              case DialogInterface.BUTTON_NEGATIVE:
                Collect.getInstance()
                    .getActivityLogger()
                    .logInstanceAction(this, "cancelLocation", "cancel");
                mLocation = null;
                finish();
                break;
            }
          }
        };

    // back button doesn't cancel
    mLocationDialog.setCancelable(false);
    mLocationDialog.setIndeterminate(true);
    mLocationDialog.setIcon(android.R.drawable.ic_dialog_info);
    mLocationDialog.setTitle(getString(R.string.getting_location));
    mLocationDialog.setMessage(getString(R.string.please_wait_long));
    mLocationDialog.setButton(
        DialogInterface.BUTTON_POSITIVE,
        getString(R.string.accept_location),
        geopointButtonListener);
    mLocationDialog.setButton(
        DialogInterface.BUTTON_NEGATIVE,
        getString(R.string.cancel_location),
        geopointButtonListener);
  }
Example #10
0
  private void connect(BookmarkBase bookmark) {
    session = GlobalApp.createSession(bookmark);
    session.setUIEventListener(this);

    // set writeable data directory
    LibFreeRDP.setDataDirectory(session.getInstance(), getFilesDir().toString());

    BookmarkBase.ScreenSettings screenSettings = session.getBookmark().getActiveScreenSettings();
    Log.v(TAG, "Screen Resolution: " + screenSettings.getResolutionString());
    if (screenSettings.isAutomatic()) {
      if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
          >= Configuration.SCREENLAYOUT_SIZE_LARGE) {
        // large screen device i.e. tablet: simply use screen info
        screenSettings.setHeight(screen_height);
        screenSettings.setWidth(screen_width);
      } else {
        // small screen device i.e. phone:
        // Automatic uses the largest side length of the screen and makes a 16:10 resolution setting
        // out of it
        int screenMax = (screen_width > screen_height) ? screen_width : screen_height;
        screenSettings.setHeight(screenMax);
        screenSettings.setWidth((int) ((float) screenMax * 1.6f));
      }
    }

    progressDialog = new ProgressDialog(this);
    progressDialog.setTitle(bookmark.getLabel());
    progressDialog.setMessage(getResources().getText(R.string.dlg_msg_connecting));
    progressDialog.setButton(
        ProgressDialog.BUTTON_NEGATIVE,
        "Cancel",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            connectCancelledByUser = true;
            LibFreeRDP.cancelConnection(session.getInstance());
          }
        });
    progressDialog.setCancelable(false);
    progressDialog.show();

    Thread thread =
        new Thread(
            new Runnable() {
              public void run() {
                session.connect();
              }
            });
    thread.start();
  }
  @Override
  protected Dialog onCreateDialog(int id) {
    switch (id) {
      case PROGRESS_DIALOG:
        Collect.getInstance()
            .getActivityLogger()
            .logAction(this, "onCreateDialog.PROGRESS_DIALOG", "show");

        mProgressDialog = new ProgressDialog(this);
        DialogInterface.OnClickListener loadingButtonListener =
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                Collect.getInstance()
                    .getActivityLogger()
                    .logAction(this, "onCreateDialog.PROGRESS_DIALOG", "cancel");
                dialog.dismiss();
                mUlTask.cancel(true);
                mUlTask.setUploaderListener(null);
                finish();
              }
            };
        mProgressDialog.setTitle(getString(R.string.uploading_data));
        mProgressDialog.setMessage(mAlertMsg);
        mProgressDialog.setIndeterminate(true);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        mProgressDialog.setCancelable(false);
        mProgressDialog.setButton(getString(R.string.cancel), loadingButtonListener);
        return mProgressDialog;
      case GOOGLE_USER_DIALOG:
        AlertDialog.Builder gudBuilder = new AlertDialog.Builder(this);

        gudBuilder.setTitle(getString(R.string.no_google_account));
        gudBuilder.setMessage(getString(R.string.gme_set_account));
        gudBuilder.setPositiveButton(
            R.string.ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                finish();
              }
            });
        gudBuilder.setCancelable(false);
        return gudBuilder.create();
    }
    return null;
  }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {

    mDialog = new ProgressDialog(getActivity());
    if (mBody != null && mBody.length() > 0) {
      mDialog.setMessage(mBody);
    }

    mDialog.setCancelable(false);

    mDialog.setProgressStyle(mStyle);
    if (mStyle != ProgressDialog.STYLE_SPINNER) {
      mDialog.setMax(mProgressMax);
      mDialog.setIndeterminate(false);
      mDialog.setButton(
          DialogInterface.BUTTON_NEGATIVE,
          getString(android.R.string.cancel),
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              if (mListener != null) {
                mListener.onNegativeButtonSelected(getTag());
              }
              dialog.dismiss();
            }
          });
    } else {
      mDialog.setIndeterminate(true);
    }
    mDialog.setProgress(50);
    // Disable the back button
    OnKeyListener keyListener =
        new OnKeyListener() {

          @Override
          public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

            if (keyCode == KeyEvent.KEYCODE_BACK) {
              return true;
            }
            return false;
          }
        };
    mDialog.setOnKeyListener(keyListener);
    return mDialog;
  }
Example #13
0
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.btnDefault:
        pd = new ProgressDialog(this);
        pd.setTitle("Default");
        pd.setMessage("No limit");
        pd.setButton(
            Dialog.BUTTON_POSITIVE,
            "OK",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {}
            });
        pd.show();
        break;
      case R.id.btnHoriz:
        pd = new ProgressDialog(this);
        pd.setTitle("Horizontal");
        pd.setMessage("I see end of this");
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setMax(2150);
        pd.setIndeterminate(true);
        pd.show();

        h =
            new Handler() {
              public void handleMessage(Message msg) {
                pd.setIndeterminate(false);
                if (pd.getProgress() < pd.getMax()) {
                  pd.incrementProgressBy(50);
                  pd.incrementSecondaryProgressBy(61);
                  h.sendEmptyMessageDelayed(0, 100);
                } else {
                  pd.dismiss();
                }
              }
            };
        h.sendEmptyMessageDelayed(0, 2000);
        break;
      default:
        break;
    }
  }
Example #14
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        Intent intent = new Intent();
        intent.setClassName(UP_ACTIVITY_PACKAGE, UP_ACTIVITY_CLASS);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
        return true;
      case MENU_IMPORT_ALL:
        CharSequence title = getString(R.string.importAllSimEntries);
        CharSequence message = getString(R.string.importingSimContacts);

        thread = new ImportAllSimContactsThread();

        // TODO: need to show some error dialog.
        if (mCursor == null) {
          Log.e(LOG_TAG, "cursor is null. Ignore silently.");
          break;
        } else if (mCursor.getCount() == 0) {
          break;
        }
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setTitle(title);
        mProgressDialog.setMessage(message);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        mProgressDialog.setButton(
            DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel), thread);
        mProgressDialog.setProgress(0);
        mProgressDialog.setCanceledOnTouchOutside(false);
        mProgressDialog.setMax(mCursor.getCount());
        mProgressDialog.show();

        nCursor = mCursor;
        if (nCursor != null) {
          thread.start();
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
Example #15
0
 protected Dialog onCreateDialog(int id) {
   switch (id) {
     case 0:
       mProgress = new ProgressDialog(this);
       mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
       mProgress.setTitle("Updating");
       mProgress.setMessage("Wait...");
       mProgress.setCancelable(false);
       mProgress.setButton(
           "Cancel",
           new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int whichButton) {
               mQuit = true;
               dismissDialog(0);
             }
           });
       return mProgress;
   }
   return null;
 }
 private void showTransportDialog() {
   transportDialog = new ProgressDialog(context);
   transportDialog.setIndeterminate(false);
   transportDialog.setMax(100);
   transportDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
   transportDialog.setProgress(0);
   transportDialog.setButton(
       DialogInterface.BUTTON_NEGATIVE,
       context.getString(R.string.dialog_btn_cancel),
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
           isCanceled = true;
           dialog.dismiss();
         }
       });
   transportDialog.show();
   transportDialog.setCancelable(false);
   transportDialog.setCanceledOnTouchOutside(false);
 }
Example #17
0
  public void showDialog(boolean run) {

    if (run) {
      dialog = new ProgressDialog(this);
      dialog.setTitle("Dialog");
      dialog.setMessage("Pleas Waite...");
      dialog.setButton(
          "Cancel",
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              cancelTask();
            }
          });
      dialog.show();

    } else {

      dialog.dismiss();
    }
  }
 @Override
 protected Dialog onCreateDialog(int id) {
   switch (id) {
     case PROGRESS_DIALOG:
       mProgressDialog = new ProgressDialog(this);
       DialogInterface.OnClickListener loadingButtonListener =
           new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) {
               dialog.dismiss();
               mInstanceUploaderTask.setUploaderListener(null);
               finish();
             }
           };
       mProgressDialog.setTitle(getString(R.string.uploading_data));
       mProgressDialog.setMessage(getString(R.string.please_wait));
       mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
       mProgressDialog.setCancelable(false);
       mProgressDialog.setMax(0);
       mProgressDialog.setButton(getString(R.string.cancel), loadingButtonListener);
       return mProgressDialog;
   }
   return null;
 }
  private void startDownload(int progress) {
    progress = Math.max(0, progress);
    if (mDownloader == null) {
      mDownloader = new PageDownloader(getApplicationContext(), book);
      mDownloader.setCurrentPosition(0);
      mDownloader.setOnDownloadListener(
          new PageDownloader.OnDownloadListener() {
            @Override
            public void onFinish(int position, final int progress) {
              if (mDialogDownloading == null) return;
              runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      mDialogDownloading.setProgress(
                          Utility.calcProgress(progress, book.pageCount));
                      mDialogDownloading.setMessage(
                          (mDownloader.isPause() ? getString(R.string.dialog_download_paused) : "")
                              + getString(
                                  R.string.dialog_download_progress, progress, book.pageCount));
                    }
                  });
            }

            @Override
            public void onError(int position, int errorCode) {}

            @Override
            public void onStateChange(int state, final int progress) {
              switch (state) {
                case PageDownloader.STATE_STOP:
                  if (mDialogDownloading == null) return;
                  runOnUiThread(
                      new Runnable() {
                        @Override
                        public void run() {
                          mDialogDownloading.dismiss();
                        }
                      });
                  break;
                case PageDownloader.STATE_PAUSE:
                  if (mDialogDownloading == null) return;
                  runOnUiThread(
                      new Runnable() {
                        @Override
                        public void run() {
                          mDialogDownloading.setMessage(
                              (mDownloader.isPause()
                                      ? getString(R.string.dialog_download_paused)
                                      : "")
                                  + getString(
                                      R.string.dialog_download_progress, progress, book.pageCount));
                        }
                      });
                  break;
                case PageDownloader.STATE_ALL_OK:
                  startCopyToExternal();
                  break;
              }
            }
          });
    }

    mDialogDownloading = new ProgressDialog(BookDetailsActivity.this);
    mDialogDownloading.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    mDialogDownloading.setCancelable(false);
    mDialogDownloading.setCanceledOnTouchOutside(false);
    mDialogDownloading.setMax(100);
    mDialogDownloading.setProgress(Utility.calcProgress(progress, book.pageCount));
    mDialogDownloading.setTitle(
        getString(R.string.dialog_download_title, book.getAvailableTitle()));
    mDialogDownloading.setMessage(
        getString(R.string.dialog_download_progress, progress, book.pageCount));
    mDialogDownloading.setButton(
        DialogInterface.BUTTON_POSITIVE,
        getString(R.string.dialog_download_pause),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialogInterface, int i) {
            if (mDownloader.isThreadAllOk()) return;
            if (mDownloader.isDownloading()) {
              mDownloader.pause();
            } else {
              mDownloader.continueDownload();
            }
          }
        });
    mDialogDownloading.setButton(
        DialogInterface.BUTTON_NEGATIVE,
        getString(android.R.string.cancel),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialogInterface, int i) {
            mDownloader.stop();
          }
        });
    /**
     * mDialogDownloading.setButton( DialogInterface.BUTTON_NEUTRAL,
     * getString(R.string.dialog_download_restart), new DialogInterface.OnClickListener()
     * { @Override public void onClick(DialogInterface dialogInterface, int i) { if
     * (mDownloader.isThreadAllOk()) return; mDownloader.start(); } } ); *
     */
    mDialogDownloading.show();
    mFileCacheManager.saveBookDataToExternalPath(book);
    mDownloader.start();
  }
Example #20
0
  @Override
  protected Dialog onCreateDialog(int id) {
    super.onCreateDialog(id);
    final Activity activity = this;
    AlertDialog alertDialog;
    final ProgressDialog progressDialog = new ProgressDialog(this);
    SyncService currentService = SyncManager.getInstance().getCurrentService();
    String serviceDescription = currentService.getDescription();
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);

    switch (id) {
      case DIALOG_SYNC:
        progressDialog.setIndeterminate(true);
        progressDialog.setTitle(String.format(getString(R.string.syncing), serviceDescription));
        progressDialog.setMessage(dialogString);
        progressDialog.setOnCancelListener(
            new DialogInterface.OnCancelListener() {

              public void onCancel(DialogInterface dialog) {
                SyncManager.getInstance().cancel();
              }
            });
        progressDialog.setButton(
            ProgressDialog.BUTTON_NEGATIVE,
            getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
                progressDialog.cancel();
              }
            });
        return progressDialog;
      case DIALOG_AUTH_PROGRESS:
        authProgressDialog = new ProgressDialog(this);
        authProgressDialog.setTitle("");
        authProgressDialog.setMessage(getString(R.string.prefSyncCompleteAuth));
        authProgressDialog.setIndeterminate(true);
        authProgressDialog.setCancelable(false);
        return authProgressDialog;
      case DIALOG_ABOUT:
        // grab version info
        String ver;
        try {
          ver = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        } catch (NameNotFoundException e) {
          e.printStackTrace();
          ver = "Not found!";
          return null;
        }

        // format the string
        String aboutDialogFormat = getString(R.string.strAbout);
        String aboutDialogStr =
            String.format(
                aboutDialogFormat,
                getString(R.string.app_desc), // App description
                getString(R.string.author), // Author name
                ver // Version
                );

        // build and show the dialog
        return new AlertDialog.Builder(this)
            .setMessage(aboutDialogStr)
            .setTitle(getString(R.string.titleAbout))
            .setIcon(R.drawable.icon)
            .setNegativeButton(
                getString(R.string.btnProjectPage),
                new OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse(Tomdroid.PROJECT_HOMEPAGE)));
                    dialog.dismiss();
                  }
                })
            .setPositiveButton(
                getString(R.string.btnOk),
                new OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                  }
                })
            .create();
      case DIALOG_FIRST_RUN:
        return new AlertDialog.Builder(this)
            .setMessage(getString(R.string.strWelcome))
            .setTitle(getString(R.string.titleWelcome))
            .setNeutralButton(
                getString(R.string.btnOk),
                new OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    Preferences.putBoolean(Preferences.Key.FIRST_RUN, false);
                    dialog.dismiss();
                  }
                })
            .setIcon(R.drawable.icon)
            .create();
      case DIALOG_NOT_FOUND:
        addCommonNoteNotFoundDialogElements(builder);
        return builder.create();
      case DIALOG_NOT_FOUND_SHORTCUT:
        addCommonNoteNotFoundDialogElements(builder);
        final Intent removeIntent =
            new NoteViewShortcutsHelper(this).getRemoveShortcutIntent(dialogString, uri);
        builder.setPositiveButton(
            getString(R.string.btnRemoveShortcut),
            new OnClickListener() {
              public void onClick(final DialogInterface dialogInterface, final int i) {
                sendBroadcast(removeIntent);
                finish();
              }
            });
        return builder.create();
      case DIALOG_PARSE_ERROR:
        return new AlertDialog.Builder(this)
            .setMessage(getString(R.string.messageErrorNoteParsing))
            .setTitle(getString(R.string.error))
            .setNeutralButton(
                getString(R.string.btnOk),
                new OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    showNote(true);
                  }
                })
            .create();
      case DIALOG_REVERT_ALL:
        return new AlertDialog.Builder(this)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle(R.string.revert_notes)
            .setMessage(R.string.revert_notes_message)
            .setPositiveButton(
                getString(R.string.yes),
                new OnClickListener() {

                  public void onClick(DialogInterface dialog, int which) {
                    resetSyncValues();
                    startSyncing(false);
                  }
                })
            .setNegativeButton(R.string.no, null)
            .create();
      case DIALOG_CONNECT_FAILED:
        return new AlertDialog.Builder(this)
            .setMessage(getString(R.string.prefSyncConnectionFailed))
            .setNeutralButton(
                getString(R.string.btnOk),
                new OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                  }
                })
            .create();
      case DIALOG_DELETE_NOTE:
        return new AlertDialog.Builder(this)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle(R.string.delete_note)
            .setMessage(R.string.delete_message)
            .setPositiveButton(getString(R.string.yes), null)
            .setNegativeButton(R.string.no, null)
            .create();
      case DIALOG_REVERT_NOTE:
        return new AlertDialog.Builder(this)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle(R.string.revert_note)
            .setMessage(R.string.revert_note_message)
            .setPositiveButton(getString(R.string.yes), null)
            .setNegativeButton(R.string.no, null)
            .create();
      case DIALOG_SYNC_ERRORS:
        return new AlertDialog.Builder(activity)
            .setTitle(getString(R.string.error))
            .setMessage(dialogString)
            .setPositiveButton(getString(R.string.yes), null)
            .setNegativeButton(
                getString(R.string.close),
                new OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    finishSync();
                  }
                })
            .create();
      case DIALOG_SEND_CHOOSE:
        final Uri intentUri = Uri.parse(dialogString);
        return new AlertDialog.Builder(activity)
            .setMessage(getString(R.string.sendChoice))
            .setTitle(getString(R.string.sendChoiceTitle))
            .setPositiveButton(getString(R.string.btnSendAsFile), null)
            .setNegativeButton(getString(R.string.btnSendAsText), null)
            .create();
      case DIALOG_VIEW_TAGS:
        dialogInput = new EditText(this);
        return new AlertDialog.Builder(activity)
            .setMessage(getString(R.string.edit_tags))
            .setTitle(String.format(getString(R.string.note_x_tags), dialogNote.getTitle()))
            .setView(dialogInput)
            .setNegativeButton(
                R.string.btnCancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                    removeDialog(DIALOG_VIEW_TAGS);
                  }
                })
            .setPositiveButton(R.string.btnOk, null)
            .create();
      default:
        alertDialog = null;
    }
    return alertDialog;
  }
  @Override
  protected Dialog onCreateDialog(int id) {
    switch (id) {
      case DIALOG_YES_NO_MESSAGE:
        return new AlertDialog.Builder(AlertDialogSamples.this)
            .setIconAttribute(android.R.attr.alertDialogIcon)
            .setTitle(R.string.alert_dialog_two_buttons_title)
            .setPositiveButton(
                R.string.alert_dialog_ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked OK so do some stuff */
                  }
                })
            .setNegativeButton(
                R.string.alert_dialog_cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked Cancel so do some stuff */
                  }
                })
            .create();
      case DIALOG_YES_NO_OLD_SCHOOL_MESSAGE:
        return new AlertDialog.Builder(AlertDialogSamples.this, AlertDialog.THEME_TRADITIONAL)
            .setIconAttribute(android.R.attr.alertDialogIcon)
            .setTitle(R.string.alert_dialog_two_buttons_title)
            .setPositiveButton(
                R.string.alert_dialog_ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {}
                })
            .setNegativeButton(
                R.string.alert_dialog_cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {}
                })
            .create();
      case DIALOG_YES_NO_HOLO_LIGHT_MESSAGE:
        return new AlertDialog.Builder(AlertDialogSamples.this, AlertDialog.THEME_HOLO_LIGHT)
            .setIconAttribute(android.R.attr.alertDialogIcon)
            .setTitle(R.string.alert_dialog_two_buttons_title)
            .setPositiveButton(
                R.string.alert_dialog_ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {}
                })
            .setNegativeButton(
                R.string.alert_dialog_cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {}
                })
            .create();
      case DIALOG_YES_NO_LONG_MESSAGE:
        return new AlertDialog.Builder(AlertDialogSamples.this)
            .setIconAttribute(android.R.attr.alertDialogIcon)
            .setTitle(R.string.alert_dialog_two_buttons_msg)
            .setMessage(R.string.alert_dialog_two_buttons2_msg)
            .setPositiveButton(
                R.string.alert_dialog_ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked OK so do some stuff */
                  }
                })
            .setNeutralButton(
                R.string.alert_dialog_something,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked Something so do some stuff */
                  }
                })
            .setNegativeButton(
                R.string.alert_dialog_cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked Cancel so do some stuff */
                  }
                })
            .create();
      case DIALOG_YES_NO_ULTRA_LONG_MESSAGE:
        return new AlertDialog.Builder(AlertDialogSamples.this)
            .setIconAttribute(android.R.attr.alertDialogIcon)
            .setTitle(R.string.alert_dialog_two_buttons_msg)
            .setMessage(R.string.alert_dialog_two_buttons2ultra_msg)
            .setPositiveButton(
                R.string.alert_dialog_ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked OK so do some stuff */
                  }
                })
            .setNeutralButton(
                R.string.alert_dialog_something,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked Something so do some stuff */
                  }
                })
            .setNegativeButton(
                R.string.alert_dialog_cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked Cancel so do some stuff */
                  }
                })
            .create();
      case DIALOG_LIST:
        return new AlertDialog.Builder(AlertDialogSamples.this)
            .setTitle(R.string.select_dialog)
            .setItems(
                R.array.select_dialog_items,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {

                    /* User clicked so do some stuff */
                    String[] items = getResources().getStringArray(R.array.select_dialog_items);
                    new AlertDialog.Builder(AlertDialogSamples.this)
                        .setMessage("You selected: " + which + " , " + items[which])
                        .show();
                  }
                })
            .create();
      case DIALOG_PROGRESS:
        mProgressDialog = new ProgressDialog(AlertDialogSamples.this);
        mProgressDialog.setIconAttribute(android.R.attr.alertDialogIcon);
        mProgressDialog.setTitle(R.string.select_dialog);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        mProgressDialog.setMax(MAX_PROGRESS);
        mProgressDialog.setButton(
            DialogInterface.BUTTON_POSITIVE,
            getText(R.string.alert_dialog_hide),
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {

                /* User clicked Yes so do some stuff */
              }
            });
        mProgressDialog.setButton(
            DialogInterface.BUTTON_NEGATIVE,
            getText(R.string.alert_dialog_cancel),
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {

                /* User clicked No so do some stuff */
              }
            });
        return mProgressDialog;
      case DIALOG_SINGLE_CHOICE:
        return new AlertDialog.Builder(AlertDialogSamples.this)
            .setIconAttribute(android.R.attr.alertDialogIcon)
            .setTitle(R.string.alert_dialog_single_choice)
            .setSingleChoiceItems(
                R.array.select_dialog_items2,
                0,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked on a radio button do some stuff */
                  }
                })
            .setPositiveButton(
                R.string.alert_dialog_ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked Yes so do some stuff */
                  }
                })
            .setNegativeButton(
                R.string.alert_dialog_cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked No so do some stuff */
                  }
                })
            .create();
      case DIALOG_MULTIPLE_CHOICE:
        return new AlertDialog.Builder(AlertDialogSamples.this)
            .setIcon(R.drawable.ic_popup_reminder)
            .setTitle(R.string.alert_dialog_multi_choice)
            .setMultiChoiceItems(
                R.array.select_dialog_items3,
                new boolean[] {false, true, false, true, false, false, false},
                new DialogInterface.OnMultiChoiceClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {

                    /* User clicked on a check box do some stuff */
                  }
                })
            .setPositiveButton(
                R.string.alert_dialog_ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked Yes so do some stuff */
                  }
                })
            .setNegativeButton(
                R.string.alert_dialog_cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked No so do some stuff */
                  }
                })
            .create();
      case DIALOG_MULTIPLE_CHOICE_CURSOR:
        String[] projection =
            new String[] {
              ContactsContract.Contacts._ID,
              ContactsContract.Contacts.DISPLAY_NAME,
              ContactsContract.Contacts.SEND_TO_VOICEMAIL
            };
        Cursor cursor =
            managedQuery(ContactsContract.Contacts.CONTENT_URI, projection, null, null, null);
        return new AlertDialog.Builder(AlertDialogSamples.this)
            .setIcon(R.drawable.ic_popup_reminder)
            .setTitle(R.string.alert_dialog_multi_choice_cursor)
            .setMultiChoiceItems(
                cursor,
                ContactsContract.Contacts.SEND_TO_VOICEMAIL,
                ContactsContract.Contacts.DISPLAY_NAME,
                new DialogInterface.OnMultiChoiceClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
                    Toast.makeText(
                            AlertDialogSamples.this,
                            "Readonly Demo Only - Data will not be updated",
                            Toast.LENGTH_SHORT)
                        .show();
                  }
                })
            .create();
      case DIALOG_TEXT_ENTRY:
        // This example shows how to add a custom layout to an AlertDialog
        LayoutInflater factory = LayoutInflater.from(this);
        final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
        return new AlertDialog.Builder(AlertDialogSamples.this)
            .setIconAttribute(android.R.attr.alertDialogIcon)
            .setTitle(R.string.alert_dialog_text_entry)
            .setView(textEntryView)
            .setPositiveButton(
                R.string.alert_dialog_ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked OK so do some stuff */
                  }
                })
            .setNegativeButton(
                R.string.alert_dialog_cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked cancel so do some stuff */
                  }
                })
            .create();
    }
    return null;
  }
Example #22
0
  protected void loadFriends() {
    mFriends.clear();
    //		SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new
    // String[]{Entities.PROFILE, Entities.FRIEND, Entities
    // .ESID}, new int[]{R.id.profile, R.id.name, R.id.selected});
    SimpleAdapter sa =
        new SimpleAdapter(
            SelectFriends.this,
            mFriends,
            R.layout.friend,
            new String[] {Entity.FRIEND, Entity.ESID},
            new int[] {R.id.name, R.id.selected});
    setListAdapter(sa);
    final ProgressDialog loadingDialog = new ProgressDialog(this);
    final AsyncTask<Long, String, Boolean> asyncTask =
        new AsyncTask<Long, String, Boolean>() {
          @Override
          protected Boolean doInBackground(Long... params) {
            boolean loadList = false;
            SonetCrypto sonetCrypto = SonetCrypto.getInstance(getApplicationContext());
            // load the session
            Cursor account =
                getContentResolver()
                    .query(
                        Accounts.getContentUri(SelectFriends.this),
                        new String[] {Accounts.TOKEN, Accounts.SECRET, Accounts.SERVICE},
                        Accounts._ID + "=?",
                        new String[] {Long.toString(params[0])},
                        null);
            if (account.moveToFirst()) {
              mToken = sonetCrypto.Decrypt(account.getString(0));
              mSecret = sonetCrypto.Decrypt(account.getString(1));
              mService = account.getInt(2);
            }
            account.close();
            String response;
            switch (mService) {
              case TWITTER:
                break;
              case FACEBOOK:
                Request request =
                    new Request.Builder()
                        .url(
                            String.format(
                                Facebook.FACEBOOK_FRIENDS,
                                Facebook.FACEBOOK_BASE_URL,
                                Saccess_token,
                                mToken))
                        .build();
                response = SonetHttpClient.getResponse(request);

                if (!TextUtils.isEmpty(response)) {
                  try {
                    JSONArray friends = new JSONObject(response).getJSONArray(Sdata);

                    for (int i = 0, l = friends.length(); i < l; i++) {
                      JSONObject f = friends.getJSONObject(i);
                      HashMap<String, String> newFriend = new HashMap<String, String>();
                      newFriend.put(Entity.ESID, f.getString(Sid));
                      newFriend.put(
                          Entity.PROFILE_URL,
                          String.format(Facebook.FACEBOOK_PICTURE, f.getString(Sid)));
                      newFriend.put(Entity.FRIEND, f.getString(Sname));
                      // need to alphabetize
                      if (mFriends.isEmpty()) {
                        mFriends.add(newFriend);
                      } else {
                        String fullName = f.getString(Sname);
                        int spaceIdx = fullName.lastIndexOf(" ");
                        String newFirstName = null;
                        String newLastName = null;
                        if (spaceIdx == -1) {
                          newFirstName = fullName;
                        } else {
                          newFirstName = fullName.substring(0, spaceIdx++);
                          newLastName = fullName.substring(spaceIdx);
                        }
                        List<HashMap<String, String>> newFriends =
                            new ArrayList<HashMap<String, String>>();
                        for (int i2 = 0, l2 = mFriends.size(); i2 < l2; i2++) {
                          HashMap<String, String> oldFriend = mFriends.get(i2);
                          if (newFriend == null) {
                            newFriends.add(oldFriend);
                          } else {
                            fullName = oldFriend.get(Entity.FRIEND);
                            spaceIdx = fullName.lastIndexOf(" ");
                            String oldFirstName = null;
                            String oldLastName = null;
                            if (spaceIdx == -1) {
                              oldFirstName = fullName;
                            } else {
                              oldFirstName = fullName.substring(0, spaceIdx++);
                              oldLastName = fullName.substring(spaceIdx);
                            }
                            if (newFirstName == null) {
                              newFriends.add(newFriend);
                              newFriend = null;
                            } else {
                              int comparison = oldFirstName.compareToIgnoreCase(newFirstName);
                              if (comparison == 0) {
                                // compare firstnames
                                if (newLastName == null) {
                                  newFriends.add(newFriend);
                                  newFriend = null;
                                } else if (oldLastName != null) {
                                  comparison = oldLastName.compareToIgnoreCase(newLastName);
                                  if (comparison == 0) {
                                    newFriends.add(newFriend);
                                    newFriend = null;
                                  } else if (comparison > 0) {
                                    newFriends.add(newFriend);
                                    newFriend = null;
                                  }
                                }
                              } else if (comparison > 0) {
                                newFriends.add(newFriend);
                                newFriend = null;
                              }
                            }
                            newFriends.add(oldFriend);
                          }
                        }
                        if (newFriend != null) {
                          newFriends.add(newFriend);
                        }
                        mFriends = newFriends;
                      }
                    }
                    loadList = true;
                  } catch (JSONException e) {
                    Log.e(TAG, e.toString());
                  }
                }
                break;
              case MYSPACE:
                break;
              case LINKEDIN:
                break;
              case FOURSQUARE:
                break;
              case IDENTICA:
                break;
              case GOOGLEPLUS:
                break;
              case CHATTER:
                break;
            }
            return loadList;
          }

          @Override
          protected void onPostExecute(Boolean loadList) {
            if (loadList) {
              //					SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends,
              // R.layout.friend, new String[]{Entities.PROFILE, Entities
              // .FRIEND}, new int[]{R.id.profile, R.id.name});
              SimpleAdapter sa =
                  new SimpleAdapter(
                      SelectFriends.this,
                      mFriends,
                      R.layout.friend,
                      new String[] {Entity.FRIEND, Entity.ESID},
                      new int[] {R.id.name, R.id.selected});
              sa.setViewBinder(mViewBinder);
              setListAdapter(sa);
            }
            if (loadingDialog.isShowing()) loadingDialog.dismiss();
          }
        };
    loadingDialog.setMessage(getString(R.string.loading));
    loadingDialog.setCancelable(true);
    loadingDialog.setOnCancelListener(
        new DialogInterface.OnCancelListener() {
          @Override
          public void onCancel(DialogInterface dialog) {
            if (!asyncTask.isCancelled()) {
              asyncTask.cancel(true);
            }
          }
        });
    loadingDialog.setButton(
        ProgressDialog.BUTTON_NEGATIVE,
        getString(android.R.string.cancel),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
          }
        });
    loadingDialog.show();
    asyncTask.execute(mAccountId);
  }
Example #23
0
  /*
   * Method for an activity to record audio
   */
  public String recordAudio(String text, String audioFile, View v) {
    try {
      String filePath =
          PinyinApplication.getInstance()
                  .getExternalFilesDir(Environment.DIRECTORY_MUSIC)
                  .getAbsolutePath()
              + File.separator
              + audioFile
              + ".mp3";

      final MediaRecorder recorder = new MediaRecorder();
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      recorder.setOutputFile(filePath);
      recorder.prepare();
      final ProgressDialog mProgressDialog = new RecorderProgressDialog(this);
      final Thread thread =
          new Thread() {
            @Override
            public void run() {
              try {
                sleep(10000);
                recorder.stop();
                recorder.release();
                mProgressDialog.dismiss();
              } catch (InterruptedException e) {
              }
            }
          };
      mProgressDialog.setTitle(text);
      mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
      mProgressDialog.setMessage(text);
      mProgressDialog.setButton(
          ProgressDialog.BUTTON_POSITIVE,
          "Stop",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
              thread.interrupt();
              mProgressDialog.dismiss();
              recorder.stop();
              recorder.release();
            }
          });

      mProgressDialog.setOnCancelListener(
          new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface p1) {
              thread.interrupt();
              recorder.stop();
              recorder.release();
            }
          });
      recorder.start();

      thread.start();
      mProgressDialog.show();
      return filePath;
    } catch (Exception e) {
      e.printStackTrace();
      Toast.makeText(this, R.string.problem_recording, Toast.LENGTH_SHORT).show();
    }
    return null;
  }
Example #24
0
          @Override
          public void handleMessage(Message msg) {
            try {
              switch (msg.what) {
                case MESSAGE_EXCEPTION:
                  if (Canceller.flCancel) break; // . >
                  Exception E = (Exception) msg.obj;
                  Toast.makeText(TSensorsMetersPanel.this, E.getMessage(), Toast.LENGTH_SHORT)
                      .show();
                  // .
                  break; // . >

                case MESSAGE_COMPLETED:
                  if (Canceller.flCancel) break; // . >
                  // .
                  TSensorsMetersPanel.this.Device = Device;
                  // .
                  TSensorsMetersPanel.this.MetersInfo = MetersInfo;
                  // .
                  TSensorsMetersPanel.this.Update();
                  // .
                  break; // . >

                case MESSAGE_FINISHED:
                  if (Canceller.flCancel) break; // . >
                  TSensorsMetersPanel.this.Updating = null;
                  // .
                  break; // . >

                case MESSAGE_PROGRESSBAR_SHOW:
                  progressDialog = new ProgressDialog(TSensorsMetersPanel.this);
                  progressDialog.setMessage(TSensorsMetersPanel.this.getString(R.string.SLoading));
                  progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                  progressDialog.setIndeterminate(true);
                  progressDialog.setCancelable(true);
                  progressDialog.setOnCancelListener(
                      new OnCancelListener() {

                        @Override
                        public void onCancel(DialogInterface arg0) {
                          Cancel();
                          // .
                          if (flClosePanelOnCancel) TSensorsMetersPanel.this.finish();
                        }
                      });
                  progressDialog.setButton(
                      ProgressDialog.BUTTON_NEGATIVE,
                      TSensorsMetersPanel.this.getString(R.string.SCancel),
                      new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                          Cancel();
                          // .
                          if (flClosePanelOnCancel) TSensorsMetersPanel.this.finish();
                        }
                      });
                  // .
                  progressDialog.show();
                  // .
                  break; // . >

                case MESSAGE_PROGRESSBAR_HIDE:
                  if ((!isFinishing()) && progressDialog.isShowing())
                    try {
                      progressDialog.dismiss();
                    } catch (IllegalArgumentException IAE) {
                    }
                  // .
                  break; // . >

                case MESSAGE_PROGRESSBAR_PROGRESS:
                  progressDialog.setProgress((Integer) msg.obj);
                  // .
                  break; // . >
              }
            } catch (Throwable E) {
              TGeoLogApplication.Log_WriteError(E);
            }
          }
Example #25
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fin_splash);
    manual = false;

    db = new FINDatabase(this).getReadableDatabase();

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    rid = prefs.getInt("rid", 0);

    if (rid == 0) {
      // Acquire a reference to the system Location Manager
      final LocationManager locationManager =
          (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

      // Define a listener that responds to location updates
      final LocationListener locationListener =
          new LocationListener() {
            public void onLocationChanged(Location location) {
              SharedPreferences.Editor editor = prefs.edit();

              editor.putInt("location_lat", (int) (location.getLatitude() * 1E6));
              editor.putInt("location_lon", (int) (location.getLatitude() * 1E6));
              editor.commit();

              handler4.sendEmptyMessage(0);

              locationManager.removeUpdates(this);
            }

            public void onStatusChanged(String provider, int status, Bundle extras) {}

            public void onProviderEnabled(String provider) {}

            public void onProviderDisabled(String provider) {}
          };

      // Register the listener with the Location Manager to receive location updates
      locationManager.requestLocationUpdates(
          LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

      myDialog = new ProgressDialog(this);
      myDialog.setTitle("Welcome to FIN");
      myDialog.setMessage("Please wait while we detect the regions nearest you...");
      myDialog.setIcon(R.drawable.icon);
      myDialog.setCancelable(false);
      myDialog.setButton(
          "Manually Choose",
          new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
              locationManager.removeUpdates(locationListener);
              manual = true;
              myDialog.dismiss();
              handler4.sendEmptyMessage(0);
            }
          });
      myDialog.show();
    } else {
      handler3.sendEmptyMessage(0);
    }

    // thread for displaying the SplashScreen
    splashThread =
        new Thread() {

          @Override
          public void run() {

            Intent myIntent = null;

            // Set color theme (hardcoded for now).
            Cursor cursor =
                db.query(
                    "colors", null, "rid = " + prefs.getInt("rid", 0) + "", null, null, null, null);
            cursor.moveToFirst();
            String color = cursor.getString(cursor.getColumnIndex("color1"));

            cursor =
                db.query(
                    "regions",
                    null,
                    "rid = " + prefs.getInt("rid", 0) + "",
                    null,
                    null,
                    null,
                    null);
            cursor.moveToFirst();
            campus = cursor.getString(cursor.getColumnIndex("name"));

            // Set default location
            handler.sendEmptyMessage(0);

            myIntent = new Intent(getBaseContext(), FINHome.class);
            myIntent.addCategory("App Startup");

            // Check logged in status
            final String phone_id =
                Secure.getString(getBaseContext().getContentResolver(), Secure.ANDROID_ID);

            String loggedinstr = DBCommunicator.loggedIn(phone_id, getBaseContext());
            boolean loggedin = loggedinstr.contains(getString(R.string.login_already));

            campusJson =
                DBCommunicator.getRegions(
                    prefs.getInt("location_lat", 0) + "",
                    prefs.getInt("location_lon", 0) + "",
                    getBaseContext());
            if (!campusJson.equals(getString(R.string.timeout)))
              JsonParser.parseRegionJson(campusJson, getBaseContext());

            String categories = DBCommunicator.getCategories(getBaseContext());
            if (!categories.equals(getString(R.string.timeout)))
              JsonParser.parseCategoriesList(categories, getBaseContext());

            String buildings =
                DBCommunicator.getBuildings(prefs.getInt("rid", 0) + "", getBaseContext());
            if (!buildings.equals(getString(R.string.timeout)))
              JsonParser.parseBuildingJson(buildings, getBaseContext());

            String items = DBCommunicator.getItems(prefs.getInt("rid", 0) + "", getBaseContext());
            if (!items.equals(getString(R.string.timeout)))
              JsonParser.parseItemJson(items, getBaseContext());

            SharedPreferences.Editor editor = prefs.edit();
            editor.putBoolean("loggedin", loggedin);
            editor.putString("lastOpened", System.currentTimeMillis() / 1000 + "");
            editor.putString("color", color);
            editor.commit();

            if (loggedin) {
              myIntent.putExtra("username", loggedinstr.substring(21, loggedinstr.length()));
            }

            try {
              int waited = 0;

              while (active && (waited < splashTime)) {
                sleep(100);
                if (active) {
                  waited += 100;
                }
              }
            } catch (InterruptedException e) {
              // do nothing
            } finally {
              cursor.close();

              startActivity(myIntent);
              finish();
            }
          }
        };
  }
  @Override
  protected Dialog onCreateDialog(int id) {
    switch (id) {
      case PROGRESS_DIALOG:
        Collect.getInstance()
            .getActivityLogger()
            .logAction(this, "onCreateDialog.PROGRESS_DIALOG", "show");

        mProgressDialog = new ProgressDialog(this);
        DialogInterface.OnClickListener loadingButtonListener =
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                Collect.getInstance()
                    .getActivityLogger()
                    .logAction(this, "onCreateDialog.PROGRESS_DIALOG", "cancel");
                dialog.dismiss();
                mInstanceUploaderTask.cancel(true);
                mInstanceUploaderTask.setUploaderListener(null);
                finish();
              }
            };
        mProgressDialog.setTitle(getString(R.string.uploading_data));
        mProgressDialog.setMessage(mAlertMsg);
        mProgressDialog.setIndeterminate(true);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        mProgressDialog.setCancelable(false);
        mProgressDialog.setButton(getString(R.string.cancel), loadingButtonListener);
        return mProgressDialog;
      case AUTH_DIALOG:
        Log.i(
            t,
            "onCreateDialog(AUTH_DIALOG): for upload of "
                + mInstancesToSend.length
                + " instances!");
        Collect.getInstance()
            .getActivityLogger()
            .logAction(this, "onCreateDialog.AUTH_DIALOG", "show");
        AlertDialog.Builder b = new AlertDialog.Builder(this);

        LayoutInflater factory = LayoutInflater.from(this);
        final View dialogView = factory.inflate(R.layout.server_auth_dialog, null);

        // Get the server, username, and password from the settings
        SharedPreferences settings =
            PreferenceManager.getDefaultSharedPreferences(getBaseContext());

        String server = mUrl;
        if (server == null) {
          Log.e(
              t,
              "onCreateDialog(AUTH_DIALOG): No failing mUrl specified for upload of "
                  + mInstancesToSend.length
                  + " instances!");
          // if the bundle is null, we're looking for a formlist
          String submissionUrl = getString(R.string.default_odk_submission);
          server =
              settings.getString(
                      PreferencesActivity.KEY_SERVER_URL, getString(R.string.default_server_url))
                  + settings.getString(PreferencesActivity.KEY_SUBMISSION_URL, submissionUrl);
        }

        final String url = server;

        Log.i(t, "Trying connecting to: " + url);

        EditText username = (EditText) dialogView.findViewById(R.id.username_edit);
        String storedUsername = settings.getString(PreferencesActivity.KEY_USERNAME, null);
        username.setText(storedUsername);

        EditText password = (EditText) dialogView.findViewById(R.id.password_edit);
        String storedPassword = settings.getString(PreferencesActivity.KEY_PASSWORD, null);
        password.setText(storedPassword);

        b.setTitle(getString(R.string.server_requires_auth));
        b.setMessage(getString(R.string.server_auth_credentials, url));
        b.setView(dialogView);
        b.setPositiveButton(
            R.string.ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                Collect.getInstance()
                    .getActivityLogger()
                    .logAction(this, "onCreateDialog.AUTH_DIALOG", "OK");
                EditText username = (EditText) dialogView.findViewById(R.id.username_edit);
                EditText password = (EditText) dialogView.findViewById(R.id.password_edit);

                Uri u = Uri.parse(url);
                WebUtils.addCredentials(
                    username.getText().toString(), password.getText().toString(), u.getHost());

                showDialog(PROGRESS_DIALOG);
                mInstanceUploaderTask = new InstanceUploaderTask();

                // register this activity with the new uploader task
                mInstanceUploaderTask.setUploaderListener(InstanceUploaderActivity.this);

                mInstanceUploaderTask.execute(mInstancesToSend);
              }
            });
        b.setNegativeButton(
            R.string.cancel,
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
                Collect.getInstance()
                    .getActivityLogger()
                    .logAction(this, "onCreateDialog.AUTH_DIALOG", "cancel");
                finish();
              }
            });

        b.setCancelable(false);
        return b.create();
    }
    return null;
  }
  // so there is question of checking for existing items (auto-completion?)
  // and uploading sounds and images ...
  public void onClick(View v) {
    EditText cueInput = (EditText) findViewById(R.id.cue);
    EditText responseInput = (EditText) findViewById(R.id.response);
    Spinner posInput = (Spinner) findViewById(R.id.pos);
    EditText characterResponseInput = (EditText) findViewById(R.id.response_character);
    EditText characterCueInput = (EditText) findViewById(R.id.cue_character);
    final String cue = cueInput.getText().toString();
    final String response = responseInput.getText().toString();
    final String pos = posInput.getSelectedItem().toString();
    final String character_cue = characterCueInput.getText().toString();
    final String character_response = characterResponseInput.getText().toString();
    String pos_code = Utils.POS_MAP.get(pos);
    if (TextUtils.isEmpty(pos_code)) {
      pos_code = "NONE";
    }
    final String final_pos_code = pos_code;

    if (Main.isNotLoggedIn(this)) {
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.setClassName(this, LoginActivity.class.getName());
      intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid
      // navigation
      // back to this?
      LoginActivity.return_to = CreateItemActivity.class.getName();
      LoginActivity.params = new HashMap<String, String>();
      LoginActivity.params.put("list_id", list_id);
      LoginActivity.params.put("cue", cue);
      LoginActivity.params.put("response", response);
      LoginActivity.params.put("cue_language", cue_language);
      LoginActivity.params.put("response_language", response_language);
      LoginActivity.params.put("pos", pos);
      LoginActivity.params.put("character_cue", character_cue);
      LoginActivity.params.put("character_response", character_response);
      startActivity(intent);
    } else {
      // TODO cue and response languages need to be inferred from list we are
      // adding to ... Might want to fix those, i.e. not allow variation
      // on
      // search ...
      // TODO wondering whether there is some way to edit existing items
      // ...

      final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
      myOtherProgressDialog.setTitle("Please Wait ...");
      myOtherProgressDialog.setMessage("Creating Item ...");
      myOtherProgressDialog.setIndeterminate(true);
      myOtherProgressDialog.setCancelable(true);

      final Thread create_item =
          new Thread() {
            public void run() {
              // TODO make this interruptable .../*if
              // (!this.isInterrupted())*/
              CreateItemActivity.create_item_result =
                  createItem(
                      cue,
                      cue_language,
                      character_cue,
                      final_pos_code,
                      response,
                      response_language,
                      character_response,
                      list_id);

              myOtherProgressDialog.dismiss();
            }
          };
      myOtherProgressDialog.setButton(
          "Cancel",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
              create_item.interrupt();
            }
          });
      OnCancelListener ocl =
          new OnCancelListener() {
            public void onCancel(DialogInterface arg0) {
              create_item.interrupt();
            }
          };
      myOtherProgressDialog.setOnCancelListener(ocl);
      myOtherProgressDialog.show();
      create_item.start();
    }
  }