1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-30 00:01:19 +00:00

Remove unneeded explicit view casts

This commit is contained in:
Felix Ableitner 2017-09-26 11:53:52 +09:00
parent 5aed81a8f3
commit 3f0be34f3e
19 changed files with 56 additions and 67 deletions

View file

@ -159,15 +159,15 @@ public class DeviceActivity extends SyncthingActivity implements View.OnClickLis
setTitle(mIsCreateMode ? R.string.add_device : R.string.edit_device); setTitle(mIsCreateMode ? R.string.add_device : R.string.edit_device);
mIdContainer = findViewById(R.id.idContainer); mIdContainer = findViewById(R.id.idContainer);
mIdView = (EditText) findViewById(R.id.id); mIdView = findViewById(R.id.id);
mQrButton = findViewById(R.id.qrButton); mQrButton = findViewById(R.id.qrButton);
mNameView = (EditText) findViewById(R.id.name); mNameView = findViewById(R.id.name);
mAddressesView = (EditText) findViewById(R.id.addresses); mAddressesView = findViewById(R.id.addresses);
mCurrentAddressView = (TextView) findViewById(R.id.currentAddress); mCurrentAddressView = findViewById(R.id.currentAddress);
mCompressionContainer = findViewById(R.id.compressionContainer); mCompressionContainer = findViewById(R.id.compressionContainer);
mCompressionValueView = (TextView) findViewById(R.id.compressionValue); mCompressionValueView = findViewById(R.id.compressionValue);
mIntroducerView = (SwitchCompat) findViewById(R.id.introducer); mIntroducerView = findViewById(R.id.introducer);
mSyncthingVersionView = (TextView) findViewById(R.id.syncthingVersion); mSyncthingVersionView = findViewById(R.id.syncthingVersion);
mQrButton.setOnClickListener(this); mQrButton.setOnClickListener(this);
mCompressionContainer.setOnClickListener(this); mCompressionContainer.setOnClickListener(this);

View file

@ -43,7 +43,7 @@ public class FirstStartActivity extends Activity implements Button.OnClickListen
} }
setContentView(R.layout.activity_first_start); setContentView(R.layout.activity_first_start);
Button cont = (Button) findViewById(R.id.cont); Button cont = findViewById(R.id.cont);
cont.setOnClickListener(this); cont.setOnClickListener(this);
} }

View file

@ -123,13 +123,13 @@ public class FolderActivity extends SyncthingActivity
setTitle(mIsCreateMode ? R.string.create_folder : R.string.edit_folder); setTitle(mIsCreateMode ? R.string.create_folder : R.string.edit_folder);
registerOnServiceConnectedListener(this); registerOnServiceConnectedListener(this);
mLabelView = (EditText) findViewById(R.id.label); mLabelView = findViewById(R.id.label);
mIdView = (EditText) findViewById(R.id.id); mIdView = findViewById(R.id.id);
mPathView = (TextView) findViewById(R.id.directoryTextView); mPathView = findViewById(R.id.directoryTextView);
mFolderMasterView = (SwitchCompat) findViewById(R.id.master); mFolderMasterView = findViewById(R.id.master);
mVersioningDescriptionView = (TextView) findViewById(R.id.versioningDescription); mVersioningDescriptionView = findViewById(R.id.versioningDescription);
mVersioningTypeView = (TextView) findViewById(R.id.versioningType); mVersioningTypeView = findViewById(R.id.versioningType);
mDevicesContainer = (ViewGroup) findViewById(R.id.devicesContainer); mDevicesContainer = findViewById(R.id.devicesContainer);
mPathView.setOnClickListener(view -> mPathView.setOnClickListener(view ->
startActivityForResult(FolderPickerActivity.createIntent(this, mFolder.path), FolderPickerActivity.DIRECTORY_REQUEST_CODE)); startActivityForResult(FolderPickerActivity.createIntent(this, mFolder.path), FolderPickerActivity.DIRECTORY_REQUEST_CODE));

View file

@ -77,7 +77,7 @@ public class FolderPickerActivity extends SyncthingActivity
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_folder_picker); setContentView(R.layout.activity_folder_picker);
mListView = (ListView) findViewById(android.R.id.list); mListView = findViewById(android.R.id.list);
mListView.setOnItemClickListener(this); mListView.setOnItemClickListener(this);
mListView.setEmptyView(findViewById(android.R.id.empty)); mListView.setEmptyView(findViewById(android.R.id.empty));
mFilesAdapter = new FileAdapter(this); mFilesAdapter = new FileAdapter(this);
@ -252,7 +252,7 @@ public class FolderPickerActivity extends SyncthingActivity
@NonNull @NonNull
public View getView(int position, View convertView, @NonNull ViewGroup parent) { public View getView(int position, View convertView, @NonNull ViewGroup parent) {
convertView = super.getView(position, convertView, parent); convertView = super.getView(position, convertView, parent);
TextView title = (TextView) convertView.findViewById(android.R.id.text1); TextView title = convertView.findViewById(android.R.id.text1);
File f = getItem(position); File f = getItem(position);
title.setText(f.getName()); title.setText(f.getName());
int textColor = (f.isDirectory()) int textColor = (f.isDirectory())
@ -274,7 +274,7 @@ public class FolderPickerActivity extends SyncthingActivity
@NonNull @NonNull
public View getView(int position, View convertView, @NonNull ViewGroup parent) { public View getView(int position, View convertView, @NonNull ViewGroup parent) {
convertView = super.getView(position, convertView, parent); convertView = super.getView(position, convertView, parent);
TextView title = (TextView) convertView.findViewById(android.R.id.text1); TextView title = convertView.findViewById(android.R.id.text1);
title.setText(getItem(position).getAbsolutePath()); title.setText(getItem(position).getAbsolutePath());
return convertView; return convertView;
} }

View file

@ -45,8 +45,8 @@ public class LogActivity extends SyncthingActivity {
invalidateOptionsMenu(); invalidateOptionsMenu();
} }
mLog = (TextView) findViewById(R.id.log); mLog = findViewById(R.id.log);
mScrollView = (ScrollView) findViewById(R.id.scroller); mScrollView = findViewById(R.id.scroller);
updateLog(); updateLog();
} }

View file

@ -206,12 +206,12 @@ public class MainActivity extends StateDialogActivity
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout = findViewById(R.id.drawer_layout);
mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager = findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabContainer); TabLayout tabLayout = findViewById(R.id.tabContainer);
tabLayout.setupWithViewPager(mViewPager); tabLayout.setupWithViewPager(mViewPager);
if (savedInstanceState != null) { if (savedInstanceState != null) {
@ -283,8 +283,8 @@ public class MainActivity extends StateDialogActivity
outState.putBoolean(IS_SHOWING_RESTART_DIALOG, mRestartDialog != null && mRestartDialog.isShowing()); outState.putBoolean(IS_SHOWING_RESTART_DIALOG, mRestartDialog != null && mRestartDialog.isShowing());
if(mQrCodeDialog != null && mQrCodeDialog.isShowing()) { if(mQrCodeDialog != null && mQrCodeDialog.isShowing()) {
outState.putBoolean(IS_QRCODE_DIALOG_DISPLAYED, true); outState.putBoolean(IS_QRCODE_DIALOG_DISPLAYED, true);
ImageView qrCode = (ImageView) mQrCodeDialog.findViewById(R.id.qrcode_image_view); ImageView qrCode = mQrCodeDialog.findViewById(R.id.qrcode_image_view);
TextView deviceID = (TextView) mQrCodeDialog.findViewById(R.id.device_id); TextView deviceID = mQrCodeDialog.findViewById(R.id.device_id);
outState.putParcelable(QRCODE_BITMAP_KEY, ((BitmapDrawable) qrCode.getDrawable()).getBitmap()); outState.putParcelable(QRCODE_BITMAP_KEY, ((BitmapDrawable) qrCode.getDrawable()).getBitmap());
outState.putString(DEVICEID_KEY, deviceID.getText().toString()); outState.putString(DEVICEID_KEY, deviceID.getText().toString());
} }
@ -329,9 +329,9 @@ public class MainActivity extends StateDialogActivity
public void showQrCodeDialog(String deviceId, Bitmap qrCode) { public void showQrCodeDialog(String deviceId, Bitmap qrCode) {
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
View qrCodeDialogView = this.getLayoutInflater().inflate(R.layout.dialog_qrcode, null); View qrCodeDialogView = this.getLayoutInflater().inflate(R.layout.dialog_qrcode, null);
TextView deviceIdTextView = (TextView) qrCodeDialogView.findViewById(R.id.device_id); TextView deviceIdTextView = qrCodeDialogView.findViewById(R.id.device_id);
TextView shareDeviceIdTextView = (TextView) qrCodeDialogView.findViewById(R.id.actionShareId); TextView shareDeviceIdTextView = qrCodeDialogView.findViewById(R.id.actionShareId);
ImageView qrCodeImageView = (ImageView) qrCodeDialogView.findViewById(R.id.qrcode_image_view); ImageView qrCodeImageView = qrCodeDialogView.findViewById(R.id.qrcode_image_view);
deviceIdTextView.setText(deviceId); deviceIdTextView.setText(deviceId);
deviceIdTextView.setOnClickListener(v -> Util.copyDeviceId(this, deviceIdTextView.getText().toString())); deviceIdTextView.setOnClickListener(v -> Util.copyDeviceId(this, deviceIdTextView.getText().toString()));
@ -463,7 +463,7 @@ public class MainActivity extends StateDialogActivity
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
View v = LayoutInflater.from(MainActivity.this) View v = LayoutInflater.from(MainActivity.this)
.inflate(R.layout.dialog_usage_reporting, null); .inflate(R.layout.dialog_usage_reporting, null);
TextView tv = (TextView) v.findViewById(R.id.example); TextView tv = v.findViewById(R.id.example);
tv.setText(report); tv.setText(report);
new AlertDialog.Builder(MainActivity.this) new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.usage_reporting_dialog_title) .setTitle(R.string.usage_reporting_dialog_title)

View file

@ -28,7 +28,6 @@ import com.nutomic.syncthingandroid.util.Util;
import com.nutomic.syncthingandroid.views.WifiSsidPreference; import com.nutomic.syncthingandroid.views.WifiSsidPreference;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import java.util.List;
import eu.chainfire.libsuperuser.Shell; import eu.chainfire.libsuperuser.Shell;

View file

@ -56,7 +56,7 @@ public class ShareActivity extends StateDialogActivity
this, android.R.layout.simple_spinner_item, folders); this, android.R.layout.simple_spinner_item, folders);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner sItems = (Spinner) findViewById(R.id.folders); Spinner sItems = findViewById(R.id.folders);
sItems.setAdapter(adapter); sItems.setAdapter(adapter);
} }
@ -80,11 +80,11 @@ public class ShareActivity extends StateDialogActivity
registerOnServiceConnectedListener(this); registerOnServiceConnectedListener(this);
Spinner mFoldersSpinner = (Spinner) findViewById(R.id.folders); Spinner mFoldersSpinner = findViewById(R.id.folders);
Button mShareButton = (Button) findViewById(R.id.share_button); Button mShareButton = findViewById(R.id.share_button);
Button mCancelButton = (Button) findViewById(R.id.cancel_button); Button mCancelButton = findViewById(R.id.cancel_button);
EditText mShareName = (EditText) findViewById(R.id.name); EditText mShareName = findViewById(R.id.name);
TextView mShareTitle = (TextView) findViewById(R.id.namesTitle); TextView mShareTitle = findViewById(R.id.namesTitle);
// TODO: add support for EXTRA_TEXT (notes, memos sharing) // TODO: add support for EXTRA_TEXT (notes, memos sharing)
ArrayList<Uri> extrasToCopy = new ArrayList<>(); ArrayList<Uri> extrasToCopy = new ArrayList<>();

View file

@ -27,9 +27,8 @@ public abstract class StateDialogActivity extends SyncthingActivity {
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
registerOnServiceConnectedListener(() -> { registerOnServiceConnectedListener(() ->
getService().registerOnApiChangeListener(this::onApiChange); getService().registerOnApiChangeListener(this::onApiChange));
});
} }
@Override @Override
@ -96,7 +95,7 @@ public abstract class StateDialogActivity extends SyncthingActivity {
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = getLayoutInflater();
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
View dialogLayout = inflater.inflate(R.layout.dialog_loading, null); View dialogLayout = inflater.inflate(R.layout.dialog_loading, null);
TextView loadingText = (TextView) dialogLayout.findViewById(R.id.loading_text); TextView loadingText = dialogLayout.findViewById(R.id.loading_text);
loadingText.setText((getIntent().getBooleanExtra(EXTRA_FIRST_START, false)) loadingText.setText((getIntent().getBooleanExtra(EXTRA_FIRST_START, false))
? R.string.web_gui_creating_key ? R.string.web_gui_creating_key
: R.string.api_loading); : R.string.api_loading);

View file

@ -46,9 +46,7 @@ public abstract class SyncthingActivity extends ToolbarBindingActivity implement
public void onServiceConnected(ComponentName componentName, IBinder iBinder) { public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
SyncthingServiceBinder binder = (SyncthingServiceBinder) iBinder; SyncthingServiceBinder binder = (SyncthingServiceBinder) iBinder;
mSyncthingService = binder.getService(); mSyncthingService = binder.getService();
for (OnServiceConnectedListener listener : mServiceConnectedListeners) { mServiceConnectedListeners.forEach(OnServiceConnectedListener::onServiceConnected);
listener.onServiceConnected();
}
mServiceConnectedListeners.clear(); mServiceConnectedListeners.clear();
} }

View file

@ -21,7 +21,7 @@ public abstract class ToolbarBindingActivity extends AppCompatActivity {
protected void onPostCreate(Bundle savedInstanceState) { protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState); super.onPostCreate(savedInstanceState);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar == null) if (toolbar == null)
return; return;

View file

@ -45,7 +45,7 @@ public class VersioningDialogActivity extends AppCompatActivity {
} }
private void initiateFinishBtn() { private void initiateFinishBtn() {
Button finishBtn = (Button) findViewById(R.id.finish_btn); Button finishBtn = findViewById(R.id.finish_btn);
finishBtn.setOnClickListener(v -> { finishBtn.setOnClickListener(v -> {
saveConfiguration(); saveConfiguration();
finish(); finish();
@ -59,7 +59,7 @@ public class VersioningDialogActivity extends AppCompatActivity {
} }
private void initiateSpinner() { private void initiateSpinner() {
Spinner versioningTypeSpinner = (Spinner) findViewById(R.id.versioningTypeSpinner); Spinner versioningTypeSpinner = findViewById(R.id.versioningTypeSpinner);
versioningTypeSpinner.setSelection(mTypes.indexOf(getIntent().getExtras().getString("type"))); versioningTypeSpinner.setSelection(mTypes.indexOf(getIntent().getExtras().getString("type")));
versioningTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { versioningTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override

View file

@ -125,7 +125,7 @@ public class WebGuiActivity extends StateDialogActivity
mConfig = new ConfigXml(this); mConfig = new ConfigXml(this);
loadCaCert(); loadCaCert();
mWebView = (WebView) findViewById(R.id.webview); mWebView = findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(mWebViewClient); mWebView.setWebViewClient(mWebViewClient);
mWebView.clearCache(true); mWebView.clearCache(true);

View file

@ -90,13 +90,13 @@ public class DrawerFragment extends Fragment implements View.OnClickListener {
@Override @Override
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
mCpuUsage = (TextView) view.findViewById(R.id.cpu_usage); mCpuUsage = view.findViewById(R.id.cpu_usage);
mRamUsage = (TextView) view.findViewById(R.id.ram_usage); mRamUsage = view.findViewById(R.id.ram_usage);
mDownload = (TextView) view.findViewById(R.id.download); mDownload = view.findViewById(R.id.download);
mUpload = (TextView) view.findViewById(R.id.upload); mUpload = view.findViewById(R.id.upload);
mAnnounceServer = (TextView) view.findViewById(R.id.announce_server); mAnnounceServer = view.findViewById(R.id.announce_server);
mVersion = (TextView) view.findViewById(R.id.version); mVersion = view.findViewById(R.id.version);
mExitButton = (TextView) view.findViewById(R.id.drawerActionExit); mExitButton = view.findViewById(R.id.drawerActionExit);
view.findViewById(R.id.drawerActionWebGui) view.findViewById(R.id.drawerActionWebGui)
.setOnClickListener(this); .setOnClickListener(this);

View file

@ -43,7 +43,7 @@ public class ExternalVersioningFragment extends Fragment {
} }
private void initateTextView() { private void initateTextView() {
TextView commandTextView = (TextView) mView.findViewById(R.id.commandTextView); TextView commandTextView = mView.findViewById(R.id.commandTextView);
commandTextView.setText(getCommand()); commandTextView.setText(getCommand());
commandTextView.addTextChangedListener(new TextWatcher() { commandTextView.addTextChangedListener(new TextWatcher() {

View file

@ -60,7 +60,7 @@ public class StaggeredVersioningFragment extends Fragment {
} }
private void initiateVersionsPathTextView() { private void initiateVersionsPathTextView() {
mPathView = (TextView) mView.findViewById(R.id.directoryTextView); mPathView = mView.findViewById(R.id.directoryTextView);
String currentPath = getVersionsPath(); String currentPath = getVersionsPath();
mPathView.setText(currentPath); mPathView.setText(currentPath);

View file

@ -1,9 +1,6 @@
package com.nutomic.syncthingandroid.util; package com.nutomic.syncthingandroid.util;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.text.TextUtils; import android.text.TextUtils;
@ -11,7 +8,6 @@ import android.util.Log;
import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.service.SyncthingRunnable; import com.nutomic.syncthingandroid.service.SyncthingRunnable;
import com.nutomic.syncthingandroid.service.SyncthingService;
import com.nutomic.syncthingandroid.util.Util; import com.nutomic.syncthingandroid.util.Util;
import org.mindrot.jbcrypt.BCrypt; import org.mindrot.jbcrypt.BCrypt;
@ -23,7 +19,6 @@ import org.xml.sax.SAXException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.DataOutputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Locale; import java.util.Locale;
@ -37,7 +32,6 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import eu.chainfire.libsuperuser.Shell;
/** /**
* Provides direct access to the config.xml file in the file system. * Provides direct access to the config.xml file in the file system.
* *

View file

@ -2,7 +2,6 @@ package com.nutomic.syncthingandroid.util;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context;
import android.widget.Toast; import android.widget.Toast;
import android.util.Log; import android.util.Log;
import android.content.Context; import android.content.Context;

View file

@ -36,10 +36,10 @@ public class DevicesAdapter extends ArrayAdapter<Device> {
convertView = inflater.inflate(R.layout.item_device_list, parent, false); convertView = inflater.inflate(R.layout.item_device_list, parent, false);
} }
TextView name = (TextView) convertView.findViewById(R.id.name); TextView name = convertView.findViewById(R.id.name);
TextView status = (TextView) convertView.findViewById(R.id.status); TextView status = convertView.findViewById(R.id.status);
TextView download = (TextView) convertView.findViewById(R.id.download); TextView download = convertView.findViewById(R.id.download);
TextView upload = (TextView) convertView.findViewById(R.id.upload); TextView upload = convertView.findViewById(R.id.upload);
String deviceId = getItem(position).deviceID; String deviceId = getItem(position).deviceID;