Skip to content

Instantly share code, notes, and snippets.

View shuanghua's full-sized avatar
🍃
I

Sam.Mo shuanghua

🍃
I
  • Android Engineer
  • CN
View GitHub Profile
@shuanghua
shuanghua / ViewUtil.java
Last active March 23, 2018 09:08
Android pxTodp
public static int dpToPx(float dp, Context context) {
return dpToPx(dp, context.getResources());
}
public static int dpToPx(float dp, Resources resources) {
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
return (int) px;
}
println("HomeFragment.javaClass.simpleName = ${HomeFragment.javaClass.simpleName}2")// = Companion
println("HomeFragment::class.java.simpleName = ${HomeFragment::class.java.simpleName}1")// = 类名
println("homeFragment.javaClass.simpleName = ${homeFragment.javaClass.simpleName}3")// = 类名
println("homeFragment::javaClass.simpleName = ${homeFragment::javaClass.simpleName}5")// = 类名
println("homeFragment.javaClass.Name = ${homeFragment.javaClass.name}4")// = 包名.类名
println("homeFragment::class.java.Name = ${homeFragment::class.java.name}6")// = 包名.类名
@shuanghua
shuanghua / AndroidManifest.xml
Last active August 27, 2020 08:47
调用相机拍照
<application
<!--适配7.0+拍照返回 Start-->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_path" />
@shuanghua
shuanghua / shr_next_button_state_list_anim.xm
Created June 29, 2018 02:55
Copy From Google MaterialComponents
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!-- Pressed state -->
<item
android:state_enabled="true"
android:state_pressed="true">
<set>
<objectAnimator
方式1:
var resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
//修改高度
return resources.getDimensionPixelSize(resourceId)
方式2:
myView.setOnApplyWindwoInsetListener{view,insets ->
val statusBarSize = insets.systemWindowInsetTop
return insets
}
@shuanghua
shuanghua / IconView.kt
Created March 15, 2019 09:59 — forked from nickbutcher/IconView.kt
A prototype implementation of a shadow effect inspired by the Google Play Games app (https://play.google.com/store/apps/details?id=com.google.android.play.games).
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, 0)
@shuanghua
shuanghua / build.gradle.kts
Last active January 28, 2023 00:57
一份包含签名、DataBinding 等配置的 Android 项目 build.gradle.kts
// Project/keystore//keystore/xxxxxx.jks
// Project/keystore//keystore.properties
// < keystore.properties 内容> :
// storePassword=xxxxxxx
// keyPassword=xxxxxxx
// keyAlias=xxxxxxx
// storeFile=/keystore/xxxxxx.jks
import org.jetbrains.kotlin.konan.properties.Properties
@shuanghua
shuanghua / debian-ufw.md
Created July 19, 2020 12:56
debian ufw 防火墙安装

安装 ufw

sudo apt install ufw
sudo ufw allow OpenSSH                         //让 ufw 允许 ssh 连接,避免后续连接不上 vps

如果SSH服务器 ssh 登录的端口不是 22 ,则还必须需要打开该端口。

下载 caddy2

去 caddy2 官方 github 下载和 Linux 系统对应的可执行文件 https://github.com/caddyserver/caddy/releases 尽可能下载最新的版本,因为 bug 少,下载完成后并移动到 /usr/bin/ 下 (如果你有能力也可以下载源码进行编译安装)

Caddyfile 有两种配置写法

  • 第一种:
{
	experimental_http3
}