예제 #1
0
  public List<EventInfoBean> getAllEvents() {
    SQLiteDatabase db = this.getReadableDatabase();
    List<EventInfoBean> eventList = new ArrayList<EventInfoBean>();
    try {

      Cursor cursor = db.query(EVENT_TABLE_NAME, null, null, null, null, null, null);
      if (cursor != null && cursor.moveToFirst()) {
        do {
          EventInfoBean event =
              new EventInfoBean(
                  cursor.getInt(cursor.getColumnIndex(COL_EVENT_START_TIME)),
                  cursor.getInt(cursor.getColumnIndex(COL_EVENT_END_TIME)),
                  cursor.getString(cursor.getColumnIndex(COL_EVENT_CREATOR_ID)),
                  cursor.getString(cursor.getColumnIndex(COL_EVENT_NAME)),
                  cursor.getString(cursor.getColumnIndex(COL_EVENT_DESCRIPTION)));
          event.setEventStatus(cursor.getInt(cursor.getColumnIndex(COL_EVENT_STATUS)));

          eventList.add(event);
        } while (cursor.moveToNext());
      }
    } catch (SQLiteException se) {
      Log.v(TAG, Log.getStackTraceString(se));
    } catch (Exception e) {
      Log.v(TAG, Log.getStackTraceString(e));
    } finally {
      db.close();
    }

    return eventList;
  }
예제 #2
0
  @Override
  protected Output doInBackground(Void... params) {

    // call the function
    double value = 0;
    ParseException e1 = null;
    try {
      value = CloudFunctions.getAccountValue(publicKeyBase64, itemType);
    } catch (ParseException e) {
      e1 = e;
      Log.e(Utils.LOG_TAG, Log.getStackTraceString(e));
    }

    // now grab the asset type
    Asset asset = null;
    if (e1 == null) {
      try {
        asset = Asset.fetchAsset(itemType);
      } catch (ParseException e) {
        e1 = e;
        Log.e(Utils.LOG_TAG, Log.getStackTraceString(e));
      }
    }
    return new Output(value, e1, asset, publicKeyBase64);
  }
        @Override
        public void run() {
          try {
            if (end) return;

            if (evercamCamera.loadingStatus == ImageLoadingStatus.not_started) {
              if (evercamCamera.isActive()) {
                // showAndSaveLiveSnapshot();
              }
            } else if (evercamCamera.loadingStatus == ImageLoadingStatus.live_received) {
              setLayoutForLiveImageReceived();
            } else if (evercamCamera.loadingStatus == ImageLoadingStatus.live_not_received) {
              setLayoutForNoImageReceived();
            }
          } catch (OutOfMemoryError e) {
            Log.e(TAG, e.toString() + "-::OOM::-" + Log.getStackTraceString(e));

            handler.postDelayed(LoadImageRunnable, 5000);
          } catch (Exception e) {
            Log.e(TAG, e.toString() + "::" + Log.getStackTraceString(e));
            if (!end) {
              handler.postDelayed(LoadImageRunnable, 5000);
            }
          }
        }
예제 #4
0
  public boolean validateUser(String user, String password) {
    boolean retValue = false;
    SQLiteDatabase db = this.getReadableDatabase();
    try {

      Cursor cursor =
          db.query(
              EVENT_USER_TABLE_NAME,
              new String[] {COL_USER_PASSWORD},
              COL_USER_ID + WHERE_EQUALS,
              new String[] {user},
              null,
              null,
              null);
      if (cursor != null && cursor.moveToFirst()) {
        if (password.equals(cursor.getString(cursor.getColumnIndex(COL_USER_PASSWORD)))) {
          retValue = true;
        }
      }
    } catch (SQLiteException se) {
      Log.v(TAG, Log.getStackTraceString(se));
    } catch (Exception e) {
      Log.v(TAG, Log.getStackTraceString(e));
    } finally {
      db.close();
    }
    return retValue;
  }
예제 #5
0
  private static void writeToFile(int priority, String tag, String msg, Throwable tr) {
    if ((priority >= sCurrentPriority) && (sBufferedWriter != null)) {
      try {
        if (checkFileSize()) {
          sBufferedWriter = new BufferedWriter(new FileWriter(sTheLogFile, true));
        }

        sBufferedWriter.write(formatMsg(tag, msg));
        sBufferedWriter.newLine();

        if (tr != null) {
          sBufferedWriter.write(Log.getStackTraceString(tr));
          sBufferedWriter.newLine();
        }

        sBufferedWriter.flush();
      } catch (IOException e) {
        Log.e("FileLog", Log.getStackTraceString(e));
      }
    }

    if (sBufferedWriter == null) {
      Log.e("FileLog", "You have to call FileLog.open(...) before starting to log");
    }
  }
예제 #6
0
    @Override
    protected StatsAdapter doInBackground(Boolean... refresh) {
      // do we need to refresh current
      if (refresh[0]) {
        // make sure to create a valid "current" stat
        StatsProvider.getInstance(StatsActivity.this).setCurrentReference(m_iSorting);
      }
      // super.doInBackground(params);
      m_listViewAdapter = null;
      try {
        Log.i(
            TAG,
            "LoadStatData: refreshing display for stats " + m_refFromName + " to " + m_refToName);
        m_listViewAdapter =
            new StatsAdapter(
                StatsActivity.this,
                StatsProvider.getInstance(StatsActivity.this)
                    .getStatList(m_iStat, m_refFromName, m_iSorting, m_refToName));
      } catch (BatteryInfoUnavailableException e) {
        // Log.e(TAG, e.getMessage(), e.fillInStackTrace());
        Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
        m_exception = e;

      } catch (Exception e) {
        // Log.e(TAG, e.getMessage(), e.fillInStackTrace());
        Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
        m_exception = e;
      }

      // StatsActivity.this.setListAdapter(m_listViewAdapter);
      // getStatList();
      return m_listViewAdapter;
    }
예제 #7
0
  public List<UserInfoBean> getEventAttendies(int eventid) {
    SQLiteDatabase db = this.getReadableDatabase();
    List<UserInfoBean> userList = new ArrayList<UserInfoBean>();
    try {

      Cursor cursor =
          db.query(
              EVENT_ATTENDEES_TABLE_NAME,
              null,
              COL_EVENT_ID + WHERE_EQUALS,
              new String[] {String.valueOf(eventid)},
              null,
              null,
              null);
      if (cursor != null && cursor.moveToFirst()) {
        do {
          UserInfoBean user =
              new UserInfoBean(
                  cursor.getString(cursor.getColumnIndex(COL_USER_ID)),
                  null,
                  cursor.getString(cursor.getColumnIndex(COL_USER_NAME)),
                  cursor.getLong(cursor.getColumnIndex(COL_USER_PHONE)));
          userList.add(user);
        } while (cursor.moveToNext());
      }
    } catch (SQLiteException se) {
      Log.v(TAG, Log.getStackTraceString(se));
    } catch (Exception e) {
      Log.v(TAG, Log.getStackTraceString(e));
    } finally {
      db.close();
    }

    return userList;
  }
  private void throwShade(int priority, String message, Throwable t) {
    if (message == null || message.length() == 0) {
      if (t != null) {
        message = Log.getStackTraceString(t);
      } else {
        // Swallow message if it's null and there's no throwable.
        return;
      }
    } else if (t != null) {
      message += "\n" + Log.getStackTraceString(t);
    }

    final ContentValues cv = new ContentValues();
    cv.put(LogColumns.TIMESTAMP, ISODateTimeFormat.dateTime().print(new DateTime()));
    cv.put(LogColumns.LEVEL, priority);
    cv.put(LogColumns.TAG, createTag());
    cv.put(LogColumns.MSG, message);
    new Thread(
            new Runnable() {
              @Override
              public void run() {
                ContentResolver contentResolver = appContext.getContentResolver();
                contentResolver.insert(LogsProvider.Logs.LOGS, cv);
              }
            })
        .run();
  }
  public static boolean powerNfc(boolean isOn, Context context) {
    boolean success = false;
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);

    if (nfcAdapter != null) {
      Class<?> NfcManagerClass;
      Method setNfcEnabled;

      try {
        NfcManagerClass = Class.forName(nfcAdapter.getClass().getName());
        setNfcEnabled = NfcManagerClass.getDeclaredMethod(isOn ? "enable" : "disable");
        setNfcEnabled.setAccessible(true);
        success = (Boolean) setNfcEnabled.invoke(nfcAdapter);
      } catch (ClassNotFoundException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      } catch (NoSuchMethodException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      } catch (IllegalArgumentException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      } catch (IllegalAccessException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      } catch (InvocationTargetException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      }
    }

    return success;
  }
    public void taskData() {
      if ("https".equals(url.getProtocol())) {
        HttpsURLConnection httpsUrlConnection;
        try {

          URLrequestection = url.openConnection();
          httpsUrlConnection = (HttpsURLConnection) URLrequestection;
          httpsUrlConnection.setRequestMethod("GET");
        } catch (IOException e) {

          Log.d(
              "Exception ",
              "Message :" + e.getMessage() + "\n StackTrace: " + Log.getStackTraceString(e));
        }

      } else {
        URLConnection URLrequestection;
        HttpURLConnection httpUrlConnection;
        try {
          URLrequestection = url.openConnection();
          httpUrlConnection = (HttpURLConnection) URLrequestection;
          httpUrlConnection.setRequestMethod("GET");

        } catch (IOException e) {

          Log.d(
              "Exception ",
              "Message :" + e.getMessage() + "\n StackTrace: " + Log.getStackTraceString(e));
        }
      }
    }
예제 #11
0
    public void processingFinished() {
      try {
        Bitmap result = (Bitmap) processing.get();

        // generate filename
        byte[] hashBytes = ByteBuffer.allocate(4).putInt(result.hashCode()).array();
        processed =
            Uri.parse(
                "/sdcard/Download/"
                    + Base64.encodeToString(hashBytes, Base64.URL_SAFE).trim()
                    + ".png");

        // save to file
        FileOutputStream out = null;
        try {
          out = new FileOutputStream(processed.getPath());
          result.compress(Bitmap.CompressFormat.PNG, 90, out);
          Log.d(TAG, "saved to " + processed);
        } catch (Exception e) {
          Log.e(TAG, Log.getStackTraceString(e));
        } finally {
          try {
            out.close();
          } catch (Throwable ignore) {
          }
        }

        double sx = noteList.getWidth();
        double sy = (noteList.getWidth() / result.getWidth()) * result.getHeight();
        interestingThumbnail(Bitmap.createScaledBitmap(result, (int) sx, (int) sy, false));
      } catch (Exception e) {
        Log.d(TAG, Log.getStackTraceString(e));
      }
    }
    @Override
    protected String doInBackground(String... sUrl) {
      HttpURLConnection requestection = null;
      FileOutputStream fos = null;
      File file = new File(fileName);
      try {
        requestection = (HttpURLConnection) url.openConnection();
        requestection.connect();
        InputStream is = requestection.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayBuffer baf = new ByteArrayBuffer(1024);
        int current = 0;
        while ((current = bis.read()) != -1) {
          baf.append((byte) current);
        }
        fos = new FileOutputStream(file);
        fos.write(baf.toByteArray());
      } catch (IOException e) {

        Log.d(
            "Exception ",
            "Message :" + e.getMessage() + "\n StackTrace: " + Log.getStackTraceString(e));
      } finally {
        try {
          fos.close();
        } catch (IOException e) {

          Log.d(
              "Exception ",
              "Message :" + e.getMessage() + "\n StackTrace: " + Log.getStackTraceString(e));
        }
      }

      return null;
    }
예제 #13
0
  public static void setActionBarTranslation(Activity activity, float y) {
    ViewGroup vg = (ViewGroup) activity.findViewById(android.R.id.content).getParent();
    int count = vg.getChildCount();

    if (DEBUG) {
      Log.d(TAG, "==========================");
    }

    // Get the class of action bar
    Class<?> actionBarContainer = null;
    Field isSplit = null;

    try {
      actionBarContainer = Class.forName("com.android.internal.widget.ActionBarContainer");
      isSplit = actionBarContainer.getDeclaredField("mIsSplit");
      isSplit.setAccessible(true);
    } catch (Exception e) {
      if (DEBUG) {
        Log.e(TAG, Log.getStackTraceString(e));
      }
    }

    for (int i = 0; i < count; i++) {
      View v = vg.getChildAt(i);

      if (v.getId() != android.R.id.content) {
        if (DEBUG) {
          Log.d(TAG, "Found View: " + v.getClass().getName());
        }

        try {
          if (actionBarContainer.isInstance(v)) {
            if (DEBUG) {
              Log.d(TAG, "Found ActionBarContainer");
            }

            if (isSplit.getBoolean(v)) {
              if (DEBUG) {
                Log.d(TAG, "Found Split Action Bar");
              }

              continue;
            }
          }
        } catch (Exception e) {
          if (DEBUG) {
            Log.e(TAG, Log.getStackTraceString(e));
          }
        }

        v.setTranslationY(y);
      }
    }

    if (DEBUG) {
      Log.d(TAG, "==========================");
    }
  }
예제 #14
0
  private Bitmap downloadBitmap(String url) {
    try {
      Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(url).getContent());
      cache.put(url, new SoftReference<Bitmap>(bitmap));
      return bitmap;
    } catch (MalformedURLException e) {
      Log.e("MalformedURLException: ", Log.getStackTraceString(e));
    } catch (IOException e) {
      Log.e("IOException: ", Log.getStackTraceString(e));
    }

    return null;
  }
예제 #15
0
  private void getWallpapersFromUrl(String url) {
    wallslist.clear();
    wallslist = wdb.getAllWalls();

    if (wallslist.size() == 0) {
      try {
        HttpClient cl = new DefaultHttpClient();
        HttpResponse response = cl.execute(new HttpGet(url));
        if (response.getStatusLine().getStatusCode() == 200) {
          final String data = EntityUtils.toString(response.getEntity());
          JSONObject jsonobject = new JSONObject(data);
          final JSONArray jsonarray = jsonobject.getJSONArray("wallpapers");
          wallslist.clear();
          wdb.deleteAllWallpapers();
          for (int i = 0; i < jsonarray.length(); i++) {
            jsonobject = jsonarray.getJSONObject(i);
            WallpaperInfo jsondata =
                new WallpaperInfo(
                    jsonobject.getString("name"),
                    jsonobject.getString("author"),
                    jsonobject.getString("url"));
            wdb.addWallpaper(jsondata);
            wallslist.add(jsondata);
          }
        }
      } catch (Exception e) {
        Log.d("Wallpapers", Log.getStackTraceString(e));
      }
    }
  }
  boolean resizeCameras() {
    try {
      int screen_width = readScreenWidth(this);
      camerasPerRow = recalculateCameraPerRow();

      io.evercam.androidapp.custom.FlowLayout camsLineView =
          (io.evercam.androidapp.custom.FlowLayout) this.findViewById(R.id.cameras_flow_layout);
      for (int i = 0; i < camsLineView.getChildCount(); i++) {
        LinearLayout pview = (LinearLayout) camsLineView.getChildAt(i);
        CameraLayout cameraLayout = (CameraLayout) pview.getChildAt(0);

        LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
        params.width =
            ((i + 1 % camerasPerRow == 0)
                ? (screen_width - (i % camerasPerRow) * (screen_width / camerasPerRow))
                : screen_width / camerasPerRow);
        params.width = params.width - 1; // 1 pixels spacing between cameras
        params.height = (int) (params.width / (1.25));
        params.setMargins(1, 1, 0, 0); // 1 pixels spacing between cameras
        cameraLayout.setLayoutParams(params);
      }
      return true;
    } catch (Exception e) {
      Log.e(TAG, e.toString() + "::" + Log.getStackTraceString(e));

      sendToMint(e);

      EvercamPlayApplication.sendCaughtException(this, e);
      CustomedDialog.showUnexpectedErrorDialog(CamerasActivity.this);
    }
    return false;
  }
예제 #17
0
    private void loadAll() {
      final SyncResultsActivity activity = mActivity.get();
      if (activity == null) {
        return;
      }
      final ContentResolver resolver = activity.getContentResolver();
      if (resolver == null) {
        return;
      }

      mLoading = true;

      String[] projection = {Results._ID, Results.CONTACT_ID, Results.PIC_URL};

      Cursor cursor = null;
      try {
        cursor =
            resolver.query(Results.CONTENT_URI, projection, null, null, Results.DEFAULT_SORT_ORDER);

        while (running && cursor.moveToNext()) {
          String url = cursor.getString(cursor.getColumnIndex(Results.PIC_URL));
          url = url != null ? url.trim() : null;
          String id = cursor.getString(cursor.getColumnIndex(Results.CONTACT_ID));
          queueWork(id, url);
        }
      } catch (Exception ex) {
        Log.e(TAG, android.util.Log.getStackTraceString(ex));
      } finally {
        if (cursor != null) {
          cursor.close();
        }
        // ((SimpleCursorAdapter)activity.mListview.getAdapter()).notifyDataSetChanged();
        mLoading = false;
      }
    }
예제 #18
0
 /**
  * bindSpinnerItems: Queries the database to find the list of unique ExpenseType values for
  * presentation in the list.
  */
 private void bindExpenseTypeSpinner() {
   ArrayList<CharSequence> listOfTypes = new ArrayList<CharSequence>();
   try {
     String[] projection = new String[] {ExpenseContentProvider.CATEGORY};
     String selection =
         "1=1) GROUP BY ("
             + ExpenseContentProvider
                 .CATEGORY; // sloppy sql injection hack to get distinct categories
     Cursor c =
         getContentResolver()
             .query(ExpenseContentProvider.CONTENT_URI, projection, selection, null, null);
     if (c != null && c.getCount() > 0) {
       c.moveToFirst();
       do {
         listOfTypes.add((CharSequence) c.getString(0));
       } while (c.moveToNext());
     }
     c.close();
   } catch (Exception e) {
     Log.getStackTraceString(e);
   }
   ArrayAdapter<CharSequence> typesArrayAdapter =
       new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, listOfTypes);
   spinnerExpenseType.setAdapter(typesArrayAdapter);
 }
예제 #19
0
  private void deleteLocation(LocationInfo info) {
    if (NavigineApp.Navigation == null) return;

    if (info != null) {
      try {
        (new File(info.archiveFile)).delete();
        info.localVersion = -1;
        info.localModified = false;

        String locationDir = LocationLoader.getLocationDir(mContext, info.title);
        File dir = new File(locationDir);
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; ++i) files[i].delete();
        dir.delete();

        String mapFile = NavigineApp.Settings.getString("map_file", "");
        if (mapFile.equals(info.archiveFile)) {
          NavigineApp.Navigation.loadArchive(null);
          SharedPreferences.Editor editor = NavigineApp.Settings.edit();
          editor.putString("map_file", "");
          editor.commit();
        }

        mAdapter.updateList();
      } catch (Throwable e) {
        Log.e(TAG, Log.getStackTraceString(e));
      }
    }
  }
  /** CalledMethod Bringer (誰叫的 出來!) */
  protected void CalledMethodBringer(Throwable ex) {
    /*
            //取得呼叫當前方法之上一層函式
            for (StackTraceElement ste : Thread.currentThread().getStackTrace())
            {
                System.out.println(ste);
                Log.w(TAG, ste.toString());//然後會印出 CalledMethodBringer, saveCrashInfoToFile, handleException, uncaughtException, NativeStart.main...真是沒用的資訊..
            }
    */
    // another medth from stackoverflow
    //         Thread.currentThread().getStackTrace();// if you don't care what the first element of
    // the stack is. That returns an array of StackTraceElement
    //         new Throwable().getStackTrace();//  will have a defined position for your current
    // method, if that matters.

    // 以下兩個效果與saveCrashInfoToFile裡的printStackTrace相同,會印出java.lang.NullPointerException,
    // MainActivity$2.onClick, View.performClick , View$PerformClick.run , Handler.handleCallback ,
    // Handler.dispatchMessage, Looper.loop , ActivityThread.main , etc...

    //
    Log.e(TAG, "stackTrace by Throwable Exception :");
    String stackTrace = Log.getStackTraceString(ex);
    Log.e(TAG, stackTrace);
    //
    Log.e(TAG, "printStackTrace:");
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw, true);
    ex.printStackTrace(pw);
    pw.flush();
    sw.flush();
    String sTemp = sw.toString();
    Log.e(TAG, sTemp);
  }
  /** Writes an activity record at the end of todays log file. */
  public void writeRecord(ActivityRecord record) {

    // Opens todays log file for writing
    Date date = new Date();
    FileOutputStream outStream = getOutStream(date);

    if (outStream != null && record != null) {
      String line = record + LINE_SEPARATOR;
      try {
        outStream.write(line.getBytes());
        mNewerRecords = true;

        // Delete old files if this is the first record of the day
        if (isNewDay(date)) {
          deleteOldFiles(date);
        }

        // Updates latest write date
        mLatestWrite = date;
      } catch (Exception e) {
        Log.e(LOGTAG, Log.getStackTraceString(e));
      } finally {
        closeOutStream(outStream);
      }
    }
  }
예제 #22
0
파일: GLog.java 프로젝트: XuWei0205/Weather
 public static void e(Throwable ex, Object... args) {
   if (args == null) {
     return;
   }
   if (DEBUG.DEVELOP_MODE) {
     final StackTraceElement[] stack = new Throwable().getStackTrace();
     final int i = 1;
     final StackTraceElement ste = stack[i];
     StringBuffer message = new StringBuffer();
     if (args.length > 0) {
       for (int j = 0; j < args.length; j++) {
         message.append(args[j].toString()).append(" ");
       }
     }
     String log;
     if (ex == null) {
       log = message.toString();
     } else {
       String logMessage = message.toString() == null ? ex.getMessage() : message.toString();
       String logBody = Log.getStackTraceString(ex);
       log = String.format(LOG_FORMAT, logMessage, logBody);
     }
     Log.println(
         Log.ERROR,
         LOG_TAG,
         String.format(
             "[%s][%s][%s]%s", ste.getFileName(), ste.getMethodName(), ste.getLineNumber(), log));
   }
 }
예제 #23
0
 public static void w(Throwable tr) {
   final String formattedString = formatMessage("", new Object[] {}) + Log.getStackTraceString(tr);
   if (isDebuggable) {
     Log.w(TAG_NAME, formattedString);
   }
   sendMessageToListener(formattedString);
 }
예제 #24
0
      private String queryContact(String url) {
        final SyncResultsActivity activity = mActivity.get();
        if (activity == null) {
          return null;
        }
        final ContentResolver resolver = activity.getContentResolver();
        if (resolver == null) {
          return null;
        }

        final String where = Results.PIC_URL + "='" + url + "'";

        String[] projection = {Results._ID, Results.CONTACT_ID, Results.PIC_URL};

        Cursor cursor = null;
        String id = null;
        try {
          cursor =
              resolver.query(
                  Results.CONTENT_URI, projection, where, null, Results.DEFAULT_SORT_ORDER);

          if (cursor.moveToNext()) {
            id = cursor.getString(cursor.getColumnIndex(Results.CONTACT_ID));
          }
        } catch (Exception ex) {
          Log.e(TAG, android.util.Log.getStackTraceString(ex));
        } finally {
          if (cursor != null) {
            cursor.close();
          }
        }

        return id;
      }
  public boolean onSavePassword(
      String schemePlusHost, String username, String password, Message resumeMsg) {
    // resumeMsg should be null at this point because we want to create it
    // within the CallbackProxy.
    if (Config.DEBUG) {
      junit.framework.Assert.assertNull(resumeMsg);
    }
    resumeMsg = obtainMessage(NOTIFY);

    Message msg = obtainMessage(SAVE_PASSWORD, resumeMsg);
    Bundle bundle = msg.getData();
    bundle.putString("host", schemePlusHost);
    bundle.putString("username", username);
    bundle.putString("password", password);
    synchronized (this) {
      sendMessage(msg);
      try {
        wait();
      } catch (InterruptedException e) {
        Log.e(LOGTAG, "Caught exception while waiting for onSavePassword");
        Log.e(LOGTAG, Log.getStackTraceString(e));
      }
    }
    // Doesn't matter here
    return false;
  }
예제 #26
0
  public static int restoreBackup(String path, String backupPath) {
    // rename old file and move it to subdirectory
    if (!(new File(path)).exists() || !moveDatabaseToBrokenFolder(path, false)) {
      return RETURN_ERROR;
    }

    // copy backup to new position and rename it
    File backupFile = new File(backupPath);
    File colFile = new File(path);
    if (getFreeDiscSpace(colFile) < colFile.length() + (MIN_FREE_SPACE * 1024 * 1024)) {
      Log.e(AnkiDroidApp.TAG, "Not enough space on sd card to restore " + colFile.getName() + ".");
      return RETURN_NOT_ENOUGH_SPACE;
    }
    try {
      InputStream stream = new FileInputStream(backupFile);
      Utils.writeToFile(stream, colFile.getAbsolutePath());
      stream.close();

      // set timestamp of file in order to avoid creating a new backup unless its changed
      colFile.setLastModified(backupFile.lastModified());
    } catch (IOException e) {
      Log.e(AnkiDroidApp.TAG, Log.getStackTraceString(e));
      Log.e(AnkiDroidApp.TAG, "Restore of file " + colFile.getName() + " failed.");
      return RETURN_ERROR;
    }
    return RETURN_DECK_RESTORED;
  }
      @Override
      public void onClick(View view) {
        try {
          long genreId = genres.get(getAdapterPosition()).getId();
          Context context = getActivity();
          Intent mIntent = new Intent(context, PlaylistActivity.class);

          Bundle mBundle = new Bundle();
          mBundle.putLong("id", genreId);
          mBundle.putLong("tagfor", PhoneMediaControl.SongsLoadFor.Genre.ordinal());
          mBundle.putString(
              "albumname", ((TextView) view.findViewById(R.id.title)).getText().toString().trim());
          mBundle.putString("title_one", "All my songs");
          mBundle.putString(
              "title_sec",
              ((TextView) view.findViewById(R.id.details)).getText().toString().trim());

          mIntent.putExtras(mBundle);

          context.startActivity(mIntent);
          ((Activity) context).overridePendingTransition(0, 0);
        } catch (Exception e) {
          Log.i(TAG, Log.getStackTraceString(e));
        }
      }
예제 #28
0
  public void completeTodo(long resourceId, int action) {
    try {
      Resource r = Resource.fromDatabase(this, resourceId);
      VCalendar todoCalendarResource = (VCalendar) VComponent.createComponentFromResource(r);
      todoCalendarResource.setEditable();
      VTodo task = (VTodo) todoCalendarResource.getMasterChild();
      task.setCompleted(AcalDateTime.getInstance());
      task.setPercentComplete(100);
      todoCalendarResource.updateTimeZones();

      ResourceManager.getInstance(this)
          .sendRequest(
              new RRResourceEditedRequest(
                  new ResourceResponseListener<Long>() {
                    @Override
                    public void resourceResponse(ResourceResponse<Long> response) {}
                  },
                  r.getCollectionId(),
                  resourceId,
                  todoCalendarResource,
                  RRResourceEditedRequest.ACTION_UPDATE));

    } catch (Exception e) {
      if (e.getMessage() != null) Log.d(TAG, e.getMessage());
      if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, Log.getStackTraceString(e));
      Toast.makeText(this, getString(R.string.ErrorCompletingTask), Toast.LENGTH_LONG).show();
    }
  }
  public WebView createWindow(boolean dialog, boolean userGesture) {
    // Do an unsynchronized quick check to avoid posting if no callback has
    // been set.
    if (mWebChromeClient == null) {
      return null;
    }

    WebView.WebViewTransport transport = mWebView.new WebViewTransport();
    final Message msg = obtainMessage(NOTIFY);
    msg.obj = transport;
    synchronized (this) {
      sendMessage(obtainMessage(CREATE_WINDOW, dialog ? 1 : 0, userGesture ? 1 : 0, msg));
      try {
        wait();
      } catch (InterruptedException e) {
        Log.e(LOGTAG, "Caught exception while waiting for createWindow");
        Log.e(LOGTAG, Log.getStackTraceString(e));
      }
    }

    WebView w = transport.getWebView();
    if (w != null) {
      w.getWebViewCore().initializeSubwindow();
    }
    return w;
  }
예제 #30
0
  public static synchronized boolean parrotNativeLibsAlreadyLoadedOrLoadingWasSucessful() {
    if (parrotLibrariesLoaded == true) {
      return parrotLibrariesLoaded;
    }

    if (BuildConfig.FEATURE_PARROT_AR_DRONE_ENABLED
        && parrotLibrariesLoaded
            == false) { // Drone is deactivated in release builds for now 04.2014
      Log.d(TAG, "Current platform = \"" + OS_ARCH + "\"");
      if (OS_ARCH.startsWith("arm")) {
        Log.d(TAG, "We are on an arm platform load parrot native libs");
        try {
          System.loadLibrary("avutil");
          System.loadLibrary("swscale");
          System.loadLibrary("avcodec");
          System.loadLibrary("avfilter");
          System.loadLibrary("avformat");
          System.loadLibrary("avdevice");
          System.loadLibrary("adfreeflight");
        } catch (UnsatisfiedLinkError e) {
          Log.e(TAG, Log.getStackTraceString(e));
          return parrotLibrariesLoaded;
        }
        parrotLibrariesLoaded = true;
      } else {
        Log.d(TAG, "We are not on an arm based device, dont load libs");
      }
    }
    return parrotLibrariesLoaded;
  }