Search in sources :

Example 26 with Handler

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();
}
Also used : HandlerThread(android.os.HandlerThread) Message(android.os.Message) Handler(android.os.Handler) Intent(android.content.Intent) SDCardInfo(com.youku.service.download.SDCardManager.SDCardInfo)

Example 27 with Handler

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();
    }
}
Also used : Bitmap(android.graphics.Bitmap) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Canvas(android.graphics.Canvas) Handler(android.os.Handler) Activity(android.app.Activity) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) View(android.view.View)

Example 28 with Handler

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;
                }
            }
        }
    };
}
Also used : Message(android.os.Message) Handler(android.os.Handler)

Example 29 with Handler

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);
        }
    });
//
}
Also used : SimpleItemTouchHelperCallback(com.marshalchen.ultimaterecyclerview.itemTouchHelper.SimpleItemTouchHelperCallback) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) Drawable(android.graphics.drawable.Drawable) Handler(android.os.Handler) StickyRecyclerHeadersDecoration(com.marshalchen.ultimaterecyclerview.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 30 with Handler

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);
}
Also used : FrameLayout(android.widget.FrameLayout) ImageScanner(net.sourceforge.zbar.ImageScanner) Handler(android.os.Handler)

Aggregations

Handler (android.os.Handler)1843 Message (android.os.Message)253 View (android.view.View)201 Intent (android.content.Intent)165 HandlerThread (android.os.HandlerThread)135 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 TextView (android.widget.TextView)114 ArrayList (java.util.ArrayList)95 Test (org.junit.Test)80 Context (android.content.Context)67 RemoteException (android.os.RemoteException)63 IOException (java.io.IOException)61 IntentFilter (android.content.IntentFilter)57 ComponentName (android.content.ComponentName)56 ImageView (android.widget.ImageView)55 RecyclerView (android.support.v7.widget.RecyclerView)52 Bundle (android.os.Bundle)51 Looper (android.os.Looper)51 File (java.io.File)45 HashMap (java.util.HashMap)44