From 0d1d899d7cdedab8c024bc594ab883f2c8db49e9 Mon Sep 17 00:00:00 2001 From: mittorn Date: Thu, 5 Apr 2018 22:08:11 +0700 Subject: [PATCH] Refactoring, fix theme --- build-test.sh | 4 +- src/in/celest/xash3d/FPicker.java | 4 + src/in/celest/xash3d/LauncherActivity.java | 50 +------ src/in/celest/xash3d/XashActivity.java | 2 +- .../celest/xash3d/XashTutorialActivity.java | 137 +----------------- src/su/xash/fwgslib/FWGSLib.java | 44 ++++++ src/su/xash/fwgslib/PagedView.java | 137 ++++++++++++++++++ 7 files changed, 196 insertions(+), 182 deletions(-) create mode 100644 src/su/xash/fwgslib/PagedView.java diff --git a/build-test.sh b/build-test.sh index 2977982a..17404f39 100644 --- a/build-test.sh +++ b/build-test.sh @@ -1,4 +1,4 @@ -ANDROID_JAR=../android-14_.jar +ANDROID_JAR=../android-24.jar AAPT=./../aapt DX=./../dx APKBUILDER=./../apkbuilder @@ -19,7 +19,7 @@ rm assets/extras.pak python2.7 makepak.py xash-extras assets/extras.pak $AAPT package -m -J gen/ --rename-manifest-package in.celest.xash3d.hl -M AndroidManifest.xml -S test/res -I $ANDROID_JAR echo "package in.celest.xash3d.hl;public final class BuildConfig {public final static boolean DEBUG = true;}" > gen/in/celest/xash3d/hl/BuildConfig.java -$JAVAC -d bin/classes -s bin/classes -cp $ANDROID_JAR gen/in/celest/xash3d/hl/* src/in/celest/xash3d/*.java +$JAVAC -d bin/classes -s bin/classes -cp $ANDROID_JAR gen/in/celest/xash3d/hl/* src/in/celest/xash3d/*.java src/su/xash/fwgslib/*.java $DX --dex --output=bin/classes.dex bin/classes/ $AAPT package -f -M test/AndroidManifest.xml -S test/res -I $ANDROID_JAR -F bin/xash3d.apk.unaligned zip bin/xash3d.apk.unaligned assets/* diff --git a/src/in/celest/xash3d/FPicker.java b/src/in/celest/xash3d/FPicker.java index a109d484..2717cb64 100644 --- a/src/in/celest/xash3d/FPicker.java +++ b/src/in/celest/xash3d/FPicker.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; +import su.xash.fwgslib.FWGSLib; import in.celest.xash3d.hl.R; @@ -59,6 +60,9 @@ public class FPicker extends Activity { onFileClick(v); } }); + + FWGSLib.changeButtonsStyle((ViewGroup)mSelectBtn.getParent()); + fill(currentDir); } diff --git a/src/in/celest/xash3d/LauncherActivity.java b/src/in/celest/xash3d/LauncherActivity.java index caaafd7b..6bc92f1e 100644 --- a/src/in/celest/xash3d/LauncherActivity.java +++ b/src/in/celest/xash3d/LauncherActivity.java @@ -37,50 +37,7 @@ public class LauncherActivity extends Activity static LinearLayout rodirSettings; // to easy show/hide static int mEngineWidth, mEngineHeight; - - public static void changeButtonsStyle( ViewGroup parent ) - { - if( sdk >= 21 ) - return; - - for( int i = parent.getChildCount() - 1; i >= 0; i-- ) - { - try - { - final View child = parent.getChildAt(i); - - if( child == null ) - continue; - - if( child instanceof ViewGroup ) - { - changeButtonsStyle((ViewGroup) child); - // DO SOMETHING WITH VIEWGROUP, AFTER CHILDREN HAS BEEN LOOPED - } - else if( child instanceof Button ) - { - final Button b = (Button)child; - final Drawable bg = b.getBackground(); - if(bg!= null)bg.setAlpha( 96 ); - b.setTextColor( 0xFFFFFFFF ); - b.setTextSize( 15f ); - //b.setText(b.getText().toString().toUpperCase()); - b.setTypeface( b.getTypeface(),Typeface.BOLD ); - } - else if( child instanceof EditText ) - { - final EditText b = ( EditText )child; - b.setBackgroundColor( 0xFF353535 ); - b.setTextColor( 0xFFFFFFFF ); - b.setTextSize( 15f ); - } - } - catch( Exception e ) - { - } - } - } - + @Override protected void onCreate(Bundle savedInstanceState) { @@ -91,7 +48,7 @@ public class LauncherActivity extends Activity super.setTheme( 0x01030224 ); else super.setTheme( 0x01030005 ); - if( CertCheck.dumbAntiPDALifeCheck( this ) ) + if( sdk >= 8 && CertCheck.dumbAntiPDALifeCheck( this ) ) { finish(); return; @@ -301,7 +258,7 @@ public class LauncherActivity extends Activity { new CheckUpdate(true, false).execute(UPDATE_LINK); } - changeButtonsStyle((ViewGroup)tabHost.getParent()); + FWGSLib.changeButtonsStyle((ViewGroup)tabHost.getParent()); hideResolutionSettings( !resolution.isChecked() ); hideRodirSettings( !useRoDir.isChecked() ); updateResolutionResult(); @@ -450,6 +407,7 @@ public class LauncherActivity extends Activity startActivity(intent); } }); + FWGSLib.changeButtonsStyle((ViewGroup)dialog.findViewById( R.id.show_firstrun ).getParent()); } }); diff --git a/src/in/celest/xash3d/XashActivity.java b/src/in/celest/xash3d/XashActivity.java index b0958364..f2af5d87 100644 --- a/src/in/celest/xash3d/XashActivity.java +++ b/src/in/celest/xash3d/XashActivity.java @@ -110,7 +110,7 @@ public class XashActivity extends Activity { super.onCreate( savedInstanceState ); mEngineReady = false; - if( CertCheck.dumbAntiPDALifeCheck( this ) ) + if( sdk >= 8 && CertCheck.dumbAntiPDALifeCheck( this ) ) { finish(); return; diff --git a/src/in/celest/xash3d/XashTutorialActivity.java b/src/in/celest/xash3d/XashTutorialActivity.java index d495dac3..dc28493d 100644 --- a/src/in/celest/xash3d/XashTutorialActivity.java +++ b/src/in/celest/xash3d/XashTutorialActivity.java @@ -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); } diff --git a/src/su/xash/fwgslib/FWGSLib.java b/src/su/xash/fwgslib/FWGSLib.java index b796788a..c25ed2b9 100644 --- a/src/su/xash/fwgslib/FWGSLib.java +++ b/src/su/xash/fwgslib/FWGSLib.java @@ -182,6 +182,50 @@ public class FWGSLib return ret; } + public static void changeButtonsStyle( ViewGroup parent ) + { + if( sdk >= 21 ) + return; + + for( int i = parent.getChildCount() - 1; i >= 0; i-- ) + { + try + { + final View child = parent.getChildAt(i); + + if( child == null ) + continue; + + if( child instanceof ViewGroup ) + { + changeButtonsStyle((ViewGroup) child); + // DO SOMETHING WITH VIEWGROUP, AFTER CHILDREN HAS BEEN LOOPED + } + else if( child instanceof Button ) + { + final Button b = (Button)child; + final Drawable bg = b.getBackground(); + if(bg!= null)bg.setAlpha( 96 ); + b.setTextColor( 0xFFFFFFFF ); + b.setTextSize( 15f ); + //b.setText(b.getText().toString().toUpperCase()); + b.setTypeface( b.getTypeface(),Typeface.BOLD ); + } + else if( child instanceof EditText ) + { + final EditText b = ( EditText )child; + b.setBackgroundColor( 0xFF353535 ); + b.setTextColor( 0xFFFFFFFF ); + b.setTextSize( 15f ); + } + } + catch( Exception e ) + { + } + } + } + + public static final int sdk = Integer.valueOf(Build.VERSION.SDK); } diff --git a/src/su/xash/fwgslib/PagedView.java b/src/su/xash/fwgslib/PagedView.java new file mode 100644 index 00000000..a070120c --- /dev/null +++ b/src/su/xash/fwgslib/PagedView.java @@ -0,0 +1,137 @@ +package su.xash.fwgslib; + +import android.view.*; +import android.view.View.*; +import android.widget.*; +import android.content.Context; + +public 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 + public 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; + } +}