Beispiel #1
0
 private void createMonitorAlarm() {
   AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
   Intent intent = new Intent(this, MonitoringAlarmReceiver.class);
   PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
   // the monitoring alarm will schedule another alarm once it's finished
   alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pendingIntent);
 }
  /**
   * Saves the image on the SD card and inserts a record into the DB.
   *
   * @param lastPic the image to save
   * @return the filename of the saved image
   */
  public String saveImage(byte[] lastPic) {
    final String imageFileName = String.valueOf(System.currentTimeMillis()) + ".jpg";

    File root = Environment.getExternalStorageDirectory();

    // create the note folder if it doesn't exist
    File folder = new File(root, Note.FOLDER_PREFIX);
    if (!folder.isDirectory()) folder.mkdir();

    // decode the image into a Bitmap
    Bitmap bmp = BitmapFactory.decodeByteArray(lastPic, 0, lastPic.length);

    File targetFile = new File(folder, imageFileName);
    FileOutputStream out = null;
    try {
      out = new FileOutputStream(targetFile);
      if (!bmp.compress(Bitmap.CompressFormat.JPEG, 90, out))
        throw new IOException("Error writing bmp to stream!");
      db.addNewImage(imageFileName);
    } catch (IOException e) {
      Log.e(SBActivity.TAG, "Error writing image file", e);
    } finally {
      try {
        out.close();
      } catch (Exception e) {
        // ignore
      }
    }

    return imageFileName;
  }
Beispiel #3
0
  /** 刷新本地全局搜索粉丝 */
  private void refreshLocalFans() {
    long last_refresh_all_fans_time =
        PreferenceUtils.getLong(context, Constant.LAST_REFRESH_ALLFANS_TIME, 0);
    long currentTime = System.currentTimeMillis();

    if (currentTime - last_refresh_all_fans_time > THREE_HOUR) {

      int empID = PreferenceUtils.getInt(context, Constant.PREFERENCE_EMP_ID, 0);
      HttpRequestController.fansGroup(
          context,
          empID,
          5,
          1000,
          1,
          1,
          1,
          new HttpResponseListener<ApiFansGroup.ApiFansGroupResponse>() {
            @Override
            public void onResult(ApiFansGroup.ApiFansGroupResponse response) {
              if (response.getRetCode() == BaseResponse.RET_HTTP_STATUS_OK) {
                List<Fans> fans = response.fansGroupResult.fans;
                MyLogger.i(TAG, "fans: " + fans.size());

                ApiAllFansInfoDb.delete(context);
                ApiAllFansInfoDb.bulkInsert(context, fans);
                PreferenceUtils.putLong(
                    context, Constant.LAST_REFRESH_ALLFANS_TIME, System.currentTimeMillis());
              }
              // Utils.toast(context, "" + response.getRetInfo());
            }
          });
    }
  }
  /** Notify user when they have a score that's a multiple of ten. */
  private void generateScoreNotification() {
    int suc = Score.getSuccesses();
    int mod = suc % 10;

    if (suc < 0 || mod != 0) return;

    String title = "MathApp Score";
    String text = "MathApp score reached " + suc + " points!";

    Intent onTrigger = new Intent(this, ActivityScore.class);
    PendingIntent pending =
        PendingIntent.getActivity(this, 0, onTrigger, Intent.FLAG_ACTIVITY_NEW_TASK);

    int nResID = R.drawable.ic_launcher;
    String nText = title;
    long nTime = System.currentTimeMillis();

    Notification notification = new Notification(nResID, nText, nTime);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.setLatestEventInfo(this, title, text, pending);

    NotificationManager manager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(0, notification);
  }
    @Override
    public void onScroll(
        AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
      if (loading) {
        if (totalItemCount > previousTotal) {
          loading = false;
          previousTotal = totalItemCount;
          currentPage++;
        }
      }

      if (!loading
          && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
        tcallbacks.LoadDataForScroll(totalItemCount);
        loading = true;
      }

      if (previousFirstVisibleItem != firstVisibleItem) {
        currTime = System.currentTimeMillis();
        timeToScrollOneElement = currTime - previousEventTime;
        speed = ((double) 1 / timeToScrollOneElement) * 1000;

        previousFirstVisibleItem = firstVisibleItem;
        previousEventTime = currTime;
      }
    }
  private void setState(State state) {
    this.state = state;
    switch (state) {
      case PULL_TO_REFRESH:
        spinner.setVisibility(View.INVISIBLE);
        image.setVisibility(View.VISIBLE);
        text.setText(pullToRefreshText);

        if (showLastUpdatedText && lastUpdated != -1) {
          lastUpdatedTextView.setVisibility(View.VISIBLE);
          lastUpdatedTextView.setText(
              String.format(lastUpdatedText, lastUpdatedDateFormat.format(new Date(lastUpdated))));
        }

        break;

      case RELEASE_TO_REFRESH:
        spinner.setVisibility(View.INVISIBLE);
        image.setVisibility(View.VISIBLE);
        text.setText(releaseToRefreshText);
        break;

      case REFRESHING:
        setUiRefreshing();

        lastUpdated = System.currentTimeMillis();
        if (onRefreshListener == null) {
          setState(State.PULL_TO_REFRESH);
        } else {
          onRefreshListener.onRefresh();
        }

        break;
    }
  }
  // initialize moving to center animation
  private void startAnimateToCenter(long duration) {
    startFlingX = ring.getPaddingLeft();
    startFlingY = ring.getPaddingTop();
    endFlingX = (mDisplayWidth - ringWidth) / 2;
    endFlingY = (mDisplayHeight - ringHeight) / 2;
    startTime = System.currentTimeMillis();
    endTime = startTime + duration;
    interpolator = new DecelerateInterpolator();
    isFlinging = true;

    if (DBG)
      Log.i(
          TAG,
          "startAnimateToCenter: sx="
              + startFlingX
              + " sy="
              + startFlingY
              + " ex="
              + endFlingX
              + " ey="
              + endFlingY);
    post(
        new Runnable() {
          @Override
          public void run() {
            animateToCenterStep();
          }
        });
  }
    /**
     * Constructor definition
     *
     * @param array list
     */
    ChapterListAdapter(String[] arrayList, Dialog dialog) {
      opendDialog = dialog;

      arrayListOfItems = new String[arrayList.length];
      System.arraycopy(arrayList, 0, arrayListOfItems, 0, arrayList.length);

      // clear the last selected chapter name
      selectedChapterName = "";
    }
Beispiel #9
0
 public void addEnvToIntent(Intent intent) {
   Map<String, String> envMap = System.getenv();
   Set<Map.Entry<String, String>> envSet = envMap.entrySet();
   Iterator<Map.Entry<String, String>> envIter = envSet.iterator();
   int c = 0;
   while (envIter.hasNext()) {
     Map.Entry<String, String> entry = envIter.next();
     intent.putExtra("env" + c, entry.getKey() + "=" + entry.getValue());
     c++;
   }
 }
Beispiel #10
0
  private void checkAndLaunchUpdate() {
    Log.i(LOG_FILE_NAME, "Checking for an update");

    int statusCode = 8; // UNEXPECTED_ERROR
    File baseUpdateDir = null;
    if (Build.VERSION.SDK_INT >= 8)
      baseUpdateDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
    else baseUpdateDir = new File(Environment.getExternalStorageDirectory().getPath(), "download");

    File updateDir = new File(new File(baseUpdateDir, "updates"), "0");

    File updateFile = new File(updateDir, "update.apk");
    File statusFile = new File(updateDir, "update.status");

    if (!statusFile.exists() || !readUpdateStatus(statusFile).equals("pending")) return;

    if (!updateFile.exists()) return;

    Log.i(LOG_FILE_NAME, "Update is available!");

    // Launch APK
    File updateFileToRun = new File(updateDir, getPackageName() + "-update.apk");
    try {
      if (updateFile.renameTo(updateFileToRun)) {
        String amCmd =
            "/system/bin/am start -a android.intent.action.VIEW "
                + "-n com.android.packageinstaller/.PackageInstallerActivity -d file://"
                + updateFileToRun.getPath();
        Log.i(LOG_FILE_NAME, amCmd);
        Runtime.getRuntime().exec(amCmd);
        statusCode = 0; // OK
      } else {
        Log.i(LOG_FILE_NAME, "Cannot rename the update file!");
        statusCode = 7; // WRITE_ERROR
      }
    } catch (Exception e) {
      Log.i(LOG_FILE_NAME, "error launching installer to update", e);
    }

    // Update the status file
    String status = statusCode == 0 ? "succeeded\n" : "failed: " + statusCode + "\n";

    OutputStream outStream;
    try {
      byte[] buf = status.getBytes("UTF-8");
      outStream = new FileOutputStream(statusFile);
      outStream.write(buf, 0, buf.length);
      outStream.close();
    } catch (Exception e) {
      Log.i(LOG_FILE_NAME, "error writing status file", e);
    }

    if (statusCode == 0) System.exit(0);
  }
 public int selectStatusIconIndex(MtvReservation mtvreservation)
 {
     Log.d("smali", "Lcom/samsung/sec/mtv/ui/channelguide/MtvUiFragReservationList$ReservationAdapter;->selectStatusIconIndex(Lcom/samsung/sec/mtv/provider/MtvReservation;)I");
     int i;
     if(mtvreservation.mPgmStatus == 0 && mtvreservation.mTimeStart < System.currentTimeMillis() - 5000L)
     {
         MtvUtilDebug.Mid(Log.d(), "selectStatusIconIndex() : ooops!!! hit an expired reservation,setting it failed");
         i = 1;
         MtvReservationManager.UpdateStatus(getActivity(), mtvreservation, 2);
     } else
     if(mtvreservation.mPgmStatus == 0 || mtvreservation.mPgmStatus == 6 || mtvreservation.mPgmStatus == 1)
         i = 0;
     else
         i = 1;
     return i;
 }
Beispiel #12
0
  @Override
  protected void onNewIntent(Intent intent) {
    if (checkLaunchState(LaunchState.GeckoExiting)) {
      // We're exiting and shouldn't try to do anything else just incase
      // we're hung for some reason we'll force the process to exit
      System.exit(0);
      return;
    }
    final String action = intent.getAction();
    if (ACTION_DEBUG.equals(action)
        && checkAndSetLaunchState(LaunchState.Launching, LaunchState.WaitForDebugger)) {

      mMainHandler.postDelayed(
          new Runnable() {
            public void run() {
              Log.i(LOG_FILE_NAME, "Launching from debug intent after 5s wait");
              setLaunchState(LaunchState.Launching);
              launch(null);
            }
          },
          1000 * 5 /* 5 seconds */);
      Log.i(LOG_FILE_NAME, "Intent : ACTION_DEBUG - waiting 5s before launching");
      return;
    }
    if (checkLaunchState(LaunchState.WaitForDebugger) || launch(intent)) return;

    if (Intent.ACTION_MAIN.equals(action)) {
      Log.i(LOG_FILE_NAME, "Intent : ACTION_MAIN");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(""));
    } else if (Intent.ACTION_VIEW.equals(action)) {
      String uri = intent.getDataString();
      GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
      Log.i(LOG_FILE_NAME, "onNewIntent: " + uri);
    } else if (ACTION_WEBAPP.equals(action)) {
      String uri = intent.getStringExtra("args");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
      Log.i(LOG_FILE_NAME, "Intent : WEBAPP - " + uri);
    } else if (ACTION_BOOKMARK.equals(action)) {
      String args = intent.getStringExtra("args");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(args));
      Log.i(LOG_FILE_NAME, "Intent : BOOKMARK - " + args);
    }
  }
Beispiel #13
0
  private void initializeGameSettings() {

    // m_Random = new Random(1);
    m_Random = new Random(System.currentTimeMillis());

    try {
      mTimeToAnswerQuestion =
          Integer.parseInt(m_SharedPreferences.getString("editTextPreferenceCountDownTimer", "10"));
      mTimeToAnswerQuestion *= 1000;

    } catch (ClassCastException e) {
      mTimeToAnswerQuestion = 10000;
      Log.e(TAG, e.getMessage().toString());
    }
    try {
      mDelayBetweenQuestions =
          Integer.parseInt(
              m_SharedPreferences.getString("editTextPreferenceDelayBetweenQuestions", "500"));
    } catch (ClassCastException e) {
      Log.e(TAG, e.getMessage().toString());
    }
  }
Beispiel #14
0
  private void pressAgainToExit() {
    long current = System.currentTimeMillis();
    long duration = (current - lastPressBackTime) / 1000;

    if (duration <= PRESS_AGAIN_LIMIT_DURATION) {
      runOnUiThread(
          new Runnable() {
            @Override
            public void run() {
              try {
                Thread.sleep(200);
              } catch (InterruptedException e) {
                e.printStackTrace();
              }

              //                    exitApp();
              finish();
            }
          });
    } else {
      lastPressBackTime = current;
      ToastUtil.showToast(getApplicationContext(), getString(R.string.press_again_to_exit));
    }
  }
  private void animateToCenterStep() {
    long curTime = System.currentTimeMillis();
    float percentTime = (float) (curTime - startTime) / (float) (endTime - startTime);
    float percentDistance = interpolator.getInterpolation(percentTime);

    if (DBG)
      Log.i(
          TAG,
          "animateToCenterStep: %t="
              + percentDistance
              + " %d="
              + percentDistance
              + " x="
              + (int) (percentDistance * (endFlingX - startFlingX))
              + " y="
              + (int) (percentDistance * (endFlingY - startFlingY)));
    moveRing(
        (int) (startFlingX + percentDistance * (endFlingX - startFlingX)),
        (int) (startFlingY + percentDistance * (endFlingY - startFlingY)));

    // not yet finished?
    if (percentTime < 1.0f) {
      // more!
      post(
          new Runnable() {
            @Override
            public void run() {
              animateToCenterStep();
            }
          });
    } else {
      // finished
      isFlinging = false;
      mCallback.goToUnlockScreen();
    }
  }
Beispiel #16
0
 @Override
 public void onClick(View v) {
   if (v.getId() == btnStart.getId()) {
     try {
       Intent game = new Intent(this, GameActivity.class);
       startActivity(game);
     } catch (Exception ex) {
       System.out.println(ex.getMessage());
     }
   }
   if (v.getId() == btnResume.getId()) {
     try {
       Intent game = new Intent(this, GameActivity.class);
       game.putExtra(GameActivity.RESUME_GAME, true);
       startActivity(game);
     } catch (Exception ex) {
       System.out.println(ex.getMessage());
     }
   }
   if (v.getId() == btnExit.getId()) {
     this.finish();
     System.exit(0);
   }
 }
Beispiel #17
0
 static {
   System.loadLibrary("audio-tools");
 }
Beispiel #18
0
 static {
   System.arraycopy(PROJ, 3, FROM, 0, FROM.length);
 }
 /**
  * Set the state back to 'pull to refresh'. Call this method when refreshing the data is finished.
  */
 public void onRefreshComplete() {
   state = State.PULL_TO_REFRESH;
   resetHeader();
   lastUpdated = System.currentTimeMillis();
 }
Beispiel #20
0
 private String buildTransaction(final String type) {
   return (type == null)
       ? String.valueOf(System.currentTimeMillis())
       : type + System.currentTimeMillis();
 }
  public void run() {
    int x, y;
    Bitmap locTile;
    Canvas canvas;
    float useLon, useLat, useLonMax, useLatMax;

    System.gc();
    if ((useOverlay.tileX == 0) && (useOverlay.tileY == 0)) return;
    mapThreadRunning = true;
    try {
      if (locMap == null)
        locMap = Bitmap.createBitmap(tileWidth * 256, tileHeight * 256, Bitmap.Config.ARGB_8888);
    } catch (OutOfMemoryError oome) {
      return;
    }
    locMap.eraseColor(Color.BLACK);
    canvas = new Canvas(locMap);

    useLon =
        (GeoUtils.tilex2long(useOverlay.tileX, useOverlay.m_zoom)
                + GeoUtils.tilex2long(useOverlay.tileX + 1, useOverlay.m_zoom))
            / 2.0f;
    useLat =
        (GeoUtils.tiley2lat(useOverlay.tileY, useOverlay.m_zoom)
                + GeoUtils.tiley2lat(useOverlay.tileY + 1, useOverlay.m_zoom))
            / 2.0f;

    while (mScaleFactor >= 2.0) {
      mScaleFactor /= 2.0f;
      useOverlay.m_zoom++;
      if (useOverlay.m_zoom > 17) {
        useOverlay.m_zoom = 17;
        imgOffsetX -= (scrWidth - (scrWidth * 2.0)) / 2.0;
        imgOffsetY -= (scrHeight - (scrHeight * 2.0)) / 2.0;
      }
    }
    while (mScaleFactor <= 0.5) {
      mScaleFactor *= 2.0f;
      useOverlay.m_zoom--;
      if (useOverlay.m_zoom < 3) {
        useOverlay.m_zoom = 3;
        imgOffsetX -= (scrWidth - (scrWidth * 2.0)) / 2.0;
        imgOffsetY -= (scrHeight - (scrHeight * 2.0)) / 2.0;
      }
    }
    mScaleFactor = 1.0f;

    /*      if ((wasScaleOp) && (lonCenter!=0.0f) && (latCenter!=0.0f))
    {
       tileX=GeoUtils.long2tilex(lonCenter,m_zoom);
       tileY=GeoUtils.lat2tiley(latCenter,m_zoom);

       tileX-=(scrWidth / 256);
       tileY-=(scrWidth / 256);
    }
    else*/
    {
      useOverlay.tileX = GeoUtils.long2tilex(useLon, useOverlay.m_zoom);
      useOverlay.tileY = GeoUtils.lat2tiley(useLat, useOverlay.m_zoom);
    }
    useLon = GeoUtils.tilex2long(useOverlay.tileX - 1, useOverlay.m_zoom);
    useLat = GeoUtils.tiley2lat(useOverlay.tileY - 1, useOverlay.m_zoom);
    useLonMax = GeoUtils.tilex2long(useOverlay.tileX + tileWidth + 1, useOverlay.m_zoom);
    useLatMax = GeoUtils.tiley2lat(useOverlay.tileY + tileHeight + 1, useOverlay.m_zoom);

    /*      if (imgOffsetX>scrWidth)
    {
       imgOffsetX=scrWidth/2;
    }
    if (imgOffsetX<=-scrWidth)
    {
       imgOffsetX=-scrWidth/2;
    }
    if (imgOffsetY>scrHeight)
    {
       imgOffsetY=scrHeight/2;
    }
    if (imgOffsetY<=-scrHeight)
    {
       imgOffsetY=-scrHeight/2;
    }*/

    while (imgOffsetX > 0) {
      imgOffsetX -= 256.0f;
      useOverlay.tileX--;
    }
    while (imgOffsetX <= -256.0) {
      imgOffsetX += 256.0f;
      useOverlay.tileX++;
    }
    while (imgOffsetY > 0) {
      imgOffsetY -= 256.0f;
      useOverlay.tileY--;
    }
    while (imgOffsetY <= -256.0) {
      imgOffsetY += 256.0f;
      useOverlay.tileY++;
    }

    // calculate lat/lon of screen center point
    /*      {
       int useTileX=tileX,useTileY=tileY;

       x=(int)((scrWidth/2.0f)+imgOffsetX);
       y=(int)((scrHeight/2.0f)+imgOffsetY);

       useTileX+=(x / 256);
       x=x % 256;
       useTileY+=(y / 256);
       y=y % 256;

       float tileLon1=GeoUtils.tilex2long(useTileX,m_zoom);
       float tileLat1=GeoUtils.tiley2lat(useTileY,m_zoom);
       float tileLon2=GeoUtils.tilex2long(useTileX+1,m_zoom);
       float tileLat2=GeoUtils.tiley2lat(useTileY+1,m_zoom);

       lonCenter=(((tileLon2-tileLon1)/256.0f)*x)+tileLon1;
       latCenter=(((tileLat2-tileLat1)/256.0f)*y)+tileLat1;
    }*/

    matrix.setTranslate(imgOffsetX, imgOffsetY);
    breakMapThread = false;
    mapThreadRunning = false;
    for (x = 0; x < tileWidth; x++)
      for (y = 0; y < tileHeight; y++) {
        if (breakMapThread) return;
        locTile =
            geoUtils.loadMapTile(
                getContext(),
                useOverlay.tileX + x,
                useOverlay.tileY + y,
                useOverlay.m_zoom,
                allowNetAccess);
        if (locTile != null) canvas.drawBitmap(locTile, x * 256, y * 256, null);
        postInvalidate();
      }
    useOverlay.doDraw(canvas, useLon, useLonMax, useLat, useLatMax, locMap);
    postInvalidate();
    System.gc();
  }
Beispiel #22
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.offline:
       if (prefs.getBoolean("hideOffline", false)) service.setPreference("hideOffline", false);
       else service.setPreference("hideOffline", true);
       updateMenu();
       updateList();
       break;
     case R.id.status:
       RosterDialogs.changeStatusDialog(this, null, null);
       break;
     case android.R.id.home:
       RosterDialogs.changeStatusDialog(this, null, null);
       break;
     case R.id.add:
       RosterDialogs.addDialog(this, null);
       break;
     case R.id.search:
       menu.removeItem(R.id.chats);
       item.expandActionView();
       break;
     case R.id.bookmarks:
       Intent bIntent = new Intent(this, Bookmarks.class);
       startActivity(bIntent);
       break;
     case R.id.chats:
       ChangeChatDialog.show(this);
       break;
     case R.id.accounts:
       Intent aIntent = new Intent(this, Accounts.class);
       startActivity(aIntent);
       break;
     case R.id.prefs:
       startActivityForResult(new Intent(this, Preferences.class), ACTIVITY_PREFERENCES);
       break;
     case R.id.disco:
       startActivity(new Intent(this, ServiceDiscovery.class));
       break;
     case R.id.notes:
       startActivity(new Intent(this, NotesActivity.class));
       break;
     case R.id.xml:
       startActivity(new Intent(this, XMLConsole.class));
       break;
     case R.id.notify:
       if (prefs.getBoolean("soundDisabled", false)) service.setPreference("soundDisabled", false);
       else service.setPreference("soundDisabled", true);
       updateMenu();
       break;
     case R.id.exit:
       if (prefs.getBoolean("DeleteHistory", false)) {
         getContentResolver().delete(JTalkProvider.CONTENT_URI, null, null);
       }
       Notify.cancelAll(this);
       stopService(new Intent(this, JTalkService.class));
       finish();
       System.exit(0);
       break;
     default:
       return false;
   }
   return true;
 }
    /**
     * Constructor definition
     *
     * @param array list
     */
    BookListAdapter(String[] arrayList, Dialog dialog) {
      arrayListOfItems = new String[arrayList.length];
      System.arraycopy(arrayList, 0, arrayListOfItems, 0, arrayList.length);

      opendDialog = dialog;
    }