美文网首页
技能大赛记录

技能大赛记录

作者: dylancc | 来源:发表于2020-02-03 13:37 被阅读0次

消除闪屏白色

//消除闪屏白色
<item name="android:windowDisablePreview">true</item>

跑马灯效果

//跑马灯效果
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"

tv.setSelected(true);

loading加载

//loading加载
public class LoadingUtil {
    private static View loadingView;
    private static boolean flag;
    public static void loading(Activity activity){
        if (loadingView == null)
           loadingView = View.inflate(activity, R.layout.page_loading,null);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        if (!flag){
            activity.addContentView(loadingView,layoutParams);
            flag = true;
        }
    }
    public static void unloading(){
        if (flag){
            CommonUtil.removeSelfFromParent(loadingView);
            flag = false;
        }
    }
}

网络请求

//网络请求
public class HttpCoonUtil {
    private static String url = "http://127.0.0.1:7080/transportservice/action/";

    public static void doPost(String action, Object obj, Class clazz, Mycallback mycallback, int type) {
        OkHttpClient okHttpClient = new OkHttpClient();
        RequestBody requestBody = RequestBody.create(MediaType.get("application/json;chartset=UTF-8"), JSON.toJSONString(obj));
        Request request = new Request.Builder().post(requestBody).url(url+action).build();
        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override public void onFailure(Call call, IOException e) {}
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String str = response.body().string();
                Log.d("jsonData",str);
                Object o = JSON.parseObject(str,clazz);
                mycallback.sendResult(o,type);
            }
        });
    }

    public interface Mycallback {
        void sendResult(Object obj, int type);
    }
}

二维码

//二维码
public class ZXingUtil {
    private static int width = 800;
    private static int height = 800;

    public static Bitmap zxing(String context) {
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        Map<EncodeHintType, String> hints = new HashMap<>();
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
        BitMatrix encode = null;
        try {
            encode = qrCodeWriter.encode(context, BarcodeFormat.QR_CODE, width, height, hints);
        } catch (WriterException e) {
            e.printStackTrace();
        }
        int[] colors = new int[width * height];
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                if (encode.get(i,j))
                    colors[i * width +j] = Color.BLACK;
                else 
                    colors[i * width +j] = Color.WHITE;
            }
        }
        return Bitmap.createBitmap(colors,width,height,Bitmap.Config.RGB_565);
    }
}

播放视频

//播放视频
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/raw/" + R.raw.test_video);
            mVideoView.setVideoURI(uri);

通知

//通知
 private void showNotification() {
        NotificationManager manager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
        Notification.Builder builder = new Notification.Builder(getActivity());
        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setContentTitle("title");
        builder.setContentText("123");
        Notification build = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
            build = builder.build();
        }
        manager.notify(1,build);
    }

DatePickerDialog

//DatePickerDialog
private void setDate() {
        Calendar calendar = Calendar.getInstance();
        new DatePickerDialog(getContext(), (datePicker, i, i1, i2) -> {
            tvDate.setText(i+"年"+i1+1+"月"+i2+"日");
        }, calendar.get(Calendar.YEAR)
                , calendar.get(Calendar.MONTH)
                , calendar.get(Calendar.DAY_OF_MONTH))
                .show();
    }

TimePickerView

TimePickerView pvTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
  @Override
   public void onTimeSelect(Date date, View v) {
     tv.setText("<" + getTime(date) + ">");
   }
 }).isDialog(true).build(); //.isDialog(true)是否为弹窗模式
 pvTime.show();

private String getTime(Date date) {
  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  return format.format(date);
}

自定义dialog

//自定义dialog
 private void showDialog(){
        View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_num6,null,false);
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).setView(view);
        alertDialog = builder.create();
        alertDialog.show();
        alertDialog.setCanceledOnTouchOutside(false);//设置点击外部不可取消
    }

MPAndroidChart

//饼图半径
pieChart.setTransparentCircleRadius(0);
pieChart.setHoleRadius(0);

 pieDataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);//lable外部展示
 pieDataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);//value外部展示
 pieDataSet.setValueLinePart1OffsetPercentage(80f);
 pieDataSet.setValueLinePart1Length(1f);//
 pieDataSet.setValueLinePart2Length(1f);//组成折线的两段折线长短
 pieDataSet.setDrawValues(false);

//柱状图上下对比 new float[]{200,200}
 yVal.add(new BarEntry(1,new float[]{200,200}));

//柱状图对比图
private ArrayList<IBarDataSet> getBarDataSet() {...}
barChart.groupBars(0.1f,0.1f,0.01f);

HTML

  //html文件新建assets创建.html
  webview.loadUrl("file:////android_asset/num26.html");
  ProgressDialog progressDialog = new ProgressDialog(this);
  progressDialog.setProgress(0);
  progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
  progressDialog.setMax(100);
  progressDialog.show();
  webview.setWebViewClient(new WebViewClient(){
     @Override
     public void onPageFinished(WebView view, String url) {
       super.onPageFinished(view, url);
       progressDialog.cancel();//页面加载完成后progress取消
       }
     });

广播判断网络连接

public class NetWorkChangeReceiver extends BroadcastReceiver {
    boolean flag = true;

    @Override
    public void onReceive(Context context, Intent intent) {
        NetworkInfo networkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
        if (networkInfo != null) {
            if (NetworkInfo.State.CONNECTED == networkInfo.getState() && networkInfo.isAvailable()) {
                Log.e("success", "网络连接" + networkInfo.getState().toString());
                flag = true;
            } else {
                if (flag) {
                    Log.e("error", "网络未连接");
                    flag = false;
                }
            }
        }
    }
}

 <receiver android:name=".util.NetWorkChangeReceiver"/>//别忘了注册广播

//使用
netWorkChangeReceiver = new NetWorkChangeReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
 _mActivity.registerReceiver(netWorkChangeReceiver,filter);//注册

if (isRegistered)//解除注册
    _mActivity.unregisterReceiver(netWorkChangeReceiver);

动态设置布局宽度

int width = _mActivity.getWindowManager().getDefaultDisplay().getWidth();//屏幕宽
public static int dip2px(Context context, float dpValue) {
       final float scale = context.getResources().getDisplayMetrics().density;
       return (int) (dpValue * scale + 0.5f);
   }
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) tvLeft.getLayoutParams();
layoutParams.width = dip2px(_mActivity, width);
tvLeft.setLayoutParams(layoutParams);

高德地图

<com.amap.api.maps.MapView
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>

//创建map
 map.onCreate(savedInstanceState);
 AMap aMap;
 if (aMap == null) aMap = map.getMap();
//锚点
LatLng latLng = new LatLng(39.906901, 116.397972);
aMap.addMarker(new MarkerOptions().position(latLng).title("北京").snippet("DefaultMarker"));
//设置地图模式
//public static final int MAP_TYPE_NORMAL = 1;普通模式
//public static final int MAP_TYPE_SATELLITE = 2;卫星模式
//public static final int MAP_TYPE_NIGHT = 3;夜间模式
//public static final int MAP_TYPE_NAVI = 4;导航模式
//public static final int MAP_TYPE_BUS = 5;交通模式
 aMap.setMapType(AMap.MAP_TYPE_SATELLITE);

Recyclerview

Num25Adapter2 adapter2 = new Num25Adapter2(bean.getSites(), (tv, tv2, position) -> {
  View view = rv.getLayoutManager().findViewByPosition(lastposition);//找到上次点击的item并设置成原来的颜色
  TextView tv_site = view.findViewById(R.id.tv_site);
  TextView tv_num = view.findViewById(R.id.tv_num);
  tv_site.setTextColor(Color.BLACK);
  tv_num.setTextColor(Color.BLACK);
  tv_num.setBackgroundResource(R.drawable.round_white);
  //设置新点击的颜色
  tv2.setTextColor(Color.RED); tv.setBackgroundResource(R.drawable.num25_shape);
  tv.setTextColor(Color.WHITE);
  lastposition = position;  //此次点击的位置放入历史位置中
  });
  rv.setItemViewCacheSize(30);//设置缓存

相关文章

  • 技能大赛记录

    消除闪屏白色 跑马灯效果 loading加载 网络请求 二维码 播放视频 通知 DatePickerDialog ...

  • 教师

    教师技能大赛

  • 技能大赛

  • 技能大赛

    技能大赛,明日一战,祝马到功成。

  • 技能大赛

    从没想过我可以进国赛,代表我们学校去参加全国护理技能大赛,真的超级高兴,其实我并不优秀,可能只是在大三的时候突然找...

  • 技能大赛

    就在昨天,参加了一场社团的技能大赛。 比赛内容分为笔试与点钞。这是一个团体赛,但笔试时,还是各自答题。 三人组队...

  • 中国式赛课

    在校学生——12.13外国语学院高师技能大赛。四川省师范生技能大赛。华文杯全国师范生技能大赛。 在校老师——七中网...

  • 写在厦门市首届教师教学技能大赛之后

    写在厦门市首届教师教学技能大赛之后 厦门市首届中小学幼儿园教师教学技能大赛已经落下帷幕,大赛之后,自然是有功...

  • 情怀/职工技能大赛随想

    文/蛮子 01 省能源局每年都要组织煤炭行业职工职业技能大赛,今年是“人人持证、技能社会”年,四月初,省局技能大赛...

  • 11.15

    技能大赛先技能后理论,全班准备,注意最近的胃肠道感染

网友评论

      本文标题:技能大赛记录

      本文链接:https://www.haomeiwen.com/subject/zidhxhtx.html