Android 查找不推荐使用的API的步骤
我得到了这个活动。ReportActivity.java 在我重新编译之后,这里是错误 使用或重写不推荐使用的API。 使用-Xlint重新编译:详细信息不推荐 但是,该活动在右上角有一个绿色勾号,没有任何警告 我的问题是,Android 查找不推荐使用的API的步骤,android,Android,我得到了这个活动。ReportActivity.java 在我重新编译之后,这里是错误 使用或重写不推荐使用的API。 使用-Xlint重新编译:详细信息不推荐 但是,该活动在右上角有一个绿色勾号,没有任何警告 我的问题是, 1.哪里是不推荐的方法 2.如何在编译过程中消除警告 package tk.myessentialoils.a16personalities; import android.content.Intent; import android.content.res.AssetMa
1.哪里是不推荐的方法
2.如何在编译过程中消除警告
package tk.myessentialoils.a16personalities;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class ReportActivity extends CustomMenu {
private TextView mTextMessage;
String path ="portraits";
LinearLayout parent;
int[] result = new int[4];
String typeName;
List<String[]> rows;
Spinner spinner;
TextView textView,desc;
BottomNavigationView navView;
int navigator;
ImageView imageView;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
mTextMessage.scrollTo(0,0);
mTextMessage.setText(Html.fromHtml(getStringResourceByName(typeName+"2")));
navigator=R.id.navigation_home;
return true;
case R.id.navigation_dashboard:
mTextMessage.scrollTo(0,0);
mTextMessage.setText(Html.fromHtml(getStringResourceByName(typeName+"1")));
navigator=R.id.navigation_dashboard;
return true;
case R.id.navigation_notifications:
mTextMessage.scrollTo(0,0);
mTextMessage.setText(Html.fromHtml(getStringResourceByName(typeName+"3")));
navigator=R.id.navigation_notifications;
return true;
}
return false;
}
};
public void setImageParticular(){
rows = new ArrayList<>();
CSVReader csvReader = new CSVReader(this, "16p.csv");
try {
rows = csvReader.readCSV();
} catch (IOException e) {
e.printStackTrace();
}
int i = check();
//int i = Arrays.asList(rows).indexOf(typeName.toUpperCase());
TextView job = findViewById(R.id.textView11);
job.setText(String.valueOf(rows.get(i)[1]));
desc = findViewById(R.id.textView7);
String a = (rows.get(i)[2]+"\n"+(rows.get(i)[3]));
//String a = String.valueOf(rows.get(i)[2]+"\n"+String.valueOf(rows.get(i)[3]));
desc.setText(a);
textView.setText(typeName.toUpperCase());
mTextMessage.setText(Html.fromHtml(getStringResourceByName(typeName+"2")));
}
public int check (){
int index = -1;
for (int i=0;i<rows.size();i++) {
if (rows.get(i)[0].equals(typeName.toUpperCase())) {
index = i;
break;
}
}
Log.d("index",""+index);
return index;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_report);
navView = findViewById(R.id.nav_view);
parent = findViewById(R.id.linearChart);
spinner = findViewById(R.id.spinner2);
mTextMessage = findViewById(R.id.description);
mTextMessage.setMovementMethod(new ScrollingMovementMethod());
navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
Intent intent = getIntent();
typeName = intent.getStringExtra("type");
textView = findViewById(R.id.textView10);
textView.setText(typeName.toUpperCase());
mTextMessage.setText(Html.fromHtml(getStringResourceByName(typeName+"2")));
//Log.d("TYPE",typeName);
setImage(typeName);
result = intent.getIntArrayExtra("arrays");
Log.d("Array", "arr: " + Arrays.toString(result));
if (result!=null){
drawMyChart();
}
setImageParticular();
boolean result = intent.getBooleanExtra("result",false);
//Toast.makeText(this,typeName,Toast.LENGTH_SHORT).show();
if (result) {
spinner.setVisibility(View.GONE);
desc.setVisibility(View.GONE);
imageView.setVisibility(View.GONE);
}else {
addItemsOnSpinner();
}
}
public void addItemsOnSpinner() {
final ArrayList<String> items = new ArrayList<>();
AssetManager assetManager = getApplicationContext().getAssets();
try {
for (String file : Objects.requireNonNull(assetManager.list(path))) {
if (file.endsWith(".jpg"))
items.add(file.replaceAll(".jpg$", "").toUpperCase());
}
} catch (IOException e) {
e.printStackTrace();
}
//List<String> stringList = new ArrayList<String>(Arrays.asList(list));
ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, items);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
typeName = items.get(position).toLowerCase();
setImage(items.get(position).toLowerCase());
setImageParticular();
navView.setSelectedItemId(navigator);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
public void setImage(String typeName){
imageView = findViewById(R.id.imageView4);
InputStream inputStream = null;
try {
inputStream = getAssets().open(path+"/"+typeName+".jpg");
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
imageView.setImageBitmap(bitmap);
}
private String getStringResourceByName(String aString) {
String packageName = getPackageName();
int resId = getResources().getIdentifier(aString, "string", packageName);
return getString(resId);
}
public void drawMyChart(){
String[]a= new String[]{
check(result[0], "E", "I"),
check(result[1], "N", "S"),
check(result[2], "T", "F"),
check(result[3], "P", "J")};
for (int i = 0; i< result.length; i++){
double percent = (result[i] - 8) * 100 >> 5;
//double percent = (result[i]-8)*100/32;
float f = (float) percent/100;
if(result[i]>24){
createBarChart(f,a[i]);
}else{
createBarChart(1-f,a[i]);
}
Log.d("PERCENT",""+percent+","+f);
}
}
public String check(int set,String a, String b){
if (set>24){
return a;
}else{
return b;
}
}
public void createBarChart(float percent, String a){
View custom = getLayoutInflater().inflate(R.layout.layout_bar_chart, null);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, 100);
lp.weight = percent;
LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(0, 100);
lp2.weight = 1-percent;
LinearLayout leftLL = custom.findViewById(R.id.leftLL);
leftLL.setLayoutParams(lp);
LinearLayout rightLL = custom.findViewById(R.id.rightLL);
rightLL.setLayoutParams(lp2);
TextView tvLeft = custom.findViewById(R.id.left_percentage);
String b = String.format("%.0f", (double) percent *100)+"%";
tvLeft.setText(b);
TextView textView= custom.findViewById(R.id.leftLetter);
textView.setText(a);
parent.addView(custom);
}
}
包装tk.myessentialoils.A16;
导入android.content.Intent;
导入android.content.res.AssetManager;
导入android.graphics.Bitmap;
导入android.graphics.BitmapFactory;
导入android.os.Bundle;
导入android.support.annotation.NonNull;
导入android.support.design.widget.BottomNavigationView;
导入android.text.Html;
导入android.text.method.ScrollingMovementMethod;
导入android.util.Log;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ArrayAdapter;
导入android.widget.ImageView;
导入android.widget.LinearLayout;
导入android.widget.Spinner;
导入android.widget.TextView;
导入java.io.IOException;
导入java.io.InputStream;
导入java.util.ArrayList;
导入java.util.array;
导入java.util.List;
导入java.util.Objects;
公共类ReportActivity扩展自定义菜单{
私有文本视图mTextMessage;
String path=“肖像”;
直系亲属;
int[]结果=新的int[4];
字符串类型名;
列出行;
纺纱机;
TextView TextView,desc;
底部导航视图导航视图;
int导航器;
图像视图图像视图;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
=新的BottomNavigationView.OnNavigationItemSelectedListener(){
@凌驾
公共布尔值onNavigationItemSelected(@NonNull MenuItem item){
开关(item.getItemId()){
案例R.id.navigation\u主页:
mTextMessage.scrollTo(0,0);
mTextMessage.setText(Html.fromHtml(getStringResourceByName(typeName+“2”)));
导航器=R.id.navigation\u home;
返回true;
案例R.id.navigation\u仪表板:
mTextMessage.scrollTo(0,0);
mTextMessage.setText(Html.fromHtml(getStringResourceByName(typeName+“1”)));
导航器=R.id.navigation\u仪表板;
返回true;
案例R.id.navigation\u通知:
mTextMessage.scrollTo(0,0);
mTextMessage.setText(Html.fromHtml(getStringResourceByName(typeName+“3”)));
navigator=R.id.navigation\u通知;
返回true;
}
返回false;
}
};
public void setImageSpecial(){
行=新的ArrayList();
CSVReader CSVReader=新CSVReader(本“16p.csv”);
试一试{
rows=csvReader.readCSV();
}捕获(IOE异常){
e、 printStackTrace();
}
int i=检查();
//inti=Arrays.asList(rows.indexOf(typeName.toUpperCase());
TextView作业=findViewById(R.id.textView11);
job.setText(String.valueOf(rows.get(i)[1]));
desc=findViewById(R.id.textView7);
字符串a=(rows.get(i)[2]+“\n”+(rows.get(i)[3]);
//String a=String.valueOf(rows.get(i)[2]+“\n”+String.valueOf(rows.get(i)[3]);
desc.setText(a);
textView.setText(typeName.toUpperCase());
mTextMessage.setText(Html.fromHtml(getStringResourceByName(typeName+“2”)));
}
公共整数检查(){
int指数=-1;
对于(int i=0;i父级){
}
});
}
public void setImage(字符串类型名){
imageView=findViewById(R.id.imageView4);
InputStream InputStream=null;
试一试{
inputStream=getAssets().open(路径+“/”+typeName+”.jpg”);
}捕获(IOE异常){
e、 printStackTrace();
}
位图位图=位图工厂.decodeStream(inputStream);
设置图像位图(位图);
}
私有字符串getStringResourceByName(字符串搜索){
字符串packageName=getPackageName();
int resId=getResources().getIdentifier(aString,“string”,packageName);
返回getString(resId);
}
公共无效drawMyChart(){
字符串[]a=新字符串[]{
检查(结果[0]、“E”、“I”),
检查(结果[1],“N”,“S”),
检查(结果[2],“T”,“F”),
检查(结果[3],“P”,“J”)};
for(int i=0;i>5;
//双百分比=(结果[i]-8)*100/32;
浮动f=(浮动)百分比/100;
如果(结果[i]>24){
createBarChart(f,a[i]);
}否则{
createBarChart(1-f,a[i]);
}
对数d(“百分比”,“百分比+”,“+f”);
}
}
公共字符串检查(整数集、字符串a、字符串b){
如果(设置>24){
返回a;
}否则{
返回b;
}
}
公共无效createBarChart(浮动百分比,字符串a){
查看自定义=GetLayoutFlater()。充气(R.layout.layout\u条形图,空);
LinearLayout.LayoutParams lp=新的LinearLayout.LayoutParams(0,100);
lp.重量=百分比;
LinearLayout.LayoutParams lp2=新的LinearLayout.LayoutParams(0,100);
lp2.重量=1%;
LinearLayout leftLL=custom.findviewbyd(R.id.leftLL);
leftLL.setLayoutParams(lp);
LinearLayout rightLL=custom.findviewbyd(R.id.rightLL);
rightLL.setLayoutParams(lp2);
TextView tvleet=custom.findViewById(R.id.left\u百分比);
字符串b=String.format(“%.0f”,(双精度)百分比*100)+“%”;
tvleet.setText(b);
TextView TextView=custom.findViewById(R.id.leftLetter);
textView.setText(a);
parent.addView(自定义);
}
}
我认为,如果您运行LINT(很遗憾,我不记得选项在哪里),它将向您提供一个报告,其中将包括项目中哪些类和哪些行存在不推荐的API。它也可能不在您的项目中,可能是您正在导入的库。忽略它可以吗?是和否,您的应用程序仍然可以使用d