/*
* VoIP.ms SMS
* Copyright (C) 2015-2016 Michael Kourlas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.kourlas.voipms_sms.activities;
import android.annotation.TargetApi;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import net.kourlas.voipms_sms.R;
public class HelpActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
ViewCompat.setElevation(toolbar, getResources()
.getDimension(R.dimen.toolbar_elevation));
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
WebView browser = (WebView) findViewById(R.id.web_view);
browser.loadUrl(getString(R.string.help_url));
browser.setWebViewClient(new WebViewClient() {
@SuppressWarnings("deprecation")
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && (url.startsWith("http://")
|| url.startsWith("https://")))
{
view.getContext().startActivity(new Intent(
Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
@TargetApi(Build.VERSION_CODES.N)
@Override
public boolean shouldOverrideUrlLoading(WebView view,
WebResourceRequest request)
{
final String url = request.getUrl().toString();
if (url != null && (url.startsWith("http://")
|| url.startsWith("https://")))
{
view.getContext().startActivity(new Intent(
Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
ActivityMonitor.getInstance().deleteReferenceToActivity(this);
}
@Override
protected void onPause() {
super.onPause();
ActivityMonitor.getInstance().deleteReferenceToActivity(this);
}
@Override
protected void onResume() {
super.onResume();
ActivityMonitor.getInstance().setCurrentActivity(this);
}
}