List of usage examples for android.widget ImageView setId
public void setId(@IdRes int id)
From source file:com.hybris.mobile.lib.ui.view.Alert.java
/** * Set the icon on the alert/*from ww w . j a v a 2 s . c o m*/ * * @param context application-specific resources * @param configuration describes all device configuration information * @param mainView ViewGroup resources * @param textView alert message to be viewed message to be displayedView */ @SuppressLint("NewApi") private static void setIcon(Activity context, Configuration configuration, ViewGroup mainView, TextView textView) { ImageView imageView = (ImageView) mainView.findViewById(R.id.alert_view_icon); // Reset the current icon if (imageView != null) { mainView.removeView(imageView); } // On the textview as well textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); textView.setCompoundDrawablePadding(0); if (configuration.getIconResId() != -1) { imageView = new ImageView(context); imageView.setId(R.id.alert_view_icon); imageView.setImageResource(configuration.getIconResId()); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); imageView.setLayoutParams(layoutParams); switch (configuration.getIconPosition()) { case LEFT_TEXT: textView.setCompoundDrawablesWithIntrinsicBounds(configuration.getIconResId(), 0, 0, 0); textView.setCompoundDrawablePadding(10); break; case RIGHT_TEXT: textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, configuration.getIconResId(), 0); textView.setCompoundDrawablePadding(10); break; case LEFT: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START); } layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); layoutParams.setMargins(25, 0, 0, 0); mainView.addView(imageView); // We redefine the layout params otherwise the image is not well aligned textView.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); break; case RIGHT: default: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END); } layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); layoutParams.setMargins(0, 0, 25, 0); mainView.addView(imageView); // We redefine the layout params otherwise the image is not well aligned textView.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); break; } } }
From source file:com.ouyangzn.github.module.main.MainActivity.java
@Override protected void initView(Bundle savedInstanceState) { Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar); UiUtils.setCenterTitle(toolbar, R.string.app_name); ImageView collectImg = UiUtils.addImage2Toolbar(toolbar, R.drawable.selector_collect, Gravity.END, new int[] { 0, 0, ScreenUtils.dp2px(mContext, 15), 0 }); collectImg.setId(R.id.id_toolbar_right_img); collectImg.setOnClickListener(this); // @BindView ?NavigationViewviewfind? mNavView = ButterKnife.findById(this, R.id.nav_view); mNavView.setNavigationItemSelectedListener(this); View headerView = mNavView.getHeaderView(0); mImgAvatar = (ImageView) headerView.findViewById(R.id.img_photo); mTvEmail = (TextView) headerView.findViewById(R.id.tv_email); User user = App.getUser();//from www . j a va 2s. com if (user != null) { ImageLoader.loadAsCircle(mImgAvatar, R.drawable.ic_default_photo, user.getAvatarUrl()); mTvEmail.setText(user.getEmail()); } else { mImgAvatar.setImageResource(R.drawable.ic_default_photo); mTvEmail.setText(null); } // @BindView ? mDrawerLayout = ButterKnife.findById(this, R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); mDrawerLayout.addDrawerListener(toggle); toggle.syncState(); ViewPager viewPager = ButterKnife.findById(this, R.id.view_pager_main); TabLayout tabLayout = ButterKnife.findById(this, R.id.tabs); tabLayout.setupWithViewPager(viewPager); /** ?list **/ List<Fragment> fragmentList = new ArrayList<>(); /** ?title list **/ String[] array = getResources().getStringArray(R.array.array_language); List<String> titleList = Arrays.asList(array); for (String title : titleList) { fragmentList.add(MainFragment.getInstance(title)); } viewPager.setAdapter(new MainPagerAdapter(getSupportFragmentManager(), fragmentList, titleList)); viewPager.setOffscreenPageLimit(fragmentList.size()); }
From source file:ru.orangesoftware.financisto.activity.ActivityLayout.java
public Pair<TextView, AutoCompleteTextView> addListNodeCategory(LinearLayout layout, int filterToggleId) { ListBuilder b = inflater.new ListBuilder(layout, R.layout.select_entry_category); View v = b.withButtonId(R.id.category_add, listener).withClearButtonId(R.id.category_clear, listener) .withAutoCompleteFilter(listener, filterToggleId).withId(R.id.category, listener) .withLabel(R.string.category).withData(R.string.select_category).create(); ImageView transferImageView = v.findViewById(R.id.split); transferImageView.setId(R.id.category_split); transferImageView.setOnClickListener(listener); ToggleButton toggleBtn = v.findViewById(filterToggleId); AutoCompleteTextView filterTxt = v.findViewById(R.id.autocomplete_filter); filterTxt.setTag(toggleBtn);/*from w ww. ja v a 2 s . c o m*/ TextView entityNameTxt = v.findViewById(R.id.data); entityNameTxt.setTag(R.id.bMinus, v.findViewById(R.id.category_clear)); return Pair.create(entityNameTxt, filterTxt); }
From source file:self.philbrown.droidQuery.Example.ExampleActivity.java
/** * Refreshes the list of cells containing App.net messages. This <em>ListView</em> is actually * a <em>scrollable LinearLayout</em>, and is assembled in much the same way a layout would be * made using <em>JavaScript</em>, with the <em>CSS3</em> attribute <em>overscroll-y: scroll</em>. * <br>// w ww. j a va 2 s .c om * For this example, the public stream is retrieved using <em>ajax</em>, and for each message * received, a new cell is created. For each cell, a new <em>ajax</em> request is started to * retrieve the thumbnail image for the user. As all these events occur on a background thread, the * main ScrollView is populated with cells and displayed to the user. * <br> * The stream <em>JSON</em> request is performed in a <em>global ajax</em> request, which will * trigger the global start and stop events (which show a progress indicator, using a droidQuery * extension). The image get requests are not global, so they will not trigger global events. */ public void refresh() { $.ajax(new AjaxOptions().url("https://alpha-api.app.net/stream/0/posts/stream/global").dataType("json") .type("GET").error(new Function() { @Override public void invoke($ droidQuery, Object... params) { //Object error, int status, String reason Object error = params[0]; int status = (Integer) params[1]; String reason = (String) params[2]; Log.w("app.net Client", "Could not complete request: " + reason); } }).success(new Function() { @Override public void invoke($ droidQuery, Object... params) { //Object, reason JSONObject json = (JSONObject) params[0]; String reason = (String) params[1]; try { Map<String, ?> map = $.map(json); JSONArray datas = (JSONArray) map.get("data"); if (datas.length() != 0) { //clear old subviews in layout $.with(ExampleActivity.this, R.id.example_layout).selectChildren().remove(); //get each message infos and create a cell for (int i = 0; i < datas.length(); i++) { JSONObject jdata = (JSONObject) datas.get(i); Map<String, ?> data = $.map(jdata); String text = data.get("text").toString(); Map<String, ?> user = $.map((JSONObject) data.get("user")); String username = user.get("username").toString(); String avatarURL = ((JSONObject) user.get("avatar_image")).getString("url"); //get Avatar image in a new task (but go ahead and create the cell for now) LinearLayout cell = new LinearLayout(ExampleActivity.this); LinearLayout.LayoutParams cell_params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); cell_params.bottomMargin = 5; cell.setLayoutParams(cell_params); cell.setOrientation(LinearLayout.HORIZONTAL); cell.setWeightSum(8); cell.setPadding(5, 5, 5, 5); cell.setBackgroundColor(Color.parseColor("#333333")); final LinearLayout fcell = cell; //contains the image location ImageView image = new ImageView(ExampleActivity.this); image.setId(99); LinearLayout.LayoutParams ip_params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT); ip_params.weight = 2; image.setLayoutParams(ip_params); image.setPadding(0, 0, 5, 0); $.with(image).attr("alpha", 0.0f); cell.addView(image); final ImageView fimage = image; //the text location in the cell LinearLayout body = new LinearLayout(ExampleActivity.this); LinearLayout.LayoutParams body_params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT); body_params.weight = 5; body.setLayoutParams(body_params); body.setOrientation(LinearLayout.VERTICAL); body.setGravity(Gravity.CENTER_VERTICAL); cell.addView(body); //the username TextView name = new TextView(ExampleActivity.this); LinearLayout.LayoutParams name_params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); name.setLayoutParams(name_params); name.setTextColor(Color.GRAY); name.setText(username); body.addView(name); //the message TextView message = new TextView(ExampleActivity.this); LinearLayout.LayoutParams msg_params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); message.setLayoutParams(msg_params); message.setTextColor(Color.WHITE); message.setTextSize(18); message.setText(text); body.addView(message); CheckBox checkbox = new CheckBox(ExampleActivity.this); LinearLayout.LayoutParams box_params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT); box_params.weight = 1; checkbox.setLayoutParams(box_params); cell.addView(checkbox); $.with(ExampleActivity.this, R.id.example_layout).add(cell); //$.with(fimage).image(avatarURL, 200, 200, $.noop()); $.ajax(new AjaxOptions(avatarURL).type("GET").dataType("image").imageHeight(200) .imageWidth(200).global(false).success(new Function() { @Override public void invoke($ droidQuery, Object... params) { //Object, reason Bitmap src = (Bitmap) params[0]; String reason = (String) params[1]; $.with(fimage).val(src); try { $.with(fimage) .fadeIn(new AnimationOptions("{ duration: 400 }")); } catch (Throwable e) { e.printStackTrace(); } LinearLayout.LayoutParams lparams = (LinearLayout.LayoutParams) fcell .getLayoutParams(); try { lparams.height = Math.min(src.getWidth(), fimage.getWidth()); } catch (Throwable t) { //ignore NPE } fcell.setLayoutParams(lparams); } }).error(new Function() { @Override public void invoke($ droidQuery, Object... params) { //Object error, int status, String reason Object error = params[0]; int status = (Integer) params[1]; String reason = (String) params[2]; Log.w("app.net Client", "Could not complete image request: " + reason); } })); } } else { Log.w("app.net client", "could not update data"); } } catch (Throwable t) { t.printStackTrace(); } } })); }
From source file:com.jgkj.bxxc.fragment.IndexFragment2.java
private void scrollView() { SharedPreferences sp = getActivity().getSharedPreferences("PicCount", Activity.MODE_PRIVATE); final int count = sp.getInt("Count", -1); if (count != -1) { final ImageView[] dots = new ImageView[count]; for (int k = 0; k < count; k++) { ImageView image = new ImageView(getActivity()); image.setImageDrawable(getResources().getDrawable(R.drawable.selector)); image.setId(k); wrapParams = new LinearLayout.LayoutParams(ViewPager.LayoutParams.WRAP_CONTENT, ViewPager.LayoutParams.WRAP_CONTENT); wrapParams.leftMargin = 5;//from w ww .j a v a 2s. c o m image.setLayoutParams(wrapParams); linearlayout.addView(image); dots[k] = (ImageView) linearlayout.getChildAt(k); dots[k].setEnabled(true); } final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (currentItem < (count - 1)) { currentItem++; viewpager.setCurrentItem(currentItem); } else if (currentItem == (count - 1)) { currentItem = 0; viewpager.setCurrentItem(currentItem); } for (int j = 0; j < count; j++) { dots[j].setEnabled(false); } dots[currentItem].setEnabled(true); } }; TimerTask timerTask = new TimerTask() { @Override public void run() { mHandler.sendEmptyMessage(0); } }; timer.schedule(timerTask, 1000, 3000); } }
From source file:th.in.ffc.person.PersonMainActivity.java
private void addNotification(int id, int icon, String msg, String subMSg) { if (qa == null) { qa = new QuickAction(this, QuickAction.VERTICAL); }/*w ww .ja va 2 s. c o m*/ ActionItem item = new ActionItem(id, msg, icon); qa.addActionItem(item); if (!TextUtils.isEmpty(subMSg)) { ActionItem subItem = new ActionItem(id, subMSg); qa.addActionItem(subItem); } if (mNotifacate == null) { mNotifacate = (LinearLayout) findViewById(R.id.notifacation); mNotifacate.setVisibility(View.VISIBLE); mNotifacate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { qa.show(mNotifacate); } }); } ImageView img = (ImageView) mNotifacate.findViewById(id); if (img == null) { img = new ImageView(this); img.setId(id); img.setImageResource(icon); mNotifacate.addView(img, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); } }
From source file:org.catrobat.catroid.ui.fragment.AddBrickFragment.java
public ImageView getGlowingBorder(Bitmap bitmap) { ImageView imageView = new ImageView(getActivity()); imageView.setBackgroundColor(Color.TRANSPARENT); imageView.setId(R.id.drag_and_drop_list_view_image_view); Bitmap glowingBitmap = Bitmap.createBitmap(bitmap.getWidth() + 30, bitmap.getHeight() + 30, Bitmap.Config.ARGB_8888);/* w ww .j a v a 2 s. c o m*/ Canvas glowingCanvas = new Canvas(glowingBitmap); Bitmap alpha = bitmap.extractAlpha(); Paint paintBlur = new Paint(); paintBlur.setColor(Color.WHITE); glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur); BlurMaskFilter blurMaskFilter = new BlurMaskFilter(15.0f, BlurMaskFilter.Blur.OUTER); paintBlur.setMaskFilter(blurMaskFilter); glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur); paintBlur.setMaskFilter(null); glowingCanvas.drawBitmap(bitmap, 15, 15, paintBlur); imageView.setImageBitmap(glowingBitmap); return imageView; }
From source file:hku.fyp14017.blencode.ui.fragment.AddBrickFragment.java
public ImageView getGlowingBorder(Bitmap bitmap) { ImageView imageView = new ImageView(getActivity()); imageView.setBackgroundColor(Color.TRANSPARENT); imageView.setId(hku.fyp14017.blencode.R.id.drag_and_drop_list_view_image_view); Bitmap glowingBitmap = Bitmap.createBitmap(bitmap.getWidth() + 30, bitmap.getHeight() + 30, Bitmap.Config.ARGB_8888);/*from w ww.ja v a 2 s .co m*/ Canvas glowingCanvas = new Canvas(glowingBitmap); Bitmap alpha = bitmap.extractAlpha(); Paint paintBlur = new Paint(); paintBlur.setColor(Color.WHITE); glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur); BlurMaskFilter blurMaskFilter = new BlurMaskFilter(15.0f, BlurMaskFilter.Blur.OUTER); paintBlur.setMaskFilter(blurMaskFilter); glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur); paintBlur.setMaskFilter(null); glowingCanvas.drawBitmap(bitmap, 15, 15, paintBlur); imageView.setImageBitmap(glowingBitmap); return imageView; }
From source file:com.joravasal.comicagg.ComicDetailFragment.java
@SuppressLint({ "NewApi" }) @Override//from w w w.j ava 2s . c om public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_comic_detail, container, false); if (comicItem == null && savedInstanceState.containsKey(ARG_ITEM_ID)) { comicItem = new ComicItem(savedInstanceState.getString(ARG_ITEM_ID), savedInstanceState.getString("comicname"), savedInstanceState.getString("comicurl"), savedInstanceState.getString("unreadcount")); } int unread = Integer.parseInt(comicItem.unreadCount); if (unread == 0) { rootView.findViewById(R.id.vote_bar).setVisibility(View.GONE); } LinearLayout stripList = (LinearLayout) rootView.findViewById(R.id.strips_list); LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); if (comicItem.id.equals(ComicStripsContent.id) && ComicStripsContent.ITEMS.size() > unread) { unread = ComicStripsContent.ITEMS.size(); } for (int i = 1; i < unread; i++) { ImageView iv = new ImageView(getActivity()); iv.setId(Integer.MAX_VALUE - i); iv.setPadding(16, 16, 16, 0); iv.setContentDescription(getString(R.string.strip_description)); iv.setAdjustViewBounds(true); iv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO check if there is need of opening? or always open? openFullscreenStrip(v); } }); TextView tv = new TextView(getActivity()); tv.setId(i); tv.setPadding(16, 4, 16, 4); tv.setGravity(Gravity.CENTER); stripList.addView(iv, layoutParams); stripList.addView(tv, layoutParams); } if (!comicItem.id.equals(ComicStripsContent.id)) { new GetComicsStrips(comicItem.id, unread, rootView).execute(); } else { new GetComicsStrips(comicItem.id, unread, rootView).onPostExecute(null); } if (savedInstanceState != null && savedInstanceState.containsKey(VERTICAL_SCROLLING_POSITION) && VERSION.SDK_INT >= 14) { rootView.findViewById(R.id.comic_scrollView).scrollTo(0, savedInstanceState.getInt(VERTICAL_SCROLLING_POSITION)); } return rootView; }
From source file:com.yktx.check.widget.OldPagerSlidingTabStrip.java
private void addIconAndTextTab(final int position, int resId, String title) { LinearLayout layout = new LinearLayout(getContext()); layout.setGravity(Gravity.CENTER);//from www .j ava 2 s . co m layout.setOrientation(LinearLayout.VERTICAL); ImageView tabImage = new ImageView(getContext()); tabImage.setImageResource(resId); tabImage.setId(R.id.image); TextView tabText = new TextView(getContext()); tabText.setText(title); tabText.setSingleLine(); tabText.setId(R.id.text); tabText.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); tabText.setGravity(Gravity.CENTER_HORIZONTAL); tabText.setPadding(0, 3, 0, 0); layout.addView(tabImage); layout.addView(tabText); addTab(position, layout); }