Итак, у меня есть основное занятие, которое запускает приложение для моего веб-приложения.
package com.hayzedesign.webapp.activities;
import android.Manifest;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.webkit.DownloadListener;
import android.webkit.GeolocationPermissions;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;
import com.hayzedesign.webapp.BuildConfig;
import com.hayzedesign.webapp.R;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class HomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
protected String Timeline;
protected String Explore;
protected String Messages;
protected String SavedPosts;
protected String Albums;
protected String Events;
protected String Settings;
protected String Games;
protected String LogOut;
protected WebView webView;
private ProgressBar progressBar;
private FrameLayout frameLayout;
public NavigationView navigationView;
public static String PACKAGE_NAME;
private InterstitialAd interstitialAd;
protected AdView bannerAd;
public Toast exitToast;
private ValueCallback<Uri> mUploadMessage;
private Uri mCapturedImageURI = null;
private ValueCallback<Uri[]> mFilePathCallback;
private String mCameraPhotoPath;
private static final int INPUT_FILE_REQUEST_CODE = 1;
private static final int FILECHOOSER_RESULTCODE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
/** Link your web pages below */
// Timeline
Timeline = getResources().getString(R.string.Timeline);
// Explore
Explore = getResources().getString(R.string.Explore);
// Messages
Messages = getResources().getString(R.string.Messages);
// Saved Posts
SavedPosts = getResources().getString(R.string.SavedPosts);
// Albums
Albums = getResources().getString(R.string.Albums);
// Events
Events = getResources().getString(R.string.Events);
// Games
Games = getResources().getString(R.string.Games);
// Settings
Settings = getResources().getString(R.string.Settings);
// Logout
LogOut = getResources().getString(R.string.LogOut);
// Activity Theme
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
// Activity Layout
setContentView(R.layout.activity_home);
// Activity Toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Interstitial Ad
AdRequest adRequestInterstitial = new AdRequest.Builder().build();
interstitialAd = new InterstitialAd(HomeActivity.this);
interstitialAd.setAdUnitId(getString(R.string.admob_interstitial_id));
interstitialAd.loadAd(adRequestInterstitial);
interstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
displayInterstitialAd();
}
});
// Banner Ad
AdRequest adRequestBanner = new AdRequest.Builder().build();
MobileAds.initialize(this, getString(R.string.admob_app_id));
bannerAd = findViewById(R.id.adView);
bannerAd.loadAd(adRequestBanner);
bannerAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
bannerAd.setVisibility(View.VISIBLE);
}
@Override
public void onAdFailedToLoad(int error) {
bannerAd.setVisibility(View.GONE);
}
});
// Full Screen
/** Full Screen */
//Hides Status Bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//Hides Actionbar
getSupportActionBar().hide();
DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.Timeline);
frameLayout = findViewById(R.id.frameLayout);
webView = findViewById(R.id.webView);
progressBar = findViewById(R.id.progressBar);
progressBar.setMax(100);
webView.loadUrl(Timeline);
webView = findViewById(R.id.webView);
// Uncomment if you want zoom enabled
//webView.getSettings().supportZoom();
// If you don't want JavaScript enabled, change from true to false
webView.getSettings().setJavaScriptEnabled(true);
// If you don't want cache enabled, change from true to false
webView.getSettings().setAppCacheEnabled(true);
// If you don't want file upload enabled, change from true to false
webView.getSettings().setAllowFileAccess(true);
// If you don't want file upload enabled, change from true to false
webView.getSettings().setAllowContentAccess(true);
webView.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);
}
});
webView.setWebViewClient(new HelpClient());
webView.setWebChromeClient(new WebChromeClient(){
@Override
public void onGeolocationPermissionsShowPrompt(String origin,
GeolocationPermissions.Callback callback) {
//Runtime permission
ActivityCompat.requestPermissions(HomeActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
1);
callback.invoke(origin, true, false);
}
public void onProgressChanged(WebView view, int progress){
frameLayout.setVisibility(View.VISIBLE);
progressBar.setProgress(progress);
//Optional custom title before page has loaded:
setTitle("Loading...");
if (progress == 100) {
frameLayout.setVisibility(View.GONE);
// New title once this page has finished loading.
// Change to:
// setTitle("Your Title Here");
// If you want custom page title.
setTitle(view.getTitle());
}
super.onProgressChanged(view, progress);
}
// Fullscreen video support
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout mFullscreenContainer;
private int mOriginalOrientation;
private int mOriginalSystemUiVisibility;
public Bitmap getDefaultVideoPoster()
{
if (mCustomView == null) {
return null;
}
return BitmapFactory.decodeResource(getApplicationContext().getResources(), 2130837573);
}
public void onHideCustomView()
{
((FrameLayout)getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
setRequestedOrientation(this.mOriginalOrientation);
getSupportActionBar().show();
this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
{
if (this.mCustomView != null)
{
onHideCustomView();
return;
}
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();
this.mOriginalOrientation = getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
getSupportActionBar().hide();
((FrameLayout)getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
getWindow().getDecorView().setSystemUiVisibility(3846);
}
// << Image upload >>
// For Android 5.0
public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) {
// Double check that we don't have any existing callbacks
if (mFilePathCallback != null) {
mFilePathCallback.onReceiveValue(null);
}
mFilePathCallback = filePath;
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
} else {
takePictureIntent = null;
}
}
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
contentSelectionIntent.setType("image/*");
Intent[] intentArray;
if (takePictureIntent != null) {
intentArray = new Intent[]{takePictureIntent};
} else {
intentArray = new Intent[0];
}
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);
return true;
}
// openFileChooser for Android 3.0+
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
mUploadMessage = uploadMsg;
// Create AndroidExampleFolder at sdcard
// Create AndroidExampleFolder at sdcard
File imageStorageDir = new File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES)
, "AndroidExampleFolder");
if (!imageStorageDir.exists()) {
// Create AndroidExampleFolder at sdcard
imageStorageDir.mkdirs();
}
// Create camera captured image file path and name
File file = new File(
imageStorageDir + File.separator + "IMG_"
+ String.valueOf(System.currentTimeMillis())
+ ".jpg");
mCapturedImageURI = Uri.fromFile(file);
// Camera capture image intent
final Intent captureIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
// Create file chooser intent
Intent chooserIntent = Intent.createChooser(i, "Image Chooser");
// Set camera intent to file chooser
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS
, new Parcelable[] { captureIntent });
// On select image call onActivityResult method of activity
startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);
}
// openFileChooser for Android < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
openFileChooser(uploadMsg, "");
}
//openFileChooser for other Android versions
public void openFileChooser(ValueCallback<Uri> uploadMsg,
String acceptType,
String capture) {
openFileChooser(uploadMsg, acceptType);
}
});
// Exit prompt
exitToast = Toast.makeText(getApplicationContext(), "Tap again to exit", Toast.LENGTH_SHORT);
PACKAGE_NAME = getApplicationContext().getPackageName();
}
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File imageFile = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
return imageFile;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
super.onActivityResult(requestCode, resultCode, data);
return;
}
Uri[] results = null;
// Check that the response is a good one
if (resultCode == Activity.RESULT_OK) {
if (data == null || data.getDataString() == null) {
// If there is not data, then we may have taken a photo
if (mCameraPhotoPath != null) {
results = new Uri[]{Uri.parse(mCameraPhotoPath)};
}
} else {
String dataString = data.getDataString();
if (dataString != null) {
results = new Uri[]{Uri.parse(dataString)};
}
}
}
mFilePathCallback.onReceiveValue(results);
mFilePathCallback = null;
} else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
if (requestCode != FILECHOOSER_RESULTCODE || mUploadMessage == null) {
super.onActivityResult(requestCode, resultCode, data);
return;
}
if (requestCode == FILECHOOSER_RESULTCODE) {
if (null == this.mUploadMessage) {
return;
}
Uri result = null;
try {
if (resultCode != RESULT_OK) {
result = null;
} else {
// retrieve from the private variable if the intent is null
result = data == null ? mCapturedImageURI : data.getData();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "activity :" + e,
Toast.LENGTH_LONG).show();
}
mUploadMessage.onReceiveValue(result);
mUploadMessage = null;
}
}
return;
}
private class HelpClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains(".pdf")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "application/pdf");
try {
view.getContext().startActivity(intent);
view.loadUrl(url);
frameLayout.setVisibility(View.VISIBLE);
return true;
} catch (ActivityNotFoundException e) {
//user does not have a pdf viewer installed
}
} else {
view.loadUrl(url);
frameLayout.setVisibility(View.VISIBLE);
return true;
}
return false;
}
// Loading dialog
final ProgressDialog pd = ProgressDialog.show(HomeActivity.this, "", "Loading...", true);
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
pd.show();
super.onPageStarted(view, url, favicon);
}
public void onPageFinished(WebView view, String url) {
pd.dismiss();
super.onPageFinished(view, url);
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
/** No Internet Page */
webView.loadUrl("file:///android_asset/error.html");
}
}
@Override
public void onBackPressed() {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
}
else if(webView.canGoBack()) {
webView.goBack();
}
else {
if (exitToast.getView().isShown()) {
exitToast.cancel();
finish();
} else {
exitToast.show();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Actionbar menu items
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
/** Handle Actionbar item clicks here */
// Action 1
if (id == R.id.action_share) {
Intent shareIntent;
shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());
shareIntent.setType("text/plain");
startActivity(shareIntent);
}
// Action 2
else if (id == R.id.action_refresh) {
webView.reload();
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
/** Navigation Drawer Items */
/** Home */
if (id == R.id.Timeline) {
webView.loadUrl(Timeline);
}
/** 2nd item Explore*/
else if (id == R.id.Explore) {
webView.loadUrl(Explore);
}
/** 3rd item Messages */
else if (id == R.id.Messages) {
webView.loadUrl(Messages);
}
/** 4th item Saved Posts */
else if (id == R.id.SavedPosts) {
webView.loadUrl(SavedPosts);
}
/** 5th item Albums */
else if (id == R.id.Albums) {
webView.loadUrl(Albums);
}
/** 5th item Albums */
else if (id == R.id.Events) {
webView.loadUrl(Events);
}
/** 5th item Settings */
else if (id == R.id.Settings) {
webView.loadUrl(Settings);
}
/** 6th item Games */
else if (id == R.id.Games) {
webView.loadUrl(Games);
}
/** Share Action */
else if (id == R.id.share) {
Intent shareIntent;
shareIntent = new Intent();
PACKAGE_NAME = getApplicationContext().getPackageName();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT,
// Write your share text below
"Hey, earn money using " + getResources().getString(R.string.app_name) + ": " + "https://play.google.com/store/apps/details?id=" + PACKAGE_NAME);
shareIntent.setType("text/plain");
startActivity(shareIntent);
}
/** Rate Action */
else if (id == R.id.rateApp) {
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(myAppLinkToMarket);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "Unable to find Google Play", Toast.LENGTH_LONG).show();
}
}
/** About Action */
else if (id == R.id.about) {
String m1 = "Version " + BuildConfig.VERSION_NAME;
String m2 = "Copyright (c) " + getResources().getString(R.string.app_name);
String m3 = "All rights reserved.";
new AlertDialog.Builder(this)
.setIcon(R.mipmap.ic_launcher)
.setTitle("About " + getResources().getString(R.string.app_name))
.setMessage(m1 +"\n"+ m2 +"\n"+ m3)
.setNeutralButton("Close", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
}
/** LogOut Activity */
else if (id == R.id.LogOut) {
webView.loadUrl(LogOut);
}
/** Exit Action */
else if (id == R.id.exit) {
new AlertDialog.Builder(this)
.setIcon(R.mipmap.ic_launcher)
.setTitle("Closing " + getResources().getString(R.string.app_name))
.setMessage(R.string.exit)
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
finishAffinity();
System.exit(0);
}
})
.setNegativeButton("No", null)
.show();
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
public void displayInterstitialAd() {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
}
}
Как видите, нет ничего, что говорит swipeRefresh. или имеет какое-либо отношение к анимации swipeRefreshing. Что дает!? и как я могу отключить swipeRefresh на моем веб-приложении? PS мои фрагменты также не имеют swipeRefresh код.
Спасибо всем за помощь и советы.