Dear support,
I add the KProgressHUD in my InitsViews() and call InitsViews onCreate, but the loader on the section i mentioned here is not showing up, and no error return
if (!prefManager.geRole().equals("0")) {
hud.show(); //<<===================Not working , it does not shw up , No error return , no force close , but not show up
String[] user = prefManager.geRole().split(":");
helpView.loadUrl(Splash.main.getWelcome() + "?name=" + user[0] + "&private=" + user[1] + "&user_id=" + user[2] + "&random=" +
getRandomNumberInRange(999, 15000));
} else {
hud.show(); //<<===================Not working , it does not shw up , No error return , no force close , but not show up
helpView.loadUrl(Splash.main.getWelcome());
}
package com.hala.instgram.views;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.support.annotation.RequiresApi;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.PopupMenu;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewConfiguration;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.hala.instgram.R;
import com.hala.instgram.helper.PrefManager;
import com.hala.instgram.helper.WebAppInterface;
import com.hala.instgram.network.ServerRequests;
import com.kaopiz.kprogresshud.KProgressHUD;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static com.hala.instgram.helper.WebAppInterface.xvflage;
public class MainPage extends AppCompatActivity {
public static WebView helpView;
FloatingActionButton floatingActionButton;
PrefManager prefManager;
KProgressHUD hud;
private FirebaseAnalytics mFirebaseAnalytics;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_page);
InitsViews();
}
public void InitsViews() {
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
prefManager = new PrefManager(this);
helpView = findViewById(R.id.de);
helpView.addJavascriptInterface(new WebAppInterface(this), "AndroidInterface");
helpView.getSettings().setJavaScriptEnabled(true);
helpView.getSettings().setDomStorageEnabled(true);
helpView.getSettings().setAppCacheEnabled(true);
ImageView imageView = new ImageView(this);
imageView.setBackgroundResource(R.drawable.original);
hud = KProgressHUD.create(MainPage.this)
.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
.setCancellable(false)
.setAnimationSpeed(2)
.setBackgroundColor(Color.parseColor("#ffa10197"))
.setDimAmount(0);
hud.show();
floatingActionButton = findViewById(R.id.floatingActionButton);
if (!prefManager.geRole().equals("0")) {
floatingActionButton.setImageResource(R.drawable.ic_logout);
}
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@SuppressLint("RestrictedApi")
@Override
public void onClick(View v) {
if (!prefManager.geRole().equals("0")) {
showDialog1();
} else {
hud.show();
floatingActionButton.setVisibility(View.GONE);
helpView.loadUrl(Splash.main.getLogin());
}
}
});
helpView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
helpView.setVisibility(View.GONE);
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
hud.dismiss();
if (prefManager.isFirstTimeLaunch()) {
if (view.getUrl().equals(Splash.main.getWebsite() + "/")) {
injectScriptFile(view, "lib.js");
getSupportActionBar().setSubtitle(view.getUrl());
}
if (view.getUrl().contains(Splash.main.getLogin())) {
getSupportActionBar().setSubtitle(view.getUrl());
}
}
helpView.setVisibility(View.VISIBLE);
}
});
if (!prefManager.geRole().equals("0")) {
hud.show();
String[] user = prefManager.geRole().split(":");
helpView.loadUrl(Splash.main.getWelcome() + "?name=" + user[0] + "&private=" + user[1] + "&user_id=" + user[2] + "&random=" +
getRandomNumberInRange(999, 15000));
} else {
hud.show();
helpView.loadUrl(Splash.main.getWelcome());
}
}
@SuppressLint("RestrictedApi")
@Override
public void onBackPressed() {
if (!helpView.getUrl().contains(Splash.main.getWelcome())) {
if (!prefManager.geRole().equals("0")) {
hud.show();
String[] user = prefManager.geRole().split(":");
helpView.loadUrl(Splash.main.getWelcome() + "?name=" + user[0] + "&private=" + user[1] + "&user_id=" + user[2] + "&random=" +
getRandomNumberInRange(999, 15000));
} else {
hud.show();
helpView.loadUrl(Splash.main.getWelcome());
}
floatingActionButton.setVisibility(View.VISIBLE);
getSupportActionBar().setSubtitle(null);
} else {
finish();
}
}
@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);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_favorite:
hud.show();
getSupportActionBar().setSubtitle(null);
helpView.loadUrl(Splash.main.getHelp());
return true;
case R.id.action_help:
View buttonAddProduct = findViewById(R.id.action_help);
showPopupMenu(buttonAddProduct);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void injectScriptFile(WebView view, String scriptFile) {
InputStream input;
try {
xvflage = true;
InputStream stream = new ByteArrayInputStream(Splash.main.getActions().getJavascript().getBytes());
Log.e("javascr", Splash.main.getActions().getJavascript());
input = getAssets().open(scriptFile);
int x = input.available();
byte[] buffer = new byte[x];
input.read(buffer);
input.close();
// String-ify the script byte-array using BASE64 encoding !!!
String encoded = Base64.encodeToString(buffer, Base64.NO_WRAP);
String encoded1 = Base64.encodeToString(Splash.main.getActions().getJavascript().getBytes(), Base64.NO_WRAP);
Log.e("ed", encoded);
view.loadUrl("javascript:(function() {" +
"var parent = document.getElementsByTagName('head').item(0);" +
"var script = document.createElement('script');" +
"script.type = 'text/javascript';" +
// Tell the browser to BASE64-decode the string into your script !!!
"script.innerHTML = window.atob('" + encoded + "');" +
"parent.appendChild(script)" +
"})()");
view.loadUrl("javascript:(function() {" +
"var parent = document.getElementsByTagName('head').item(0);" +
"var script = document.createElement('script');" +
"script.type = 'text/javascript';" +
// Tell the browser to BASE64-decode the string into your script !!!
"script.innerHTML = window.atob('" + encoded1 + "');" +
"parent.appendChild(script)" +
"})()");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
public void clearCookies(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
Log.d("f", "Using clearCookies code for API >=" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));
CookieManager.getInstance().removeAllCookies(null);
CookieManager.getInstance().flush();
} else {
Log.d("f", "Using clearCookies code for API <" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));
CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
cookieSyncMngr.startSync();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
cookieManager.removeSessionCookie();
cookieSyncMngr.stopSync();
cookieSyncMngr.sync();
}
startActivity(new Intent(MainPage.this, Splash.class));
finish();
}
private void showPopupMenu(View view) {
// inflate menu
PopupMenu popup = new PopupMenu(MainPage.this, view);
for (int x = 0; x < Splash.main.getMenu().size(); x++)
{
popup.getMenu().add(Splash.main.getMenu().get(x).getText());
}
popup.setOnMenuItemClickListener(new MyMenuItemClickListener());
popup.show();
}
public void showDialog1() {
// Create the object of
// AlertDialog Builder class
AlertDialog.Builder builder = new AlertDialog.Builder(MainPage.this);
builder.setMessage("Are you sure you want to disconnect your Instagram account form InstaGroup app?");
builder.setTitle("InstaGroup");
builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onClick(DialogInterface dialog,
int which) {
helpView.clearCache(true);
helpView.clearHistory();
prefManager.setrole("0");
prefManager.setFirstTimeLaunch(true);
clearCookies(MainPage.this);
floatingActionButton.setImageResource(R.drawable.ic_add);
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.cancel();
}
});
// Create the Alert dialog
AlertDialog alertDialog = builder.create();
// Show the Alert Dialog box
alertDialog.show();
}
@Override
protected void onResume() {
if (!prefManager.geRole().equals("0")) {
String[] user = prefManager.geRole().split(":");
helpView.loadUrl(Splash.main.getWelcome() + "?name=" + user[0] + "&private=" + user[1] + "&user_id=" + user[2] + "&random=" +
getRandomNumberInRange(999, 15000));
} else {
helpView.loadUrl(Splash.main.getWelcome());
}
super.onResume();
}
@Override
public void onPause() {
finish();
super.onPause();
}
private int getRandomNumberInRange(int min, int max) {
if (min >= max) {
throw new IllegalArgumentException("max must be greater than min");
}
Random r = new Random();
return r.nextInt((max - min) + 1) + min;
}
/**
* Click listener for popup menu items
*/
class MyMenuItemClickListener implements PopupMenu.OnMenuItemClickListener {
public MyMenuItemClickListener() {
}
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
for (int x = 0; x < Splash.main.getMenu().size(); x++) {
if (menuItem.getTitle().equals(Splash.main.getMenu().get(x).getText())) {
hud.show();
helpView.loadUrl(Splash.main.getMenu().get(x).getUrl());
getSupportActionBar().setSubtitle(null);
}
}
return true;
}
}
}