Java Code Examples for android.widget.ImageView#setImageLevel()

The following examples show how to use android.widget.ImageView#setImageLevel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageViewSensorAnimationBehavior.java    From science-journal with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeLargeIcon(RelativeLayout layout, @Nullable Double value) {
  // Remove previous views.
  if (layout.getChildCount() > 0) {
    layout.removeAllViews();
  }
  ImageView largeIcon = new ImageView(layout.getContext());
  layout.addView(
      largeIcon, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  largeIcon.setImageDrawable(getLevelDrawable(largeIcon.getContext()));
  largeIcon.setRotation(0.0f);
  // Icon level depends on type -- we want to pick something in the middle to look reasonable.
  if (behaviorType == TYPE_ACCELEROMETER_SCALE
      || behaviorType == TYPE_ACCELEROMETER_SCALE_ROTATES) {
    // Pick the middle icon
    largeIcon.setImageLevel(2);
  } else if (behaviorType == TYPE_POSITIVE_RELATIVE_SCALE
      || behaviorType == TYPE_RELATIVE_SCALE) {
    // Pick the most exciting icon (the biggest value represented)
    largeIcon.setImageLevel(3);
  }
}
 
Example 2
Source File: UARTButtonAdapter.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public View getView(final int position, @Nullable final View convertView, @NonNull final ViewGroup parent) {
	View view = convertView;
	if (view == null) {
		final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
		view = inflater.inflate(R.layout.feature_uart_button, parent, false);
	}
	view.setEnabled(isEnabled(position));
	view.setActivated(editMode);

	// Update image
	final Command command = (Command) getItem(position);
	final ImageView image = (ImageView) view;
	final boolean active = command != null && command.isActive();
	if (active) {
		final int icon = command.getIconIndex();
		image.setImageResource(R.drawable.uart_button);
		image.setImageLevel(icon);
	} else
		image.setImageDrawable(null);

	return view;
}
 
Example 3
Source File: WiFiListAdapter.java    From esp-idf-provisioning-android with Apache License 2.0 5 votes vote down vote up
public View getView(int position, View convertView, ViewGroup parent) {

        WiFiAccessPoint wiFiAccessPoint = wifiApList.get(position);

        //get the inflater and inflate the XML layout for each item
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.item_wifi_access_point, null);

        TextView wifiNameText = view.findViewById(R.id.tv_wifi_name);
        ImageView rssiImage = view.findViewById(R.id.iv_wifi_rssi);
        ImageView lockImage = view.findViewById(R.id.iv_wifi_security);

        wifiNameText.setText(wiFiAccessPoint.getWifiName());
        rssiImage.setImageLevel(getRssiLevel(wiFiAccessPoint.getRssi()));

        if (wiFiAccessPoint.getSecurity() == ESPConstants.WIFI_OPEN) {
            lockImage.setVisibility(View.GONE);
        } else {
            lockImage.setVisibility(View.VISIBLE);
        }

        if (wiFiAccessPoint.getWifiName().equals(context.getString(R.string.join_other_network))) {

            wifiNameText.setTextColor(ContextCompat.getColor(context.getApplicationContext(), R.color.colorPrimary));
            rssiImage.setVisibility(View.VISIBLE);
            rssiImage.setImageResource(R.drawable.ic_right_arrow);
        }

        return view;
    }
 
Example 4
Source File: UARTEditDialog.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public View getView(final int position, @Nullable final View convertView, @NonNull final ViewGroup parent) {
	View view = convertView;
	if (view == null) {
		view = LayoutInflater.from(parent.getContext())
				.inflate(R.layout.feature_uart_dialog_edit_icon, parent, false);
	}
	final ImageView image = (ImageView) view;
	image.setImageLevel(position);
	image.setActivated(position == activeIcon && activeCheckBox.isChecked());
	return view;
}
 
Example 5
Source File: TweetProgressListAdapter.java    From YiBo with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	if (convertView == null) {
		convertView = inflater.inflate(R.layout.list_item_dialog_tweet_progress, null);
	}
	final LocalAccount account = (LocalAccount)getItem(position);
	
	ImageView ivProfileImage = (ImageView) convertView.findViewById(R.id.ivProfileImage);
       ivProfileImage.setImageDrawable(GlobalResource.getDefaultMinHeader(context));
       
	String profileImageUrl = account.getUser().getProfileImageUrl();
	if (StringUtil.isNotEmpty(profileImageUrl)) {
		new ImageLoad4HeadTask(ivProfileImage, profileImageUrl, true).execute();
	}
	
	TextView screenName = (TextView) convertView.findViewById(R.id.tvScreenName);
	TextView spName = (TextView) convertView.findViewById(R.id.tvSPName);
	ImageView ivTweetState = (ImageView) convertView.findViewById(R.id.ivTweetState);
	
	State state = mapState.get(account);
	if (state == null) {
		state = State.Waiting;
		mapState.put(account, state);
	}
	ivTweetState.setImageLevel(state.getState());
       if (state == State.Loading) {
       	ivTweetState.startAnimation(rotateAnimation);
       } else {
       	ivTweetState.clearAnimation();
       }
       
	screenName.setText(account.getUser().getScreenName());
	String snNameText = account.getServiceProvider().getSpName();
	spName.setText(snNameText);
	
	return convertView;
}
 
Example 6
Source File: ChangeTabLayout.java    From ChangeTabLayout with Apache License 2.0 4 votes vote down vote up
private void scrollToTab(int tabIndex, float positionOffset) {

        final int tabStripChildCount = tabStrip.getChildCount();
        if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
            return;
        }

        LinearLayout selectedTab = (LinearLayout) getTabAt(tabIndex);

        if (0f <= positionOffset && positionOffset < 1f) {
            if(!tabLayoutState){
                ImageView imageView = (ImageView) selectedTab.getChildAt(0);
                ((RevealDrawable)imageView.getDrawable()).setOrientation(RevealDrawable.VERTICAL);
                imageView.setImageLevel((int) (positionOffset * 5000 + 5000));
            }
            if(flag){
                ChangeTextView textView = (ChangeTextView) selectedTab.getChildAt(1);
                textView.setLevel((int) (positionOffset * 5000 + 5000));
            }
        }

        if(!(tabIndex + 1 >= tabStripChildCount)){
            LinearLayout tab = (LinearLayout) getTabAt(tabIndex + 1);

            if(!tabLayoutState){
                ImageView img = (ImageView) tab.getChildAt(0);
                ((RevealDrawable)img.getDrawable()).setOrientation(RevealDrawable.VERTICAL);
                img.setImageLevel((int) (positionOffset * 5000));
            }
            if(flag){
                ChangeTextView text = (ChangeTextView) tab.getChildAt(1);
                text.setLevel((int) (positionOffset * 5000));
            }
        }

        int titleOffset = tabViewHeight * 2;
        int extraOffset = (int) (positionOffset * selectedTab.getHeight());

        int y = (tabIndex > 0 || positionOffset > 0) ? -titleOffset : 0;
        int start = selectedTab.getTop();
        y += start + extraOffset;

        scrollTo(0, y);
    }
 
Example 7
Source File: ChangeTabLayout.java    From ChangeTabLayout with Apache License 2.0 4 votes vote down vote up
/**
 * 水平VIewPager控制
 */
public void setPageScrolled(int p, int position, float positionOffset) {
    if (page != p){
        return;
    }
    //竖屏状态下`ViewPage`的`onPageScrolled`监听不正常修复(统一数据)
    if (positionOffset > 0.99 && positionOffset < 1){
        positionOffset = 0;
        position = position + 1;
    }else if (positionOffset < 0.01 && positionOffset > 0.00001){
        positionOffset = 0;
    }

    if (position - lastPosition[page] > 0) {
        if (lastPosition[page] != ARRAY_INITIAL_VALUE){
            tabLayoutState = false; //每次向左滑动结束时,进入判断,菜单关闭状态
            tabLayoutIsClick = true;
        }
    }else if(position - lastPosition[page] < 0){
        if(lastValue[page] - positionOffset < 0){
            //向左滑动时,不操作。
            return;
        }
    }

    lastPosition[page] = position;
    lastValue[page] = positionOffset;

    if(positionOffset == 0){
        return;
    }

    if(tabLayoutState){ //防止重复收起
        final int tabStripChildCount = tabStrip.getChildCount();
        if (tabStripChildCount == 0 || page < 0 || page >= tabStripChildCount) {
            return;
        }

        LinearLayout selectedTab = (LinearLayout) getTabAt(page);
        ImageView imageView = (ImageView) selectedTab.getChildAt(0);
        ((RevealDrawable)imageView.getDrawable()).setOrientation(RevealDrawable.HORIZONTAL);
        if (0f < positionOffset && positionOffset <= 1f) {
            imageView.setImageLevel((int) ((1 - positionOffset) * 5000 + 5000));
        }

        for (int i = 0, size = tabStrip.getChildCount(); i < size; i++) {
            ChangeTextView textView = (ChangeTextView) ((LinearLayout) tabStrip.getChildAt(i)).getChildAt(1);
            if (0f < positionOffset && positionOffset <= 1f) {
                textView.setAlpha((1 - positionOffset));
                if(positionOffset > 0.9f){
                    textView.setVisibility(INVISIBLE);
                    tabLayoutIsClick = false; //防止同时点击,导致状态混乱
                }else{
                    textView.setVisibility(VISIBLE);
                    tabLayoutIsClick = true;
                }
            }
        }

        if (positionOffset > 0.98){
            positionOffset = 1;
        }
        tabStrip.onViewPagerPageChanged(positionOffset);
    }
}
 
Example 8
Source File: IssueActivity.java    From android with MIT License 4 votes vote down vote up
private void populateRepView(View repView, Contact contact, final int index,
                             List<String> previousCalls) {
    TextView contactName = repView.findViewById(R.id.contact_name);
    final ImageView repImage = repView.findViewById(R.id.rep_image);
    ImageView contactChecked = repView.findViewById(R.id.contact_done_img);
    TextView contactReason = repView.findViewById(R.id.contact_reason);
    TextView contactWarning = repView.findViewById(R.id.contact_warning);
    contactName.setText(contact.name);
    contactWarning.setVisibility(View.GONE);
    if (!TextUtils.isEmpty(contact.area)) {
        contactReason.setText(contact.area);
        if (TextUtils.equals(contact.area, "US House") && mIssue.isSplit) {
            contactWarning.setVisibility(View.VISIBLE);
            contactWarning.setText(R.string.split_district_warning);
        }
        contactReason.setVisibility(View.VISIBLE);
    } else {
        contactReason.setVisibility(View.GONE);
    }
    if (!TextUtils.isEmpty(contact.photoURL)) {
        repImage.setVisibility(View.VISIBLE);
        Glide.with(getApplicationContext())
                .load(contact.photoURL)
                .asBitmap()
                .centerCrop()
                .into(new BitmapImageViewTarget(repImage) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(
                                repImage.getContext().getResources(), resource);
                        drawable.setCircular(true);
                        drawable.setGravity(Gravity.TOP);
                        repImage.setImageDrawable(drawable);
                    }
                });
    } else {
        repImage.setVisibility(View.GONE);
    }
    // Show a bit about whether they've been contacted yet
    if (previousCalls.size() > 0) {
        contactChecked.setImageLevel(1);
        contactChecked.setContentDescription(getResources().getString(
                R.string.contact_done_img_description));
    } else {
        contactChecked.setImageLevel(0);
        contactChecked.setContentDescription(null);
    }

    repView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getApplicationContext(), RepCallActivity.class);
            intent.putExtra(KEY_ISSUE, mIssue);
            intent.putExtra(RepCallActivity.KEY_ADDRESS,
                    getIntent().getStringExtra(RepCallActivity.KEY_ADDRESS));
            intent.putExtra(RepCallActivity.KEY_ACTIVE_CONTACT_INDEX, index);
            startActivity(intent);
        }
    });
}
 
Example 9
Source File: ImageViewSensorAnimationBehavior.java    From science-journal with Apache License 2.0 4 votes vote down vote up
@Override
public void resetIcon(RelativeLayout layout) {
  ImageView view = getImageView(layout);
  view.setImageLevel(0);
}