use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class VideoPlayerActivity method playWithShort.
private void playWithShort(final String url) {
shortUri = Uri.parse(url);
Logger.d(TAG, "short : " + url);
new WorkTask<Void, Void, VideoBean>() {
@Override
protected void onPrepare() {
super.onPrepare();
layoutContent.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
}
@Override
public VideoBean workInBackground(Void... params) throws TaskException {
String id = KeyGenerator.generateMD5(url);
// VideoBean videoBean = SinaDB.getDB().selectById(null, VideoBean.class, id);
// if (videoBean != null && !TextUtils.isEmpty(videoBean.getImage()) && !TextUtils.isEmpty(videoBean.getVideoUrl())) {
// return videoBean;
// }
UrlsBean urlsBean = SinaSDK.getInstance(AppContext.getAccount().getAccessToken()).urlShort2Long(url);
if (urlsBean != null && urlsBean.getUrls() != null && urlsBean.getUrls().size() > 0) {
UrlBean urlBean = urlsBean.getUrls().get(0);
VideoBean videoBean = new VideoBean();
videoBean.setIdStr(KeyGenerator.generateMD5(url));
videoBean.setShortUrl(urlBean.getUrl_short());
videoBean.setLongUrl(urlBean.getUrl_long());
int repeat = 8;
while (repeat-- > 0) {
try {
if (VideoService.isSinaVideo(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_SINA);
videoBean = VideoService.getVideoFromSinaVideo(videoBean);
} else if (VideoService.isWeipai(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_WEIPAI);
videoBean = VideoService.getVideoFromWeipai(videoBean);
} else if (VideoService.isMeipai(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_MEIPAI);
videoBean = VideoService.getVideoFromMeipai(videoBean);
}
repeat = 0;
if (!TextUtils.isEmpty(videoBean.getVideoUrl())) {
if (!TextUtils.isEmpty(videoBean.getImage())) {
SinaDB.getDB().update(null, videoBean);
}
return videoBean;
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
throw new TaskException("解析短链接失败");
}
@Override
protected void onSuccess(VideoBean videoBean) {
super.onSuccess(videoBean);
playWithVideo(url, videoBean);
}
@Override
protected void onFailure(TaskException exception) {
super.onFailure(exception);
if (isDestory())
return;
new MaterialDialog.Builder(VideoPlayerActivity.this).forceStacking(true).content(R.string.video_short_faild).positiveText(R.string.video2browser).negativeText(R.string.video_again).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
toBrowser(url);
}
}).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
playWithShort(url);
}
}).show();
}
}.execute();
}
use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class CacheClearFragment method calculateCacheFileSize.
private void calculateCacheFileSize() {
cacheSize = 0;
cacheCount = 0;
new WorkTask<Void, Void, Void>() {
@Override
protected void onPrepare() {
super.onPrepare();
clearCachePref.setEnabled(false);
clearCachePref.setSummary("正在计算...");
}
@Override
public Void workInBackground(Void... params) throws TaskException {
calculateFileSize(cachePath);
return null;
}
@Override
protected void onFinished() {
super.onFinished();
clearCachePref.setEnabled(true);
if (cacheSize * 1.0f / 1024 / 1024 > 1)
clearCachePref.setSummary(String.format("%s M", new DecimalFormat("#.00").format(cacheSize * 1.0d / 1024 / 1024)));
else
clearCachePref.setSummary(String.format("%d Kb", cacheSize / 1024));
}
void calculateFileSize(String path) {
File file = new File(path);
if (file.isDirectory()) {
File[] childFiles = file.listFiles();
for (File childFile : childFiles) calculateFileSize(childFile.getAbsolutePath());
} else {
cacheSize += file.length();
cacheCount += 1;
}
}
}.execute();
}
use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class WeiboClientActivity method choieUri.
@Override
public void choieUri(Uri uri, int requestCode) {
// 当拍摄照片时,提示是否设置旋转90度
if (!AppSettings.isRotatePic() && !ActivityHelper.getBooleanShareData(GlobalContext.getInstance(), "RotatePicNoRemind", false)) {
new MaterialDialog.Builder(this).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(WeiboClientActivity.this), SystemUtils.getScreenHeight(WeiboClientActivity.this));
bitmap = BitmapUtil.rotateBitmap(bitmap, 90);
ByteArrayOutputStream outArray = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outArray);
FileUtils.writeFile(new File(path), outArray.toByteArray());
} catch (OutOfMemoryError e) {
e.printStackTrace();
}
return path;
}
protected void onSuccess(String result) {
uploadPic(result);
}
}.execute();
} else {
uploadPic(uri.toString());
}
}
use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class WeiboClientActivity method fillAccount.
private void fillAccount() {
final String url = "http://passport.weibo.cn/signin/login?";
new WorkTask<Void, Void, String>() {
@Override
protected void onPrepare() {
super.onPrepare();
ViewUtils.createProgressDialog(WeiboClientActivity.this, getString(R.string.account_fillaccount_loading), ThemeUtils.getThemeColor()).show();
}
@Override
public String workInBackground(Void... p) throws TaskException {
try {
AccountBean accountBean = AccountUtils.getLogedinAccount();
if (TextUtils.isEmpty(accountBean.getAccount()) || TextUtils.isEmpty(accountBean.getPassword()))
throw new TaskException("", getString(R.string.account_fillaccount_faild));
String js = FileUtils.readAssetsFile("mobile.js", GlobalContext.getInstance());
js = js.replace("%username%", accountBean.getAccount());
js = js.replace("%password%", accountBean.getPassword());
Document dom = Jsoup.connect(url).get();
String html = dom.toString();
html = html.replace("</head>", js + "</head>");
return html;
} catch (Exception e) {
e.printStackTrace();
}
throw new TaskException("", getString(R.string.account_fillaccount_faild));
}
@Override
protected void onSuccess(String s) {
super.onSuccess(s);
Logger.e(s);
mWebView.loadDataWithBaseURL("http://passport.weibo.cn", s, "text/html", "UTF-8", "");
GlobalContext.getInstance().getHandler().postDelayed(new Runnable() {
@Override
public void run() {
mWebView.loadUrl("javascript:fillAccount()");
ViewUtils.dismissProgressDialog();
}
}, 1500);
}
@Override
protected void onFailure(TaskException exception) {
super.onFailure(exception);
showMessage(exception.getMessage());
ViewUtils.dismissProgressDialog();
}
}.execute();
}
use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.
the class MenuHeaderView method setupHeaderView.
public void setupHeaderView(FrameLayout parent) {
LayoutInflater inflater = LayoutInflater.from(menuFragment.getActivity());
// 初始化View
if (mHeaderView == null) {
mHeaderView = inflater.inflate(R.layout.layout_menu_header, parent, false);
int height = GlobalContext.getInstance().getResources().getDimensionPixelSize(R.dimen.material_drawer_account_header_height);
if (Build.VERSION.SDK_INT >= 19) {
height += SystemUtils.getStatusBarHeight(menuFragment.getActivity());
}
parent.addView(mHeaderView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, height));
// 绑定视图
InjectUtility.initInjectedView(GlobalContext.getInstance(), this, mHeaderView);
}
View view = mHeaderView.findViewById(R.id.material_drawer_account_header);
if (Build.VERSION.SDK_INT >= 19) {
view.setPadding(view.getPaddingStart(), SystemUtils.getStatusBarHeight(menuFragment.getActivity()), view.getPaddingRight(), view.getPaddingBottom());
}
final WeiBoUser user = AppContext.getAccount().getUser();
// 头像
ImageView imgPhoto = (ImageView) mHeaderView.findViewById(R.id.material_drawer_account_header_current);
imgPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (txtFollowersNewHint != null && txtFollowersNewHint.getVisibility() == View.VISIBLE) {
((MainActivity) menuFragment.getActivity()).closeDrawer();
FriendshipPagerFragment.launch(menuFragment.getActivity(), AppContext.getAccount().getUser(), 1);
} else {
BizFragment.createBizFragment(menuFragment).launchProfile(AppContext.getAccount().getUser());
}
}
});
BitmapLoader.getInstance().display(menuFragment, user.getAvatar_large(), imgPhoto, ImageConfigUtils.getLargePhotoConfig());
// 名字
TextView txtName = (TextView) mHeaderView.findViewById(R.id.material_drawer_account_header_name);
txtName.setText(user.getScreen_name());
// 背景
final ImageView imgCover = (ImageView) mHeaderView.findViewById(R.id.material_drawer_account_header_background);
new WorkTask<Void, Void, Bitmap>() {
@Override
public Bitmap workInBackground(Void... params) throws TaskException {
try {
BitmapLoader.BitmapBytesAndFlag bitmapBytesAndFlag = BitmapLoader.getInstance().doDownload(user.getCover_image_phone(), new ImageConfig());
return BitmapFactory.decodeByteArray(bitmapBytesAndFlag.bitmapBytes, 0, bitmapBytesAndFlag.bitmapBytes.length);
} catch (Exception e) {
}
throw new TaskException("", "");
}
@Override
protected void onSuccess(Bitmap bitmap) {
super.onSuccess(bitmap);
new FadeInDisplayer().loadCompletedisplay(imgCover, new BitmapDrawable(GlobalContext.getInstance().getResources(), bitmap));
}
@Override
protected void onFailure(TaskException exception) {
super.onFailure(exception);
imgCover.setImageDrawable(new BitmapDrawable(GlobalContext.getInstance().getResources(), BitmapFactory.decodeResource(GlobalContext.getInstance().getResources(), R.drawable.bg_banner_dialog)));
}
}.execute();
// 显示账号
mHeaderView.findViewById(R.id.material_drawer_account_header_text_section).setOnClickListener(this);
}
Aggregations