今天需要做关于wode.xml中的数据展示,需要获取当月时间,对本月预算进行计算,将数据展示在我的界面之中
相关代码:
package com.example.myapplicationgb; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import com.example.myapplicationgb.domain.ImageItem; import com.example.myapplicationgb.utils.PickerConfig; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Calendar; import java.util.List; public class siFragment extends Fragment implements PickerConfig.OnImageSelectFinishListener{ private String context; private TextView mTextView; private Button daka; private final String TAG="siFragment"; int i=0; private TextView day; int year1,month1,day1; private DatabaseHelper mDatabaseHelper ; private List<CostBean> mCostBeanList; TextView zhichu_money; TextView yue_money; EditText jine; String jin; int all_1; Button queding; ImageView dreamImage; public siFragment(String context){ this.context = context; } public siFragment() { } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //取本月 Calendar calendar = Calendar.getInstance(); year1 = calendar.get(Calendar.YEAR); month1 = calendar.get(Calendar.MONTH)+1; day1 = calendar.get(Calendar.DAY_OF_MONTH); String i= siFragment.this.month1+"月"; Log.e("22",i); Cursor cursor =mDatabaseHelper.selectlist(i); if (cursor != null){ while (cursor.moveToNext()){ CostBean costBean = new CostBean(); costBean.costTitle = cursor.getString(cursor.getColumnIndex("cost_title")); costBean.costDate = cursor.getString(cursor.getColumnIndex("cost_date")); costBean.costMoney = cursor.getString(cursor.getColumnIndex("cost_money")); mCostBeanList.add(costBean); Log.e("data",costBean.costMoney ); } cursor.close(); } } @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.wode,container,false); mDatabaseHelper = new DatabaseHelper(getActivity()); mCostBeanList = new ArrayList<>(); daka=view.findViewById(R.id.daka); day=view.findViewById(R.id.day); daka.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { i++; int f=i; daka.setText("已打卡"); day.setText(i+"天"); } }); zhichu_money=view.findViewById(R.id.zhichu_money); jine=view.findViewById(R.id.jine); yue_money=view.findViewById(R.id.yue_money); queding=view.findViewById(R.id.queding); queding.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { jin=jine.getText().toString(); all_1=Integer.parseInt(jin); SumList(); } }); dreamImage =view.findViewById(R.id.dream_image_iv); dreamImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(view.getContext(),PickerAvtivity.class)); } }); return view; } @Override public void onSelectedFinished(List<ImageItem> result) { //返回来的数据显示出来 for (ImageItem imageItem : result) { Log.d(TAG, " item----> "+imageItem); } ImageItem i=result.get(0); func(i.getPath(),i.getW(),i.getH()); } private void SumList() { int sumzhichu = 0; int sumshouru = 0; int lastyue = 0; int all=0; for (int i = 0; i < mCostBeanList.size(); i++) { CostBean costBean = mCostBeanList.get(i); int costMoney = Integer.parseInt(costBean.getCostMoney()); if(costMoney<=0){ sumzhichu += costMoney; }else{ sumshouru += costMoney; } } lastyue = sumzhichu+sumshouru; all=all_1+lastyue; //shouru.setText(String.valueOf(sumshouru)); zhichu_money.setText(String.valueOf(sumzhichu)); yue_money.setText(String.valueOf(all)); } //褪色处理 public void func(String path,int w,int h) { Log.d(TAG, "func: "+path); Bitmap bitmap = convertToBitmap(path,w,h); // int width = bitmap.getWidth(); // int height = bitmap.getHeight(); Bitmap base = bitmap.copy(Bitmap.Config.ARGB_8888, true); // Bitmap B=toGrayscale(base); Canvas canvas = new Canvas(base);//以base为模板创建canvas对象 canvas.drawBitmap(bitmap, new Matrix(),new Paint()); for(int i = 0; i < base.getWidth(); i++)//遍历像素点 { for(int j = 0; j < base.getHeight()*0.5; j++) { int color = bitmap.getPixel(i, j); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); int a = Color.alpha(color); int avg = (r+g+b)/3;//RGB均值 r= (int) (r/3); g=(int)(g/3); b=(int)(b/3); base.setPixel(i, j,Color.argb(a, r, g, b)); // if(avg >= 100)//100可以理解为经验值 // { // base.setPixel(i, j,Color.argb(a, 255, 255, 255));//设为白色 // } // else // { // base.setPixel(i, j,Color.argb(a, 0, 0, 0));//设为黑色 // } } } bitmap.recycle(); dreamImage.setImageBitmap(base); } public static Bitmap convertToBitmap(String path, int w, int h) { BitmapFactory.Options opts = new BitmapFactory.Options(); // 设置为ture只获取图片大小 opts.inJustDecodeBounds = true; opts.inPreferredConfig = Bitmap.Config.ARGB_8888; // 返回为空 BitmapFactory.decodeFile(path, opts); int width = opts.outWidth; int height = opts.outHeight; float scaleWidth = 0.f, scaleHeight = 0.f; if (width > w || height > h) { // 缩放 scaleWidth = ((float) width) / w; scaleHeight = ((float) height) / h; } opts.inJustDecodeBounds = false; float scale = Math.max(scaleWidth, scaleHeight); opts.inSampleSize = (int)scale; WeakReference<Bitmap> weak = new WeakReference<Bitmap>(BitmapFactory.decodeFile(path, opts)); return Bitmap.createScaledBitmap(weak.get(), w, h, true); } }
明天放慢进度,排查一下app的一些bug,以及一些对客户来说不方便的地方,将那些东西进行改进。