Refactoring, fix theme

This commit is contained in:
mittorn
2018-04-05 22:08:11 +07:00
parent 72e3313c30
commit 0d1d899d7c
7 changed files with 196 additions and 182 deletions

View File

@@ -25,136 +25,6 @@ public class XashTutorialActivity extends Activity implements View.OnClickListen
private int currentItem;
private int prevText, nextText, finishText, cancelText, numPages;
static class PagedView extends HorizontalScrollView
{
boolean isDelayed, isInc, anim;
int lastScroll, pageWidth, currentPage, numPages, targetPage;
float firstx,lastx;
LinearLayout pageContainer;
ViewGroup.LayoutParams pageParams;
// allow detect animation end
static abstract class OnPageListener
{
abstract public void onPage(int page);
}
OnPageListener listener;
public PagedView(Context ctx, int pagewidth)
{
super(ctx);
pageContainer = new LinearLayout(ctx);
pageContainer.setOrientation(LinearLayout.HORIZONTAL);
setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
setScrollBarStyle(SCROLLBARS_INSIDE_INSET);
addView(pageContainer);
pageWidth = pagewidth;
// this will be applied to every page
pageParams = new ViewGroup.LayoutParams(pagewidth, LayoutParams.FILL_PARENT);
}
private void animateScroll()
{
if( !anim )
{
// allow only correct position if anim disabled
scrollTo(pageWidth*currentPage,0);
return;
}
if( isInc && lastScroll >= pageWidth * targetPage || !isInc && lastScroll <= pageWidth * targetPage )
{
// got target page, stop now
anim = false;
currentPage = targetPage;
scrollTo(pageWidth*targetPage,0);
if( listener != null )
listener.onPage(currentPage);
return;
}
if( !isDelayed ) //semaphore
{
isDelayed = true;
postDelayed(new Runnable()
{
public void run()
{
isDelayed = false;
// animate to 1/50 of page every 10 ms
scrollBy(isInc?pageWidth/50:-pageWidth/50,0);
}
},10);
}
}
// add view and set layout
public void addPage(View view)
{
view.setLayoutParams(pageParams);
pageContainer.addView(view);
numPages++;
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt)
{
// this called on every scrollTo/scrollBy and touch scroll
super.onScrollChanged(l,t,oldl,oldt);
lastScroll=l;
isInc = l>oldl;
animateScroll();
}
@Override
public boolean onTouchEvent(MotionEvent e)
{
switch( e.getAction() )
{
case MotionEvent.ACTION_DOWN:
// store swipe start
lastx = firstx = e.getX();
// animation will be started on next scroll event
anim = true;
break;
case MotionEvent.ACTION_MOVE:
// animation will start in supercall, so select direction now
isInc = e.getX() < lastx;
targetPage = isInc?currentPage+1:currentPage-1;
lastx = e.getX();
break;
case MotionEvent.ACTION_UP:
// detect misstouch (<100 pixels)
if( Math.abs(e.getX()-firstx) < 100)
{
/*
anim = false;
targetPage = currentPage;
scrollTo(currentPage*pageWidth,0);*/
targetPage = currentPage;
isInc = currentPage * pageWidth > lastScroll;
}
return false;
}
return super.onTouchEvent(e);
}
// set page number
public void changePage(int page)
{
targetPage = page;
anim = true;
isInc = targetPage > currentPage;
animateScroll();
}
// call when animation ends
public void setOnPageListener(OnPageListener listener1)
{
listener = listener1;
}
}
PagedView scroll;
@@ -170,7 +40,6 @@ public class XashTutorialActivity extends Activity implements View.OnClickListen
initViews();
initPages();
changeFragment(0);
}
@@ -229,6 +98,8 @@ public class XashTutorialActivity extends Activity implements View.OnClickListen
controlPosition();
}
});
if( FWGSLib.sdk < 14 ) // pre-ics does not apply buttons background
FWGSLib.changeButtonsStyle((ViewGroup)container.getParent());
}
private void controlPosition()
@@ -290,8 +161,8 @@ public class XashTutorialActivity extends Activity implements View.OnClickListen
@Override
public void onBackPressed() {
if (currentItem == 0) {
super.onBackPressed();
if (currentItem == 0) {
finish();
} else {
changeFragment(false);
}