2019-04-28 18:54:22 +02:00
|
|
|
package com.darkweb.genesissearchengine;
|
2019-03-27 19:07:03 +01:00
|
|
|
|
|
|
|
import android.content.Context;
|
2019-05-10 20:44:08 +02:00
|
|
|
import android.content.SharedPreferences;
|
2019-06-22 17:03:44 +02:00
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.Canvas;
|
2019-03-27 19:07:03 +01:00
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
import android.net.NetworkInfo;
|
2019-06-22 17:03:44 +02:00
|
|
|
import android.os.Build;
|
2019-05-10 20:44:08 +02:00
|
|
|
import android.preference.PreferenceManager;
|
2019-06-22 17:03:44 +02:00
|
|
|
import android.util.DisplayMetrics;
|
|
|
|
import android.view.Display;
|
2019-06-15 19:13:52 +02:00
|
|
|
import android.view.View;
|
2019-06-22 17:03:44 +02:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.animation.Animation;
|
|
|
|
import android.view.animation.RotateAnimation;
|
2019-06-15 19:13:52 +02:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
import com.darkweb.genesissearchengine.appManager.app_model;
|
|
|
|
import com.darkweb.genesissearchengine.constants.keys;
|
2019-06-22 17:03:44 +02:00
|
|
|
import com.example.myapplication.BuildConfig;
|
2019-05-30 21:19:30 +02:00
|
|
|
|
2019-03-27 19:07:03 +01:00
|
|
|
public class helperMethod
|
|
|
|
{
|
2019-06-15 19:13:52 +02:00
|
|
|
/*Helper Methods*/
|
|
|
|
public static boolean isNetworkAvailable()
|
2019-03-27 19:07:03 +01:00
|
|
|
{
|
2019-06-15 19:13:52 +02:00
|
|
|
ConnectivityManager cm = (ConnectivityManager) app_model.getInstance().getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
2019-03-27 19:07:03 +01:00
|
|
|
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
|
|
|
if (networkInfo != null && networkInfo.isConnected())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-15 19:13:52 +02:00
|
|
|
public static String readHomepageHTML(Context applicationContext)
|
|
|
|
{
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext);
|
|
|
|
return prefs.getString(keys.homepage_html_key,"");
|
2019-05-10 20:44:08 +02:00
|
|
|
}
|
|
|
|
|
2019-06-15 19:13:52 +02:00
|
|
|
public static void setHomepageHTML(String html, Context applicationContext)
|
|
|
|
{
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext);
|
2019-05-10 20:44:08 +02:00
|
|
|
SharedPreferences.Editor edit = prefs.edit();
|
2019-06-15 19:13:52 +02:00
|
|
|
edit.putString(keys.homepage_html_key, html);
|
2019-05-10 20:44:08 +02:00
|
|
|
edit.commit();
|
2019-05-30 21:19:30 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-22 17:03:44 +02:00
|
|
|
public static String completeURL(String url)
|
|
|
|
{
|
|
|
|
if(!url.startsWith("www.")&& !url.startsWith("http://")&& !url.startsWith("https://")){
|
|
|
|
url = "www."+url;
|
|
|
|
}
|
|
|
|
if(!url.startsWith("http://")&&!url.startsWith("https://")){
|
|
|
|
url = "http://"+url;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2019-06-15 19:13:52 +02:00
|
|
|
public static void hideKeyboard()
|
2019-05-30 21:19:30 +02:00
|
|
|
{
|
2019-06-15 19:13:52 +02:00
|
|
|
View view = app_model.getInstance().getAppInstance().findViewById(android.R.id.content);
|
|
|
|
if (view != null)
|
|
|
|
{
|
|
|
|
InputMethodManager imm = (InputMethodManager) app_model.getInstance().getAppInstance().getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
|
|
|
}
|
2019-05-10 20:44:08 +02:00
|
|
|
}
|
|
|
|
|
2019-06-22 17:03:44 +02:00
|
|
|
public static int screenHeight(boolean hasSoftKeys)
|
|
|
|
{
|
|
|
|
if(!hasSoftKeys)
|
|
|
|
{
|
|
|
|
return (int)(Resources.getSystem().getDisplayMetrics().heightPixels)-(helperMethod.getNavigationBarHeight());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return (int)(Resources.getSystem().getDisplayMetrics().heightPixels);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getNavigationBarHeight() {
|
|
|
|
Resources resources = app_model.getInstance().getAppContext().getResources();
|
|
|
|
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
|
|
|
|
if (resourceId > 0) {
|
|
|
|
return resources.getDimensionPixelSize(resourceId);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static RotateAnimation getRotationAnimation()
|
|
|
|
{
|
|
|
|
RotateAnimation rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);
|
|
|
|
rotate.setDuration(2000);
|
|
|
|
rotate.setRepeatCount(Animation.INFINITE);
|
|
|
|
return rotate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Bitmap screenShot(View view)
|
|
|
|
{
|
|
|
|
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
|
|
|
|
Canvas canvas = new Canvas(bitmap);
|
|
|
|
view.draw(canvas);
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ViewGroup.MarginLayoutParams getCenterScreenPoint(ViewGroup.LayoutParams itemLayoutParams)
|
|
|
|
{
|
|
|
|
double heightloader = Resources.getSystem().getDisplayMetrics().heightPixels*0.78;
|
|
|
|
ViewGroup.MarginLayoutParams params_loading = (ViewGroup.MarginLayoutParams) itemLayoutParams;
|
|
|
|
params_loading.topMargin = (int)(heightloader);
|
|
|
|
|
|
|
|
return params_loading;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasSoftKeys(WindowManager windowManager)
|
|
|
|
{
|
|
|
|
Display d = windowManager.getDefaultDisplay();
|
|
|
|
|
|
|
|
DisplayMetrics realDisplayMetrics = new DisplayMetrics();
|
|
|
|
d.getRealMetrics(realDisplayMetrics);
|
|
|
|
|
|
|
|
int realHeight = realDisplayMetrics.heightPixels;
|
|
|
|
int realWidth = realDisplayMetrics.widthPixels;
|
|
|
|
|
|
|
|
DisplayMetrics displayMetrics = new DisplayMetrics();
|
|
|
|
d.getMetrics(displayMetrics);
|
|
|
|
|
|
|
|
int displayHeight = displayMetrics.heightPixels;
|
|
|
|
int displayWidth = displayMetrics.widthPixels;
|
|
|
|
|
|
|
|
return (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isBuildValid ()
|
|
|
|
{
|
|
|
|
if(BuildConfig.FLAVOR.equals("aarch64")&& Build.SUPPORTED_ABIS[0].equals("arm64-v8a") || BuildConfig.FLAVOR.equals("arm")&&Build.SUPPORTED_ABIS[0].equals("armeabi-v7a") || BuildConfig.FLAVOR.equals("x86")&&Build.SUPPORTED_ABIS[0].equals("x86") || BuildConfig.FLAVOR.equals("x86_64")&&Build.SUPPORTED_ABIS[0].equals("x86_64"))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-27 19:07:03 +01:00
|
|
|
}
|