List of usage examples for android.text.style UnderlineSpan UnderlineSpan
public UnderlineSpan()
From source file:com.freshdigitable.udonroad.UserInfoView.java
private void bindURL(String displayUrl, String actualUrl) { if (TextUtils.isEmpty(displayUrl) || TextUtils.isEmpty(actualUrl)) { return;//from w w w . j av a 2 s. c o m } final SpannableStringBuilder ssb = new SpannableStringBuilder(displayUrl); ssb.setSpan(new UnderlineSpan(), 0, displayUrl.length(), 0); url.setText(ssb); url.setVisibility(VISIBLE); urlIcon.setVisibility(VISIBLE); final OnClickListener clickListener = create(actualUrl); url.setOnClickListener(clickListener); urlIcon.setOnClickListener(clickListener); }
From source file:org.awesomeapp.messenger.ui.ConversationListItem.java
/** public void bind(ConversationViewHolder holder, Cursor cursor, String underLineText, boolean scrolling) { bind(holder, cursor, underLineText, true, scrolling); }/*www .j a va 2s .c om*/ */ public void bind(ConversationViewHolder holder, long contactId, long providerId, long accountId, String address, String nickname, int contactType, String message, long messageDate, int presence, String underLineText, boolean showChatMsg, boolean scrolling) { //applyStyleColors(holder); if (nickname == null) { nickname = address.split("@")[0].split("\\.")[0]; } else { nickname = nickname.split("@")[0].split("\\.")[0]; } if (Imps.Contacts.TYPE_GROUP == contactType) { String groupCountString = getGroupCount(getContext().getContentResolver(), contactId); nickname += groupCountString; } if (!TextUtils.isEmpty(underLineText)) { // highlight/underline the word being searched String lowercase = nickname.toLowerCase(); int start = lowercase.indexOf(underLineText.toLowerCase()); if (start >= 0) { int end = start + underLineText.length(); SpannableString str = new SpannableString(nickname); str.setSpan(new UnderlineSpan(), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE); holder.mLine1.setText(str); } else holder.mLine1.setText(nickname); } else holder.mLine1.setText(nickname); holder.mStatusIcon.setVisibility(View.GONE); if (holder.mAvatar != null) { if (Imps.Contacts.TYPE_GROUP == contactType) { holder.mAvatar.setVisibility(View.VISIBLE); if (AVATAR_DEFAULT_GROUP == null) AVATAR_DEFAULT_GROUP = new RoundedAvatarDrawable( BitmapFactory.decodeResource(getResources(), R.drawable.group_chat)); holder.mAvatar.setImageDrawable(AVATAR_DEFAULT_GROUP); } // else if (cursor.getColumnIndex(Imps.Contacts.AVATAR_DATA)!=-1) else { // holder.mAvatar.setVisibility(View.GONE); Drawable avatar = null; try { avatar = DatabaseUtils.getAvatarFromAddress(this.getContext().getContentResolver(), address, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT); // avatar = DatabaseUtils.getAvatarFromCursor(cursor, COLUMN_AVATAR_DATA, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT); } catch (Exception e) { //problem decoding avatar Log.e(ImApp.LOG_TAG, "error decoding avatar", e); } try { if (avatar != null) { //if (avatar instanceof RoundedAvatarDrawable) // setAvatarBorder(presence,(RoundedAvatarDrawable)avatar); holder.mAvatar.setImageDrawable(avatar); } else { // int color = getAvatarBorder(presence); int padding = 24; LetterAvatar lavatar = new LetterAvatar(getContext(), nickname, padding); holder.mAvatar.setImageDrawable(lavatar); } holder.mAvatar.setVisibility(View.VISIBLE); } catch (OutOfMemoryError ome) { //this seems to happen now and then even on tiny images; let's catch it and just not set an avatar } } } if (showChatMsg && message != null) { if (holder.mLine2 != null) { if (SecureMediaStore.isVfsUri(message)) { FileInfo fInfo = SystemServices.getFileInfoFromURI(getContext(), Uri.parse(message)); if (fInfo.type == null || fInfo.type.startsWith("image")) { if (holder.mMediaThumb != null) { holder.mMediaThumb.setVisibility(View.VISIBLE); if (fInfo.type != null && fInfo.type.equals("image/png")) { holder.mMediaThumb.setScaleType(ImageView.ScaleType.FIT_CENTER); } else { holder.mMediaThumb.setScaleType(ImageView.ScaleType.CENTER_CROP); } setThumbnail(getContext().getContentResolver(), holder, Uri.parse(message)); holder.mLine2.setVisibility(View.GONE); } } else { holder.mLine2.setText(""); } } else if ((!TextUtils.isEmpty(message)) && message.startsWith("/")) { String cmd = message.toString().substring(1); if (cmd.startsWith("sticker")) { String[] cmds = cmd.split(":"); String mimeTypeSticker = "image/png"; Uri mediaUri = Uri.parse("asset://" + cmds[1]); setThumbnail(getContext().getContentResolver(), holder, mediaUri); holder.mLine2.setVisibility(View.GONE); holder.mMediaThumb.setScaleType(ImageView.ScaleType.FIT_CENTER); } } else if ((!TextUtils.isEmpty(message)) && message.startsWith(":")) { String[] cmds = message.split(":"); try { String[] stickerParts = cmds[1].split("-"); String stickerPath = "stickers/" + stickerParts[0].toLowerCase() + "/" + stickerParts[1].toLowerCase() + ".png"; //make sure sticker exists AssetFileDescriptor afd = getContext().getAssets().openFd(stickerPath); afd.getLength(); afd.close(); //now setup the new URI for loading local sticker asset Uri mediaUri = Uri.parse("asset://localhost/" + stickerPath); setThumbnail(getContext().getContentResolver(), holder, mediaUri); holder.mLine2.setVisibility(View.GONE); holder.mMediaThumb.setScaleType(ImageView.ScaleType.FIT_CENTER); } catch (Exception e) { } } else { if (holder.mMediaThumb != null) holder.mMediaThumb.setVisibility(View.GONE); holder.mLine2.setVisibility(View.VISIBLE); try { holder.mLine2.setText(android.text.Html.fromHtml(message).toString()); } catch (RuntimeException re) { } } } if (messageDate != -1) { Date dateLast = new Date(messageDate); holder.mStatusText.setText(sPrettyTime.format(dateLast)); } else { holder.mStatusText.setText(""); } } else if (holder.mLine2 != null) { holder.mLine2.setText(address); if (holder.mMediaThumb != null) holder.mMediaThumb.setVisibility(View.GONE); } holder.mLine1.setVisibility(View.VISIBLE); if (providerId != -1) getEncryptionState(providerId, accountId, address, holder); }
From source file:com.citrus.sdk.fragments.SavedOptions.java
private void showSignInFlow(String errorMessage) { signInLayout = (RelativeLayout) returnView.findViewById(R.id.signInLayout); signInLayout.setVisibility(View.VISIBLE); usernameET = (EditText) returnView.findViewById(R.id.username); passwordET = (EditText) returnView.findViewById(R.id.password); errorText = (TextView) returnView.findViewById(R.id.errorText); resetPass = (TextView) returnView.findViewById(R.id.resetPass); passwordET.requestFocus();//from www . j a v a 2 s . c om String udata = "Reset Password?"; SpannableString content = new SpannableString(udata); content.setSpan(new UnderlineSpan(), 0, udata.length(), 0); resetPass.setText(content); usernameET.setText(OneClicksignup.getDefaultGmail(getActivity())); errorText.setText(errorMessage); Button signIn = (Button) returnView.findViewById(R.id.signIn); signIn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String username = usernameET.getText().toString(); String password = passwordET.getText().toString(); String params[] = new String[] { username, password }; signInLayout.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.VISIBLE); new SignInAsynch(getActivity(), signInListener).execute(params); } }); resetPass.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { showPopup(); } }); }
From source file:org.awesomeapp.messenger.ui.ContactListItem.java
public void bind(Cursor cursor, String underLineText, boolean showChatMsg, boolean scrolling) { ViewHolder holder = (ViewHolder) getTag(); if (holder == null) { holder = new ViewHolder(); holder.mLine1 = (TextView) findViewById(R.id.line1); holder.mLine2 = (TextView) findViewById(R.id.line2); holder.mAvatar = (ImageView) findViewById(R.id.avatar); holder.mStatusIcon = (ImageView) findViewById(R.id.statusIcon); holder.mStatusText = (TextView) findViewById(R.id.statusText); //holder.mEncryptionIcon = (ImageView)view.findViewById(R.id.encryptionIcon); holder.mContainer = findViewById(R.id.message_container); // holder.mMediaThumb = (ImageView)findViewById(R.id.media_thumbnail); setTag(holder);//from w ww .j a va 2 s . c o m } final long providerId = cursor.getLong(COLUMN_CONTACT_PROVIDER); final String address = cursor.getString(COLUMN_CONTACT_USERNAME); final String displayName = cursor.getString(COLUMN_CONTACT_NICKNAME); final int type = cursor.getInt(COLUMN_CONTACT_TYPE); final String lastMsg = cursor.getString(COLUMN_LAST_MESSAGE); long lastMsgDate = cursor.getLong(COLUMN_LAST_MESSAGE_DATE); final int presence = cursor.getInt(COLUMN_CONTACT_PRESENCE_STATUS); final int subType = cursor.getInt(COLUMN_SUBSCRIPTION_TYPE); final int subStatus = cursor.getInt(COLUMN_SUBSCRIPTION_STATUS); String statusText = cursor.getString(COLUMN_CONTACT_CUSTOM_STATUS); String nickname = displayName; if (nickname == null) { nickname = address.split("@")[0]; } else if (nickname.indexOf('@') != -1) { nickname = nickname.split("@")[0]; } if (!TextUtils.isEmpty(underLineText)) { // highlight/underline the word being searched String lowercase = nickname.toLowerCase(); int start = lowercase.indexOf(underLineText.toLowerCase()); if (start >= 0) { int end = start + underLineText.length(); SpannableString str = new SpannableString(nickname); str.setSpan(new UnderlineSpan(), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE); holder.mLine1.setText(str); } else holder.mLine1.setText(nickname); } else holder.mLine1.setText(nickname); /* if (holder.mStatusIcon != null) { Drawable statusIcon = brandingRes.getDrawable(PresenceUtils.getStatusIconId(presence)); //statusIcon.setBounds(0, 0, statusIcon.getIntrinsicWidth(), // statusIcon.getIntrinsicHeight()); holder.mStatusIcon.setImageDrawable(statusIcon);address }*/ holder.mStatusIcon.setVisibility(View.GONE); if (holder.mAvatar != null) { if (Imps.Contacts.TYPE_GROUP == type) { holder.mAvatar.setVisibility(View.VISIBLE); if (AVATAR_DEFAULT_GROUP == null) AVATAR_DEFAULT_GROUP = new RoundedAvatarDrawable( BitmapFactory.decodeResource(getResources(), R.drawable.group_chat)); holder.mAvatar.setImageDrawable(AVATAR_DEFAULT_GROUP); } else if (cursor.getColumnIndex(Imps.Contacts.AVATAR_DATA) != -1) { RoundedAvatarDrawable avatar = null; try { avatar = DatabaseUtils.getAvatarFromCursor(cursor, COLUMN_AVATAR_DATA, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT); } catch (Exception e) { //problem decoding avatar Log.e(ImApp.LOG_TAG, "error decoding avatar", e); } try { if (avatar != null) { setAvatarBorder(presence, avatar); holder.mAvatar.setImageDrawable(avatar); } else { String letterString = null; if (nickname.length() > 0) letterString = nickname.substring(0, 1).toUpperCase(); else letterString = "?"; //the unknown name! int color = getAvatarBorder(presence); int padding = 24; LetterAvatar lavatar = new LetterAvatar(getContext(), color, letterString, padding); holder.mAvatar.setImageDrawable(lavatar); } holder.mAvatar.setVisibility(View.VISIBLE); } catch (OutOfMemoryError ome) { //this seems to happen now and then even on tiny images; let's catch it and just not set an avatar } } else { //holder.mAvatar.setImageDrawable(getContext().getResources().getDrawable(R.drawable.avatar_unknown)); holder.mAvatar.setVisibility(View.GONE); } } holder.mStatusText.setText(""); statusText = address; holder.mLine2.setText(statusText); if (subType == Imps.ContactsColumns.SUBSCRIPTION_TYPE_INVITATIONS) { // if (holder.mLine2 != null) // holder.mLine2.setText("Contact List Request"); } holder.mLine1.setVisibility(View.VISIBLE); }
From source file:com.android.browser.GearsBaseDialog.java
/** * Display a button as an HTML link. Remove the background, set the * text color to R.color.dialog_link and draw an underline *//*from w w w. j ava2 s .co m*/ void displayAsLink(Button button) { if (button == null) { return; } CharSequence text = button.getText(); button.setBackgroundDrawable(null); int color = getResources().getColor(R.color.dialog_link); button.setTextColor(color); SpannableString str = new SpannableString(text); str.setSpan(new UnderlineSpan(), 0, str.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); button.setText(str); button.setFocusable(false); }
From source file:com.evandroid.musica.fragment.LyricsViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRetainInstance(true);//from w w w . j a va 2 s . com setHasOptionsMenu(true); View layout = inflater.inflate(R.layout.lyrics_view, container, false); if (savedInstanceState != null) try { Lyrics l = Lyrics.fromBytes(savedInstanceState.getByteArray("lyrics")); if (l != null) this.mLyrics = l; mSearchQuery = savedInstanceState.getString("searchQuery"); mSearchFocused = savedInstanceState.getBoolean("searchFocused"); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } else { Bundle args = getArguments(); if (args != null) try { Lyrics lyrics = Lyrics.fromBytes(args.getByteArray("lyrics")); this.mLyrics = lyrics; if (lyrics != null && lyrics.getText() == null && lyrics.getArtist() != null) { String artist = lyrics.getArtist(); String track = lyrics.getTrack(); String url = lyrics.getURL(); fetchLyrics(artist, track, url); mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout); startRefreshAnimation(); } } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } } if (layout != null) { Bundle args = savedInstanceState != null ? savedInstanceState : getArguments(); boolean screenOn = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getBoolean("pref_force_screen_on", false); TextSwitcher textSwitcher = (TextSwitcher) layout.findViewById(R.id.switcher); textSwitcher.setFactory(new LyricsTextFactory(layout.getContext())); ActionMode.Callback callback = new CustomSelectionCallback(getActivity()); ((TextView) textSwitcher.getChildAt(0)).setCustomSelectionActionModeCallback(callback); ((TextView) textSwitcher.getChildAt(1)).setCustomSelectionActionModeCallback(callback); textSwitcher.setKeepScreenOn(screenOn); layout.findViewById(R.id.lrc_view).setKeepScreenOn(screenOn); TextView id3TV = (TextView) layout.findViewById(R.id.id3_tv); SpannableString text = new SpannableString(id3TV.getText()); text.setSpan(new UnderlineSpan(), 1, text.length() - 1, 0); id3TV.setText(text); final RefreshIcon refreshFab = (RefreshIcon) getActivity().findViewById(R.id.refresh_fab); refreshFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!mRefreshLayout.isRefreshing()) fetchCurrentLyrics(true); } }); FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent settingsIntent = new Intent(getActivity(), SettingsActivity.class); startActivity(settingsIntent); } }); if (args != null) refreshFab.setEnabled(args.getBoolean("refreshFabEnabled", true)); mScrollView = (NestedScrollView) layout.findViewById(R.id.scrollview); mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout); TypedValue primaryColor = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.colorPrimary, primaryColor, true); mRefreshLayout.setColorSchemeResources(primaryColor.resourceId, R.color.accent); float offset = getResources().getDisplayMetrics().density * 64; mRefreshLayout.setProgressViewEndTarget(true, (int) offset); mRefreshLayout.setOnRefreshListener(this); if (mLyrics == null) { if (!startEmtpy) fetchCurrentLyrics(false); } else if (mLyrics.getFlag() == Lyrics.SEARCH_ITEM) { mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout); startRefreshAnimation(); if (mLyrics.getArtist() != null) fetchLyrics(mLyrics.getArtist(), mLyrics.getTrack()); } else //Rotation, resume update(mLyrics, layout, false); } if (broadcastReceiver == null) broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { searchResultLock = false; String artist = intent.getStringExtra("artist"); String track = intent.getStringExtra("track"); if (artist != null && track != null && mRefreshLayout.isEnabled()) { startRefreshAnimation(); new ParseTask(LyricsViewFragment.this, false, true).execute(mLyrics); } } }; return layout; }
From source file:gov.wa.wsdot.android.wsdot.ui.tollrates.SR167TollRatesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_dynamic_toll_rates, null); mRecyclerView = root.findViewById(R.id.my_recycler_view); mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(getActivity()); mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new SR167TollRatesItemAdapter(getActivity()); mRecyclerView.setAdapter(mAdapter);/* ww w . j a va2 s . co m*/ mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity())); mRecyclerView.setPadding(0, 0, 0, 120); addDisclaimerView(root); directionRadioGroup = root.findViewById(R.id.segment_control); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); radioGroupDirectionIndex = sharedPref.getInt(getString(R.string.toll_rates_167_travel_direction_key), 0); if (radioGroupDirectionIndex == 0) { RadioButton leftSegment = root.findViewById(R.id.radio_left); leftSegment.setChecked(true); } else { RadioButton rightSegment = root.findViewById(R.id.radio_right); rightSegment.setChecked(true); } directionRadioGroup.setOnCheckedChangeListener((group, checkedId) -> { RadioButton selectedDirection = directionRadioGroup.findViewById(checkedId); mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0)))); mLayoutManager.scrollToPositionWithOffset(0, 0); SharedPreferences sharedPref1 = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences.Editor editor = sharedPref1.edit(); radioGroupDirectionIndex = directionRadioGroup.indexOfChild(selectedDirection); TextView travelTimeView = root.findViewById(R.id.travel_time_text); travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S")); editor.putInt(getString(R.string.toll_rates_167_travel_direction_key), radioGroupDirectionIndex); editor.apply(); }); // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity. root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); swipeRefreshLayout = root.findViewById(R.id.swipe_container); swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light, R.color.holo_orange_light, R.color.holo_red_light); mEmptyView = root.findViewById(R.id.empty_list_view); TextView header_link = root.findViewById(R.id.header_text); // create spannable string for underline SpannableString content = new SpannableString( getActivity().getResources().getString(R.string.sr167_info_link)); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); header_link.setText(content); header_link.setTextColor(getResources().getColor(R.color.primary_default)); header_link.setOnClickListener(v -> { Intent intent = new Intent(); // GA tracker mTracker = ((WsdotApplication) getActivity().getApplication()).getDefaultTracker(); mTracker.setScreenName("/Toll Rates/Learn about SR-167"); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://www.wsdot.wa.gov/Tolling/SR167HotLanes/HOTtollrates.htm")); startActivity(intent); }); viewModel = ViewModelProviders.of(this, viewModelFactory).get(TollRatesViewModel.class); viewModel.getResourceStatus().observe(this, resourceStatus -> { if (resourceStatus != null) { switch (resourceStatus.status) { case LOADING: swipeRefreshLayout.setRefreshing(true); break; case SUCCESS: swipeRefreshLayout.setRefreshing(false); break; case ERROR: swipeRefreshLayout.setRefreshing(false); Toast.makeText(this.getContext(), "connection error", Toast.LENGTH_LONG).show(); } } }); viewModel.getSR167TollRateItems().observe(this, tollRateGroups -> { if (tollRateGroups != null) { mEmptyView.setVisibility(View.GONE); Collections.sort(tollRateGroups, new SortTollGroupByLocation()); Collections.sort(tollRateGroups, new SortTollGroupByDirection()); tollGroups = new ArrayList<>(tollRateGroups); directionRadioGroup.getCheckedRadioButtonId(); RadioButton selectedDirection = directionRadioGroup .findViewById(directionRadioGroup.getCheckedRadioButtonId()); mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0)))); } }); viewModel.getTravelTimesForETLFor("167").observe(this, travelTimes -> { TextView travelTimeView = root.findViewById(R.id.travel_time_text); if (travelTimes.size() > 0) { travelTimeView.setVisibility(View.VISIBLE); this.travelTimes = new ArrayList<>(travelTimes); travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S")); } else { travelTimeView.setVisibility(View.GONE); } }); timer = new Timer(); timer.schedule(new SR167TollRatesFragment.RatesTimerTask(), 0, 60000); // Schedule rates to update every 60 seconds return root; }
From source file:gov.wa.wsdot.android.wsdot.ui.tollrates.I405TollRatesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_dynamic_toll_rates, null); mRecyclerView = root.findViewById(R.id.my_recycler_view); mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(getActivity()); mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new I405TollRatesItemAdapter(getActivity()); mRecyclerView.setAdapter(mAdapter);//w ww .j a v a2s. c o m mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity())); mRecyclerView.setPadding(0, 0, 0, 120); addDisclaimerView(root); directionRadioGroup = root.findViewById(R.id.segment_control); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); radioGroupDirectionIndex = sharedPref.getInt(getString(R.string.toll_rates_405_travel_direction_key), 0); if (radioGroupDirectionIndex == 0) { RadioButton leftSegment = root.findViewById(R.id.radio_left); leftSegment.setChecked(true); } else { RadioButton rightSegment = root.findViewById(R.id.radio_right); rightSegment.setChecked(true); } directionRadioGroup.setOnCheckedChangeListener((group, checkedId) -> { RadioButton selectedDirection = directionRadioGroup.findViewById(checkedId); mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0)))); mLayoutManager.scrollToPositionWithOffset(0, 0); SharedPreferences sharedPref1 = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences.Editor editor = sharedPref1.edit(); radioGroupDirectionIndex = directionRadioGroup.indexOfChild(selectedDirection); TextView travelTimeView = root.findViewById(R.id.travel_time_text); travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S")); editor.putInt(getString(R.string.toll_rates_405_travel_direction_key), radioGroupDirectionIndex); editor.apply(); }); // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity. root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); swipeRefreshLayout = root.findViewById(R.id.swipe_container); swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light, R.color.holo_orange_light, R.color.holo_red_light); mEmptyView = root.findViewById(R.id.empty_list_view); TextView header_link = root.findViewById(R.id.header_text); // create spannable string for underline SpannableString content = new SpannableString( getActivity().getResources().getString(R.string.i405_info_link)); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); header_link.setText(content); header_link.setTextColor(getResources().getColor(R.color.primary_default)); header_link.setOnClickListener(v -> { Intent intent = new Intent(); // GA tracker mTracker = ((WsdotApplication) getActivity().getApplication()).getDefaultTracker(); mTracker.setScreenName("/Toll Rates/Learn about I-405"); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://www.wsdot.wa.gov/Tolling/405/rates.htm")); startActivity(intent); }); viewModel = ViewModelProviders.of(this, viewModelFactory).get(TollRatesViewModel.class); viewModel.getResourceStatus().observe(this, resourceStatus -> { if (resourceStatus != null) { switch (resourceStatus.status) { case LOADING: swipeRefreshLayout.setRefreshing(true); break; case SUCCESS: swipeRefreshLayout.setRefreshing(false); break; case ERROR: swipeRefreshLayout.setRefreshing(false); Toast.makeText(this.getContext(), "connection error", Toast.LENGTH_LONG).show(); } } }); viewModel.getTravelTimesStatus().observe(this, resourceStatus -> { if (resourceStatus != null) { switch (resourceStatus.status) { case LOADING: break; case SUCCESS: root.findViewById(R.id.travel_time_text).setVisibility(View.VISIBLE); break; case ERROR: root.findViewById(R.id.travel_time_text).setVisibility(View.GONE); } } }); viewModel.getI405TollRateItems().observe(this, tollRateGroups -> { if (tollRateGroups != null) { mEmptyView.setVisibility(View.GONE); Collections.sort(tollRateGroups, new SortTollGroupByLocation()); Collections.sort(tollRateGroups, new SortTollGroupByDirection()); tollGroups = new ArrayList<>(tollRateGroups); directionRadioGroup.getCheckedRadioButtonId(); RadioButton selectedDirection = directionRadioGroup .findViewById(directionRadioGroup.getCheckedRadioButtonId()); mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0)))); } }); viewModel.getTravelTimesForETLFor("405").observe(this, travelTimes -> { TextView travelTimeView = root.findViewById(R.id.travel_time_text); if (travelTimes.size() > 0) { travelTimeView.setVisibility(View.VISIBLE); this.travelTimes = new ArrayList<>(travelTimes); travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S")); } else { travelTimeView.setVisibility(View.GONE); } }); timer = new Timer(); timer.schedule(new RatesTimerTask(), 0, 60000); // Schedule rates to update every 60 seconds return root; }
From source file:org.sirimangalo.meditationplus.AdapterCommit.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.list_item_commit, parent, false); final View shell = rowView.findViewById(R.id.detail_shell); rowView.setOnClickListener(new View.OnClickListener() { @Override//from ww w.j av a2s.com public void onClick(View view) { boolean visible = shell.getVisibility() == View.VISIBLE; shell.setVisibility(visible ? View.GONE : View.VISIBLE); context.setCommitVisible(position, !visible); } }); final JSONObject p = values.get(position); TextView title = (TextView) rowView.findViewById(R.id.title); TextView descV = (TextView) rowView.findViewById(R.id.desc); TextView defV = (TextView) rowView.findViewById(R.id.def); TextView usersV = (TextView) rowView.findViewById(R.id.users); TextView youV = (TextView) rowView.findViewById(R.id.you); try { if (p.getBoolean("open")) shell.setVisibility(View.VISIBLE); title.setText(p.getString("title")); descV.setText(p.getString("description")); String length = p.getString("length"); String time = p.getString("time"); final String cid = p.getString("cid"); String def = ""; boolean repeat = false; if (length.indexOf(":") > 0) { repeat = true; String[] lengtha = length.split(":"); def += lengtha[0] + " minutes walking and " + lengtha[1] + " minutes sitting"; } else def += length + " minutes total meditation"; String period = p.getString("period"); String day = p.getString("day"); if (period.equals("daily")) { if (repeat) def += " every day"; else def += " per day"; } else if (period.equals("weekly")) { if (repeat) def += " every " + dow[Integer.parseInt(day)]; else def += " per week"; } else if (period.equals("monthly")) { if (repeat) def += " on the " + day + (day.substring(day.length() - 1).equals("1") ? "st" : (day.substring(day.length() - 1).equals("2") ? "nd" : (day.substring(day.length() - 1).equals("3") ? "rd" : "th"))) + " day of the month"; else def += " per month"; } else if (period.equals("yearly")) { if (repeat) def += " on the " + day + (day.substring(day.length() - 1).equals("1") ? "st" : (day.substring(day.length() - 1).equals("2") ? "nd" : (day.substring(day.length() - 1).equals("3") ? "rd" : "th"))) + " day of the year"; else def += " per year"; } if (!time.equals("any")) { Calendar utc = Calendar.getInstance(TimeZone.getTimeZone("UTC")); utc.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0])); utc.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1])); Calendar here = Calendar.getInstance(); here.setTimeInMillis(utc.getTimeInMillis()); int hours = here.get(Calendar.HOUR_OF_DAY); int minutes = here.get(Calendar.MINUTE); def += " at " + (time.length() == 4 ? "0" : "") + time.replace(":", "") + "h UTC <i>(" + (hours > 12 ? hours - 12 : hours) + ":" + ((minutes < 10 ? "0" : "") + minutes) + " " + (hours > 11 && hours < 24 ? "PM" : "AM") + " your time)</i>"; } defV.setText(Html.fromHtml(def)); JSONObject usersJ = p.getJSONObject("users"); ArrayList<String> committedArray = new ArrayList<String>(); // collect into array for (int i = 0; i < usersJ.names().length(); i++) { try { String j = usersJ.names().getString(i); String k = j; // if(j.equals(p.getString("creator"))) // k = "["+j+"]"; committedArray.add(k); } catch (JSONException e) { e.printStackTrace(); } } String text = context.getString(R.string.committed) + " "; // add spans int committed = -1; int pos = text.length(); // start after "Committed: " text += TextUtils.join(", ", committedArray); Spannable span = new SpannableString(text); span.setSpan(new StyleSpan(Typeface.BOLD), 0, pos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // bold the "Online: " for (int i = 0; i < committedArray.size(); i++) { try { final String oneCom = committedArray.get(i); String userCom = usersJ.getString(oneCom); //String userCom = usersJ.getString(oneCom.replace("[", "").replace("]", "")); //if(oneCom.replace("[","").replace("]","").equals(loggedUser)) if (oneCom.equals(loggedUser)) committed = Integer.parseInt(userCom); int end = pos + oneCom.length(); ClickableSpan clickable = new ClickableSpan() { @Override public void onClick(View widget) { context.showProfile(oneCom); } }; span.setSpan(clickable, pos, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new UnderlineSpan() { public void updateDrawState(TextPaint tp) { tp.setUnderlineText(false); } }, pos, end, 0); String color = Utils.makeRedGreen(Integer.parseInt(userCom), true); span.setSpan(new ForegroundColorSpan(Color.parseColor("#FF" + color)), pos, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); pos += oneCom.length() + 2; } catch (JSONException e) { e.printStackTrace(); } } usersV.setText(span); usersV.setMovementMethod(new LinkMovementMethod()); if (loggedUser != null && loggedUser.length() > 0) { LinearLayout bl = (LinearLayout) rowView.findViewById(R.id.commit_buttons); if (!usersJ.has(loggedUser)) { Button commitB = new Button(context); commitB.setId(R.id.commit_button); commitB.setText(R.string.commit); commitB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("commitform_" + cid, nvp, true); } }); bl.addView(commitB); } else { Button commitB = new Button(context); commitB.setId(R.id.uncommit_button); commitB.setText(R.string.uncommit); commitB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("uncommitform_" + cid, nvp, true); } }); bl.addView(commitB); } if (loggedUser.equals(p.getString("creator")) || context.isAdmin) { Button commitB2 = new Button(context); commitB2.setId(R.id.edit_commit_button); commitB2.setText(R.string.edit); commitB2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(context, ActivityCommit.class); i.putExtra("commitment", p.toString()); context.startActivity(i); } }); bl.addView(commitB2); Button commitB3 = new Button(context); commitB3.setId(R.id.uncommit_button); commitB3.setText(R.string.delete); commitB3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("delcommitform_" + cid, nvp, true); } }); bl.addView(commitB3); } } if (committed > -1) { int color = Color.parseColor("#FF" + Utils.makeRedGreen(committed, false)); rowView.setBackgroundColor(color); } if (committed != -1) { youV.setText(String.format(context.getString(R.string.you_commit_x), committed)); youV.setVisibility(View.VISIBLE); } } catch (Exception e) { e.printStackTrace(); } return rowView; }
From source file:org.de.jmg.learn.SettingsActivity.java
public void init(boolean blnRestart) throws Exception { if (_Intent == null || _main == null || SettingsView == null || _blnInitialized) { return;//from ww w . j a va 2 s. c o m } try { //lib.ShowToast(_main, "Settings Start"); RelativeLayout layout = (RelativeLayout) findViewById(R.id.layoutSettings); // id fetch from xml ShapeDrawable rectShapeDrawable = new ShapeDrawable(); // pre defined class int pxPadding = lib.dpToPx(10); rectShapeDrawable.setPadding(pxPadding, pxPadding, pxPadding, pxPadding * ((lib.NookSimpleTouch()) ? 2 : 1)); Paint paint = rectShapeDrawable.getPaint(); paint.setColor(Color.BLACK); paint.setStyle(Style.STROKE); paint.setStrokeWidth(5); // you can change the value of 5 lib.setBg(layout, rectShapeDrawable); mainView = _main.findViewById(Window.ID_ANDROID_CONTENT); //Thread.setDefaultUncaughtExceptionHandler(ErrorHandler); prefs = _main.getPreferences(Context.MODE_PRIVATE); TextView txtSettings = (TextView) findViewById(R.id.txtSettings); SpannableString Settings = new SpannableString(txtSettings.getText()); Settings.setSpan(new UnderlineSpan(), 0, Settings.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); txtSettings.setText(Settings); initCheckBoxes(); initSpinners(blnRestart); initButtons(); initHelp(); edDataDir = (EditText) findViewById(R.id.edDataDir); edDataDir.setSingleLine(true); edDataDir.setText(_main.JMGDataDirectory); edDataDir.setImeOptions(EditorInfo.IME_ACTION_DONE); edDataDir.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { String strDataDir = edDataDir.getText().toString(); File fileSelected = new File(strDataDir); if (fileSelected.isDirectory() && fileSelected.exists()) { _main.setJMGDataDirectory(fileSelected.getPath()); edDataDir.setText(_main.JMGDataDirectory); Editor editor = prefs.edit(); editor.putString("JMGDataDirectory", fileSelected.getPath()); editor.commit(); } } return true; } }); edDataDir.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { ShowDataDirDialog(); return true; } }); if (!(lib.NookSimpleTouch()) && !_main.isSmallDevice) { SettingsView.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // Ensure you call it only once : lib.removeLayoutListener(SettingsView.getViewTreeObserver(), this); // Here you can get the size :) resize(0); //lib.ShowToast(_main, "Resize End"); } }); } else { //resize(1.8f); mScale = 1.0f; } _blnInitialized = true; } catch (Exception ex) { lib.ShowException(_main, ex); } }