編輯:關於Android編程
Android——滑動屏幕監聽+ Palette獲取圖片中的顏色
滑動屏幕監聽——音量+亮度的調整
package c.example.jreduch09; import android.content.res.Configuration; import android.media.AudioManager; import android.media.MediaPlayer; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.GestureDetector; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.WindowManager; import android.widget.MediaController; import android.widget.VideoView; public class VideoActivity extends AppCompatActivity { private VideoView vv; private GestureDetector gestureDetector; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_video); getSupportActionBar().hide(); vv=(VideoView)findViewById(R.id.vv); MediaController controller=new MediaController(this); vv.setMediaController(controller); controller.setMediaPlayer(vv); //vv.setVideoPath("http://baobab.wandoujia.com/api/v1/playUrl?vid=8792&editionType=high"); vv.setVideoPath("/storage/emulated/0/DCIM/Camera/VID_20150703_195112.mp4"); vv.requestFocus(); vv.start(); Log.d("====onCreate","===onCreate"); vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mediaPlayer) { finish(); } }); setGestureDetector(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); Log.d("====onCreate","onConfigurationChanged"+newConfig.orientation); } //物理鍵 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { return super.onKeyDown(keyCode, event); } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { return super.onKeyUp(keyCode, event); } @Override public boolean onKeyLongPress(int keyCode, KeyEvent event) { return super.onKeyLongPress(keyCode, event); } //滑動 @Override public boolean onTouchEvent(MotionEvent event) { return gestureDetector.onTouchEvent(event); // if (event.getAction()==MotionEvent.ACTION_DOWN){ // Log.d("==00000","down"); // Log.d("==00000getX","down"+ event.getX()); // Log.d("==00000getY","down"+ event.getY()); // event.getX(); // event.getY(); // } // if (event.getAction()==MotionEvent.ACTION_UP){ // Log.d("==00000","UP"); // Log.d("==00000getX","down"+ event.getX()); // Log.d("==00000getY","down"+ event.getY()); // } // if (event.getAction()==MotionEvent.ACTION_MOVE){ // Log.d("==00000","MOVE"); // Log.d("==00000getX","down"+ event.getX()); // Log.d("==00000getY","down"+ event.getY()); // } // // return super.onTouchEvent(event); } public void setGestureDetector(){ gestureDetector=new GestureDetector(new GestureDetector.OnGestureListener() { @Override public boolean onDown(MotionEvent motionEvent) { return false; } @Override public void onShowPress(MotionEvent motionEvent) { } @Override public boolean onSingleTapUp(MotionEvent motionEvent) { return false; } /* 1.motionEvent收勢的起點 2.motionEvent1手勢終點 3.v X軸方向上的移動的速度/秒 4。v1 Y軸方向上的移動的速度/秒 */ @Override //滾動 public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) { Log.d("7==========","upX"+motionEvent.getX()); Log.d("7==========","upY"+motionEvent.getY()); if (motionEvent.getX()<500) { if (motionEvent.getY()-motionEvent1.getY()>0.5&&Math.abs(v1)>0.5){ Log.d("==========","up"+motionEvent.getY()+"::::"+motionEvent1.getY()); setLightness(30); } if (motionEvent.getY()-motionEvent1.getY()<0.5&&Math.abs(v1)>0.5){ Log.d("==========","down"+motionEvent.getY()+"::::"+motionEvent1.getY()); setLightness(-30); } }else { if (motionEvent.getY()-motionEvent1.getY()>0.5&&Math.abs(v1)>0.5){ Log.d("==========","up"+motionEvent.getY()+"::::"+motionEvent1.getY()); setAudio(1); } if (motionEvent.getY()-motionEvent1.getY()<0.5&&Math.abs(v1)>0.5){ Log.d("==========","down"+motionEvent.getY()+"::::"+motionEvent1.getY()); setAudio(-1); } } return true; } @Override public void onLongPress(MotionEvent motionEvent) { } @Override //拋 public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) { return false; } }); } //改變屏幕亮度 public void setLightness(float lightness){ WindowManager.LayoutParams layoutParams=getWindow().getAttributes(); layoutParams.screenBrightness= layoutParams.screenBrightness+lightness/255f; if (layoutParams.screenBrightness>1){ layoutParams.screenBrightness=1; }else if (layoutParams.screenBrightness<0.2){ layoutParams.screenBrightness=0.2f; } getWindow().setAttributes(layoutParams); } //聲音不能用 public void setAudio(int volume){ AudioManager audioManager=(AudioManager) getSystemService(AUDIO_SERVICE); int i=audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); int max=audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); Log.d("======i====",i+""); Log.d("=======max===",max+""); int o=i+volume; if (o<0){ o=0; } if (o>15){ o=15; } Log.d("=======o===",o+""); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,o,AudioManager.FLAG_PLAY_SOUND); } }
Palette獲取圖片中的顏色
package c.example.jreduch10; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.graphics.Palette; import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.RelativeLayout; public class MainActivity extends AppCompatActivity { private ImageView iv; private Bitmap bitmap; private Button bt1; private RelativeLayout rl; private int count; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle("Toolbar Actionbar"); setSupportActionBar(toolbar); iv=(ImageView)findViewById(R.id.iv); bt1= (Button) findViewById(R.id.bt1); rl= (RelativeLayout) findViewById(R.id.rl); BitmapDrawable bitmapDrawable= (BitmapDrawable) iv.getDrawable(); bitmap=bitmapDrawable.getBitmap(); count =1; bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Palette palette=Palette.from(bitmap).generate(); int defaultColor= Color.BLUE; int color=0; switch (count){ case 1: color= palette.getMutedColor(defaultColor); rl.setBackgroundColor(color); toolbar.setBackgroundColor(color); count++; break; case 2: color= palette.getDominantColor(defaultColor); rl.setBackgroundColor(color); toolbar.setBackgroundColor(color); count++; break; case 3: color= palette.getVibrantColor(defaultColor); rl.setBackgroundColor(color); toolbar.setBackgroundColor(color); count++; break; case 4: color= palette.getDarkMutedColor(defaultColor); rl.setBackgroundColor(color); toolbar.setBackgroundColor(color); count++; break; case 5: color= palette.getLightMutedColor(defaultColor); rl.setBackgroundColor(color); toolbar.setBackgroundColor(color); count++; break; case 6: color= palette.getLightVibrantColor(defaultColor); rl.setBackgroundColor(color); toolbar.setBackgroundColor(color); count++; break; case 7: color= palette.getDarkVibrantColor(defaultColor); rl.setBackgroundColor(color); toolbar.setBackgroundColor(color); count=1; break; } } }); } }
在Android Studio裡面想設置代碼風格,在這裡我想把代碼風格從Java的行尾式改成C風格的代碼,如下 if(true) { // TODO}if
ListView網上資料很多,我所知擴展性最好、最通用的代碼做個備忘。總體上來講:ListView+BaseAdapter+xml文件實現:話不多說,先貼個圖,預期效果如
這個控件之前就大致又看到V1版本的,然後坐著又做了更新,又寫了分析的博文,那這邊就簡單的把內容貼出來介紹給大家就好了(又幫我省事了)先來看下運行效果:內容都是手繪,可見原
為大家提供的MySQL忘記密碼的解決方案,供大家參考,具體內容如下1.在操作系統windows操作系統,xp或win7.中進入如下目錄:復制代碼 代碼如下:C:\User