Example usage for android.text.style UnderlineSpan UnderlineSpan

List of usage examples for android.text.style UnderlineSpan UnderlineSpan

Introduction

In this page you can find the example usage for android.text.style UnderlineSpan UnderlineSpan.

Prototype

public UnderlineSpan() 

Source Link

Document

Creates an UnderlineSpan .

Usage

From source file:com.senior.fragments.HomeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.i("HomeFrag", "View Created");

    view = inflater.inflate(R.layout.home_fragment, container, false);

    titletext = (TextView) view.findViewById(R.id.calenderevents);

    SpannableString NewTitle = new SpannableString("Calendar Of Events");

    NewTitle.setSpan(new UnderlineSpan(), 0, NewTitle.length(), 0);

    titletext.setText(NewTitle);//from   w  w w . j  a v a  2s  .  com

    mListView = (ListView) view.findViewById(android.R.id.list);

    reloadButton = (Button) view.findViewById(R.id.refresh);
    reloadButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            getArticles();
        }

    });

    progress = (ProgressBar) view.findViewById(R.id.progress);

    return view;
}

From source file:com.handpoint.headstart.client.ui.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    HeadstartService.removeProperty("last_activity");
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    long elapsedTime = SystemClock.elapsedRealtime();
    long lastAttempt = getLastAttempt();
    if (elapsedTime > lastAttempt && lastAttempt > 0 && lastAttempt + ATTEMPT_DELAY > elapsedTime) {
        long timeToWait = ATTEMPT_DELAY - (elapsedTime - lastAttempt);
        Toast.makeText(this, getString(R.string.warn_wait_message, formatTime(timeToWait)), Toast.LENGTH_LONG)
                .show();/* w ww  .j a  va 2 s. c  om*/
        finish();
        return;
    }
    setLastAttempt(0);
    setContentView(R.layout.login);

    Button loginButton = (Button) findViewById(R.id.login_button);
    loginButton.setOnClickListener(this);

    TextView forgotLink = (TextView) findViewById(R.id.forgot_password_link);
    SpannableString content = new SpannableString(getString(R.string.forgot_password_link_label));
    content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
    forgotLink.setText(content);
    forgotLink.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            DialogFragment newFragment = new ForgotPasscodeDialog();
            newFragment.show(getSupportFragmentManager(), "forgot_passcode");
        }
    });
}

From source file:net.net76.lifeiq.TaskiQ.RegisterActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    inputFirstname = (EditText) findViewById(R.id.firstname);
    inputSurname = (EditText) findViewById(R.id.surname);
    inputUserID = (EditText) findViewById(R.id.userID);
    inputEmail = (EditText) findViewById(R.id.email);
    //1 inputPassword = (EditText) findViewById(R.id.password);
    //1inputPassword2 = (EditText) findViewById(R.id.password2);
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    EULA = (TextView) findViewById(R.id.EULA);

    SpannableString content = new SpannableString(EULA.getText().toString());
    content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
    EULA.setText(content);//  w ww .j  a  v a2  s  .c o  m
    EULA.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PackageInfo versionInfo = getPackageInfo();
            // EULA title
            String title = RegisterActivity.this.getString(R.string.app_name) + " v " + versionInfo.versionName;

            // EULA text
            String message = RegisterActivity.this.getString(R.string.eula_string);

            android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(RegisterActivity.this)
                    .setTitle(title).setMessage(message).setCancelable(false)
                    .setPositiveButton(R.string.accept, new Dialog.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                            EULAAccept = true;
                            // Close dialog
                            dialogInterface.dismiss();

                        }
                    }).setNegativeButton(android.R.string.cancel, new Dialog.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            EULAAccept = false;

                        }

                    });
            builder.create().show();
        }

    });

    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.Country_array,
            android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    spinner.setAdapter(adapter);

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Log.v("item", (String) parent.getItemAtPosition(position));
            countryString = (String) parent.getItemAtPosition(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // TODO Auto-generated method stub
        }
    });

    btnRegister = (Button) findViewById(R.id.btnRegister);
    btnLinkToLogin = (Button) findViewById(R.id.btnLinkToLoginScreen);

    // Progress dialog
    pDialog = new ProgressDialog(this);
    //pDialog.setCancelable(false);
    pDialog.setCanceledOnTouchOutside(false);

    // Session manager
    session = new SessionManager(getApplicationContext());

    // SQLite database handler
    db = new SQLiteHandler(getApplicationContext());

    // Check if user is already logged in or not
    if (session.isLoggedIn()) {
        // User is already logged in. Take him to main activity
        Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }

    // Register Button Click event
    btnRegister.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            String Firstname = inputFirstname.getText().toString();
            String Surname = inputSurname.getText().toString();
            String UserID = inputUserID.getText().toString();
            String email = inputEmail.getText().toString();
            //1    String password = inputPassword.getText().toString();
            //1   String password2 = inputPassword2.getText().toString();

            if (!Firstname.isEmpty() && !Surname.isEmpty() && !email.isEmpty() && !UserID.isEmpty()) {

                if (isEmailValid(email)) {

                    if (!UserID.contains(" ")) {

                        if (!countryString.equals("Select country of residence")) {
                            if (EULAAccept.equals(true)) {

                                if (isNetworkAvaliable(getApplicationContext())) {
                                    registerUser(Firstname, Surname, UserID, email, countryString);
                                } else {
                                    Toast.makeText(getApplicationContext(),
                                            "Currently there is no network. Please try later.",
                                            Toast.LENGTH_SHORT).show();
                                }
                            } else {
                                Toast.makeText(getApplicationContext(),
                                        "Please read and accept End User License Agreement.",
                                        Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            Toast.makeText(getApplicationContext(), "Please select a country of residence.",
                                    Toast.LENGTH_SHORT).show();
                        }

                    } else {
                        Toast.makeText(getApplicationContext(), "In the User ID no spaces are allowed.",
                                Toast.LENGTH_SHORT).show();
                    }

                } else {
                    Toast.makeText(getApplicationContext(), "Please enter a valid email address!",
                            Toast.LENGTH_SHORT).show();
                }

            } else {
                Toast.makeText(getApplicationContext(), "Please enter your details!", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

    // Link to Login Screen
    btnLinkToLogin.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), LoginActivity.class);
            startActivity(i);
            finish();
        }
    });

}

From source file:com.doomy.decode.ResultDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater mLayoutInflater = LayoutInflater.from(getActivity());
    View mView = mLayoutInflater.inflate(R.layout.view_result, null);

    TextView mTextViewFormat = (TextView) mView.findViewById(R.id.textViewFormat);
    TextView mTextViewContent = (TextView) mView.findViewById(R.id.textViewContent);

    if (mTitle.equals("EAN 13") && mMessage.startsWith("978")) {
        GetResponseTask mGetResponseTask = new GetResponseTask();
        mGetResponseTask.execute(mMessage);

        try {/*from w  w w  . j a  v a2 s  . co  m*/
            if (mGetResponseTask.get().equals("")) {
                mTitle = "ISBN";
                mTextViewContent.setText(mMessage);
            } else {
                mTitle = "ISBN";
                mMessage = mGetResponseTask.get();
                SpannableString mSpan = new SpannableString(mMessage);
                mSpan.setSpan(new UnderlineSpan(), 0, mMessage.length(), 0);
                mTextViewContent.setText(mSpan);
                mTextViewContent.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        createURLIntent(makeURLSearch(mMessage));
                    }
                });
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    } else if (mTitle.equals("ISBN")) {
        if (!mMessage.startsWith("978")) {
            SpannableString mSpan = new SpannableString(mMessage);
            mSpan.setSpan(new UnderlineSpan(), 0, mMessage.length(), 0);
            mTextViewContent.setText(mSpan);
            mTextViewContent.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    createURLIntent(makeURLSearch(mMessage));
                }
            });
        } else {
            mTextViewContent.setText(mMessage);
        }
    } else if (mMessage.startsWith("www") || mMessage.startsWith("http://")
            || mMessage.startsWith("https://")) {
        SpannableString mSpan = new SpannableString(mMessage);
        mSpan.setSpan(new UnderlineSpan(), 0, mMessage.length(), 0);
        mTextViewContent.setText(mSpan);
        mTextViewContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                createURLIntent(mMessage);
            }
        });
    } else {
        mTextViewContent.setText(mMessage);
    }

    if (mKey) {
        SimpleDateFormat mDateFormat = new SimpleDateFormat("dd/MM/yyyy-HH:mm");
        String mDate = mDateFormat.format(new Date());
        Scan mScan = new Scan(mTitle, mMessage, mDate);
        mDB.addOne(mScan);
    }

    mTextViewFormat.setText(mTitle);

    AlertDialog.Builder mAlertBuilder = new AlertDialog.Builder(getActivity(), Utils.setThemeDialog());

    mAlertBuilder.setTitle(getString(R.string.info)).setView(mView).setPositiveButton(getString(R.string.okay),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    if (mListener != null) {
                        mListener.onDialogPositiveClick(ResultDialogFragment.this);
                    }
                }
            });

    return mAlertBuilder.create();
}

From source file:com.github.jobs.ui.fragment.JobDetailsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Bundle arguments = getArguments();/*from   w  w  w  .  ja  v a  2s  . c  o  m*/
    String jobId = arguments.getString(KEY_JOB_ID);
    mJob = new Job();
    mJob.setId(jobId);
    mJob = adapter.findFirst(mJob);
    if (mJob == null) {
        mJob = new Job();
        Toast.makeText(getActivity(), R.string.error_getting_job_info, Toast.LENGTH_LONG).show();
    }
    setHasOptionsMenu(true);

    TextView title = (TextView) getView().findViewById(R.id.title);
    title.setText(StringUtils.trim(mJob.getTitle()));

    TextView description = (TextView) getView().findViewById(R.id.description);
    String jobDescription = mJob.getDescription();
    if (jobDescription != null) {
        description.setText(Html.fromHtml(jobDescription));
        description.setMovementMethod(LinkMovementMethod.getInstance());
    }

    TextView company = (TextView) getView().findViewById(R.id.company);
    company.setText(mJob.getCompany());

    TextView companyUrl = (TextView) getView().findViewById(R.id.company_url);
    if (mJob.getCompanyUrl() == null) {
        companyUrl.setVisibility(View.GONE);
    } else {
        SpannableString content = new SpannableString(mJob.getCompanyUrl());
        content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
        companyUrl.setText(content);
        companyUrl.setOnClickListener(this);
        companyUrl.setVisibility(View.VISIBLE);
    }

    TextView companyLocation = (TextView) getView().findViewById(R.id.company_location);
    if (mJob.getLocation() == null) {
        companyLocation.setVisibility(View.GONE);
    } else {
        companyLocation.setText(mJob.getLocation());
        companyLocation.setVisibility(View.VISIBLE);
    }

    if (!JobDetailsActivity.FULL_TIME.equalsIgnoreCase(mJob.getType())) {
        getView().findViewById(R.id.full_time).setVisibility(View.INVISIBLE);
    }

    mBackground = (ImageView) getView().findViewById(R.id.job_details_background);
    setLogoBackground();
}

From source file:at.jclehner.rxdroid.SplashScreenActivity.java

@TargetApi(11)
@Override/*from www.j  a  v a  2s. c om*/
protected void onCreate(Bundle savedInstanceState) {
    Settings.init();

    setTheme(Theme.get());
    setContentView(R.layout.loader);

    mDate = Settings.getActiveDate();

    final SpannableString dateString = new SpannableString(DateTime.toNativeDate(mDate));

    Util.applyStyle(dateString, new RelativeSizeSpan(0.75f));
    Util.applyStyle(dateString, new UnderlineSpan());

    getSupportActionBar().setSubtitle(dateString);

    try {
        Class.forName(com.michaelnovakjr.numberpicker.NumberPicker.class.getName());
    } catch (ClassNotFoundException e) {
        throw new WrappedCheckedException("NumberPicker library is missing", e);
    }

    super.onCreate(savedInstanceState);
}

From source file:info.guardianproject.otr.app.im.app.ContactView.java

public void bind(Cursor cursor, String underLineText, boolean showChatMsg, boolean scrolling) {

    mHolder = (ViewHolder) getTag();/*from w w w  .java 2 s . c o m*/

    long providerId = cursor.getLong(COLUMN_CONTACT_PROVIDER);
    String address = cursor.getString(COLUMN_CONTACT_USERNAME);
    String nickname = cursor.getString(COLUMN_CONTACT_NICKNAME);
    int type = cursor.getInt(COLUMN_CONTACT_TYPE);
    String statusText = cursor.getString(COLUMN_CONTACT_CUSTOM_STATUS);
    String lastMsg = cursor.getString(COLUMN_LAST_MESSAGE);

    int presence = cursor.getInt(COLUMN_CONTACT_PRESENCE_STATUS);

    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);

            mHolder.mLine1.setText(str);

        } else
            mHolder.mLine1.setText(nickname);

    } else
        mHolder.mLine1.setText(nickname);

    if (mHolder.mAvatar != null) {
        if (Imps.Contacts.TYPE_GROUP == type) {
            mHolder.mAvatar.setImageResource(R.drawable.group_chat);

        } else {

            Drawable avatar = DatabaseUtils.getAvatarFromCursor(cursor, COLUMN_AVATAR_DATA,
                    ImApp.DEFAULT_AVATAR_WIDTH, ImApp.DEFAULT_AVATAR_HEIGHT);

            if (avatar != null)
                mHolder.mAvatar.setImageDrawable(avatar);
            else
                mHolder.mAvatar.setImageDrawable(mAvatarUnknown);
        }
    }

    if (showChatMsg && lastMsg != null) {

        if (mHolder.mAvatar != null) {
            setBackgroundResource(R.color.holo_blue_bright);
            mHolder.mLine1.setBackgroundColor(getResources().getColor(R.color.holo_blue_bright));
            mHolder.mLine1.setTextColor(Color.WHITE);
        } else if (mHolder.mStatusBlock != null) {
            mHolder.mStatusBlock.setBackgroundColor(getResources().getColor(R.color.holo_blue_bright));

        }

        if (mHolder.mLine2 != null)
            mHolder.mLine2.setText(android.text.Html.fromHtml(lastMsg).toString());

    } else {
        if (mHolder.mLine2 != null) {

            if (statusText == null || statusText.length() == 0) {

                if (Imps.Contacts.TYPE_GROUP == type) {
                    statusText = mContext.getString(R.string.menu_new_group_chat);
                } else {
                    ImApp app = ((ImApp) ((Activity) mContext).getApplication());
                    BrandingResources brandingRes = app.getBrandingResource(providerId);
                    statusText = brandingRes.getString(PresenceUtils.getStatusStringRes(presence));
                }
            }

            mHolder.mLine2.setText(statusText);

        }

        if (presence == Imps.Presence.AVAILABLE) {
            if (mHolder.mAvatar != null) {
                setBackgroundColor(getResources().getColor(R.color.holo_green_light));
                mHolder.mLine1.setBackgroundColor(getResources().getColor(R.color.holo_green_dark));
                mHolder.mLine1.setTextColor(getResources().getColor(R.color.contact_status_fg_light));
            } else if (mHolder.mStatusBlock != null) {
                mHolder.mStatusBlock.setBackgroundColor(getResources().getColor(R.color.holo_green_light));

            }

        } else if (presence == Imps.Presence.AWAY || presence == Imps.Presence.IDLE) {
            if (mHolder.mAvatar != null) {
                setBackgroundColor(getResources().getColor(R.color.holo_orange_light));
                mHolder.mLine1.setBackgroundColor(getResources().getColor(R.color.holo_orange_dark));
                mHolder.mLine1.setTextColor(getResources().getColor(R.color.contact_status_fg_light));
            } else if (mHolder.mStatusBlock != null) {
                mHolder.mStatusBlock.setBackgroundColor(getResources().getColor(R.color.holo_orange_light));

            }

        } else if (presence == Imps.Presence.DO_NOT_DISTURB) {
            if (mHolder.mAvatar != null) {
                setBackgroundColor(getResources().getColor(R.color.holo_red_light));
                mHolder.mLine1.setBackgroundColor(getResources().getColor(R.color.holo_red_dark));
                mHolder.mLine1.setTextColor(getResources().getColor(R.color.contact_status_fg_light));
            } else if (mHolder.mStatusBlock != null) {
                mHolder.mStatusBlock.setBackgroundColor(getResources().getColor(R.color.holo_red_light));

            }
        } else {
            if (mHolder.mAvatar != null) {
                setBackgroundColor(Color.LTGRAY);
                mHolder.mLine1.setBackgroundColor(Color.LTGRAY);
            } else if (mHolder.mStatusBlock != null) {
                mHolder.mStatusBlock.setBackgroundColor(Color.LTGRAY);

            }
        }

    }

}

From source file:cm.aptoide.pt.webservices.login.Login.java

private void drawLoginForm() {
    setContentView(R.layout.form_login);
    username_box = (EditText) findViewById(R.id.username);
    password_box = (EditText) findViewById(R.id.password);
    checkShowPass = (CheckBox) findViewById(R.id.show_login_passwd);
    checkShowPass.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                password_box.setTransformationMethod(null);
            } else {
                password_box.setTransformationMethod(new PasswordTransformationMethod());
            }/*from ww w .  java 2  s  . c o m*/
        }
    });
    checkShowPass.setEnabled(true);

    createUser = (Button) findViewById(R.id.new_to_aptoide);
    SpannableString newUserString = new SpannableString(getString(R.string.new_to_aptoide));
    newUserString.setSpan(new UnderlineSpan(), 0, newUserString.length(), 0);
    createUser.setText(newUserString);

    forgot_password = (TextView) findViewById(R.id.forgot_password);
    SpannableString forgetString = new SpannableString(getString(R.string.forgot_passwd));
    forgetString.setSpan(new UnderlineSpan(), 0, forgetString.length(), 0);
    forgot_password.setText(forgetString);
    forgot_password.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent passwordRecovery = new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://m.aptoide.com/account/password-recovery"));
            startActivity(passwordRecovery);
        }
    });
}

From source file:eu.faircode.netguard.AdapterAccess.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final int version = cursor.getInt(colVersion);
    final int protocol = cursor.getInt(colProtocol);
    final String daddr = cursor.getString(colDaddr);
    final int dport = cursor.getInt(colDPort);
    long time = cursor.getLong(colTime);
    int allowed = cursor.getInt(colAllowed);
    int block = cursor.getInt(colBlock);
    int count = cursor.getInt(colCount);
    long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent);
    long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived);
    int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections);

    // Get views/*  ww  w. j ava2  s.c o  m*/
    TextView tvTime = view.findViewById(R.id.tvTime);
    ImageView ivBlock = view.findViewById(R.id.ivBlock);
    final TextView tvDest = view.findViewById(R.id.tvDest);
    LinearLayout llTraffic = view.findViewById(R.id.llTraffic);
    TextView tvConnections = view.findViewById(R.id.tvConnections);
    TextView tvTraffic = view.findViewById(R.id.tvTraffic);

    // Set values
    tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time));
    if (block < 0)
        ivBlock.setImageDrawable(null);
    else {
        ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable());
            DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn);
        }
    }

    String dest = Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : "")
            + (count > 1 ? " ?" + count : "");
    SpannableString span = new SpannableString(dest);
    span.setSpan(new UnderlineSpan(), 0, dest.length(), 0);
    tvDest.setText(span);

    if (Util.isNumericAddress(daddr))
        new AsyncTask<String, Object, String>() {
            @Override
            protected void onPreExecute() {
                ViewCompat.setHasTransientState(tvDest, true);
            }

            @Override
            protected String doInBackground(String... args) {
                try {
                    return InetAddress.getByName(args[0]).getHostName();
                } catch (UnknownHostException ignored) {
                    return args[0];
                }
            }

            @Override
            protected void onPostExecute(String addr) {
                tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr
                        + (dport > 0 ? "/" + dport : ""));
                ViewCompat.setHasTransientState(tvDest, false);
            }
        }.execute(daddr);

    if (allowed < 0)
        tvDest.setTextColor(colorText);
    else if (allowed > 0)
        tvDest.setTextColor(colorOn);
    else
        tvDest.setTextColor(colorOff);

    llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE);
    if (connections > 0)
        tvConnections.setText(context.getString(R.string.msg_count, connections));

    if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024 * 1024f) : 0)));
    else if (sent > 1204 * 1024L || received > 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024f) : 0)));
    else
        tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0),
                (received > 0 ? received / 1024f : 0)));
}

From source file:com.liuwuping.sm.ui.repodetail.RepoDetailActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_repodetail);
    setSupportActionBar(toolbar);// ww w  .j a  va 2 s. c om
    ActionBar bar = getSupportActionBar();
    bar.setDisplayHomeAsUpEnabled(true);
    bar.setDisplayShowHomeEnabled(true);
    bar.setDisplayShowTitleEnabled(false);
    bar.setHomeButtonEnabled(true);

    Bundle bundle = getIntent().getExtras();
    repo = (Repo) bundle.get("repo");
    String[] names = repo.getFull_name().split("/");
    login = names[0];
    repoName = names[1];

    appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
        boolean isShow = false;
        int scrollRange = -1;

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if (scrollRange == -1) {
                scrollRange = appBarLayout.getTotalScrollRange();
            }
            if (scrollRange + verticalOffset == 0) {
                collapsingToolbarLayout.setTitle(repoName);
                isShow = true;
            } else if (isShow) {
                collapsingToolbarLayout.setTitle("");
                isShow = false;
            }

        }
    });

    repoNameTv.setText(repoName);
    SpannableString spannableString = new SpannableString(login);
    spannableString.setSpan(new UnderlineSpan(), 0, login.length(), 0);
    repoOwnerTv.setText(spannableString);
    starTv.setText(String.valueOf(repo.getStargazers_count()));
    forkTv.setText(String.valueOf(repo.getForks()));
    issueTv.setText(String.valueOf(repo.getOpen_issues()));

    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    SimpleDividerDecoration decoration = new SimpleDividerDecoration(this);
    recyclerView.addItemDecoration(decoration);
    recyclerView.setHasFixedSize(true);
    adapter = new TagAdapter();
    recyclerView.setAdapter(adapter);
    RecyclerItemClickSupport.addTo(recyclerView)
            .setOnItemClickListener(new RecyclerItemClickSupport.OnItemClickListener() {
                @Override
                public void onItemClicked(RecyclerView recyclerView, int position, View v) {
                    Tag tag = tagList.get(position);
                    repo.setTagId(tag.getId());
                    presenter.addRepoToTag(repo);

                }
            });

    presenter = new RepoDetailPresenter(this);
    presenter.getReadMeUrl(login, repoName);
    presenter.getAvatarUrl(login);
    presenter.isStar(login, repoName);
    presenter.loadTags();

    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            webViewProgressBar.setVisibility(View.INVISIBLE);
        }
    });

}