use of android.os.Handler in project SimplifyReader by chentao0707.
the class FileCreateThread method run.
@Override
public void run() {
for (DownloadInfo info : download_temp_infos) {
if (download.existsDownloadInfo(info.videoid)) {
if (download.isDownloadFinished(info.videoid)) {
// 已下载完成
PlayerUtil.showTips(R.string.download_exist_finished);
} else {
PlayerUtil.showTips(R.string.download_exist_not_finished);
}
continue;
}
long time = System.currentTimeMillis();
info.createTime = time;
// 用时间戳做ID
info.taskId = String.valueOf(time).substring(5);
if (init(info)) {
Logger.d("DownloadFlow", "init() success");
download.addDownloadingInfo(info);
switch(info.format) {
case DownloadInfo.FORMAT_HD2:
break;
case DownloadInfo.FORMAT_MP4:
break;
default:
break;
}
successCount++;
YoukuPlayerApplication.context.sendBroadcast(new Intent(IDownload.ACTION_CREATE_DOWNLOAD_ONE_READY));
} else {
Logger.d("DownloadFlow", "init() fail");
failCount++;
YoukuPlayerApplication.context.sendBroadcast(new Intent(IDownload.ACTION_CREATE_DOWNLOAD_ONE_FAILED));
if (info.getExceptionId() == DownloadInfo.EXCEPTION_NO_SPACE) {
// 没有空间,提示切换空间
failCount = download_temp_infos.size() - successCount;
ArrayList<SDCardInfo> card = SDCardManager.getExternalStorageDirectory();
if (card != null && card.size() > 1) {
hasMaryPaths = true;
HandlerThread ht = new HandlerThread("handler_thread1");
ht.start();
new Handler(ht.getLooper()) {
public void handleMessage(Message msg) {
/* YoukuPlayerApplication.context
.startActivity(new Intent(
YoukuPlayerApplication.context,
EmptyActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));*/
Toast.makeText(YoukuPlayerApplication.context, "存储空间不足", Toast.LENGTH_SHORT).show();
}
;
}.sendEmptyMessageDelayed(0, 500L);
}
break;
}
continue;
}
}
for (DownloadInfo info : download_temp_infos) {
tempCreateData.remove(info.videoid);
}
showTips();
over();
HandlerThread ht = new HandlerThread("handler_thread2");
ht.start();
new Handler(ht.getLooper()) {
public void handleMessage(Message msg) {
Logger.d("DownloadFlow", "FileCreateThread: create task to download");
download.startNewTask();
}
;
}.sendEmptyMessageDelayed(0, 1000L);
super.run();
}
use of android.os.Handler in project UltimateAndroid by cymcsg.
the class IntentUtils method startPreviewActivity.
/**
* start screen capture after "delay" milliseconds, so the previous activity's
* state recover to normal state, such as button click, list item click,wait
* them to normal state so we can make a good screen capture
*
* @param context
* @param intent
* @param delay time in milliseconds
*/
public static void startPreviewActivity(final Context context, final Intent intent, long delay) {
final Handler mainThread = new Handler(Looper.getMainLooper());
final Runnable postAction = new Runnable() {
@Override
public void run() {
context.startActivity(intent);
}
};
/** process screen capture on background thread */
Runnable action = new Runnable() {
@Override
public void run() {
/**
* activity's root layout id, you can change the android.R.id.content to your root
* layout id
*/
final View contentView = ((Activity) context).findViewById(android.R.id.content);
ByteArrayOutputStream baos = null;
Bitmap bitmap = null;
try {
bitmap = Bitmap.createBitmap(contentView.getWidth(), contentView.getHeight(), Bitmap.Config.ARGB_8888);
contentView.draw(new Canvas(bitmap));
baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, baos);
intent.putExtra(KEY_PREVIEW_IMAGE, baos.toByteArray());
} finally {
try {
/** no need to close, actually do nothing */
if (null != baos)
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
if (null != bitmap && !bitmap.isRecycled()) {
bitmap.recycle();
bitmap = null;
}
}
mainThread.post(postAction);
}
};
if (delay > 0) {
ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
worker.schedule(action, delay, TimeUnit.MILLISECONDS);
} else {
action.run();
}
}
use of android.os.Handler in project UltimateAndroid by cymcsg.
the class MatchView method initView.
private void initView() {
this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Utils.init(getContext());
mLineWidth = Utils.dp2px(1);
mDropHeight = Utils.dp2px(40);
horizontalRandomness = Utils.SCREEN_WIDTH_PIXELS / 2;
setPadding(0, Utils.dp2px(mPaddingTop), 0, Utils.dp2px(mPaddingTop));
mHandler = new Handler() {
@Override
public void dispatchMessage(Message msg) {
super.dispatchMessage(msg);
if (STATE == 1) {
//划入
if (progress < 100) {
progress++;
setProgress((progress * 1f / (100)));
mHandler.sendEmptyMessageDelayed(0, (long) (mInTime * 10));
} else {
STATE = 2;
if (mMatchInListener != null) {
mMatchInListener.onFinish();
}
}
} else if (STATE == 2) {
//划出
if (mIsInLoading) {
lightFinish();
}
if (progress > 0) {
progress--;
setProgress((progress * 1f / (100)));
mHandler.sendEmptyMessageDelayed(0, (long) (mOutTime * 10));
} else {
progress = 0;
if (mMatchOutListener != null) {
mMatchOutListener.onFinish();
}
STATE = 1;
}
}
}
};
}
use of android.os.Handler in project UltimateRecyclerView by cymcsg.
the class LauncherActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
ultimateRecyclerView = (UltimateRecyclerView) findViewById(R.id.ultimate_recycler_view);
ultimateRecyclerView.setHasFixedSize(false);
final List<String> stringList = new ArrayList<>();
stringList.add("111");
stringList.add("aaa");
stringList.add("222");
stringList.add("33");
stringList.add("44");
stringList.add("55");
stringList.add("66");
stringList.add("11771");
simpleRecyclerViewAdapter = new SimpleAdapter(stringList);
linearLayoutManager = new LinearLayoutManager(this);
ultimateRecyclerView.setLayoutManager(linearLayoutManager);
StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(simpleRecyclerViewAdapter);
ultimateRecyclerView.addItemDecoration(headersDecor);
//// ultimateRecyclerView.setEmptyView(getResources().getIdentifier("empty_view","layout",getPackageName()));
// ultimateRecyclerView.showEmptyView();
// ultimateRecyclerView.enableLoadmore();
//simpleRecyclerViewAdapter.setCustomLoadMoreView(LayoutInflater.from(this)
// .inflate(R.layout.custom_bottom_progressbar, null));
ultimateRecyclerView.setLoadMoreView(LayoutInflater.from(this).inflate(R.layout.custom_bottom_progressbar, null));
ultimateRecyclerView.setParallaxHeader(getLayoutInflater().inflate(R.layout.parallax_recyclerview_header, ultimateRecyclerView.mRecyclerView, false));
// // ultimateRecyclerView.setNormalHeader(getLayoutInflater().inflate(R.layout.parallax_recyclerview_header, ultimateRecyclerView.mRecyclerView, false));
ultimateRecyclerView.setOnParallaxScroll(new UltimateRecyclerView.OnParallaxScroll() {
@Override
public void onParallaxScroll(float percentage, float offset, View parallax) {
Drawable c = toolbar.getBackground();
c.setAlpha(Math.round(127 + percentage * 128));
toolbar.setBackgroundDrawable(c);
}
});
ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff"));
ultimateRecyclerView.setDefaultOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
simpleRecyclerViewAdapter.insert(moreNum++ + " Refresh things", 0);
ultimateRecyclerView.setRefreshing(false);
// ultimateRecyclerView.scrollBy(0, -50);
linearLayoutManager.scrollToPosition(0);
// ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter);
// simpleRecyclerViewAdapter.notifyDataSetChanged();
}
}, 1000);
}
});
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(simpleRecyclerViewAdapter);
mItemTouchHelper = new ItemTouchHelper(callback);
mItemTouchHelper.attachToRecyclerView(ultimateRecyclerView.mRecyclerView);
simpleRecyclerViewAdapter.setOnDragStartListener(new SimpleAdapter.OnStartDragListener() {
@Override
public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
mItemTouchHelper.startDrag(viewHolder);
}
});
ultimateRecyclerView.reenableLoadmore();
ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter);
ultimateRecyclerView.setOnLoadMoreListener(new UltimateRecyclerView.OnLoadMoreListener() {
@Override
public void loadMore(int itemsCount, final int maxLastVisiblePosition) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
// linearLayoutManager.scrollToPositionWithOffset(maxLastVisiblePosition,-1);
// linearLayoutManager.scrollToPosition(maxLastVisiblePosition);
}
}, 1000);
}
});
// ultimateRecyclerView.setDefaultSwipeToRefreshColorScheme(getResources().getColor(android.R.color.holo_blue_bright),
// getResources().getColor(android.R.color.holo_green_light),
// getResources().getColor(android.R.color.holo_orange_light),
// getResources().getColor(android.R.color.holo_red_light));
// ultimateRecyclerView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
// @Override
// public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
//
// }
//
// @Override
// public void onDownMotionEvent() {
//
// }
//
// @Override
// public void onUpOrCancelMotionEvent(ObservableScrollState observableScrollState) {
//// if (observableScrollState == ObservableScrollState.DOWN) {
//// ultimateRecyclerView.showToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
//// ultimateRecyclerView.showFloatingActionMenu();
//// } else if (observableScrollState == ObservableScrollState.UP) {
//// ultimateRecyclerView.hideToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
//// ultimateRecyclerView.hideFloatingActionMenu();
//// } else if (observableScrollState == ObservableScrollState.STOP) {
//// }
// URLogs.d("onUpOrCancelMotionEvent");
// if (observableScrollState == ObservableScrollState.UP) {
// ultimateRecyclerView.hideToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
// ultimateRecyclerView.hideFloatingActionMenu();
// } else if (observableScrollState == ObservableScrollState.DOWN) {
// ultimateRecyclerView.showToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
// ultimateRecyclerView.showFloatingActionMenu();
// }
// }
// });
ultimateRecyclerView.showFloatingButtonView();
//
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
for (Type type : Type.values()) {
spinnerAdapter.add(type.name());
}
spinner.setAdapter(spinnerAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
ultimateRecyclerView.setItemAnimator(Type.values()[position].getAnimator());
ultimateRecyclerView.getItemAnimator().setAddDuration(500);
ultimateRecyclerView.getItemAnimator().setRemoveDuration(500);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
simpleRecyclerViewAdapter.insert("newly added item", 1);
}
});
findViewById(R.id.del).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
simpleRecyclerViewAdapter.remove(1);
}
});
//
}
use of android.os.Handler in project glasquare by davidvavra.
the class QrScanActivity method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan_qr);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
autoFocusHandler = new Handler();
mCamera = getCameraInstance();
/* Instance barcode scanner */
scanner = new ImageScanner();
scanner.setConfig(0, Config.X_DENSITY, 3);
scanner.setConfig(0, Config.Y_DENSITY, 3);
mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
FrameLayout preview = (FrameLayout) findViewById(R.id.cameraPreview);
preview.addView(mPreview);
}
Aggregations