Jump to content

Une aide pour optimiser les fichiers XML


Sylvaner

Recommended Posts

Bonjour,

 

Je viens de réaliser un petit programme qui fait une recherche dans tous les fichiers XML d'un répertoire à la recherche de tous les doublons des attributs dans le but de réaliser des styles (pour les thèmes).

 

C'est un actuellement un jar que l'ont lance dans le répertoire concerné ou en l'indiquant en paramètre.

 

J'ai mis en ligne le code source avec le fichier JAR sur GitHub et j'aimerai savoir si des gens sont intéressés pour voir si ça vaut le coup de l'améliorer ou pas :).

 

 

Un exemple restant plus parlant, j'ai écrit une petite page volontairement répétitive : 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:tools="http://schemas.android.com/tools"
	tools:context="com.example.layouttest.MainActivity"
	android:id="@+id/container"
	android:layout_width="match_parent"
	android:layout_height="match_parent">
	<LinearLayout
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:orientation="vertical">
		<RelativeLayout 
			android:layout_width="match_parent"
			android:layout_height="wrap_content">
			<Button
				android:id="@+id/find"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:layout_alignParentRight="true"
				android:text="Rechercher" />
			<EditText
				android:layout_width="wrap_content"
				android:layout_height="match_parent"
				android:layout_alignParentLeft="true"
				android:layout_toLeftOf="@+id/find"
				android:layout_centerVertical="true"
				android:inputType="text"/>
		</RelativeLayout>
		<TextView 
			android:text="Une option : "
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:textColor="#FF0000"
			android:gravity="center_horizontal"/>
		<RadioGroup 
			android:layout_height="wrap_content"
			android:layout_width="match_parent"
			android:orientation="horizontal">
			<RadioButton 
				android:text="Oui"
				android:layout_height="wrap_content"
				android:layout_width="0dp"
				android:layout_weight="0.5"/>
			<RadioButton 
				android:text="Non"
				android:layout_height="wrap_content"
				android:layout_width="0dp"
				android:layout_weight="0.5"/>
		</RadioGroup>
		<TextView 
			android:text="Une autre option : "
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:textColor="#FF0000"
			android:gravity="center_horizontal"/>
		<RadioGroup 
			android:layout_height="wrap_content"
			android:layout_width="match_parent"
			android:orientation="horizontal">
			<RadioButton 
				android:text="Oui"
				android:layout_height="wrap_content"
				android:layout_width="0dp"
				android:layout_weight="0.5"/>
			<RadioButton 
				android:text="Non"
				android:layout_height="wrap_content"
				android:layout_width="0dp"
				android:layout_weight="0.5"/>
		</RadioGroup>
		<LinearLayout
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:orientation="horizontal">
			<TextView 
				android:text="Un label : "
				android:layout_width="0dp"
				android:layout_weight="0.33"
				android:layout_height="wrap_content"/>
			<Spinner 
				android:id="@+id/spinner"
				android:layout_width="0dp"
				android:layout_weight="0.66"
				android:layout_height="wrap_content"/>
		</LinearLayout>
		<LinearLayout
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:orientation="horizontal">
			<TextView 
				android:text="Un label : "
				android:layout_width="0dp"
				android:layout_weight="0.33"
				android:layout_height="wrap_content"/>
			<EditText
				android:text="A remplir"
				android:layout_width="0dp"
				android:layout_weight="0.66"
				android:layout_height="wrap_content"/>
		</LinearLayout>
		<LinearLayout
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:gravity="center_horizontal"
			android:orientation="horizontal">
			<ImageView 
				android:background="@drawable/ic_launcher"
				android:layout_width="128dip"
				android:layout_height="128dip"
				android:scaleType="fitCenter"/>
			<ImageView 
				android:background="@drawable/ic_launcher"
				android:layout_width="128dip"
				android:layout_height="128dip"
				android:scaleType="fitCenter"/>
			<ImageView 
				android:background="@drawable/ic_launcher"
				android:layout_width="128dip"
				android:layout_height="128dip"
				android:scaleType="fitCenter"/>
		</LinearLayout>
		<LinearLayout
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:orientation="horizontal">
			<Button
				android:text="Bouton 1"
				android:layout_width="0dp"
				android:layout_weight="0.33"
				android:layout_height="wrap_content"/>
			<Button
				android:text="Bouton 2"
				android:layout_width="0dp"
				android:layout_weight="0.33"
				android:layout_height="wrap_content"/>
			<Button
				android:text="Bouton 3"
				android:layout_width="0dp"
				android:layout_weight="0.33"
				android:layout_height="wrap_content"/>
		</LinearLayout>
	</LinearLayout>
</ScrollView>

Voici ce que vous indiquera le programme : 

Occurence : 3
Group of attributes : 
	android:background="@drawable/ic_launcher"
	android:layout_height="128dip"
	android:layout_width="128dip"
	android:scaleType="fitCenter"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:gravity="center_horizontal"
	android:layout_height="wrap_content"
	android:layout_width="match_parent"
	android:textColor="#FF0000"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_weight="0.5"
	android:layout_width="0dp"
	android:text="Oui"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_weight="0.5"
	android:layout_width="0dp"
	android:text="Non"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_weight="0.33"
	android:layout_width="0dp"
	android:text="Un label : "
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 6
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_width="match_parent"
	android:orientation="horizontal"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 5
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_weight="0.33"
	android:layout_width="0dp"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 4
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_weight="0.5"
	android:layout_width="0dp"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:gravity="center_horizontal"
	android:layout_height="wrap_content"
	android:layout_width="match_parent"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:background="@drawable/ic_launcher"
	android:layout_height="128dip"
	android:layout_width="128dip"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:background="@drawable/ic_launcher"
	android:layout_height="128dip"
	android:scaleType="fitCenter"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:background="@drawable/ic_launcher"
	android:layout_width="128dip"
	android:scaleType="fitCenter"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:layout_height="128dip"
	android:layout_width="128dip"
	android:scaleType="fitCenter"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:gravity="center_horizontal"
	android:layout_height="wrap_content"
	android:textColor="#FF0000"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:gravity="center_horizontal"
	android:layout_width="match_parent"
	android:textColor="#FF0000"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_width="match_parent"
	android:textColor="#FF0000"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_weight="0.5"
	android:text="Oui"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_width="0dp"
	android:text="Oui"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_weight="0.5"
	android:layout_width="0dp"
	android:text="Oui"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_weight="0.5"
	android:text="Non"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_width="0dp"
	android:text="Non"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_weight="0.5"
	android:layout_width="0dp"
	android:text="Non"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_weight="0.33"
	android:text="Un label : "
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_width="0dp"
	android:text="Un label : "
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_weight="0.33"
	android:layout_width="0dp"
	android:text="Un label : "
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_weight="0.66"
	android:layout_width="0dp"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 11
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_width="0dp"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 10
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_width="match_parent"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 6
Group of attributes : 
	android:layout_height="wrap_content"
	android:orientation="horizontal"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 6
Group of attributes : 
	android:layout_width="match_parent"
	android:orientation="horizontal"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 5
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_weight="0.33"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 5
Group of attributes : 
	android:layout_weight="0.33"
	android:layout_width="0dp"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 4
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_weight="0.5"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 4
Group of attributes : 
	android:layout_weight="0.5"
	android:layout_width="0dp"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:gravity="center_horizontal"
	android:layout_height="wrap_content"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:gravity="center_horizontal"
	android:layout_width="match_parent"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:background="@drawable/ic_launcher"
	android:layout_height="128dip"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:background="@drawable/ic_launcher"
	android:layout_width="128dip"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:background="@drawable/ic_launcher"
	android:scaleType="fitCenter"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:layout_height="128dip"
	android:layout_width="128dip"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:layout_height="128dip"
	android:scaleType="fitCenter"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 3
Group of attributes : 
	android:layout_width="128dip"
	android:scaleType="fitCenter"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:gravity="center_horizontal"
	android:textColor="#FF0000"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:textColor="#FF0000"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_width="match_parent"
	android:textColor="#FF0000"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:text="Oui"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_weight="0.5"
	android:text="Oui"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_width="0dp"
	android:text="Oui"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:text="Non"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_weight="0.5"
	android:text="Non"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_width="0dp"
	android:text="Non"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:text="Un label : "
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_weight="0.33"
	android:text="Un label : "
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_width="0dp"
	android:text="Un label : "
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_height="wrap_content"
	android:layout_weight="0.66"
Concerned files : 
	/path/res/layout/activity_main.xml

Occurence : 2
Group of attributes : 
	android:layout_weight="0.66"
	android:layout_width="0dp"
Concerned files : 
	/path/res/layout/activity_main.xml

Merci pour vos réponses.

Link to comment
Share on other sites

Rebonjour,

 

Voici la version "plugin eclipse" pour ceux qui veulent essayer :
 
Il faut copier ce fichier dans le répertoire plugin d'eclipse.
 
Ensuite il faut faire un clic droit sur le répertoire ou le fichier, Layout inspector -> Inspect the...
 
Voici un exemple de résultat (pour le fichier du post précédent) : 
 
example_eclipse.png
 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...