Browse Source

Getting rid of unnecessary casts in findViewById!!!

master
anthony restaino 8 years ago
parent
commit
395c967381
  1. 6
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 2
      app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java
  3. 4
      app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java
  4. 6
      app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java
  5. 6
      app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java
  6. 2
      app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java
  7. 4
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  8. 2
      app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java
  9. 6
      app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java
  10. 14
      app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java
  11. 6
      app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java
  12. 2
      app/src/main/java/acr/browser/lightning/utils/IntentUtils.java
  13. 6
      app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

6
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -327,8 +327,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
lp.height = LayoutParams.MATCH_PARENT; lp.height = LayoutParams.MATCH_PARENT;
customView.setLayoutParams(lp); customView.setLayoutParams(lp);
mArrowImage = (ImageView) customView.findViewById(R.id.arrow); mArrowImage = customView.findViewById(R.id.arrow);
FrameLayout arrowButton = (FrameLayout) customView.findViewById(R.id.arrow_button); FrameLayout arrowButton = customView.findViewById(R.id.arrow_button);
if (mShowTabsInDrawer) { if (mShowTabsInDrawer) {
if (mArrowImage.getWidth() <= 0) { if (mArrowImage.getWidth() <= 0) {
mArrowImage.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); mArrowImage.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
@ -366,7 +366,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
arrowButton.setOnClickListener(this); arrowButton.setOnClickListener(this);
// create the search EditText in the ToolBar // create the search EditText in the ToolBar
mSearch = (SearchView) customView.findViewById(R.id.search); mSearch = customView.findViewById(R.id.search);
mSearchBackground = customView.findViewById(R.id.search_container); mSearchBackground = customView.findViewById(R.id.search_container);
// initialize search background color // initialize search background color

2
app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java

@ -297,7 +297,7 @@ public class ReadingActivity extends AppCompatActivity {
case R.id.text_size_item: case R.id.text_size_item:
View view = LayoutInflater.from(this).inflate(R.layout.dialog_seek_bar, null); View view = LayoutInflater.from(this).inflate(R.layout.dialog_seek_bar, null);
final SeekBar bar = (SeekBar) view.findViewById(R.id.text_size_seekbar); final SeekBar bar = view.findViewById(R.id.text_size_seekbar);
bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override @Override

4
app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java

@ -29,7 +29,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// this is a workaround for the Toolbar in PreferenceActitivty // this is a workaround for the Toolbar in PreferenceActitivty
ViewGroup root = (ViewGroup) findViewById(android.R.id.content); ViewGroup root = findViewById(android.R.id.content);
LinearLayout content = (LinearLayout) root.getChildAt(0); LinearLayout content = (LinearLayout) root.getChildAt(0);
LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.toolbar_settings, null); LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.toolbar_settings, null);
@ -38,7 +38,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
root.addView(toolbarContainer); root.addView(toolbarContainer);
// now we can set the Toolbar using AppCompatPreferenceActivity // now we can set the Toolbar using AppCompatPreferenceActivity
Toolbar toolbar = (Toolbar) toolbarContainer.findViewById(R.id.toolbar); Toolbar toolbar = toolbarContainer.findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }

6
app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java

@ -82,8 +82,8 @@ public class BrowserDialog {
View layout = LayoutInflater.from(activity).inflate(R.layout.list_dialog, null); View layout = LayoutInflater.from(activity).inflate(R.layout.list_dialog, null);
TextView titleView = (TextView) layout.findViewById(R.id.dialog_title); TextView titleView = layout.findViewById(R.id.dialog_title);
ListView listView = (ListView) layout.findViewById(R.id.dialog_list); ListView listView = layout.findViewById(R.id.dialog_list);
ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, ArrayAdapter<String> adapter = new ArrayAdapter<>(activity,
android.R.layout.simple_list_item_1); android.R.layout.simple_list_item_1);
@ -136,7 +136,7 @@ public class BrowserDialog {
@StringRes int action, @StringRes int action,
@NonNull final EditorListener listener) { @NonNull final EditorListener listener) {
View dialogView = LayoutInflater.from(activity).inflate(R.layout.dialog_edit_text, null); View dialogView = LayoutInflater.from(activity).inflate(R.layout.dialog_edit_text, null);
final EditText editText = (EditText) dialogView.findViewById(R.id.dialog_edit_text); final EditText editText = dialogView.findViewById(R.id.dialog_edit_text);
editText.setHint(hint); editText.setHint(hint);
if (currentText != null) { if (currentText != null) {

6
app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java

@ -191,12 +191,12 @@ public class LightningDialogBuilder {
final AlertDialog.Builder editBookmarkDialog = new AlertDialog.Builder(activity); final AlertDialog.Builder editBookmarkDialog = new AlertDialog.Builder(activity);
editBookmarkDialog.setTitle(R.string.title_edit_bookmark); editBookmarkDialog.setTitle(R.string.title_edit_bookmark);
final View dialogLayout = View.inflate(activity, R.layout.dialog_edit_bookmark, null); final View dialogLayout = View.inflate(activity, R.layout.dialog_edit_bookmark, null);
final EditText getTitle = (EditText) dialogLayout.findViewById(R.id.bookmark_title); final EditText getTitle = dialogLayout.findViewById(R.id.bookmark_title);
getTitle.setText(item.getTitle()); getTitle.setText(item.getTitle());
final EditText getUrl = (EditText) dialogLayout.findViewById(R.id.bookmark_url); final EditText getUrl = dialogLayout.findViewById(R.id.bookmark_url);
getUrl.setText(item.getUrl()); getUrl.setText(item.getUrl());
final AutoCompleteTextView getFolder = final AutoCompleteTextView getFolder =
(AutoCompleteTextView) dialogLayout.findViewById(R.id.bookmark_folder); dialogLayout.findViewById(R.id.bookmark_folder);
getFolder.setHint(R.string.folder); getFolder.setHint(R.string.folder);
getFolder.setText(item.getFolder()); getFolder.setText(item.getFolder());

2
app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java

@ -495,7 +495,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
public void onComplete() { public void onComplete() {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity != null) { if (activity != null) {
String message = activity.getResources().getString(R.string.message_import); String message = activity.getString(R.string.message_import);
Utils.showSnackbar(activity, importList.size() + " " + message); Utils.showSnackbar(activity, importList.size() + " " + message);
} }
} }

4
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -320,10 +320,10 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
} }
private void setupNavigationButton(@NonNull View view, @IdRes int buttonId, @IdRes int imageId) { private void setupNavigationButton(@NonNull View view, @IdRes int buttonId, @IdRes int imageId) {
FrameLayout frameButton = (FrameLayout) view.findViewById(buttonId); FrameLayout frameButton = view.findViewById(buttonId);
frameButton.setOnClickListener(this); frameButton.setOnClickListener(this);
frameButton.setOnLongClickListener(this); frameButton.setOnLongClickListener(this);
ImageView buttonImage = (ImageView) view.findViewById(imageId); ImageView buttonImage = view.findViewById(imageId);
buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
} }

2
app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java

@ -152,7 +152,7 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater(); LayoutInflater inflater = getActivity().getLayoutInflater();
LinearLayout view = (LinearLayout) inflater.inflate(R.layout.dialog_seek_bar, null); LinearLayout view = (LinearLayout) inflater.inflate(R.layout.dialog_seek_bar, null);
final SeekBar bar = (SeekBar) view.findViewById(R.id.text_size_seekbar); final SeekBar bar = view.findViewById(R.id.text_size_seekbar);
final TextView sample = new TextView(getActivity()); final TextView sample = new TextView(getActivity());
sample.setText(R.string.untitled); sample.setText(R.string.untitled);
sample.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT)); sample.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT));

6
app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java

@ -257,8 +257,8 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
private void manualProxyPicker() { private void manualProxyPicker() {
View v = mActivity.getLayoutInflater().inflate(R.layout.dialog_manual_proxy, null); View v = mActivity.getLayoutInflater().inflate(R.layout.dialog_manual_proxy, null);
final EditText eProxyHost = (EditText) v.findViewById(R.id.proxyHost); final EditText eProxyHost = v.findViewById(R.id.proxyHost);
final EditText eProxyPort = (EditText) v.findViewById(R.id.proxyPort); final EditText eProxyPort = v.findViewById(R.id.proxyPort);
// Limit the number of characters since the port needs to be of type int // Limit the number of characters since the port needs to be of type int
// Use input filters to limite the EditText length and determine the max // Use input filters to limite the EditText length and determine the max
@ -519,7 +519,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
private void downPicker() { private void downPicker() {
View dialogView = LayoutInflater.from(mActivity).inflate(R.layout.dialog_edit_text, null); View dialogView = LayoutInflater.from(mActivity).inflate(R.layout.dialog_edit_text, null);
final EditText getDownload = (EditText) dialogView.findViewById(R.id.dialog_edit_text); final EditText getDownload = dialogView.findViewById(R.id.dialog_edit_text);
final int errorColor = ContextCompat.getColor(mActivity, R.color.error_red); final int errorColor = ContextCompat.getColor(mActivity, R.color.error_red);
final int regularColor = ThemeUtils.getTextColor(mActivity); final int regularColor = ThemeUtils.getTextColor(mActivity);

14
app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java

@ -130,7 +130,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
} else { } else {
view = inflater.inflate(R.layout.tab_strip, container, false); view = inflater.inflate(R.layout.tab_strip, container, false);
layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
ImageView newTab = (ImageView) view.findViewById(R.id.new_tab_button); ImageView newTab = view.findViewById(R.id.new_tab_button);
newTab.setColorFilter(ThemeUtils.getIconDarkThemeColor(getActivity())); newTab.setColorFilter(ThemeUtils.getIconDarkThemeColor(getActivity()));
newTab.setOnClickListener(new View.OnClickListener() { newTab.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -183,7 +183,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
private void setupFrameLayoutButton(@NonNull final View root, @IdRes final int buttonId, private void setupFrameLayoutButton(@NonNull final View root, @IdRes final int buttonId,
@IdRes final int imageId) { @IdRes final int imageId) {
final View frameButton = root.findViewById(buttonId); final View frameButton = root.findViewById(buttonId);
final ImageView buttonImage = (ImageView) root.findViewById(imageId); final ImageView buttonImage = root.findViewById(imageId);
frameButton.setOnClickListener(this); frameButton.setOnClickListener(this);
frameButton.setOnLongClickListener(this); frameButton.setOnLongClickListener(this);
buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
@ -399,11 +399,11 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
public LightningViewHolder(@NonNull View view) { public LightningViewHolder(@NonNull View view) {
super(view); super(view);
txtTitle = (TextView) view.findViewById(R.id.textTab); txtTitle = view.findViewById(R.id.textTab);
favicon = (ImageView) view.findViewById(R.id.faviconTab); favicon = view.findViewById(R.id.faviconTab);
exit = (ImageView) view.findViewById(R.id.deleteButton); exit = view.findViewById(R.id.deleteButton);
layout = (LinearLayout) view.findViewById(R.id.tab_item_background); layout = view.findViewById(R.id.tab_item_background);
exitButton = (FrameLayout) view.findViewById(R.id.deleteAction); exitButton = view.findViewById(R.id.deleteAction);
exit.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); exit.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
exitButton.setOnClickListener(this); exitButton.setOnClickListener(this);

6
app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java

@ -136,9 +136,9 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable {
private static class SuggestionHolder { private static class SuggestionHolder {
SuggestionHolder(@NonNull View view) { SuggestionHolder(@NonNull View view) {
mTitle = (TextView) view.findViewById(R.id.title); mTitle = view.findViewById(R.id.title);
mUrl = (TextView) view.findViewById(R.id.url); mUrl = view.findViewById(R.id.url);
mImage = (ImageView) view.findViewById(R.id.suggestionIcon); mImage = view.findViewById(R.id.suggestionIcon);
} }
@NonNull final ImageView mImage; @NonNull final ImageView mImage;

2
app/src/main/java/acr/browser/lightning/utils/IntentUtils.java

@ -1,14 +1,12 @@
package acr.browser.lightning.utils; package acr.browser.lightning.utils;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.FileUriExposedException;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;

6
app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

@ -135,9 +135,9 @@ public class LightningWebClient extends WebViewClient {
View dialogView = LayoutInflater.from(mActivity).inflate(R.layout.dialog_auth_request, null); View dialogView = LayoutInflater.from(mActivity).inflate(R.layout.dialog_auth_request, null);
final TextView realmLabel = (TextView) dialogView.findViewById(R.id.auth_request_realm_textview); final TextView realmLabel = dialogView.findViewById(R.id.auth_request_realm_textview);
final EditText name = (EditText) dialogView.findViewById(R.id.auth_request_username_edittext); final EditText name = dialogView.findViewById(R.id.auth_request_username_edittext);
final EditText password = (EditText) dialogView.findViewById(R.id.auth_request_password_edittext); final EditText password = dialogView.findViewById(R.id.auth_request_password_edittext);
realmLabel.setText(mActivity.getString(R.string.label_realm, realm)); realmLabel.setText(mActivity.getString(R.string.label_realm, realm));

Loading…
Cancel
Save