use of org.telegram.ui.Components.BottomPagesView in project Telegram-FOSS by Telegram-FOSS-Team.
the class IntroActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_TMessages);
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
preferences.edit().putLong("intro_crashed_time", System.currentTimeMillis()).commit();
titles = new String[] { LocaleController.getString("Page1Title", R.string.Page1Title), LocaleController.getString("Page2Title", R.string.Page2Title), LocaleController.getString("Page3Title", R.string.Page3Title), LocaleController.getString("Page5Title", R.string.Page5Title), LocaleController.getString("Page4Title", R.string.Page4Title), LocaleController.getString("Page6Title", R.string.Page6Title) };
messages = new String[] { LocaleController.getString("Page1Message", R.string.Page1Message), LocaleController.getString("Page2Message", R.string.Page2Message), LocaleController.getString("Page3Message", R.string.Page3Message), LocaleController.getString("Page5Message", R.string.Page5Message), LocaleController.getString("Page4Message", R.string.Page4Message), LocaleController.getString("Page6Message", R.string.Page6Message) };
ScrollView scrollView = new ScrollView(this);
scrollView.setFillViewport(true);
FrameLayout frameLayout = new FrameLayout(this) {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
int oneFourth = (bottom - top) / 4;
int y = (oneFourth * 3 - AndroidUtilities.dp(275)) / 2;
frameLayout2.layout(0, y, frameLayout2.getMeasuredWidth(), y + frameLayout2.getMeasuredHeight());
y += AndroidUtilities.dp(272);
int x = (getMeasuredWidth() - bottomPages.getMeasuredWidth()) / 2;
bottomPages.layout(x, y, x + bottomPages.getMeasuredWidth(), y + bottomPages.getMeasuredHeight());
viewPager.layout(0, 0, viewPager.getMeasuredWidth(), viewPager.getMeasuredHeight());
y = oneFourth * 3 + (oneFourth - startMessagingButton.getMeasuredHeight()) / 2;
x = (getMeasuredWidth() - startMessagingButton.getMeasuredWidth()) / 2;
startMessagingButton.layout(x, y, x + startMessagingButton.getMeasuredWidth(), y + startMessagingButton.getMeasuredHeight());
y -= AndroidUtilities.dp(30);
x = (getMeasuredWidth() - textView.getMeasuredWidth()) / 2;
textView.layout(x, y - textView.getMeasuredHeight(), x + textView.getMeasuredWidth(), y);
}
};
frameLayout.setBackgroundColor(0xffffffff);
scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
frameLayout2 = new FrameLayout(this);
frameLayout.addView(frameLayout2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 78, 0, 0));
TextureView textureView = new TextureView(this);
frameLayout2.addView(textureView, LayoutHelper.createFrame(200, 150, Gravity.CENTER));
textureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
if (eglThread == null && surface != null) {
eglThread = new EGLThread(surface);
eglThread.setSurfaceTextureSize(width, height);
eglThread.postRunnable(() -> eglThread.drawRunnable.run());
}
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, final int width, final int height) {
if (eglThread != null) {
eglThread.setSurfaceTextureSize(width, height);
}
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
if (eglThread != null) {
eglThread.shutdown();
eglThread = null;
}
return true;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
});
viewPager = new ViewPager(this);
viewPager.setAdapter(new IntroAdapter());
viewPager.setPageMargin(0);
viewPager.setOffscreenPageLimit(1);
frameLayout.addView(viewPager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
bottomPages.setPageOffset(position, positionOffset);
float width = viewPager.getMeasuredWidth();
if (width == 0) {
return;
}
float offset = (position * width + positionOffsetPixels - currentViewPagerPage * width) / width;
Intro.setScrollOffset(offset);
}
@Override
public void onPageSelected(int i) {
currentViewPagerPage = i;
}
@Override
public void onPageScrollStateChanged(int i) {
if (i == ViewPager.SCROLL_STATE_DRAGGING) {
dragging = true;
startDragX = viewPager.getCurrentItem() * viewPager.getMeasuredWidth();
} else if (i == ViewPager.SCROLL_STATE_IDLE || i == ViewPager.SCROLL_STATE_SETTLING) {
if (dragging) {
justEndDragging = true;
dragging = false;
}
if (lastPage != viewPager.getCurrentItem()) {
lastPage = viewPager.getCurrentItem();
}
}
}
});
startMessagingButton = new TextView(this) {
CellFlickerDrawable cellFlickerDrawable;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (cellFlickerDrawable == null) {
cellFlickerDrawable = new CellFlickerDrawable();
cellFlickerDrawable.drawFrame = false;
cellFlickerDrawable.repeatProgress = 2f;
}
cellFlickerDrawable.setParentWidth(getMeasuredWidth());
AndroidUtilities.rectTmp.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
cellFlickerDrawable.draw(canvas, AndroidUtilities.rectTmp, AndroidUtilities.dp(4));
invalidate();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int size = MeasureSpec.getSize(widthMeasureSpec);
if (size > AndroidUtilities.dp(260)) {
super.onMeasure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(320), MeasureSpec.EXACTLY), heightMeasureSpec);
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
};
startMessagingButton.setText(LocaleController.getString("StartMessaging", R.string.StartMessaging));
startMessagingButton.setGravity(Gravity.CENTER);
startMessagingButton.setTextColor(0xffffffff);
startMessagingButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
startMessagingButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
startMessagingButton.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), 0xff50a8eb, 0xff439bde));
startMessagingButton.setPadding(AndroidUtilities.dp(34), 0, AndroidUtilities.dp(34), 0);
frameLayout.addView(startMessagingButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 42, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 36, 0, 36, 76));
startMessagingButton.setOnClickListener(view -> {
if (startPressed) {
return;
}
startPressed = true;
Intent intent2 = new Intent(IntroActivity.this, LaunchActivity.class);
intent2.putExtra("fromIntro", true);
startActivity(intent2);
destroyed = true;
finish();
});
bottomPages = new BottomPagesView(this, viewPager, 6);
frameLayout.addView(bottomPages, LayoutHelper.createFrame(66, 5, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 350, 0, 0));
textView = new TextView(this);
textView.setTextColor(0xff1393d2);
textView.setGravity(Gravity.CENTER);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 30, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0, 0, 20));
textView.setOnClickListener(v -> {
if (startPressed || localeInfo == null) {
return;
}
LocaleController.getInstance().applyLanguage(localeInfo, true, false, currentAccount);
startPressed = true;
Intent intent2 = new Intent(IntroActivity.this, LaunchActivity.class);
intent2.putExtra("fromIntro", true);
startActivity(intent2);
destroyed = true;
finish();
});
if (AndroidUtilities.isTablet()) {
FrameLayout frameLayout3 = new FrameLayout(this);
setContentView(frameLayout3);
SizeNotifierFrameLayout backgroundTablet = new SizeNotifierFrameLayout(this) {
@Override
protected boolean isActionBarVisible() {
return false;
}
};
backgroundTablet.setOccupyStatusBar(false);
backgroundTablet.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion());
frameLayout3.addView(backgroundTablet, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
FrameLayout frameLayout4 = new FrameLayout(this);
frameLayout4.setBackgroundResource(R.drawable.btnshadow);
frameLayout4.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
frameLayout3.addView(frameLayout4, LayoutHelper.createFrame(498, 528, Gravity.CENTER));
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(scrollView);
}
LocaleController.getInstance().loadRemoteLanguages(currentAccount);
checkContinueText();
justCreated = true;
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.suggestedLangpack);
AndroidUtilities.handleProxyIntent(this, getIntent());
AndroidUtilities.startAppCenter(this);
}
Aggregations