android.os.Handler类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(266)

本文整理了Java中android.os.Handler类的一些代码示例,展示了Handler类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Handler类的具体详情如下:
包路径:android.os.Handler
类名称:Handler

Handler介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

// initialize the progress dialog like in the first example

// this is how you fire the downloader
mProgressDialog.show();
Intent intent = new Intent(this, DownloadService.class);
intent.putExtra("url", "url of the file to download");
intent.putExtra("receiver", new DownloadReceiver(new Handler()));
startService(intent);

代码示例来源:origin: chrisbanes/PhotoView

private void rotateLoop() {
    handler.postDelayed(new Runnable() {
      @Override
      public void run() {
        photo.setRotationBy(1);
        rotateLoop();
      }
    }, 15);
  }
}

代码示例来源:origin: libgdx/libgdx

@Override
public void runOnUiThread (Runnable runnable) {
  if (Looper.myLooper() != Looper.getMainLooper()) {
    // The current thread is not the UI thread.
    // Let's post the runnable to the event queue of the UI thread.
    new Handler(Looper.getMainLooper()).post(runnable);
  } else {
    // The current thread is the UI thread already.
    // Let's execute the runnable immediately.
    runnable.run();
  }
}

代码示例来源:origin: square/picasso

void dispatchAirplaneModeChange(boolean airplaneMode) {
 handler.sendMessage(handler.obtainMessage(AIRPLANE_MODE_CHANGE,
   airplaneMode ? AIRPLANE_MODE_ON : AIRPLANE_MODE_OFF, 0));
}

代码示例来源:origin: square/picasso

/**
 * Prior to Android 5, HandlerThread always keeps a stack local reference to the last message
 * that was sent to it. This method makes sure that stack local reference never stays there
 * for too long by sending new messages to it every second.
 */
static void flushStackLocalLeaks(Looper looper) {
 Handler handler = new Handler(looper) {
  @Override public void handleMessage(Message msg) {
   sendMessageDelayed(obtainMessage(), THREAD_LEAK_CLEANING_MS);
  }
 };
 handler.sendMessageDelayed(handler.obtainMessage(), THREAD_LEAK_CLEANING_MS);
}

代码示例来源:origin: google/ExoPlayer

@Override
public void setProgressUpdatingEnabled(boolean enabled) {
 handler.removeCallbacks(this);
 if (enabled) {
  handler.post(this);
 }
}

代码示例来源:origin: naman14/Timber

@Override
public void onCreate(Bundle savedInstanceState) {
  action = getIntent().getAction();
  View header = navigationView.inflateHeaderView(R.layout.nav_header);
  albumart = (ImageView) header.findViewById(R.id.album_art);
  songtitle = (TextView) header.findViewById(R.id.song_title);
  songartist = (TextView) header.findViewById(R.id.song_artist);
  navDrawerRunnable.postDelayed(new Runnable() {
    @Override
    public void run() {
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
      @Override
      public void run() {
    contentRoot.addView(LayoutInflater.from(this)
        .inflate(R.layout.fragment_cast_mini_controller, null), params);
    findViewById(R.id.castMiniController).setOnClickListener(new View.OnClickListener() {

代码示例来源:origin: Yalantis/Side-Menu.Android

double size = list.size();
for (int i = 0; i < size; i++) {
  View viewMenu = appCompatActivity.getLayoutInflater().inflate(R.layout.menu_list_item, null);
  viewMenu.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
  ((ImageView) viewMenu.findViewById(R.id.menu_item_image)).setImageResource(list.get(i).getImageRes());
  viewMenu.setVisibility(View.GONE);
  viewMenu.setEnabled(false);
  viewList.add(viewMenu);
  final double position = i;
  final double delay = 3 * ANIMATION_DURATION * (position / size);
  new Handler().postDelayed(new Runnable() {
    public void run() {
      if (position < viewList.size()) {

代码示例来源:origin: scwang90/SmartRefreshLayout

if (!thisView.isInEditMode()) {
    mHandler = new Handler();
      mHandler.postDelayed(runnable, runnable.delayMillis);
      setRefreshHeader(sHeaderCreator.createRefreshHeader(thisView.getContext(), this));
    } else {
      setRefreshHeader(new BezierRadarHeader(thisView.getContext()));
    final TextView errorView = new TextView(thisView.getContext());
    errorView.setTextColor(0xffff6600);
    errorView.setGravity(Gravity.CENTER);
    errorView.setTextSize(20);
    errorView.setText(R.string.srl_content_empty);

代码示例来源:origin: iammert/MaterialIntroView

handler = new Handler();
eraser.setFlags(Paint.ANTI_ALIAS_FLAG);
View layoutInfo = LayoutInflater.from(getContext()).inflate(R.layout.material_intro_card, null);
infoView = layoutInfo.findViewById(R.id.info_layout);
textViewInfo = (TextView) layoutInfo.findViewById(R.id.textview_info);
textViewInfo.setTextColor(colorTextViewInfo);
imageViewIcon = (ImageView) layoutInfo.findViewById(R.id.imageview_icon);
dotView = LayoutInflater.from(getContext()).inflate(R.layout.dotview, null);
dotView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);

代码示例来源:origin: hidroh/materialistic

@Override
protected void bind(SubmissionViewHolder holder, final Item item) {
  super.bind(holder, item);
  holder.mPostedTextView.setText(item.getDisplayedTime(mContext));
  holder.mPostedTextView.append(item.getDisplayedAuthor(mContext,
      !TextUtils.equals(item.getBy(), mUsername), 0));
  holder.mMoreButton.setVisibility(View.GONE);
  if (TextUtils.equals(item.getType(), Item.COMMENT_TYPE)) {
    holder.mTitleTextView.setText(null);
    holder.itemView.setOnClickListener(null);
    holder.mCommentButton.setVisibility(View.GONE);
  } else {
    holder.mTitleTextView.setText(item.getDisplayedTitle());
    holder.mCommentButton.setVisibility(View.VISIBLE);
    holder.mCommentButton.setOnClickListener(v -> openItem(item));
  }
  holder.mTitleTextView.setVisibility(holder.mTitleTextView.length() > 0 ?
      View.VISIBLE : View.GONE);
  holder.mContentTextView.setVisibility(holder.mContentTextView.length() > 0 ?
      View.VISIBLE : View.GONE);
  if (!mExpanded.contains(item.getId()) && item.getParentItem() != null) {
    mExpanded.add(item.getId());
    new Handler().post(() -> {
      mItems.add(0, item.getParentItem()); // recursive
      notifyItemInserted(0);
      notifyItemRangeChanged(1, mItems.size());
    });
  }
}

代码示例来源:origin: mikepenz/MaterialDrawer

contentView = LayoutInflater.from(mActivity).inflate(R.layout.material_drawer_recycler_view, mSliderLayout, false);
mRecyclerView = (RecyclerView) contentView.findViewById(R.id.material_drawer_recycler_view);
innerShadow.setVisibility(View.VISIBLE);
innerShadow.bringToFront();
if (mDrawerGravity == GravityCompat.START) {
  innerShadow.setBackgroundResource(R.drawable.material_drawer_shadow_left);
      new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {

代码示例来源:origin: aa112901/remusic

@Override
protected void onCreate(Bundle savedInstanceState) {
  LayoutInflater inflater = LayoutInflater.from(getContext());
  if (mProgressStyle == STYLE_HORIZONTAL) {
    mViewUpdateHandler = new Handler(this);
    View view = inflater.inflate(R.layout.dialog_alert_progress, null);
    mProgress = (ProgressBar) view.findViewById(android.R.id.progress);
    mProgressNumber = (TextView) view.findViewById(R.id.progress_number);
    mProgressPercent = (TextView) view.findViewById(R.id.progress_percent);
    setView(view);
  } else {
    View view = inflater.inflate(R.layout.dialog_progress, null);
    mProgress = (ProgressBar) view.findViewById(android.R.id.progress);
    mMessageView = (TextView) view.findViewById(R.id.message);

代码示例来源:origin: iammert/MaterialIntroView

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  View view = inflater.inflate(R.layout.fragment_recyclerview, container, false);
  recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
  initializeRecyclerview();
  loadData();
  new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
      showMaterialIntro();
    }
  }, 2000);
  return view;
}

代码示例来源:origin: rey5137/material

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  View v = inflater.inflate(R.layout.fragment_progress, container, false);
  
  pv_circular = (ProgressView)v.findViewById(R.id.progress_pv_circular);
  pv_circular_colors = (ProgressView)v.findViewById(R.id.progress_pv_circular_colors);
  pv_circular_inout = (ProgressView)v.findViewById(R.id.progress_pv_circular_inout);
  pv_circular_inout_colors = (ProgressView)v.findViewById(R.id.progress_pv_circular_inout_colors);
  pv_circular_determinate_in_out = (ProgressView)v.findViewById(R.id.progress_pv_circular_determinate_in_out);
  pv_circular_determinate = (ProgressView)v.findViewById(R.id.progress_pv_circular_determinate);
  pv_linear = (ProgressView)v.findViewById(R.id.progress_pv_linear);
  pv_linear_colors = (ProgressView)v.findViewById(R.id.progress_pv_linear_colors);
  pv_linear_determinate = (ProgressView)v.findViewById(R.id.progress_pv_linear_determinate);
  pv_linear_query = (ProgressView)v.findViewById(R.id.progress_pv_linear_query);
  pv_linear_buffer = (ProgressView)v.findViewById(R.id.progress_pv_linear_buffer);
  
  mHandler = new Handler(this);
                  
  return v;
}

代码示例来源:origin: ribot/ribot-app-android

super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= 21) {
  getWindow().getDecorView().setSystemUiVisibility(
      View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
  getWindow().setStatusBarColor(getResources().getColor(R.color.black_20p));
Profile profile = intent.getParcelableExtra(EXTRA_PROFILE);
mTimeDisplaying = intent.getLongExtra(EXTRA_TIME_DISPLAYING, -1);
mGreetingText.setText(getString(R.string.welcome_greetings, profile.name.first));
loadProfileImage(profile.avatar);
if (hexColor != null) mProfileInfoLayout.setBackgroundColor(Color.parseColor(hexColor));
mHandler = new Handler();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  mProfileInfoLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
    @Override
    public void onLayoutChange(View v, int left, int top, int right, int bottom,

代码示例来源:origin: Rukey7/MvpApp

/**
 * 显示跳转提示
 */
private void _showSkipTip() {
  if (mSkipPosition != INVALID_VALUE && mLlSkipLayout.getVisibility() == GONE) {
    mLlSkipLayout.setVisibility(VISIBLE);
    mTvSkipTime.setText(generateTime(mSkipPosition));
    AnimHelper.doSlideRightIn(mLlSkipLayout, mWidthPixels, 0, 800);
    mHandler.postDelayed(mHideSkipTipRunnable, DEFAULT_HIDE_TIMEOUT * 3);
  }
}

代码示例来源:origin: aa112901/remusic

@Override
protected void onDestroy() {
  Intent intent = new Intent();
  intent.setAction(MediaService.LOCK_SCREEN);
  intent.putExtra("islock",false);
  sendBroadcast(intent);
  mHandler.removeCallbacks(updateRunnable);
  super.onDestroy();
  Log.e("lock"," on destroy");
}

代码示例来源:origin: stackoverflow.com

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class Splash extends Activity {

  /** Duration of wait **/
  private final int SPLASH_DISPLAY_LENGTH = 1000;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.splashscreen);

    /* New Handler to start the Menu-Activity 
     * and close this Splash-Screen after some seconds.*/
    new Handler().postDelayed(new Runnable(){
      @Override
      public void run() {
        /* Create an Intent that will start the Menu-Activity. */
        Intent mainIntent = new Intent(Splash.this,Menu.class);
        Splash.this.startActivity(mainIntent);
        Splash.this.finish();
      }
    }, SPLASH_DISPLAY_LENGTH);
  }
}

代码示例来源:origin: iSoron/uhabits

public void restartWithFade(Class<?> cls)
{
  new Handler().postDelayed(() ->
  {
    finish();
    overridePendingTransition(fade_in, fade_out);
    startActivity(new Intent(this, cls));
  }, 500); // HACK: Let the menu disappear first
}

相关文章