List of usage examples for java.lang Math hypot
public static double hypot(double x, double y)
From source file:sg.fxl.topekaport.QuizActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void prepareCircularReveal(View startView, FrameLayout targetView) { int centerX = (startView.getLeft() + startView.getRight()) / 2; // Subtract the start view's height to adjust for relative coordinates on screen. int centerY = (startView.getTop() + startView.getBottom()) / 2 - startView.getHeight(); float endRadius = (float) Math.hypot((double) centerX, (double) centerY); circularReveal = ViewAnimationUtils.createCircularReveal(targetView, centerX, centerY, startView.getWidth(), endRadius);/* ww w . ja v a2s . c o m*/ circularReveal.setInterpolator(new FastOutLinearInInterpolator()); circularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { icon.setVisibility(View.GONE); circularReveal.removeListener(this); } }); // Adding a color animation from the FAB's color to transparent creates a dissolve like // effect to the circular reveal. int accentColor = ContextCompat.getColor(this, quiz.getTheme().getAccentColor()); colorChange = ObjectAnimator.ofInt(targetView, ViewUtils.FOREGROUND_COLOR, accentColor, Color.TRANSPARENT); colorChange.setEvaluator(new ArgbEvaluator()); colorChange.setInterpolator(interpolator); }
From source file:uk.ac.diamond.scisoft.analysis.diffraction.powder.PixelIntegrationUtils.java
private static Dataset generateRadialArray(int[] shape, QSpace qSpace, XAxis xAxis, boolean radians) { if (qSpace == null) return null; double[] beamCentre = qSpace.getDetectorProperties().getBeamCentreCoords(); Dataset ra = DatasetFactory.zeros(shape, Dataset.FLOAT64); PositionIterator iter = ra.getPositionIterator(); int[] pos = iter.getPos(); while (iter.hasNext()) { Vector3d q;//w w w . ja v a 2s. co m double value = 0; //FIXME or not fix me, but I would expect centre to be +0.5, but this //clashes with much of the rest of DAWN q = qSpace.qFromPixelPosition(pos[1] + 0.5, pos[0] + 0.5); switch (xAxis) { case ANGLE: value = qSpace.scatteringAngle(q); if (!radians) value = Math.toDegrees(value); break; case Q: value = q.length(); break; case RESOLUTION: value = (2 * Math.PI) / q.length(); break; case PIXEL: value = Math.hypot(pos[1] - beamCentre[0] + 0.5, pos[0] - beamCentre[1] + 0.5); break; } ra.set(value, pos); } return ra; }
From source file:io.github.silencio_app.silencio.MainActivity.java
public void hideGraph(View view) { TextView tview = (TextView) findViewById(R.id.amp); tview.setText(getString(R.string.press_start)); // previously visible view final View myView = findViewById(R.id.graph); // get the center for the clipping circle int cx = myView.getWidth() / 2; int cy = myView.getHeight() / 2; // get the initial radius for the clipping circle float initialRadius = (float) Math.hypot(cx, cy); // create the animation (the final radius is zero) Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0); // make the view invisible when the animation is done anim.addListener(new AnimatorListenerAdapter() { @Override//from w w w. ja v a 2 s . c o m public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); // make graph and meter invisible myView.setVisibility(View.INVISIBLE); // db_meter.setVisibility(View.GONE); } }); // start the animation anim.start(); }
From source file:com.google.samples.apps.topeka.view.quiz.QuizActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void prepareCircularReveal(View startView, FrameLayout targetView, int themeAccentColor) { int centerX = (startView.getLeft() + startView.getRight()) / 2; // Subtract the start view's height to adjust for relative coordinates on screen. int centerY = (startView.getTop() + startView.getBottom()) / 2 - startView.getHeight(); float endRadius = (float) Math.hypot(centerX, centerY); mCircularReveal = ViewAnimationUtils.createCircularReveal(targetView, centerX, centerY, startView.getWidth(), endRadius); mCircularReveal.setInterpolator(new FastOutLinearInInterpolator()); mCircularReveal.addListener(new AnimatorListenerAdapter() { @Override/*from w w w. j a v a 2 s . co m*/ public void onAnimationEnd(Animator animation) { mIcon.setVisibility(View.GONE); mCircularReveal.removeListener(this); } }); // Adding a color animation from the FAB's color to transparent creates a dissolve like // effect to the circular reveal. mColorChange = ObjectAnimator.ofInt(targetView, ViewUtils.FOREGROUND_COLOR, themeAccentColor, Color.TRANSPARENT); mColorChange.setEvaluator(new ArgbEvaluator()); mColorChange.setInterpolator(mInterpolator); }
From source file:com.example.gps_project.Places.java
public static double D_jw(double wd1, double jd1, double wd2, double jd2) { double x, y, out; double PI = 3.14159265; double R = 6.371229 * 1e6; x = (jd2 - jd1) * PI * R * Math.cos(((wd1 + wd2) / 2) * PI / 180) / 180; y = (wd2 - wd1) * PI * R / 180;//from w w w . j a va 2 s . c o m out = Math.hypot(x, y); return out / 1000; }
From source file:com.adkdevelopment.earthquakesurvival.utils.Utilities.java
/** * Animates RecyclerView card on click with revealing effect * @param viewHolder to make animation on */// w w w . j a va 2 s . com public static void animationCard(RecyclerView.ViewHolder viewHolder) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (mBlueColor == 0) { mBlueColor = ContextCompat.getColor(viewHolder.itemView.getContext(), R.color.colorPrimary); } if (mWhiteColor == 0) { mWhiteColor = ContextCompat.getColor(viewHolder.itemView.getContext(), R.color.white); } int finalRadius = (int) Math.hypot(viewHolder.itemView.getWidth() / 2, viewHolder.itemView.getHeight() / 2); Animator anim = ViewAnimationUtils.createCircularReveal(viewHolder.itemView, viewHolder.itemView.getWidth() / 2, viewHolder.itemView.getHeight() / 2, 0, finalRadius); viewHolder.itemView.setBackgroundColor(mBlueColor); anim.start(); anim.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { viewHolder.itemView.setBackgroundColor(mWhiteColor); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); } }
From source file:uk.ac.diamond.scisoft.analysis.diffraction.powder.PixelIntegrationUtils.java
public static int calculateNumberOfBins(IDiffractionMetadata metadata) { int[] shape = getShape(metadata); double[] beamCentre = metadata.getDetector2DProperties().getBeamCentreCoords(); if (beamCentre[1] < shape[0] && beamCentre[1] > 0 && beamCentre[0] < shape[1] && beamCentre[0] > 0) { double[] farCorner = new double[] { 0, 0 }; if (beamCentre[1] < shape[0] / 2.0) farCorner[0] = shape[0];//from w w w . j av a 2s. c om if (beamCentre[0] < shape[1] / 2.0) farCorner[1] = shape[1]; return (int) Math.hypot(beamCentre[0] - farCorner[1], beamCentre[1] - farCorner[0]); } else if (beamCentre[1] < shape[0] && beamCentre[1] > 0 && (beamCentre[0] > shape[1] || beamCentre[0] < 0)) { return shape[1]; } else if (beamCentre[0] < shape[1] && beamCentre[0] > 0 && (beamCentre[1] > shape[0] || beamCentre[1] < 0)) { return shape[0]; } else { return (int) Math.hypot(shape[1], shape[0]); } }
From source file:babbq.com.searchplace.SearchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); ButterKnife.bind(this); setupSearchView();// w w w .j av a 2 s. c om auto = TransitionInflater.from(this).inflateTransition(R.transition.auto); mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API) .addApi(Places.GEO_DATA_API).addConnectionCallbacks(this).addOnConnectionFailedListener(this) .build(); mAdapter = new TestAdapter(null, v -> { int position = results.getChildLayoutPosition(v); //Toast.makeText(getActivity(), "#" + position, Toast.LENGTH_SHORT).show(); PendingResult result = Places.GeoDataApi.getPlaceById(mGoogleApiClient, String.valueOf(mAdapter.getElementAt(position).placeId)); result.setResultCallback(mCoordinatePlaceDetailsCallback); }, mGoogleApiClient); dataManager = new SearchDataManager(mGoogleApiClient, mCoordinatePlaceDetailsCallback) { @Override public void onDataLoaded(List<? extends PlaceAutocomplete> data) { if (data != null && data.size() > 0) { if (results.getVisibility() != View.VISIBLE) { TransitionManager.beginDelayedTransition(container, auto); progress.setVisibility(View.GONE); results.setVisibility(View.VISIBLE); // fab.setVisibility(View.VISIBLE); fab.setAlpha(0.6f); fab.setScaleX(0f); fab.setScaleY(0f); fab.animate().alpha(1f).scaleX(1f).scaleY(1f).setStartDelay(800L).setDuration(300L) .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); } // mAdapter.addAndResort(data); mAdapter.setList(data); } else { TransitionManager.beginDelayedTransition(container, auto); progress.setVisibility(View.GONE); setNoResultsVisibility(View.VISIBLE); } } }; // mAdapter = new FeedAdapter(this, dataManager, columns); results.setAdapter(mAdapter); GridLayoutManager layoutManager = new GridLayoutManager(this, columns); // layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { // // @Override // public int getSpanSize(int position) { // return mAdapter.getItemColumnSpan(position); // } // }); results.setLayoutManager(layoutManager); results.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) { @Override public void onLoadMore() { dataManager.loadMore(); } }); results.setHasFixedSize(true); results.addOnScrollListener(gridScroll); // extract the search icon's location passed from the launching activity, minus 4dp to // compensate for different paddings in the views searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics()); searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0); // translate icon to match the launching screen then animate back into position searchBackContainer.setTranslationX(searchBackDistanceX); searchBackContainer.animate().translationX(0f).setDuration(650L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in)); // transform from search icon to back icon AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this, R.drawable.avd_search_to_back); searchBack.setImageDrawable(searchToBack); searchToBack.start(); // for some reason the animation doesn't always finish (leaving a part arrow!?) so after // the animation set a static drawable. Also animation callbacks weren't added until API23 // so using post delayed :( // TODO fix properly!! searchBack.postDelayed(new Runnable() { @Override public void run() { searchBack.setImageDrawable( ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded)); } }, 600); // fade in the other search chrome searchBackground.animate().alpha(1f).setDuration(300L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in)); searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in)) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { searchView.requestFocus(); ImeUtils.showIme(searchView); } }); // animate in a scrim over the content behind scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { scrim.getViewTreeObserver().removeOnPreDrawListener(this); AnimatorSet showScrim = new AnimatorSet(); showScrim.playTogether( ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX, searchBackground.getBottom(), 0, (float) Math.hypot(searchBackDistanceX, scrim.getHeight() - searchBackground.getBottom())), ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT, ContextCompat.getColor(SearchActivity.this, R.color.scrim))); showScrim.setDuration(400L); showScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); showScrim.start(); return false; } }); onNewIntent(getIntent()); }
From source file:im.ene.lab.attiq.ui.activities.SearchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); ButterKnife.bind(this); setupSearchView();// w w w . j a va2s. co m mAutoTransition = TransitionInflater.from(this).inflateTransition(R.transition.auto) .setInterpolator(LINEAR_OUT_SLOW_INT); mSearchResultCallback = new Callback<List<Article>>() { @Override public void onResponse(Call<List<Article>> call, Response<List<Article>> response) { List<Article> data = response.body(); if (!UIUtil.isEmpty(data)) { if (mRecyclerView.getVisibility() != View.VISIBLE) { TransitionManager.beginDelayedTransition(mMainContainer, mAutoTransition); mProgress.setVisibility(View.GONE); mRecyclerView.setVisibility(View.VISIBLE); } mAdapter.addItems(data); } else { TransitionManager.beginDelayedTransition(mMainContainer, mAutoTransition); mProgress.setVisibility(View.GONE); setNoResultsVisibility(View.VISIBLE); } } @Override public void onFailure(Call<List<Article>> call, Throwable t) { } }; mAdapter = new ArticleListAdapter() { @Override public void loadItems(boolean isLoadingMore, int page, int pageLimit, @Nullable String query, Callback<List<Article>> callback) { ApiClient.items(page, pageLimit, query).enqueue(callback); } }; mOnResultItemClick = new ArticleListAdapter.OnArticleClickListener() { @Override public void onUserClick(User user) { startActivity(ProfileActivity.createIntent(SearchActivity.this, user.getId())); } @Override public void onItemContentClick(Article item) { startActivity(ItemDetailActivity.createIntent(SearchActivity.this, item.getId())); } }; mAdapter.setOnItemClickListener(mOnResultItemClick); mRecyclerView.setAdapter(mAdapter); mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST)); GridLayoutManager layoutManager = new GridLayoutManager(this, mColumns); layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { // return mAdapter.getItemColumnSpan(position); return mColumns; } }); mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.addOnScrollListener(new EndlessScrollListener(layoutManager) { @Override protected void loadMore() { mHandler.removeMessages(MESSAGE_LOAD_MORE); mHandler.sendEmptyMessageDelayed(MESSAGE_LOAD_MORE, 200); } }); mRecyclerView.setHasFixedSize(true); mRecyclerView.addOnScrollListener(mOnGridScroll); // extract the search icon's location passed from the launching activity, minus 4dp to // compensate for different paddings in the views mSearchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics()); mSearchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0); // translate icon to match the launching screen then animate back into position mSearchNavButtonContainer.setTranslationX(mSearchBackDistanceX); mSearchNavButtonContainer.animate().translationX(0f).setDuration(650L).setInterpolator(LINEAR_OUT_SLOW_INT); // change from search icon to back icon DrawerArrowDrawable searchToBack = new DrawerArrowDrawable(mSearchNavButton.getContext()); searchToBack.setDirection(DrawerArrowDrawable.ARROW_DIRECTION_LEFT); searchToBack.setProgress(1.f); mSearchNavButton.setImageDrawable(searchToBack); // fade in the other search chrome mSearchBackground.animate().alpha(1f).setDuration(300L).setInterpolator(LINEAR_OUT_SLOW_INT); mSearchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L).setInterpolator(LINEAR_OUT_SLOW_INT) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mSearchView.requestFocus(); ImeUtil.showIme(mSearchView); } }); // animate in a mScrim over the content behind mScrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { mScrim.getViewTreeObserver().removeOnPreDrawListener(this); AnimatorSet showScrim = new AnimatorSet(); showScrim.playTogether( ViewAnimationUtils.createCircularReveal(mScrim, mSearchIconCenterX, mSearchBackground.getBottom(), 0, (float) Math.hypot(mSearchBackDistanceX, mScrim.getHeight() - mSearchBackground.getBottom())), AnimUtil.ofArgb(mScrim, UIUtil.BACKGROUND_COLOR, Color.TRANSPARENT, ContextCompat.getColor(SearchActivity.this, R.color.scrim))); showScrim.setDuration(400L); showScrim.setInterpolator(LINEAR_OUT_SLOW_INT); showScrim.start(); return false; } }); onNewIntent(getIntent()); }
From source file:org.telegraph.ui.Components.EmojiView.java
public EmojiView(boolean needStickers, Context context) { super(context); showStickers = needStickers;// ww w .ja v a2s. c om for (int i = 0; i < Emoji.data.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); views.add(gridView); EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1); gridView.setAdapter(emojiGridAdapter); AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7); adapters.add(emojiGridAdapter); } if (showStickers) { StickersQuery.checkStickers(); stickersGridView = new GridView(context) { @Override public boolean onInterceptTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); int count = stickersGridView.getChildCount(); for (int a = 0; a < count; a++) { View view = stickersGridView.getChildAt(a); int top = view.getTop(); int bottom = view.getBottom(); int left = view.getLeft(); int right = view.getRight(); if (top > y || bottom < y || left > x || right < x) { continue; } if (!(view instanceof StickerEmojiCell) || !((StickerEmojiCell) view).showingBitmap()) { return super.onInterceptTouchEvent(event); } startX = x; startY = y; currentStickerPreviewCell = (StickerEmojiCell) view; openStickerPreviewRunnable = new Runnable() { @Override public void run() { if (openStickerPreviewRunnable == null) { return; } stickersGridView.setOnItemClickListener(null); stickersGridView.requestDisallowInterceptTouchEvent(true); openStickerPreviewRunnable = null; StickerPreviewViewer.getInstance().setParentActivity((Activity) getContext()); StickerPreviewViewer.getInstance() .setKeyboardHeight(EmojiView.this.getMeasuredHeight()); StickerPreviewViewer.getInstance().open(currentStickerPreviewCell.getSticker()); currentStickerPreviewCell.setScaled(true); } }; AndroidUtilities.runOnUIThread(openStickerPreviewRunnable, 200); return true; } } return false; } }; stickersGridView.setSelector(R.drawable.transparent); stickersGridView.setColumnWidth(AndroidUtilities.dp(72)); stickersGridView.setNumColumns(-1); stickersGridView.setPadding(0, AndroidUtilities.dp(4), 0, 0); stickersGridView.setClipToPadding(false); views.add(stickersGridView); stickersGridAdapter = new StickersGridAdapter(context); stickersGridView.setAdapter(stickersGridAdapter); stickersGridView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (openStickerPreviewRunnable != null || StickerPreviewViewer.getInstance().isVisible()) { if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_POINTER_UP) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { stickersGridView.setOnItemClickListener(stickersOnItemClickListener); } }, 150); if (openStickerPreviewRunnable != null) { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } else if (StickerPreviewViewer.getInstance().isVisible()) { StickerPreviewViewer.getInstance().close(); if (currentStickerPreviewCell != null) { currentStickerPreviewCell.setScaled(false); currentStickerPreviewCell = null; } } } else if (event.getAction() != MotionEvent.ACTION_DOWN) { if (StickerPreviewViewer.getInstance().isVisible()) { if (event.getAction() == MotionEvent.ACTION_MOVE) { int x = (int) event.getX(); int y = (int) event.getY(); int count = stickersGridView.getChildCount(); for (int a = 0; a < count; a++) { View view = stickersGridView.getChildAt(a); int top = view.getTop(); int bottom = view.getBottom(); int left = view.getLeft(); int right = view.getRight(); if (top > y || bottom < y || left > x || right < x) { continue; } if (!(view instanceof StickerEmojiCell) || view == currentStickerPreviewCell) { break; } if (currentStickerPreviewCell != null) { currentStickerPreviewCell.setScaled(false); } currentStickerPreviewCell = (StickerEmojiCell) view; StickerPreviewViewer.getInstance() .setKeyboardHeight(EmojiView.this.getMeasuredHeight()); StickerPreviewViewer.getInstance() .open(currentStickerPreviewCell.getSticker()); currentStickerPreviewCell.setScaled(true); return true; } } return true; } else if (openStickerPreviewRunnable != null) { if (event.getAction() == MotionEvent.ACTION_MOVE) { if (Math.hypot(startX - event.getX(), startY - event.getY()) > AndroidUtilities .dp(10)) { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } } else { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } } } } return false; } }); stickersOnItemClickListener = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long i) { if (!(view instanceof StickerEmojiCell)) { return; } if (openStickerPreviewRunnable != null) { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } if (currentStickerPreviewCell != null) { currentStickerPreviewCell.setScaled(false); currentStickerPreviewCell = null; } StickerEmojiCell cell = (StickerEmojiCell) view; if (cell.isDisabled()) { return; } cell.disable(); TLRPC.Document document = cell.getSticker(); Integer count = stickersUseHistory.get(document.id); if (count == null) { count = 0; } if (count == 0 && stickersUseHistory.size() > 19) { for (int a = recentStickers.size() - 1; a >= 0; a--) { TLRPC.Document sticker = recentStickers.get(a); stickersUseHistory.remove(sticker.id); recentStickers.remove(a); if (stickersUseHistory.size() <= 19) { break; } } } stickersUseHistory.put(document.id, ++count); long id = StickersQuery.getStickerSetId(document); if (id != -1) { count = stickerSetsUseCount.get(id); if (count == null) { count = 0; } stickerSetsUseCount.put(id, ++count); } saveRecentStickers(); if (listener != null) { listener.onStickerSelected(document); } } }; stickersGridView.setOnItemClickListener(stickersOnItemClickListener); AndroidUtilities.setListViewEdgeEffectColor(stickersGridView, 0xfff5f6f7); stickersWrap = new FrameLayout(context); stickersWrap.addView(stickersGridView); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoStickers", R.string.NoStickers)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); textView.setTextColor(0xff888888); stickersWrap.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); stickersGridView.setEmptyView(textView); scrollSlidingTabStrip = 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 (Build.VERSION.SDK_INT >= 11) { if (first) { first = false; lastX = ev.getX(); } float newTranslationX = ViewProxy.getTranslationX(scrollSlidingTabStrip); if (scrollSlidingTabStrip.getScrollX() == 0 && newTranslationX == 0) { if (!startedScroll && lastX - ev.getX() < 0) { if (pager.beginFakeDrag()) { startedScroll = true; lastTranslateX = ViewProxy.getTranslationX(scrollSlidingTabStrip); } } 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); } return super.onTouchEvent(ev); } }; scrollSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); scrollSlidingTabStrip.setIndicatorColor(0xffe2e5e7); scrollSlidingTabStrip.setUnderlineColor(0xffe2e5e7); scrollSlidingTabStrip.setVisibility(INVISIBLE); addView(scrollSlidingTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP)); ViewProxy.setTranslationX(scrollSlidingTabStrip, AndroidUtilities.displaySize.x); updateStickerTabs(); scrollSlidingTabStrip.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() { @Override public void onPageSelected(int page) { if (page == 0) { pager.setCurrentItem(0); return; } else if (page == 1 && !recentStickers.isEmpty()) { views.get(6).setSelection(0); return; } int index = page - (recentStickers.isEmpty() ? 1 : 2); if (index >= stickerSets.size()) { index = stickerSets.size() - 1; } views.get(6).setSelection(stickersGridAdapter.getPositionForPack(stickerSets.get(index))); } }); stickersGridView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { int count = view.getChildCount(); for (int a = 0; a < count; a++) { View child = view.getChildAt(a); if (child.getHeight() + child.getTop() < AndroidUtilities.dp(5)) { firstVisibleItem++; } else { break; } } scrollSlidingTabStrip .onPageScrolled(stickersGridAdapter.getTabForPosition(firstVisibleItem) + 1, 0); } }); } setBackgroundColor(0xfff5f6f7); pager = new ViewPager(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pager.setAdapter(new EmojiPagesAdapter()); pagerSlidingTabStripContainer = new LinearLayout(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pagerSlidingTabStripContainer.setOrientation(LinearLayout.HORIZONTAL); pagerSlidingTabStripContainer.setBackgroundColor(0xfff5f6f7); addView(pagerSlidingTabStripContainer, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48)); PagerSlidingTabStrip 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); pagerSlidingTabStripContainer.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(), positionOffsetPixels); } @Override public void onPageSelected(int position) { } @Override public void onPageScrollStateChanged(int state) { } }); FrameLayout frameLayout = new FrameLayout(context); pagerSlidingTabStripContainer.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)); recentsWrap = new FrameLayout(context); recentsWrap.addView(views.get(0)); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoRecent", R.string.NoRecent)); textView.setTextSize(18); textView.setTextColor(0xff888888); textView.setGravity(Gravity.CENTER); recentsWrap.addView(textView); views.get(0).setEmptyView(textView); addView(pager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 48, 0, 0)); loadRecents(); if (Emoji.data[0] == null || Emoji.data[0].length == 0) { pager.setCurrentItem(1); } }