Example usage for android.widget TextView setShadowLayer

List of usage examples for android.widget TextView setShadowLayer

Introduction

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

Prototype

public void setShadowLayer(float radius, float dx, float dy, int color) 

Source Link

Document

Gives the text a shadow of the specified blur radius and color, the specified distance from its drawn position.

Usage

From source file:de.qabel.qabelbox.fragments.WelcomeDisclaimerFragment.java

private void setShader(TextView tv) {
    float dx = getResources().getDimension(R.dimen.welcome_shadow_dx);
    float dy = getResources().getDimension(R.dimen.welcome_shadow_dy);
    float radius = getResources().getDimension(R.dimen.welcome_shadow_radius);
    int col = getResources().getColor(R.color.welcome_shadow);
    tv.setShadowLayer(radius, dx, dy, col);
}

From source file:de.qabel.qabelbox.fragments.WelcomeDisclaimerFragment.java

private void setSmallShader(TextView tv) {
    float dx = getResources().getDimension(R.dimen.welcome_shadow_dx);
    float dy = getResources().getDimension(R.dimen.welcome_shadow_dy);
    float radius = getResources().getDimension(R.dimen.welcome_shadow_radius);
    int col = getResources().getColor(R.color.welcome_shadow);
    tv.setShadowLayer(radius, dx, dy, col);
}

From source file:info.tellmetime.DaydreamService.java

private void inflateMinutesIndicators() {
    FrameLayout minutesLayout = (FrameLayout) findViewById(R.id.minutes_indicators);
    minutesLayout.removeAllViews();//w w w  .  j  av  a2  s .  co m
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final boolean isLandscape = getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    inflater.inflate(isLandscape ? R.layout.minutes_land : R.layout.minutes_portrait, minutesLayout);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            isLandscape ? FrameLayout.LayoutParams.MATCH_PARENT : FrameLayout.LayoutParams.WRAP_CONTENT);
    if (!isLandscape) {
        layoutParams.addRule(RelativeLayout.BELOW, R.id.clock);
        layoutParams.topMargin = (int) -TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize / 3,
                getResources().getDisplayMetrics());
    }
    minutesLayout.setLayoutParams(layoutParams);

    Typeface mTypefaceBold = Typeface.createFromAsset(getAssets(), "Roboto-BoldCondensed.ttf");
    ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots);
    for (int i = 0; i < minutesDots.getChildCount(); i++) {
        TextView m = (TextView) minutesDots.getChildAt(i);

        m.setTypeface(mTypefaceBold);
        m.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize);
        m.setTextColor(mBacklightColor);
        m.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor);
    }
}

From source file:info.tellmetime.DaydreamService.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    setInteractive(true);/*from   w ww .j  a va  2s  .c  o  m*/

    setFullscreen(true);

    setContentView(R.layout.daydream);

    LinearLayout mClock = (LinearLayout) findViewById(R.id.clock);

    SharedPreferences settings = getSharedPreferences("PREFS", Context.MODE_PRIVATE);
    mHighlightColor = settings.getInt(TellmetimeActivity.HIGHLIGHT, Color.WHITE);
    mBacklightColor = settings.getInt(TellmetimeActivity.BACKLIGHT,
            getResources().getColor(R.color.backlight_light));
    mMinutesSize = settings.getInt(TellmetimeActivity.MINUTES_SIZE, 36);
    isNightMode = settings.getBoolean(TellmetimeActivity.NIGHTMODE, false);

    setScreenBright(!isNightMode);
    findViewById(R.id.overlay).setBackgroundColor(
            getResources().getColor(isNightMode ? R.color.night_mode_overlay : android.R.color.transparent));

    RelativeLayout mSurface = (RelativeLayout) findViewById(R.id.surface);
    mSurface.setBackgroundColor(
            settings.getInt(TellmetimeActivity.BACKGROUND, getResources().getColor(R.color.background)));
    switch (settings.getInt(TellmetimeActivity.BACKGROUND_MODE, TellmetimeActivity.MODE_BACKGROUND_SOLID)) {
    case TellmetimeActivity.MODE_BACKGROUND_WALLPAPER:
        ((ImageView) findViewById(R.id.background_image))
                .setImageDrawable(WallpaperManager.getInstance(this).getDrawable());
        break;

    case TellmetimeActivity.MODE_BACKGROUND_IMAGE:
        try {
            ((ImageView) findViewById(R.id.background_image)).setImageBitmap(BitmapFactory.decodeStream(
                    new FileInputStream(new File(getFilesDir(), TellmetimeActivity.IMAGE_FILE_NAME))));
        } catch (Exception ignored) {
            // Image is not set, set background color loaded from setting is visible.
        }

        break;
    }

    mShorterEdge = Math.min(getResources().getDisplayMetrics().widthPixels,
            getResources().getDisplayMetrics().heightPixels);
    mDensity = getResources().getDisplayMetrics().density;

    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT);
    lp.width = mShorterEdge;
    mClock.setLayoutParams(lp);

    Typeface mTypeface = Typeface.createFromAsset(getAssets(), "Roboto-BoldCondensed.ttf");
    final float mItemSize = mShorterEdge / mClock.getChildCount();
    final int mRowMargin = (int) -(mItemSize / 2.2);

    for (int i = 0; i < mClock.getChildCount(); i++) {
        LinearLayout row = (LinearLayout) mClock.getChildAt(i);

        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams();
        params.bottomMargin = mRowMargin;
        row.setLayoutParams(params);

        for (int j = 0; j < row.getChildCount(); j++) {
            TextView tv = (TextView) row.getChildAt(j);

            tv.setTypeface(mTypeface);
            tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemSize);
            tv.setTextColor(mBacklightColor);
            tv.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor);
        }
    }
    LinearLayout lastRow = (LinearLayout) mClock.getChildAt(mClock.getChildCount() - 1);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lastRow.getLayoutParams();
    params.bottomMargin = 0;
    lastRow.setLayoutParams(params);

    TextView twenty = (TextView) findViewById(R.id.twenty);
    params = (LinearLayout.LayoutParams) twenty.getLayoutParams();
    params.leftMargin = 0;
    twenty.setLayoutParams(params);

    inflateMinutesIndicators();
}

From source file:edu.rowan.app.carousel.CarouselFeature.java

private void setupView() {
    imageView.setId(1);//from  w w w  .  java  2 s .com
    RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT);
    imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    imageView.setLayoutParams(imageParams);
    //      imageView.setAdjustViewBounds(true);
    Resources r = context.getResources();
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());

    TextView descriptionView = new TextView(context);
    descriptionView.setId(2);
    descriptionView.setPadding(padding, 0, padding, padding);
    descriptionView.setText(description);
    descriptionView.setBackgroundColor(Color.argb(220, 63, 26, 10));
    descriptionView.setTextColor(Color.WHITE);
    RelativeLayout.LayoutParams descParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    descParams.addRule(RelativeLayout.ALIGN_BOTTOM, imageView.getId());
    carouselView.addView(descriptionView, descParams);

    TextView titleView = new TextView(context);
    titleView.setText(title);
    titleView.setPadding(padding, 0, padding, 0);
    RelativeLayout.LayoutParams titleParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    titleParams.addRule(RelativeLayout.ABOVE, descriptionView.getId());
    titleView.setLayoutParams(titleParams);
    titleView.setTextColor(Color.WHITE);
    titleView.setShadowLayer(2, 3, 3, Color.argb(230, 0, 0, 0));
    titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);

    carouselView.addView(titleView);
}

From source file:com.gmobi.poponews.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    int px = DipHelper.dip2px(50);

    tab.setHeight(px);//from  w w w .j  av  a  2  s.c om
    px = DipHelper.dip2px(90);
    tab.setPadding(20, 0, 20, 0);
    tab.setText(title);

    tab.setTextAppearance(this.getContext(), R.style.TabTextStyle);
    tab.setGravity(Gravity.CENTER);
    tab.setShadowLayer((float) 0.01, 0, (float) 1.0, 0xffffff);

    addTab(position, tab);
}

From source file:info.tellmetime.TellmetimeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_tellmetime);

    mDensity = getResources().getDisplayMetrics().density;
    mScreenWidth = getResources().getDisplayMetrics().widthPixels;
    mScreenHeight = getResources().getDisplayMetrics().heightPixels;
    mShorterEdge = Math.min(mScreenWidth, mScreenHeight);
    mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();
    mBacklightLight = getResources().getColor(R.color.backlight_light);
    mBacklightDark = getResources().getColor(R.color.backlight_dark);

    // Restore background and highlight colors from saved values or set defaults.
    mSettings = getSharedPreferences("PREFS", Context.MODE_PRIVATE);
    mHighlightColor = mSettings.getInt(HIGHLIGHT, Color.WHITE);
    mBacklightColor = mSettings.getInt(BACKLIGHT, mBacklightLight);
    mBackgroundColor = mSettings.getInt(BACKGROUND, getResources().getColor(R.color.background));
    mBackgroundMode = mSettings.getInt(BACKGROUND_MODE, MODE_BACKGROUND_SOLID);
    mHighlightPosition = mSettings.getFloat(POSITION, 0.0f);
    mMinutesSize = mSettings.getInt(MINUTES_SIZE, 36);
    isNightMode = mSettings.getBoolean(NIGHTMODE, false);

    // Dim the navigation bar.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        getWindow().getDecorView().setSystemUiVisibility(isNightMode ? View.SYSTEM_UI_FLAG_LOW_PROFILE : 0);

    mSurface = (RelativeLayout) findViewById(R.id.surface);
    mSurface.setBackgroundColor(mBackgroundColor);

    resizeClock();/*from  w ww  .ja va 2  s .  co m*/

    Typeface mTypefaceBold = Typeface.createFromAsset(getAssets(), "Roboto-BoldCondensed.ttf");

    // Set typeface of all items in the clock to Roboto and dim each one and drop shadow on them.
    final LinearLayout mClock = (LinearLayout) findViewById(R.id.clock);
    for (int i = 0; i < mClock.getChildCount(); i++) {
        LinearLayout row = (LinearLayout) mClock.getChildAt(i);

        for (int j = 0; j < row.getChildCount(); j++) {
            TextView tv = (TextView) row.getChildAt(j);

            tv.setTypeface(mTypefaceBold);
            tv.setTextColor(mBacklightColor);
            tv.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor);
        }
    }

    ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots);
    for (int i = 0; i < minutesDots.getChildCount(); i++) {
        TextView m = (TextView) minutesDots.getChildAt(i);

        m.setTypeface(mTypefaceBold);
        m.setTextColor(mBacklightColor);
        m.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor);
    }

    // Set Roboto font on TextView where it isn't default.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        Typeface mTypefaceItalic = Typeface.createFromAsset(getAssets(), "Roboto-CondensedItalic.ttf");

        ((TextView) findViewById(R.id.labelBackground)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.info_background)).setTypeface(mTypefaceItalic);
        ((TextView) findViewById(R.id.info_image)).setTypeface(mTypefaceItalic);
        ((TextView) findViewById(R.id.labelHighlight)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.labelBackground)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.radio_backlight_light)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.radio_backlight_dark)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.radio_backlight_highlight)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.labelMinutes)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.m1)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.m2)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.m3)).setTypeface(mTypefaceBold);
        ((TextView) findViewById(R.id.m4)).setTypeface(mTypefaceBold);
    }

    FrameLayout mTouchZone = (FrameLayout) findViewById(R.id.touchZone);
    mTouchZone.setOnTouchListener(this);
    mTouchZone.setBackgroundColor(
            getResources().getColor(isNightMode ? R.color.night_mode_overlay : android.R.color.transparent));

    mBackgroundImage = (ImageView) findViewById(R.id.background_image);
    switchBackgroundMode(mBackgroundMode);

    RelativeLayout mPanel = (RelativeLayout) findViewById(R.id.panel);
    mPanel.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            mHider.delayedHide(4000);
            return true;
        }
    });

    mHider = new PanelHider(mPanel, this);

    Spinner spinnerBackgroundMode = (Spinner) findViewById(R.id.spinnerBackgroundMode);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.backgrounds_modes,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerBackgroundMode.setAdapter(adapter);
    spinnerBackgroundMode.setOnItemSelectedListener(this);
    spinnerBackgroundMode.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            mHider.showNoAutoHide();
            return false;
        }
    });
    spinnerBackgroundMode.setSelection(mBackgroundMode);

    mSeekBarHighlight = (SeekBar) findViewById(R.id.highlightValue);
    mSeekBarHighlight.setOnSeekBarChangeListener(this);

    // Draw rainbow gradient on #mSeekBarHighlight and set position.
    drawRainbow();

    if (mBacklightColor == mBacklightLight)
        ((RadioButton) findViewById(R.id.radio_backlight_light)).setChecked(true);
    else if (mBacklightColor == mBacklightDark)
        ((RadioButton) findViewById(R.id.radio_backlight_dark)).setChecked(true);
    else
        ((RadioButton) findViewById(R.id.radio_backlight_highlight)).setChecked(true);

    SeekBar mSeekBarMinutes = (SeekBar) findViewById(R.id.minutesSize);
    mSeekBarMinutes.setOnSeekBarChangeListener(this);
    mSeekBarMinutes.setProgress(mMinutesSize);

    mHider.hideNow();

    Color.colorToHSV(mBackgroundColor, mHSV);
    mHSV[1] = 1.0f;

    //Trigger initial tick.
    mClockAlgorithm.tickTock();

    // Schedule the clock algorithm to tick every round minute.
    Calendar time = Calendar.getInstance();
    time.set(Calendar.MILLISECOND, 0);
    time.set(Calendar.SECOND, 0);
    time.add(Calendar.MINUTE, 1);

    Timer timer = new Timer();
    timer.schedule(mClockTask, time.getTime(), 60 * 1000);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mSurface.setAlpha(0.0f);
        mSurface.animate().alpha(1.0f).setDuration(1500);
    }

    // If it is first run, hint to user that panel is available.
    if (!mSettings.contains(HIGHLIGHT))
        showToast(R.string.info_first_run);
}

From source file:de.enlightened.peris.MessageActivity.java

private void renderMessage(final Message message) {
    final Context context = this.getApplicationContext();
    final SharedPreferences appPreferences = context.getSharedPreferences("prefs", 0);
    final boolean useShading = appPreferences.getBoolean("use_shading", false);
    final boolean useOpenSans = appPreferences.getBoolean("use_opensans", false);
    final int fontSize = appPreferences.getInt("font_size", DEFAULT_FONT_SIZE);
    final boolean currentAvatarSetting = appPreferences.getBoolean("show_images", true);
    final Typeface opensans = Typeface.createFromAsset(context.getAssets(), "fonts/opensans.ttf");

    final View view = this.findViewById(R.id.message_layout);
    final TextView poAuthor = (TextView) view.findViewById(R.id.message_author);
    final TextView poTimestamp = (TextView) view.findViewById(R.id.message_timestamp);
    final TextView tvOnline = (TextView) view.findViewById(R.id.message_online_status);

    final LinearLayout llBorderBackground = (LinearLayout) view.findViewById(R.id.ll_border_background);
    final LinearLayout llColorBackground = (LinearLayout) view.findViewById(R.id.ll_color_background);

    String textColor = context.getString(R.string.default_text_color);
    if (this.application.getSession().getServer().serverTextColor.contains("#")) {
        textColor = this.application.getSession().getServer().serverTextColor;
    }//from   w  w  w  .j  av  a 2 s  .  c  o  m

    String boxColor = context.getString(R.string.default_element_background);
    if (this.application.getSession().getServer().serverBoxColor != null) {
        boxColor = this.application.getSession().getServer().serverBoxColor;
    }

    if (boxColor.contains("#")) {
        llColorBackground.setBackgroundColor(Color.parseColor(boxColor));
    } else {
        llColorBackground.setBackgroundColor(Color.TRANSPARENT);
    }

    //TODO: remove border?
    String boxBorder = context.getString(R.string.default_element_border);
    if (this.application.getSession().getServer().serverBoxBorder != null) {
        boxBorder = this.application.getSession().getServer().serverBoxBorder;
    }

    if (boxBorder.contentEquals("1")) {
        llBorderBackground.setBackgroundResource(R.drawable.element_border);
    } else {
        llBorderBackground.setBackgroundColor(Color.TRANSPARENT);
    }

    if (useOpenSans) {
        poAuthor.setTypeface(opensans);
        poTimestamp.setTypeface(opensans);
        tvOnline.setTypeface(opensans);
    }

    if (useShading) {
        poAuthor.setShadowLayer(2, 0, 0, Color.parseColor("#66000000"));
        tvOnline.setShadowLayer(2, 0, 0, Color.parseColor("#66000000"));
    }

    final LinearLayout llPostBodyHolder = (LinearLayout) view.findViewById(R.id.message_body_holder);
    llPostBodyHolder.removeAllViews();

    final ImageView poAvatar = (ImageView) view.findViewById(R.id.message_avatar);

    if (boxColor != null && boxColor.contains("#") && boxColor.length() == 7) {
        final ImageView postAvatarFrame = (ImageView) view.findViewById(R.id.message_avatar_frame);
        postAvatarFrame.setColorFilter(Color.parseColor(boxColor));
    } else {
        final ImageView postAvatarFrame = (ImageView) view.findViewById(R.id.message_avatar_frame);
        postAvatarFrame.setVisibility(View.GONE);
    }

    if (message.isAuthorOnline()) {
        tvOnline.setText("ONLINE");
        tvOnline.setVisibility(View.VISIBLE);
    } else {
        tvOnline.setVisibility(View.GONE);
    }

    poAuthor.setText(message.getAuthor());
    poTimestamp.setText(DateTimeUtils.getTimeAgo(message.getTimestamp()));

    final String postContent = message.getBody();
    // TODO: add attachments
    BBCodeParser.parseCode(context, llPostBodyHolder, postContent, opensans, useOpenSans, useShading,
            new ArrayList<PostAttachment>(), fontSize, true, textColor, this.application);

    poAuthor.setTextColor(Color.parseColor(textColor));
    poTimestamp.setTextColor(Color.parseColor(textColor));

    if (currentAvatarSetting) {
        if (Net.isUrl(message.getAuthorAvatar())) {
            final String imageUrl = message.getAuthorAvatar();
            ImageLoader.getInstance().displayImage(imageUrl, poAvatar);
        } else {
            poAvatar.setImageResource(R.drawable.no_avatar);
        }
    } else {
        poAvatar.setVisibility(View.GONE);
    }
}