隨筆雜記

             :: 首頁 :: 新隨筆 ::  ::  :: 管理 ::

          #

          1) 已經(jīng)添加到service中的程序
          chkconfig name on

          2)其他使用命令啟動的程序
          在/etc/rc.local中加入:
          sudo su - username -c "cd /www/jetty8.1/bin/ && sh jetty.sh start &"
          posted @ 2016-03-05 11:23 天宇恒星 閱讀(680) | 評論 (0)編輯 收藏

          修改httpd文件
          vim /etc/httpd/conf/httpd.conf

          ErrorLog logs/error_log
          CustomLog logs/access_log common
          將其改為 
          ErrorLog "| /usr/local/apache/bin/rotatelogs /data/www/apache_logs/error_%Y%m%d.log 86400 480"
          CustomLog "| /usr/local/apache/bin/rotatelogs /data/www/apache_logs/access_%Y%m%d.log 86400 480" common
          posted @ 2015-12-26 14:43 天宇恒星 閱讀(375) | 評論 (0)編輯 收藏

          使用:
          (Boolean) invokeMethod(LockPatternUtils.class, mLockutils,
                              "savedPasswordExists", new Class[] {int.class}, new Object[] {UserHandle.myUserId()});

          (Boolean) invokeMethod(LockPatternUtils.class, mLockutils, "checkPattern",
                              new Class[] {List.classint.class}, new Object[] {null, UserHandle.myUserId()});

          方法實現(xiàn):

              public static Method getMethod(Class<?> cls, String methodName, Class<?> parameterTypes) {
                  try {
                      return cls.getDeclaredMethod(methodName, parameterTypes);
                  } catch (NoSuchMethodException e) {
                      Log.e(TAG, "getMethod() Exception: ", e);
                      try {
                          return cls.getMethod(methodName, parameterTypes);
                      } catch (NoSuchMethodException ex) {
                          Log.e(TAG, "getMethod() Exception: ", ex);
                          return null;
                      }
                  }
              }

              public static Object invokeStaticMethod(Class<?> cls, String methodName) {
                  return invokeMethod(cls, null, methodName, nullnull);
              }

              public static Object invokeStaticMethod(Class<?> cls, String methodName, Class<?>[] parasTypes,
                      Object[] parasObjs) {
                  return invokeMethod(cls, null, methodName, parasTypes, parasObjs);
              }

              public static Object invokeMethod(Class<?> cls, Object obj, String methodName) {
                  return invokeMethod(cls, obj, methodName, nullnull);
              }

              public static Object invokeMethod(Class<?> cls, Object obj, String methodName, Class<?>[] parasTypes,
                      Object[] parasObjs) {
                  Method method = getMethod(cls, methodName, parasTypes);
                  try {
                      if (method != null) {
                          method.setAccessible(true);
                          return method.invoke(obj, parasObjs);
                      }
                  } catch (Exception e) {
                      Log.e(TAG, "invokeStaticMethod() Exception: ", e);
                  }
                  return null;
              }
              
          posted @ 2015-12-18 09:42 天宇恒星| 編輯 收藏


          http://www.aygfsteel.com/Green-nut/articles/336256.html
          posted @ 2012-11-23 09:12 天宇恒星 閱讀(356) | 評論 (0)編輯 收藏


          public class NetworkConnectChangedReceiver extends BroadcastReceiver{  
              @Override  
              public void onReceive(Context context, Intent intent) {  
              if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {//這個監(jiān)聽wifi的打開與關閉,與wifi的連接無關  
                      int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);   
                      LogTag.showTAG_e("WIFI狀態(tài)", "wifiState"+wifiState);  
                      switch (wifiState) {   
                      case WifiManager.WIFI_STATE_DISABLED:   
                          break;   
                      case WifiManager.WIFI_STATE_DISABLING:   
                          break;   
                     //  
                      }   
                  }  
              // 這個監(jiān)聽wifi的連接狀態(tài)即是否連上了一個有效無線路由,當上邊廣播的狀態(tài)是WifiManager.WIFI_STATE_DISABLING,和WIFI_STATE_DISABLED的時候,根本不會接到這個廣播。  
              
          // 在上邊廣播接到廣播是WifiManager.WIFI_STATE_ENABLED狀態(tài)的同時也會接到這個廣播,當然剛打開wifi肯定還沒有連接到有效的無線  
              if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {  
                      Parcelable parcelableExtra = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);    
                      if (null != parcelableExtra) {    
                          NetworkInfo networkInfo = (NetworkInfo) parcelableExtra;    
                          State state = networkInfo.getState();  
                          boolean isConnected = state==State.CONNECTED;//當然,這邊可以更精確的確定狀態(tài)  
                          LogTag.showTAG_e(this.getClass().getSimpleName(), "isConnected"+isConnected);  
                          if(isConnected){  
                          }else{  
                                
                          }  
                      }    
                  }  
              //這個監(jiān)聽網(wǎng)絡連接的設置,包括wifi和移動數(shù)據(jù)的打開和關閉。.   
                  
          //最好用的還是這個監(jiān)聽。wifi如果打開,關閉,以及連接上可用的連接都會接到監(jiān)聽。見log  
                  
          // 這個廣播的最大弊端是比上邊兩個廣播的反應要慢,如果只是要監(jiān)聽wifi,我覺得還是用上邊兩個配合比較合適  
              if(ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())){  
                  NetworkInfo info = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);  
                  if (info != null) {  
                      LogTag.showTAG_e("CONNECTIVITY_ACTION", "info.getTypeName()"+info.getTypeName());  
                      LogTag.showTAG_e("CONNECTIVITY_ACTION", "getSubtypeName()"+info.getSubtypeName());  
                      LogTag.showTAG_e("CONNECTIVITY_ACTION", "getState()"+info.getState());  
                      LogTag.showTAG_e("CONNECTIVITY_ACTION",  
                                          "getDetailedState()"+info.getDetailedState().name());  
                      LogTag.showTAG_e("CONNECTIVITY_ACTION", "getDetailedState()"+info.getExtraInfo());  
                      LogTag.showTAG_e("CONNECTIVITY_ACTION", "getType()"+info.getType());  
                  }   
              }  

          if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {// 這個監(jiān)聽wifi的連接狀態(tài)  
                     Parcelable parcelableExtra = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);    
                     if (null != parcelableExtra) {    
                         NetworkInfo networkInfo = (NetworkInfo) parcelableExtra;    
                         State state = networkInfo.getState();  
                         if(state==State.CONNECTED){  
                          showWifiCconnected(context);  
                         }  
                         /**else if(state==State.DISCONNECTED){ 
                          showWifiDisconnected(context); 
                         }
          *///昨天寫的這個方法,在坐地鐵的時候發(fā)現(xiàn),如果地鐵上有無效的wifi站點,手機會自動連接,但是連接失敗后還是會接到廣播,所以不能用了  
                     }    
                 }  
          if(ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())){//這個監(jiān)聽網(wǎng)絡連接的設置,包括wifi和移動數(shù)據(jù) 的打開和關閉  
          NetworkInfo info = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);  
          if (info != null) {  
              if(NetworkInfo.State.CONNECTED==info.getState()){  
                  Intent pushIntent = new Intent();  
                  pushIntent.setClass(context, NotificationService.class);  
              }else if(info.getType()==1){  
                      if(NetworkInfo.State.DISCONNECTING==info.getState())  
                          showWifiDisconnected(context);  
                  }  
              }   
          }  
                 }  
          posted @ 2012-09-17 11:56 天宇恒星 閱讀(21897) | 評論 (0)編輯 收藏

          如下錯誤:

          java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread.

          可以使用如下方式解決:
          將notifyDataSetChanged 放在handler中,同時加上紅字字體代碼:

          mWifiListView.setVisibility(View.GONE);
          mWifiListAdapter.notifyDataSetChanged();
          mWifiListView.setVisibility(View.VISIBLE);    
          posted @ 2012-09-13 10:12 天宇恒星 閱讀(949) | 評論 (0)編輯 收藏

          1.startPreview之前設置PreviewCallback
             mCameraDevice.setPreviewCallback(mPreviewCallback);
             mCameraDevice.startPreview();
          2. 獲取preview數(shù)據(jù)
          private final class PreviewCallback implements 
                  android.hardware.Camera.PreviewCallback 
          {
                   
          public void onPreviewFrame(byte[] data, android.hardware.Camera camera) {
                               
                          Size size 
          = mParameters.getPreviewSize();
                          
                          YuvImage yuvimage 
          = new YuvImage(data, ImageFormat.NV21, size.width, 
                              size.height, 
          null);
                          ByteArrayOutputStream outputSteam 
          = new ByteArrayOutputStream();
                          yuvimage.compressToJpeg(
          new Rect(00, size.width, size.height), 80, outputSteam);
                      
                   }

              }

          posted @ 2012-08-04 15:15 天宇恒星 閱讀(3359) | 評論 (0)編輯 收藏


          @Override
              public boolean dispatchKeyEvent(KeyEvent event) {
                  if (event.getRepeatCount() > 0
                          && event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
                      return true;
                  }
                  return super.dispatchKeyEvent(event);
              }
          posted @ 2012-05-24 10:11 天宇恒星 閱讀(341) | 評論 (0)編輯 收藏

          有時,Android系統(tǒng)控件無法滿足我們的需求,因此有必要自定義View。具體方法參見官方開發(fā)文檔:http://developer.android.com/guide/topics/ui/custom-components.html


          一般來說,自定義控件都會去重寫View的onMeasure方法,因為該方法指定該控件在屏幕上的大小。

          protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

          onMeasure傳入的兩個參數(shù)是由上一層控件傳入的大小,有多種情況,重寫該方法時需要對計算控件的實際大小,然后調(diào)用setMeasuredDimension(int, int)設置實際大小。


          onMeasure傳入的widthMeasureSpec和heightMeasureSpec不是一般的尺寸數(shù)值,而是將模式和尺寸組合在一起的數(shù)值。我們需要通過int mode = MeasureSpec.getMode(widthMeasureSpec)得到模式,用int size = MeasureSpec.getSize(widthMeasureSpec)得到尺寸。


          mode共有三種情況,取值分別為MeasureSpec.UNSPECIFIED, MeasureSpec.EXACTLY, MeasureSpec.AT_MOST。


          MeasureSpec.EXACTLY是精確尺寸,當我們將控件的layout_width或layout_height指定為具體數(shù)值時如andorid:layout_width="50dip",或者為FILL_PARENT是,都是控件大小已經(jīng)確定的情況,都是精確尺寸。


          MeasureSpec.AT_MOST是最大尺寸,當控件的layout_width或layout_height指定為WRAP_CONTENT時,控件大小一般隨著控件的子空間或內(nèi)容進行變化,此時控件尺寸只要不超過父控件允許的最大尺寸即可。因此,此時的mode是AT_MOST,size給出了父控件允許的最大尺寸。


          MeasureSpec.UNSPECIFIED是未指定尺寸,這種情況不多,一般都是父控件是AdapterView,通過measure方法傳入的模式。


          因此,在重寫onMeasure方法時要根據(jù)模式不同進行尺寸計算。下面代碼就是一種比較典型的方式:

          @Override    
          protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {    
              setMeasuredDimension(getMeasuredLength(widthMeasureSpec, true), getMeasuredLength(heightMeasureSpec, false));    
          }    
              
              
          private int getMeasuredLength(int length, boolean isWidth) {    
              int specMode = MeasureSpec.getMode(length);    
              int specSize = MeasureSpec.getSize(length);    
              int size;    
              int padding = isWidth ? getPaddingLeft() + getPaddingRight()    
                      : getPaddingTop() + getPaddingBottom();    
              if (specMode == MeasureSpec.EXACTLY) {    
                  size = specSize;    
              } else {    
                  size = isWidth ? padding + mWave.length / 4 : DEFAULT_HEIGHT    
                          + padding;    
                  if (specMode == MeasureSpec.AT_MOST) {    
                      size = Math.min(size, specSize);    
                  }    
              }    
              return size;    
          }  

          posted @ 2012-03-15 19:18 天宇恒星 閱讀(30323) | 評論 (2)編輯 收藏

               摘要: 引用 AudioManager 對象?AudioManager audio = (AudioManager) getSystemService(Service.AUDIO_SERVICE);重寫 Activity 的 onKeyDown 方法?@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {  &n...  閱讀全文
          posted @ 2012-03-13 14:50 天宇恒星 閱讀(3060) | 評論 (0)編輯 收藏

          僅列出標題
          共3頁: 上一頁 1 2 3 下一頁 
          主站蜘蛛池模板: 固镇县| 永靖县| 手游| 鄂托克前旗| 天台县| 明光市| 江门市| 洞头县| 克山县| 凤冈县| 句容市| 井冈山市| 黄浦区| 固始县| 大港区| 无棣县| 凌云县| 福泉市| 栾川县| 成都市| 华亭县| 且末县| 馆陶县| 福泉市| 邹平县| 车险| 黄山市| 凤台县| 绥中县| 类乌齐县| 汝州市| 岑巩县| 抚顺市| 茶陵县| 拜泉县| 庆元县| 红原县| 富平县| 方正县| 鹿邑县| 冷水江市|