androidx.appcompat.widget.AppCompatImageView Java Examples

The following examples show how to use androidx.appcompat.widget.AppCompatImageView. 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: AppUtil.java    From weather with Apache License 2.0 6 votes vote down vote up
/**
 * Set icon to imageView according to weather code status
 *
 * @param context     instance of {@link Context}
 * @param imageView   instance of {@link android.widget.ImageView}
 * @param weatherCode code of weather status
 */
public static void setWeatherIcon(Context context, AppCompatImageView imageView, int weatherCode) {
  if (weatherCode / 100 == 2) {
    Glide.with(context).load(R.drawable.ic_storm_weather).into(imageView);
  } else if (weatherCode / 100 == 3) {
    Glide.with(context).load(R.drawable.ic_rainy_weather).into(imageView);
  } else if (weatherCode / 100 == 5) {
    Glide.with(context).load(R.drawable.ic_rainy_weather).into(imageView);
  } else if (weatherCode / 100 == 6) {
    Glide.with(context).load(R.drawable.ic_snow_weather).into(imageView);
  } else if (weatherCode / 100 == 7) {
    Glide.with(context).load(R.drawable.ic_unknown).into(imageView);
  } else if (weatherCode == 800) {
    Glide.with(context).load(R.drawable.ic_clear_day).into(imageView);
  } else if (weatherCode == 801) {
    Glide.with(context).load(R.drawable.ic_few_clouds).into(imageView);
  } else if (weatherCode == 803) {
    Glide.with(context).load(R.drawable.ic_broken_clouds).into(imageView);
  } else if (weatherCode / 100 == 8) {
    Glide.with(context).load(R.drawable.ic_cloudy_weather).into(imageView);
  }
}
 
Example #2
Source File: CircularProgressIcon.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void initialize() {
    image = new AppCompatImageView(getContext());
    image.setBackgroundColor(Color.TRANSPARENT);
    LayoutParams imageParams = new LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
    );
    int imageMargin = getResources().getDimensionPixelSize(R.dimen.little_margin);
    imageParams.setMargins(imageMargin, imageMargin, imageMargin, imageMargin);
    image.setLayoutParams(imageParams);
    addView(image);

    progress = new CircularProgressView(getContext());
    progress.setIndeterminate(true);
    progress.setColor(Color.WHITE);
    LayoutParams progressParams = new LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
    );
    int progressMargin = (int) new DisplayUtils(getContext()).dpToPx(5);
    progressParams.setMargins(progressMargin, progressMargin, progressMargin, progressMargin);
    progress.setLayoutParams(progressParams);
    addView(progress);

    forceSetResultState(android.R.color.transparent);
}
 
Example #3
Source File: LoginActivity.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void initWidget() {
    swipeBackView.setOnSwipeListener(this);

    AppCompatImageView icon = findViewById(R.id.activity_login_icon);
    ImageHelper.loadImage(this, icon, R.drawable.ic_launcher);

    Button loginBtn = findViewById(R.id.activity_login_loginBtn);
    Button joinBtn = findViewById(R.id.activity_login_joinBtn);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        if (ThemeManager.getInstance(this).isLightTheme()) {
            loginBtn.setBackgroundResource(R.color.colorPrimaryDark_dark);
            joinBtn.setBackgroundResource(R.color.colorPrimaryDark_light);
        } else {
            loginBtn.setBackgroundResource(R.color.colorPrimaryDark_light);
            joinBtn.setBackgroundResource(R.color.colorPrimaryDark_dark);
        }
    } else {
        loginBtn.setBackgroundResource(R.drawable.button_login);
        joinBtn.setBackgroundResource(R.drawable.button_join);
    }

    progressContainer.setVisibility(View.GONE);
}
 
Example #4
Source File: MinimalIconDialog.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void initWidget(View view) {
    if (getActivity() == null) {
        return;
    }

    AppCompatImageView xmlIcon = view.findViewById(R.id.dialog_minimal_icon_xmlIcon);
    xmlIcon.setImageDrawable(xmlIconDrawable);

    TextView titleView = view.findViewById(R.id.dialog_minimal_icon_title);
    titleView.setText(title);

    AppCompatImageView lightIconView = view.findViewById(R.id.dialog_minimal_icon_lightIcon);
    lightIconView.setImageDrawable(lightDrawable);

    AppCompatImageView greyIconView = view.findViewById(R.id.dialog_minimal_icon_greyIcon);
    greyIconView.setImageDrawable(greyDrawable);

    AppCompatImageView darkIconView = view.findViewById(R.id.dialog_minimal_icon_darkIcon);
    darkIconView.setImageDrawable(darkDrawable);
}
 
Example #5
Source File: AnimatableIconView.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void initialize(TypedArray attributes) {
    int innerMargin = attributes.getDimensionPixelSize(
            R.styleable.AnimatableIconView_inner_margins, 0);
    LayoutParams params = new LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    params.setMargins(innerMargin, innerMargin, innerMargin, innerMargin);

    iconImageViews = new AppCompatImageView[] {
            new AppCompatImageView(getContext()),
            new AppCompatImageView(getContext()),
            new AppCompatImageView(getContext())
    };
    iconAnimators = new Animator[] {null, null, null};

    for (int i = iconImageViews.length - 1; i >= 0; i --) {
        addView(iconImageViews[i], params);
    }
}
 
Example #6
Source File: WechatDonateDialog.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
@NonNull
@SuppressLint("InflateParams")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View view = LayoutInflater.from(getActivity())
            .inflate(R.layout.dialog_donate_wechat, null, false);

    AppCompatImageView image = view.findViewById(R.id.dialog_donate_wechat_img);
    Glide.with(getActivity())
            .load(R.drawable.donate_wechat)
            .into(image);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(view);
    return builder.create();
}
 
Example #7
Source File: RepliesListAdapter.java    From mimi-reader with Apache License 2.0 6 votes vote down vote up
public ViewHolderItem(final View v) {
    threadId = (TextView) v.findViewById(R.id.thread_id);
    userName = (TextView) v.findViewById(R.id.user_name);
    postTime = (TextView) v.findViewById(R.id.timestamp);
    userId = (TextView) v.findViewById(R.id.user_id);
    tripCode = (TextView) v.findViewById(R.id.tripcode);
    subject = (TextView) v.findViewById(R.id.subject);
    comment = (TextView) v.findViewById(R.id.comment);
    thumbUrl = (AppCompatImageView) v.findViewById(R.id.thumbnail);
    gotoPost = (TextView) v.findViewById(R.id.goto_post);
    repliesText = (TextView) v.findViewById(R.id.replies_number);
    thumbnailContainer = (ViewGroup) v.findViewById(R.id.thumbnail_container);
    flagIcon = (AppCompatImageView) v.findViewById(R.id.flag_icon);

    comment.setMovementMethod(LongClickLinkMovementMethod.getInstance());
}
 
Example #8
Source File: ExchangeSpinnerAdapter.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = inflater.inflate(R.layout.spinner_item, null);

        try {
            AppCompatImageView icon = view.findViewById(R.id.imageView);
//            icon.setImageDrawable(rows.get(i).icon);
            TextView name = (TextView) view.findViewById(R.id.textView);
            name.setText(rows.get(i).text);
            if (rows.get(i).url != null && !rows.get(i).url.equalsIgnoreCase("")) {
                Picasso
                        .with(inflater.getContext())
                        .load(rows.get(i).url)
                        .placeholder(R.drawable.ic_curr_empty)
                        .error(R.drawable.ic_curr_empty)
                        .into(icon);
            } else {
                icon.setImageDrawable(rows.get(i).icon);
            }
        } catch (IndexOutOfBoundsException iobe) {
            iobe.printStackTrace();
        }

        return view;
    }
 
Example #9
Source File: MainNavigationDrawer.java    From onpc with GNU General Public License v3.0 6 votes vote down vote up
private void updateNavigationHeader(final String versionName)
{
    for (int i = 0; i < navigationView.getHeaderCount(); i++)
    {
        final TextView versionInfo = navigationView.getHeaderView(i).findViewById(R.id.navigation_view_header_version);
        if (versionInfo != null)
        {
            versionInfo.setText(versionName);
        }

        final AppCompatImageView logo = navigationView.getHeaderView(i).findViewById(R.id.drawer_header);
        if (logo != null)
        {
            Utils.setImageViewColorAttr(activity, logo, R.attr.colorAccent);
        }
    }
}
 
Example #10
Source File: MainNavigationDrawer.java    From onpc with GNU General Public License v3.0 6 votes vote down vote up
private void updateItem(@NonNull final MenuItem m, final @DrawableRes int iconId, final String title, final ButtonListener editListener)
{
    if (m.getActionView() != null && m.getActionView() instanceof LinearLayout)
    {
        final LinearLayout l = (LinearLayout)m.getActionView();
        ((AppCompatImageView) l.findViewWithTag("ICON")).setImageResource(iconId);
        ((AppCompatTextView)l.findViewWithTag("TEXT")).setText(title);
        final AppCompatImageButton editBtn = l.findViewWithTag("EDIT");
        if (editListener != null)
        {
            editBtn.setVisibility(View.VISIBLE);
            editBtn.setOnClickListener(v -> editListener.onEditItem());
            Utils.setButtonEnabled(activity, editBtn, true);
        }
        else
        {
            editBtn.setVisibility(View.GONE);
        }
    }
    m.setVisible(true);
}
 
Example #11
Source File: CustomColorDialogPreferenceX.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder)
{
    super.onBindViewHolder(holder);

    backgroundPreview = (AppCompatImageView)holder.findViewById(R.id.dialog_color_chooser_pref_background_preview);
    colorPreview = (AppCompatImageView)holder.findViewById(R.id.dialog_color_chooser_pref_color_preview);

    setColorInWidget();
}
 
Example #12
Source File: RatingBar.java    From Kore with Apache License 2.0 5 votes vote down vote up
private FrameLayout createStar(Context context, AttributeSet attrs, int defStyle) {
    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));

    AppCompatImageView ivStarBackground = new AppCompatImageView(context, attrs, defStyle);
    ivStarBackground.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));
    ivStarBackground.setImageResource(iconResourceId);
    ivStarBackground.setAdjustViewBounds(true);
    ImageViewCompat.setImageTintList(ivStarBackground, ColorStateList.valueOf(backgroundColor));
    frameLayout.addView(ivStarBackground);

    ClipDrawable clipDrawable = new ClipDrawable(
            ContextCompat.getDrawable(context, iconResourceId),
            Gravity.START,
            ClipDrawable.HORIZONTAL);

    AppCompatImageView ivStarForeground = new AppCompatImageView(context, attrs, defStyle);
    ivStarForeground.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));
    ivStarForeground.setImageDrawable(clipDrawable);
    ivStarForeground.setAdjustViewBounds(true);
    ImageViewCompat.setImageTintList(ivStarForeground, ColorStateList.valueOf(foregroundColor));
    frameLayout.addView(ivStarForeground);

    clipDrawables.add((ClipDrawable) ivStarForeground.getDrawable());

    return frameLayout;
}
 
Example #13
Source File: SelectCollectionDialog.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initWidget(View v) {
    setCancelable(true);

    AppCompatImageView cover = v.findViewById(R.id.dialog_select_collection_cover);
    cover.setVisibility(View.GONE);

    progressContainer.setVisibility(View.GONE);
    selectorContainer.setVisibility(View.VISIBLE);

    refreshLayout.setColorSchemeColors(ThemeManager.getContentColor(requireActivity()));
    refreshLayout.setProgressBackgroundColorSchemeColor(ThemeManager.getRootColor(requireActivity()));
    refreshLayout.setRefreshEnabled(false);
    refreshLayout.setLoadEnabled(false);

    recyclerView.setLayoutManager(new LinearLayoutManager(requireActivity(), RecyclerView.VERTICAL, false));
    recyclerView.setAdapter(adapter);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        recyclerView.addOnScrollListener(new ElevationScrollListener());
    }
    recyclerView.addOnScrollListener(new LoadScrollListener());

    updatePhotoAdapter();

    creatorContainer.setVisibility(View.GONE);

    nameTxt.setOnFocusChangeListener((v1, hasFocus) -> nameTxtContainer.setError(null));
}
 
Example #14
Source File: MainActivity.java    From SmartFlasher with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    // Initialize App Theme & FaceBook Ads
    Utils.initializeAppTheme(this);
    Utils.getInstance().initializeFaceBookAds(this);
    super.onCreate(savedInstanceState);
    // Set App Language
    Utils.setLanguage(this);
    setContentView(R.layout.activity_main);

    AppCompatImageView unsupported = findViewById(R.id.no_root_Image);
    TextView textView = findViewById(R.id.no_root_Text);
    TabLayout tabLayout = findViewById(R.id.tabLayoutID);
    mViewPager = findViewById(R.id.viewPagerID);

    if (!RootUtils.rootAccess()) {
        textView.setText(getString(R.string.no_root));
        unsupported.setImageDrawable(Utils.getColoredIcon(R.drawable.ic_help, this));
        return;
    }

    PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager());
    adapter.AddFragment(new FlasherFragment(), getString(R.string.flasher));
    adapter.AddFragment(new BackupFragment(), getString(R.string.backup));
    adapter.AddFragment(new AboutFragment(), getString(R.string.about));

    mViewPager.setAdapter(adapter);
    tabLayout.setupWithViewPager(mViewPager);
}
 
Example #15
Source File: IntroduceActivity.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressLint("InflateParams")
private void initPage() {
    List<View> pageList = new ArrayList<>();
    List<String> titleList = new ArrayList<>();
    for (int i = 0; i < introduceModelList.size(); i ++) {
        View v = LayoutInflater.from(this).inflate(R.layout.container_introduce, null);

        TextView title = v.findViewById(R.id.container_introduce_title);
        title.setText(introduceModelList.get(i).title);

        AppCompatImageView image = v.findViewById(R.id.container_introduce_image);
        ImageHelper.loadImage(this, image, introduceModelList.get(i).imageRes);

        TextView description = v.findViewById(R.id.container_introduce_description);
        description.setText(introduceModelList.get(i).description);

        setPageButtonStyle(v, i);

        pageList.add(v);
        titleList.add(introduceModelList.get(i).title);
    }

    PagerAdapter adapter = new PagerAdapter(viewPager, pageList, titleList);

    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(this);
}
 
Example #16
Source File: AccountInfoFragment.java    From tindroid with Apache License 2.0 5 votes vote down vote up
@Override
public void updateFormValues(final AppCompatActivity activity, final MeTopic<VxCard> me) {
    if (activity == null) {
        return;
    }

    ((TextView) activity.findViewById(R.id.topicAddress)).setText(Cache.getTinode().getMyId());

    String fn = null;
    if (me != null) {
        VxCard pub = me.getPub();
        if (pub != null) {
            fn = pub.fn;
            final Bitmap bmp = pub.getBitmap();
            if (bmp != null) {
                ((AppCompatImageView) activity.findViewById(R.id.imageAvatar))
                        .setImageDrawable(new RoundImageDrawable(getResources(), bmp));
            }
        }
    }

    final TextView title = activity.findViewById(R.id.topicTitle);
    if (!TextUtils.isEmpty(fn)) {
        title.setText(fn);
        title.setTypeface(null, Typeface.NORMAL);
        title.setTextIsSelectable(true);
    } else {
        title.setText(R.string.placeholder_contact_title);
        title.setTypeface(null, Typeface.ITALIC);
        title.setTextIsSelectable(false);
    }
}
 
Example #17
Source File: BaseActivity.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
public void getUserInfo(AppCompatImageView imageView){
    if (currentUser != null) {
        if (currentUser.getPhotoUrl() != null) {
            Glide.with(this)
                    .load(currentUser.getPhotoUrl().toString())
                    .apply(RequestOptions.circleCropTransform()
                    .diskCacheStrategy(DiskCacheStrategy.ALL))
                    .into(imageView);
        }
    }

}
 
Example #18
Source File: ExpandableItemIndicator.java    From AppOpsX with MIT License 5 votes vote down vote up
@Override
public void onInit(Context context, AttributeSet attrs, int defStyleAttr,
    ExpandableItemIndicator thiz) {
  View v = LayoutInflater.from(context)
      .inflate(R.layout.widget_expandable_item_indicator, thiz, true);
  mImageView = (AppCompatImageView) v.findViewById(R.id.image_view);
}
 
Example #19
Source File: ContributorView.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateView(View view) {
    super.onCreateView(view);

    AppCompatImageView image = view.findViewById(R.id.image);
    TextView name = view.findViewById(R.id.name);
    TextView contributions = view.findViewById(R.id.contributions);

    ViewUtils.loadImagefromUrl(mContributor.getAvatarUrl(), image, 200, 200);
    name.setText(mContributor.getLogin());
    contributions.setText(view.getResources().getString(R.string.commits, mContributor.getContributions()));

    view.setOnClickListener(v -> Utils.launchUrl(mContributor.getHtmlUrl(), v.getContext()));
}
 
Example #20
Source File: ExpansionPanelSampleActivityProgrammatically.java    From ExpansionPanel with Apache License 2.0 5 votes vote down vote up
@NonNull
private ExpansionHeader createExpansionHeader() {
    final ExpansionHeader expansionHeader = new ExpansionHeader(this);
    expansionHeader.setBackgroundColor(Color.WHITE);

    expansionHeader.setPadding(dpToPx(this, 16), dpToPx(this, 8), dpToPx(this, 16), dpToPx(this, 8));

    final RelativeLayout layout = new RelativeLayout(this);
    expansionHeader.addView(layout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); //equivalent to addView(linearLayout)

    //image
    final ImageView expansionIndicator = new AppCompatImageView(this);
    expansionIndicator.setImageResource(R.drawable.ic_expansion_header_indicator_grey_24dp);
    final RelativeLayout.LayoutParams imageLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    imageLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    imageLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
    layout.addView(expansionIndicator, imageLayoutParams);

    //label
    final TextView text = new TextView(this);
    text.setText("Trip name");
    text.setTextColor(Color.parseColor("#3E3E3E"));

    final RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    textLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    textLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL);

    layout.addView(text, textLayoutParams);

    expansionHeader.setExpansionHeaderIndicator(expansionIndicator);
    return expansionHeader;
}
 
Example #21
Source File: AppCompat.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
public static void useSimpleStyleForSearchView(SearchView searchView, String hint){
    AppCompatImageView search = searchView.findViewById(androidx.appcompat.R.id.search_mag_icon);
    search.setImageDrawable(null);
    LinearLayout plate = searchView.findViewById(R.id.search_plate);
    plate.setBackground(null);
    AppCompatImageView close = searchView.findViewById(R.id.search_close_btn);
    AppCompat.setTint(close, searchView.getResources().getColor(R.color.colorBarText));
    SearchView.SearchAutoComplete searchAutoComplete = searchView.findViewById(R.id.search_src_text);
    searchAutoComplete.setHint(hint);
}
 
Example #22
Source File: KToast.java    From KToast with Apache License 2.0 5 votes vote down vote up
/**
 * Normal type toast with icon.
 * @param activity
 * @param message
 * @param gravity
 * @param duration
 * @param icon
 */
@SuppressLint("WrongViewCast")
public static void normalToast(final Activity activity, String message, final int gravity, int duration, @DrawableRes int icon){
    final View view = (activity.getLayoutInflater().inflate(R.layout.layout_normal_toast, null));

    ((TextView)view.findViewById(R.id.txtNormalToast)).setText(message);
    view.findViewById(R.id.normalToastImg).setVisibility(View.VISIBLE);
    ((AppCompatImageView)view.findViewById(R.id.normalToastImg)).setImageResource(icon);

    if (duration == LENGTH_AUTO){
        duration = Util.toastTime(message);
    }

    new CountDownTimer(Math.max(duration+1000, 1000), 2000){
        @Override
        public void onFinish() {

        }

        @Override
        public void onTick(long millisUntilFinished) {
            Toast toast = new Toast(activity);
            toast.setGravity(gravity, 0, 0);
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.setView(view);
            toast.show();
        }
    }.start();
}
 
Example #23
Source File: KToast.java    From KToast with Apache License 2.0 5 votes vote down vote up
/**
 * Custom toast background color and icon.
 * @param activity
 * @param message
 * @param gravity
 * @param duration
 * @param toastColor
 * @param icon
 */
@SuppressLint("WrongViewCast")
public static void customColorToast(final Activity activity, String message, final int gravity, int duration, @ColorRes int toastColor, @DrawableRes int icon){
    final View view = (activity.getLayoutInflater().inflate(R.layout.layout_custom_toast, null));

    ((TextView)view.findViewById(R.id.txtCustomToast)).setText(message);

    Drawable customBackground = view.getResources().getDrawable(R.drawable.background_custom_toast);
    customBackground.setColorFilter(ContextCompat.getColor(view.getContext(), toastColor), PorterDuff.Mode.ADD);

    view.findViewById(R.id.customToastLyt).setBackground(customBackground);

    view.findViewById(R.id.customToastImg).setVisibility(View.VISIBLE);
    ((AppCompatImageView)view.findViewById(R.id.customToastImg)).setImageResource(icon);

    if (duration == LENGTH_AUTO){
        duration = Util.toastTime(message);
    }

    new CountDownTimer(Math.max(duration+1000, 1000), 2000){
        @Override
        public void onFinish() {

        }

        @Override
        public void onTick(long millisUntilFinished) {
            Toast toast = new Toast(activity);
            toast.setGravity(gravity, 0, 0);
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.setView(view);
            toast.show();
        }
    }.start();
}
 
Example #24
Source File: PhotoPickerAdapter.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
@Override
protected void convert(@NonNull BaseViewHolder holder, MediaEntity item) {
    AppCompatImageView data = holder.getView(R.id.item_photo_picker_data, AppCompatImageView.class);
    ImageLoader.load(mContext, item.getData(), R.mipmap.ic_launcher, data);
    // 选中
    AppCompatTextView select = holder.getView(R.id.item_photo_picker_select, AppCompatTextView.class);
    final int index = item.getIndex();
    if (index > 0) {
        // 选中
        select.setSelected(true);
        select.setText(String.valueOf(index));
    } else {
        select.setSelected(false);
        select.setText(R.string.ic_tick);
    }
    View video = holder.getView(R.id.item_photo_picker_video);
    // 视频信息
    final long duration = item.getDuration();
    if (duration > 0) {
        // 视频
        video.setVisibility(View.VISIBLE);
        AppCompatTextView durationView = holder.getView(R.id.item_photo_picker_duration, AppCompatTextView.class);
        durationView.setText(StringUtil.handleTimeStringByMilli(duration));
    } else {
        video.setVisibility(View.GONE);
    }
    // 监听
    holder.getView(R.id.item_photo_picker_select_wrap).setOnClickListener(v -> {
        if (mOnItemSelectClickListener != null) {
            mOnItemSelectClickListener.onItemSelectClick(item);
        }
    });
    holder.itemView.setOnClickListener(v -> {
        if (mOnItemClickListener != null) {
            mOnItemClickListener.onItemClick(item);
        }
    });
}
 
Example #25
Source File: GuidePagerAdapter.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
    AppCompatImageView imageView = new AppCompatImageView(container.getContext());
    imageView.setPaddingRelative(0, 0, 0,
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, container.getContext().getResources().getDisplayMetrics()));
    imageView.setImageResource(DRAWABLES[position]);
    container.addView(imageView);
    return imageView;
}
 
Example #26
Source File: CircularSkyWeatherView.java    From GeometricWeather with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressLint("InflateParams")
private void initialize() {
    this.daytime = TimeManager.getInstance(getContext()).isDayTime();

    this.backgroundColor = getBackgroundColor();
    setBackgroundColor(backgroundColor);

    this.binding = ContainerCircularSkyViewBinding.inflate(LayoutInflater.from(getContext()));
    /*
    this.controlView = (WeatherIconControlView) LayoutInflater.from(getContext()).inflate(
            R.layout.container_circular_sky_view, this, false);*/
    binding.controller.setOnWeatherIconChangingListener(this);
    addView(binding.getRoot());

    if (daytime) {
        binding.starContainer.setAlpha(0);
    } else {
        binding.starContainer.setAlpha(1);
    }

    this.iconDrawables = new Drawable[] {null, null, null};
    this.iconAnimators = new Animator[] {null, null, null};

    AppCompatImageView[] starts = new AppCompatImageView[] {
            findViewById(R.id.star_1),
            findViewById(R.id.star_2)};
    Glide.with(getContext())
            .load(R.drawable.star_1)
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .into(starts[0]);
    Glide.with(getContext())
            .load(R.drawable.star_2)
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .into(starts[1]);

    this.starShineAnimators = new AnimatorSet[] {
            (AnimatorSet) AnimatorInflater.loadAnimator(getContext(), R.animator.start_shine_1),
            (AnimatorSet) AnimatorInflater.loadAnimator(getContext(), R.animator.start_shine_2)};
    for (int i = 0; i < starShineAnimators.length; i ++) {
        starShineAnimators[i].addListener(starShineAnimatorListeners[i]);
        starShineAnimators[i].setTarget(starts[i]);
        starShineAnimators[i].start();
    }

    this.insetTop = 0;
    this.firstCardMarginTop = 0;
}
 
Example #27
Source File: HomeAdapter.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
private void renderZhihuNews(BaseViewHolder holder, ZhihuNewsEntity.StoriesEntity item) {
    final AppCompatImageView icon = holder.getView(R.id.item_zhihu_news_icon);
    ImageLoader.load(mContext, getUrl(item.getImages()), icon);
    holder.setText(R.id.item_zhihu_news_title, item.getTitle());
    holder.itemView.setOnClickListener(v -> ZhihuNewsDetailActivity.start((Activity) v.getContext(), item.getId(), icon));
}
 
Example #28
Source File: TopicInfoFragment.java    From tindroid with Apache License 2.0 4 votes vote down vote up
private void notifyContentChanged() {

        final Activity activity = getActivity();
        if (activity == null || activity.isFinishing() || activity.isDestroyed()) {
            return;
        }

        final AppCompatImageView avatar = activity.findViewById(R.id.imageAvatar);
        final TextView title = activity.findViewById(R.id.topicTitle);
        final TextView subtitle = activity.findViewById(R.id.topicSubtitle);

        VxCard pub = mTopic.getPub();
        if (pub != null && !TextUtils.isEmpty(pub.fn)) {
            title.setText(pub.fn);
            title.setTypeface(null, Typeface.NORMAL);
            title.setTextIsSelectable(true);
        } else {
            title.setText(R.string.placeholder_contact_title);
            title.setTypeface(null, Typeface.ITALIC);
            title.setTextIsSelectable(false);
        }

        final Bitmap bmp = pub != null ? pub.getBitmap() : null;
        if (bmp != null) {
            avatar.setImageDrawable(new RoundImageDrawable(getResources(), bmp));
        } else {
            avatar.setImageDrawable(
                    new LetterTileDrawable(requireContext())
                            .setIsCircular(true)
                            .setContactTypeAndColor(
                                    mTopic.getTopicType() == Topic.TopicType.P2P ?
                                            LetterTileDrawable.ContactType.PERSON :
                                            LetterTileDrawable.ContactType.GROUP)
                            .setLetterAndColor(pub != null ? pub.fn : null, mTopic.getName()));
        }

        PrivateType priv = mTopic.getPriv();
        if (priv != null && !TextUtils.isEmpty(priv.getComment())) {
            subtitle.setText(priv.getComment());
            subtitle.setTypeface(null, Typeface.NORMAL);
            TypedValue typedValue = new TypedValue();
            Resources.Theme theme = getActivity().getTheme();
            theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true);
            TypedArray arr = activity.obtainStyledAttributes(typedValue.data,
                    new int[]{android.R.attr.textColorSecondary});
            subtitle.setTextColor(arr.getColor(0, -1));
            arr.recycle();
            subtitle.setTextIsSelectable(true);
        } else {
            subtitle.setText(R.string.placeholder_private);
            subtitle.setTypeface(null, Typeface.ITALIC);
            subtitle.setTextColor(getResources().getColor(R.color.colorTextPlaceholder));
            subtitle.setTextIsSelectable(false);
        }

        ((Switch) activity.findViewById(R.id.switchMuted)).setChecked(mTopic.isMuted());
        ((Switch) activity.findViewById(R.id.switchArchived)).setChecked(mTopic.isArchived());

        Acs acs = mTopic.getAccessMode();
        ((TextView) activity.findViewById(R.id.permissionsSingle)).setText(acs == null ? "" : acs.getMode());
    }
 
Example #29
Source File: FirstCardHeaderController.java    From GeometricWeather with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressLint({"SetTextI18n", "InflateParams"})
public FirstCardHeaderController(@NonNull GeoActivity activity, @NonNull Location location) {
    this.activity = activity;
    this.view = LayoutInflater.from(activity).inflate(R.layout.container_main_first_card_header, null);

    AppCompatImageView timeIcon = view.findViewById(R.id.container_main_first_card_header_timeIcon);
    TextView refreshTime = view.findViewById(R.id.container_main_first_card_header_timeText);
    TextClock localTime = view.findViewById(R.id.container_main_first_card_header_localTimeText);
    TextView alert = view.findViewById(R.id.container_main_first_card_header_alert);
    View line = view.findViewById(R.id.container_main_first_card_header_line);

    ThemeManager themeManager = ThemeManager.getInstance(activity);

    if (location.getWeather() != null) {
        this.weather = location.getWeather();

        view.setOnClickListener(v ->
                IntentHelper.startManageActivityForResult(activity, MainActivity.MANAGE_ACTIVITY));
        view.setEnabled(!MainDisplayUtils.isMultiFragmentEnabled(activity));

        if (weather.getAlertList().size() == 0) {
            timeIcon.setEnabled(false);
            timeIcon.setImageResource(R.drawable.ic_time);
        } else {
            timeIcon.setEnabled(true);
            timeIcon.setImageResource(R.drawable.ic_alert);
        }
        ImageViewCompat.setImageTintList(
                timeIcon,
                ColorStateList.valueOf(themeManager.getTextContentColor(activity))
        );
        timeIcon.setOnClickListener(this);

        refreshTime.setText(
                activity.getString(R.string.refresh_at)
                        + " "
                        + Base.getTime(activity, weather.getBase().getUpdateDate())
        );
        refreshTime.setTextColor(themeManager.getTextContentColor(activity));

        long time = System.currentTimeMillis();
        if (TimeZone.getDefault().getOffset(time) == location.getTimeZone().getOffset(time)) {
            // same time zone.
            localTime.setVisibility(View.GONE);
        } else {
            localTime.setVisibility(View.VISIBLE);
            localTime.setTimeZone(location.getTimeZone().getID());
            localTime.setTextColor(themeManager.getTextSubtitleColor(activity));
            localTime.setFormat12Hour(
                    activity.getString(R.string.date_format_widget_long) + ", h:mm aa"
            );
            localTime.setFormat24Hour(
                    activity.getString(R.string.date_format_widget_long) + ", HH:mm"
            );
        }

        if (weather.getAlertList().size() == 0) {
            alert.setVisibility(View.GONE);
            line.setVisibility(View.GONE);
        } else {
            alert.setVisibility(View.VISIBLE);
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < weather.getAlertList().size(); i ++) {
                builder.append(weather.getAlertList().get(i).getDescription())
                        .append(", ")
                        .append(
                                DateFormat.getDateTimeInstance(
                                        DateFormat.LONG,
                                        DateFormat.DEFAULT
                                ).format(weather.getAlertList().get(i).getDate())
                        );
                if (i != weather.getAlertList().size() - 1) {
                    builder.append("\n");
                }
            }
            alert.setText(builder.toString());
            alert.setTextColor(themeManager.getTextSubtitleColor(activity));

            line.setVisibility(View.VISIBLE);
            line.setBackgroundColor(themeManager.getRootColor(activity));
        }
        alert.setOnClickListener(this);
    }
}
 
Example #30
Source File: AppCompat.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
public static void useCustomIconForSearchView(SearchView searchView, String hint, boolean showSearchHintIcon, boolean showBg) {
    final int normalColor = searchView.getResources().getColor(R.color.colorBarText);
    AppCompatImageView search = searchView.findViewById(androidx.appcompat.R.id.search_button);
    search.setImageResource(R.drawable.ic_search_large_black_24dp);
    setTint(search, normalColor);

    SearchView.SearchAutoComplete searchText = searchView.findViewById(R.id.search_src_text);
    searchText.setTextSize(14f);
    searchText.setPaddingRelative(searchText.getPaddingLeft(), 0, 0, 0);

    final int textSize = Math.round(searchText.getTextSize() * DRAWABLE_SCALE);
    Drawable searchIcon = searchText.getResources().getDrawable(R.drawable.ic_search_black_24dp);
    searchIcon.setBounds(0, 0, textSize, textSize);
    setTint(searchIcon, normalColor);
    searchText.setCompoundDrawablesRelative(searchIcon, null, null, null);
    searchText.setCompoundDrawablePadding(DensityUtil.dp2px(searchText.getContext(), 5));
    searchText.setIncludeFontPadding(false);

    AppCompatImageView close = searchView.findViewById(R.id.search_close_btn);
    close.setImageResource(R.drawable.ic_close_black_24dp);
    setTint(close, normalColor);

    LinearLayout plate = searchView.findViewById(R.id.search_plate);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) plate.getLayoutParams();
    params.topMargin = DensityUtil.dp2px(plate.getContext(), 6);
    params.bottomMargin = params.topMargin;
    plate.setLayoutParams(params);

    View editFrame = searchView.findViewById(R.id.search_edit_frame);
    params = (LinearLayout.LayoutParams) editFrame.getLayoutParams();
    params.leftMargin = DensityUtil.dp2px(editFrame.getContext(), 4);
    editFrame.setLayoutParams(params);

    int padding = DensityUtil.dp2px(plate.getContext(), 6);
    plate.setPaddingRelative(padding, 0, padding, 0);

    if (showBg) {
        Drawable bag = searchView.getResources().getDrawable(R.drawable.bg_search_field);
        androidx.core.view.ViewCompat.setBackground(plate, bag);
    } else {
        androidx.core.view.ViewCompat.setBackground(plate, null);
    }

    setQueryHintForSearchText(searchText, hint, showSearchHintIcon);
}