List of usage examples for android.widget FrameLayout FrameLayout
public FrameLayout(@NonNull Context context)
From source file:jfabrix101.lib.fragmentActivity.AbstractFragmentActivityController.java
/** * Crea un layout in landscape utilizzando due fragment di peso proporzionale * Per cambiare le dimensioni dei pesi effettuare l'override dei * metodi <code>getLeftFragmentSize</code> e <code>getRightFragmentSize</code> */// w ww . ja v a2s. c o m @SuppressWarnings("all") protected View makeLandscapeLayout(LayoutInflater inflater) { if (getLayoutResourceId() > 0) { View v = inflater.inflate(getLayoutResourceId(), null); mVisualizationMode = VisualizationMode.LANDSCAPE; return v; } else { LinearLayout layout = new LinearLayout(this); layout.setPadding(10, 10, 10, 10); layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); layout.setOrientation(LinearLayout.HORIZONTAL); FrameLayout leftFrame = new FrameLayout(this); leftFrame.setId(getLeftFragmentId()); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LayoutParams.FILL_PARENT, getLeftFragmentWeigth()); leftFrame.setLayoutParams(lp); FrameLayout rightFrame = new FrameLayout(this); rightFrame.setId(getRightFragmentId()); lp = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, getRightFragmentWeigth()); rightFrame.setLayoutParams(lp); layout.addView(leftFrame); layout.addView(rightFrame); mVisualizationMode = VisualizationMode.LANDSCAPE; return layout; } }
From source file:kr.wdream.ui.WallpapersActivity.java
@Override public View createView(Context context) { Log.d(LOG_TAG, "createView"); actionBar.setBackButtonImage(kr.wdream.storyshop.R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(// w w w . j ava2 s . c o m LocaleController.getString("ChatBackground", kr.wdream.storyshop.R.string.ChatBackground)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { boolean done; TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground); if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) { int width = AndroidUtilities.displaySize.x; int height = AndroidUtilities.displaySize.y; if (width > height) { int temp = width; width = height; height = temp; } TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, Math.min(width, height)); String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg"; File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName); File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg"); try { done = AndroidUtilities.copyFile(f, toFile); } catch (Exception e) { done = false; FileLog.e("tmessages", e); } } else { if (selectedBackground == -1) { File fromFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper-temp.jpg"); File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg"); done = fromFile.renameTo(toFile); } else { done = true; } } if (done) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("selectedBackground", selectedBackground); editor.putInt("selectedColor", selectedColor); editor.commit(); ApplicationLoader.reloadWallpaper(); } finishFragment(); } } }); ActionBarMenu menu = actionBar.createMenu(); doneButton = menu.addItemWithWidth(done_button, kr.wdream.storyshop.R.drawable.ic_done, AndroidUtilities.dp(56)); FrameLayout frameLayout = new FrameLayout(context); fragmentView = frameLayout; backgroundImage = new ImageView(context); backgroundImage.setScaleType(ImageView.ScaleType.CENTER_CROP); frameLayout.addView(backgroundImage, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); backgroundImage.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); progressView = new FrameLayout(context); progressView.setVisibility(View.INVISIBLE); frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 52)); progressViewBackground = new View(context); progressViewBackground.setBackgroundResource(kr.wdream.storyshop.R.drawable.system_loader); progressView.addView(progressViewBackground, LayoutHelper.createFrame(36, 36, Gravity.CENTER)); ProgressBar progressBar = new ProgressBar(context); try { progressBar.setIndeterminateDrawable( context.getResources().getDrawable(kr.wdream.storyshop.R.drawable.loading_animation)); } catch (Exception e) { //don't promt } progressBar.setIndeterminate(true); AndroidUtilities.setProgressBarAnimationDuration(progressBar, 1500); progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER)); RecyclerListView listView = new RecyclerListView(context); listView.setClipToPadding(false); listView.setTag(8); listView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0); LinearLayoutManager layoutManager = new LinearLayoutManager(context); layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); listView.setLayoutManager(layoutManager); listView.setDisallowInterceptTouchEvents(true); listView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); listView.setAdapter(listAdapter = new ListAdapter(context)); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 102, Gravity.LEFT | Gravity.BOTTOM)); listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (position == 0) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items = new CharSequence[] { LocaleController.getString("FromCamera", kr.wdream.storyshop.R.string.FromCamera), LocaleController.getString("FromGalley", kr.wdream.storyshop.R.string.FromGalley), LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel) }; builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { try { if (i == 0) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File image = AndroidUtilities.generatePicturePath(); if (image != null) { if (Build.VERSION.SDK_INT >= 24) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", image)); takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); } currentPicturePath = image.getAbsolutePath(); } startActivityForResult(takePictureIntent, 10); } else if (i == 1) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 11); } } catch (Exception e) { FileLog.e("tmessages", e); } } }); showDialog(builder.create()); } else { if (position - 1 < 0 || position - 1 >= wallPapers.size()) { return; } TLRPC.WallPaper wallPaper = wallPapers.get(position - 1); selectedBackground = wallPaper.id; listAdapter.notifyDataSetChanged(); processSelectedBackground(); } } }); processSelectedBackground(); return fragmentView; }
From source file:com.ashlikun.badgeview.BadgeView.java
public void setTargetView(View target) { if (getParent() != null) { ((ViewGroup) getParent()).removeView(this); }// w w w. j a v a 2 s .c o m if (target == null) { return; } if (target.getParent() instanceof FrameLayout) { ((FrameLayout) target.getParent()).addView(this); } else if (target.getParent() instanceof ViewGroup) { // use a new Framelayout container for adding badge ViewGroup parentContainer = (ViewGroup) target.getParent(); int groupIndex = parentContainer.indexOfChild(target); parentContainer.removeView(target); FrameLayout badgeContainer = new FrameLayout(getContext()); ViewGroup.LayoutParams parentLayoutParams = target.getLayoutParams(); badgeContainer.setLayoutParams(parentLayoutParams); target.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); parentContainer.addView(badgeContainer, groupIndex, parentLayoutParams); badgeContainer.addView(target); badgeContainer.addView(this); } else if (target.getParent() == null) { Log.e(getClass().getSimpleName(), "ParentView is needed"); } }
From source file:com.achep.base.ui.DialogBuilder.java
private View createSkeleton() { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout rootLayout = (LinearLayout) inflater.inflate(R.layout.dialog_main_skeleton, new FrameLayout(mContext), false); TextView titleView = (TextView) rootLayout.findViewById(R.id.title); if (Device.hasLollipopApi()) { // The dividers are quite ugly with material design. rootLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE); }/*from w ww. j a v a 2 s . c om*/ if (mTitleText == null && mIcon == null) { rootLayout.removeView(titleView); } else { if (mTitleText != null) titleView.setText(mTitleText); if (mIcon != null) titleView.setCompoundDrawablesWithIntrinsicBounds(mIcon, null, null, null); } return rootLayout; }
From source file:com.github.yggie.pulltorefresh.PullListFragment.java
/** * Called to do initial creation of the fragment. Creates all the Views in code * * @param inflater The LayoutInflater//from w ww . ja v a 2s. c om * @param container The parent container * @param savedInstanceState The saved pullState * @return The inflated view */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Context context = getActivity(); // setup the list view listView = new CustomListView(this); listView.setId(ID_LIST_VIEW); final RelativeLayout.LayoutParams listViewParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); listViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); listViewParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); listView.setLayoutParams(listViewParams); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { onListItemClick((ListView) adapterView, view, position, id); } }); // setup the empty view final TextView textView = new TextView(context); textView.setLayoutParams(listViewParams); textView.setGravity(Gravity.CENTER); textView.setText("Nothing to show"); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18.0f); emptyView = textView; emptyView.setId(ID_EMPTY_VIEW); // setup top pulled view final RelativeLayout.LayoutParams topViewParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); topViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); topViewParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); final FrameLayout topFrameLayout = new FrameLayout(context); topFrameLayout.setLayoutParams(topViewParams); // setup the default child of the FrameLayout topManager = new DefaultPulledView(this, true); topFrameLayout.addView(topManager); topPulledView = topFrameLayout; topPulledView.setId(ID_TOP_VIEW); // setup bottom pulled view final RelativeLayout.LayoutParams bottomViewParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); bottomViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); bottomViewParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); final FrameLayout bottomFrameLayout = new FrameLayout(context); bottomFrameLayout.setLayoutParams(bottomViewParams); // setup the default child in the FrameLayout bottomManager = new DefaultPulledView(this, false); bottomFrameLayout.addView(bottomManager); bottomPulledView = bottomFrameLayout; bottomPulledView.setId(ID_BOTTOM_VIEW); layout = new PullToRefreshLayout(this); layout.addView(topPulledView); layout.addView(bottomPulledView); layout.addView(listView); layout.addView(emptyView); layout.setId(ID_LAYOUT); listShown = false; listView.setVisibility(View.GONE); emptyView.setVisibility(View.VISIBLE); // applies the XML attributes, if exists if (attrs != null) { final TypedArray a = getActivity().obtainStyledAttributes(attrs, R.styleable.PullListFragment); if (a != null) { parseXmlAttributes(a); a.recycle(); } attrs = null; } return layout; }
From source file:it.geosolutions.geocollect.android.core.form.FormPageFragment.java
/** * Creates the page content cycling the page fields *//* ww w . jav a 2 s .c om*/ private void buildForm() { if (BuildConfig.DEBUG) { Log.d(TAG, "buildForm()"); } // if the view hierarchy was already build, skip this if (mDone) { return; } FormBuilder.buildForm(getActivity(), this.mFormView, page.fields, mission);//TODO page is not enough, some data should be accessible like constants and data // It is safe to initialize field here because buildForm is a callback of the onActivityCreated(); PersistenceUtils.loadPageData(page, mFormView, mission, getActivity(), true); // TODO: add a timer and start an animation for the tutorial if (page.attributes != null && page.attributes.containsKey("tutorial")) { if (page.attributes.get("tutorial") != null && page.attributes.get("tutorial") instanceof Boolean && (Boolean) page.attributes.get("tutorial")) { Log.v(TAG, "Showing tutorial"); // create new Layout FrameLayout overlayFramelayout = new FrameLayout(getSherlockActivity()); View view = getSherlockActivity().getLayoutInflater().inflate(R.layout.swipe_overlay, overlayFramelayout, false); overlayFramelayout.addView(view); // Viewpager layoutparams LayoutParams layoutParams = new LayoutParams(); layoutParams.gravity = Gravity.BOTTOM; //getSherlockActivity().addContentView(overlayFramelayout, layoutParams); this.mFormView.addView(overlayFramelayout, layoutParams); } } // the view hierarchy is now complete mDone = true; // TODO: merge this code block with the previous "tutorial" if (visibleToUser && page.attributes != null && page.attributes.containsKey("message")) { Toast.makeText(getSherlockActivity(), (String) page.attributes.get("message"), Toast.LENGTH_LONG) .show(); } }
From source file:org.telegram.ui.Components.AudioPlayerAlert.java
public AudioPlayerAlert(final Context context) { super(context, true); MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject(); if (messageObject != null) { currentAccount = messageObject.currentAccount; } else {/* w w w . ja v a2 s.co m*/ currentAccount = UserConfig.selectedAccount; } parentActivity = (LaunchActivity) context; noCoverDrawable = context.getResources().getDrawable(R.drawable.nocover).mutate(); noCoverDrawable.setColorFilter( new PorterDuffColorFilter(Theme.getColor(Theme.key_player_placeholder), PorterDuff.Mode.MULTIPLY)); TAG = DownloadController.getInstance(currentAccount).generateObserverTag(); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingPlayStateChanged); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidStart); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingProgressDidChanged); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.musicDidLoad); shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow).mutate(); shadowDrawable.setColorFilter( new PorterDuffColorFilter(Theme.getColor(Theme.key_player_background), PorterDuff.Mode.MULTIPLY)); paint.setColor(Theme.getColor(Theme.key_player_placeholderBackground)); containerView = new FrameLayout(context) { private boolean ignoreLayout = false; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY && placeholderImageView.getTranslationX() == 0) { dismiss(); return true; } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent e) { return !isDismissed() && super.onTouchEvent(e); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.getSize(heightMeasureSpec); int contentSize = AndroidUtilities.dp(178) + playlist.size() * AndroidUtilities.dp(56) + backgroundPaddingTop + ActionBar.getCurrentActionBarHeight() + AndroidUtilities.statusBarHeight; int padding; heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (searching) { padding = AndroidUtilities.dp(178) + ActionBar.getCurrentActionBarHeight() + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0); } else { if (contentSize < height) { padding = height - contentSize; } else { padding = (contentSize < height ? 0 : height - (height / 5 * 3)); } padding += ActionBar.getCurrentActionBarHeight() + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0); } if (listView.getPaddingTop() != padding) { ignoreLayout = true; listView.setPadding(0, padding, 0, AndroidUtilities.dp(8)); ignoreLayout = false; } super.onMeasure(widthMeasureSpec, heightMeasureSpec); inFullSize = getMeasuredHeight() >= height; int availableHeight = height - ActionBar.getCurrentActionBarHeight() - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.dp(120); int maxSize = Math.max(availableHeight, getMeasuredWidth()); thumbMaxX = (getMeasuredWidth() - maxSize) / 2 - AndroidUtilities.dp(17); thumbMaxY = AndroidUtilities.dp(19); panelEndTranslation = getMeasuredHeight() - playerLayout.getMeasuredHeight(); thumbMaxScale = maxSize / (float) placeholderImageView.getMeasuredWidth() - 1.0f; endTranslation = ActionBar.getCurrentActionBarHeight() + AndroidUtilities.dp(5); int scaledHeight = (int) Math .ceil(placeholderImageView.getMeasuredHeight() * (1.0f + thumbMaxScale)); if (scaledHeight > availableHeight) { endTranslation -= (scaledHeight - availableHeight); } } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); int y = actionBar.getMeasuredHeight(); shadow.layout(shadow.getLeft(), y, shadow.getRight(), y + shadow.getMeasuredHeight()); updateLayout(); setFullAnimationProgress(fullAnimationProgress); } @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } @Override protected void onDraw(Canvas canvas) { shadowDrawable.setBounds(0, Math.max(actionBar.getMeasuredHeight(), scrollOffsetY) - backgroundPaddingTop, getMeasuredWidth(), getMeasuredHeight()); shadowDrawable.draw(canvas); } }; containerView.setWillNotDraw(false); containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0); actionBar = new ActionBar(context); actionBar.setBackgroundColor(Theme.getColor(Theme.key_player_actionBar)); actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setItemsColor(Theme.getColor(Theme.key_player_actionBarItems), false); actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_player_actionBarSelector), false); actionBar.setTitleColor(Theme.getColor(Theme.key_player_actionBarTitle)); actionBar.setSubtitleColor(Theme.getColor(Theme.key_player_actionBarSubtitle)); actionBar.setAlpha(0.0f); actionBar.setTitle("1"); actionBar.setSubtitle("1"); actionBar.getTitleTextView().setAlpha(0.0f); actionBar.getSubtitleTextView().setAlpha(0.0f); avatarContainer = new ChatAvatarContainer(context, null, false); avatarContainer.setEnabled(false); avatarContainer.setTitleColors(Theme.getColor(Theme.key_player_actionBarTitle), Theme.getColor(Theme.key_player_actionBarSubtitle)); if (messageObject != null) { long did = messageObject.getDialogId(); int lower_id = (int) did; int high_id = (int) (did >> 32); if (lower_id != 0) { if (lower_id > 0) { TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(lower_id); if (user != null) { avatarContainer.setTitle(ContactsController.formatName(user.first_name, user.last_name)); avatarContainer.setUserAvatar(user); } } else { TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id); if (chat != null) { avatarContainer.setTitle(chat.title); avatarContainer.setChatAvatar(chat); } } } else { TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount) .getEncryptedChat(high_id); if (encryptedChat != null) { TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(encryptedChat.user_id); if (user != null) { avatarContainer.setTitle(ContactsController.formatName(user.first_name, user.last_name)); avatarContainer.setUserAvatar(user); } } } } avatarContainer.setSubtitle(LocaleController.getString("AudioTitle", R.string.AudioTitle)); actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0)); ActionBarMenu menu = actionBar.createMenu(); menuItem = menu.addItem(0, R.drawable.ic_ab_other); menuItem.addSubItem(1, LocaleController.getString("Forward", R.string.Forward)); menuItem.addSubItem(2, LocaleController.getString("ShareFile", R.string.ShareFile)); //menuItem.addSubItem(3, LocaleController.getString("Delete", R.string.Delete)); menuItem.addSubItem(4, LocaleController.getString("ShowInChat", R.string.ShowInChat)); menuItem.setTranslationX(AndroidUtilities.dp(48)); menuItem.setAlpha(0.0f); searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchCollapse() { avatarContainer.setVisibility(View.VISIBLE); if (hasOptions) { menuItem.setVisibility(View.INVISIBLE); } if (searching) { searchWas = false; searching = false; setAllowNestedScroll(true); listAdapter.search(null); } } @Override public void onSearchExpand() { searchOpenPosition = layoutManager.findLastVisibleItemPosition(); View firstVisView = layoutManager.findViewByPosition(searchOpenPosition); searchOpenOffset = ((firstVisView == null) ? 0 : firstVisView.getTop()) - listView.getPaddingTop(); avatarContainer.setVisibility(View.GONE); if (hasOptions) { menuItem.setVisibility(View.GONE); } searching = true; setAllowNestedScroll(false); listAdapter.notifyDataSetChanged(); } @Override public void onTextChanged(EditText editText) { if (editText.length() > 0) { listAdapter.search(editText.getText().toString()); } else { searchWas = false; listAdapter.search(null); } } }); EditTextBoldCursor editText = searchItem.getSearchField(); editText.setHint(LocaleController.getString("Search", R.string.Search)); editText.setTextColor(Theme.getColor(Theme.key_player_actionBarTitle)); editText.setHintTextColor(Theme.getColor(Theme.key_player_time)); editText.setCursorColor(Theme.getColor(Theme.key_player_actionBarTitle)); if (!AndroidUtilities.isTablet()) { actionBar.showActionModeTop(); actionBar.setActionModeTopColor(Theme.getColor(Theme.key_player_actionBarTop)); } actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { dismiss(); } else { onSubItemClick(id); } } }); shadow = new View(context); shadow.setAlpha(0.0f); shadow.setBackgroundResource(R.drawable.header_shadow); shadow2 = new View(context); shadow2.setAlpha(0.0f); shadow2.setBackgroundResource(R.drawable.header_shadow); playerLayout = new FrameLayout(context); playerLayout.setBackgroundColor(Theme.getColor(Theme.key_player_background)); placeholderImageView = new BackupImageView(context) { private RectF rect = new RectF(); @Override protected void onDraw(Canvas canvas) { if (hasNoCover == 1 || hasNoCover == 2 && (!getImageReceiver().hasBitmapImage() || getImageReceiver().getCurrentAlpha() != 1.0f)) { rect.set(0, 0, getMeasuredWidth(), getMeasuredHeight()); canvas.drawRoundRect(rect, getRoundRadius(), getRoundRadius(), paint); float plusScale = thumbMaxScale / getScaleX() / 3; int s = (int) (AndroidUtilities.dp(63) * Math.max(plusScale / thumbMaxScale, 1.0f / thumbMaxScale)); int x = (int) (rect.centerX() - s / 2); int y = (int) (rect.centerY() - s / 2); noCoverDrawable.setBounds(x, y, x + s, y + s); noCoverDrawable.draw(canvas); } if (hasNoCover != 1) { super.onDraw(canvas); } } }; placeholderImageView.setRoundRadius(AndroidUtilities.dp(20)); placeholderImageView.setPivotX(0); placeholderImageView.setPivotY(0); placeholderImageView.setOnClickListener(view -> { if (animatorSet != null) { animatorSet.cancel(); animatorSet = null; } animatorSet = new AnimatorSet(); if (scrollOffsetY <= actionBar.getMeasuredHeight()) { animatorSet.playTogether(ObjectAnimator.ofFloat(AudioPlayerAlert.this, "fullAnimationProgress", isInFullMode ? 0.0f : 1.0f)); } else { animatorSet.playTogether( ObjectAnimator.ofFloat(AudioPlayerAlert.this, "fullAnimationProgress", isInFullMode ? 0.0f : 1.0f), ObjectAnimator.ofFloat(actionBar, "alpha", isInFullMode ? 0.0f : 1.0f), ObjectAnimator.ofFloat(shadow, "alpha", isInFullMode ? 0.0f : 1.0f), ObjectAnimator.ofFloat(shadow2, "alpha", isInFullMode ? 0.0f : 1.0f)); } animatorSet.setInterpolator(new DecelerateInterpolator()); animatorSet.setDuration(250); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (animation.equals(animatorSet)) { if (!isInFullMode) { listView.setScrollEnabled(true); if (hasOptions) { menuItem.setVisibility(View.INVISIBLE); } searchItem.setVisibility(View.VISIBLE); } else { if (hasOptions) { menuItem.setVisibility(View.VISIBLE); } searchItem.setVisibility(View.INVISIBLE); } animatorSet = null; } } }); animatorSet.start(); if (hasOptions) { menuItem.setVisibility(View.VISIBLE); } searchItem.setVisibility(View.VISIBLE); isInFullMode = !isInFullMode; listView.setScrollEnabled(false); if (isInFullMode) { shuffleButton.setAdditionalOffset(-AndroidUtilities.dp(20 + 48)); } else { shuffleButton.setAdditionalOffset(-AndroidUtilities.dp(10)); } }); titleTextView = new TextView(context); titleTextView.setTextColor(Theme.getColor(Theme.key_player_actionBarTitle)); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); titleTextView.setEllipsize(TextUtils.TruncateAt.END); titleTextView.setSingleLine(true); playerLayout.addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 72, 18, 60, 0)); authorTextView = new TextView(context); authorTextView.setTextColor(Theme.getColor(Theme.key_player_time)); authorTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); authorTextView.setEllipsize(TextUtils.TruncateAt.END); authorTextView.setSingleLine(true); playerLayout.addView(authorTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 72, 40, 60, 0)); optionsButton = new ActionBarMenuItem(context, null, 0, Theme.getColor(Theme.key_player_actionBarItems)); optionsButton.setLongClickEnabled(false); optionsButton.setIcon(R.drawable.ic_ab_other); optionsButton.setAdditionalOffset(-AndroidUtilities.dp(120)); playerLayout.addView(optionsButton, LayoutHelper.createFrame(40, 40, Gravity.TOP | Gravity.RIGHT, 0, 19, 10, 0)); optionsButton.addSubItem(1, LocaleController.getString("Forward", R.string.Forward)); optionsButton.addSubItem(2, LocaleController.getString("ShareFile", R.string.ShareFile)); //optionsButton.addSubItem(3, LocaleController.getString("Delete", R.string.Delete)); optionsButton.addSubItem(4, LocaleController.getString("ShowInChat", R.string.ShowInChat)); optionsButton.setOnClickListener(v -> optionsButton.toggleSubMenu()); optionsButton.setDelegate(this::onSubItemClick); seekBarView = new SeekBarView(context); seekBarView.setDelegate(progress -> MediaController.getInstance() .seekToProgress(MediaController.getInstance().getPlayingMessageObject(), progress)); playerLayout.addView(seekBarView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 30, Gravity.TOP | Gravity.LEFT, 8, 62, 8, 0)); progressView = new LineProgressView(context); progressView.setVisibility(View.INVISIBLE); progressView.setBackgroundColor(Theme.getColor(Theme.key_player_progressBackground)); progressView.setProgressColor(Theme.getColor(Theme.key_player_progress)); playerLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 2, Gravity.TOP | Gravity.LEFT, 20, 78, 20, 0)); timeTextView = new SimpleTextView(context); timeTextView.setTextSize(12); timeTextView.setText("0:00"); timeTextView.setTextColor(Theme.getColor(Theme.key_player_time)); playerLayout.addView(timeTextView, LayoutHelper.createFrame(100, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 20, 92, 0, 0)); durationTextView = new TextView(context); durationTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); durationTextView.setTextColor(Theme.getColor(Theme.key_player_time)); durationTextView.setGravity(Gravity.CENTER); playerLayout.addView(durationTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.RIGHT, 0, 90, 20, 0)); FrameLayout bottomView = new FrameLayout(context) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int dist = ((right - left) - AndroidUtilities.dp(8 + 48 * 5)) / 4; for (int a = 0; a < 5; a++) { int l = AndroidUtilities.dp(4 + 48 * a) + dist * a; int t = AndroidUtilities.dp(9); buttons[a].layout(l, t, l + buttons[a].getMeasuredWidth(), t + buttons[a].getMeasuredHeight()); } } }; playerLayout.addView(bottomView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 66, Gravity.TOP | Gravity.LEFT, 0, 106, 0, 0)); buttons[0] = shuffleButton = new ActionBarMenuItem(context, null, 0, 0); shuffleButton.setLongClickEnabled(false); shuffleButton.setAdditionalOffset(-AndroidUtilities.dp(10)); bottomView.addView(shuffleButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); shuffleButton.setOnClickListener(v -> shuffleButton.toggleSubMenu()); TextView textView = shuffleButton.addSubItem(1, LocaleController.getString("ReverseOrder", R.string.ReverseOrder)); textView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(16), 0); playOrderButtons[0] = context.getResources().getDrawable(R.drawable.music_reverse).mutate(); textView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); textView.setCompoundDrawablesWithIntrinsicBounds(playOrderButtons[0], null, null, null); textView = shuffleButton.addSubItem(2, LocaleController.getString("Shuffle", R.string.Shuffle)); textView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(16), 0); playOrderButtons[1] = context.getResources().getDrawable(R.drawable.pl_shuffle).mutate(); textView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); textView.setCompoundDrawablesWithIntrinsicBounds(playOrderButtons[1], null, null, null); shuffleButton.setDelegate(id -> { MediaController.getInstance().toggleShuffleMusic(id); updateShuffleButton(); listAdapter.notifyDataSetChanged(); }); ImageView prevButton; buttons[1] = prevButton = new ImageView(context); prevButton.setScaleType(ImageView.ScaleType.CENTER); prevButton.setImageDrawable(Theme.createSimpleSelectorDrawable(context, R.drawable.pl_previous, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive))); bottomView.addView(prevButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); prevButton.setOnClickListener(v -> MediaController.getInstance().playPreviousMessage()); buttons[2] = playButton = new ImageView(context); playButton.setScaleType(ImageView.ScaleType.CENTER); playButton.setImageDrawable(Theme.createSimpleSelectorDrawable(context, R.drawable.pl_play, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive))); bottomView.addView(playButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); playButton.setOnClickListener(v -> { if (MediaController.getInstance().isDownloadingCurrentMessage()) { return; } if (MediaController.getInstance().isMessagePaused()) { MediaController.getInstance().playMessage(MediaController.getInstance().getPlayingMessageObject()); } else { MediaController.getInstance().pauseMessage(MediaController.getInstance().getPlayingMessageObject()); } }); ImageView nextButton; buttons[3] = nextButton = new ImageView(context); nextButton.setScaleType(ImageView.ScaleType.CENTER); nextButton.setImageDrawable(Theme.createSimpleSelectorDrawable(context, R.drawable.pl_next, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive))); bottomView.addView(nextButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); nextButton.setOnClickListener(v -> MediaController.getInstance().playNextMessage()); buttons[4] = repeatButton = new ImageView(context); repeatButton.setScaleType(ImageView.ScaleType.CENTER); repeatButton.setPadding(0, 0, AndroidUtilities.dp(8), 0); bottomView.addView(repeatButton, LayoutHelper.createFrame(50, 48, Gravity.LEFT | Gravity.TOP)); repeatButton.setOnClickListener(v -> { SharedConfig.toggleRepeatMode(); updateRepeatButton(); }); listView = new RecyclerListView(context) { boolean ignoreLayout; @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); if (searchOpenPosition != -1 && !actionBar.isSearchFieldVisible()) { ignoreLayout = true; layoutManager.scrollToPositionWithOffset(searchOpenPosition, searchOpenOffset); super.onLayout(false, l, t, r, b); ignoreLayout = false; searchOpenPosition = -1; } else if (scrollToSong) { scrollToSong = false; boolean found = false; MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject(); if (playingMessageObject != null) { int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); if (child instanceof AudioPlayerCell) { if (((AudioPlayerCell) child).getMessageObject() == playingMessageObject) { if (child.getBottom() <= getMeasuredHeight()) { found = true; } break; } } } if (!found) { int idx = playlist.indexOf(playingMessageObject); if (idx >= 0) { ignoreLayout = true; if (SharedConfig.playOrderReversed) { layoutManager.scrollToPosition(idx); } else { layoutManager.scrollToPosition(playlist.size() - idx); } super.onLayout(false, l, t, r, b); ignoreLayout = false; } } } } } @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } @Override protected boolean allowSelectChildAtPosition(float x, float y) { float p = playerLayout.getY() + playerLayout.getMeasuredHeight(); return playerLayout == null || y > playerLayout.getY() + playerLayout.getMeasuredHeight(); } @Override public boolean drawChild(Canvas canvas, View child, long drawingTime) { canvas.save(); canvas.clipRect(0, (actionBar != null ? actionBar.getMeasuredHeight() : 0) + AndroidUtilities.dp(50), getMeasuredWidth(), getMeasuredHeight()); boolean result = super.drawChild(canvas, child, drawingTime); canvas.restore(); return result; } }; listView.setPadding(0, 0, 0, AndroidUtilities.dp(8)); listView.setClipToPadding(false); listView.setLayoutManager( layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false)); listView.setHorizontalScrollBarEnabled(false); listView.setVerticalScrollBarEnabled(false); containerView.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); listView.setAdapter(listAdapter = new ListAdapter(context)); listView.setGlowColor(Theme.getColor(Theme.key_dialogScrollGlow)); listView.setOnItemClickListener((view, position) -> { if (view instanceof AudioPlayerCell) { ((AudioPlayerCell) view).didPressedButton(); } }); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) { AndroidUtilities.hideKeyboard(getCurrentFocus()); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { updateLayout(); } }); playlist = MediaController.getInstance().getPlaylist(); listAdapter.notifyDataSetChanged(); containerView.addView(playerLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 178)); containerView.addView(shadow2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3)); containerView.addView(placeholderImageView, LayoutHelper.createFrame(40, 40, Gravity.TOP | Gravity.LEFT, 17, 19, 0, 0)); containerView.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3)); containerView.addView(actionBar); updateTitle(false); updateRepeatButton(); updateShuffleButton(); }
From source file:dk.nordfalk.aktivitetsliste.PagerSlidingTabStrip.java
private void addIconTabBdeTekstOgBillede(final int position, int resId, String title) { FrameLayout tabfl = new FrameLayout(getContext()); ImageView tabi = new ImageView(getContext()); tabi.setContentDescription(title);/*from w ww. j a va 2 s . c o m*/ tabi.setImageResource(resId); tabi.setVisibility(View.INVISIBLE); TextView tabt = new TextView(getContext()); tabt.setText(title); tabt.setGravity(Gravity.CENTER); tabt.setSingleLine(); tabfl.addView(tabi); tabfl.addView(tabt); LayoutParams lp = (LayoutParams) tabi.getLayoutParams(); lp.gravity = Gravity.CENTER; lp = (LayoutParams) tabt.getLayoutParams(); lp.width = lp.height = ViewGroup.LayoutParams.MATCH_PARENT; lp.gravity = Gravity.CENTER; addTab(position, tabfl); }
From source file:com.handmark.pulltorefresh.library.PullToRefreshListView.java
@Override protected void handleStyledAttributes(TypedArray a) { super.handleStyledAttributes(a); mListViewExtrasEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrListViewExtrasEnabled, true); if (mListViewExtrasEnabled) { final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL); // Create Loading Views ready for use later FrameLayout frame = new FrameLayout(getContext()); mHeaderLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_START, a); mHeaderLoadingView.setVisibility(View.GONE); frame.addView(mHeaderLoadingView, lp); mRefreshableView.addHeaderView(frame, null, false); mLvFooterLoadingFrame = new FrameLayout(getContext()); mFooterLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_END, a); mFooterLoadingView.setVisibility(View.GONE); mLvFooterLoadingFrame.addView(mFooterLoadingView, lp); /**//from w ww. j a v a2s. c o m * If the value for Scrolling While Refreshing hasn't been * explicitly set via XML, enable Scrolling While Refreshing. */ if (!a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) { setScrollingWhileRefreshingEnabled(true); } } }