package com.desk.move.point.utils;
import android.content.Context;
public class DimMeasureUtils {
Context context;
public DimMeasureUtils(Context context){
this.context = context;
}
public int dpToPx(int dp){
final float scale = context.getResources().getDisplayMetrics().density;
return (int)(dp*scale+0.5f);
}
public int pxToDp(int px){
final float scale = context.getResources().getDisplayMetrics().density;
return (int)(px/scale+0.5f);
}
}
package com.desk.move.point.utils;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import com.desk.move.point.receive.AdminReceiver;
public class LoclScreenUtils {
private static LoclScreenUtils instance = null;
private DevicePolicyManager mDPM = null;
private ComponentName mDeviceAdminSample =null;
private LoclScreenUtils(){
}
public static LoclScreenUtils getInstance(){
if(instance==null){
instance = new LoclScreenUtils();
}
return instance;
}
public void initDevice(Context context){
if(mDPM == null&&mDeviceAdminSample == null){
mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);// 获取设备策略服务
mDeviceAdminSample = new ComponentName(context, AdminReceiver.class);// 设备管理组件
}
}
// 激活设备管理器, 也可以在设置->安全->设备管理器中手动激活
public void activeAdmin(Context context) {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
mDeviceAdminSample);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
"哈哈哈, 我们有了超级设备管理器, 好NB!");
context.startActivity(intent);
}
// 一键锁屏
public void lockScreen(Context context) {
if (mDPM.isAdminActive(mDeviceAdminSample)) {// 判断设备管理器是否已经激活
mDPM.lockNow();// 立即锁屏
//mDPM.resetPassword("1234", 0);
} else {
//activeAdmin(context);
Toast.makeText(context, "必须先激活设备管理器!", Toast.LENGTH_SHORT).show();
}
}
}
package com.desk.move.point.utils;
import android.util.DisplayMetrics;
import android.view.WindowManager;
public class ScreenSizeUtils{
private WindowManager win;
public ScreenSizeUtils(WindowManager win){
this.win = win;
}
public int getHeight(){
int screen_h=0;
DisplayMetrics dm = new DisplayMetrics();
android.view.Display display = win.getDefaultDisplay();
display.getMetrics(dm);
screen_h = dm.heightPixels;
return screen_h;
}
public int getWidth(){
int screen_w=0;
DisplayMetrics dm = new DisplayMetrics();
android.view.Display display = win.getDefaultDisplay();
display.getMetrics(dm);
screen_w = dm.widthPixels;
return screen_w;
}
}
|
|