免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項超值服

開通VIP
巧用dimens適配多個分辨率(二) | 望月聽濤
package com.example.test;

import java.io.*;

import java.util.*;

/**

* dimens數(shù)據(jù)自動生成工具

* 

*/

public class DimensTools {

     /** 源文件 */

     static String oldFilePath = "./res/values-nodpi/dimens.xml";

     /** 新生成文件路徑 */

     static String filePath720 = "./res/values-1280x720/dimens.xml";

     /** 新生成文件路徑 */

     static String filePath672 = "./res/values-1280x672/dimens.xml";

     /** 新生成文件路徑 */

     static String filePath1080 = "./res/values-1920x1080/dimens.xml";

     /** 縮小倍數(shù) */

     static float changes = 1.5f;

     public static void main(String[] args) {

          //生成1-1920px

          String allPx= getAllPx();

          DeleteFolder(oldFilePath);

          writeFile(oldFilePath, allPx);

          String st = convertStreamToString(oldFilePath, changes);

          DeleteFolder(filePath720);

          writeFile(filePath720, st);

          DeleteFolder(filePath672);

          writeFile(filePath672, st);

          String st1 = convertStreamToString(oldFilePath, 1f);

          DeleteFolder(filePath1080);

          writeFile(filePath1080, st1);

     }

     /** 讀取文件 生成縮放后字符串 */

     public static String convertStreamToString(String filepath, float f) {

          StringBuilder sb = new StringBuilder();

          try {

               BufferedReader bf = new BufferedReader(new FileReader(filepath));

               String line = null;

               System.out.println("q1");

               String endmark = "px</dimen>";

               String startmark = ">";

               while ((line = bf.readLine()) != null) {

                    if (line.contains(endmark)) {

                         int end = line.lastIndexOf(endmark);

                         int start = line.indexOf(startmark);

                         String stpx = line.substring(start + 1, end);

                         int px = Integer.parseInt(stpx);

                         int newpx = (int) ((float) px / f);

                         String newline = line.replace(px + "px", newpx + "px");

                         sb.append(newline + "\r\n");

                    } else {

                         sb.append(line + "\r\n");

                    }

               }

               System.out.println(sb.toString());

          } catch (IOException e) {

               e.printStackTrace();

          }

          return sb.toString();

     }

     /**

     * 根據(jù)路徑刪除指定的目錄或文件,無論存在與否

     *

     * @param sPath

     *            要刪除的目錄或文件

     * @return 刪除成功返回 true,否則返回 false。

     */

     public static boolean DeleteFolder(String sPath) {

          File file = new File(sPath);

          // // 判斷目錄或文件是否存在

          if (!file.exists()) { // 不存在返回 false

               return true;

          } else {

               // 判斷是否為文件

               if (file.isFile()) { // 為文件時調(diào)用刪除文件方法

                    return deleteFile(sPath);

               } else { // 為目錄時調(diào)用刪除目錄方法

               // return deleteDirectory(sPath);

               }

          }

          return false;

     }

     /** 存為新文件 */

     public static void writeFile(String filepath, String st) {

          try {

               FileWriter fw = new FileWriter(filepath);

               BufferedWriter bw = new BufferedWriter(fw);

               bw.write(st);

               bw.flush();

               bw.close();

          } catch (IOException e) {

               e.printStackTrace();

          }

     }

     /** 生成全px文件 */

     public static String getAllPx() {

          StringBuilder sb = new StringBuilder();

          try {

               sb.append("<resources>" + "\r\n");

               sb.append("<dimen name=\"screen_width\">1920px</dimen>" + "\r\n");

               sb.append("<dimen name=\"screen_height\">1080px</dimen>" + "\r\n");

               for (int i = 1; i <= 1920; i++) {

                    System.out.println("i="+i);

                    sb.append("<dimen name=\"px" + i + "\">" + i + "px</dimen>"

                              + "\r\n");

               }

               sb.append("</resources>" + "\r\n");

               System.out.println(sb.toString());

          } catch (Exception e) {

               e.printStackTrace();

          }

          return sb.toString();

     }

     /**

     * 刪除單個文件

     *

     * @param sPath

     *            被刪除文件的文件名

     * @return 單個文件刪除成功返回true,否則返回false

     */

     public static boolean deleteFile(String sPath) {

          boolean flag = false;

          File file = new File(sPath);

          // 路徑為文件且不為空則進(jìn)行刪除

          if (file.isFile() && file.exists()) {

               file.delete();

               flag = true;

          }

          return flag;

     }

}

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
JAVA版微信支付V3-完全版
bootstrap-treeview demo (樹形展示與后臺數(shù)據(jù)交互)
ASP.NET無限級擴(kuò)展菜單UserControl -ASP.NET實例-www.know...
極分享:高質(zhì)分享+專業(yè)互助=沒有難做的軟件+沒有不得已的加班
數(shù)組轉(zhuǎn)String串
JAVA UTF
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服