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:github.madmarty.madsonic.util.Util.java

public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService,
        Handler handler, MusicDirectory.Entry song) {

    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(R.drawable.stat_notify, song.getTitle(),
            System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    boolean playing = downloadService.getPlayerState() == PlayerState.STARTED;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        RemoteViews expandedContentView = new RemoteViews(context.getPackageName(),
                R.layout.notification_expanded);
        setupViews(expandedContentView, context, song, playing);
        notification.bigContentView = expandedContentView;
    }/*from w  w w.j  a  v a  2  s.  c om*/

    RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
    setupViews(smallContentView, context, song, playing);
    notification.contentView = smallContentView;

    Intent notificationIntent = new Intent(context, DownloadActivity.class);
    notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    handler.post(new Runnable() {
        @Override
        public void run() {
            downloadService.startForeground(Constants.NOTIFICATION_ID_PLAYING, notification);
        }
    });

    // Update widget
    MadsonicWidgetProvider.notifyInstances(context, downloadService, true);
}

From source file:org.mobicents.restcomm.android.client.sdk.RCConnection.java

@Override
public void onPeerConnectionStatsReady(final StatsReport[] reports) {
    Handler mainHandler = new Handler(RCClient.getContext().getMainLooper());
    Runnable myRunnable = new Runnable() {
        @Override/*from w  ww . j a  va  2 s  .  com*/
        public void run() {
            if (iceConnected) {
                //hudFragment.updateEncoderStatistics(reports);
            }
        }
    };
    mainHandler.post(myRunnable);
}

From source file:org.mobicents.restcomm.android.client.sdk.RCConnection.java

@Override
public void onIceCandidate(final IceCandidate candidate) {
    final RCConnection connection = this;
    Handler mainHandler = new Handler(RCClient.getContext().getMainLooper());
    Runnable myRunnable = new Runnable() {
        @Override/*from   ww  w.ja va  2  s  . c o m*/
        public void run() {
            RCLogger.i(TAG, "onIceCandidate:");
            connection.signalingParameters.addIceCandidate(candidate);
        }
    };
    mainHandler.post(myRunnable);
}

From source file:com.archer.matching_card_game.three_cards.util.IabHelper.java

/**
 * Asynchronous wrapper for inventory query. This will perform an inventory
 * query as described in {@link #queryInventory}, but will do so asynchronously
 * and call back the specified listener upon completion. This method is safe to
 * call from a UI thread.//from w  w w. j ava2s  . c  om
 *
 * @param querySkuDetails as in {@link #queryInventory}
 * @param moreSkus as in {@link #queryInventory}
 * @param listener The listener to notify when the refresh operation completes.
 */
public void queryInventoryAsync(final boolean querySkuDetails, final List<String> moreSkus,
        final QueryInventoryFinishedListener listener) {
    try {
        final Handler handler = new Handler();
        flagEndAsync();
        checkNotDisposed();
        checkSetupDone("queryInventory");
        flagStartAsync("refresh inventory");
        mThread = (new Thread(new Runnable() {
            public void run() {

                IabResult result = new IabResult(BILLING_RESPONSE_RESULT_OK, "Inventory refresh successful.");
                Inventory inv = null;
                try {
                    inv = queryInventory(querySkuDetails, moreSkus);
                } catch (IabException ex) {
                    result = ex.getResult();
                }
                final IabResult result_f = result;
                final Inventory inv_f = inv;
                if (!mDisposed && listener != null) {
                    handler.post(new Runnable() {
                        public void run() {
                            listener.onQueryInventoryFinished(result_f, inv_f);
                        }
                    });
                }
            }
        }));
        mThread.start();
    } catch (Exception ex) {
        /* do nothing */
    }
}

From source file:com.hellotracks.billing.util.IabHelper.java

/**
 * Asynchronous wrapper for inventory query. This will perform an inventory query as described in
 * {@link #queryInventory}, but will do so asynchronously and call back the specified listener upon completion. This
 * method is safe to call from a UI thread.
 * //from w w  w  . ja  va2s .c o  m
 * @param querySkuDetails
 *            as in {@link #queryInventory}
 * @param moreSkus
 *            as in {@link #queryInventory}
 * @param listener
 *            The listener to notify when the refresh operation completes.
 */
public void queryInventoryAsync(final boolean querySkuDetails, final List<String> moreSkus,
        final QueryInventoryFinishedListener listener) {
    final Handler handler = new Handler();
    checkNotDisposed();
    checkSetupDone("queryInventory");
    flagStartAsync("refresh inventory");
    (new Thread(new Runnable() {
        public void run() {
            try {
                IabResult result = new IabResult(BILLING_RESPONSE_RESULT_OK, "Inventory refresh successful.");
                Inventory inv = null;
                try {
                    inv = queryInventory(querySkuDetails, moreSkus);
                } catch (IabException ex) {
                    result = ex.getResult();
                }

                flagEndAsync();

                final IabResult result_f = result;
                final Inventory inv_f = inv;
                if (!mDisposed && listener != null) {
                    handler.post(new Runnable() {
                        public void run() {
                            listener.onQueryInventoryFinished(result_f, inv_f);
                        }
                    });
                }
            } catch (Exception exc) {
                com.hellotracks.Logger.e("iab", exc);
            }
        }
    })).start();
}

From source file:com.archer.circle_run.util.IabHelper.java

/**
 * Asynchronous wrapper for inventory query. This will perform an inventory
 * query as described in {@link #queryInventory}, but will do so asynchronously
 * and call back the specified listener upon completion. This method is safe to
 * call from a UI thread./*from w w  w .j  a  va 2  s  . c  o  m*/
 *
 * @param querySkuDetails as in {@link #queryInventory}
 * @param moreSkus as in {@link #queryInventory}
 * @param listener The listener to notify when the refresh operation completes.
 */
public void queryInventoryAsync(final boolean querySkuDetails, final List<String> moreSkus,
        final QueryInventoryFinishedListener listener) {
    try {
        final Handler handler = new Handler();
        flagEndAsync();
        checkNotDisposed();
        checkSetupDone("queryInventory");
        flagStartAsync("refresh inventory");

        mThread = (new Thread(new Runnable() {
            public void run() {

                IabResult result = new IabResult(BILLING_RESPONSE_RESULT_OK, "Inventory refresh successful.");
                Inventory inv = null;
                try {

                    inv = queryInventory(querySkuDetails, moreSkus);
                } catch (IabException ex) {
                    result = ex.getResult();
                }
                final IabResult result_f = result;
                final Inventory inv_f = inv;
                if (!mDisposed && listener != null) {
                    handler.post(new Runnable() {
                        public void run() {
                            listener.onQueryInventoryFinished(result_f, inv_f);
                        }
                    });
                }
            }
        }));
        mThread.start();
    } catch (Exception ex) {
        /* do nothing */
    }
}

From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    view = inflater.inflate(R.layout.fragment_account, container, false);
    findViews();/* w  w w.  ja va2 s  .  c om*/
    app = (OpacClient) getActivity().getApplication();
    account = app.getAccount();

    swipeRefreshLayout.setColorSchemeResources(R.color.primary_red);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refresh();
        }
    });

    setHasOptionsMenu(true);

    accountSelected(app.getAccount());

    final Handler handler = new Handler();
    // schedule alarm here and post runnable as soon as scheduled
    handler.post(new Runnable() {
        @Override
        public void run() {
            refreshage();
            handler.postDelayed(this, 60000);
        }
    });

    return view;
}

From source file:com.android.trivialdrivesample.util.IabHelper.java

void consumeAsyncInternal(final List<Purchase> purchases, final OnConsumeFinishedListener singleListener,
        final OnConsumeMultiFinishedListener multiListener) throws IabAsyncInProgressException {
    final Handler handler = new Handler();
    flagStartAsync("consume");
    (new Thread(new Runnable() {
        public void run() {
            final List<IabResult> results = new ArrayList<IabResult>();
            for (Purchase purchase : purchases) {
                try {
                    consume(purchase);//from  w  ww .  j a  v  a 2s.  co  m
                    results.add(new IabResult(BILLING_RESPONSE_RESULT_OK,
                            "Successful consume of sku " + purchase.getSku()));
                } catch (IabException ex) {
                    results.add(ex.getResult());
                }
            }

            flagEndAsync();
            if (!mDisposed && singleListener != null) {
                handler.post(new Runnable() {
                    public void run() {
                        singleListener.onConsumeFinished(purchases.get(0), results.get(0));
                    }
                });
            }
            if (!mDisposed && multiListener != null) {
                handler.post(new Runnable() {
                    public void run() {
                        multiListener.onConsumeMultiFinished(purchases, results);
                    }
                });
            }
        }
    })).start();
}

From source file:com.sentaroh.android.Utilities.Dialog.FileSelectDialogFragment.java

private void initViewWidget() {
    if (mDebugEnable)
        Log.v(APPLICATION_TAG, "initViewWidget");

    if (mDebugEnable)
        Log.v(APPLICATION_TAG, "Create=" + mDialogEnableCreate + ", Title=" + mDialogTitle + ", lurl="
                + mDialogLocalUrl + ", ldir=" + mDialogLocalDir + ", file name=" + mDialogFileName);

    mThemeColorList = ThemeUtil.getThemeColorList(getActivity());

    mDialog.setContentView(R.layout.file_select_edit_dlg);
    LinearLayout title_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_title_view);
    title_view.setBackgroundColor(mThemeColorList.dialog_title_background_color);
    TextView title = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_title);
    title.setTextColor(mThemeColorList.text_color_dialog_title);
    title.setText(mDialogTitle);/*from w ww  .  j ava  2s .  co m*/
    final TextView dlg_msg = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_msg);
    final Button btnHome = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_home_dir_btn);
    btnHome.setTextColor(mThemeColorList.text_color_primary);
    btnHome.setVisibility(Button.VISIBLE);
    final Button btnCreate = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_create_btn);
    btnCreate.setTextColor(mThemeColorList.text_color_primary);
    final Button btnOk = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_ok_btn);
    //      btnOk.setTextColor(mThemeColorList.text_color_primary);
    final Button btnCancel = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_cancel_btn);
    btnCancel.setTextColor(mThemeColorList.text_color_primary);
    final Button btnRefresh = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_refresh_btn);
    btnRefresh.setTextColor(mThemeColorList.text_color_primary);

    LinearLayout ll_dlg_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view);
    ll_dlg_view.setBackgroundColor(mThemeColorList.dialog_msg_background_color);

    final Activity activity = getActivity();
    final Context context = activity.getApplicationContext();

    if (mDialogEnableCreate) {
        btnCreate.setVisibility(TextView.VISIBLE);
    }

    mLocalMountPointSpinner = (Spinner) mDialog.findViewById(R.id.file_select_edit_dlg_rdir);
    setSpinnerBackground(context, mLocalMountPointSpinner, mThemeColorList.theme_is_light);
    mLocalMountPointSpinner.setVisibility(Spinner.VISIBLE);
    //   Root directory spinner
    CustomSpinnerAdapter adapter = new CustomSpinnerAdapter(activity, R.layout.custom_simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mLocalMountPointSpinner.setPrompt(context.getString(R.string.msgs_file_select_edit_local_mount_point));
    mLocalMountPointSpinner.setAdapter(adapter);

    int a_no = -1;
    ArrayList<String> ml = LocalMountPoint.getLocalMountPointList(context);
    mLocalMountPointSpinner.setOnItemSelectedListener(null);
    if (mDialogMpLimitInternalAndSdcard) {
        adapter.add(Environment.getExternalStorageDirectory().toString());
        File[] fl = ContextCompat.getExternalFilesDirs(context, null);
        for (File item : fl) {
            if (!item.getPath().startsWith(Environment.getExternalStorageDirectory().toString())) {
                adapter.add(item.getPath().substring(0, item.getPath().indexOf("/Android")));
                break;
            }
        }
        mLocalMountPointSpinner.setEnabled(true);
        for (int i = 0; i < adapter.getCount(); i++) {
            if (adapter.getItem(i).equals(mDialogLocalUrl)) {
                a_no = i;
                break;
            }
        }
        mLocalMountPointSpinner.setSelection(a_no);
    } else {
        if (ml.size() == 0) {
            if (mDialogIncludeRoot)
                adapter.add("/");
            adapter.add(mDialogLocalUrl);
            mLocalMountPointSpinner.setEnabled(false);
        } else {
            mLocalMountPointSpinner.setEnabled(true);
            if (mDialogIncludeRoot)
                adapter.add("/");
            for (int i = 0; i < ml.size(); i++)
                adapter.add(ml.get(i));
            for (int i = 0; i < ml.size(); i++) {
                if (mDialogLocalUrl.startsWith(ml.get(i))) {
                    a_no = i;
                    break;
                }
            }
            mLocalMountPointSpinner.setSelection(a_no);
        }
    }
    LinearLayout ll_mp = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_mp_view);
    if (mDialogHideMp)
        ll_mp.setVisibility(LinearLayout.GONE);
    else
        ll_mp.setVisibility(LinearLayout.VISIBLE);
    //      ll_mp.setVisibility(LinearLayout.GONE);

    //   final TextView v_spacer=(TextView)mDialog.findViewById(R.id.file_select_edit_dlg_spacer);
    mTreeFileListView = (ListView) mDialog.findViewById(android.R.id.list);
    final CustomTextView dir_name = (CustomTextView) mDialog.findViewById(R.id.file_select_edit_dlg_dir_name);
    dir_name.setTextColor(mThemeColorList.text_color_primary);
    final EditText file_name = (EditText) mDialog.findViewById(R.id.file_select_edit_dlg_file_name);
    if (!mDialogSingleSelect)
        file_name.setVisibility(EditText.GONE);
    else
        file_name.setVisibility(EditText.VISIBLE);
    if (mDialogFileOnly) {
        file_name.setVisibility(EditText.VISIBLE);
        file_name.setEnabled(true);
        dir_name.setVisibility(EditText.VISIBLE);
    } else {
        if (mDialogDirectoryOnly) {
            file_name.setVisibility(EditText.GONE);
            file_name.setEnabled(false);
            dir_name.setVisibility(EditText.VISIBLE);
            btnHome.setVisibility(EditText.VISIBLE);
        } else {
            file_name.setVisibility(EditText.VISIBLE);
            file_name.setEnabled(true);
            dir_name.setVisibility(EditText.VISIBLE);
            btnHome.setVisibility(EditText.VISIBLE);
        }
    }
    file_name.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View arg0, int keyCode, KeyEvent event) {
            if (//event.getAction() == KeyEvent.ACTION_DOWN &&
            keyCode == KeyEvent.KEYCODE_ENTER) {
                return true;
            }
            return false;
        }
    });
    //    if (dirs.size()<=2)   v_spacer.setVisibility(TextView.VISIBLE);

    mTreeFilelistAdapter = new TreeFilelistAdapter(activity, mDialogSingleSelect, true);
    mTreeFileListView.setAdapter(mTreeFilelistAdapter);

    if (mDialogLocalUrl.equals(""))
        mDialogLocalUrl = ml.get(0);
    ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mDialogLocalUrl, "");
    if (tfl.size() == 0) {
        tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty)));
    } else {
        mTreeFilelistAdapter.setDataList(tfl);
        if (!mDialogLocalDir.equals("")) {
            String sel_dir = mDialogLocalDir;
            String n_dir = "", e_dir = "";
            if (sel_dir.startsWith("/"))
                n_dir = sel_dir.substring(1);
            else
                n_dir = sel_dir;
            if (n_dir.endsWith("/"))
                e_dir = n_dir.substring(0, n_dir.length() - 1);
            else
                e_dir = n_dir;
            //              Log.v("","mp="+mDialogLocalUrl+", se;_dir="+sel_dir+", e_dir="+e_dir);
            selectLocalDirTree(e_dir);
        }
        if (!mDialogFileName.equals(""))
            selectLocalDirTreeFile(mDialogFileName);
    }
    mTreeFileListView.setScrollingCacheEnabled(false);
    mTreeFileListView.setScrollbarFadingEnabled(false);

    if (mSavedViewContentsValue != null && mSavedViewContentsValue.mainDialogFilename != null) {
        file_name.setText(mSavedViewContentsValue.mainDialogFilename);
        file_name.setSelection(mSavedViewContentsValue.mainDialogFilenameSelStart,
                mSavedViewContentsValue.mainDialogFilenameTextSelEnd);
        dir_name.setText(mSavedViewContentsValue.mainDialogDirName);
    } else {
        String d_name = mDialogLocalDir.equals("") ? mDialogLocalUrl + "/"
                : mDialogLocalUrl + mDialogLocalDir + "/";
        dir_name.setText(d_name);
        file_name.setText(mDialogFileName);
    }

    if (!mDialogSingleSelect)
        btnOk.setEnabled(false);

    NotifyEvent cb_ntfy = new NotifyEvent(context);
    // set file list thread response listener 
    cb_ntfy.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            int p = (Integer) o[0];
            boolean p_chk = (Boolean) o[1];
            String turl = (String) mLocalMountPointSpinner.getSelectedItem();
            if (mDialogSingleSelect) {
                if (mTreeFilelistAdapter.getDataItem(p).isChecked() && !p_chk) {
                    if (p != -1) {
                        if (mTreeFilelistAdapter.getDataItem(p).isChecked()) {
                            if (mTreeFilelistAdapter.getDataItem(p).isDir()) {
                                dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath()
                                        + mTreeFilelistAdapter.getDataItem(p).getName() + "/");
                                //                           file_name.setText("");
                            } else {
                                dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath());
                                file_name.setText(mTreeFilelistAdapter.getDataItem(p).getName());
                            }
                        }
                    }
                }
                if (mDialogFileOnly) {
                    if (file_name.getText().length() > 0) {
                        btnOk.setEnabled(true);
                        putDlgMsg(dlg_msg, "");
                    } else {
                        btnOk.setEnabled(false);
                        putDlgMsg(dlg_msg,
                                context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified));
                    }
                } else {
                    if (mTreeFilelistAdapter.isDataItemIsSelected() || file_name.getText().length() > 0) {
                        btnOk.setEnabled(true);
                        putDlgMsg(dlg_msg, "");
                    } else {
                        putDlgMsg(dlg_msg,
                                context.getString(R.string.msgs_file_select_edit_dlg_directory_not_selected));
                        btnOk.setEnabled(false);
                    }
                }
            } else {
                if (mTreeFilelistAdapter.getDataItem(p).isDir()) {
                    dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath()
                            + mTreeFilelistAdapter.getDataItem(p).getName() + "/");
                    //                  file_name.setText("");
                } else {
                    dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath());
                    file_name.setText(mTreeFilelistAdapter.getDataItem(p).getName());
                }
                putDlgMsg(dlg_msg, "");
                btnOk.setEnabled(true);
            }
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            boolean checked = false;
            //         int p=(Integer) o[0];
            boolean p_chk = (Boolean) o[1];
            if (mDialogSingleSelect) {
                if (p_chk) {
                    for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) {
                        if (mTreeFilelistAdapter.getDataItem(i).isChecked()) {
                            checked = true;
                            break;
                        }
                    }
                    if (checked)
                        btnOk.setEnabled(true);
                    else
                        btnOk.setEnabled(false);
                }
            } else {
                //               Log.v("","sel="+p_chk);
                btnOk.setEnabled(false);
                for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) {
                    if (mTreeFilelistAdapter.getDataItem(i).isChecked()) {
                        btnOk.setEnabled(true);
                        break;
                    }
                }
            }
        }
    });
    mTreeFilelistAdapter.setCbCheckListener(cb_ntfy);

    if (mDialogLocalUrl.equals(file_name.getText().toString()))
        btnOk.setEnabled(false);
    if (mDialogFileOnly && mDialogFileName.equals("")) {
        btnOk.setEnabled(false);
        putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified));
    }
    file_name.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (mDialogSingleSelect) {
                if (s.length() != 0) {
                    btnOk.setEnabled(true);
                    putDlgMsg(dlg_msg, "");
                } else {
                    btnOk.setEnabled(false);
                    putDlgMsg(dlg_msg,
                            context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified));
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    NotifyEvent ntfy_expand_close = new NotifyEvent(context);
    ntfy_expand_close.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            int idx = (Integer) o[0];
            final int pos = mTreeFilelistAdapter.getItem(idx);
            final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos);
            if (tfi.getName().startsWith("---"))
                return;
            String turl = (String) mLocalMountPointSpinner.getSelectedItem();
            if (tfi.isDir())
                processLocalDirTree(mDialogFileOnly, turl, pos, tfi, mTreeFilelistAdapter);
            else {
                mTreeFilelistAdapter.setDataItemIsSelected(pos);
                dir_name.setText((turl + mTreeFilelistAdapter.getDataItem(pos).getPath()));
                file_name.setText(mTreeFilelistAdapter.getDataItem(pos).getName());
                if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly)
                    btnOk.setEnabled(false);
                else
                    btnOk.setEnabled(true);
            }
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
        }
    });
    mTreeFilelistAdapter.setExpandCloseListener(ntfy_expand_close);
    mTreeFileListView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
            final int pos = mTreeFilelistAdapter.getItem(idx);
            final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos);
            if (tfi.getName().startsWith("---"))
                return;
            String turl = (String) mLocalMountPointSpinner.getSelectedItem();
            if (tfi.isDir())
                processLocalDirTree(mDialogFileOnly, turl, pos, tfi, mTreeFilelistAdapter);
            else {
                mTreeFilelistAdapter.setDataItemIsSelected(pos);
                dir_name.setText((turl + mTreeFilelistAdapter.getDataItem(pos).getPath()));
                file_name.setText(mTreeFilelistAdapter.getDataItem(pos).getName());
                if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly)
                    btnOk.setEnabled(false);
                else
                    btnOk.setEnabled(true);
            }
        }
    });

    mTreeFileListView.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
            return true;
        }
    });

    btnHome.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dir_name.setText(mLocalMountPointSpinner.getSelectedItem().toString() + "/");
        }
    });

    //Create button
    btnCreate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NotifyEvent ntfy = new NotifyEvent(context);
            // set file list thread response listener 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context c, Object[] o) {
                    //                  btnRefresh.performClick();                  
                }

                @Override
                public void negativeResponse(Context c, Object[] o) {
                }

            });
            fileSelectEditDialogCreateBtn(activity, context,
                    dir_name.getText().substring(0, dir_name.getText().length() - 1), "",
                    mLocalMountPointSpinner.getSelectedItem().toString(), mTreeFilelistAdapter, ntfy,
                    mTreeFileListView);

        }
    });
    //Refresh button
    btnRefresh.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String mp = mLocalMountPointSpinner.getSelectedItem().toString();
            ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mp, "");//mDialogLocalUrl,"");
            if (tfl.size() < 1)
                tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty)));
            mTreeFilelistAdapter.setDataList(tfl);
        }
    });
    //OK button
    //      btnOk.setEnabled(false);
    btnOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (mDialogSingleSelect) {
                String[] sl_array = new String[] { dir_name.getText() + file_name.getText().toString() };
                if (mNotifyEvent != null)
                    mNotifyEvent.notifyToListener(true, sl_array);
            } else {
                ArrayList<String> sl = new ArrayList<String>();
                ArrayList<TreeFilelistItem> tfl = mTreeFilelistAdapter.getDataList();
                for (TreeFilelistItem li : tfl) {
                    if (li.isChecked()) {
                        if (li.isDir())
                            sl.add(li.getPath() + li.getName());
                        else
                            sl.add(li.getPath() + li.getName());
                    }
                }
                String[] sl_array = new String[sl.size()];
                String mp = mLocalMountPointSpinner.getSelectedItem().toString();
                for (int i = 0; i < sl.size(); i++) {
                    if (mDialogSelectedFilePathWithMountPoint)
                        sl_array[i] = mp + sl.get(i);
                    else
                        sl_array[i] = sl.get(i);
                    //                  Log.v("","sel="+sl_array[i]);
                }
                if (mNotifyEvent != null)
                    mNotifyEvent.notifyToListener(true, sl_array);
            }
            //            mDialog.dismiss();
            mFragment.dismiss();
        }
    });
    // CANCEL?
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //            mDialog.dismiss();
            mFragment.dismiss();
            if (mNotifyEvent != null)
                mNotifyEvent.notifyToListener(false, null);
        }
    });

    Handler hndl = new Handler();
    hndl.postDelayed(new Runnable() {
        @Override
        public void run() {
            mLocalMountPointSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    //                    Log.v("","MP selected="+position);
                    Spinner spinner = (Spinner) parent;
                    String turl = (String) spinner.getSelectedItem();
                    ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, turl, "");
                    if (tfl.size() < 1)
                        tfl.add(new TreeFilelistItem(
                                context.getString(R.string.msgs_file_select_edit_dir_empty)));
                    mTreeFilelistAdapter.setDataList(tfl);
                    mTreeFilelistAdapter.notifyDataSetChanged();
                    if (turl.startsWith(mSafFileMgr.getExternalSdcardPath())) {
                        if (mSafFileMgr.getSdcardSafFile() == null)
                            btnCreate.setEnabled(false);
                        else
                            btnCreate.setEnabled(true);
                    } else
                        btnCreate.setEnabled(true);
                    dir_name.setText(turl + "/");
                    Handler hndl_sel = new Handler();
                    hndl_sel.post(new Runnable() {
                        @Override
                        public void run() {
                            mTreeFileListView.setSelection(0);
                        }
                    });
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                }
            });
        }
    }, 100);
}

From source file:de.geithonline.abattlwp.billinghelper.IabHelper.java

void consumeAsyncInternal(final List<Purchase> purchases, final OnConsumeFinishedListener singleListener,
        final OnConsumeMultiFinishedListener multiListener) {
    final Handler handler = new Handler();
    flagStartAsync("consume");
    (new Thread(new Runnable() {
        @Override/* ww w  . j  a v a2s. com*/
        public void run() {
            final List<IabResult> results = new ArrayList<IabResult>();
            for (final Purchase purchase : purchases) {
                try {
                    consume(purchase);
                    results.add(new IabResult(BILLING_RESPONSE_RESULT_OK,
                            "Successful consume of sku " + purchase.getSku()));
                } catch (final IabException ex) {
                    results.add(ex.getResult());
                }
            }

            flagEndAsync();
            if (!mDisposed && singleListener != null) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        singleListener.onConsumeFinished(purchases.get(0), results.get(0));
                    }
                });
            }
            if (!mDisposed && multiListener != null) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        multiListener.onConsumeMultiFinished(purchases, results);
                    }
                });
            }
        }
    })).start();
}