Skip to content
This repository has been archived by the owner on Jun 28, 2018. It is now read-only.

surfstudio/android-code-generator-plugin-fx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

android-code-generator-plugin-fx

Eclipse plugin for faster activity creation from xml layouts

This project based on http://code.google.com/p/android-code-generator-plugin/.

List of new features:

  • auto creating packages if they are not exist;
  • dividing code from "onCreate()" to several methods:
    • initView() which contains all "findViewById";
    • setFonts() which contains all "setTypeface" to support Roboto fonts to Android 2.3.3 and less.
    • setListeners which contains all listeners.
  • auto creating adapter class with classic holder implementation. It calls dialog to choose a layout for adapter item.

How to use it

  1. Select xml files with activity layout.
  2. Right click -> Android Code Generator.
  3. Wait few seconds.
  4. Use files from %packagename%.activity and %packagename%.adapter

How it works

Original activity layout file


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/news_list_activity_news_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        <ProgressBar
            android:id="@+id/articles_progress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/articles_exist_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             />

	<Button
            android:id="@+id/articles_exist_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </RelativeLayout>

</RelativeLayout> 

Original item layout file


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingLeft="15dp"
    android:paddingRight="15dp" >

    <TextView
        android:id="@+id/row_news_date_header_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
         />

    <RelativeLayout
        android:id="@+id/news_main_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <FrameLayout
            android:id="@+id/row_news_image_container"
            android:layout_width="96dp"
            android:layout_height="68dp"
             >

            <ImageView
                android:id="@+id/row_news_icon"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY" />
        </FrameLayout>

        <TextView
            android:id="@+id/row_news_title_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

        <TextView
            android:id="@+id/row_news_type_text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />

        <ImageView
            android:id="@+id/row_news_date_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

        <TextView
            android:id="@+id/row_news_date_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    </RelativeLayout>

    <View
        android:id="@+id/row_news_items_divider"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="@drawable/divider_gray_horizontal" />

</LinearLayout>

Result Activity.java


package com.test.activity;

import android.os.Bundle;
import android.app.Activity;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.graphics.Typeface;
import com.test.R;
import android.widget.ListView;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.view.View;

public class NewsListActivityActivity extends Activity {
	private static final String TAG = NewsListActivityActivity.class.getSimpleName();

	private ProgressBar articlesProgress;
	private ListView newsListActivityNewsList;
	private TextView articlesExistTextView;
	private Button articlesExistButton;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.news_list_activity);

		initActionBar();
		initViews();
		setFonts();
		setListeners();
	}

	private void initActionBar(){
	}

	private void initViews(){
		articlesProgress = (ProgressBar) findViewById(R.id.articles_progress);
		newsListActivityNewsList = (ListView) findViewById(R.id.news_list_activity_news_list);
		articlesExistTextView = (TextView) findViewById(R.id.articles_exist_text_view);
		articlesExistButton = (Button) findViewById(R.id.articles_exist_button);
	}

	private void setFonts(){
		Typeface roboto = null;//TODO init this by utils
		articlesExistTextView.setTypeface(roboto);
	}

	private void setListeners(){
		articlesExistButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

			}
		});
	}
}

Result Adapter.java


package com.test.adapter;

import com.test.R;
import android.graphics.Typeface;
import android.content.Context;
import java.util.List;
import android.widget.ArrayAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.graphics.Typeface;
import android.widget.ImageView;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.view.View.OnClickListener;
import android.view.View;

public class NewsListActivityAdapter extends ArrayAdapter<String>{
	private static final String TAG = NewsListActivityAdapter.class.getSimpleName();

	private Context context;
	private LayoutInflater inflater;


	public NewsListActivityAdapter(Context context, List<String> objects) {
		super(context, R.layout.news_list_item, objects);
		inflater = LayoutInflater.from(context);
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null){
			convertView = inflater.inflate(R.layout.news_list_item, parent, false);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		String item = getItem(position);
		if (item != null){
			holder.populateForm(item);		}
		return convertView;
	}

	private class ViewHolder{

		private TextView rowNewsDateHeaderText;
		private TextView rowNewsDateText;
		private TextView rowNewsTypeText;
		private TextView rowNewsTitleText;

		public ViewHolder(View v){
			initViews(v);
			setFonts();
		}
		private void initViews(View v){
			rowNewsDateHeaderText = (TextView) v.findViewById(R.id.row_news_date_header_text);
			rowNewsDateText = (TextView) v.findViewById(R.id.row_news_date_text);
			rowNewsTypeText = (TextView) v.findViewById(R.id.row_news_type_text);
			rowNewsTitleText = (TextView) v.findViewById(R.id.row_news_title_text);
		}

		private void setFonts(){
			Typeface roboto = null;//TODO init this by utils
			rowNewsDateHeaderText.setTypeface(roboto);
			rowNewsDateText.setTypeface(roboto);
			rowNewsTypeText.setTypeface(roboto);
			rowNewsTitleText.setTypeface(roboto);
		}

		public void populateForm(String item) {

		}
	}
}

Authors

  • Vladislav Mironov
  • Vadim Kotov

License

Copyright 2013 Vladislav Mironov, SurfStudio

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Eclipse plugin for faster activity creation from xml layouts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages