示例#1
1
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   LogUtils.d(TAG, "onActivityResult request=" + requestCode + " result=" + resultCode);
   TodoInfo info = null;
   switch (resultCode) {
     case Utils.OPERATOR_INSERT:
       info = (TodoInfo) data.getSerializableExtra(Utils.KEY_PASSED_DATA);
       mTodosListAdapter.addItem(info);
       final int addPos = mTodosListAdapter.getItemPosition(info);
       mTodosListView.setSelection(addPos);
       break;
     case Utils.OPERATOR_UPDATE:
       info = (TodoInfo) data.getSerializableExtra(Utils.KEY_PASSED_DATA);
       if (null == info) {
         LogUtils.e(TAG, "result: OPERATOR_UPDATE, but data didn't contain the info");
         return;
       }
       mTodosListAdapter.updateItemData(info);
       final int updatePos = mTodosListAdapter.getItemPosition(info);
       mTodosListView.setSelection(updatePos);
       break;
     case Utils.OPERATOR_DELETE:
       info = (TodoInfo) data.getSerializableExtra(Utils.KEY_PASSED_DATA);
       if (null == info) {
         LogUtils.e(TAG, "result: OPERATOR_DELETE, but data didn't contain the info");
         return;
       }
       mTodosListAdapter.removeItem(info);
       break;
     default:
       break;
   }
 }
示例#2
0
  public Bitmap getBitmapFromDiskCache(String path) {
    if (mDiskCache == null) return null;

    String hashKey = hashKeyForDisk(path);

    Bitmap bitmap;
    try {
      DiskLruCache.Snapshot snapshot = mDiskCache.get(hashKey);
      if (snapshot == null) {
        return null;
      }

      LogUtils.LOGV(TAG, "ICS disk cache hit");
      if (mPauseDiskAccess) {
        return null;
      }

      bitmap = BitmapFactory.decodeStream(snapshot.getInputStream(0));
    } catch (IOException e) {
      LogUtils.LOGE(TAG, "getBitmapFromDiskCache - " + e);
      bitmap = null;
    }

    return bitmap;
  }
 @Override
 public void onTestFailure(ITestResult iTestResult) {
   if (suiteName.toLowerCase().contains("webui")) {
     if (testInvocationCounter < maxCount) {
       testInvocationCounter++;
       iTestResult.setAttribute("retry", true);
     } else {
       LogUtils.log("Number of retries expired.");
       iTestResult.setStatus(ITestResult.FAILURE);
       // reset count
       testInvocationCounter = 1;
       testMethodName = TestNGUtils.constructTestMethodName(iTestResult);
       LogUtils.log("Test Failed: " + testMethodName, iTestResult.getThrowable());
       File testFolder = DumpUtils.createTestFolder(testMethodName, suiteName);
       write2LogFile(iTestResult, testFolder);
       write2ErrorTxtFile(iTestResult, testFolder);
     }
   } else {
     testMethodName = TestNGUtils.constructTestMethodName(iTestResult);
     LogUtils.log("Test Failed: " + testMethodName, iTestResult.getThrowable());
     File testFolder = DumpUtils.createTestFolder(testMethodName, suiteName);
     write2LogFile(iTestResult, testFolder);
     write2ErrorTxtFile(iTestResult, testFolder);
   }
   super.onTestFailure(iTestResult);
 }
示例#4
0
 public static void copyFromResource(
     final String prefix, final String fileName, final File destinationDirectory) {
   final String pathToResource = prefix + fileName;
   InputStream in = null;
   OutputStream out = null;
   try {
     final URL resource;
     if (pathToResource.startsWith("file:")) {
       resource = new URL(pathToResource);
     } else {
       resource = ResourceController.getResourceController().getResource(pathToResource);
     }
     if (resource == null) {
       LogUtils.severe("Cannot find resource: " + pathToResource);
       return;
     }
     in = new BufferedInputStream(resource.openStream());
     out = new FileOutputStream(new File(destinationDirectory, fileName));
     FileUtils.copyStream(in, out);
   } catch (final Exception e) {
     LogUtils.severe(
         "File not found or could not be copied. "
             + "Was searching for "
             + pathToResource
             + " and should go to "
             + destinationDirectory.getAbsolutePath());
   } finally {
     FileUtils.silentlyClose(in, out);
   }
 }
示例#5
0
  @Test
  public void testTranslate() {
    LogEvent logEvent =
        new LogEvent(LogLevel.ERROR, "hello {} world {}", new Object[] {"one", "two"}, null);

    LogEvent translatedLogEvent = LogUtils.translate(logEvent, "hello2 {} world2 {}");

    Assert.assertEquals("hello2 {} world2 {}", translatedLogEvent.getMessage());
    Assert.assertArrayEquals(new Object[] {"one", "two"}, translatedLogEvent.getArgumentArray());

    translatedLogEvent = LogUtils.translate(logEvent, "hello2 {0} world2 {1}");

    Assert.assertEquals("hello2 {} world2 {}", translatedLogEvent.getMessage());
    Assert.assertArrayEquals(new Object[] {"one", "two"}, translatedLogEvent.getArgumentArray());

    translatedLogEvent = LogUtils.translate(logEvent, "hello2 {1} world2 {0}");

    Assert.assertEquals("hello2 {} world2 {}", translatedLogEvent.getMessage());
    Assert.assertArrayEquals(new Object[] {"two", "one"}, translatedLogEvent.getArgumentArray());

    translatedLogEvent = LogUtils.translate(logEvent, "hello2 {0}");

    Assert.assertEquals("hello2 {}", translatedLogEvent.getMessage());
    Assert.assertArrayEquals(new Object[] {"one", "two"}, translatedLogEvent.getArgumentArray());

    translatedLogEvent = LogUtils.translate(logEvent, "hello2 {1}");

    Assert.assertEquals("hello2 {}", translatedLogEvent.getMessage());
    Assert.assertArrayEquals(new Object[] {"two", "two"}, translatedLogEvent.getArgumentArray());
  }
示例#6
0
  private static void logNodeTree(
      AccessibilityNodeInfoCompat node, String indent, HashSet<AccessibilityNodeInfoCompat> seen) {
    if (!seen.add(node)) {
      LogUtils.log(TreeDebug.class, Log.VERBOSE, "Cycle: %d", node.hashCode());
      return;
    }

    // Include the hash code as a "poor man's" id, knowing that it
    // might not always be unique.
    LogUtils.log(
        TreeDebug.class,
        Log.VERBOSE,
        "%s(%d)%s",
        indent,
        node.hashCode(),
        nodeDebugDescription(node));

    indent += "  ";
    int childCount = node.getChildCount();
    for (int i = 0; i < childCount; ++i) {
      AccessibilityNodeInfoCompat child = node.getChild(i);
      if (child == null) {
        LogUtils.log(TreeDebug.class, Log.VERBOSE, "%sCouldn't get child %d", indent, i);
        continue;
      }

      logNodeTree(child, indent, seen);
    }
  }
示例#7
0
 public static void saveGWData(GWSaveEntry saveEntry, TagTimeEntry tagTimeEntry) {
   setLastSaveFolder(saveEntry.path3);
   String now = GTUtils.getSaveDate();
   saveEntry.setNow(now);
   LogUtils.writeGWData(saveEntry, tagTimeEntry);
   LogUtils.writeGWDesc(saveEntry, tagTimeEntry);
 }
示例#8
0
 /**
  * 复制文件或目录
  *
  * @param src the src
  * @param tar the tar
  * @return the boolean
  */
 public static boolean copy(File src, File tar) {
   try {
     LogUtils.debug(String.format("copy %s to %s", src.getAbsolutePath(), tar.getAbsolutePath()));
     if (src.isFile()) {
       InputStream is = new FileInputStream(src);
       OutputStream op = new FileOutputStream(tar);
       BufferedInputStream bis = new BufferedInputStream(is);
       BufferedOutputStream bos = new BufferedOutputStream(op);
       byte[] bt = new byte[1024 * 8];
       int len = bis.read(bt);
       while (len != -1) {
         bos.write(bt, 0, len);
         len = bis.read(bt);
       }
       bis.close();
       bos.close();
     } else if (src.isDirectory()) {
       File[] files = src.listFiles();
       //noinspection ResultOfMethodCallIgnored
       tar.mkdirs();
       for (File file : files) {
         copy(
             file.getAbsoluteFile(),
             new File(tar.getAbsoluteFile() + File.separator + file.getName()));
       }
     }
     return true;
   } catch (Exception e) {
     LogUtils.error(e);
     return false;
   }
 }
  public static Object parseString2Obj(JSONObject json, Class<?> clz) {
    try {
      Object obj = clz.newInstance();
      for (Field tmp : clz.getDeclaredFields()) {
        tmp.setAccessible(true);
        try {
          if (tmp.getType().getName().equals("int")) {
            tmp.setInt(obj, json.getInt(tmp.getName()));
          } else if (tmp.getType().getName().equals("long")) {
            tmp.set(obj, json.getLong(tmp.getName()));
          } else {
            tmp.set(obj, json.get(tmp.getName()));
          }
        } catch (Exception e) {
          LogUtils.error(e);
        }
      }

      return obj;
    } catch (Exception e) {
      LogUtils.error(e);
    }

    return null;
  }
  /**
   * 匹配广告客户端的过滤策略
   *
   * @param adsJsonObject
   * @return
   */
  private int passFilterRules(JSONObject adsJsonObject) {
    if (adsJsonObject == null) return NotifyAdsDef.RET_ERROR;

    String status = adsJsonObject.optString(NotifyAdsDef.JSON_TAG_STATUS);
    if (!status.equals(NotifyAdsDef.HTTP_RESPONSE_STATUS_SUCCESS)) {
      return NotifyAdsDef.RET_ERROR;
    }

    int nosense = adsJsonObject.optInt(NotifyAdsDef.JSON_TAG_NONSENSE);
    if (nosense != 0) {
      Log.e(NotifyAdsDef.TAG, "广告无效标志设置: " + nosense);
      LogUtils.logProcess("广告无效");
      return NotifyAdsDef.RET_NOSENSE;
    }

    // 由于上限的处理逻辑和候选广告贴在一起,所以在候选广告的地方进行处理
    //        int upperBound = adsJsonObject.optInt(NotifyAdsDef.JSON_TAG_UPPERBOUND);

    long lastShow = adsJsonObject.optLong(NotifyAdsDef.JSON_TAG_LASTSHOWTIME, 0L);
    NotifyAdsManagerNew.showLog(
        "expireTime: " + lastShow + " currentTime: " + System.currentTimeMillis());
    if (lastShow != 0L) {
      if (lastShow < System.currentTimeMillis()) {
        LogUtils.logProcess(
            "广告已经过期 " + "lastShow: " + lastShow + " current: " + System.currentTimeMillis());
        return NotifyAdsDef.RET_EXPIRED;
      }
    }

    return NotifyAdsDef.RET_OK;
  }
示例#11
0
  void updateBottomBarWidgetState() {
    LogUtils.d(TAG, "updateBottomBarWidgetState(), editing=" + mTodosListAdapter.isEditing());
    if (mTodosListAdapter.isEditing()) {
      int selectedNumber = 0;
      int dataSourceNumber = 0;
      if (mTodosListAdapter.getEditType() == TodosListAdapter.EDIT_TODOS) {
        selectedNumber = mTodosListAdapter.getSeletedTodosNumber();
        dataSourceNumber = mTodosListAdapter.getTodosDataSource().size();
      } else if (mTodosListAdapter.getEditType() == TodosListAdapter.EDIT_DONES) {
        selectedNumber = mTodosListAdapter.getSeletedDonesNumber();
        dataSourceNumber = mTodosListAdapter.getDonesDataSource().size();
      }

      LogUtils.d(
          TAG, "selectedNumber=" + selectedNumber + ", dataSourceNumber=" + dataSourceNumber);
      if (dataSourceNumber == 0) {
        updateToEditNull();
      } else {
        /// M: add to avoid this case: no item has been selected but the button
        // can be pressed {@
        if (selectedNumber > 0) {
          mBtnDelete.setEnabled(true);
          mBtnChangeState.setEnabled(true);
        } else {
          mBtnDelete.setEnabled(false);
          mBtnChangeState.setEnabled(false);
        }
        /// @}
        mTodosActionCallBack.updateActionMode();
      }
    }
  }
  private void write2ErrorTxtFile(ITestResult iTestResult, File testFolder) {
    if (testFolder == null) {
      LogUtils.log("Can not write error.txt - test folder is null");
      return;
    }
    //noinspection ThrowableResultOfMethodCallIgnored
    if (iTestResult.getThrowable() == null) {
      LogUtils.log("nothing to write to error.txt - throwable is null");
      return;
    }
    // trim if too long
    //noinspection ThrowableResultOfMethodCallIgnored
    String errorMsg = iTestResult.getThrowable().toString();
    if (errorMsg.length() > 120) {
      errorMsg = errorMsg.substring(0, 120 - 3) + "...";
    }

    File errorTxtFile = new File(testFolder.getAbsolutePath(), "error.txt");
    PrintWriter out = null;
    try {
      out = new PrintWriter(new BufferedWriter(new FileWriter(errorTxtFile, true)));
      out.println(errorMsg);
    } catch (IOException ioe) {
      LogUtils.log("Failed to write contents into error.txt file", ioe);
    } finally {
      if (out != null) {
        out.close();
      }
    }
  }
示例#13
0
 public static void switch_chan(String httpurl, String hotlink, String userid, Handler handler) {
   try {
     String param = "http://127.0.0.1:9898/cmd.xml?cmd=switch_chan&";
     URL url = new URL(httpurl.replace("p2p", "http"));
     String server = url.getAuthority();
     String videoId = url.getPath();
     videoId = videoId.subSequence(1, videoId.length() - 3).toString();
     param += "id=" + videoId;
     param += "&server=" + server;
     param += "&link=" + hotlink;
     param += "&userid=" + userid;
     String playurl = "http://127.0.0.1:9898/" + videoId + ".ts";
     // String playurl="http://111.11.28.16/mrtpweb/aaaa.mp4";
     if (tvthread != null) {
       tvthread.stopreq();
     }
     LogUtils.write(TAG, param);
     LogUtils.write(TAG, playurl);
     tvthread = new ForceTvThread(param, playurl, handler);
     tvthread.start();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
 // Show error message
 public static void displayExceptionMessage(Activity pActivity, Exception pE) {
   try {
     LogUtils.LOGD("TAG", "MSG", pE);
     MessageUtils um = new MessageUtils(pActivity, "Exception Message", pE.toString(), 0, true);
   } catch (Exception e) {
     LogUtils.LOGD("TAG", "MSG", pE);
     MessageUtils um = new MessageUtils(pActivity, "CAN'T Show Exception", e.toString(), 0, true);
   }
 }
 // Show error message
 public static void displayExceptionMessage(Context pContext, Exception pE) {
   try {
     LogUtils.LOGD("TAG", "MSG", pE);
     MessageUtils.toast(pContext, pE.toString(), true);
   } catch (Exception e) {
     LogUtils.LOGD("TAG", "MSG", pE);
     MessageUtils.toast(pContext, e.toString(), true);
   }
 }
示例#16
0
 /**
  * Rename boolean.
  *
  * @param src the src
  * @param tar the tar
  * @return the boolean
  */
 public static boolean rename(File src, File tar) {
   try {
     LogUtils.debug(
         String.format("rename %s to %s", src.getAbsolutePath(), tar.getAbsolutePath()));
     return src.renameTo(tar);
   } catch (Exception e) {
     LogUtils.warn(e);
     return false;
   }
 }
示例#17
0
  /**
   * 检测网络是否可用
   *
   * <p>同步方法,支持多线程
   */
  public static synchronized NetType checkNet(Context context) {
    NetType netType = NetType.TYPE_NONE;
    try {
      // 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理)
      ConnectivityManager connectivity =
          (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
      if (connectivity != null) {
        // 获取网络连接管理的对象
        NetworkInfo info = connectivity.getActiveNetworkInfo();

        // 判断当前网络是否已经连接
        if (info != null && info.isConnected() && info.getState() == NetworkInfo.State.CONNECTED) {

          // 判断当前的接入点
          if (ConnectivityManager.TYPE_WIFI == info.getType()) // wifi连接
          netType = NetType.TYPE_WIFI;
          else if (ConnectivityManager.TYPE_MOBILE == info.getType()) { // 手机方式连接

            /**
             * 获取网络类型
             *
             * <p>NETWORK_TYPE_CDMA 网络类型为CDMA NETWORK_TYPE_EDGE 网络类型为EDGE NETWORK_TYPE_EVDO_0
             * 网络类型为EVDO0 NETWORK_TYPE_EVDO_A 网络类型为EVDOA NETWORK_TYPE_GPRS 网络类型为GPRS
             * NETWORK_TYPE_HSDPA 网络类型为HSDPA NETWORK_TYPE_HSPA 网络类型为HSPA NETWORK_TYPE_HSUPA
             * 网络类型为HSUPA NETWORK_TYPE_UMTS 网络类型为UMTS
             *
             * <p>在中国,联通的3G为UMTS或HSDPA,移动和联通的2G为GPRS或EGDE,电信的2G为CDMA,电信的3G为EVDO
             */
            if (TelephonyManager.NETWORK_TYPE_GPRS == info.getSubtype()
                || //
                TelephonyManager.NETWORK_TYPE_EDGE == info.getSubtype()
                || //
                TelephonyManager.NETWORK_TYPE_CDMA == info.getSubtype()) { // 2G网络

              netType = NetType.TYPE_2G;

            } else { // 3G或其它手机网络
              netType = NetType.TYPE_3G_OR_OTHERS;
            }

          } else { // 其它未知连接方式
            netType = NetType.TYPE_UNKNOWN;
          }

          LogUtils.info(
              "当前网络类型|" + netType.getDesc() + "|" + info.getType() + "|" + info.getSubtype());
        }
      }

    } catch (Throwable e) {
      LogUtils.error(e.getMessage(), e);
    }

    return netType;
  }
  private void initLogstash(String testName) {

    initLogstashHost();

    String pathToLogstash =
        SGTestHelper.getSGTestRootDir().replace("\\", "/") + "/src/main/resources/logstash";
    String confFilePath = pathToLogstash + "/logstash-shipper-client.conf";
    String fixedTestName = testName.substring(0, testName.length() - 2);
    String backupFilePath = pathToLogstash + "/logstash-shipper-client-" + fixedTestName + ".conf";

    if (process == null) {

      try {

        LogUtils.log("copying file " + confFilePath + " to " + backupFilePath);
        IOUtils.copyFile(confFilePath, backupFilePath);
        //                backupFilePath = IOUtils.backupFile(confFilePath);
        IOUtils.replaceTextInFile(
            backupFilePath,
            "<path_to_test_folder>",
            SGTestHelper.getSGTestRootDir().replace("\\", "/")
                + "/../"
                + suiteName
                + "/"
                + testName);
        IOUtils.replaceTextInFile(backupFilePath, "<suite_name>", suiteName);
        IOUtils.replaceTextInFile(backupFilePath, "<test_name>", testName);
        IOUtils.replaceTextInFile(backupFilePath, "<build_number>", buildNumber);
        IOUtils.replaceTextInFile(backupFilePath, "<version>", version);
        IOUtils.replaceTextInFile(backupFilePath, "<host>", logstashHost);

        String logstashJarPath =
            DeploymentUtils.getLocalRepository() + "net/logstash/1.2.2/logstash-1.2.2.jar";
        logstashLogPath = pathToLogstash + "/logstash-" + fixedTestName + ".txt";
        String cmdLine =
            "java -jar "
                + logstashJarPath
                + " agent -f "
                + backupFilePath
                + " -l "
                + logstashLogPath;

        final String[] parts = cmdLine.split(" ");
        final ProcessBuilder pb = new ProcessBuilder(parts);
        LogUtils.log("Executing Command line: " + cmdLine);

        TimeUnit.SECONDS.sleep(1);
        process = pb.start();

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
示例#19
0
 @Override
 protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
   LogUtils.d(TAG, "onQueryComplete token=" + token);
   if (cookie instanceof QueryListener) {
     QueryListener listener = (QueryListener) cookie;
     listener.onQueryComplete(token, cursor);
   } else {
     cursor.close();
     LogUtils.e(TAG, "cookie is another object: " + cookie);
   }
 }
  @Override
  public void onConfigurationFailure(ITestResult iTestResult) {
    super.onConfigurationFailure(iTestResult);
    String testName = iTestResult.getTestClass().getName();
    String configurationName = iTestResult.getMethod().toString().split("\\(|\\)")[0];
    if (!enableLogstash && isAfter(iTestResult)) {
      DumpUtils.copyBeforeConfigurationsLogToTestDir(testName, suiteName);
      testName = testMethodName;
    }
    if (suiteName
        == null) { // this is in case the suite has a @BeforeSuite method. which is invoked before
                   // the onStart is.
      suiteName = System.getProperty("iTests.suiteName", "sgtest");
    }
    LogUtils.log("Configuration Failed: " + configurationName, iTestResult.getThrowable());

    if (enableLogstash && iTestResult.getMethod().isBeforeClassConfiguration()) {
      initLogstash2(iTestResult);
    }

    String newmanTestFolder = System.getProperty("newman.test.path");
    if (newmanTestFolder != null) {
      File testFolder = new File(newmanTestFolder);
      ZipUtils.unzipArchive(testFolder);
      try {
        copyAllFilesToLogDir(testFolder, testFolder);
      } catch (IOException e) {
        LogUtils.log("Failed to copy all log files");
      }
    } else {
      ZipUtils.unzipArchive(testMethodName, suiteName);
    }

    if (enableLogstash
        && isAfter(iTestResult)
        && !iTestResult.getMethod().isAfterClassConfiguration()
        && !iTestResult.getMethod().isAfterSuiteConfiguration()) {
      testName = testMethodName;
    }
    File testFolder = DumpUtils.createTestFolder(testName, suiteName);
    write2LogFile(iTestResult, testFolder);
    write2ErrorTxtFile(iTestResult, testFolder);

    if (isAfter(iTestResult)) {
      if (enableLogstash) {
        if (process != null) {
          killLogstashAgent(1, logstashLogPath);
        }
        if (process2 != null && iTestResult.getMethod().isAfterClassConfiguration()) {
          killLogstashAgent(2, logstashLogPath2);
        }
      }
    }
  }
  @Override
  public void onStart(ITestContext iTestContext) {
    suiteName = System.getProperty("iTests.suiteName", "sgtest");
    LogUtils.log("suite number is now (on start) - " + suiteName);

    if (enableLogstash) {
      buildNumber = System.getProperty("iTests.buildNumber");
      LogUtils.log("build number is now (on start) - " + buildNumber);
      version = System.getProperty("cloudifyVersion");
    }
  }
示例#22
0
 /**
  * M: change the buttons to disable or enable
  *
  * @param whichButton to be setting state
  * @param isEnable whether enable button or disable
  */
 public void setButton(int whichButton, boolean isEnable) {
   AlertDialog dialog = (AlertDialog) getDialog();
   if (null != dialog) {
     Button btn = dialog.getButton(whichButton);
     if (btn != null) {
       btn.setEnabled(isEnable);
       LogUtils.d(TAG, " set button state to " + btn.isEnabled());
     } else {
       LogUtils.d(TAG, "get button" + whichButton + " from dialog is null ");
     }
   }
 }
示例#23
0
 public static void saveAllEnableGWData(GWSaveEntry saveEntry) {
   setLastSaveFolder(saveEntry.path3);
   String now = GTUtils.getSaveDate();
   saveEntry.setNow(now);
   TagTimeEntry[] ttes = OpPerfBridge.getAllEnableProfilerData();
   for (TagTimeEntry tte : ttes) {
     if (null != tte && tte.getAlias().equals("SM")) {
       LogUtils.writeGWDataForSM(saveEntry, tte);
     } else {
       LogUtils.writeGWData(saveEntry, tte);
     }
   }
   LogUtils.writeGWDesc(saveEntry, ttes);
 }
示例#24
0
 public boolean onItemLongClick(
     AdapterView<?> adapterView, View view, int position, long rowId) {
   final int viewType = mTodosListAdapter.getItemViewType(position);
   int editType = TodosListAdapter.EDIT_NULL;
   switch (viewType) {
     case TodosListAdapter.TYPE_TODOS_ITEM:
       editType = TodosListAdapter.EDIT_TODOS;
       break;
     case TodosListAdapter.TYPE_DONES_ITEM:
       editType = TodosListAdapter.EDIT_DONES;
       break;
     default:
       LogUtils.d(TAG, "cann't switch viewType:" + viewType);
   }
   LogUtils.d(
       TAG,
       "onItemLongClick viewType ="
           + viewType
           + " position="
           + position
           + " editType="
           + editType);
   if (mTodosListAdapter.isEditing()
       && editType != mTodosListAdapter.getEditType()
       && getSelectedCount() != 0) {
     // In multi-select mode, not allow do the long click when item
     // is not in edit mode.
     return true;
   }
   if (editType != TodosListAdapter.EDIT_NULL && editType != mTodosListAdapter.getEditType()) {
     if (mTodosListAdapter.setEditingType(editType)) {
       // when first long click,start action mode
       startTodoActionMode();
     }
     updateChangeStateIcon(editType);
   }
   if (editType != TodosListAdapter.EDIT_NULL) {
     Object tag = view.getTag();
     if (tag != null && tag instanceof TodosListAdapter.ViewHolder) {
       TodosListAdapter.ViewHolder holder = (TodosListAdapter.ViewHolder) tag;
       final boolean checked = holder.mTodoInfoCheckBox.isChecked();
       holder.mTodoInfoCheckBox.setChecked(!checked);
       mTodosListAdapter.selectItem(position, !checked);
     }
   }
   updateActionModeTitle();
   updateBottomBarWidgetState();
   return true;
 }
  private boolean passLimitConstrain(int upperBound, int showType) {
    synchronized (mPrefer) {
      long current = System.currentTimeMillis();
      long start = mPrefer.getLong(NotifyAdsDef.PREFER_KEY_STARTTIME, 0);

      if (start == 0) {
        mPrefer.edit().putLong(NotifyAdsDef.PREFER_KEY_STARTTIME, current).commit();
        start = current;
        return true;
      }

      // 如果当前和原先的limit 已经超过了一天,那么就重新设置
      if (current - start > 24 * 3600 * 1000) {
        mPrefer.edit().putLong(NotifyAdsDef.PREFER_KEY_STARTTIME, 0).commit();
        mPrefer.edit().putInt(NotifyAdsDef.PREFER_KEY_NOTIFY_SUCCESS_COUNT, 0).commit();
        mPrefer.edit().putInt(NotifyAdsDef.PREFER_KEY_BUBBLE_SUCCESS_COUNT, 0).commit();
        return true;
      } else {
        // 如果在一天之内,那么我们看是否超出了上限
        if (showType == NotifyAdsDef.ADS_TYPE_NOTIFY) {
          int notifyCount = mPrefer.getInt(NotifyAdsDef.PREFER_KEY_NOTIFY_SUCCESS_COUNT, 0);
          if (notifyCount < upperBound) return true;
        } else if (showType == NotifyAdsDef.ADS_TYPE_BUBBLE) {
          int bubbleCount = mPrefer.getInt(NotifyAdsDef.PREFER_KEY_BUBBLE_SUCCESS_COUNT, 0);
          if (bubbleCount < upperBound * NotifyAdsDef.BUBBLE_LIMIT_TIMES) return true;
        }
      }

      LogUtils.logUpLimit("超过了每天接受广告的上限");
      return false;
    }
  }
  /**
   * Gobbles up all the stuff coming from the InputStream and sends it to the OutputStream specified
   * during object construction.
   */
  public void run() {

    InputStreamReader isr = null;
    BufferedReader br = null;
    try {

      // Set up the input stream
      isr = new InputStreamReader(in);
      br = new BufferedReader(isr);

      // Initialize the temporary results containers
      String line = null;

      // Main processing loop which captures the output
      while ((line = br.readLine()) != null) {
        if (quit) {
          break;
        } else {
          pwOut.println(line);
        }
      }

    } catch (final Throwable e) {
      LogUtils.debugf(this, e, "Unable to read lines.");
    } finally {
      IOUtils.closeQuietly(br);
      IOUtils.closeQuietly(isr);
    }
  }
 @Override
 public void onTestSkipped(ITestResult iTestResult) {
   super.onTestSkipped(iTestResult);
   testMethodName = TestNGUtils.constructTestMethodName(iTestResult);
   LogUtils.log("Test Skipped: " + testMethodName, iTestResult.getThrowable());
   write2LogFile(iTestResult, DumpUtils.createTestFolder(testMethodName, suiteName));
 }
示例#28
0
  public void addBitmapToCache(String url, Bitmap bitmap) {
    if (url != null && bitmap != null) {
      if (mMemoryCache != null && mMemoryCache.get(url) == null) {
        mMemoryCache.put(url, bitmap);
      }

      if (mDiskCache == null) {
        return;
      }

      String str = hashKeyForDisk(url);
      try {
        if (mDiskCache.get(str) != null) return;

        DiskLruCache.Editor editor = mDiskCache.edit(str);
        if (editor == null) return;

        OutputStream output = editor.newOutputStream(0);
        bitmap.compress(mCacheParams.compressFormat, mCacheParams.compressQuality, output);
        editor.commit();
      } catch (IOException e) {
        LogUtils.LOGE(TAG, "addBitmapToCache - " + e);
      }
    }
  }
示例#29
0
  private void init(Context context, ImageCacheParams params) {
    mCacheParams = params;
    File cacheDir = getDiskCacheDir(context, params.uniqueName);
    try {
      if (params.diskCacheEnabled) {
        if (!cacheDir.exists()) {
          cacheDir.mkdir();
        }
        if (getUsableSpace(cacheDir) > params.diskCacheSize) {
          mDiskCache = DiskLruCache.open(cacheDir, 1, 1, params.diskCacheSize);
        }
      }

      if (params.memoryCacheEnabled) {
        mMemoryCache =
            new LruCache<String, Bitmap>(params.memCacheSize) {
              protected int sizeOf(String paramString, Bitmap paramBitmap) {
                return ImageCache.getBitmapSize(paramBitmap);
              }
            };
      }
      return;
    } catch (IOException e) {
      LogUtils.LOGE(TAG, "init - " + e);
    }
  }
 /** Returns all log entries. */
 public List<String> showAll() {
   List<String> ret = new ArrayList<String>(buffer.size());
   for (Object o : buffer) {
     ret.add(LogUtils.stringifyLogObject(o));
   }
   return ret;
 }