RTL support api level < 15


(RTL) Right to Left support 4.2 above. But I need support API 15, platform is 4.0. 

Platform Version API Level VERSION_CODE Notes
Android 6.0 23 M Platform Highlights
Android 5.1 22 LOLLIPOP_MR1 Platform Highlights
Android 5.0 21 LOLLIPOP
Android 4.4W 20 KITKAT_WATCH KitKat for Wearables Only
Android 4.4 19 KITKAT Platform Highlights
Android 4.3 18 JELLY_BEAN_MR2 Platform Highlights
Android 4.2, 4.2.2 17 JELLY_BEAN_MR1 Platform Highlights
Android 4.1, 4.1.1 16 JELLY_BEAN Platform Highlights
Android 4.0.3, 4.0.4 15 ICE_CREAM_SANDWICH_MR1 Platform Highlights
Android 4.0, 4.0.1, 4.0.2 14 ICE_CREAM_SANDWICH
Android 3.2 13 HONEYCOMB_MR2

Android 3.1.x 12 HONEYCOMB_MR1 Platform Highlights
Android 3.0.x 11 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.x 8 FROYO Platform Highlights
Android 2.1.x 7 ECLAIR_MR1 Platform Highlights
Android 2.0.1 6 ECLAIR_0_1
Android 2.0 5 ECLAIR
Android 1.6 4 DONUT Platform Highlights
Android 1.5 3 CUPCAKE Platform Highlights
Android 1.1 2 BASE_1_1

Android 1.0 1 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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章