/*
- * Copyright © 2017-2018 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2017-2019 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
*
import android.os.Bundle;
import android.os.LocaleList;
import android.preference.PreferenceManager;
-import android.support.v4.app.NavUtils;
-import android.support.v4.widget.SwipeRefreshLayout;
-import android.support.v7.app.ActionBar;
-import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.Toolbar;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.widget.ProgressBar;
import android.widget.TextView;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.Toolbar; // The AndroidX toolbar must be used until the minimum API is >= 21.
+import androidx.core.app.NavUtils;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+
import com.stoutner.privacybrowser.R;
import com.stoutner.privacybrowser.dialogs.AboutViewSourceDialog;
// Set the content view.
setContentView(R.layout.view_source_coordinatorlayout);
- // `SupportActionBar` from `android.support.v7.app.ActionBar` must be used until the minimum API is >= 21.
- Toolbar viewSourceAppBar = findViewById(R.id.view_source_toolbar);
- setSupportActionBar(viewSourceAppBar);
+ // The AndroidX toolbar must be used until the minimum API is >= 21.
+ Toolbar toolbar = findViewById(R.id.view_source_toolbar);
+ setSupportActionBar(toolbar);
- // Setup the app bar.
- final ActionBar appBar = getSupportActionBar();
+ // Get a handle for the action bar.
+ final ActionBar actionBar = getSupportActionBar();
- // Remove the incorrect warning in Android Studio that appBar might be null.
- assert appBar != null;
+ // Remove the incorrect lint warning that the action bar might be null.
+ assert actionBar != null;
- // Add the custom layout to the app bar.
- appBar.setCustomView(R.layout.view_source_app_bar);
- appBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
+ // Add the custom layout to the action bar.
+ actionBar.setCustomView(R.layout.view_source_app_bar);
+ actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
// Get a handle for the url text box.
EditText urlEditText = findViewById(R.id.url_edittext);
// Get the URL.
String url = urlEditText.getText().toString();
- // Get new source data for the URL if it begins with `http`/
+ // Get new source data for the URL if it begins with `http`.
if (url.startsWith("http")) {
new GetSource(this).execute(url);
} else {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
+ // Inflate the menu. This adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.view_source_options_menu, menu);
// Display the menu.
}
}
- // `String` declares the parameters. `Void` does not declare progress units. `String[]` contains the results.
+ // `String` declares the parameters. `Void` does not declare progress units. `SpannableStringBuilder[]` contains the results.
private static class GetSource extends AsyncTask<String, Void, SpannableStringBuilder[]> {
// Create a weak reference to the calling activity.
private WeakReference<Activity> activityWeakReference;
Activity viewSourceActivity = activityWeakReference.get();
// Abort if the activity is gone.
- if ((viewSourceActivity == null) || (viewSourceActivity.isFinishing())) {
+ if ((viewSourceActivity == null) || viewSourceActivity.isFinishing()) {
return;
}
Activity activity = activityWeakReference.get();
// Abort if the activity is gone.
- if ((activity == null) || (activity.isFinishing())) {
+ if ((activity == null) || activity.isFinishing()) {
return new SpannableStringBuilder[] {requestHeadersBuilder, responseMessageBuilder, responseHeadersBuilder, responseBodyBuilder};
}
// `onPostExecute()` operates on the UI thread.
@Override
protected void onPostExecute(SpannableStringBuilder[] viewSourceStringArray){
- // Get a handle the activity.
+ // Get a handle for the activity.
Activity activity = activityWeakReference.get();
// Abort if the activity is gone.
- if ((activity == null) || (activity.isFinishing())) {
+ if ((activity == null) || activity.isFinishing()) {
return;
}