Skip to content

Commit

Permalink
SonarQube - Remove unnecessary type castings - #778
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlittle committed Feb 7, 2019
1 parent 19b2ac6 commit 8259963
Show file tree
Hide file tree
Showing 68 changed files with 230 additions and 236 deletions.
Expand Up @@ -55,9 +55,9 @@ public void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_about);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
viewPager = (ViewPager) findViewById(R.id.activity_about_pager);
viewPager = findViewById(R.id.activity_about_pager);

tabs = (TabLayout) findViewById(R.id.tabs_toolbar);
tabs = findViewById(R.id.tabs_toolbar);

Bundle bundle = this.getIntent().getExtras();
if (bundle != null) {
Expand Down
Expand Up @@ -61,7 +61,7 @@ public class AppActivity extends AppCompatActivity implements APIKeyRequestListe
* @param activities: list of activities to show on the ScheduleReminders section
*/
public void drawReminders(List<org.digitalcampus.oppia.model.Activity> activities){
ScheduleReminders reminders = (ScheduleReminders) findViewById(R.id.schedule_reminders);
ScheduleReminders reminders = findViewById(R.id.schedule_reminders);
if (reminders != null){
reminders.initSheduleReminders(activities);
}
Expand Down Expand Up @@ -90,7 +90,7 @@ protected void onStart(boolean overrideTitle, boolean configureActionBar){
if (!configureActionBar)
return;

Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null){
setSupportActionBar( toolbar );
}
Expand Down
Expand Up @@ -90,7 +90,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_course);
ActionBar actionBar = getSupportActionBar();
prefs = PreferenceManager.getDefaultSharedPreferences(this);
viewPager = (ViewPager) findViewById(R.id.activity_widget_pager);
viewPager = findViewById(R.id.activity_widget_pager);

Bundle bundle = this.getIntent().getExtras();
if (bundle != null) {
Expand All @@ -111,7 +111,7 @@ public void onCreate(Bundle savedInstanceState) {
actionBar.setDisplayShowTitleEnabled(true);
}
}
tabs = (TabLayout) findViewById(R.id.tabs_toolbar);
tabs = findViewById(R.id.tabs_toolbar);

loadActivities();
}
Expand Down
Expand Up @@ -239,7 +239,7 @@ public Boolean call() throws Exception {

private void initializeCourseIndex(boolean animate){

final ListView listView = (ListView) findViewById(R.id.section_list);
final ListView listView = findViewById(R.id.section_list);
if (listView == null) return;
ViewCompat.setNestedScrollingEnabled(listView, true);
sla = new SectionListAdapter(CourseIndexActivity.this, course, sections, new SectionListAdapter.CourseClickListener() {
Expand Down
Expand Up @@ -56,18 +56,18 @@ public void onCreate(Bundle savedInstanceState) {
cmp = course.getMetaPage(pageID);
}

TextView titleTV = (TextView) findViewById(R.id.course_title);
TextView titleTV = findViewById(R.id.course_title);
String title = cmp.getLang(prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage())).getContent();
titleTV.setText(title);

TextView versionTV = (TextView) findViewById(R.id.course_versionid);
TextView versionTV = findViewById(R.id.course_versionid);
BigDecimal big = new BigDecimal(course.getVersionId());
versionTV.setText(big.toString());

TextView shortnameTV = (TextView) findViewById(R.id.course_shortname);
TextView shortnameTV = findViewById(R.id.course_shortname);
shortnameTV.setText(course.getShortname());

WebView wv = (WebView) this.findViewById(R.id.metapage_webview);
WebView wv = this.findViewById(R.id.metapage_webview);
String url = course.getLocation() + File.separator +cmp.getLang(prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage())).getLocation();

try {
Expand Down
Expand Up @@ -57,7 +57,7 @@ public class DeviceListActivity extends Activity {

public static String EXTRA_DEVICE_ADDRESS = "device_address";
private static final List<String> BLUETOOTH_PERMISSIONS = Arrays.asList(
//Remember to update this when the Manifest permisssions change!
//Remember to update this when the Manifest permissions change!
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION
);
Expand All @@ -81,7 +81,7 @@ protected void onCreate(Bundle savedInstanceState) {

scanningMessage = findViewById(R.id.scanning_message);
// Initialize the button to perform device discovery
scanButton = (Button) findViewById(R.id.button_scan);
scanButton = findViewById(R.id.button_scan);
scanButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

Expand Down Expand Up @@ -125,12 +125,12 @@ public Boolean call() {
mNewDevicesArrayAdapter = new ArrayAdapter<>(this, R.layout.device_row);

// Find and set up the ListView for paired devices
ListView pairedListView = (ListView) findViewById(R.id.paired_devices);
ListView pairedListView = findViewById(R.id.paired_devices);
pairedListView.setAdapter(pairedDevicesArrayAdapter);
pairedListView.setOnItemClickListener(mDeviceClickListener);

// Find and set up the ListView for newly discovered devices
ListView newDevicesListView = (ListView) findViewById(R.id.new_devices);
ListView newDevicesListView = findViewById(R.id.new_devices);
newDevicesListView.setAdapter(mNewDevicesArrayAdapter);
newDevicesListView.setOnItemClickListener(mDeviceClickListener);

Expand Down
Expand Up @@ -89,7 +89,7 @@ public void onCreate(Bundle savedInstanceState) {
Tag t = (Tag) bundle.getSerializable(Tag.TAG);
if (t != null){
this.url = MobileLearning.SERVER_TAG_PATH + String.valueOf(t.getId()) + File.separator;
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null){
toolbar.setSubtitle(t.getName());
}
Expand All @@ -103,7 +103,7 @@ public void onCreate(Bundle savedInstanceState) {
courses = new ArrayList<>();
dla = new DownloadCourseListAdapter(this, courses);
dla.setOnClickListener(new CourseListListener());
ListView listView = (ListView) findViewById(R.id.tag_list);
ListView listView = findViewById(R.id.tag_list);
if (listView != null) {
listView.setAdapter(dla);
}
Expand Down
Expand Up @@ -101,7 +101,7 @@ public void onCreate(Bundle savedInstanceState) {
dmla = new DownloadMediaListAdapter(this, missingMedia);
dmla.setOnClickListener(new DownloadMediaListener());

mediaList = (ListView) findViewById(R.id.missing_media_list);
mediaList = findViewById(R.id.missing_media_list);
mediaList.setAdapter(dmla);

mediaList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
Expand Down Expand Up @@ -211,11 +211,11 @@ public void onDestroyActionMode(ActionMode mode) {
});

missingMediaContainer = this.findViewById(R.id.home_messages);
downloadSelected = (TextView) this.findViewById(R.id.download_selected);
unselectAll = (TextView) this.findViewById(R.id.unselect_all);
downloadSelected = this.findViewById(R.id.download_selected);
unselectAll = this.findViewById(R.id.unselect_all);


downloadViaPCBtn = (Button) this.findViewById(R.id.download_media_via_pc_btn);
downloadViaPCBtn = this.findViewById(R.id.download_media_via_pc_btn);
downloadViaPCBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
downloadViaPC();
Expand All @@ -224,7 +224,7 @@ public void onClick(View v) {

Media.resetMediaScan(prefs);

emptyState = (TextView) findViewById(R.id.empty_state);
emptyState = findViewById(R.id.empty_state);
}

@Override
Expand Down
Expand Up @@ -121,12 +121,12 @@ public void onCreate(Bundle savedInstanceState) {
}

messageContainer = this.findViewById(R.id.home_messages);
messageText = (TextView) this.findViewById(R.id.home_message);
messageButton = (Button) this.findViewById(R.id.message_action_button);
messageText = this.findViewById(R.id.home_message);
messageButton = this.findViewById(R.id.message_action_button);

courses = new ArrayList<>();
courseListAdapter = new CourseListAdapter(this, courses);
courseList = (ListView) findViewById(R.id.course_list);
courseList = findViewById(R.id.course_list);
courseList.setAdapter(courseListAdapter);

CourseContextMenuCustom courseMenu = new CourseContextMenuCustom(this);
Expand Down Expand Up @@ -184,13 +184,13 @@ private void displayCourses() {
courses.clear();
courses.addAll(coursesRepository.getCourses(this));

LinearLayout llLoading = (LinearLayout) this.findViewById(R.id.loading_courses);
LinearLayout llLoading = this.findViewById(R.id.loading_courses);
llLoading.setVisibility(View.GONE);

if (courses.size() < MobileLearning.DOWNLOAD_COURSES_DISPLAY){
displayDownloadSection();
} else {
TextView tv = (TextView) this.findViewById(R.id.manage_courses_text);
TextView tv = this.findViewById(R.id.manage_courses_text);
tv.setText(R.string.no_courses);
noCoursesView.setVisibility(View.GONE);
}
Expand All @@ -209,7 +209,7 @@ private void updateReminders(){

this.drawReminders(activities);
} else {
LinearLayout ll = (LinearLayout) findViewById(R.id.schedule_reminders);
LinearLayout ll = findViewById(R.id.schedule_reminders);
ll.setVisibility(View.GONE);
}
}
Expand Down Expand Up @@ -248,10 +248,10 @@ private void startPrefsActivity(){
private void displayDownloadSection(){
noCoursesView.setVisibility(View.VISIBLE);

TextView tv = (TextView) this.findViewById(R.id.manage_courses_text);
TextView tv = this.findViewById(R.id.manage_courses_text);
tv.setText((!courses.isEmpty())? R.string.more_courses : R.string.no_courses);

Button manageBtn = (Button) this.findViewById(R.id.manage_courses_btn);
Button manageBtn = this.findViewById(R.id.manage_courses_btn);
manageBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AdminSecurityManager.checkAdminPermission(OppiaMobileActivity.this, R.id.menu_download, new AdminSecurityManager.AuthListener() {
Expand Down
Expand Up @@ -61,8 +61,8 @@ public void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_scorecard);

viewPager = (ViewPager) findViewById(R.id.activity_scorecard_pager);
tabs = (TabLayout) findViewById(R.id.tabs_toolbar);
viewPager = findViewById(R.id.activity_scorecard_pager);
tabs = findViewById(R.id.tabs_toolbar);
prefs = PreferenceManager.getDefaultSharedPreferences(this);

Bundle bundle = this.getIntent().getExtras();
Expand Down
Expand Up @@ -75,7 +75,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_search);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
srla = new SearchResultsListAdapter(this, results);
resultsList = (ListView) findViewById(R.id.search_results_list);
resultsList = findViewById(R.id.search_results_list);
if (resultsList != null) {
resultsList.setAdapter(srla);
resultsList.setOnItemClickListener(new OnItemClickListener() {
Expand Down Expand Up @@ -106,7 +106,7 @@ public void onStart(){
DbHelper db = DbHelper.getInstance(this);
userId = db.getUserId(prefs.getString("preUsername", ""));

searchText = (EditText) findViewById(R.id.search_string);
searchText = findViewById(R.id.search_string);
searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
//@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Expand All @@ -115,9 +115,9 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return false;
}
});
summary = (TextView) findViewById(R.id.search_results_summary);
loadingSpinner = (ProgressBar) findViewById(R.id.progressBar);
searchButton = (ImageView) findViewById(R.id.searchbutton);
summary = findViewById(R.id.search_results_summary);
loadingSpinner = findViewById(R.id.progressBar);
searchButton = findViewById(R.id.searchbutton);
if (searchButton != null) {
searchButton.setClickable(true);
searchButton.setOnClickListener(new View.OnClickListener() {
Expand Down
Expand Up @@ -78,7 +78,7 @@ public void onErrorDialogClosed() {
if (!isGooglePlayAvailable) return;
}

tvProgress = (TextView) this.findViewById(R.id.start_up_progress);
tvProgress = this.findViewById(R.id.start_up_progress);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
String username = SessionManager.getUsername(this);
Mint.setUserIdentifier( username.equals("") ? "anon" : username);
Expand Down
Expand Up @@ -33,8 +33,8 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_sync);
viewPager = (ViewPager) findViewById(R.id.activity_sync_pager);
tabs = (TabLayout) findViewById(R.id.tabs_toolbar);
viewPager = findViewById(R.id.activity_sync_pager);
tabs = findViewById(R.id.tabs_toolbar);

Bundle bundle = this.getIntent().getExtras();
if (bundle != null) {
Expand All @@ -47,7 +47,7 @@ public void onStart() {
super.onStart();

// Make the Toolbar back button call the back press (to close possible bluetooth connection)
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null){
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Expand Up @@ -66,7 +66,7 @@ public void onCreate(Bundle savedInstanceState) {
tags = new ArrayList<>();
tla = new TagListAdapter(this, tags);

ListView listView = (ListView) findViewById(R.id.tag_list);
ListView listView = findViewById(R.id.tag_list);
listView.setAdapter(tla);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Expand Down
Expand Up @@ -40,7 +40,7 @@ protected void onCreate(Bundle savedInstanceState) {
final String digest = intent.getData().getQueryParameter(ACTIVITY_DIGEST_PARAM);

activityDetail = findViewById(R.id.activity_detail);
errorText = (TextView) findViewById(R.id.error_text);
errorText = findViewById(R.id.error_text);

boolean validDigest = validate(digest);
if (validDigest){
Expand Down
Expand Up @@ -52,14 +52,13 @@ public class WelcomeActivity extends AppActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
//tabs = (TabLayout) findViewById(R.id.tabs_toolbar);
viewPager = (ViewPager) findViewById(R.id.activity_welcome_pager);
viewPager = findViewById(R.id.activity_welcome_pager);
}

@Override
public void onStart() {
super.onStart(true, false);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.getMenu().clear();
toolbar.inflateMenu(R.menu.activity_welcome);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
Expand Down
Expand Up @@ -75,7 +75,7 @@ public void updateTabViews(TabLayout tabs) {

for (int i = 0; i < tabs.getTabCount(); i++) {
View v = LayoutInflater.from(ctx).inflate(R.layout.tablayout_fixed_tab, null);
TextView tv = (TextView) v.findViewById(R.id.tabTitle);
TextView tv = v.findViewById(R.id.tabTitle);
tv.setText(tabTitles.get(i));

TabLayout.Tab tab = tabs.getTabAt(i);
Expand Down
Expand Up @@ -57,8 +57,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.fragment_badges_list_row, parent, false);
viewHolder = new BadgeViewHolder();
viewHolder.badgeDescription = (TextView) convertView.findViewById(R.id.badges_description);
viewHolder.badgeDate = (TextView) convertView.findViewById(R.id.badges_date);
viewHolder.badgeDescription = convertView.findViewById(R.id.badges_description);
viewHolder.badgeDate = convertView.findViewById(R.id.badges_date);
convertView.setTag(viewHolder);
}
else{
Expand Down
Expand Up @@ -73,10 +73,10 @@ public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.course_list_row, parent, false);
viewHolder = new CourseViewHolder();
viewHolder.courseTitle = (TextView) convertView.findViewById(R.id.course_title);
viewHolder.courseDescription = (TextView) convertView.findViewById(R.id.course_description);
viewHolder.courseProgress = (ProgressBar) convertView.findViewById(R.id.course_progress_bar);
viewHolder.courseImage = (ImageView) convertView.findViewById(R.id.course_image);
viewHolder.courseTitle = convertView.findViewById(R.id.course_title);
viewHolder.courseDescription = convertView.findViewById(R.id.course_description);
viewHolder.courseProgress = convertView.findViewById(R.id.course_progress_bar);
viewHolder.courseImage = convertView.findViewById(R.id.course_image);
viewHolder.barAnimator = new ProgressBarAnimator(viewHolder.courseProgress);
convertView.setTag(viewHolder);
}
Expand Down
Expand Up @@ -59,7 +59,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.scorecard_quiz_item, parent, false);
viewHolder = new QuizStatsViewHolder();
viewHolder.percent = (TextView) convertView.findViewById(R.id.percent_label);
viewHolder.percent = convertView.findViewById(R.id.percent_label);
viewHolder.baseView = convertView;
convertView.setTag(viewHolder);
}
Expand Down
Expand Up @@ -84,13 +84,13 @@ public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.course_download_row, parent, false);
viewHolder = new DownloadCourseViewHolder();
viewHolder.courseTitle = (TextView) convertView.findViewById(R.id.course_title);
viewHolder.courseDraft = (TextView) convertView.findViewById(R.id.course_draft);
viewHolder.courseDescription = (TextView) convertView.findViewById(R.id.course_description);
viewHolder.actionBtn = (ImageButton) convertView.findViewById(R.id.download_course_btn);
viewHolder.actionProgress = (ProgressBar) convertView.findViewById(R.id.download_progress);
viewHolder.courseAuthor = (TextView) convertView.findViewById(R.id.course_author);
viewHolder.labelAuthor = (TextView) convertView.findViewById(R.id.label_author);
viewHolder.courseTitle = convertView.findViewById(R.id.course_title);
viewHolder.courseDraft = convertView.findViewById(R.id.course_draft);
viewHolder.courseDescription = convertView.findViewById(R.id.course_description);
viewHolder.actionBtn = convertView.findViewById(R.id.download_course_btn);
viewHolder.actionProgress = convertView.findViewById(R.id.download_progress);
viewHolder.courseAuthor = convertView.findViewById(R.id.course_author);
viewHolder.labelAuthor = convertView.findViewById(R.id.label_author);

convertView.setTag(viewHolder);
}
Expand Down

0 comments on commit 8259963

Please sign in to comment.