~Twilyappsrcmainjavacomtwilytwilyapp
5 itemsDownload ./*

5 itemsDownload ./*

..
CustomWebView.java
MainActivity.java
ReceiveData.java
customChromeClient.java
customViewClient.java


twilyappMainActivity.java
317•  2 years ago•  DownloadRawClose
2 years ago•  317

{}
package com.twily.twilyapp;

// latest apk available at https://twily.info/apk

import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
//import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.text.InputType;
import android.os.Looper;
import android.util.DisplayMetrics;
import android.view.ContextMenu;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
//import android.view.animation.AccelerateInterpolator;
//import android.view.animation.DecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.Window;
import android.view.animation.Transformation;
import android.webkit.CookieManager;
import android.webkit.DownloadListener;
import android.webkit.PermissionRequest;
import android.webkit.ValueCallback;
import android.webkit.WebSettings;
import android.widget.EditText;
import android.webkit.WebView;
//import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
//import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.PermissionChecker;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.MalformedInputException;

public class MainActivity extends AppCompatActivity {
	//CustomWebView browser = new CustomWebView(this,null);
	CustomWebView browser;
	Toolbar toolbar;

	String initialOrient = "portrait";
	public static String currentOrient = "portrait";
	public static int newVersion = 0;

	public static String defaultPage = "";

	public static int desktopMode = 0;

	public static int injectOnce = 0;

	public static int pxw = 0;
	
	private Menu menu;

	//String username = "analiestar";
	//SharedPreferences settings;
	//Button button;
	//ProgressBar progressBar;
	private static Context mContext;

	int outerWidth = 0;
	int outerHeight = 0;
	int toolbarHeight = 400;

	//int zoomText = 100;

	private static final int REQUEST_CODE_PERMISSIONS_CAMERA = 100;
	private static final int REQUEST_CODE_PERMISSIONS_AUDIO = 101;
	private PermissionRequest pRequest;

	private ValueCallback<Uri[]> mUploadMessage;
	private final static int FILECHOOSER_RESULTCODE = 1;

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
		if (requestCode == FILECHOOSER_RESULTCODE) {

			if (null == mUploadMessage || intent == null || resultCode != RESULT_OK) {
				return;
			}

			Uri[] result = null;
			String dataString = intent.getDataString();

			if (dataString != null) {
				result = new Uri[] { Uri.parse(dataString) };
			}

			mUploadMessage.onReceiveValue(result);
			mUploadMessage = null;
		}
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		browser.saveState(outState);
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
		browser.restoreState(savedInstanceState);
	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);

		// Checks the orientation of the screen
		if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
			//Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
			currentOrient = "landscape";
		} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
			//Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
			currentOrient = "portrait";
		}

		if (desktopMode == 1) {
			setDesktopMode(browser, true);
		} else {
			setDesktopMode(browser, false);
		}
	}
	//@Override
	//public void onRefresh() {
	//Toast.makeText(this, "Refresh", Toast.LENGTH_SHORT).show();
	//new Handler().postDelayed(new Runnable() {
	//@Override
	//public void run() {
	//mSwipeRefreshLayout.setRefreshing(false);
	//browser.loadUrl(browser.getUrl());
	//}
	//}, 2000);
	//}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = getApplicationContext();

		AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

		setContentView(R.layout.activity_main);

		toolbar = (Toolbar) findViewById(R.id.toolMain);
		setSupportActionBar(toolbar);

		browser = (CustomWebView) findViewById(R.id.wvwMain);

		ViewTreeObserver viewTreeObserver = toolbar.getViewTreeObserver();
		if (viewTreeObserver.isAlive()) {
			viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
				@Override
				public void onGlobalLayout() {
					int viewHeight = toolbar.getHeight();
					if (viewHeight != 0) {
						toolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);

						int orientation = getResources().getConfiguration().orientation;
						if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
							// In landscape
							initialOrient = "landscape";
						} else {
							// In portrait
							initialOrient = "portrait";
						}

						toolbarHeight = viewHeight;

						currentOrient = initialOrient;

						//setNewDimension();

						/*View dumbView =find9ViewById(R.id.theDumbViewId);
						dumbView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
							@Override
							public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
								// Your code about size changed
								//boolean widthChanged = (right-left) != (oldRight-oldLeft);
								//if( widthChanged )
								//{
								// width has changed
								//Log.e(TAG,"Width has changed new width is "+(right-left)+"px");
								//}
								boolean heightChanged = (bottom-top) != (oldBottom-oldTop);
								if( heightChanged)
								{
									// height has changed
									//Log.e(TAG,"height has changed new height is "+(bottom-top)+"px");
									setNewDimension();
								}
							}
						});*/

						//Rect rectgle= new Rect();
						//Window window= getWindow();
						//window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
						//int StatusBarHeight= rectgle.top;
						//height-=StatusBarHeight;
						//browser.animate().translationY(toolbar.getHeight()).setInterpolator(new LinearInterpolator());

						//ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) browser.getLayoutParams();
						//params.height = height-toolbar.getHeight();
						//params.setMargins(0,toolbar.getHeight(),0,0);
						//browser.setLayoutParams(params);
						ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(
								ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT);
						params.setMargins(0, toolbar.getHeight(), 0, 0);
						browser.setLayoutParams(params);

						String vv = getVersionCode();
						//CallAPI postData = new CallAPI();
						//postData.performPostCall("","");
						try {
							URL url = new URL("https://twily.info/ajaxapp.php");
							new ReceiveData(MainActivity.this, "getversion", vv, "").execute(url);
						} catch (MalformedURLException e) {
							System.out.println("Exception caught MalformedURLException");
						}
					}
				}
			});
		}

		//progressBar = (ProgressBar) findViewById(R.id.progressBar1);
		browser.setBackgroundColor(0xFF2A1E27);

		CookieManager cookieManager = CookieManager.getInstance();
		cookieManager.setAcceptThirdPartyCookies(browser, false);

		WebSettings browserSettings = browser.getSettings();
		String newUA = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
		browserSettings.setUserAgentString(newUA);
		//setDesktopMode(browser,true);

		browserSettings.setJavaScriptEnabled(true);
		browserSettings.setJavaScriptCanOpenWindowsAutomatically(true);
		browserSettings.setAllowFileAccess(true);
		browserSettings.setAllowContentAccess(true);
		//browserSettings.setAllowFileAccessFromFileURLs(true);
		//browserSettings.setAllowUniversalAccessFromFileURLs(true);
		browserSettings.setLoadWithOverviewMode(true);
		browserSettings.setUseWideViewPort(true);
		browserSettings.setDomStorageEnabled(true);
		browserSettings.setMediaPlaybackRequiresUserGesture(false);
		//browserSettings.setAppCacheEnabled(true);

		browserSettings.setSupportZoom(true);
		browserSettings.setBuiltInZoomControls(true);
		browserSettings.setDisplayZoomControls(false);

		//browserSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);

		//browser.setInitialScrollBarStyle(browser.SCROLLBARS_OUTSIDE_OVERLAY);
		//browser.setScrollbarFadingEnabled(false);

		//browserSettings.setCacheMode( WebSettings.LOAD_DEFAULT ); // load online by default
		browser.setOverScrollMode(View.OVER_SCROLL_NEVER);
		//

		//browser.setOnScrollChangeListener(new View.OnScrollChangeListener() {
		//	@Override
		//	public void onScrollChange(View v, int newX, int newY, int oldX, int oldY)
		//	{
		//		if(newY>(oldY+25)) {
		//			toolbarAnimateHide();
		//		} else if(oldY>(newY+25)) {
		//			toolbarAnimateShow();
		//		}
		//		//Toast.makeText(mContext, "Scrolled", Toast.LENGTH_SHORT).show();
		//	}
		//});
		browser.setDownloadListener(new DownloadListener() {
			public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
					long contentLength) {
				Intent i = new Intent(Intent.ACTION_VIEW);
				i.setData(Uri.parse(url));
				startActivity(i);
			}
		});
		browser.setWebViewClient(new customViewClient() {
			//browser.setWebViewClient(new CustomWebView() {
			//
		});
		browser.setGestureDetector(new GestureDetector(mContext, new CustomeGestureDetector()));
		//browser.setGestureDetector(new GestureDetector(new CustomeGestureDetector()));

		browser.setWebChromeClient(new customChromeClient() {
			@Override
			public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
					FileChooserParams fileChooserParams) {
				if (mUploadMessage != null) {
					mUploadMessage.onReceiveValue(null);
				}

				mUploadMessage = filePathCallback;

				Intent i = new Intent(Intent.ACTION_GET_CONTENT);
				i.addCategory(Intent.CATEGORY_OPENABLE);
				i.setType("*/*"); // set MIME type to filter

				MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"),
						MainActivity.FILECHOOSER_RESULTCODE);

				return true;
			}

			@Override
			public void onPermissionRequest(final PermissionRequest request) {
				if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
					request.grant(request.getResources());
				}
			}
		});

		SharedPreferences settings = getApplicationContext().getSharedPreferences("twily-app-data", 0);
		int hexdark = settings.getInt("hexdark", 0);
		int hexlight = settings.getInt("hexlight", 0);
		if (hexdark != 0 && hexlight != 0) {
			setTheme(hexdark, hexlight);
		} else {
			int backgroundColor = ContextCompat.getColor(mContext, R.color.cyan_dark);
			int foregroundColor = ContextCompat.getColor(mContext, R.color.cyan_light);
			setTheme(backgroundColor, foregroundColor);
		}

		//String savedusedname = settings.getString("username","");
		//if(savedusedname!="") {
		//	username = savedusedname;
		//}
		//int savedzoomText = settings.getInt("zoomtext",0);
		//if(savedzoomText!=0) {
		//	zoomText = savedzoomText;
		//}

		//browserSettings.setTextZoom(zoomText);

		String getSavedPage = settings.getString("lastpage", "");
		if (getSavedPage == "") {
			defaultPage = "https://twily.info";
		} else {
			defaultPage = getSavedPage;
		}

		int getDesktopMode = settings.getInt("desktopmode", 0);

		if (getDesktopMode == 1 || desktopMode == 1) {
			setDesktopMode(browser, true);
			browser.setInitialScale(1);
			desktopMode = 1;
		} else {
			setDesktopMode(browser, false);
			browser.setInitialScale(0);
			desktopMode = 0;
		}

		//
		if (savedInstanceState != null && savedInstanceState.containsKey("date")) {
			//
		} else {
			injectOnce = 10;

			browser.loadUrl(defaultPage);
		}
	}

	// Menu icons are inflated just as they were with actionbar
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu_main, menu);

		this.menu = menu;
		
		if(desktopMode==1) {
			//MenuItem omu = (MenuItem) menu.getMenu().findItem(R.id.miDesktop);
			menu.getItem(0).setIcon(ContextCompat.getDrawable(this, R.mipmap.ic_desktop));
		}
		
		//return true;
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		View view;
		PopupMenu popupMenu;

		switch (item.getItemId()) {
			case R.id.miDesktop:
			MenuItem omu = (MenuItem) menu.getItem(0);
			
			if (desktopMode==1) {
				omu.setIcon(ContextCompat.getDrawable(this, R.mipmap.ic_mobile));
				setDesktopMode(browser, false);
				browser.setInitialScale(0);
				desktopMode = 0;
				} else {
				omu.setIcon(ContextCompat.getDrawable(this, R.mipmap.ic_desktop));
				setDesktopMode(browser, true);
				browser.setInitialScale(1);
				desktopMode = 1;
			}
			
			SharedPreferences settings = getApplicationContext().getSharedPreferences("analiestar-app-data",
			0);
			SharedPreferences.Editor editor = settings.edit();
			editor.putInt("desktopmode", desktopMode);
			editor.apply();
			
			return true;
		case R.id.miStyle:
			view = findViewById(R.id.miStyle);
			popupMenu = new PopupMenu(MainActivity.this, view);
			popupMenu.getMenuInflater().inflate(R.menu.color_menu, popupMenu.getMenu());

			popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
				@Override
				public boolean onMenuItemClick(MenuItem item) {
					int backgroundColor;
					int foregroundColor;
					switch (item.getItemId()) {
					case R.id.mBlue:
						backgroundColor = ContextCompat.getColor(mContext, R.color.blue_dark);
						foregroundColor = ContextCompat.getColor(mContext, R.color.blue_light);
						setTheme(backgroundColor, foregroundColor);
						return true;
					case R.id.mCyan:
						backgroundColor = ContextCompat.getColor(mContext, R.color.cyan_dark);
						foregroundColor = ContextCompat.getColor(mContext, R.color.cyan_light);
						setTheme(backgroundColor, foregroundColor);
						return true;
					case R.id.mGreen:
						backgroundColor = ContextCompat.getColor(mContext, R.color.green_dark);
						foregroundColor = ContextCompat.getColor(mContext, R.color.green_light);
						setTheme(backgroundColor, foregroundColor);
						return true;
					case R.id.mPink:
						backgroundColor = ContextCompat.getColor(mContext, R.color.pink_dark);
						foregroundColor = ContextCompat.getColor(mContext, R.color.pink_light);
						setTheme(backgroundColor, foregroundColor);
						return true;
					case R.id.mPurple:
						backgroundColor = ContextCompat.getColor(mContext, R.color.purple_dark);
						foregroundColor = ContextCompat.getColor(mContext, R.color.purple_light);
						setTheme(backgroundColor, foregroundColor);
						return true;
					case R.id.mRed:
						backgroundColor = ContextCompat.getColor(mContext, R.color.red_dark);
						foregroundColor = ContextCompat.getColor(mContext, R.color.red_light);
						setTheme(backgroundColor, foregroundColor);
						return true;
					case R.id.mYellow:
						backgroundColor = ContextCompat.getColor(mContext, R.color.yellow_dark);
						foregroundColor = ContextCompat.getColor(mContext, R.color.yellow_light);
						setTheme(backgroundColor, foregroundColor);
						return true;
					case R.id.mGrey:
						backgroundColor = ContextCompat.getColor(mContext, R.color.grey_dark);
						foregroundColor = ContextCompat.getColor(mContext, R.color.grey_light);
						setTheme(backgroundColor, foregroundColor);
						return true;
					case R.id.mDark:
						backgroundColor = ContextCompat.getColor(mContext, R.color.dark_dark);
						foregroundColor = ContextCompat.getColor(mContext, R.color.dark_light);
						setTheme(backgroundColor, foregroundColor);
						return true;

					}
					return false;
				}
			});
			popupMenu.show();
			return true;
		case R.id.miCompose:
			//PopupMenu popupMenu;
			view = findViewById(R.id.miCompose);
			popupMenu = new PopupMenu(MainActivity.this, view);
			popupMenu.getMenuInflater().inflate(R.menu.option_menu, popupMenu.getMenu());

			if (newVersion == 0) {
				popupMenu.getMenu().findItem(R.id.mUpdate).setVisible(false);
			}
			//popupMenu.getMenu().findItem(R.id.mSetuser).setTitle("User: "+username);

			//MenuItem pmu = (MenuItem) popupMenu.getMenu().findItem(R.id.mDesktop);
			//if (desktopMode == 1) {
			//	pmu.setChecked(true);
			//}

			popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
				@Override
				public boolean onMenuItemClick(MenuItem item) {
					switch (item.getItemId()) {
					case R.id.mHome:
						navWeb("https://twily.info");
						return true;
					case R.id.mFirefox:
						navWeb("https://twily.info/firefox");
						return true;
					case R.id.mWww:
						navWeb("https://twily.info/www");
						return true;
					case R.id.mStuff:
						navWeb("https://twily.info/stuff");
						return true;
					case R.id.mScripts:
						navWeb("https://twily.info/scripts");
						return true;
					case R.id.mConfigs:
						navWeb("https://twily.info/.config");
						return true;
					case R.id.mCodepaste:
						navWeb("https://twily.info/codepaste");
						return true;
					case R.id.mTwilycam:
						navWeb("https://twily.info/stuff/anacam-adultery~.$#view");
						return true;
					case R.id.mTemplate:
						navWeb("https://twily.info/firefox/template.min.html#view");
						return true;
					case R.id.mSitemap:
						navWeb("https://twily.info/sitemap.$#view");
						return true;
					case R.id.mLicense:
						navWeb("https://twily.info/license.$#view");
						return true;
					case R.id.mLinks:
						navWeb("https://twily.info/links");
						return true;
					/*case R.id.mSetuser:
						AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
						builder.setTitle("Set username / default page:");
						
						// Set up the input
						final EditText input = new EditText(MainActivity.this);
						input.setInputType(InputType.TYPE_CLASS_TEXT);
						builder.setView(input);
						
						// Set up the buttons
						builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int which) {
								String m_Text = input.getText().toString();
								SharedPreferences settings = getApplicationContext().getSharedPreferences("twily-app-data", 0);
								SharedPreferences.Editor editor = settings.edit();
								editor.putString("username", m_Text);
								editor.apply();
								
								if(m_Text!="") {
									username = m_Text;
								}
							}
						});
						builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.cancel();
							}
						});
						
						builder.show();
						
						return true;*/
					/*case R.id.mDesktop:
						if (pmu.isChecked()) {
							pmu.setChecked(false);
							setDesktopMode(browser, false);
							browser.setInitialScale(0);
							desktopMode = 0;
						} else {
							pmu.setChecked(true);
							setDesktopMode(browser, true);
							browser.setInitialScale(1);
							desktopMode = 1;
						}

						SharedPreferences settings = getApplicationContext().getSharedPreferences("twily-app-data", 0);
						SharedPreferences.Editor editor = settings.edit();
						editor.putInt("desktopmode", desktopMode);
						editor.apply();

						return true;*/
					case R.id.mUpdate:
						navWeb("https://twily.info/apk");
						return true;
					default:
						return false;
					}
				}
			});
			popupMenu.show();
			return true;
		}
		return false;
	}

	//
	public String getVersionCode() {
		String v = "";
		try {
			v = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
		} catch (NameNotFoundException e) {

		}
		return v;
	}

	/*public void setNewDimension() {
		DisplayMetrics displayMetrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
		outerHeight = displayMetrics.heightPixels;
		outerWidth = displayMetrics.widthPixels;
	}*/

	/*public void saveZoomText(int x) {
		WebSettings browserSettings = browser.getSettings();
		browserSettings.setTextZoom(x);
		
		//int duration = Toast.LENGTH_SHORT
		
		//Toast toast = Toast.makeText(mContext, "zoomText: "+x, duration);
		//toast.show();
		
		SharedPreferences settings = getApplicationContext().getSharedPreferences("twily-app-data", 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putInt("zoomtext", x);
		editor.apply();
	}*/

	public void setTheme(Integer hexdark, Integer hexlight) {
		//browser=(WebView) findViewById(R.id.wvwMain);
		browser.setBackgroundColor(hexlight);

		//toolbar=(Toolbar) findViewById(R.id.toolMain);
		toolbar.setBackgroundColor(hexdark);

		int whiteLight = ContextCompat.getColor(mContext, R.color.white_light);
		toolbar.setTitleTextColor(whiteLight);

		if (Build.VERSION.SDK_INT >= 21) {
			Window window = this.getWindow();
			window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
			window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
			window.setStatusBarColor(hexlight);
		}

		SharedPreferences settings = getApplicationContext().getSharedPreferences("twily-app-data", 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putInt("hexdark", hexdark);
		editor.putInt("hexlight", hexlight);
		editor.apply();
	}

	private void toolbarAnimateShow() {
		toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator());

		final int newTopMargin = toolbar.getHeight();
		Animation a = new Animation() {
			@Override
			protected void applyTransformation(float interpolatedTime, Transformation t) {
				ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) browser.getLayoutParams();
				//params.topMargin = (int)(newTopMargin * interpolatedTime);
				params.topMargin = (int) (params.topMargin + (newTopMargin - params.topMargin) * interpolatedTime);
				browser.setLayoutParams(params);
			}
		};
		a.setDuration(500); // in ms
		browser.startAnimation(a);
	}

	private void toolbarAnimateHide() {
		toolbar.animate().translationY(-toolbar.getHeight()).setInterpolator(new AccelerateInterpolator());

		final int newTopMargin = 0;
		Animation a = new Animation() {
			@Override
			protected void applyTransformation(float interpolatedTime, Transformation t) {
				ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) browser.getLayoutParams();
				//params.topMargin = (int)(newTopMargin * interpolatedTime);
				params.topMargin = (int) (params.topMargin + (newTopMargin - params.topMargin) * interpolatedTime);
				browser.setLayoutParams(params);
			}
		};
		a.setDuration(500); // in ms
		browser.startAnimation(a);
	}

	private void askForPermission(String webkitPermission, String androidPermission, Integer requestCode) {
		//int permissionCheck = pRequest.checkPermission();
		int res = getContext().checkCallingOrSelfPermission(androidPermission);

		if (res == PackageManager.PERMISSION_DENIED) {
			requestPermissions(new String[] { androidPermission }, requestCode);
		} else {
			pRequest.grant(pRequest.getResources());
		}
	}

	public void navWeb(String url) {
		//WebView view = (WebView) findViewById(R.id.wvwMain);
		injectOnce = 10;

		browser.loadUrl(url);
	}

	public static Context getContext() {
		return mContext;
	}

	public static void setDefaultPage(String url) {
		SharedPreferences settings = mContext.getApplicationContext().getSharedPreferences("twily-app-data", 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putString("lastpage", url);
		editor.apply();

		//int duration = Toast.LENGTH_SHORT;

		//Toast toast = Toast.makeText(mContext, "New url "+url+" to defaultPage", duration);
		//toast.show();

		defaultPage = url;
	}

	public void setDesktopMode(WebView webView, boolean enabled) {
		String newUserAgent = webView.getSettings().getUserAgentString();
		if (enabled) {
			try {
				String ua = webView.getSettings().getUserAgentString();
				String androidOSString = webView.getSettings().getUserAgentString().substring(ua.indexOf("("),
						ua.indexOf(")") + 1);
				newUserAgent = webView.getSettings().getUserAgentString().replace(androidOSString,
						"(X11; Linux x86_64)");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			newUserAgent = null;
		}

		webView.getSettings().setUserAgentString(newUserAgent);
		webView.getSettings().setUseWideViewPort(enabled);
		webView.getSettings().setLoadWithOverviewMode(enabled);

		if (desktopMode == 1) {
			pxw = 810;
			if (currentOrient == "landscape") {
				pxw = 1260;
			}

			browser.evaluateJavascript(
					"document.querySelector('meta[name=\"viewport\"]').setAttribute('content', 'width=" + pxw
							+ "px, initial-scale=' + (document.documentElement.clientWidth / " + pxw + "));",
					null);
		}
		//injectOnce=10;
		//webView.reload();
	}

	private class CustomeGestureDetector extends GestureDetector.SimpleOnGestureListener {
		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
			if (e1 == null || e2 == null)
				return false;
			if (e1.getPointerCount() > 1 || e2.getPointerCount() > 1)
				return false;
			else {
				try { // right to left swipe .. go to next page
					if (e1.getX() - e2.getX() > 100 && Math.abs(velocityX) > 800) {
						//do your stuff
						return false;
					} //left to right swipe .. go to prev page
					else if (e2.getX() - e1.getX() > 100 && Math.abs(velocityX) > 800) {
						//do your stuff
						return false;
					} //bottom to top, go to next document
					else if (e1.getY() - e2.getY() > 100 && e2.getY() < toolbarHeight) {
						//&& browser.getScrollY() >= browser.getScale() * (browser.getContentHeight() - browser.getHeight())) {
						//do your stuff
						toolbarAnimateHide();
						return false;
					} //top to bottom, go to prev document
					else if (e2.getY() - e1.getY() > 100 && e1.getY() < toolbarHeight) {
						//do your stuff
						toolbarAnimateShow();
						return false;
					}
				} catch (Exception e) { // nothing
				}
				return false;
			}
		}
	}
}

Top
©twily.info 2013 - 2025
twily at twily dot info



20 119 visits
... ^ v