darling_shadow吧 关注:26贴子:1,642

回复:【Android学习】Android开发学习中的一些小技巧、、、、

只看楼主收藏回复

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
//隐藏软键盘
// imm.hideSoftInputFromWindow(tv.getWindowToken(), 0);
//显示软键盘
// imm.showSoftInputFromInputMethod(tv.getWindowToken(), 0);
//切换软键盘的显示与隐藏
imm.toggleSoftInputFromWindow(tv.getWindowToken(), 0, InputMethodManager.HIDE_NOT_ALWAYS);
//或者
// imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);


18楼2013-03-02 17:27
回复
    1.android 中设置Activity启动时候是单例(singleTask)时候是,onActivityResult将失去应有的功能,当startActivityForResult执行时候将立即执行onActivityResult方法,原因待查,先mark...


    19楼2013-06-09 10:26
    回复
      自定义布局,继承view的时候,在构造函数中引入xml文件,这种写法是错误,它是view包下。不是wight包下,所以需继承wight包下的控件,然后在myBarView(Context context, AttributeSet attrs)带两个参数的构造函数下引入xml文件。
      可能这种理解本身就是错误的。这是我自己找的原因,待查。


      20楼2013-06-09 10:29
      回复

        生成水印的过程。其实分为三个环节:第一,载入原始图片;第二,载入水印图片;第三,保存新的图片。
        /**
        * create the bitmap from a byte array
        *
        * @param src the bitmap object you want proecss
        * @param watermark the water mark above the src
        * @return return a bitmap object ,if paramter's length is 0,return null
        */
        private Bitmap createBitmap( Bitmap src, Bitmap watermark )
        {
        String tag = "createBitmap";
        Log.d( tag, "create a new bitmap" );
        if( src == null )
        {
        return null;
        }
        int w = src.getWidth();
        int h = src.getHeight();
        int ww = watermark.getWidth();
        int wh = watermark.getHeight();
        //create the new blank bitmap
        Bitmap newb = Bitmap.createBitmap( w, h, Config.ARGB_8888 );//创建一个新的和SRC长度宽度一样的位图
        Canvas cv = new Canvas( newb );
        //draw src into
        cv.drawBitmap( src, 0, 0, null );//在 0,0坐标开始画入src
        //draw watermark into
        cv.drawBitmap( watermark, w - ww + 5, h - wh + 5, null );//在src的右下角画入水印
        //save all clip
        cv.save( Canvas.ALL_SAVE_FLAG );//保存
        //store
        cv.restore();//存储
        return newb;


        21楼2013-06-09 10:38
        回复
          public class fanShe {
          private String print(int s,String sss) {
          System.out.println(s + sss);
          return "今天周日";
          }
          }
          反射
          fanShe fanshe = new fanShe();
          // 获取这个反射对象
          Class<fanShe> tm_class = (Class<fanShe>) fanshe.getClass();
          // 得到这个方法,后面传参的class类型,顺序要与方法一致
          Method print = tm_class.getDeclaredMethod("print", int.class,String.class);
          // 打开这个方法的访问权限,因为这个方法是私有的
          print.setAccessible(true);
          // 执行这个方法,ss是这个方法执行的返回值,Object里面传参与方法的类型一致
          String returnss = (String) print.invoke(fanshe, new Object[] { 1,"天下第一" });
          System.err.println(returnss);
          打印结果
          今天周日
          1天下第一


          22楼2013-06-09 16:29
          回复
            计算距离的逻辑是从Android的提供的接口(Location.distanceBetween)中拔来的,应该是最精确的方法了。
            EG:
            public static double computeDistance(double lat1, double lon1,
            double lat2, double lon2) {
            // Based on http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf
            // using the "Inverse Formula" (section 4)
            int MAXITERS = 20;
            // Convert lat/long to radians
            lat1 *= Math.PI / 180.0;
            lat2 *= Math.PI / 180.0;
            lon1 *= Math.PI / 180.0;
            lon2 *= Math.PI / 180.0;
            double a = 6378137.0; // WGS84 major axis
            double b = 6356752.3142; // WGS84 semi-major axis
            double f = (a - b) / a;
            double aSqMinusBSqOverBSq = (a * a - b * b) / (b * b);
            double L = lon2 - lon1;
            double A = 0.0;
            double U1 = Math.atan((1.0 - f) * Math.tan(lat1));
            double U2 = Math.atan((1.0 - f) * Math.tan(lat2));
            double cosU1 = Math.cos(U1);
            double cosU2 = Math.cos(U2);
            double sinU1 = Math.sin(U1);
            double sinU2 = Math.sin(U2);
            double cosU1cosU2 = cosU1 * cosU2;
            double sinU1sinU2 = sinU1 * sinU2;
            double sigma = 0.0;
            double deltaSigma = 0.0;
            double cosSqAlpha = 0.0;
            double cos2SM = 0.0;
            double cosSigma = 0.0;
            double sinSigma = 0.0;
            double cosLambda = 0.0;
            double sinLambda = 0.0;
            double lambda = L; // initial guess
            for (int iter = 0; iter < MAXITERS; iter++) {
            double lambdaOrig = lambda;
            cosLambda = Math.cos(lambda);
            sinLambda = Math.sin(lambda);
            double t1 = cosU2 * sinLambda;
            double t2 = cosU1 * sinU2 - sinU1 * cosU2 * cosLambda;
            double sinSqSigma = t1 * t1 + t2 * t2; // (14)
            sinSigma = Math.sqrt(sinSqSigma);
            cosSigma = sinU1sinU2 + cosU1cosU2 * cosLambda; // (15)
            sigma = Math.atan2(sinSigma, cosSigma); // (16)
            double sinAlpha = (sinSigma == 0) ? 0.0 :
            cosU1cosU2 * sinLambda / sinSigma; // (17)
            cosSqAlpha = 1.0 - sinAlpha * sinAlpha;
            cos2SM = (cosSqAlpha == 0) ? 0.0 :
            cosSigma - 2.0 * sinU1sinU2 / cosSqAlpha; // (18)
            double uSquared = cosSqAlpha * aSqMinusBSqOverBSq; // defn
            A = 1 + (uSquared / 16384.0) * // (3)
            (4096.0 + uSquared *
            (-768 + uSquared * (320.0 - 175.0 * uSquared)));
            double B = (uSquared / 1024.0) * // (4)
            (256.0 + uSquared *
            (-128.0 + uSquared * (74.0 - 47.0 * uSquared)));
            double C = (f / 16.0) *
            cosSqAlpha *
            (4.0 + f * (4.0 - 3.0 * cosSqAlpha)); // (10)
            double cos2SMSq = cos2SM * cos2SM;
            deltaSigma = B * sinSigma * // (6)
            (cos2SM + (B / 4.0) *
            (cosSigma * (-1.0 + 2.0 * cos2SMSq) -
            (B / 6.0) * cos2SM *
            (-3.0 + 4.0 * sinSigma * sinSigma) *
            (-3.0 + 4.0 * cos2SMSq)));
            lambda = L +
            (1.0 - C) * f * sinAlpha *
            (sigma + C * sinSigma *
            (cos2SM + C * cosSigma *
            (-1.0 + 2.0 * cos2SM * cos2SM))); // (11)
            double delta = (lambda - lambdaOrig) / lambda;
            if (Math.abs(delta) < 1.0e-12) {
            break;
            }
            }
            return b * A * (sigma - deltaSigma);
            }


            23楼2013-06-21 17:15
            回复
              还有一个计算两个坐标间距离比较简单的方法,这里思考的地球是一个圆球。
              public static double getDistance(double lat1,double longt1 , double lat2,double longt2
              ) {
              double PI = 3.14159265358979323; // 圆周率
              double R = 6371229; // 地球的半径
              double x, y, distance;
              x = (longt2 - longt1) * PI * R
              * Math.cos(((lat1 + lat2) / 2) * PI / 180) / 180;
              y = (lat2 - lat1) * PI * R / 180;
              distance = Math.hypot(x, y);
              return distance;
              }


              25楼2013-06-21 17:16
              回复