Unverified Commit a7886d9c authored by Vitalii Koshura's avatar Vitalii Koshura Committed by GitHub

Merge pull request #3987 from Isira-Seneviratne/Avoid_potential_memory_usage_problems

[Android] Avoid potential memory usage problems.
parents 7ea8f427 f8841585
......@@ -135,7 +135,6 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.fragment:fragment-ktx:1.2.5'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
......
......@@ -33,10 +33,10 @@ import android.widget.AdapterView
import android.widget.AdapterView.OnItemClickListener
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import androidx.fragment.app.replace
import androidx.legacy.app.ActionBarDrawerToggle
import androidx.lifecycle.lifecycleScope
import edu.berkeley.boinc.adapter.NavDrawerListAdapter
import edu.berkeley.boinc.adapter.NavDrawerListAdapter.NavDrawerItem
......@@ -112,11 +112,8 @@ class BOINCActivity : AppCompatActivity() {
// enabling action bar app icon and behaving it as toggle button
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
supportActionBar!!.setHomeButtonEnabled(true)
supportActionBar!!.setHomeAsUpIndicator(R.drawable.ic_baseline_menu_white)
// TODO: Replace with a non-deprecated class.
mDrawerToggle = object : ActionBarDrawerToggle(this, binding.drawerLayout,
R.drawable.ic_baseline_menu_white, //nav menu toggle icon
R.string.app_name, // nav drawer openapplicationContext - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
......
......@@ -18,7 +18,6 @@
*/
package edu.berkeley.boinc
import androidx.appcompat.app.AppCompatDelegate
import androidx.multidex.MultiDexApplication
import androidx.preference.PreferenceManager
import edu.berkeley.boinc.di.AppComponent
......@@ -28,7 +27,6 @@ import edu.berkeley.boinc.utils.setAppTheme
open class BOINCApplication : MultiDexApplication() {
override fun onCreate() {
super.onCreate()
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
setAppTheme(sharedPreferences.getString("theme", "light")!!)
......
......@@ -23,7 +23,6 @@ import android.graphics.Bitmap
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.core.net.toUri
import androidx.core.text.HtmlCompat
import androidx.recyclerview.widget.RecyclerView
......@@ -71,8 +70,7 @@ class NoticesRecyclerViewAdapter(
// if available set icon, if not boinc logo
// if available set icon, if not boinc logo
if (icon == null) {
holder.projectIcon.setImageDrawable(ContextCompat.getDrawable(fragment.requireContext(),
R.drawable.ic_boinc))
holder.projectIcon.setImageResource(R.drawable.ic_boinc)
} else {
holder.projectIcon.setImageBitmap(icon)
}
......
......@@ -26,7 +26,7 @@ import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.appcompat.content.res.AppCompatResources;
import java.util.List;
......@@ -36,7 +36,7 @@ import edu.berkeley.boinc.R;
import edu.berkeley.boinc.rpc.RpcClient;
public class ProjectControlsListAdapter extends ArrayAdapter<ProjectControl> {
private List<ProjectControl> entries; // ID of control texts in strings.xml
private final List<ProjectControl> entries; // ID of control texts in strings.xml
public ProjectControlsListAdapter(Activity activity, List<ProjectControl> entries) {
super(activity, R.layout.projects_controls_listitem_layout, entries);
......@@ -89,14 +89,14 @@ public class ProjectControlsListAdapter extends ArrayAdapter<ProjectControl> {
text = getContext().getResources().getString(R.string.projects_control_reset);
break;
case RpcClient.PROJECT_DETACH:
tvText.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_light_red_background));
tvText.setBackground(AppCompatResources.getDrawable(getContext(), R.drawable.shape_light_red_background));
text = getContext().getResources().getString(R.string.projects_control_remove);
break;
case RpcClient.MGR_SYNC:
text = getContext().getResources().getString(R.string.projects_control_sync_acctmgr);
break;
case RpcClient.MGR_DETACH:
tvText.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_light_red_background));
tvText.setBackground(AppCompatResources.getDrawable(getContext(), R.drawable.shape_light_red_background));
text = getContext().getResources().getString(R.string.projects_control_remove_acctmgr);
break;
case RpcClient.TRANSFER_RETRY:
......
......@@ -33,6 +33,7 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
import org.apache.commons.lang3.StringUtils;
......@@ -192,7 +193,7 @@ public class ProjectsListAdapter extends ArrayAdapter<ProjectsListData> {
// if available set icon, if not boinc logo
if(icon == null) {
// BOINC logo
ivIcon.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_boinc));
ivIcon.setImageResource(R.drawable.ic_boinc);
}
else {
// project icon
......@@ -299,8 +300,8 @@ public class ProjectsListAdapter extends ArrayAdapter<ProjectsListData> {
RelativeLayout iconBackground = vi.findViewById(R.id.icon_background);
if(data.getProject().getAttachedViaAcctMgr()) {
final Drawable background =
ContextCompat.getDrawable(activity.getApplicationContext(),
R.drawable.shape_boinc_icon_light_blue_background);
AppCompatResources.getDrawable(activity.getApplicationContext(),
R.drawable.shape_boinc_icon_light_blue_background);
iconBackground.setBackground(background);
}
else {
......
......@@ -69,8 +69,7 @@ class TaskRecyclerViewAdapter(
if (item.id != finalIconId) {
val icon = getIcon(position)
if (icon == null) {
holder.projectIcon.setImageDrawable(AppCompatResources.getDrawable(fragment.requireContext(),
R.drawable.ic_boinc))
holder.projectIcon.setImageResource(R.drawable.ic_boinc)
} else {
holder.projectIcon.setImageBitmap(icon)
holder.projectIcon.tag = item.id
......
......@@ -22,7 +22,6 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.RecyclerView
import edu.berkeley.boinc.R
......@@ -54,7 +53,7 @@ class BatchConflictRecyclerViewAdapter(
holder.resolveButtonImage.visibility = View.GONE
holder.statusProgressBar.visibility = View.GONE
holder.statusImage.visibility = View.VISIBLE
holder.statusImage.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_baseline_check))
holder.statusImage.setImageResource(R.drawable.ic_baseline_check)
} else if (listItem.result == ProjectAttachService.RESULT_ONGOING ||
listItem.result == ProjectAttachService.RESULT_UNINITIALIZED) {
// ongoing
......@@ -82,7 +81,7 @@ class BatchConflictRecyclerViewAdapter(
holder.resolveButtonImage.visibility = View.GONE
holder.statusProgressBar.visibility = View.GONE
holder.statusImage.visibility = View.VISIBLE
holder.statusImage.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_baseline_clear))
holder.statusImage.setImageResource(R.drawable.ic_baseline_clear)
} else {
// failed
holder.status.visibility = View.VISIBLE
......@@ -97,11 +96,11 @@ class BatchConflictRecyclerViewAdapter(
}
holder.statusProgressBar.visibility = View.GONE
holder.statusImage.visibility = View.VISIBLE
holder.statusImage.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_baseline_clear))
holder.statusImage.setImageResource(R.drawable.ic_baseline_clear)
}
}
inner class ViewHolder(binding: AttachProjectBatchConflictsListItemBinding):
class ViewHolder(binding: AttachProjectBatchConflictsListItemBinding):
RecyclerView.ViewHolder(binding.root) {
val name = binding.name
val status = binding.status
......
......@@ -27,7 +27,7 @@ import android.os.Build
import android.os.RemoteException
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.drawable.toBitmap
import edu.berkeley.boinc.BOINCActivity
import edu.berkeley.boinc.R
......@@ -75,7 +75,7 @@ suspend fun writeClientModeAsync(mode: Int) = coroutineScope {
//from https://stackoverflow.com/questions/33696488/getting-bitmap-from-vector-drawable
fun Context.getBitmapFromVectorDrawable(@DrawableRes drawableId: Int): Bitmap {
val drawable = ContextCompat.getDrawable(this, drawableId)!!
val drawable = AppCompatResources.getDrawable(this, drawableId)!!
return drawable.toBitmap()
}
......
<!--
This file is part of BOINC.
http://boinc.berkeley.edu
Copyright (C) 2020 University of California
BOINC is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
BOINC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BOINC. If not, see <http://www.gnu.org/licenses/>.
-->
<vector android:height="48dp" android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/black" android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z"/>
</vector>
<!--
This file is part of BOINC.
http://boinc.berkeley.edu
Copyright (C) 2020 University of California
BOINC is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
BOINC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BOINC. If not, see <http://www.gnu.org/licenses/>.
-->
<vector android:height="48dp" android:tint="@android:color/white"
android:viewportHeight="24" android:viewportWidth="24"
android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z"/>
</vector>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment