Example usage for android.widget TextView post

List of usage examples for android.widget TextView post

Introduction

In this page you can find the example usage for android.widget TextView post.

Prototype

public boolean post(Runnable action) 

Source Link

Document

Causes the Runnable to be added to the message queue.

Usage

From source file:eu.fistar.sdcs.pa.MainActivity.java

private void updateLog(String log) {
    Log.d(LOGTAG, log);//w w  w . java2s.co  m

    final String fLog = log;

    final TextView tv = (TextView) findViewById(R.id.logBox);
    tv.post(new Runnable() {
        @Override
        public void run() {
            tv.append(fLog + "\n");
        }
    });

    final ScrollView sv = (ScrollView) findViewById(R.id.scrollBox);
    sv.postDelayed(new Runnable() {
        @Override
        public void run() {
            sv.fullScroll(ScrollView.FOCUS_DOWN);
        }
    }, 100L);

}

From source file:edu.pdx.cs410.wifi.direct.file.transfer.ClientActivity.java

public void sendFile(View view) {

    //Only try to send file if there isn't already a transfer active
    if (!transferActive) {
        if (!filePathProvided) {
            setClientFileTransferStatus("Select a file to send before pressing send");
        } else if (!connectedAndReadyToSendFile) {
            setClientFileTransferStatus("You must be connected to a server before attempting to send a file");
        }//from   www  .  ja va2  s .  co  m
        /*
        else if(targetDevice == null)
        {
           setClientFileTransferStatus("Target Device network information unknown");
        }
        */
        else if (wifiInfo == null) {
            setClientFileTransferStatus("Missing Wifi P2P information");
        } else {
            //Launch client service
            clientServiceIntent = new Intent(this, ClientService.class);
            clientServiceIntent.putExtra("fileToSend", fileToSend);
            clientServiceIntent.putExtra("port", new Integer(port));
            //clientServiceIntent.putExtra("targetDevice", targetDevice);
            clientServiceIntent.putExtra("wifiInfo", wifiInfo);
            clientServiceIntent.putExtra("clientResult", new ResultReceiver(null) {
                @Override
                protected void onReceiveResult(int resultCode, final Bundle resultData) {

                    if (resultCode == port) {
                        if (resultData == null) {
                            //Client service has shut down, the transfer may or may not have been successful. Refer to message 
                            transferActive = false;
                        } else {
                            final TextView client_status_text = (TextView) findViewById(
                                    R.id.file_transfer_status);

                            client_status_text.post(new Runnable() {
                                public void run() {
                                    client_status_text.setText((String) resultData.get("message"));
                                }
                            });
                        }
                    }

                }
            });

            transferActive = true;
            startService(clientServiceIntent);

            //end
        }
    }
}

From source file:edu.nust.distributed.downloader.ClientActivity.java

public void sendFile(View view) {

    //Only try to send file if there isn't already a transfer active
    if (!transferActive) {

        if (!connectedAndReadyToSendFile) {
            setClientFileTransferStatus("You must be connected to a server before attempting to send a file");
        }/*  w w  w  . j  a  v a  2 s .  c  o  m*/
        /*
        else if(targetDevice == null)
        {
           setClientFileTransferStatus("Target Device network information unknown");
        }
        */
        else if (wifiInfo == null) {
            setClientFileTransferStatus("Missing Wifi P2P information");
        } else {
            //Launch client service
            clientServiceIntent = new Intent(this, ClientService.class);
            TextView location = (TextView) (TextView) findViewById(R.id.textView);
            clientServiceIntent.putExtra("fileToSend", location.getText());
            clientServiceIntent.putExtra("port", new Integer(port));
            //clientServiceIntent.putExtra("targetDevice", targetDevice);
            clientServiceIntent.putExtra("wifiInfo", wifiInfo);
            clientServiceIntent.putExtra("clientResult", new ResultReceiver(null) {
                @Override
                protected void onReceiveResult(int resultCode, final Bundle resultData) {

                    if (resultCode == port) {
                        if (resultData == null) {
                            //Client service has shut down, the transfer may or may not have been successful. Refer to message 
                            transferActive = false;
                        } else {
                            final TextView client_status_text = (TextView) findViewById(
                                    R.id.file_transfer_status);

                            client_status_text.post(new Runnable() {
                                public void run() {
                                    client_status_text.setText((String) resultData.get("message"));
                                }
                            });
                        }
                    }

                }
            });

            transferActive = true;
            startService(clientServiceIntent);

            //end
        }
    }
}

From source file:fr.jerome.climbinggymlog.view.googletools.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//  w  ww  .j  ava  2s.  c  o m
 */
protected TextView createDefaultTabView(Context context) {
    final TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.post(new Runnable() {
        @Override
        public void run() {
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textView.getLayoutParams();
            if (textView.getWidth() < ((View) textView.getParent().getParent()).getWidth() * 0.33f) {
                params.width = 0;
                params.weight = 0.33f;
            }
            textView.requestLayout();
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.example.ramesh.p2pfileshare.ClientActivity.java

public void sendFile() {

    //Only try to send file if there isn't already a transfer active
    if (!transferActive) {
        if (!filePathProvided) {
            setClientFileTransferStatus("Select a file to send before pressing send");
        } else if (!connectedAndReadyToSendFile) {
            setClientFileTransferStatus("You must be connected to a server before attempting to send a file");
        }/*from www .j a  v  a 2 s.c  o  m*/
        /*
        else if(targetDevice == null)
        {
           setClientFileTransferStatus("Target Device network information unknown");
        }
        */
        else if (wifiInfo == null) {
            setClientFileTransferStatus("Missing Wifi P2P information");
        } else {
            //Launch client service
            clientServiceIntent = new Intent(this, ClientService.class);
            clientServiceIntent.putExtra("fileToSend", fileToSend);
            clientServiceIntent.putExtra("port", new Integer(port));
            //clientServiceIntent.putExtra("targetDevice", targetDevice);
            clientServiceIntent.putExtra("wifiInfo", wifiInfo);
            clientServiceIntent.putExtra("clientResult", new ResultReceiver(null) {
                @Override
                protected void onReceiveResult(int resultCode, final Bundle resultData) {

                    if (resultCode == port) {
                        if (resultData == null) {
                            //Client service has shut down, the transfer may or may not have been successful. Refer to message 
                            transferActive = false;
                        } else {
                            final TextView client_status_text = (TextView) findViewById(
                                    R.id.file_transfer_status);

                            client_status_text.post(new Runnable() {
                                public void run() {
                                    client_status_text.setText((String) resultData.get("message"));
                                }
                            });
                        }
                    }

                }
            });

            transferActive = true;
            startService(clientServiceIntent);

            //end
        }
    }
}

From source file:org.ros.android.app_chooser.ExchangeActivity.java

private void safeSetStatus(final String statusMessage) {
    final TextView statusView = (TextView) findViewById(R.id.status_view);
    if (statusView != null) {
        statusView.post(new Runnable() {
            @Override/*from   www  .  j  a v a 2  s.c o  m*/
            public void run() {
                statusView.setText(statusMessage);
            }
        });
    }
}

From source file:com.vuze.android.remote.dialog.DialogFragmentFilterByTags.java

@NonNull
@Override/*from  w  w  w.j  a  va  2s . co m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    SessionInfo sessionInfo = getSessionInfo();
    List<Map<?, ?>> tags = sessionInfo == null ? null : sessionInfo.getTags();
    if (tags != null && tags.size() > 0) {
        TreeMap<String, Long> map = new TreeMap<>();
        for (Object o : tags) {
            if (o instanceof Map) {
                Map<?, ?> mapTag = (Map<?, ?>) o;
                long uid = MapUtils.getMapLong(mapTag, "uid", 0);
                String name = MapUtils.getMapString(mapTag, "name", "??");
                int type = MapUtils.getMapInt(mapTag, "type", 0);
                if (type == 3) {
                    // type-name will be "Manual" :(
                    name = "Tag: " + name;
                } else {
                    String typeName = MapUtils.getMapString(mapTag, "type-name", null);
                    if (typeName != null) {
                        name = typeName + ": " + name;
                    }
                }
                map.put(name, uid);
            }
        }

        long[] vals = new long[map.size()];
        String[] strings = map.keySet().toArray(new String[map.keySet().size()]);
        for (int i = 0; i < vals.length; i++) {
            vals[i] = map.get(strings[i]);
        }

        filterByList = new ValueStringArray(vals, strings);
    }

    if (filterByList == null) {
        filterByList = AndroidUtils.getValueStringArray(getResources(), R.array.filterby_list);
    }

    AndroidUtils.AlertDialogBuilder alertDialogBuilder = AndroidUtils.createAlertDialogBuilder(getActivity(),
            R.layout.dialog_filter_by);

    View view = alertDialogBuilder.view;
    AlertDialog.Builder builder = alertDialogBuilder.builder;

    // get our tabHost from the xml
    TabHost tabHost = (TabHost) view.findViewById(R.id.filterby_tabhost);
    tabHost.setup();

    // create tab 1
    TabHost.TabSpec spec1 = tabHost.newTabSpec("tab1");
    spec1.setIndicator("States");
    spec1.setContent(R.id.filterby_sv_state);
    tabHost.addTab(spec1);
    //create tab2
    TabHost.TabSpec spec2 = tabHost.newTabSpec("tab2");
    spec2.setIndicator("Tags");
    spec2.setContent(R.id.filterby_tv_tags);
    tabHost.addTab(spec2);

    int height = AndroidUtilsUI.dpToPx(32);
    tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
    tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;

    TextView tvState = (TextView) view.findViewById(R.id.filterby_tv_state);
    tvState.setMovementMethod(LinkMovementMethod.getInstance());

    final TextView tvTags = (TextView) view.findViewById(R.id.filterby_tv_tags);
    tvTags.setMovementMethod(LinkMovementMethod.getInstance());

    // for API <= 10 (maybe 11?), otherwise tags will display on one line
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (!tabId.equals("tab2")) {
                return;
            }
            tvTags.post(new Runnable() {
                @Override
                public void run() {
                    spanTags.updateTags();
                }
            });
        }
    });

    builder.setTitle(R.string.filterby_title);

    // Add action buttons
    builder.setPositiveButton(R.string.action_filterby, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            if (mapSelectedTag == null) {
                return;
            }
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            String name = MapUtils.getMapString(mapSelectedTag, "name", "??");

            mListener.filterBy(uidSelected, name, true);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            DialogFragmentFilterByTags.this.getDialog().cancel();
        }
    });

    List<Map<?, ?>> manualTags = new ArrayList<>();
    List<Map<?, ?>> stateTags = new ArrayList<>();

    if (sessionInfo != null) {
        // Dialog never gets called wehn getTags has no tags
        List<Map<?, ?>> allTags = sessionInfo.getTags();
        if (allTags != null) {
            for (Map<?, ?> mapTag : allTags) {
                int type = MapUtils.getMapInt(mapTag, "type", 0);
                switch (type) {
                case 0:
                case 1:
                case 2:
                    stateTags.add(mapTag);
                    break;
                case 3: // manual
                    manualTags.add(mapTag);
                    break;
                }
            }
        }
    }

    SpanTagsListener l = new SpanTagsListener() {
        @Override
        public void tagClicked(Map mapTag, String name) {
            mapSelectedTag = mapTag;
            // todo: long click, don't exit
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            mListener.filterBy(uidSelected, name, true);
            DialogFragmentFilterByTags.this.getDialog().dismiss();
        }

        @Override
        public int getTagState(Map mapTag, String name) {
            if (mapSelectedTag == null) {
                return SpanTags.TAG_STATE_UNSELECTED;
            }
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            if (uidSelected == -1) {
                return SpanTags.TAG_STATE_UNSELECTED;
            }
            long uidQuery = MapUtils.getMapLong(mapTag, "uid", -1);
            return uidQuery == uidSelected ? SpanTags.TAG_STATE_SELECTED : SpanTags.TAG_STATE_UNSELECTED;
        }
    };
    spanTags = new SpanTags(getActivity(), sessionInfo, tvTags, l);
    spanTags.setTagMaps(manualTags);
    spanTags.setShowIcon(false);
    spanTags.updateTags();

    SpanTags spanState = new SpanTags(getActivity(), sessionInfo, tvState, l);
    spanState.setTagMaps(stateTags);
    spanState.setShowIcon(false);
    spanState.updateTags();

    return builder.create();
}

From source file:com.kaku.weac.fragment.AlarmClockOntimeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    LogUtil.d(LOG_TAG, getActivity().toString() + "onCreateView");

    View view = inflater.inflate(R.layout.fm_alarm_clock_ontime, container, false);
    mTimeTv = (TextView) view.findViewById(R.id.ontime_time);
    // /* w w  w.  j a v  a  2  s .co  m*/
    mTimeTv.setText(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date()));
    mCurrentTimeDisplay = mTimeTv.getText().toString();
    // ?
    new Thread(new TimeUpdateThread()).start();

    // 
    TextView tagTv = (TextView) view.findViewById(R.id.ontime_tag);
    tagTv.setText(mAlarmClock.getTag());

    // ??
    TextView napTv = (TextView) view.findViewById(R.id.ontime_nap);
    // ????
    if (mAlarmClock.isNap()) {
        // X???????
        if (mNapTimesRan != mNapTimes) {
            // ??
            napTv.setText(String.format(getString(R.string.touch_here_nap), mNapInterval));
            napTv.setOnClickListener(this);
        } else {
            napTv.setVisibility(View.GONE);
        }
    } else {
        napTv.setVisibility(View.GONE);
    }

    LogUtil.i(LOG_TAG, "??" + mNapTimes);

    // ??
    TextView slidingTipIv = (TextView) view.findViewById(R.id.sliding_tip_tv);
    final AnimationDrawable animationDrawable = (AnimationDrawable) slidingTipIv.getCompoundDrawables()[0];
    // ?4.0
    slidingTipIv.post(new Runnable() {
        @Override
        public void run() {
            animationDrawable.start();
        }
    });

    MySlidingView mySlidingView = (MySlidingView) view.findViewById(R.id.my_sliding_view);
    mySlidingView.setSlidingTipListener(new MySlidingView.SlidingTipListener() {
        @Override
        public void onSlidFinish() {
            // ?
            finishActivity();
        }
    });

    // ??
    if (mAlarmClock.isWeaPrompt()) {
        mWeatherInfoGroup = (ViewGroup) view.findViewById(R.id.weather_info_group);
        mWeatherPbar = (ProgressBar) view.findViewById(R.id.progress_bar);
        mWeatherTypeTv = (TextView) view.findViewById(R.id.weather_type_tv);
        mUmbrellaTv = (TextView) view.findViewById(R.id.umbrella_tv);
        // ?
        initWeather();
    }
    return view;
}

From source file:com.sentaroh.android.TextFileBrowser.ViewedFileListAdapter.java

@SuppressWarnings("deprecation")
@Override/*w  w  w.j a  v  a 2s  . c om*/
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    final TextView text = (TextView) super.getDropDownView(position, convertView, parent);
    //        text.setBackgroundColor(Color.LTGRAY);
    if (Build.VERSION.SDK_INT >= 11) {
        //          text.setCompoundDrawablePadding(10);
        //          text.setCompoundDrawablesWithIntrinsicBounds(
        //                mContext.getResources().getDrawable(android.R.drawable.btn_radio), 
        //                null, null, null);
        text.setCompoundDrawablesWithIntrinsicBounds(null, null,
                mContext.getResources().getDrawable(android.R.drawable.btn_radio), null);

    }
    text.setText(getItem(position).file_path);
    //       text.setEllipsize(TruncateAt.START);
    text.post(new Runnable() {
        @Override
        public void run() {
            text.setSingleLine(false);
        }
    });

    //        text.setTextColor(Color.BLACK);
    //        if (text_color!=0) text.setTextColor(text_color);
    //        if (text_size!=0) text.setTextSize(text_size);

    return text;
}

From source file:org.tigase.mobile.roster.AuthRequestActivity.java

@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    setContentView(R.layout.auth_request);

    this.jid = JID.jidInstance(getIntent().getStringExtra("jid"));
    BareJID account = BareJID.bareJIDInstance(getIntent().getStringExtra("account"));

    final TextView jidTextView = (TextView) findViewById(R.id.vcard_jid);
    jidTextView.setText(jid.toString());

    final VCardModule module = ((MessengerApplication) getApplicationContext()).getMultiJaxmpp().get(account)
            .getModule(VCardModule.class);
    final PresenceModule presenceModule = ((MessengerApplication) getApplicationContext()).getMultiJaxmpp()
            .get(account).getModule(PresenceModule.class);

    final Button okButton = (Button) findViewById(R.id.req_yesButton);
    okButton.setOnClickListener(new OnClickListener() {

        @Override//from   w ww  .  j  ava2 s  . c  om
        public void onClick(View v) {
            (new Thread() {
                @Override
                public void run() {
                    try {
                        presenceModule.subscribed(jid);
                        presenceModule.subscribe(jid);
                    } catch (Exception e) {
                        WarningDialog.showWarning(AuthRequestActivity.this, R.string.auth_request_cant_accept);
                    }
                }
            }).start();
            finish();
        }
    });

    final Button noButton = (Button) findViewById(R.id.req_noButton);
    noButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            (new Thread() {
                @Override
                public void run() {
                    try {
                        presenceModule.unsubscribe(jid);
                        presenceModule.unsubscribed(jid);
                    } catch (Exception e) {
                        WarningDialog.showWarning(AuthRequestActivity.this, R.string.auth_request_cant_deny);
                    }
                }
            }).start();
            finish();
        }
    });
    final Button cancelButton = (Button) findViewById(R.id.req_cancelButton);
    cancelButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });

    (new Thread() {
        @Override
        public void run() {
            try {
                module.retrieveVCard(jid, new VCardAsyncCallback() {

                    @Override
                    public void onError(Stanza responseStanza, ErrorCondition error) throws JaxmppException {
                    }

                    @Override
                    public void onTimeout() throws JaxmppException {
                    }

                    @Override
                    protected void onVCardReceived(final VCard vcard) throws XMLException {
                        jidTextView.post(new Runnable() {

                            @Override
                            public void run() {
                                VCardViewActivity.fillFields(AuthRequestActivity.this, getContentResolver(),
                                        getResources(), jid, vcard, null);
                            }
                        });
                    }
                });
            } catch (JaxmppException e) {
                e.printStackTrace();
            }
        }
    }).start();

}