Search in sources :

Example 51 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project robolectric by robolectric.

the class ShadowTypedArrayTest method getDrawable_withExplicitColorValue_shouldReturnColorDrawable.

@Test
public void getDrawable_withExplicitColorValue_shouldReturnColorDrawable() throws Exception {
    TypedArray typedArray = context.obtainStyledAttributes(Robolectric.buildAttributeSet().addAttribute(android.R.attr.background, "#ff777777").build(), new int[] { android.R.attr.background });
    assertThat(typedArray.getDrawable(0)).isEqualTo(new ColorDrawable(0xff777777));
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) TypedArray(android.content.res.TypedArray) Test(org.junit.Test)

Example 52 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project xabber-android by redsolution.

the class GroupedContactAdapter method getAccountView.

private View getAccountView(int position, View convertView, ViewGroup parent) {
    final View view;
    final ContactListAccountItemViewHolder viewHolder;
    if (convertView == null) {
        view = layoutInflater.inflate(R.layout.contact_list_account_group_item, parent, false);
        viewHolder = new ContactListAccountItemViewHolder(view);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            view.setElevation(accountElevation);
        }
        view.setTag(viewHolder);
    } else {
        view = convertView;
        viewHolder = (ContactListAccountItemViewHolder) view.getTag();
    }
    final AccountConfiguration configuration = (AccountConfiguration) getItem(position);
    final String account = configuration.getAccount();
    viewHolder.statusIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickListener.onAccountMenuClick(v, account);
        }
    });
    final int level = AccountManager.getInstance().getColorLevel(account);
    view.setBackgroundDrawable(new ColorDrawable(accountGroupColors[level]));
    viewHolder.name.setText(GroupManager.getInstance().getGroupName(account, configuration.getUser()));
    viewHolder.smallRightText.setText(configuration.getOnline() + "/" + configuration.getTotal());
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    String statusText = accountItem.getStatusText().trim();
    if (statusText.isEmpty()) {
        statusText = activity.getString(accountItem.getDisplayStatusMode().getStringID());
    }
    viewHolder.secondLineMessage.setText(statusText);
    if (SettingsManager.contactsShowAvatars()) {
        viewHolder.avatar.setVisibility(View.VISIBLE);
        viewHolder.avatar.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
    } else {
        viewHolder.avatar.setVisibility(View.GONE);
    }
    viewHolder.avatar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            activity.startActivity(AccountViewer.createAccountInfoIntent(activity, account));
        }
    });
    viewHolder.statusIcon.setImageLevel(accountItem.getDisplayStatusMode().getStatusLevel());
    ShowOfflineMode showOfflineMode = configuration.getShowOfflineMode();
    if (showOfflineMode == ShowOfflineMode.normal) {
        if (SettingsManager.contactsShowOffline()) {
            showOfflineMode = ShowOfflineMode.always;
        } else {
            showOfflineMode = ShowOfflineMode.never;
        }
    }
    viewHolder.smallRightIcon.setImageLevel(showOfflineMode.ordinal());
    StatusMode statusMode = AccountManager.getInstance().getAccount(configuration.getAccount()).getDisplayStatusMode();
    if (statusMode == StatusMode.unavailable || statusMode == StatusMode.connection) {
        viewHolder.offlineShadow.setVisibility(View.VISIBLE);
    } else {
        viewHolder.offlineShadow.setVisibility(View.GONE);
    }
    return view;
}
Also used : StatusMode(com.xabber.android.data.account.StatusMode) ColorDrawable(android.graphics.drawable.ColorDrawable) AccountItem(com.xabber.android.data.account.AccountItem) ShowOfflineMode(com.xabber.android.data.roster.ShowOfflineMode) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 53 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project picasso by square.

the class RequestCreatorTest method invalidErrorImage.

@Test
public void invalidErrorImage() {
    try {
        new RequestCreator().error(0);
        fail("Resource ID of zero should throw exception.");
    } catch (IllegalArgumentException ignored) {
    }
    try {
        new RequestCreator().error(null);
        fail("Null drawable should throw exception.");
    } catch (IllegalArgumentException ignored) {
    }
    try {
        new RequestCreator().error(1).error(new ColorDrawable(0));
        fail("Two placeholders should throw exception.");
    } catch (IllegalStateException ignored) {
    }
    try {
        new RequestCreator().error(new ColorDrawable(0)).error(1);
        fail("Two placeholders should throw exception.");
    } catch (IllegalStateException ignored) {
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Test(org.junit.Test)

Example 54 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project picasso by square.

the class RequestCreatorTest method invalidNoPlaceholder.

@Test
public void invalidNoPlaceholder() {
    try {
        new RequestCreator().noPlaceholder().placeholder(new ColorDrawable(0));
        fail("Placeholder after no placeholder should throw exception.");
    } catch (IllegalStateException ignored) {
    }
    try {
        new RequestCreator().noPlaceholder().placeholder(1);
        fail("Placeholder after no placeholder should throw exception.");
    } catch (IllegalStateException ignored) {
    }
    try {
        new RequestCreator().placeholder(1).noPlaceholder();
        fail("No placeholder after placeholder should throw exception.");
    } catch (IllegalStateException ignored) {
    }
    try {
        new RequestCreator().placeholder(new ColorDrawable(0)).noPlaceholder();
        fail("No placeholder after placeholder should throw exception.");
    } catch (IllegalStateException ignored) {
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Test(org.junit.Test)

Example 55 with ColorDrawable

use of android.graphics.drawable.ColorDrawable in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class RentalsStyleFragment method createView.

@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_materail_style, null);
    setHeaderTitle(R.string.ptr_demo_rentals_style);
    final CubeImageView imageView = (CubeImageView) view.findViewById(R.id.material_style_image_view);
    final ImageLoader imageLoader = ImageLoaderFactory.create(getContext());
    final PtrFrameLayout frame = (PtrFrameLayout) view.findViewById(R.id.material_style_ptr_frame);
    // header
    final RentalsSunHeaderView header = new RentalsSunHeaderView(getContext());
    header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
    header.setPadding(0, LocalDisplay.dp2px(15), 0, LocalDisplay.dp2px(10));
    header.setUp(frame);
    frame.setLoadingMinTime(1000);
    frame.setDurationToCloseHeader(1500);
    frame.setHeaderView(header);
    frame.addPtrUIHandler(header);
    // frame.setPullToRefresh(true);
    frame.postDelayed(new Runnable() {

        @Override
        public void run() {
            frame.autoRefresh(true);
        }
    }, 100);
    frame.setPtrHandler(new PtrHandler() {

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return true;
        }

        @Override
        public void onRefreshBegin(final PtrFrameLayout frame) {
            if (mImageHasLoaded) {
                long delay = 1500;
                frame.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        frame.refreshComplete();
                    }
                }, delay);
            } else {
                mStartLoadingTime = System.currentTimeMillis();
                imageView.loadImage(imageLoader, mUrl);
            }
        }
    });
    ImageLoadHandler imageLoadHandler = new ImageLoadHandler() {

        @Override
        public void onLoading(ImageTask imageTask, CubeImageView cubeImageView) {
        }

        @Override
        public void onLoadFinish(ImageTask imageTask, final CubeImageView cubeImageView, final BitmapDrawable bitmapDrawable) {
            mImageHasLoaded = true;
            long delay = 1500;
            frame.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (cubeImageView != null && bitmapDrawable != null) {
                        TransitionDrawable w1 = new TransitionDrawable(new Drawable[] { new ColorDrawable(Color.WHITE), (Drawable) bitmapDrawable });
                        imageView.setImageDrawable(w1);
                        w1.startTransition(200);
                    }
                    frame.refreshComplete();
                }
            }, delay);
        }

        @Override
        public void onLoadError(ImageTask imageTask, CubeImageView cubeImageView, int i) {
        }
    };
    imageLoader.setImageLoadHandler(imageLoadHandler);
    return view;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) PtrHandler(in.srain.cube.views.ptr.PtrHandler) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ImageLoadHandler(in.srain.cube.image.iface.ImageLoadHandler) BitmapDrawable(android.graphics.drawable.BitmapDrawable) CubeImageView(in.srain.cube.image.CubeImageView) RentalsSunHeaderView(in.srain.cube.views.ptr.demo.ui.header.RentalsSunHeaderView) View(android.view.View) ColorDrawable(android.graphics.drawable.ColorDrawable) CubeImageView(in.srain.cube.image.CubeImageView) ImageTask(in.srain.cube.image.ImageTask) ImageLoader(in.srain.cube.image.ImageLoader) RentalsSunHeaderView(in.srain.cube.views.ptr.demo.ui.header.RentalsSunHeaderView)

Aggregations

ColorDrawable (android.graphics.drawable.ColorDrawable)530 View (android.view.View)113 Drawable (android.graphics.drawable.Drawable)103 BitmapDrawable (android.graphics.drawable.BitmapDrawable)69 ImageView (android.widget.ImageView)62 TextView (android.widget.TextView)55 Bitmap (android.graphics.Bitmap)52 AdapterView (android.widget.AdapterView)32 LinearLayout (android.widget.LinearLayout)32 Test (org.junit.Test)31 Canvas (android.graphics.Canvas)30 ListView (android.widget.ListView)27 FrameLayout (android.widget.FrameLayout)23 ViewGroup (android.view.ViewGroup)22 Handler (android.os.Handler)20 Paint (android.graphics.Paint)19 StateListDrawable (android.graphics.drawable.StateListDrawable)19 TransitionDrawable (android.graphics.drawable.TransitionDrawable)19 WindowManager (android.view.WindowManager)17 Intent (android.content.Intent)16