com.hippo.yorozuya.SimpleHandler Java Examples

The following examples show how to use com.hippo.yorozuya.SimpleHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TypeSendFragment.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private void doReply() {
    ACReplyStruct struct = new ACReplyStruct();
    struct.name = mName.getText().toString();
    struct.email = mEmail.getText().toString();
    struct.title = mTitle.getText().toString();
    struct.content = mEditText.getText().toString();
    struct.resto = mId;
    struct.image = mSeletedImageUri != null ? new UriInputStreamPipe(
            getContext().getApplicationContext(), mSeletedImageUri) : null;
    struct.imageType = mSeletedImageType;
    struct.water = mWatermark.isChecked();

    NMBRequest request = new NMBRequest();
    request.setSite(mSite);
    request.setMethod(NMBClient.METHOD_REPLY);
    request.setArgs(struct);
    request.setCallback(new ActionListener(getContext(), mMethod, mId, struct.content, mSeletedImageBitmap));
    mNMBClient.execute(request);

    SimpleHandler.getInstance().post(new Runnable() {
        @Override
        public void run() {
            getFragmentHost().finishFragment(TypeSendFragment.this);
        }
    });
}
 
Example #2
Source File: DownloadService.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
public void startForeground() {
    if (mPosted) {
        mOps = OPS_START_FOREGROUND;
    } else {
        long now = SystemClock.currentThreadTimeMillis();
        if (now - mLastTime > DELAY) {
            // Wait long enough, do it now
            if (mService != null) {
                mService.startForeground(mId, mBuilder.build());
            }
        } else {
            // Too quick, post delay
            mOps = OPS_START_FOREGROUND;
            mPosted = true;
            SimpleHandler.getInstance().postDelayed(this, DELAY);
        }
    }
}
 
Example #3
Source File: DownloadService.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
public void cancel() {
    if (mPosted) {
        mOps = OPS_CANCEL;
    } else {
        long now = SystemClock.currentThreadTimeMillis();
        if (now - mLastTime > DELAY) {
            // Wait long enough, do it now
            mNotifyManager.cancel(mId);
        } else {
            // Too quick, post delay
            mOps = OPS_CANCEL;
            mPosted = true;
            SimpleHandler.getInstance().postDelayed(this, DELAY);
        }
    }
}
 
Example #4
Source File: GalleryActivity.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    mGLRootView = null;
    mGalleryView = null;
    if (mGalleryAdapter != null) {
        mGalleryAdapter.clearUploader();
        mGalleryAdapter = null;
    }
    if (mGalleryProvider != null) {
        mGalleryProvider.setListener(null);
        mGalleryProvider.stop();
        mGalleryProvider = null;
    }

    mMaskView = null;
    mClock = null;
    mProgress = null;
    mBattery = null;
    mSeekBarPanel = null;
    mLeftText = null;
    mRightText = null;
    mSeekBar = null;

    SimpleHandler.getInstance().removeCallbacks(mHideSliderRunnable);
}
 
Example #5
Source File: RecaptchaView.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
public void load() {
  if (loading) {
    return;
  }
  loading = false;
  challenge = null;
  image = null;

  if (loadingDrawable == null) {
    loadingDrawable = new TextDrawable(getContext().getString(R.string.recaptcha_loading), 0.6f);
    loadingDrawable.setBackgroundColor(Color.GRAY);
    loadingDrawable.setTextColor(Color.WHITE);
  }
  load(loadingDrawable);

  RecaptchaV1.recaptcha(getContext(), CHALLENGE, SimpleHandler.getInstance(), this);
}
 
Example #6
Source File: FavoritesScene.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
@Override
@Implemented(EasyRecyclerView.CustomChoiceListener.class)
public void onIntoCustomChoice(EasyRecyclerView view) {
    if (mFabLayout != null) {
        showSelectionFabs();
        mFabLayout.setAutoCancel(false);
        // Delay expanding action to make layout work fine
        SimpleHandler.getInstance().post(() -> mFabLayout.setExpanded(true));
    }
    if (mHelper != null) {
        mHelper.setRefreshLayoutEnable(false);
    }
    // Lock drawer
    setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT);
    setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
}
 
Example #7
Source File: DownloadService.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
public void show() {
    if (mPosted) {
        mOps = OPS_NOTIFY;
    } else {
        long now = SystemClock.currentThreadTimeMillis();
        if (now - mLastTime > DELAY) {
            // Wait long enough, do it now
            mNotifyManager.notify(mId, mBuilder.build());
        } else {
            // Too quick, post delay
            mOps = OPS_NOTIFY;
            mPosted = true;
            SimpleHandler.getInstance().postDelayed(this, DELAY);
        }
        mLastTime = now;
    }
}
 
Example #8
Source File: GalleryActivity.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    mGLRootView = null;
    mGalleryView = null;
    if (mGalleryAdapter != null) {
        mGalleryAdapter.clearUploader();
        mGalleryAdapter = null;
    }
    if (mGalleryProvider != null) {
        mGalleryProvider.setListener(null);
        mGalleryProvider.stop();
        mGalleryProvider = null;
    }

    mMaskView = null;
    mClock = null;
    mProgress = null;
    mBattery = null;
    mSeekBarPanel = null;
    mLeftText = null;
    mRightText = null;
    mSeekBar = null;

    SimpleHandler.getInstance().removeCallbacks(mHideSliderRunnable);
}
 
Example #9
Source File: ImageWrapper.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    //Log.i(TAG, this + " run");

    // Check recycled
    if (mImage.isRecycled()) {
        mRunning = false;
        return;
    }

    mImage.advance();

    if (notifyUpdate()) {
        if (mRunning) {
            SimpleHandler.getInstance().postDelayed(this, Math.max(0, mImage.getDelay()));
        }
    } else {
        // No callback ? Stop now
        Log.w(TAG, "No callback");
        mRunning = false;
    }
}
 
Example #10
Source File: TypeSendFragment.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
@Override
public void onFailure(final Exception e) {
    mImage = null;

    if (!TextUtils.isEmpty(mContent)) {
        DB.addDraft(mContent);
    }

    SimpleHandler.getInstance().postDelayed(new Runnable() {
        @Override
        public void run() {
            Context context = mContext;
            Toast.makeText(context, context.getString(mMethod == METHOD_REPLY ? R.string.reply_failed :
                    R.string.create_post_failed) + "\n" +
                    ExceptionUtils.getReadableString(context, e), Toast.LENGTH_SHORT).show();
            Messenger.getInstance().notify(METHOD_REPLY == mMethod ?
                    Constants.MESSENGER_ID_REPLY : Constants.MESSENGER_ID_CREATE_POST, mId);
        }
    }, 1000); // Wait a seconds to make sure the server has done with the post
}
 
Example #11
Source File: TypeSendFragment.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private void doCreatePost() {
    ACPostStruct struct = new ACPostStruct();
    struct.name = mName.getText().toString();
    struct.email = mEmail.getText().toString();
    struct.title = mTitle.getText().toString();
    struct.content = mEditText.getText().toString();
    struct.fid = mId;
    struct.image = mSeletedImageUri != null ? new UriInputStreamPipe(
            getContext().getApplicationContext(), mSeletedImageUri) : null;
    struct.imageType = mSeletedImageType;
    struct.water = mWatermark.isChecked();

    NMBRequest request = new NMBRequest();
    request.setSite(mSite);
    request.setMethod(NMBClient.METHOD_CREATE_POST);
    request.setArgs(struct);
    request.setCallback(new ActionListener(getContext(), mMethod, mId, struct.content, mSeletedImageBitmap));
    mNMBClient.execute(request);

    SimpleHandler.getInstance().post(new Runnable() {
        @Override
        public void run() {
            getFragmentHost().finishFragment(TypeSendFragment.this);
        }
    });
}
 
Example #12
Source File: TypeSendFragment.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private void hideEmojiKeyboard() {
    mEmoji.setDrawable(mEmojiOff);

    // Clear FLAG_ALT_FOCUSABLE_IM
    getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

    // Show ime keyboard
    SimpleHandler.getInstance().post(new Runnable() {
        @Override
        public void run() {
            InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Service.INPUT_METHOD_SERVICE);
            imm.showSoftInput(mEditText, 0);
        }
    });

    mEmojiKeyboard.setVisibility(View.GONE);
}
 
Example #13
Source File: DownloadService.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
public void startForeground() {
    if (mPosted) {
        mOps = OPS_START_FOREGROUND;
    } else {
        long now = SystemClock.currentThreadTimeMillis();
        if (now - mLastTime > DELAY) {
            // Wait long enough, do it now
            if (mService != null) {
                mService.startForeground(mId, mBuilder.build());
            }
        } else {
            // Too quick, post delay
            mOps = OPS_START_FOREGROUND;
            mPosted = true;
            SimpleHandler.getInstance().postDelayed(this, DELAY);
        }
    }
}
 
Example #14
Source File: DownloadService.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
public void cancel() {
    if (mPosted) {
        mOps = OPS_CANCEL;
    } else {
        long now = SystemClock.currentThreadTimeMillis();
        if (now - mLastTime > DELAY) {
            // Wait long enough, do it now
            mNotifyManager.cancel(mId);
        } else {
            // Too quick, post delay
            mOps = OPS_CANCEL;
            mPosted = true;
            SimpleHandler.getInstance().postDelayed(this, DELAY);
        }
    }
}
 
Example #15
Source File: DownloadService.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
public void show() {
    if (mPosted) {
        mOps = OPS_NOTIFY;
    } else {
        long now = SystemClock.currentThreadTimeMillis();
        if (now - mLastTime > DELAY) {
            // Wait long enough, do it now
            mNotifyManager.notify(mId, mBuilder.build());
        } else {
            // Too quick, post delay
            mOps = OPS_NOTIFY;
            mPosted = true;
            SimpleHandler.getInstance().postDelayed(this, DELAY);
        }
        mLastTime = now;
    }
}
 
Example #16
Source File: DownloadManager.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public void stop() {
    if (!mStop) {
        mStop = true;
        mBytesRead = 0;
        oldSpeed = -1;
        mContentLengthMap.clear();
        mReceivedSizeMap.clear();
        SimpleHandler.getInstance().removeCallbacks(this);
    }
}
 
Example #17
Source File: GalleryActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
    SimpleHandler.getInstance().postDelayed(mHideSliderRunnable, HIDE_SLIDER_DELAY);
    int progress = seekBar.getProgress();
    if (progress != mCurrentIndex && null != mGalleryView) {
        mGalleryView.setCurrentPage(progress);
    }
}
 
Example #18
Source File: GalleryActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged() {
    super.onDataChanged();

    if (mGalleryProvider != null) {
        int size = mGalleryProvider.size();
        NotifyTask task = mNotifyTaskPool.pop();
        if (task == null) {
            task = new NotifyTask();
        }
        task.setData(NotifyTask.KEY_SIZE, size);
        SimpleHandler.getInstance().post(task);
    }
}
 
Example #19
Source File: GalleryActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private void onTapSliderArea() {
    if (mSeekBarPanel == null || mSize <= 0 || mCurrentIndex < 0) {
        return;
    }

    SimpleHandler.getInstance().removeCallbacks(mHideSliderRunnable);

    if (mSeekBarPanel.getVisibility() == View.VISIBLE) {
        hideSlider(mSeekBarPanel);
    } else {
        showSlider(mSeekBarPanel);
        SimpleHandler.getInstance().postDelayed(mHideSliderRunnable, HIDE_SLIDER_DELAY);
    }
}
 
Example #20
Source File: GalleryActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onTapMenuArea() {
    NotifyTask task = mNotifyTaskPool.pop();
    if (task == null) {
        task = new NotifyTask();
    }
    task.setData(NotifyTask.KEY_TAP_MENU_AREA, 0);
    SimpleHandler.getInstance().post(task);
}
 
Example #21
Source File: GalleryActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onTapSliderArea() {
    NotifyTask task = mNotifyTaskPool.pop();
    if (task == null) {
        task = new NotifyTask();
    }
    task.setData(NotifyTask.KEY_TAP_SLIDER_AREA, 0);
    SimpleHandler.getInstance().post(task);
}
 
Example #22
Source File: GalleryActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpdateCurrentIndex(int index) {
    if (null != mGalleryProvider) {
        mGalleryProvider.putStartPage(index);
    }

    NotifyTask task = mNotifyTaskPool.pop();
    if (task == null) {
        task = new NotifyTask();
    }
    task.setData(NotifyTask.KEY_CURRENT_INDEX, index);
    SimpleHandler.getInstance().post(task);
}
 
Example #23
Source File: GalleryActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onTapErrorText(int index) {
    NotifyTask task = mNotifyTaskPool.pop();
    if (task == null) {
        task = new NotifyTask();
    }
    task.setData(NotifyTask.KEY_TAP_ERROR_TEXT, index);
    SimpleHandler.getInstance().post(task);
}
 
Example #24
Source File: DownloadManager.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onPageDownload(int index, long contentLength, long receivedSize, int bytesRead) {
    NotifyTask task = mNotifyTaskPool.pop();
    if (task == null) {
        task = new NotifyTask();
    }
    task.setOnPageDownloadData(index, contentLength, receivedSize, bytesRead);
    SimpleHandler.getInstance().post(task);
}
 
Example #25
Source File: DownloadManager.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onGet509(int index) {
    NotifyTask task = mNotifyTaskPool.pop();
    if (task == null) {
        task = new NotifyTask();
    }
    task.setOnGet509Data(index);
    SimpleHandler.getInstance().post(task);
}
 
Example #26
Source File: DownloadManager.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onGetPages(int pages) {
    NotifyTask task = mNotifyTaskPool.pop();
    if (task == null) {
        task = new NotifyTask();
    }
    task.setOnGetPagesData(pages);
    SimpleHandler.getInstance().post(task);
}
 
Example #27
Source File: DoodleActivity.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
private void hideSide() {
    if (mHideSideRunnable != null) {
        SimpleHandler.getInstance().removeCallbacks(mHideSideRunnable);
        mHideSideRunnable = null;
    }

    if (mShowSide) {
        mShowSide = false;
        mSideAnimator.cancel();

        mSideAnimator.setInterpolator(AnimationUtils2.SLOW_FAST_INTERPOLATOR);
        mSideAnimator.setFloatValues(mSide.getTranslationX(), -mSide.getWidth());
        mSideAnimator.start();
    }
}
 
Example #28
Source File: EhApplication.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private void debugPrint() {
    new Runnable() {
        @Override
        public void run() {
            if (DEBUG_PRINT_NATIVE_MEMORY) {
                Log.i(TAG, "Native memory: " + FileUtils.humanReadableByteCount(
                        Debug.getNativeHeapAllocatedSize(), false));
            }
            if (DEBUG_PRINT_IMAGE_COUNT) {
                Log.i(TAG, "Image count: " + Image.getImageCount());
            }
            SimpleHandler.getInstance().postDelayed(this, DEBUG_PRINT_INTERVAL);
        }
    }.run();
}
 
Example #29
Source File: EhGalleryProvider.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void stop() {
    super.stop();

    if (mSpiderQueen != null) {
        mSpiderQueen.removeOnSpiderListener(this);
        // Activity recreate may called, so wait 3000s
        SimpleHandler.getInstance().postDelayed(new ReleaseTask(mSpiderQueen), 3000);
        mSpiderQueen = null;
    }
}
 
Example #30
Source File: DoodleActivity.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
private void showSide() {
    if (mHideSideRunnable != null) {
        SimpleHandler.getInstance().removeCallbacks(mHideSideRunnable);
        mHideSideRunnable = null;
    }

    if (!mShowSide) {
        mShowSide = true;
        mSideAnimator.cancel();

        mSideAnimator.setInterpolator(AnimationUtils2.FAST_SLOW_INTERPOLATOR);
        mSideAnimator.setFloatValues(mSide.getTranslationX(), 0);
        mSideAnimator.start();
    }
}