@Override
 protected void onPostExecute(Boolean result) {
   // marca datas disponiveis
   if (result) {
     highlightDailyScheduleList(selectedProfFreeCalendars);
   } else {
     screenCalendar.clearHighlightedDates();
     screenCalendar.unselectDate(selectedDate);
     finishUpViewLoad();
     Ping ping = new Ping();
     if (!ping.check()) {
       Toast.makeText(
               getActivity(),
               mParentActivity.getResources().getString(R.string.err_no_connection_try_again),
               Toast.LENGTH_LONG)
           .show();
     } else {
       Toast.makeText(
               getActivity(),
               mParentActivity.getResources().getString(R.string.err_toast),
               Toast.LENGTH_LONG)
           .show();
     }
   }
   finishFullViewLoad();
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nutrients_new_item);

    setTag(this.getClass().getSimpleName());
    // set activity name
    toolbarsManager = new ToolbarsManager(this);
    toolbarsManager.setNameActivity(this.getTitle().toString());

    nutrientsDBAdapter = new NutrientsDBAdapter();
    newName = (EditText) findViewById(R.id.nutrients_new_name);
    newProteins = (EditText) findViewById(R.id.nutrients_new_proteins);
    newFats = (EditText) findViewById(R.id.nutrients_new_fats);
    newCarbs = (EditText) findViewById(R.id.nutrients_new_carbs);
    newCalories = (EditText) findViewById(R.id.nutrients_new_calories);

    warningToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
    toastText = (TextView) warningToast.getView().findViewById(android.R.id.message);
    toastText.setTextColor(Color.RED);

    intent = getIntent();
    if (intent.getAction().equals(Intent.ACTION_EDIT))
      atEdit = true; // It's updating existing item, not inserting
    else atEdit = false; // It's inserting new row
  }
Beispiel #3
0
 @Override
 protected void handlerData() {
   if (quoteData == null) {
     if (btnTag == 2) {
       Toast.makeText(Bill.this, "读取数据失败!请刷新或者重新设置网络。。", Toast.LENGTH_LONG).show();
       super.onPageUp();
       hiddenProgressToolBar();
       return;
     }
     fillNullCurrentPageContent(this);
     hiddenProgressToolBar();
     if (type == 1 || btnTag == 3) { // 进去页面请求 或 刷新
       Toast.makeText(Bill.this, "读取数据失败!请刷新或者重新设置网络。。", Toast.LENGTH_LONG).show();
       setToolBar(0, false, R.color.zr_dimgray);
       setToolBar(1, false, R.color.zr_dimgray);
       setToolBar(2, false, R.color.zr_dimgray);
     }
     return;
   } else {
     try {
       String res = TradeUtil.checkResult(quoteData);
       if (res != null) {
         if (!("-1").equals(res)) toast(res);
         hiddenProgressToolBar();
         return;
       }
       totalRecordCount = allRecords.length();
       fillCurrentPageContent(this);
     } catch (Exception e) {
       hiddenProgressToolBar();
     }
   }
   hiddenProgressToolBar();
   setBtnStatus();
 }
 public void doAfterPostSuccess(String s, int articleId) {
   if (s.equals("IOException")) {
     Toast.makeText(
             getActivity().getApplicationContext(),
             "Server not available, please contact application owner",
             Toast.LENGTH_SHORT)
         .show();
     mAdapter.notifyDataSetChanged();
     swipeLayout.setRefreshing(false);
     return;
   }
   addNewArticleToUser(s, articleId);
   done++;
   Log.d("SVF", "Done " + done + " out of " + topics.length());
   if (done == topics.length()) {
     swipeLayout.setRefreshing(false);
     ValuesAndUtil.getInstance().saveUserData(user, getActivity().getApplicationContext());
     try {
       JSONArray sortedTopics =
           ValuesAndUtil.getInstance().sortTopicsArray(user.getJSONArray("topics"));
       user.put("topics", sortedTopics);
       ValuesAndUtil.getInstance().saveUserData(user, getActivity().getApplicationContext());
       mAdapter = new StoriesViewAdapter(sortedTopics);
       if (numUpdated == 0) {
         Toast.makeText(getActivity(), "No updates found for any stories", Toast.LENGTH_SHORT)
             .show();
       }
     } catch (JSONException e) {
       e.printStackTrace();
     }
     mRecyclerView.setAdapter(mAdapter);
     Log.d("SVF", "Finished updating all articles");
   }
 }
 public void refreshWeather(int flag, boolean isAuto, boolean broadcast) {
   if (!Help.networkState(mContext) && !broadcast) {
     Log.d(TAG, "network is disabled");
     return;
   }
   SharedPreferences preferences =
       mContext.getSharedPreferences("controller", Context.MODE_PRIVATE);
   long lastTime = preferences.getLong("last_time_fetch_datas", 0);
   boolean isSuccess = preferences.getBoolean("update_success", true);
   if (System.currentTimeMillis() - lastTime > 1000 * 3600 * 2) {
     updateWeather(flag, preferences);
   } else if (System.currentTimeMillis() - lastTime <= 1000 * 3600 * 2 && isSuccess && !isAuto) {
     Toast.makeText(
             mContext,
             "It's unnecessary to update so frequently. Updating every 2h maybe is better.",
             Toast.LENGTH_SHORT)
         .show();
   } else if (System.currentTimeMillis() - lastTime <= 1000 * 10 && !isSuccess && !isAuto) {
     Toast.makeText(
             mContext, "Last update was fail. Just wait another ten second!", Toast.LENGTH_SHORT)
         .show();
   } else if (System.currentTimeMillis() - lastTime > 1000 * 10 && !isSuccess) {
     updateWeather(flag, preferences);
   } else if (System.currentTimeMillis() - lastTime > 1000 * 3600 * 3 && broadcast) {
     updateWeather(flag, preferences);
   }
   //        else if (broadcast && System.currentTimeMillis() - lastTime > 1000 * 3600 * 2) {
   //            updateWeather(flag, preferences);
   //        }
 }
Beispiel #6
0
  private void playFile() {
    if (playingFile == null || !playingFile.isFile()) resetPlayingFile();
    if (playingFile == null) {
      Toast.makeText(AndroidWave.this, "Cannot play file", Toast.LENGTH_SHORT).show();
      return;
    }
    if (mp != null) mp.stop();
    Log.d("file to play", playingFile.getAbsolutePath());
    mp = MediaPlayer.create(AndroidWave.this, Uri.fromFile(playingFile));
    if (mp == null) {
      Toast.makeText(AndroidWave.this, "Cannot play file", Toast.LENGTH_SHORT).show();
      return;
    }
    mp.setOnCompletionListener(
        new OnCompletionListener() {

          @Override
          public void onCompletion(MediaPlayer arg0) {
            stopPlayFile();
          }
        });
    sm.stop();
    mp.start();
    playButton.setText(R.string.stop);
    playButton.setBackgroundColor(0xFF009900);
  }
 @Override
 public void onInfoWindowClick(Marker marker) {
   if (marker.getTitle().equals(getString(R.string.Marker_NotRegistered))) {
     // 未登録のマーカーであれば情報を追加する
     // 地点情報追加画面に遷移
     Intent intent = new Intent(this, AddPlaceActivity.class);
     intent.putExtra("latitude", marker.getPosition().latitude);
     intent.putExtra("longitude", marker.getPosition().longitude);
     startActivityForResult(intent, 123);
   }
   PlaceInfo pInfo = new PlaceInfo();
   pInfo.mMarker = marker;
   if (mPlaceInfoList.contains(pInfo)) {
     // マーカーの詳細情報画面を開く
     Intent intent = new Intent(this, DisplayDetailActivity.class);
     PlaceInfo pClone = mPlaceInfoList.get(mPlaceInfoList.indexOf(pInfo)).getSeralizable();
     intent.putExtra("placeInfo", pClone);
     try {
       startActivity(intent);
     } catch (RuntimeException e) {
       Toast t = Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG);
       t.show();
       e.getStackTrace();
     }
   }
 }
  // This method will trigger on item Click of navigation menu
  @Override
  public boolean onNavigationItemSelected(MenuItem menuItem) {

    // Checking if the item is in checked state or not, if not make it in checked state
    if (menuItem.isChecked()) menuItem.setChecked(false);
    else menuItem.setChecked(true);

    // Closing drawer on item click
    drawerLayout.closeDrawers();

    // Check to see which item was being clicked and perform appropriate action
    switch (menuItem.getItemId()) {
      case R.id.option_1:
        Toast.makeText(getApplicationContext(), "Option 1 Selected", Toast.LENGTH_SHORT).show();
        launchHomeFragment();
        return true;

      case R.id.option_2:
        Toast.makeText(getApplicationContext(), "Option 2 Selected", Toast.LENGTH_SHORT).show();
        return true;
      case R.id.option_3:
        Toast.makeText(getApplicationContext(), "Option 3 Selected", Toast.LENGTH_SHORT).show();
        return true;
      default:
        Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show();
        return true;
    }
  }
Beispiel #9
0
  @SuppressWarnings("StatementWithEmptyBody")
  @Override
  public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_camara) {
      // Handle the camera action
    } else if (id == R.id.nav_gallery) {

      Toast.makeText(getApplicationContext(), "Galeria", Toast.LENGTH_SHORT).show();

    } else if (id == R.id.nav_slideshow) {

      Toast.makeText(getApplicationContext(), "Slideshow", Toast.LENGTH_SHORT).show();

    } else if (id == R.id.nav_manage) {

      Toast.makeText(getApplicationContext(), "Manage", Toast.LENGTH_SHORT).show();

    } else if (id == R.id.nav_share) {

      Toast.makeText(getApplicationContext(), "Share", Toast.LENGTH_SHORT).show();

    } else if (id == R.id.nav_send) {

      Toast.makeText(getApplicationContext(), "Send", Toast.LENGTH_SHORT).show();
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
  }
    @Override
    protected void onPostExecute(ArtistsPager artistsPager) {
      myArtistListQuery = new ArrayList<MyArtist>();
      customAdapterSpotify.clear();

      if (artistsPager != null && !artistsPager.artists.items.isEmpty()) {
        MyArtist myArtist;
        for (Artist artist : artistsPager.artists.items) {

          if (artist.images.isEmpty()) {
            myArtist = new MyArtist(artist.name, artist.id);
          } else {
            myArtist = new MyArtist(artist.name, artist.images.get(0).url, artist.id);
          }
          // List to save for recovering when resume application
          myArtistListQuery.add(myArtist);
          // Add to ArrayAdapter
          customAdapterSpotify.add(myArtist);
        }
      } else {
        Toast toast =
            Toast.makeText(
                getActivity(), res.getString(R.string.no_artist_found), Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
      }
    }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // mounted sdcard ?
    if (!Environment.getExternalStorageState().equals("mounted")) {
      Log.e(GlobalConstants.LOG_TAG, "External storage is not mounted");

      Toast toast =
          Toast.makeText(
              getApplicationContext(), "External storage not mounted", Toast.LENGTH_LONG);
      toast.show();
      return;
    }

    // install needed ?
    boolean installNeeded = isInstallNeeded();

    if (installNeeded) {
      setContentView(R.layout.install);
      new InstallAsyncTask().execute();
    } else {
      runScriptService();
      finish();
    }

    // onStart();
  }
Beispiel #12
0
  /**
   * computes a geopoint the is the central geopoint between the user and the car. also it zooms so
   * both marks are visible on the map
   *
   * @author ricky barrette
   */
  protected void showBoth() {
    if (mMap != null) {
      if (mCarPoint == null) {
        Toast.makeText(getActivity(), R.string.mark_car_first, Toast.LENGTH_LONG).show();
      } else if (mMap.getUserLocation() == null) {
        Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
      } else {
        if (mMap.getMap() != null) {
          mMap.getMap().getController().stopAnimation(false);
          mMap.followUser(false);
          final GeoPoint user = mMap.getUserLocation();

          /*
           * here we null check our next set of value before we send
           * them off to geoutils if they have became null for some
           * reason we disable show both mode
           */
          if (mCarPoint != null && user != null) {
            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        mHandler.sendMessage(
                            mHandler.obtainMessage(MIDPOINT, GeoUtils.midPoint(mCarPoint, user)));
                      }
                    })
                .start();
          }

        } else {
          Log.e(TAG, "showBoth.mMap.getMap() is null");
        }
      }
    }
  }
        @Override
        public void handleMessage(Message msg) {

          if (msg != null) {
            switch (msg.what) {
              case TOAST_HANDLER_MESSAGE_SENT:
                Toast.makeText(
                        SmsReceiverService.this,
                        SmsReceiverService.this.getString(R.string.quickreply_sent_toast),
                        Toast.LENGTH_SHORT)
                    .show();
                break;
              case TOAST_HANDLER_MESSAGE_SEND_LATER:
                Toast.makeText(
                        SmsReceiverService.this,
                        SmsReceiverService.this.getString(R.string.quickreply_failed_send_later),
                        Toast.LENGTH_SHORT)
                    .show();
                break;
              case TOAST_HANDLER_MESSAGE_FAILED:
                Toast.makeText(
                        SmsReceiverService.this,
                        SmsReceiverService.this.getString(R.string.quickreply_failed),
                        Toast.LENGTH_SHORT)
                    .show();
                break;
            }
          }
        }
 @Override
 protected void onPostExecute(Boolean result) {
   // marca datas disponiveis
   if (result) {
     highlightProfessionalDTOList(
         selectedDateFreeProfessionalDTOSet, unavailableProfessionalsSet);
   } else {
     selectedDateFreeProfessionalDTOSet.clear();
     screenCalendar.unselectDate(selectedDate);
     highlightProfessionalDTOList(
         selectedDateFreeProfessionalDTOSet, unavailableProfessionalsSet);
     finishDownViewLoad();
     Ping ping = new Ping();
     if (!ping.check()) {
       Toast.makeText(
               getActivity(),
               mParentActivity.getResources().getString(R.string.err_no_connection_try_again),
               Toast.LENGTH_LONG)
           .show();
     } else {
       Toast.makeText(
               getActivity(),
               mParentActivity.getResources().getString(R.string.err_toast),
               Toast.LENGTH_LONG)
           .show();
     }
   }
   finishFullViewLoad();
 }
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.reset_btn:
        if (reset_password1.getText().toString().trim().length() < 8) {
          Toast.makeText(this, "密码须大于8位", Toast.LENGTH_SHORT).show();
        } else if (!reset_password1
            .getText()
            .toString()
            .equals(reset_password2.getText().toString())) {
          Toast.makeText(this, "输入的两次密码不相等", Toast.LENGTH_SHORT).show();
        } else {
          HttpUtils.resetPassword(
              res,
              phone.replaceAll(" ", ""),
              reset_password2.getText().toString().replaceAll(" ", ""));
        }
        break;
      case R.id.register_back:
        super.finish();
        overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
        break;
      case R.id.policy:
        Intent intent = new Intent(E8_ResetPwdActivity.this, E13_User_policy_Activity.class);
        startActivity(intent);
        this.overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
        break;

      default:
        break;
    }
  }
  // ------------------------------------------------------------------------------------------
  private void selectErrorMessageToShow(int statusCode) {

    switch (statusCode) {
      case 400:

      case 401:

      case 403:

      case 404:
        Toast.makeText(this, ErrorMessage.ERROR_MESSAGE_INPUT, Toast.LENGTH_SHORT).show();
        break;

      case 500:
        Toast.makeText(this, ErrorMessage.ERROR_MESSAGE_SERVER, Toast.LENGTH_SHORT).show();
        break;

      case 502:
        Toast.makeText(this, ErrorMessage.ERROR_MESSAGE_BADGATEWAY, Toast.LENGTH_SHORT).show();
        break;

      case 503:
        Toast.makeText(this, ErrorMessage.ERROR_MESSAGE_SERVICE_UNAVAILABLE, Toast.LENGTH_SHORT)
            .show();
        break;

      default:
        Toast.makeText(this, ErrorMessage.ERROR_MESSAGE_INPUT, Toast.LENGTH_SHORT).show();
        break;
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setTitle(R.string.title_devices);
    mHandler = new Handler();

    // Use this check to determine whether BLE is supported on the device.  Then you can
    // selectively disable BLE-related features.
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
      Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
      finish();
    }

    // Initializes a Bluetooth adapter.  For API level 18 and above, get a reference to
    // BluetoothAdapter through BluetoothManager.
    final BluetoothManager bluetoothManager =
        (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothAdapter = bluetoothManager.getAdapter();

    // Checks if Bluetooth is supported on the device.
    if (mBluetoothAdapter == null) {
      Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show();
      finish();
      return;
    }

    Log.i("SCAN", "" + mBluetoothAdapter.isMultipleAdvertisementSupported());
    Log.i("SCAN", "" + mBluetoothAdapter.isOffloadedFilteringSupported());
    Log.i("SCAN", "" + mBluetoothAdapter.isOffloadedScanBatchingSupported());
  }
        @Override
        public boolean onLongClick(View v) {

          int nBtnID = v.getId();
          // If the mode is not changed, open the setting view. If the mode is same, close the
          // setting view.
          if (nBtnID == mPenBtn.getId()) {
            mSCanvas.setSettingViewSizeOption(
                SCanvasConstants.SCANVAS_SETTINGVIEW_PEN,
                SCanvasConstants.SCANVAS_SETTINGVIEW_SIZE_MINI);
            if (mSCanvas.getCanvasMode() == SCanvasConstants.SCANVAS_MODE_INPUT_PEN) {
              mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_PEN);
            } else {
              mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
              mSCanvas.showSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_PEN, true);
              updateModeState();
            }
            return true;
          } else if (nBtnID == mEraserBtn.getId()) {
            mSCanvas.setSettingViewSizeOption(
                SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER,
                SCanvasConstants.SCANVAS_SETTINGVIEW_SIZE_MINI);
            if (mSCanvas.getCanvasMode() == SCanvasConstants.SCANVAS_MODE_INPUT_ERASER) {
              mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER);
            } else {
              mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_ERASER);
              mSCanvas.showSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER, true);
              updateModeState();
            }
            return true;
          } else if (nBtnID == mTextBtn.getId()) {
            mSCanvas.setSettingViewSizeOption(
                SCanvasConstants.SCANVAS_SETTINGVIEW_TEXT,
                SCanvasConstants.SCANVAS_SETTINGVIEW_SIZE_MINI);
            if (mSCanvas.getCanvasMode() == SCanvasConstants.SCANVAS_MODE_INPUT_TEXT) {
              mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_TEXT);
            } else {
              mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_TEXT);
              mSCanvas.showSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_TEXT, true);
              updateModeState();
              Toast.makeText(mContext, "Tap Canvas to insert Text", Toast.LENGTH_SHORT).show();
            }
            return true;
          } else if (nBtnID == mFillingBtn.getId()) {
            mSCanvas.setSettingViewSizeOption(
                SCanvasConstants.SCANVAS_SETTINGVIEW_FILLING,
                SCanvasConstants.SCANVAS_SETTINGVIEW_SIZE_MINI);
            if (mSCanvas.getCanvasMode() == SCanvasConstants.SCANVAS_MODE_INPUT_FILLING) {
              mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_FILLING);
            } else {
              mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_FILLING);
              mSCanvas.showSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_FILLING, true);
              updateModeState();
              Toast.makeText(mContext, "Tap Canvas to fill color", Toast.LENGTH_SHORT).show();
            }
            return true;
          }

          return false;
        }
  void stopRecord() {
    recording = false;
    sendBroadcast(new Intent(C.actionSetIconRecord));
    try {
      mW.flush();
      mW.close();
      mW = null;

      // http://stackoverflow.com/questions/13737261/nexus-4-not-showing-files-via-mtp
      //			MediaScannerConnection.scanFile(this, new String[] { mFile.getAbsolutePath() }, null,
      // null);
      // http://stackoverflow.com/questions/5739140/mediascannerconnection-produces-android-app-serviceconnectionleaked
      sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE).setData(Uri.fromFile(mFile)));

      Toast.makeText(
              this,
              new StringBuilder()
                  .append(getString(R.string.app_name))
                  .append("Record-")
                  .append(getDate())
                  .append(".csv ")
                  .append(getString(R.string.notify_toast_saved)),
              Toast.LENGTH_LONG)
          .show();
    } catch (Exception e) {
      e.printStackTrace();
      Toast.makeText(
              this,
              getString(R.string.notify_toast_error) + " " + e.getMessage(),
              Toast.LENGTH_LONG)
          .show();
    }
    topRow = true;
    mNM.notify(10, mNotificationRead);
  }
Beispiel #20
0
  /**
   * Wipe the device.
   *
   * @param code - Operation code.
   * @param data - Data required by the operation(PIN).
   */
  public void wipeDevice(String code, String data) {
    String inputPin;
    String savedPin = Preference.getString(context, resources.getString(R.string.shared_pref_pin));

    try {
      JSONObject wipeKey = new JSONObject(data);
      inputPin = (String) wipeKey.get(resources.getString(R.string.shared_pref_pin));
      String status;
      if (inputPin.trim().equals(savedPin.trim())) {
        status = resources.getString(R.string.shared_pref_default_status);
      } else {
        status = resources.getString(R.string.shared_pref_false_status);
      }

      resultBuilder.build(code, status);

      if (inputPin.trim().equals(savedPin.trim())) {
        Toast.makeText(context, resources.getString(R.string.toast_message_wipe), Toast.LENGTH_LONG)
            .show();
        try {
          Thread.sleep(PRE_WIPE_WAIT_TIME);
        } catch (InterruptedException e) {
          Log.e(TAG, "Wipe pause interrupted :" + e.toString());
        }
        devicePolicyManager.wipeData(ACTIVATION_REQUEST);
      } else {
        Toast.makeText(
                context, resources.getString(R.string.toast_message_wipe_failed), Toast.LENGTH_LONG)
            .show();
      }
    } catch (JSONException e) {
      Log.e(TAG, "Invalid JSON format." + e);
    }
  }
  // TODO: if uploadingComplete() when activity backgrounded, won't work.
  public void uploadingComplete(ArrayList<String> result) {

    int resultSize = result.size();
    boolean success = false;
    if (resultSize == totalCount) {
      Toast.makeText(
              this, getString(R.string.upload_all_successful, totalCount), Toast.LENGTH_SHORT)
          .show();

      success = true;
    } else {
      String s = totalCount - resultSize + " of " + totalCount;
      Toast.makeText(this, getString(R.string.upload_some_failed, s), Toast.LENGTH_LONG).show();
    }

    Intent in = new Intent();
    in.putExtra(GlobalConstants.KEY_SUCCESS, success);
    setResult(RESULT_OK, in);

    // for each path, update the status
    FileDbAdapter fda = new FileDbAdapter(this);
    fda.open();
    for (int i = 0; i < resultSize; i++) {
      Cursor c = fda.fetchFilesByPath(result.get(i), null);
      if (c != null) {
        if (c.getString(c.getColumnIndex(FileDbAdapter.KEY_STATUS))
            .equals(FileDbAdapter.STATUS_COMPLETED))
          fda.updateFile(result.get(i), FileDbAdapter.STATUS_SUBMITTED, null);
      }
    }
    fda.close();
    finish();
  }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   // Check which request we're responding to
   if (requestCode == Tango.TANGO_INTENT_ACTIVITYCODE) {
     Log.i(TAG, "Triggered");
     // Make sure the request was successful
     if (resultCode == RESULT_CANCELED) {
       Toast.makeText(this, R.string.motiontrackingpermission, Toast.LENGTH_LONG).show();
       finish();
       return;
     }
     try {
       setTangoListeners();
     } catch (TangoErrorException e) {
       Toast.makeText(this, R.string.TangoError, Toast.LENGTH_SHORT).show();
     } catch (SecurityException e) {
       Toast.makeText(
               getApplicationContext(), R.string.motiontrackingpermission, Toast.LENGTH_SHORT)
           .show();
     }
     try {
       mTango.connect(mConfig);
       mIsTangoServiceConnected = true;
     } catch (TangoOutOfDateException outDateEx) {
       if (mTangoUx != null) {
         mTangoUx.showTangoOutOfDate();
       }
     } catch (TangoErrorException e) {
       Toast.makeText(getApplicationContext(), R.string.TangoError, Toast.LENGTH_SHORT).show();
     }
     setUpExtrinsics();
   }
 }
 @Override
 public void onLoadPatchListenerReceiveFail(
     final File patchFile, int errorCode, final boolean isUpgrade) {
   super.onLoadPatchListenerReceiveFail(patchFile, errorCode, isUpgrade);
   switch (errorCode) {
     case ShareConstants.ERROR_PATCH_NOTEXIST:
       Toast.makeText(context, "patch file is not exist", Toast.LENGTH_LONG).show();
       break;
     case ShareConstants.ERROR_PATCH_RUNNING:
       // try later
       // only retry for upgrade patch
       if (isUpgrade) {
         handler.postDelayed(
             new Runnable() {
               @Override
               public void run() {
                 TinkerInstaller.onReceiveUpgradePatch(context, patchFile.getAbsolutePath());
               }
             },
             60 * 1000);
       }
       break;
     case Utils.ERROR_PATCH_ROM_SPACE:
       Toast.makeText(context, "rom space is not enough", Toast.LENGTH_LONG).show();
       break;
   }
   SampleTinkerReport.onTryApplyFail(errorCode);
 }
  private void setUpExtrinsics() {
    // Set device to imu matrix in Model Matrix Calculator.
    TangoPoseData device2IMUPose = new TangoPoseData();
    TangoCoordinateFramePair framePair = new TangoCoordinateFramePair();
    framePair.baseFrame = TangoPoseData.COORDINATE_FRAME_IMU;
    framePair.targetFrame = TangoPoseData.COORDINATE_FRAME_DEVICE;
    try {
      device2IMUPose = mTango.getPoseAtTime(0.0, framePair);
    } catch (TangoErrorException e) {
      Toast.makeText(getApplicationContext(), R.string.TangoError, Toast.LENGTH_SHORT).show();
    }
    mRenderer
        .getModelMatCalculator()
        .SetDevice2IMUMatrix(
            device2IMUPose.getTranslationAsFloats(), device2IMUPose.getRotationAsFloats());

    // Set color camera to imu matrix in Model Matrix Calculator.
    TangoPoseData color2IMUPose = new TangoPoseData();

    framePair.baseFrame = TangoPoseData.COORDINATE_FRAME_IMU;
    framePair.targetFrame = TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR;
    try {
      color2IMUPose = mTango.getPoseAtTime(0.0, framePair);
    } catch (TangoErrorException e) {
      Toast.makeText(getApplicationContext(), R.string.TangoError, Toast.LENGTH_SHORT).show();
    }
    mRenderer
        .getModelMatCalculator()
        .SetColorCamera2IMUMatrix(
            color2IMUPose.getTranslationAsFloats(), color2IMUPose.getRotationAsFloats());
  }
  public void accept(View view) {

    if (checkCorrectFill()) {

      if (atEdit) {
        Toast.makeText(this, "Product changed", Toast.LENGTH_SHORT).show();
        nutrientsDBAdapter.updateRowById(
            intent.getIntExtra(GlycemicIndexDBAdapter.KEY_ROWID, 0),
            newName.getText().toString().trim(),
            Float.parseFloat(newProteins.getText().toString()),
            Float.parseFloat(newFats.getText().toString()),
            Float.parseFloat(newCarbs.getText().toString()),
            Float.parseFloat(newCalories.getText().toString()));

        navigateBack();
      } else {
        Toast.makeText(this, "Product added", Toast.LENGTH_SHORT).show();
        // insert
        nutrientsDBAdapter.insertNewRow(
            newName.getText().toString().trim(),
            Float.parseFloat(newProteins.getText().toString()),
            Float.parseFloat(newFats.getText().toString()),
            Float.parseFloat(newCarbs.getText().toString()),
            Float.parseFloat(newCalories.getText().toString()));

        // clear forms
        newName.getEditableText().clear();
        newProteins.getEditableText().clear();
        newFats.getEditableText().clear();
        newCarbs.getEditableText().clear();
        newCalories.getEditableText().clear();
      }
    }
  }
Beispiel #26
0
  public void attemptLogin() {
    String loginName = mNameView.getText().toString();
    String mPassword = mPasswordView.getText().toString();
    boolean cancel = false;
    View focusView = null;

    if (TextUtils.isEmpty(mPassword)) {
      Toast.makeText(this, getString(R.string.error_pwd_required), Toast.LENGTH_SHORT).show();
      focusView = mPasswordView;
      cancel = true;
    }

    if (TextUtils.isEmpty(loginName)) {
      Toast.makeText(this, getString(R.string.error_name_required), Toast.LENGTH_SHORT).show();
      focusView = mNameView;
      cancel = true;
    }

    if (cancel) {
      focusView.requestFocus();
    } else {
      showProgress(true);
      if (imService != null) {
        //				boolean userNameChanged = true;
        //				boolean pwdChanged = true;
        loginName = loginName.trim();
        mPassword = mPassword.trim();
        imService.getLoginManager().login(loginName, mPassword);
      }
    }
  }
 @Override
 public void onTaskFinished(String response) {
   progress.cancel();
   if (response == null) {
     Toast.makeText(this, "An error has occured.", Toast.LENGTH_LONG).show();
     onResume();
     return;
   } else if (response == LocationHelper.LOCATION_FAILED) {
     Toast.makeText(this, "Unable to determine your location.", Toast.LENGTH_LONG).show();
     onResume();
     return;
   }
   Document doc = Jsoup.parse(response);
   if (doc.title().contains("Route")) {
     RouteActivity.start(HomeActivity.this, response);
   } else if (doc.title().contains("Stop")) {
     System.out.println(doc.title());
   } else if (response.contains("Did you mean?")
       && (response.contains("class=\"routeList\"")
           || response.contains("class=\"ambiguousLocations\""))) {
     new DidYouMeanDialog()
         .newInstance(this, response)
         .show(getSupportFragmentManager(), "com.steelhawks.hawkscout.DID_YOU_MEAN_DIALOG");
   } else if (response.contains("<h3>Nearby Stops:</h3>")) {
     NearbyStopsActivity.start(this, response);
   } else {
     new NoResultsDialog()
         .show(getSupportFragmentManager(), "com.steelhawks.hawkscout.NO_RESULTS");
     onResume();
   }
 }
  public void apply(View v) {
    // read raw values from the input widgets
    master_switch = switch_master_switch.isChecked();
    left_margin = Integer.parseInt(ET_left_margin.getText().toString());
    right_margin = Integer.parseInt(ET_right_margin.getText().toString());
    top_margin = Integer.parseInt(ET_top_margin.getText().toString());
    bottom_margin = Integer.parseInt(ET_bottom_margin.getText().toString());

    // save the values
    Editor editor = pref.edit();
    editor.putBoolean(Keys.MASTER_SWITCH, master_switch);
    editor.putInt(Keys.LEFT_MARGIN, left_margin);
    editor.putInt(Keys.RIGHT_MARGIN, right_margin);
    editor.putInt(Keys.TOP_MARGIN, top_margin);
    editor.putInt(Keys.BOTTOM_MARGIN, bottom_margin);
    editor.apply();

    int viewH = (screen_height - top_margin - bottom_margin);
    Log.d("VIEW H", Integer.toString(viewH));

    int viewW = screen_width - left_margin - right_margin;
    Log.d("VIEW W", Integer.toString(viewW));

    Toast.makeText(this, "Changes applied!", Toast.LENGTH_SHORT).show();
    if (viewW < screen_width * 0.5 || viewH < screen_height * 0.5)
      Toast.makeText(this, "Warning, the view area may be too small!", Toast.LENGTH_LONG).show();
    if (left_margin > screen_width
        || top_margin > screen_height
        || right_margin < 0
        || bottom_margin < 0)
      Toast.makeText(this, "Your view area goes off the screen!", Toast.LENGTH_LONG).show();

    finish();
  }
    public void onLocationChanged(Location location) {

      String message =
          String.format(
              "New Location \n Longitude: %1$s \n Latitude: %2$s",
              location.getLongitude(), location.getLatitude());
      Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
      if (Math.abs(oldlat - location.getLatitude()) + Math.abs(oldlong - location.getLongitude())
          > 0) ;
      oldlat = location.getLatitude();
      oldlong = location.getLongitude();

      dbh.addPlace(oldlat, oldlong, 2.2);
      Toast.makeText(MainActivity.this, "Newer", Toast.LENGTH_LONG).show();
      List<location> contacts = dbh.getAllplaces();
      location newc = new location();
      newc.setlong("6.9");
      newc.setlat("9.6");
      newc.ID = 5;
      newc.radius = 2.0;
      dbh.deleteplace(newc);
      for (location cn : contacts) {
        Toast.makeText(MainActivity.this, "" + cn.getlat(), Toast.LENGTH_LONG).show();
      }
    }
  private void setInfoFromPict(Uri imageUri) {

    Bitmap resizedBitmap = RamenUtil.getResizedBitmap(imageUri, this);
    ((ImageView) findViewById(R.id.img_ramenpict)).setImageBitmap(resizedBitmap);

    ExifInterface exifInterface = null;
    try {
      ContentResolver resolver = getContentResolver();
      Cursor cursor = resolver.query(imageUri, null, null, null, null);
      cursor.moveToFirst();
      String filepath = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA));

      exifInterface = new ExifInterface(filepath);

    } catch (Exception e) {
      e.printStackTrace();
    }

    float[] latLong = new float[2];
    exifInterface.getLatLong(latLong);

    if (latLong[0] != 0.0f || latLong[1] != 0.0f) {
      ((EditText) findViewById(R.id.txt_lat)).setText(String.valueOf(latLong[0]));
      ((EditText) findViewById(R.id.txt_lon)).setText(String.valueOf(latLong[1]));
      Toast.makeText(this, "写真の位置情報を自動入力しました", Toast.LENGTH_SHORT).show();
    } else {
      Toast.makeText(this, "写真の位置情報が含まれていません。経度緯度を入力してください。", Toast.LENGTH_SHORT).show();
    }
  }