Example usage for android.os Handler post

List of usage examples for android.os Handler post

Introduction

In this page you can find the example usage for android.os Handler post.

Prototype

public final boolean post(Runnable r) 

Source Link

Document

Causes the Runnable r to be added to the message queue.

Usage

From source file:br.com.moviecreator.views.home.HomeFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getActivity().setTitle(getString(R.string.title_home));

    FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override//from   w  ww .  j  av  a2 s . c o m
        public void onClick(View view) {
            Handler handler = new Handler();
            handler.post(new Runnable() {
                @Override
                public void run() {
                    navigationListner.updateCurrentFragment(new CreateMovieFragment());
                }
            });
        }
    });
}

From source file:com.miz.service.IdentifyTvShowEpisodeService.java

@Override
protected void onHandleIntent(Intent intent) {

    if (MizLib.isTvShowLibraryBeingUpdated(this)) {
        Handler mHandler = new Handler(Looper.getMainLooper());
        mHandler.post(new Runnable() {
            @Override/*  w  w w  . j  av a  2  s . c o  m*/
            public void run() {
                Toast.makeText(IdentifyTvShowEpisodeService.this, R.string.cant_identify_while_updating,
                        Toast.LENGTH_LONG).show();
            }
        });

        return;
    }

    log("clear()");
    clear();

    log("setup()");
    setup();

    log("Intent extras");
    Bundle b = intent.getExtras();
    mNewShowId = b.getString("newShowId");
    mOldShowId = b.getString("oldShowId");
    mLanguage = b.getString("language", "all");
    mFilepaths = b.getStringArrayList("filepaths");

    if (mFilepaths != null) {
        log("setupList()");
        setupList();

        log("removeOldDatabaseEntries()");
        removeOldDatabaseEntries();

        log("start()");
        start();
    }
}

From source file:com.actinarium.rhythm.control.RhythmNotificationService.java

private void handleNextOverlay() {
    Application application = getApplication();
    if (application instanceof RhythmControl.Host) {
        final RhythmControl rhythmControl = ((RhythmControl.Host) application).getRhythmControl();
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new NextOverlayRunnable(rhythmControl.getCurrentNotificationGroup()));
    }/*from  w w w  .  j  a  v  a2 s  .  c om*/
}

From source file:com.actinarium.rhythm.control.RhythmNotificationService.java

private void handleDismissQuickConfig() {
    Application application = getApplication();
    if (application instanceof RhythmControl.Host) {
        final RhythmControl rhythmControl = ((RhythmControl.Host) application).getRhythmControl();
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new HideAllOverlaysRunnable(rhythmControl));
    }// www  .  j av a2 s. co  m
}

From source file:github.daneren2005.dsub.util.Util.java

public static void hidePlayingNotification(final Context context, final DownloadServiceImpl downloadService,
        Handler handler) {
    // Remove notification and remove the service from the foreground
    handler.post(new Runnable() {
        @Override//from ww  w.  java  2  s . c om
        public void run() {
            downloadService.stopForeground(true);
        }
    });

    // Update widget
    DSubWidgetProvider.notifyInstances(context, downloadService, false);
}

From source file:com.google.android.gcm.demo.ui.InstanceIdFragment.java

@Override
public void refresh() {
    new AsyncTask<Void, Void, Void>() {
        @Override//from  w w  w  . j  a va  2s  .co m
        protected Void doInBackground(Void... params) {
            final String instanceId = mInstanceIdHelper.getInstanceId();
            final String creationTime = DateFormat.getDateTimeInstance()
                    .format(new Date(mInstanceIdHelper.getCreationTime()));
            final Activity activity = getActivity();
            if (activity != null) {
                Handler handler = new Handler(activity.getMainLooper());
                handler.post(new Runnable() {
                    public void run() {
                        setValue(activity.findViewById(R.id.iid_instance_id), instanceId);
                        setValue(activity.findViewById(R.id.iid_creation_time), creationTime);
                    }
                });
            }
            return null;
        }
    }.execute();
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        if (sender.appTokens.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Token token : sender.appTokens.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.smartphone_grey600);
                label.setText(token.scope + " - " + AbstractFragment.truncateToMediumString(token.token));
                button.setText(R.string.iid_delete_token);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_scope, token.scope);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.iid_no_tokens));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout tokensView = (FrameLayout) getActivity().findViewById(R.id.iid_tokens_wrapper);
    tokensView.removeAllViews();
    tokensView.addView(sendersList);
}

From source file:com.microsoft.rightsmanagement.sampleapp.TextEditorFragment.java

/**
 * Sets the text view text./*from www  .j  av  a  2  s.co m*/
 * 
 * @param decryptedContent the new text view text
 */
public void setTextViewText(final String decryptedContent) {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            mTextEditor.setText(decryptedContent);
        }
    });
}

From source file:at.andreasrohner.spartantimelapserec.BackgroundService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null && intent.getBooleanExtra("powerSavingCallback", false) && recorder != null
            && wakeLock != null && settings != null && settings.shouldUsePowerSaveMode()
            && handlerThread != null && handlerThread.isAlive()) {
        wakeLock.acquire();//ww w.j  av a 2s.co m
        Handler handler = new Handler(handlerThread.getLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                recorder.start();
            }
        });
    }
    return super.onStartCommand(intent, flags, startId);
}

From source file:com.ayuget.redface.ui.misc.ImageMenuHandler.java

private void notifyImageWasSaved(final ImageSavedCallback imageSavedCallback, final File mediaFile,
        final Bitmap.CompressFormat targetFormat) {
    if (imageSavedCallback != null) {
        // We need to make sure to call the callback on the
        // main thread.
        Handler mainHandler = new Handler(activity.getMainLooper());
        mainHandler.post(new Runnable() {
            @Override/*from   www  .  j a  va 2s .c om*/
            public void run() {
                imageSavedCallback.onImageSaved(mediaFile, targetFormat);
            }
        });
    }
}

From source file:com.miz.service.IdentifyTvShowService.java

@Override
protected void onHandleIntent(Intent intent) {

    if (MizLib.isTvShowLibraryBeingUpdated(this)) {
        Handler mHandler = new Handler(Looper.getMainLooper());
        mHandler.post(new Runnable() {
            @Override/*  ww  w .j  a v  a2  s .co m*/
            public void run() {
                Toast.makeText(IdentifyTvShowService.this, R.string.cant_identify_while_updating,
                        Toast.LENGTH_LONG).show();
            }
        });

        return;
    }

    log("clear()");
    clear();

    log("setup()");
    setup();

    log("Intent extras");
    Bundle b = intent.getExtras();
    mNewShowId = b.getString("newShowId");
    mOldShowId = b.getString("oldShowId");
    mLanguage = b.getString("language", "all");

    log("setupList()");
    setupList();

    log("removeOldDatabaseEntries()");
    removeOldDatabaseEntries();

    log("start()");
    start();
}