@InjectView(R.id.title) TextView title;
title = (TextView) findViewById(R.id.title);
private NodeList getNodesWithId(InputStream inputStream) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // factory.setNamespaceAware(true); // never forget this! DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(inputStream); XPathFactory pathFactory = XPathFactory.newInstance(); XPath xPath = pathFactory.newXPath(); XPathExpression expression = xPath.compile("//*[@id]"); return (NodeList) expression.evaluate(doc, XPathConstants.NODESET); }
private final static String FIELD_PATTERN = "\tprivate %1$s %2$s;\n"; private final static String METHOD_VOID_PATTERN = "\tprivate void %1$s(){\n%2$s\t}\n";
private String getListeners(boolean innerClass){ StringBuilder builder = new StringBuilder(); for (WidgetResource widgetResource : widgetsTypes.keySet()) { if (BUTTON_WIDGETS.contains(widgetsTypes.get(widgetResource).getName())) { builder.append(String.format(innerClass ? ONCLICK_INNER_PATTERN : ONCLICK_PATTERN, widgetResource.getVariableName())); } } return builder.toString(); }
public String generate() { StringBuilder stringBuilder = new StringBuilder(); if (packageName != null && !packageName.isEmpty()) { stringBuilder.append(getPackage()); stringBuilder.append("\n"); } stringBuilder.append(getImports()); stringBuilder.append(viewGenerator.getImports()); stringBuilder.append("\n"); StringBuilder innerBuilder = new StringBuilder(); innerBuilder.append(getTag()); innerBuilder.append("\n"); innerBuilder.append(viewGenerator.getFields(false)); innerBuilder.append("\n"); innerBuilder.append(getCreateMethod()); innerBuilder.append("\n"); innerBuilder.append(getInitActionBarMethod()); innerBuilder.append("\n"); innerBuilder.append(viewGenerator.getInitViewsMethod(false)); innerBuilder.append("\n"); innerBuilder.append(viewGenerator.getSetFontsMethod(false)); innerBuilder.append("\n"); innerBuilder.append(viewGenerator.getSetListenersMethod(false)); stringBuilder.append(String.format(HEADER_PATTERN, activityResource.getVariableName(), innerBuilder.toString())); return stringBuilder.toString(); }
public String generate() { StringBuilder stringBuilder = new StringBuilder(); if (packageName != null && !packageName.isEmpty()) { stringBuilder.append(getPackage()); stringBuilder.append("\n"); } stringBuilder.append(getImports()); stringBuilder.append("\n"); stringBuilder.append(getHeader()); stringBuilder.append("\n"); stringBuilder.append(getTag()); stringBuilder.append("\n"); stringBuilder.append(FIELDS_PATTERN); stringBuilder.append("\n"); stringBuilder.append(getConstructor()); stringBuilder.append("\n"); stringBuilder.append(getGetView()); stringBuilder.append("\n"); stringBuilder.append(getHolder()); stringBuilder.append("}"); stringBuilder.append("\n"); return stringBuilder.toString(); }
<?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>
<?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>
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) { } }); } }
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) { } } }
Source: https://habr.com/ru/post/185234/
All Articles