use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class SinaSDK method webGetHotTopicsHotStatus.
/**
* 热门话题的推荐推荐微博列表
*
* @param containerId
* @param sinceId
* @return
* @throws TaskException
*/
public StatusContents webGetHotTopicsHotStatus(String containerId, String sinceId) throws TaskException {
Params params = new Params();
params.addParameter("containerid", containerId);
if (!TextUtils.isEmpty(sinceId)) {
params.addParameter("since_id", sinceId);
}
Setting action = newSetting("webGetHotTopicsHotStatus", "container/getIndex", "热门话题热门微博");
action.getExtras().put(HTTP_UTILITY, newSettingExtra(HTTP_UTILITY, TimelineHotTopicsHttpUtility.class.getName(), ""));
HttpConfig config = webConfig();
config.addHeader("Referer", String.format("http://m.weibo.cn/p/index?containerid=%s", containerId));
try {
return doGet(config, action, params, StatusContents.class);
} catch (Exception e) {
if (e instanceof TaskException)
checkWebResult((TaskException) e);
throw e;
}
}
use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class WallpaperDownloadTask method saveWallpaper.
// 保存壁纸到相册
private File saveWallpaper(File file) throws TaskException {
File savedFile = getWallpaperSaveFile(mImageUrl);
if (savedFile.exists())
return savedFile;
if (file.exists()) {
try {
FileUtils.copyFile(file, savedFile);
Logger.v("保存成功!:" + savedFile.getAbsolutePath());
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
// 解决在部分机器缓存更新不及时问题
mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
}
try {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(savedFile);
intent.setData(uri);
mContext.sendBroadcast(intent);
} catch (Exception e) {
}
} catch (Exception e) {
e.printStackTrace();
}
return savedFile;
}
return null;
}
use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class WallpaperDownloadTask method setWallpaper.
// 设置壁纸
public static void setWallpaper(Context context, File file, final OnProgressCallback callback) throws TaskException {
long time = System.currentTimeMillis();
try {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(GlobalContext.getInstance());
try {
DisplayMetrics dm = new DisplayMetrics();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
int navigationBarHeight = SystemUtils.getNavigationBarHeight(context);
int wallpaperWidth = width;
int wallpaperHeight = height;
Options opts = new Options();
opts.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), opts);
boolean decode = false;
if (opts.outHeight > height + navigationBarHeight) {
decode = true;
}
Logger.d(TAG, "image height = %d, screen height = %d", opts.outHeight, height + navigationBarHeight);
if (decode) {
// docode的时间会稍微长一点,idol3测试在1S内,所以先显示一个99%的进度
// if (progress <= 0) {
// progress = 999l;
// total = 1000l;
// publishProgress(progress, total);
// }
opts.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeStream(new FileInputStream(file));
Matrix matrix = new Matrix();
float scale = wallpaperHeight * 1.0f / bitmap.getHeight();
matrix.setScale(scale, scale);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
wallpaperManager.setStream(in);
if (callback != null) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
callback.onSetWallpaper(true);
}
});
}
Logger.d(TAG, "设置处理后的壁纸耗时 : " + (System.currentTimeMillis() - time));
return;
}
} catch (Throwable e) {
Logger.printExc(WallpaperDownloadTask.class, e);
}
wallpaperManager.setStream(new FileInputStream(file));
Logger.d(TAG, "设置原壁纸耗时 : " + (System.currentTimeMillis() - time));
if (callback != null) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
callback.onSetWallpaper(true);
}
});
}
} catch (Exception e) {
Logger.printExc(WallpaperDownloadTask.class, e);
if (callback != null) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
callback.onSetWallpaper(false);
}
});
}
throw new TaskException("", context.getResources().getString(R.string.txt_set_wallpaper_fail));
}
}
use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class APublishFragment method choieUri.
@Override
public void choieUri(Uri uri, int requestCode) {
Logger.e(uri.toString());
// 当拍摄照片时,提示是否设置旋转90度
if (!AppSettings.isRotatePic() && !ActivityHelper.getBooleanShareData(GlobalContext.getInstance(), "RotatePicNoRemind", false)) {
new MaterialDialog.Builder(getActivity()).title(R.string.remind).content(R.string.publish_rotate_remind).negativeText(R.string.donnot_remind).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
ActivityHelper.putBooleanShareData(GlobalContext.getInstance(), "RotatePicNoRemind", true);
}
}).positiveText(R.string.i_know).show();
}
// 拍摄照片时,顺时针旋转90度
if (requestCode == PhotoChoice.CAMERA_IMAGE_REQUEST_CODE && AppSettings.isRotatePic()) {
final String path = uri.toString().replace("file://", "");
new WorkTask<Void, Void, String>() {
@Override
public String workInBackground(Void... params) throws TaskException {
try {
Bitmap bitmap = BitmapDecoder.decodeSampledBitmapFromFile(path, SystemUtils.getScreenHeight(getActivity()), SystemUtils.getScreenHeight(getActivity()));
bitmap = BitmapUtil.rotateBitmap(bitmap, 90);
ByteArrayOutputStream outArray = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, outArray);
FileUtils.writeFile(new File(path), outArray.toByteArray());
} catch (OutOfMemoryError e) {
e.printStackTrace();
}
return path;
}
protected void onSuccess(String result) {
setPicUri(result);
}
}.execute();
} else {
setPicUri(uri.toString());
}
}
use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class CacheClearFragment method clearCache.
private void clearCache(final boolean all) {
UMengUtil.onEvent(getActivity(), all ? "clear_cache_all" : "clear_cache_outofdate");
final WorkTask<Void, String, Void> task = new WorkTask<Void, String, Void>() {
@Override
public Void workInBackground(Void... params) throws TaskException {
File cacheRootFile = new File(cachePath);
deleteFile(cacheRootFile, all);
return null;
}
void deleteFile(File file, boolean all) {
if (!file.exists())
return;
if (!isCancelled()) {
if (file.isDirectory()) {
File[] childFiles = file.listFiles();
for (File childFile : childFiles) deleteFile(childFile, all);
} else {
publishProgress(String.valueOf(file.length()));
boolean clear = all;
if (!clear) {
Logger.v("ClearCache", String.format("文件最后修改时间是%s", DateUtils.formatDate(file.lastModified(), DateUtils.TYPE_01)));
clear = System.currentTimeMillis() - file.lastModified() >= RETAIN_TIME;
if (clear)
Logger.v("ClearCache", "缓存超过2天,删除该缓存");
} else {
file.delete();
}
// if (clear && file.delete())
// SystemUtils.scanPhoto(file);
}
}
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
if (values != null && values.length > 0 && materialDialog != null && getActivity() != null) {
int value = Integer.parseInt(values[0]);
// materialDialog.incrementProgress(value / 1024);
materialDialog.incrementProgress(1);
// if (value * 1.0f / 1024 / 1024 > 1)
// materialDialog.setContent(String.format("%s M", new DecimalFormat("#.00").format(value * 1.0d / 1024 / 1024)));
// else
// materialDialog.setContent(String.format("%d Kb", value / 1024));
}
}
protected void onFinished() {
if (materialDialog != null && materialDialog.isShowing())
materialDialog.dismiss();
}
}.execute();
materialDialog = new MaterialDialog.Builder(getActivity()).title(R.string.settings_cache_clear).contentGravity(GravityEnum.CENTER).dismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
task.cancel(true);
calculateCacheFileSize();
}
}).positiveText(R.string.cancel).progress(false, cacheCount, true).show();
}
Aggregations