Example usage for android.text SpannableString setSpan

List of usage examples for android.text SpannableString setSpan

Introduction

In this page you can find the example usage for android.text SpannableString setSpan.

Prototype

public void setSpan(Object what, int start, int end, int flags) 

Source Link

Usage

From source file:com.kyakujin.android.tagnotepad.ui.NoteListFragment.java

/**
 * About//w  ww . j  a  va2s  .  c o  m
 */
private void showAboutDialog() {
    PackageManager pm = getActivity().getPackageManager();
    String packageName = getActivity().getPackageName();
    String versionName;
    try {
        PackageInfo info = pm.getPackageInfo(packageName, 0);
        versionName = info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        versionName = "N/A";
    }

    SpannableStringBuilder aboutBody = new SpannableStringBuilder();

    SpannableString mailAddress = new SpannableString(getString(R.string.mailto));
    mailAddress.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SENDTO);
            intent.setData(Uri.parse(getString(R.string.description_mailto)));
            intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.description_mail_subject));
            startActivity(intent);
        }
    }, 0, mailAddress.length(), 0);

    aboutBody.append(Html.fromHtml(getString(R.string.about_body, versionName)));
    aboutBody.append("\n");
    aboutBody.append(mailAddress);

    LayoutInflater layoutInflater = (LayoutInflater) getActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    TextView aboutBodyView = (TextView) layoutInflater.inflate(R.layout.fragment_about_dialog, null);
    aboutBodyView.setText(aboutBody);
    aboutBodyView.setMovementMethod(LinkMovementMethod.getInstance());

    AlertDialog dlg = new AlertDialog.Builder(getActivity()).setTitle(R.string.alert_title_about)
            .setView(aboutBodyView).setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();
    dlg.show();
}

From source file:com.easemob.chatuidemo.activity.GroupPickContactsActivity.java

private void setSelectedNumber(int number) {
    String numberStr = number + "";
    SpannableString spannableString = new SpannableString(
            String.format(getString(R.string.filter_selected), number));
    spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color_blue)), 2,
            2 + numberStr.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    selectedNumberTextView.setText(spannableString);
}

From source file:com.example.lowviscam.GalleryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    if (isLight == true) {
        inflater.inflate(R.menu.gallery, menu);
    } else {/*  www . ja v a2 s .  c  om*/
        inflater.inflate(R.menu.gallery_dark, menu);
    }

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            search(query);
            // First image toast
            String firstResult;
            if (numSearchResults == 0) {
                firstResult = "No results found for  " + query + ".";
            } else {
                firstResult = "The first image result is titled " + tagList[0];
            }

            SpannableString s = new SpannableString(firstResult);
            s.setSpan(new TypefaceSpan(GalleryActivity.this, "APHont-Regular_q15c.otf"), 0, s.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            Toast.makeText(GalleryActivity.this, s, Toast.LENGTH_LONG).show();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (TextUtils.isEmpty(newText)) {
                search("");
            }

            return true;
        }

        public void search(String query) {
            // hide keyboard
            InputMethodManager inputManager = (InputMethodManager) GalleryActivity.this
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(GalleryActivity.this.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            // Fetch the {@link LayoutInflater} service so that new views can be created
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            // Find the {@link GridView} that was already defined in the XML layout
            GridView gridView = (GridView) findViewById(R.id.grid);
            try {
                gridView.setAdapter(new CouponAdapter(inflater, createSearchedCoupons(query)));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    });

    return true;
    //return super.onCreateOptionsMenu(menu);
}

From source file:eu.veldsoft.adsbobball.ActivityStateEnum.java

protected void update(final Canvas canvas, final GameState currGameState, long frameCounter) {

    final Player currPlayer = currGameState.getPlayer(playerId);

    if ((gameView != null)) {
        gameView.draw(canvas, currGameState);
    }//  w  w w .  jav  a 2s .c o  m

    if (frameCounter % displayLoop.ITERATIONS_PER_STATUSUPDATE == 0) {

        SpannableStringBuilder timeLeftStr = SpannableStringBuilder
                .valueOf(getString(R.string.timeLeftLabel, gameManager.timeLeft() / 10));

        SpannableStringBuilder livesStr = formatPerPlayer(getString(R.string.livesLabel), new playstat() {
            @Override
            public int call(Player p) {
                return p.getLives();
            }
        });
        SpannableStringBuilder scoreStr = formatPerPlayer(getString(R.string.scoreLabel), new playstat() {
            @Override
            public int call(Player p) {
                return p.getScore();
            }
        });

        SpannableStringBuilder clearedStr = formatPerPlayer(getString(R.string.areaClearedLabel),
                new playstat() {
                    @Override
                    public int call(Player p) {
                        Grid grid = currGameState.getGrid();
                        if (grid != null)
                            return currGameState.getGrid().getPercentComplete(p.getPlayerId());
                        else
                            return 0;
                    }
                });

        // display fps
        if (secretHandshake >= 3) {

            float fps = displayLoop.getFPS();
            int color = (fps < NUMBER_OF_FRAMES_PER_SECOND * 0.98f ? Color.RED : Color.GREEN);
            SpannableString s = new SpannableString(String.format(" FPS: %2.1f", fps));

            s.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            timeLeftStr.append(s);

            color = (gameManager.getUPS() < gameManager.NUMBER_OF_UPDATES_PER_SECOND * 0.98f ? Color.RED
                    : Color.GREEN);
            s = new SpannableString(String.format(" UPS: %3.1f", gameManager.getUPS()));

            s.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            timeLeftStr.append(s);
        }

        statusTopleft.setText(timeLeftStr);
        statusTopright.setText(livesStr);
        statusBotleft.setText(scoreStr);
        statusBotright.setText(clearedStr);

    }
    if (gameManager.hasWonLevel()) {
        showWonScreen();
    } else if (gameManager.isGameLost()) {
        if ((numPlayers == 1) && scores.isTopScore(currPlayer.getScore())) {
            promptUsername();
        }
        showDeadScreen();
    }

}

From source file:com.example.lowviscam.GalleryActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    isLight = getIntent().getExtras().getBoolean("isLight");
    if (isLight == false) {
        this.setTheme(R.style.AppBaseThemeDark);
    } else {//from   w w  w. jav a  2  s  . c om
        this.setTheme(R.style.AppBaseTheme);
    }
    setContentView(R.layout.activity_gallery);

    // Retrieve APHont font and apply it
    mFace = Typeface.createFromAsset(getAssets(), "fonts/APHont-Regular_q15c.otf");
    SpannableString s = new SpannableString("Image Gallery");
    s.setSpan(new TypefaceSpan(this, "APHont-Bold_q15c.otf"), 0, s.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    // Update the action bar title with the TypefaceSpan instance
    ActionBar actionBar = getActionBar();
    actionBar.setTitle(s);

    actionBar.setDisplayHomeAsUpEnabled(true);

    // Fetch the {@link LayoutInflater} service so that new views can be created
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // Find the {@link GridView} that was already defined in the XML layout
    GridView gridView = (GridView) findViewById(R.id.grid);

    // Initialize the adapter with all the coupons. Set the adapter on the {@link GridView}.
    try {
        gridView.setAdapter(new CouponAdapter(inflater, createAllCoupons()));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // Set a click listener for each picture in the grid
    gridView.setOnItemClickListener(this);
    gridView.setOnTouchListener(new OnSwipeTouchListener() {

        public void onSwipeTop() {
            //Toast.makeText(GalleryActivity.this, "top", Toast.LENGTH_SHORT).show();
        }

        public void onSwipeRight() {
            //Toast.makeText(GalleryActivity.this, "right", Toast.LENGTH_SHORT).show();
        }

        public void onSwipeLeft() {
            //Toast.makeText(GalleryActivity.this, "left", Toast.LENGTH_SHORT).show();
        }

        public void onSwipeBottom() {
            //Toast.makeText(GalleryActivity.this, "bottom", Toast.LENGTH_SHORT).show();
        }

    });
    gridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            // Find coupon that was clicked based off of position in adapter
            Coupon coupon = (Coupon) parent.getItemAtPosition(position);
            //Get absolutepath of image for adding.
            File list[] = mediaStorageDir.listFiles();
            File tmpFile = list[list.length - position - 1];
            String photoUri = coupon.mImageUri.toString();
            try {
                photoUri = MediaStore.Images.Media.insertImage(getContentResolver(), tmpFile.getAbsolutePath(),
                        null, null);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // Create share intent
            Intent shareIntent = ShareCompat.IntentBuilder.from(GalleryActivity.this).setText(coupon.mTitle)
                    .setType("image/jpeg").setStream(Uri.parse(photoUri))
                    .setChooserTitle(getString(R.string.share_using)).createChooserIntent();
            startActivity(shareIntent);

            return true;
        }
    });

}

From source file:com.pax.pay.trans.action.activity.InputTransData2Activity.java

private void setEditText_date(EditText editText) {
    SpannableString ss = new SpannableString(getString(R.string.prompt_date_default2));
    AbsoluteSizeSpan ass = new AbsoluteSizeSpan(getResources().getDimensionPixelOffset(R.dimen.font_size_large),
            false);//from w w w.  j  a  v  a  2  s .  c o  m
    ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    editText.setHint(new SpannedString(ss)); // ??,?
    editText.setHintTextColor(getResources().getColor(R.color.textEdit_hint));
    editText.setInputType(InputType.TYPE_CLASS_NUMBER);
    editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(4) });
}

From source file:com.maxleapmobile.gitmaster.ui.fragment.RecommendFragment.java

private void initUI(View view) {
    actionArea = (LinearLayout) view.findViewById(R.id.recommend_action_area);
    starProgressBar = (ProgressBar) view.findViewById(R.id.recommend_star_progressbar);
    starText = (TextView) view.findViewById(R.id.recommend_star);
    starText.setOnClickListener(this);
    view.findViewById(R.id.recommend_fork).setOnClickListener(this);
    skipBtn = view.findViewById(R.id.recommend_skip);
    skipBtn.setOnClickListener(this);
    mProgressBar = (ProgressBar) view.findViewById(R.id.repo_progressbar);
    TextView notice2 = (TextView) view.findViewById(R.id.recommend_notice2);
    SpannableString notice2SS = new SpannableString(mContext.getString(R.string.recommend_notice2_part1) + " "
            + mContext.getString(R.string.recommend_notice2_part2));
    notice2SS.setSpan(new CustomClickableSpan(), 0,
            mContext.getString(R.string.recommend_notice2_part1).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    notice2.setText(notice2SS);//from  www. j a v a2  s.c om
    notice2.setOnClickListener(this);
    notice3 = (TextView) view.findViewById(R.id.recommend_notice3);
    final SpannableString notice3SS = new SpannableString(mContext.getString(R.string.recommend_notice3_part1)
            + " " + mContext.getString(R.string.recommend_notice3_part2));
    notice3SS.setSpan(new CustomClickableSpan(), mContext.getString(R.string.recommend_notice3_part1).length(),
            notice3SS.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    notice3.setText(notice3SS);
    notice3.setOnClickListener(this);

    mWebView = (ProgressWebView) view.findViewById(R.id.recommend_webview);
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            mProgressBar.setVisibility(View.GONE);
        }
    });

    mEmptyView = (LinearLayout) view.findViewById(R.id.recommend_empty);
    mEmptyView.setVisibility(View.GONE);
    if (mParmasMap == null) {
        mParmasMap = new HashMap();
        mParmasMap.put("userid", username);
        mParmasMap.put("page", page);
        mParmasMap.put("per_page", PER_PAGE);
    }
}

From source file:com.ubercab.client.feature.notification.handler.TripNotificationHandler.java

private NotificationCompat.InboxStyle buildStyleInbox(NotificationCompat.Builder paramBuilder,
          TripNotificationData paramTripNotificationData, String paramString) {
      NotificationCompat.InboxStyle localInboxStyle = new NotificationCompat.InboxStyle(paramBuilder)
              .setSummaryText(paramString);
      Iterator localIterator = paramTripNotificationData.getFareSplitClients().iterator();
      while (localIterator.hasNext()) {
          TripNotificationData.FareSplitClient localFareSplitClient = (TripNotificationData.FareSplitClient) localIterator
                  .next();//from   www.  j a v  a 2  s  . com
          SpannableString localSpannableString = new SpannableString(localFareSplitClient.getName());
          localSpannableString.setSpan(new StyleSpan(1), 0, localSpannableString.length(), 33);
          SpannableStringBuilder localSpannableStringBuilder = new SpannableStringBuilder();
          localSpannableStringBuilder.append(localSpannableString);
          localSpannableStringBuilder.append(" ");
          localSpannableStringBuilder.append(localFareSplitClient.getDisplayStatus(getContext()));
          localInboxStyle.addLine(localSpannableStringBuilder);
      }
      return localInboxStyle;
  }

From source file:uk.co.threeonefour.android.snowball.activities.game.GameActivity.java

@Override
public void processCommand(String command) {

    if (!initialised) {
        return;/*from   ww  w  .  ja va2s.co m*/
    }

    SpannableString styledCommand = new SpannableString(command);
    styledCommand.setSpan(new StyleSpan(Typeface.BOLD), 0, styledCommand.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    textView.append(styledCommand);
    textView.append("\n");

    lastCommand = command;
    /* pre: intercept some commands like RESTORE */
    boolean continueExecute = true;
    if ("restore".equalsIgnoreCase(command)) {
        loadGame();
        continueExecute = false;
    }

    if (continueExecute) {
        /* execute command */
        level9.execute(command);
        String text = level9.getText().trim();

        /* post: intercept some commands */

        processOutput(text);
    }
}

From source file:com.example.lowviscam.GalleryActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.action_search:

        return true;
    case R.id.action_about:
        // 1. Instantiate an AlertDialog.Builder with its constructor
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        // 2. Chain together various setter methods to set the dialog characteristics
        String aboutString = getResources().getString(R.string.dialog_message);
        String titleString = getResources().getString(R.string.dialog_title);
        SpannableString sa = new SpannableString(aboutString);
        SpannableString st = new SpannableString(titleString);
        sa.setSpan(new TypefaceSpan(this, "APHont-Regular_q15c.otf"), 0, sa.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        st.setSpan(new TypefaceSpan(this, "APHont-Bold_q15c.otf"), 0, st.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        builder.setMessage(sa).setTitle(st).setPositiveButton(R.string.ok,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // User clicked OK button
                    }/*from  w w w. j  a va 2  s  .  co  m*/
                });
        ;

        // 3. Get the AlertDialog from create()
        AlertDialog dialog = builder.create();
        dialog.show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}