FileDocCategorySizeDatePackage
ViewPropertyAlphaActivity.javaAPI DocAndroid 5.1 API5304Thu Mar 12 22:22:44 GMT 2015com.android.test.hwui

ViewPropertyAlphaActivity

public class ViewPropertyAlphaActivity extends android.app.Activity

Fields Summary
MyView
myViewAlphaDefault
MyView
myViewAlphaHandled
Constructors Summary
Methods Summary
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);

        setContentView(R.layout.view_properties);

        getWindow().getDecorView().postDelayed(new Runnable() {
            @Override
            public void run() {
                startAnim(R.id.button);
                startAnim(R.id.textview);
                startAnim(R.id.spantext);
                startAnim(R.id.edittext);
                startAnim(R.id.selectedtext);
                startAnim(R.id.textviewbackground);
                startAnim(R.id.layout);
                startAnim(R.id.imageview);
                startAnim(myViewAlphaDefault);
                startAnim(myViewAlphaHandled);
                EditText selectedText = (EditText) findViewById(R.id.selectedtext);
                selectedText.setSelection(3, 8);
            }
        }, 2000);
        
        Button invalidator = (Button) findViewById(R.id.invalidateButton);
        invalidator.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                findViewById(R.id.textview).invalidate();
                findViewById(R.id.spantext).invalidate();
            }
        });

        TextView textView = (TextView) findViewById(R.id.spantext);
        if (textView != null) {
            SpannableStringBuilder text =
                    new SpannableStringBuilder("Now this is a short text message with spans");

            text.setSpan(new BackgroundColorSpan(Color.RED), 0, 3,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            text.setSpan(new ForegroundColorSpan(Color.BLUE), 4, 9,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            text.setSpan(new SuggestionSpan(this, new String[]{"longer"}, 3), 11, 16,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            text.setSpan(new UnderlineSpan(), 17, 20,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            text.setSpan(new ImageSpan(this, R.drawable.icon), 21, 22,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            textView.setText(text);
        }
        
        LinearLayout container = (LinearLayout) findViewById(R.id.container);
        myViewAlphaDefault = new MyView(this, false);
        myViewAlphaDefault.setLayoutParams(new LinearLayout.LayoutParams(75, 75));
        container.addView(myViewAlphaDefault);
        myViewAlphaHandled = new MyView(this, true);
        myViewAlphaHandled.setLayoutParams(new LinearLayout.LayoutParams(75, 75));
        container.addView(myViewAlphaHandled);
    
private voidstartAnim(android.view.View target)

        ObjectAnimator anim = ObjectAnimator.ofFloat(target, View.ALPHA, 0);
        anim.setRepeatCount(ValueAnimator.INFINITE);
        anim.setRepeatMode(ValueAnimator.REVERSE);
        anim.setDuration(1000);
        anim.start();
    
private voidstartAnim(int id)

        startAnim(findViewById(id));