編輯:關於android開發
說明:
實現功能:
(1)屏幕右半部分上滑,聲音變大,下滑,聲音變小 屏幕左半部分上滑,亮度變大,下滑,亮度變小
(2)如果亮度>1或者小於0.2時,手機震動
private float startY;//記錄手指按下時的Y坐標
private float startX;//記錄手指按下時的Y坐標
private int downVol;//記錄手指按下時的音量
private Vibrator vibrator;//手機震動器
//不要忘記震動權限<uses-permission android:name="android.permission.VIBRATE" />
/*
* 設置屏幕亮度 lp = 0 全暗 ,lp= -1,根據系統設置, lp = 1; 最亮
*/
public void setBrightness(float brightness) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
// if (lp.screenBrightness <= 0.1) {
// return;
// }
lp.screenBrightness = lp.screenBrightness + brightness / 255.0f;
if (lp.screenBrightness > 1) {
lp.screenBrightness = 1;
vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
long[] pattern = { 10, 200 }; // OFF/ON/OFF/ON... 關閉10秒震動200毫秒,不停切換
vibrator.vibrate(pattern, -1);
} else if (lp.screenBrightness < 0.2) {
lp.screenBrightness = (float) 0.2;
vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
long[] pattern = { 10, 200 }; // OFF/ON/OFF/ON...
vibrator.vibrate(pattern, -1);
}
getWindow().setAttributes(lp);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
//把事件傳遞給手勢識別器(注:對事件只進行了解析處理,沒有攔截,解析成手勢識別的單擊、雙擊、長按)
detector.onTouchEvent(event);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN :
startY=event.getY();
startX=event.getX();
downVol=audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
handler.removeMessages(HIDE_CONTROL);
break;
case MotionEvent.ACTION_MOVE :
float endY=event.getY();
float distanceY=startY-endY;
if(startX>screenWidth/2){
//屏幕右半部分上滑,聲音變大,下滑,聲音變小
int touchRang=Math.min(screenWidth,screenHeight);
//int curvol= (int) (downVol+(distance/screenHeight)*maxVolume);
int curvol= (int) (downVol+(distanceY/touchRang)*maxVolume);//考慮到橫豎屏切換的問題
int volume=Math.min(Math.max(0,curvol),maxVolume);
updateVolume(volume);
}else{
//屏幕左半部分上滑,亮度變大,下滑,亮度變小
final double FLING_MIN_DISTANCE = 0.5;
final double FLING_MIN_VELOCITY = 0.5;
if (distanceY > FLING_MIN_DISTANCE && Math.abs(distanceY) > FLING_MIN_VELOCITY) {
setBrightness(20);
}
if (distanceY < FLING_MIN_DISTANCE
&& Math.abs(distanceY) > FLING_MIN_VELOCITY) {
setBrightness(-20);
}
}
break;
case MotionEvent.ACTION_UP :
handler.sendEmptyMessageDelayed(HIDE_CONTROL,5000);
break;
}
return super.onTouchEvent(event);
}
水滴效果的下拉刷新--第三方開源 開源--WaveSwipeRefreshLayout,swiperefreshlayout 下載地址:https://github.co
Android React Native自定義組件的流程 假設我們現在有這麼一個需求,就是自定義一個組件,該組件由一個小圖標和圖標的文字說明組成,並且帶有背景色,背景
很早就有有看到有朋友在討論QQ頭像的裁剪上傳是怎麼實現的,吼吼,之前小馬也沒做過,好奇之下學習下,發現以前項目中有類型的功能,結合官方文檔裡面的解釋
Android ViewPager+TabHost實現首頁導航,viewpagertabhost今天發的是TabHost結合ViewPager實現首頁底部導航的效果,雖然