List of usage examples for android.widget ImageView ImageView
public ImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr)
From source file:net.cpacm.library.indicator.ViewpagerIndicator.IconPageIndicator.java
public void notifyDataSetChanged() { if (iconList.size() == 0) return;// www.ja v a 2 s. c om mIconsLayout.removeAllViews(); int count = mViewPager.getAdapter().getCount(); if (mViewPager.getAdapter() instanceof InfinitePagerAdapter) { count = ((InfinitePagerAdapter) mViewPager.getAdapter()).getRealCount(); } for (int i = 0; i < count; i++) { ImageView view = new ImageView(getContext(), null, R.attr.vpiIconPageIndicatorStyle); view.setImageResource(iconList.get(i % iconList.size())); mIconsLayout.addView(view); } setCurrentItem(mSelectedIndex); requestLayout(); }
From source file:com.example.anumbrella.viewpager.IconPagerIndicator.java
@Override public void notifyDataSetChanged() { mIconsLayout.removeAllViews();/*from w w w . j av a 2s. c o m*/ IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter(); //?? int count = iconAdapter.getCount(); for (int i = 0; i < count; i++) { //??XML ImageView imageView = new ImageView(getContext(), null, R.attr.vpiIconPagerIndicatorStyle); imageView.setImageResource(iconAdapter.getIconResId(i)); //tab mIconsLayout.addView(imageView); } if (mSelectedTabIndex > count) { mSelectedTabIndex = count - 1; } setCurrentItem(mSelectedTabIndex); // requestLayout(); }
From source file:com.quran.labs.androidquran.widgets.IconPageIndicator.java
public void notifyDataSetChanged() { mIconsLayout.removeAllViews();// w w w. j a v a2s . co m IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter(); int count = iconAdapter.getCount(); for (int i = 0; i < count; i++) { ImageView view = new ImageView(getContext(), null, R.attr.actionButtonStyle); view.setImageResource(iconAdapter.getIconResId(i)); view.setTag(i); view.setOnClickListener(this); mIconsLayout.addView(view, new LayoutParams(WRAP_CONTENT, MATCH_PARENT)); } if (mSelectedIndex > count) { mSelectedIndex = count - 1; } setCurrentItem(mSelectedIndex); requestLayout(); }
From source file:com.egoclean.testpregnancy.util.ActivityHelper.java
/** * Adds an action bar button to the compatibility action bar (on phones). *//* www .j a v a2 s . c o m*/ private View addActionButtonCompat(int iconResId, int textResId, View.OnClickListener clickListener, boolean separatorAfter) { final ViewGroup actionBar = getActionBarCompat(); if (actionBar == null) { return null; } // Create the separator ImageView separator = new ImageView(mActivity, null, R.attr.actionbarCompatSeparatorStyle); separator.setLayoutParams(new ViewGroup.LayoutParams(2, ViewGroup.LayoutParams.FILL_PARENT)); // Create the button ImageButton actionButton = new ImageButton(mActivity, null, R.attr.actionbarCompatButtonStyle); actionButton.setLayoutParams(new ViewGroup.LayoutParams( (int) mActivity.getResources().getDimension(R.dimen.actionbar_compat_height), ViewGroup.LayoutParams.FILL_PARENT)); actionButton.setImageResource(iconResId); actionButton.setScaleType(ImageView.ScaleType.CENTER); actionButton.setContentDescription(mActivity.getResources().getString(textResId)); actionButton.setOnClickListener(clickListener); // Add separator and button to the action bar in the desired order if (!separatorAfter) { actionBar.addView(separator); } actionBar.addView(actionButton); if (separatorAfter) { actionBar.addView(separator); } return actionButton; }
From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java
public DrawerForm(Context context, Context unstyledContext, Callback callback, WatcherService.Client watcherServiceClient) { this.context = context; this.unstyledContext = unstyledContext; this.callback = callback; this.watcherServiceClient = watcherServiceClient; float density = ResourceUtils.obtainDensity(context); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setLayoutParams(new SortableListView.LayoutParams(SortableListView.LayoutParams.MATCH_PARENT, SortableListView.LayoutParams.WRAP_CONTENT)); LinearLayout editTextContainer = new LinearLayout(context); editTextContainer.setGravity(Gravity.CENTER_VERTICAL); linearLayout.addView(editTextContainer); searchEdit = new SafePasteEditText(context); searchEdit.setOnKeyListener((v, keyCode, event) -> { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { v.clearFocus();//w ww. j a v a2 s . c o m } return false; }); searchEdit.setHint(context.getString(R.string.text_code_number_address)); searchEdit.setOnEditorActionListener(this); searchEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); searchEdit.setImeOptions(EditorInfo.IME_ACTION_GO | EditorInfo.IME_FLAG_NO_EXTRACT_UI); ImageView searchIcon = new ImageView(context, null, android.R.attr.buttonBarButtonStyle); searchIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonForward, 0)); searchIcon.setScaleType(ImageView.ScaleType.CENTER); searchIcon.setOnClickListener(this); editTextContainer.addView(searchEdit, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); editTextContainer.addView(searchIcon, (int) (40f * density), (int) (40f * density)); if (C.API_LOLLIPOP) { editTextContainer.setPadding((int) (12f * density), (int) (8f * density), (int) (8f * density), 0); } else { editTextContainer.setPadding(0, (int) (2f * density), (int) (4f * density), (int) (2f * density)); } LinearLayout selectorContainer = new LinearLayout(context); selectorContainer.setBackgroundResource( ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0)); selectorContainer.setOrientation(LinearLayout.HORIZONTAL); selectorContainer.setGravity(Gravity.CENTER_VERTICAL); selectorContainer.setOnClickListener(v -> { hideKeyboard(); setChanSelectMode(!chanSelectMode); }); linearLayout.addView(selectorContainer); selectorContainer.setMinimumHeight((int) (40f * density)); if (C.API_LOLLIPOP) { selectorContainer.setPadding((int) (16f * density), 0, (int) (16f * density), 0); ((LinearLayout.LayoutParams) selectorContainer.getLayoutParams()).topMargin = (int) (4f * density); } else { selectorContainer.setPadding((int) (8f * density), 0, (int) (12f * density), 0); } chanNameView = new TextView(context, null, android.R.attr.textAppearanceListItem); chanNameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, C.API_LOLLIPOP ? 14f : 16f); if (C.API_LOLLIPOP) { chanNameView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM); } else { chanNameView.setFilters(new InputFilter[] { new InputFilter.AllCaps() }); } selectorContainer.addView(chanNameView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); chanSelectorIcon = new ImageView(context); chanSelectorIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonDropDownDrawer, 0)); selectorContainer.addView(chanSelectorIcon, (int) (24f * density), (int) (24f * density)); ((LinearLayout.LayoutParams) chanSelectorIcon.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL | Gravity.END; headerView = linearLayout; inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); chans.add(new ListItem(ListItem.ITEM_DIVIDER, 0, 0, null)); int color = ResourceUtils.getColor(context, R.attr.drawerIconColor); ChanManager manager = ChanManager.getInstance(); Collection<String> availableChans = manager.getAvailableChanNames(); for (String chanName : availableChans) { ChanConfiguration configuration = ChanConfiguration.get(chanName); if (configuration.getOption(ChanConfiguration.OPTION_READ_POSTS_COUNT)) { watcherSupportSet.add(chanName); } Drawable drawable = manager.getIcon(chanName, color); chanIcons.put(chanName, drawable); chans.add( new ListItem(ListItem.ITEM_CHAN, chanName, null, null, configuration.getTitle(), 0, drawable)); } if (availableChans.size() == 1) { selectorContainer.setVisibility(View.GONE); } }
From source file:com.mishiranu.dashchan.ui.navigator.page.PostsPage.java
@Override protected void onCreate() { Activity activity = getActivity();//from www.ja v a 2 s. co m PullableListView listView = getListView(); PageHolder pageHolder = getPageHolder(); UiManager uiManager = getUiManager(); hidePerformer = new HidePerformer(); PostsExtra extra = getExtra(); listView.setDivider(ResourceUtils.getDrawable(activity, R.attr.postsDivider, 0)); ChanConfiguration.Board board = getChanConfiguration().safe().obtainBoard(pageHolder.boardName); if (board.allowPosting) { replyable = data -> getUiManager().navigator().navigatePosting(pageHolder.chanName, pageHolder.boardName, pageHolder.threadNumber, data); } PostsAdapter adapter = new PostsAdapter(activity, pageHolder.chanName, pageHolder.boardName, uiManager, replyable, hidePerformer, extra.userPostNumbers, listView); initAdapter(adapter, adapter); ImageLoader.getInstance().observable().register(this); listView.getWrapper().setPullSides(PullableWrapper.Side.BOTH); uiManager.observable().register(this); hidePerformer.setPostsProvider(adapter); Context darkStyledContext = new ContextThemeWrapper(activity, R.style.Theme_General_Main_Dark); searchController = new LinearLayout(darkStyledContext); searchController.setOrientation(LinearLayout.HORIZONTAL); searchController.setGravity(Gravity.CENTER_VERTICAL); float density = ResourceUtils.obtainDensity(getResources()); int padding = (int) (10f * density); searchTextResult = new Button(darkStyledContext, null, android.R.attr.borderlessButtonStyle); searchTextResult.setTextSize(11f); if (!C.API_LOLLIPOP) { searchTextResult.setTypeface(null, Typeface.BOLD); } searchTextResult.setPadding((int) (14f * density), 0, (int) (14f * density), 0); searchTextResult.setMinimumWidth(0); searchTextResult.setMinWidth(0); searchTextResult.setOnClickListener(v -> showSearchDialog()); searchController.addView(searchTextResult, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); ImageView backButtonView = new ImageView(darkStyledContext, null, android.R.attr.borderlessButtonStyle); backButtonView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); backButtonView.setImageResource(obtainIcon(R.attr.actionBack)); backButtonView.setPadding(padding, padding, padding, padding); backButtonView.setOnClickListener(v -> findBack()); searchController.addView(backButtonView, (int) (48f * density), (int) (48f * density)); ImageView forwardButtonView = new ImageView(darkStyledContext, null, android.R.attr.borderlessButtonStyle); forwardButtonView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); forwardButtonView.setImageResource(obtainIcon(R.attr.actionForward)); forwardButtonView.setPadding(padding, padding, padding, padding); forwardButtonView.setOnClickListener(v -> findForward()); searchController.addView(forwardButtonView, (int) (48f * density), (int) (48f * density)); if (C.API_LOLLIPOP) { for (int i = 0, last = searchController.getChildCount() - 1; i <= last; i++) { View view = searchController.getChildAt(i); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams(); if (i == 0) { layoutParams.leftMargin = (int) (-6f * density); } if (i == last) { layoutParams.rightMargin = (int) (6f * density); } else { layoutParams.rightMargin = (int) (-6f * density); } } } scrollToPostNumber = pageHolder.initialPostNumber; FavoritesStorage.getInstance().getObservable().register(this); LocalBroadcastManager.getInstance(activity).registerReceiver(galleryPagerReceiver, new IntentFilter(C.ACTION_GALLERY_NAVIGATE_POST)); boolean hasNewPostDatas = handleNewPostDatas(); extra.forceRefresh = hasNewPostDatas || !pageHolder.initialFromCache; if (extra.cachedPosts != null && extra.cachedPostItems.size() > 0) { onDeserializePostsCompleteInternal(true, extra.cachedPosts, new ArrayList<>(extra.cachedPostItems), true); } else { deserializeTask = new DeserializePostsTask(this, pageHolder.chanName, pageHolder.boardName, pageHolder.threadNumber, extra.cachedPosts); deserializeTask.executeOnExecutor(DeserializePostsTask.THREAD_POOL_EXECUTOR); getListView().getWrapper().startBusyState(PullableWrapper.Side.BOTH); switchView(ViewType.PROGRESS, null); } pageHolder.setInitialPostsData(false, null); }
From source file:com.egoclean.testpregnancy.util.ActivityHelper.java
/** * Adds an action button to the compatibility action bar, using menu information from a * {@link android.view.MenuItem}. If the menu item ID is <code>menu_refresh</code>, the menu item's state * can be changed to show a loading spinner using * {@link ActivityHelper#setRefreshActionButtonCompatState(boolean)}. *//* w w w . j av a 2s . c o m*/ private View addActionButtonCompatFromMenuItem(final MenuItem item) { final ViewGroup actionBar = getActionBarCompat(); if (actionBar == null) { return null; } // Create the separator ImageView separator = new ImageView(mActivity, null, R.attr.actionbarCompatSeparatorStyle); separator.setLayoutParams(new ViewGroup.LayoutParams(2, ViewGroup.LayoutParams.FILL_PARENT)); // Create the button ImageButton actionButton = new ImageButton(mActivity, null, R.attr.actionbarCompatButtonStyle); actionButton.setId(item.getItemId()); actionButton.setLayoutParams(new ViewGroup.LayoutParams( (int) mActivity.getResources().getDimension(R.dimen.actionbar_compat_height), ViewGroup.LayoutParams.FILL_PARENT)); actionButton.setImageDrawable(item.getIcon()); actionButton.setScaleType(ImageView.ScaleType.CENTER); actionButton.setContentDescription(item.getTitle()); actionButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { mActivity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, item); } }); actionBar.addView(separator); actionBar.addView(actionButton); if (item.getItemId() == R.id.menu_refresh) { // Refresh buttons should be stateful, and allow for indeterminate progress indicators, // so add those. int buttonWidth = mActivity.getResources().getDimensionPixelSize(R.dimen.actionbar_compat_height); int buttonWidthDiv3 = buttonWidth / 3; ProgressBar indicator = new ProgressBar(mActivity, null, R.attr.actionbarCompatProgressIndicatorStyle); LinearLayout.LayoutParams indicatorLayoutParams = new LinearLayout.LayoutParams(buttonWidthDiv3, buttonWidthDiv3); indicatorLayoutParams.setMargins(buttonWidthDiv3, buttonWidthDiv3, buttonWidth - 2 * buttonWidthDiv3, 0); indicator.setLayoutParams(indicatorLayoutParams); indicator.setVisibility(View.GONE); indicator.setId(R.id.menu_refresh_progress); actionBar.addView(indicator); } return actionButton; }
From source file:gov.wa.wsdot.android.wsdot.ui.mountainpasses.passitem.MountainPassItemActivity.java
private void startRefreshAnimation() { MenuItem item = mToolbar.getMenu().findItem(MENU_ITEM_REFRESH); if (item == null) { Log.e(TAG, "null"); return;//from w ww.j av a 2 s.co m } // define the animation for rotation Animation animation = new RotateAnimation(360.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setDuration(1000); animation.setRepeatCount(Animation.INFINITE); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { mToolbar.getMenu().getItem(MENU_ITEM_REFRESH).setActionView(null); mToolbar.getMenu().getItem(MENU_ITEM_REFRESH).setIcon(R.drawable.ic_menu_refresh); } @Override public void onAnimationRepeat(Animation animation) { } }); ImageView imageView = new ImageView(this, null, android.R.style.Widget_Material_ActionButton); imageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_menu_refresh)); imageView.setPadding(31, imageView.getPaddingTop(), 32, imageView.getPaddingBottom()); imageView.startAnimation(animation); item.setActionView(imageView); }
From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.TrafficMapActivity.java
private void refreshOverlays(final MenuItem item) { // define the animation for rotation Animation animation = new RotateAnimation(360.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setDuration(1000);/*from ww w . j av a 2 s. co m*/ animation.setRepeatCount(Animation.INFINITE); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { mToolbar.getMenu().getItem(menu_item_refresh).setActionView(null); mToolbar.getMenu().getItem(menu_item_refresh).setIcon(R.drawable.ic_menu_refresh); } @Override public void onAnimationRepeat(Animation animation) { } }); ImageView imageView = new ImageView(this, null, android.R.style.Widget_Material_ActionButton); imageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_menu_refresh)); imageView.setPadding(31, imageView.getPaddingTop(), 32, imageView.getPaddingBottom()); imageView.startAnimation(animation); item.setActionView(imageView); if (mMap != null) { mapCameraViewModel.refreshCameras(); mapHighwayAlertViewModel.refreshAlerts(); } }