List of usage examples for android.widget ImageView ImageView
public ImageView(Context context)
From source file:com.baiiu.autoloopviewpager.loopvp.LoopViewPager.java
void populate(int newCurrentItem) { // CHANGE//w w w. j a va2 s . co m int oldCurrentItem = mCurItem; int oldItemsSize = mItems.size(); ItemInfo oldCurInfo = null; if (mCurItem != newCurrentItem) { oldCurInfo = infoForPosition(mCurItem); mCurItem = newCurrentItem; mRequestLayoutNeed = true; } if (mAdapter == null) { return; } // Bail now if we are waiting to populate. This is to hold off // on creating views from the time the user releases their finger to // fling to a new position until we have finished the scroll to // that position, avoiding glitches from happening at that point. if (mPopulatePending) { if (DEBUG) Log.i(TAG, "populate is pending, skipping for now..."); return; } // Also, don't populate until we are attached to a window. This is to // avoid trying to populate before we have restored our view hierarchy // state and conflicting with what is restored. if (getWindowToken() == null) { return; } mAdapter.startUpdate(this); final int N = mAdapter.getCount(); final int pageLimit = mOffscreenPageLimit; // CHANGE final int startPos = (mCurItem + N - pageLimit) % N; // final int startPos = Math.max(0, mCurItem - pageLimit); final int endPos = (mCurItem + pageLimit) % N; // final int endPos = Math.min(N - 1, mCurItem + pageLimit); // Locate the currently focused item or add it if needed. int curIndex = -1; ItemInfo curItem = null; for (curIndex = 0; curIndex < mItems.size(); curIndex++) { final ItemInfo ii = mItems.get(curIndex); // CHANGE if (ii.position == mCurItem) { curItem = ii; break; } } // CHANGE if (curIndex >= mItems.size() && mItems.size() > 0 && oldCurInfo != null) { int oldPosition = oldCurInfo.position; int f = oldPosition < mCurItem ? oldPosition + N : oldPosition; int l = oldPosition > mCurItem ? oldPosition - N : oldPosition; int fDiff = f - mCurItem; int lDiff = mCurItem - l; if (fDiff < lDiff) { curIndex = 0; } else if (lDiff < fDiff) { curIndex = mItems.size(); } else { curIndex = mCurItem < oldPosition ? 0 : mItems.size(); } } if (curItem == null && N > 0) { curItem = addNewItem(mCurItem, curIndex); } // Fill 3x the available width or up to the number of offscreen // pages requested to either side, whichever is larger. // If we have no current item we have no work to do. if (curItem != null) { if (N > 1) { // ANALYZE ?? float extraWidthLeft = 0.f; int itemIndex = curIndex - 1; ItemInfo ii = itemIndex >= 0 ? mItems.get(itemIndex) : null; final float leftWidthNeeded = 2.f - curItem.widthFactor; for (int i = 0; i < N; i++) { final int pos = ((mCurItem - 1 - i) + N) % N; // CHANGE ItemInfo firstInfo = mItems.get(0); if (pos == firstInfo.position && firstInfo.scrolling) { break; } // CHANGE if (extraWidthLeft >= leftWidthNeeded && (pos < startPos || pos > endPos || itemIndex < 0)) { if (ii == null) { break; } // ANALYZE ??????? if (pos == ii.position && !ii.scrolling && N > 3) { mItems.remove(itemIndex); mAdapter.destroyItem(this, pos, ii.object); itemIndex--; curIndex--; ii = itemIndex >= 0 ? mItems.get(itemIndex) : null; } } else if (ii != null && pos == ii.position) { extraWidthLeft += ii.widthFactor; itemIndex--; ii = itemIndex >= 0 ? mItems.get(itemIndex) : null; } else { // CHANGE ItemInfo lastInfo = mItems.get(mItems.size() - 1); if (pos == lastInfo.position) { ii = lastInfo; mItems.remove(lastInfo); mItems.add(itemIndex + 1, lastInfo); } else { // ?? ii = addNewItem(pos, itemIndex + 1); } curIndex++; extraWidthLeft += ii.widthFactor; ii = itemIndex >= 0 ? mItems.get(itemIndex) : null; } } // ANALYZE ??? float extraWidthRight = curItem.widthFactor; itemIndex = curIndex + 1; if (extraWidthRight < 2.f) { ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null; for (int i = 0; i < N; i++) { final int pos = ((mCurItem + 1 + i) + N) % N; // CHANGE if (extraWidthRight >= 2.f && (pos > endPos || pos < startPos || itemIndex >= mItems.size())) { if (ii == null) { break; } // ANALYZE ??????? // CHANGE if (pos == ii.position) { if (!ii.scrolling) { mItems.remove(itemIndex); mAdapter.destroyItem(this, pos, ii.object); ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null; } else { itemIndex++; ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null; } } } else if (ii != null && pos == ii.position) { extraWidthRight += ii.widthFactor; itemIndex++; ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null; } else { // CHANGE ItemInfo firstInfo = mItems.get(0); if (firstInfo.position == -1 && mItems.size() > 1) { firstInfo = mItems.get(1); } if (pos == firstInfo.position && N > 1) { ii = firstInfo; mItems.remove(firstInfo); mItems.add(itemIndex - 1, firstInfo); curIndex--; } else { // ??? ii = addNewItem(pos, itemIndex); itemIndex++; } extraWidthRight += ii.widthFactor; ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null; } } } } // CHANGE if (N == 2) { if (mItems.size() < 3) { ItemInfo lastInfo = mItems.get(mItems.size() - 1); // ?? ItemInfo ii = new ItemInfo(); ii.position = -1; ii.object = null; ii.widthFactor = lastInfo.widthFactor; ImageView dummyView = new ImageView(getContext()); dummyView.setTag(-1); this.addView(dummyView); mItems.add(0, ii); curIndex++; } } calculatePageOffsets(curItem, curIndex, oldCurInfo); if (N > 3) { if (DEBUG) { Log.d("??", "N = " + N + ", oldItemsSize = " + oldItemsSize + ", mItems.size = " + mItems.size() + ", mRequestLayoutNeed = " + mRequestLayoutNeed); } if (oldItemsSize > 3) { if (mItems.size() > 3) { if (mRequestLayoutNeed) { requestLayout(); mRequestLayoutNeed = false; } } } } } if (DEBUG) { Log.i(TAG, "Current page list:"); for (int i = 0; i < mItems.size(); i++) { Log.i(TAG, "#" + i + ": page " + mItems.get(i).position + " offset " + mItems.get(i).offset); } } mAdapter.setPrimaryItem(this, mCurItem, curItem != null ? curItem.object : null); mAdapter.finishUpdate(this); // Check width measurement of current pages. Update LayoutParams as // needed. final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (!lp.isDecor && lp.widthFactor == 0.f) { // 0 means requery the adapter for this, it doesn't have a valid // width. final ItemInfo ii = infoForChild(child); if (ii != null) { lp.widthFactor = ii.widthFactor; } } } if (hasFocus()) { View currentFocused = findFocus(); ItemInfo ii = currentFocused != null ? infoForAnyChild(currentFocused) : null; if (ii == null || ii.position != mCurItem) { for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); ii = infoForChild(child); if (ii != null && ii.position == mCurItem) { if (child.requestFocus(FOCUS_FORWARD)) { break; } } } } } }
From source file:com.andreadec.musicplayer.MainActivity.java
private void showItemInfo(PlayableItem item) { if (item == null || item.getInformation() == null) return;//w w w . ja v a 2 s . co m ArrayList<Information> information = item.getInformation(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.songInfo); View view = getLayoutInflater().inflate(R.layout.layout_songinfo, null, false); LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayoutInformation); Bitmap image = item.getImage(); if (image != null) { ImageView imageView = new ImageView(this); imageView.setImageBitmap(image); linearLayout.addView(imageView); } for (Information info : information) { TextView info1 = new TextView(this); info1.setTextAppearance(this, android.R.style.TextAppearance_Medium); info1.setText(getResources().getString(info.key)); TextView info2 = new TextView(this); info2.setText(info.value); info2.setPadding(0, 0, 0, 10); linearLayout.addView(info1); linearLayout.addView(info2); } builder.setView(view); builder.setPositiveButton(R.string.ok, null); builder.show(); }
From source file:net.bluehack.ui.Components.EmojiView.java
public EmojiView(boolean needStickers, boolean needGif, final Context context) { super(context); showGifs = needGif;/*from w w w.j a v a 2s.com*/ dotDrawable = context.getResources().getDrawable(R.drawable.bluecircle); if (Build.VERSION.SDK_INT >= 21) { outlineProvider = new ViewOutlineProvider() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(View view, Outline outline) { outline.setRoundRect(view.getPaddingLeft(), view.getPaddingTop(), view.getMeasuredWidth() - view.getPaddingRight(), view.getMeasuredHeight() - view.getPaddingBottom(), AndroidUtilities.dp(6)); } }; } for (int i = 0; i < EmojiData.dataColored.length + 1; i++) { GridView gridView = new GridView(context); if (AndroidUtilities.isTablet()) { gridView.setColumnWidth(AndroidUtilities.dp(60)); } else { gridView.setColumnWidth(AndroidUtilities.dp(45)); } gridView.setNumColumns(-1); EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1); AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7); gridView.setAdapter(emojiGridAdapter); adapters.add(emojiGridAdapter); emojiGrids.add(gridView); FrameLayout frameLayout = new FrameLayout(context); frameLayout.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0)); views.add(frameLayout); } if (needStickers) { stickersWrap = new FrameLayout(context); StickersQuery.checkStickers(StickersQuery.TYPE_IMAGE); StickersQuery.checkFeaturedStickers(); stickersGridView = new RecyclerListView(context) { @Override public boolean onInterceptTouchEvent(MotionEvent event) { boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, stickersGridView, EmojiView.this.getMeasuredHeight()); return super.onInterceptTouchEvent(event) || result; } @Override public void setVisibility(int visibility) { if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE || trendingGridView != null && trendingGridView.getVisibility() == VISIBLE) { super.setVisibility(GONE); return; } super.setVisibility(visibility); } }; stickersGridView.setLayoutManager(stickersLayoutManager = new GridLayoutManager(context, 5)); stickersLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (position == stickersGridAdapter.totalItems) { return stickersGridAdapter.stickersPerRow; } return 1; } }); stickersGridView.setPadding(0, AndroidUtilities.dp(4 + 48), 0, 0); stickersGridView.setClipToPadding(false); views.add(stickersWrap); stickersGridView.setAdapter(stickersGridAdapter = new StickersGridAdapter(context)); stickersGridView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return StickerPreviewViewer.getInstance().onTouch(event, stickersGridView, EmojiView.this.getMeasuredHeight(), stickersOnItemClickListener); } }); stickersOnItemClickListener = new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (!(view instanceof StickerEmojiCell)) { return; } StickerPreviewViewer.getInstance().reset(); StickerEmojiCell cell = (StickerEmojiCell) view; if (cell.isDisabled()) { return; } cell.disable(); listener.onStickerSelected(cell.getSticker()); } }; stickersGridView.setOnItemClickListener(stickersOnItemClickListener); stickersGridView.setGlowColor(0xfff5f6f7); stickersWrap.addView(stickersGridView); trendingGridView = new RecyclerListView(context); trendingGridView.setItemAnimator(null); trendingGridView.setLayoutAnimation(null); trendingGridView.setLayoutManager(trendingLayoutManager = new GridLayoutManager(context, 5) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }); trendingLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (trendingGridAdapter.cache.get(position) instanceof Integer || position == trendingGridAdapter.totalItems) { return trendingGridAdapter.stickersPerRow; } return 1; } }); trendingGridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkStickersTabY(recyclerView, dy); } }); trendingGridView.setClipToPadding(false); trendingGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0); trendingGridView.setAdapter(trendingGridAdapter = new TrendingGridAdapter(context)); trendingGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { TLRPC.StickerSetCovered pack = trendingGridAdapter.positionsToSets.get(position); if (pack != null) { listener.onShowStickerSet(pack); } } }); trendingGridAdapter.notifyDataSetChanged(); trendingGridView.setGlowColor(0xfff5f6f7); trendingGridView.setVisibility(GONE); stickersWrap.addView(trendingGridView); if (needGif) { gifsGridView = new RecyclerListView(context); gifsGridView.setClipToPadding(false); gifsGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0); gifsGridView.setLayoutManager(flowLayoutManager = new ExtendedGridLayoutManager(context, 100) { private Size size = new Size(); @Override protected Size getSizeForItem(int i) { TLRPC.Document document = recentGifs.get(i); size.width = document.thumb != null && document.thumb.w != 0 ? document.thumb.w : 100; size.height = document.thumb != null && document.thumb.h != 0 ? document.thumb.h : 100; for (int b = 0; b < document.attributes.size(); b++) { TLRPC.DocumentAttribute attribute = document.attributes.get(b); if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) { size.width = attribute.w; size.height = attribute.h; break; } } return size; } }); flowLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return flowLayoutManager.getSpanSizeForItem(position); } }); gifsGridView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(android.graphics.Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.left = 0; outRect.top = 0; outRect.bottom = 0; int position = parent.getChildAdapterPosition(view); if (!flowLayoutManager.isFirstRow(position)) { outRect.top = AndroidUtilities.dp(2); } outRect.right = flowLayoutManager.isLastInRow(position) ? 0 : AndroidUtilities.dp(2); } }); gifsGridView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); gifsGridView.setAdapter(gifsAdapter = new GifsAdapter(context)); gifsGridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkStickersTabY(recyclerView, dy); } }); gifsGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (position < 0 || position >= recentGifs.size() || listener == null) { return; } listener.onGifSelected(recentGifs.get(position)); } }); gifsGridView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { @Override public boolean onItemClick(View view, int position) { if (position < 0 || position >= recentGifs.size()) { return false; } final TLRPC.Document searchImage = recentGifs.get(position); AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("DeleteGif", R.string.DeleteGif)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK).toUpperCase(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { StickersQuery.removeRecentGif(searchImage); recentGifs = StickersQuery.getRecentGifs(); if (gifsAdapter != null) { gifsAdapter.notifyDataSetChanged(); } if (recentGifs.isEmpty()) { updateStickerTabs(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.show().setCanceledOnTouchOutside(true); return true; } }); gifsGridView.setVisibility(GONE); stickersWrap.addView(gifsGridView); } stickersEmptyView = new TextView(context); stickersEmptyView.setText(LocaleController.getString("NoStickers", R.string.NoStickers)); stickersEmptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); stickersEmptyView.setTextColor(0xff888888); stickersWrap.addView(stickersEmptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0)); stickersGridView.setEmptyView(stickersEmptyView); stickersTab = new ScrollSlidingTabStrip(context) { boolean startedScroll; float lastX; float lastTranslateX; boolean first = true; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { if (first) { first = false; lastX = ev.getX(); } float newTranslationX = stickersTab.getTranslationX(); if (stickersTab.getScrollX() == 0 && newTranslationX == 0) { if (!startedScroll && lastX - ev.getX() < 0) { if (pager.beginFakeDrag()) { startedScroll = true; lastTranslateX = stickersTab.getTranslationX(); } } else if (startedScroll && lastX - ev.getX() > 0) { if (pager.isFakeDragging()) { pager.endFakeDrag(); startedScroll = false; } } } if (startedScroll) { int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX); try { pager.fakeDragBy(dx); lastTranslateX = newTranslationX; } catch (Exception e) { try { pager.endFakeDrag(); } catch (Exception e2) { //don't promt } startedScroll = false; FileLog.e("tmessages", e); } } lastX = ev.getX(); if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) { first = true; if (startedScroll) { pager.endFakeDrag(); startedScroll = false; } } return startedScroll || super.onTouchEvent(ev); } }; stickersTab.setUnderlineHeight(AndroidUtilities.dp(1)); stickersTab.setIndicatorColor(0xffe2e5e7); stickersTab.setUnderlineColor(0xffe2e5e7); stickersTab.setBackgroundColor(0xfff5f6f7); stickersTab.setVisibility(INVISIBLE); addView(stickersTab, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP)); stickersTab.setTranslationX(AndroidUtilities.displaySize.x); updateStickerTabs(); stickersTab.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() { @Override public void onPageSelected(int page) { if (gifsGridView != null) { if (page == gifTabNum + 1) { if (gifsGridView.getVisibility() != VISIBLE) { listener.onGifTab(true); showGifTab(); } } else if (page == trendingTabNum + 1) { if (trendingGridView.getVisibility() != VISIBLE) { showTrendingTab(); } } else { if (gifsGridView.getVisibility() == VISIBLE) { listener.onGifTab(false); gifsGridView.setVisibility(GONE); stickersGridView.setVisibility(VISIBLE); stickersEmptyView .setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE); saveNewPage(); } else if (trendingGridView.getVisibility() == VISIBLE) { trendingGridView.setVisibility(GONE); stickersGridView.setVisibility(VISIBLE); stickersEmptyView .setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE); saveNewPage(); } } } if (page == 0) { pager.setCurrentItem(0); return; } else { if (page == gifTabNum + 1 || page == trendingTabNum + 1) { return; } else if (page == recentTabBum + 1) { stickersLayoutManager.scrollToPositionWithOffset(0, 0); checkStickersTabY(null, 0); stickersTab.onPageScrolled(recentTabBum + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1); return; } } int index = page - 1 - stickersTabOffset; if (index >= stickerSets.size()) { if (listener != null) { listener.onStickersSettingsClick(); } return; } if (index >= stickerSets.size()) { index = stickerSets.size() - 1; } stickersLayoutManager.scrollToPositionWithOffset( stickersGridAdapter.getPositionForPack(stickerSets.get(index)), 0); checkStickersTabY(null, 0); checkScroll(); } }); stickersGridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkScroll(); checkStickersTabY(recyclerView, dy); } }); } pager = new ViewPager(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pager.setAdapter(new EmojiPagesAdapter()); emojiTab = new LinearLayout(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; emojiTab.setOrientation(LinearLayout.HORIZONTAL); addView(emojiTab, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48)); pagerSlidingTabStrip = new PagerSlidingTabStrip(context); pagerSlidingTabStrip.setViewPager(pager); pagerSlidingTabStrip.setShouldExpand(true); pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(2)); pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2); pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7); emojiTab.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f)); pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { EmojiView.this.onPageScrolled(position, getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), positionOffsetPixels); } @Override public void onPageSelected(int position) { saveNewPage(); } @Override public void onPageScrollStateChanged(int state) { } }); FrameLayout frameLayout = new FrameLayout(context); emojiTab.addView(frameLayout, LayoutHelper.createLinear(52, 48)); backspaceButton = new ImageView(context) { @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { backspacePressed = true; backspaceOnce = false; postBackspaceRunnable(350); } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) { backspacePressed = false; if (!backspaceOnce) { if (listener != null && listener.onBackspace()) { backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); } } } super.onTouchEvent(event); return true; } }; backspaceButton.setImageResource(R.drawable.ic_smiles_backspace); backspaceButton.setBackgroundResource(R.drawable.ic_emoji_backspace); backspaceButton.setScaleType(ImageView.ScaleType.CENTER); frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48)); View view = new View(context); view.setBackgroundColor(0xffe2e5e7); frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM)); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoRecent", R.string.NoRecent)); textView.setTextSize(18); textView.setTextColor(0xff888888); textView.setGravity(Gravity.CENTER); textView.setClickable(false); textView.setFocusable(false); ((FrameLayout) views.get(0)).addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0)); emojiGrids.get(0).setEmptyView(textView); addView(pager, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); emojiSize = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 40 : 32); pickerView = new EmojiColorPickerView(context); pickerViewPopup = new EmojiPopupWindow(pickerView, popupWidth = AndroidUtilities.dp((AndroidUtilities.isTablet() ? 40 : 32) * 6 + 10 + 4 * 5), popupHeight = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 64 : 56)); pickerViewPopup.setOutsideTouchable(true); pickerViewPopup.setClippingEnabled(true); pickerViewPopup.setInputMethodMode(EmojiPopupWindow.INPUT_METHOD_NOT_NEEDED); pickerViewPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED); pickerViewPopup.getContentView().setFocusableInTouchMode(true); pickerViewPopup.getContentView().setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP && pickerViewPopup != null && pickerViewPopup.isShowing()) { pickerViewPopup.dismiss(); return true; } return false; } }); currentPage = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE).getInt("selected_page", 0); loadRecents(); }
From source file:kr.wdream.ui.Components.EmojiView.java
public EmojiView(boolean needStickers, boolean needGif, final Context context) { super(context); showGifs = needGif;/*w ww .j a v a 2s. c o m*/ dotDrawable = context.getResources().getDrawable(kr.wdream.storyshop.R.drawable.bluecircle); if (Build.VERSION.SDK_INT >= 21) { outlineProvider = new ViewOutlineProvider() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(View view, Outline outline) { outline.setRoundRect(view.getPaddingLeft(), view.getPaddingTop(), view.getMeasuredWidth() - view.getPaddingRight(), view.getMeasuredHeight() - view.getPaddingBottom(), AndroidUtilities.dp(6)); } }; } for (int i = 0; i < EmojiData.dataColored.length + 1; i++) { GridView gridView = new GridView(context); if (AndroidUtilities.isTablet()) { gridView.setColumnWidth(AndroidUtilities.dp(60)); } else { gridView.setColumnWidth(AndroidUtilities.dp(45)); } gridView.setNumColumns(-1); EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1); AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7); gridView.setAdapter(emojiGridAdapter); adapters.add(emojiGridAdapter); emojiGrids.add(gridView); FrameLayout frameLayout = new FrameLayout(context); frameLayout.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0)); views.add(frameLayout); } if (needStickers) { stickersWrap = new FrameLayout(context); StickersQuery.checkStickers(StickersQuery.TYPE_IMAGE); StickersQuery.checkFeaturedStickers(); stickersGridView = new RecyclerListView(context) { @Override public boolean onInterceptTouchEvent(MotionEvent event) { boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, stickersGridView, EmojiView.this.getMeasuredHeight()); return super.onInterceptTouchEvent(event) || result; } @Override public void setVisibility(int visibility) { if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE || trendingGridView != null && trendingGridView.getVisibility() == VISIBLE) { super.setVisibility(GONE); return; } super.setVisibility(visibility); } }; stickersGridView.setLayoutManager(stickersLayoutManager = new GridLayoutManager(context, 5)); stickersLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (position == stickersGridAdapter.totalItems) { return stickersGridAdapter.stickersPerRow; } return 1; } }); stickersGridView.setPadding(0, AndroidUtilities.dp(4 + 48), 0, 0); stickersGridView.setClipToPadding(false); views.add(stickersWrap); stickersGridView.setAdapter(stickersGridAdapter = new StickersGridAdapter(context)); stickersGridView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return StickerPreviewViewer.getInstance().onTouch(event, stickersGridView, EmojiView.this.getMeasuredHeight(), stickersOnItemClickListener); } }); stickersOnItemClickListener = new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (!(view instanceof StickerEmojiCell)) { return; } StickerPreviewViewer.getInstance().reset(); StickerEmojiCell cell = (StickerEmojiCell) view; if (cell.isDisabled()) { return; } cell.disable(); listener.onStickerSelected(cell.getSticker()); } }; stickersGridView.setOnItemClickListener(stickersOnItemClickListener); stickersGridView.setGlowColor(0xfff5f6f7); stickersWrap.addView(stickersGridView); trendingGridView = new RecyclerListView(context); trendingGridView.setItemAnimator(null); trendingGridView.setLayoutAnimation(null); trendingGridView.setLayoutManager(trendingLayoutManager = new GridLayoutManager(context, 5) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }); trendingLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (trendingGridAdapter.cache.get(position) instanceof Integer || position == trendingGridAdapter.totalItems) { return trendingGridAdapter.stickersPerRow; } return 1; } }); trendingGridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkStickersTabY(recyclerView, dy); } }); trendingGridView.setClipToPadding(false); trendingGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0); trendingGridView.setAdapter(trendingGridAdapter = new TrendingGridAdapter(context)); trendingGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { TLRPC.StickerSetCovered pack = trendingGridAdapter.positionsToSets.get(position); if (pack != null) { listener.onShowStickerSet(pack); } } }); trendingGridAdapter.notifyDataSetChanged(); trendingGridView.setGlowColor(0xfff5f6f7); trendingGridView.setVisibility(GONE); stickersWrap.addView(trendingGridView); if (needGif) { gifsGridView = new RecyclerListView(context); gifsGridView.setClipToPadding(false); gifsGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0); gifsGridView.setLayoutManager(flowLayoutManager = new ExtendedGridLayoutManager(context, 100) { private Size size = new Size(); @Override protected Size getSizeForItem(int i) { TLRPC.Document document = recentGifs.get(i); size.width = document.thumb != null && document.thumb.w != 0 ? document.thumb.w : 100; size.height = document.thumb != null && document.thumb.h != 0 ? document.thumb.h : 100; for (int b = 0; b < document.attributes.size(); b++) { TLRPC.DocumentAttribute attribute = document.attributes.get(b); if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) { size.width = attribute.w; size.height = attribute.h; break; } } return size; } }); flowLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return flowLayoutManager.getSpanSizeForItem(position); } }); gifsGridView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(android.graphics.Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.left = 0; outRect.top = 0; outRect.bottom = 0; int position = parent.getChildAdapterPosition(view); if (!flowLayoutManager.isFirstRow(position)) { outRect.top = AndroidUtilities.dp(2); } outRect.right = flowLayoutManager.isLastInRow(position) ? 0 : AndroidUtilities.dp(2); } }); gifsGridView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); gifsGridView.setAdapter(gifsAdapter = new GifsAdapter(context)); gifsGridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkStickersTabY(recyclerView, dy); } }); gifsGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (position < 0 || position >= recentGifs.size() || listener == null) { return; } listener.onGifSelected(recentGifs.get(position)); } }); gifsGridView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { @Override public boolean onItemClick(View view, int position) { if (position < 0 || position >= recentGifs.size()) { return false; } final TLRPC.Document searchImage = recentGifs.get(position); AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); builder.setTitle( LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setMessage( LocaleController.getString("DeleteGif", kr.wdream.storyshop.R.string.DeleteGif)); builder.setPositiveButton( LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK).toUpperCase(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { StickersQuery.removeRecentGif(searchImage); recentGifs = StickersQuery.getRecentGifs(); if (gifsAdapter != null) { gifsAdapter.notifyDataSetChanged(); } if (recentGifs.isEmpty()) { updateStickerTabs(); } } }); builder.setNegativeButton( LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); builder.show().setCanceledOnTouchOutside(true); return true; } }); gifsGridView.setVisibility(GONE); stickersWrap.addView(gifsGridView); } stickersEmptyView = new TextView(context); stickersEmptyView .setText(LocaleController.getString("NoStickers", kr.wdream.storyshop.R.string.NoStickers)); stickersEmptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); stickersEmptyView.setTextColor(0xff888888); stickersWrap.addView(stickersEmptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0)); stickersGridView.setEmptyView(stickersEmptyView); stickersTab = new ScrollSlidingTabStrip(context) { boolean startedScroll; float lastX; float lastTranslateX; boolean first = true; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { if (first) { first = false; lastX = ev.getX(); } float newTranslationX = stickersTab.getTranslationX(); if (stickersTab.getScrollX() == 0 && newTranslationX == 0) { if (!startedScroll && lastX - ev.getX() < 0) { if (pager.beginFakeDrag()) { startedScroll = true; lastTranslateX = stickersTab.getTranslationX(); } } else if (startedScroll && lastX - ev.getX() > 0) { if (pager.isFakeDragging()) { pager.endFakeDrag(); startedScroll = false; } } } if (startedScroll) { int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX); try { pager.fakeDragBy(dx); lastTranslateX = newTranslationX; } catch (Exception e) { try { pager.endFakeDrag(); } catch (Exception e2) { //don't promt } startedScroll = false; FileLog.e("tmessages", e); } } lastX = ev.getX(); if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) { first = true; if (startedScroll) { pager.endFakeDrag(); startedScroll = false; } } return startedScroll || super.onTouchEvent(ev); } }; stickersTab.setUnderlineHeight(AndroidUtilities.dp(1)); stickersTab.setIndicatorColor(0xffe2e5e7); stickersTab.setUnderlineColor(0xffe2e5e7); stickersTab.setBackgroundColor(0xfff5f6f7); stickersTab.setVisibility(INVISIBLE); addView(stickersTab, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP)); stickersTab.setTranslationX(AndroidUtilities.displaySize.x); updateStickerTabs(); stickersTab.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() { @Override public void onPageSelected(int page) { if (gifsGridView != null) { if (page == gifTabNum + 1) { if (gifsGridView.getVisibility() != VISIBLE) { listener.onGifTab(true); showGifTab(); } } else if (page == trendingTabNum + 1) { if (trendingGridView.getVisibility() != VISIBLE) { showTrendingTab(); } } else { if (gifsGridView.getVisibility() == VISIBLE) { listener.onGifTab(false); gifsGridView.setVisibility(GONE); stickersGridView.setVisibility(VISIBLE); stickersEmptyView .setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE); saveNewPage(); } else if (trendingGridView.getVisibility() == VISIBLE) { trendingGridView.setVisibility(GONE); stickersGridView.setVisibility(VISIBLE); stickersEmptyView .setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE); saveNewPage(); } } } if (page == 0) { pager.setCurrentItem(0); return; } else { if (page == gifTabNum + 1 || page == trendingTabNum + 1) { return; } else if (page == recentTabBum + 1) { stickersLayoutManager.scrollToPositionWithOffset(0, 0); checkStickersTabY(null, 0); stickersTab.onPageScrolled(recentTabBum + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1); return; } } int index = page - 1 - stickersTabOffset; if (index >= stickerSets.size()) { if (listener != null) { listener.onStickersSettingsClick(); } return; } if (index >= stickerSets.size()) { index = stickerSets.size() - 1; } stickersLayoutManager.scrollToPositionWithOffset( stickersGridAdapter.getPositionForPack(stickerSets.get(index)), 0); checkStickersTabY(null, 0); checkScroll(); } }); stickersGridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkScroll(); checkStickersTabY(recyclerView, dy); } }); } pager = new ViewPager(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pager.setAdapter(new EmojiPagesAdapter()); emojiTab = new LinearLayout(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; emojiTab.setOrientation(LinearLayout.HORIZONTAL); addView(emojiTab, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48)); pagerSlidingTabStrip = new PagerSlidingTabStrip(context); pagerSlidingTabStrip.setViewPager(pager); pagerSlidingTabStrip.setShouldExpand(true); pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(0)); pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); //? ? pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2); pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7); emojiTab.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f)); pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { EmojiView.this.onPageScrolled(position, getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), positionOffsetPixels); } @Override public void onPageSelected(int position) { saveNewPage(); } @Override public void onPageScrollStateChanged(int state) { } }); FrameLayout frameLayout = new FrameLayout(context); emojiTab.addView(frameLayout, LayoutHelper.createLinear(52, 48)); backspaceButton = new ImageView(context) { @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { backspacePressed = true; backspaceOnce = false; postBackspaceRunnable(350); } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) { backspacePressed = false; if (!backspaceOnce) { if (listener != null && listener.onBackspace()) { backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); } } } super.onTouchEvent(event); return true; } }; backspaceButton.setImageResource(kr.wdream.storyshop.R.drawable.ic_smiles_backspace); backspaceButton.setBackgroundResource(kr.wdream.storyshop.R.drawable.ic_emoji_backspace); backspaceButton.setScaleType(ImageView.ScaleType.CENTER); frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48)); View view = new View(context); view.setBackgroundColor(0xffe2e5e7); frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM)); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoRecent", kr.wdream.storyshop.R.string.NoRecent)); textView.setTextSize(18); textView.setTextColor(0xff888888); textView.setGravity(Gravity.CENTER); textView.setClickable(false); textView.setFocusable(false); ((FrameLayout) views.get(0)).addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0)); emojiGrids.get(0).setEmptyView(textView); addView(pager, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); emojiSize = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 40 : 32); pickerView = new EmojiColorPickerView(context); pickerViewPopup = new EmojiPopupWindow(pickerView, popupWidth = AndroidUtilities.dp((AndroidUtilities.isTablet() ? 40 : 32) * 6 + 10 + 4 * 5), popupHeight = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 64 : 56)); pickerViewPopup.setOutsideTouchable(true); pickerViewPopup.setClippingEnabled(true); pickerViewPopup.setInputMethodMode(EmojiPopupWindow.INPUT_METHOD_NOT_NEEDED); pickerViewPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED); pickerViewPopup.getContentView().setFocusableInTouchMode(true); pickerViewPopup.getContentView().setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP && pickerViewPopup != null && pickerViewPopup.isShowing()) { pickerViewPopup.dismiss(); return true; } return false; } }); currentPage = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE).getInt("selected_page", 0); loadRecents(); }
From source file:github.popeen.dsub.fragments.SelectDirectoryFragment.java
private void setupCoverArtImpl(RecyclingImageView coverArtView) { final ImageLoader imageLoader = getImageLoader(); // Try a few times to get a random cover art if (artistInfo != null) { final String url = artistInfo.getImageUrl(); coverArtView.setOnClickListener(new View.OnClickListener() { @Override//from ww w .ja v a 2 s .c om public void onClick(View v) { if (url == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(context); ImageView fullScreenView = new ImageView(context); imageLoader.loadImage(fullScreenView, url, true); builder.setCancelable(true); AlertDialog imageDialog = builder.create(); // Set view here with unecessary 0's to remove top/bottom border imageDialog.setView(fullScreenView, 0, 0, 0, 0); imageDialog.show(); } }); imageLoader.loadImage(coverArtView, url, false); } else if (entries.size() > 0) { coverArtRep = null; this.coverArtView = coverArtView; for (int i = 0; (i < 3) && (coverArtRep == null || coverArtRep.getCoverArt() == null); i++) { coverArtRep = entries.get(random.nextInt(entries.size())); } coverArtView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (coverArtRep == null || coverArtRep.getCoverArt() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(context); ImageView fullScreenView = new ImageView(context); imageLoader.loadImage(fullScreenView, coverArtRep, true, true); builder.setCancelable(true); AlertDialog imageDialog = builder.create(); // Set view here with unecessary 0's to remove top/bottom border imageDialog.setView(fullScreenView, 0, 0, 0, 0); imageDialog.show(); } }); synchronized (coverArtRep) { coverArtId = coverArtRep.getCoverArt(); updateCoverArtTask = imageLoader.loadImage(coverArtView, coverArtRep, false, true); } } coverArtView.setOnInvalidated(new RecyclingImageView.OnInvalidated() { @Override public void onInvalidated(RecyclingImageView imageView) { setupCoverArtImpl(imageView); } }); }
From source file:com.example.android.recyclingbanks.MainActivity.java
private View prepareInfoView(final Marker marker) { // TODO change this to xml? //prepare InfoView programmatically final LinearLayout infoView = new LinearLayout(MainActivity.this); LinearLayout.LayoutParams infoViewParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); infoView.setOrientation(LinearLayout.VERTICAL); // attach the above layout to the infoView infoView.setLayoutParams(infoViewParams); String markerLongitude = Double.toString(marker.getPosition().longitude); String markerLatitude = Double.toString(marker.getPosition().latitude); final String imageURL = "https://maps.googleapis.com/maps/api/streetview?size=" + "500x300&location=" + markerLatitude + "," + markerLongitude + "&fov=120&heading=0&pitch=0"; //create street view preview @ top ImageView streetViewPreviewIV = new ImageView(MainActivity.this); Log.wtf("comparing TAG", String.valueOf(marker.getTag())); if (marker.getTag() == null) { Log.i("prepareInfoView", "fetching image"); Picasso.with(this).load(imageURL).fetch(new MarkerCallback(marker)); } else {/*w w w .ja v a 2 s . c om*/ Log.wtf("prepareInfoView", "building info window"); // this scales the image to match parents WIDTH?, but retain image's height?? LinearLayout.LayoutParams streetViewImageViewParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); streetViewPreviewIV.setLayoutParams(streetViewImageViewParams); // TODO upon conversion to xml, the imageView needs these to scale image to box // android:scaleType="fitStart" // android:adjustViewBounds="true" Picasso.with(MainActivity.this).load(imageURL).into(streetViewPreviewIV); infoView.addView(streetViewPreviewIV); //Log.wtf("prepareInfoView, marker tag set?", String.valueOf(marker.getTag())); //Picasso.with(this).setLoggingEnabled(true); } // create text boxes LinearLayout subInfoView = new LinearLayout(MainActivity.this); LinearLayout.LayoutParams subInfoViewParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); subInfoView.setOrientation(LinearLayout.VERTICAL); subInfoView.setLayoutParams(subInfoViewParams); TextView titleTextView = new TextView(MainActivity.this); titleTextView.setText(marker.getTitle()); TextView snippetTextView = new TextView(MainActivity.this); snippetTextView.setText(marker.getSnippet()); subInfoView.addView(titleTextView); subInfoView.addView(snippetTextView); infoView.addView(subInfoView); // add the image on the right ImageView streetViewIcon = new ImageView(MainActivity.this); // this scales the image to match parents height. LinearLayout.LayoutParams imageViewParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); streetViewIcon.setLayoutParams(imageViewParams); Drawable drawable = ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_streetview); streetViewIcon.setImageDrawable(drawable); infoView.addView(streetViewIcon); //Picasso.with(this).load(imageURL).into(streetViewPreviewIV, new MarkerCallback(marker)); return infoView; }
From source file:com.money.manager.ex.home.MainActivity.java
private void startSyncIconRotation(MenuItem item) { if (item == null) return;/* ww w.j a va 2 s . c o 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.setInterpolator(new LinearInterpolator()); animation.setDuration(1200); // animRotate = AnimationUtils.loadAnimation(this, R.anim.rotation); animation.setRepeatCount(Animation.INFINITE); ImageView imageView = new ImageView(this); UIHelper uiHelper = new UIHelper(this); imageView.setImageDrawable( uiHelper.getIcon(GoogleMaterial.Icon.gmd_cached).color(uiHelper.getToolbarItemColor())); imageView.setPadding(8, 8, 8, 8); // imageView.setLayoutParams(new Toolbar.LayoutParams()); imageView.startAnimation(animation); item.setActionView(imageView); }
From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java
private View makeView(boolean icon, boolean watcher, boolean closeable, float density) { int size = (int) (48f * density); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setGravity(Gravity.CENTER_VERTICAL); ImageView iconView = null;//w ww. j a v a 2 s. co m if (icon) { iconView = new ImageView(context); iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); linearLayout.addView(iconView, (int) (24f * density), size); } TextView textView = makeCommonTextView(false); linearLayout.addView(textView, new LinearLayout.LayoutParams(0, size, 1)); WatcherView watcherView = null; if (watcher) { watcherView = new WatcherView(context); linearLayout.addView(watcherView, size, size); } ImageView closeView = null; if (!watcher && closeable) { closeView = new ImageView(context); closeView.setScaleType(ImageView.ScaleType.CENTER); closeView.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonCancel, 0)); closeView.setBackgroundResource(ResourceUtils.getResourceId(context, android.R.attr.borderlessButtonStyle, android.R.attr.background, 0)); linearLayout.addView(closeView, size, size); closeView.setOnClickListener(closeButtonListener); } ViewHolder holder = new ViewHolder(); holder.icon = iconView; holder.text = textView; holder.extra = watcherView != null ? watcherView : closeView; linearLayout.setTag(holder); int layoutLeftDp = 0; int layoutRightDp = 0; int textLeftDp; int textRightDp; if (C.API_LOLLIPOP) { textLeftDp = 16; textRightDp = 16; if (icon) { layoutLeftDp = 16; textLeftDp = 32; } if (watcher || closeable) { layoutRightDp = 4; textRightDp = 8; } } else { textLeftDp = 8; textRightDp = 8; if (icon) { layoutLeftDp = 8; textLeftDp = 6; textView.setAllCaps(true); } if (watcher || closeable) { layoutRightDp = 0; textRightDp = 0; } } linearLayout.setPadding((int) (layoutLeftDp * density), 0, (int) (layoutRightDp * density), 0); textView.setPadding((int) (textLeftDp * density), 0, (int) (textRightDp * density), 0); return linearLayout; }
From source file:github.daneren2005.dsub.fragments.SelectDirectoryFragment.java
private void setupCoverArt(View header) { final ImageLoader imageLoader = getImageLoader(); View coverArtView = header.findViewById(R.id.select_album_art); // Try a few times to get a random cover art if (artistInfo != null) { final String url = artistInfo.getImageUrl(); coverArtView.setOnClickListener(new View.OnClickListener() { @Override// w ww.j a va2s. c o m public void onClick(View v) { if (url == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(context); ImageView fullScreenView = new ImageView(context); imageLoader.loadImage(fullScreenView, url, true); builder.setCancelable(true); AlertDialog imageDialog = builder.create(); // Set view here with unecessary 0's to remove top/bottom border imageDialog.setView(fullScreenView, 0, 0, 0, 0); imageDialog.show(); } }); imageLoader.loadImage(coverArtView, url, false); } else if (entries.size() > 0) { Entry coverArt = null; for (int i = 0; (i < 3) && (coverArt == null || coverArt.getCoverArt() == null); i++) { coverArt = entries.get(random.nextInt(entries.size())); } final Entry albumRep = coverArt; coverArtView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (albumRep.getCoverArt() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(context); ImageView fullScreenView = new ImageView(context); imageLoader.loadImage(fullScreenView, albumRep, true, true); builder.setCancelable(true); AlertDialog imageDialog = builder.create(); // Set view here with unecessary 0's to remove top/bottom border imageDialog.setView(fullScreenView, 0, 0, 0, 0); imageDialog.show(); } }); imageLoader.loadImage(coverArtView, albumRep, false, true); } }
From source file:com.keylesspalace.tusky.ComposeActivity.java
private void makeCaptionDialog(QueuedMedia item) { LinearLayout dialogLayout = new LinearLayout(this); int padding = Utils.dpToPx(this, 8); dialogLayout.setPadding(padding, padding, padding, padding); dialogLayout.setOrientation(LinearLayout.VERTICAL); ImageView imageView = new ImageView(this); DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); Picasso.with(this).load(item.uri).resize(displayMetrics.widthPixels, displayMetrics.heightPixels) .onlyScaleDown().into(imageView); int margin = Utils.dpToPx(this, 4); dialogLayout.addView(imageView);// ww w . ja v a 2 s.c om ((LinearLayout.LayoutParams) imageView.getLayoutParams()).weight = 1; imageView.getLayoutParams().height = 0; ((LinearLayout.LayoutParams) imageView.getLayoutParams()).setMargins(0, margin, 0, 0); EditText input = new EditText(this); input.setHint(R.string.hint_describe_for_visually_impaired); dialogLayout.addView(input); ((LinearLayout.LayoutParams) input.getLayoutParams()).setMargins(margin, margin, margin, margin); input.setLines(1); input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); input.setText(item.description); DialogInterface.OnClickListener okListener = (dialog, which) -> { mastodonApi.updateMedia(item.id, input.getText().toString()).enqueue(new Callback<Attachment>() { @Override public void onResponse(@NonNull Call<Attachment> call, @NonNull Response<Attachment> response) { Attachment attachment = response.body(); if (response.isSuccessful() && attachment != null) { item.description = attachment.getDescription(); item.preview.setChecked(item.description != null && !item.description.isEmpty()); dialog.dismiss(); } else { showFailedCaptionMessage(); } } @Override public void onFailure(@NonNull Call<Attachment> call, @NonNull Throwable t) { showFailedCaptionMessage(); } }); }; AlertDialog dialog = new AlertDialog.Builder(this).setView(dialogLayout) .setPositiveButton(android.R.string.ok, okListener).setNegativeButton(android.R.string.cancel, null) .create(); Window window = dialog.getWindow(); if (window != null) { window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); } dialog.show(); }