您的位置:首页 > 编程语言 > Java开发

RTL support api level < 15

2016-04-07 11:44 447 查看
(RTL) Right to Left support 4.2 above. But I need support API 15, platform is 4.0. 

Platform VersionAPI LevelVERSION_CODENotes
Android 6.023
M
Platform Highlights
Android 5.122
LOLLIPOP_MR1
Platform Highlights
Android 5.021
LOLLIPOP
Android 4.4W20
KITKAT_WATCH
KitKat for Wearables Only
Android 4.419
KITKAT
Platform Highlights
Android 4.318
JELLY_BEAN_MR2
Platform Highlights
Android 4.2, 4.2.217
JELLY_BEAN_MR1
Platform Highlights
Android 4.1, 4.1.116
JELLY_BEAN
Platform Highlights
Android 4.0.3, 4.0.415
ICE_CREAM_SANDWICH_MR1
Platform Highlights
Android 4.0, 4.0.1, 4.0.214
ICE_CREAM_SANDWICH
Android 3.213
HONEYCOMB_MR2
Android 3.1.x12
HONEYCOMB_MR1
Platform Highlights
Android 3.0.x11
HONEYCOMB
Platform Highlights
Android 2.3.4

Android 2.3.3
10
GINGERBREAD_MR1
Platform Highlights
Android 2.3.2

Android 2.3.1

Android 2.3
9
GINGERBREAD
Android 2.2.x8
FROYO
Platform Highlights
Android 2.1.x7
ECLAIR_MR1
Platform Highlights
Android 2.0.16
ECLAIR_0_1
Android 2.05
ECLAIR
Android 1.64
DONUT
Platform Highlights
Android 1.53
CUPCAKE
Platform Highlights
Android 1.12
BASE_1_1
Android 1.01
BASE
I need change layout file like this

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="end"
android:paddingBottom="14dip"
android:paddingLeft="16dip"
android:paddingRight="16dip" >

transfer to this

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="end"
android:paddingBottom="14dip"
android:paddingEnd="16dip"
android:paddingLeft="16dip"
android:paddingRight="16dip"
android:paddingStart="16dip" >

the first thought is use Notepad++, but there are different dimension, can do replace all. so I wrote a program to solve this. try to use the NIO.2 in java7

 

here is my code.

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;

public class FilterRTL {
public static String pathStr = "E:\\workspace\\Pro\\res";
private static int i = 0;

public static void main(String[] args) throws IOException {
Path path = Paths.get(pathStr);
Path absPath = path.toAbsolutePath();
i++;
Files.walkFileTree(absPath, new FileVisitor<Path>() {

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {

return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.toString().endsWith(".xml")) {
List<String> lines = Files.readAllLines(file, Charset.forName("utf-8"));
List<String> results = new ArrayList<>();
for (String it : lines) {
results.add(it);
//android:layout_marginStart="8dip"
//android:layout_marginEnd="8dip"
//android:paddingStart="5dp"
//android:paddingEnd="5dp"
//android:layout_alignParentStart
//android:layout_alignParentEnd
if (it.contains("android:layout_marginStart")) {
String[] data = it.split("\"");
results.add("android:layout_marginLeft=\""+data[1]+"\"");
}else if (it.contains("android:layout_marginEnd")) {
String[] data = it.split("\"");
results.add("android:layout_marginRight=\""+data[1]+"\"");
}else if (it.contains("android:paddingStart")) {
String[] data = it.split("\"");
results.add("android:paddingLeft=\""+data[1]+"\"");
}else if (it.contains("android:paddingEnd")) {
String[] data = it.split("\"");
results.add("android:paddingRight=\""+data[1]+"\"");
}else if (it.contains("android:layout_alignParentStart")) {
String[] data = it.split("\"");
results.add("android:layout_alignParentLeft=\""+data[1]+"\"");
}else if (it.contains("android:layout_alignParentEnd")) {
String[] data = it.split("\"");
results.add("android:layout_alignParentRight=\""+data[1]+"\"");
}
System.out.println(it);
}
Files.write(file, results, Charset.forName("utf-8"));
i++;
}
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}
});
System.out.println(i);
}
}


I'm fish, I'm on.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  RTL java7 nio.2