Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import android.annotation.SuppressLint;
- import android.content.Context;
- import android.graphics.Color;
- import android.graphics.drawable.ShapeDrawable;
- import android.graphics.drawable.shapes.OvalShape;
- import android.util.Log;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.AdapterView;
- import android.widget.AdapterView.OnItemClickListener;
- import android.widget.Button;
- import android.widget.HorizontalScrollView;
- import android.widget.LinearLayout.LayoutParams;
- import android.widget.ArrayAdapter;
- import android.widget.GridView;
- import android.widget.LinearLayout;
- import android.widget.RelativeLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- public class YelloPageAds extends LinearLayout {
- /**
- * @param context
- */
- Context mContext;
- String url;
- LinearLayout letterLinear, yelloDetailsLinearLayout , innerYello;
- private PlanTextView btnTag;
- private List<TextView> listBtnTag;
- RelativeLayout relativeLayout;
- TextView tvde;
- Button btnNumber;
- HorizontalScrollView horizontalScrollview;
- private String[] yelloname;
- private List<String> yellonameList;
- static final String[] letters = new String[] { "A", "B", "C", "D", "E",
- "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
- "S", "T", "U", "V", "W", "X", "Y", "Z" };
- public YelloPageAds(Context context) {
- super(context);
- // TODO Auto-generated constructor stub
- }
- public YelloPageAds(Context context, String yelloUrl) {
- super(context);
- // TODO Auto-generated constructor stub
- mContext = context;
- url = yelloUrl;
- yelloname = getResources().getStringArray(R.array.yelloname);
- yellonameList = Arrays.asList(yelloname);
- listBtnTag = new ArrayList<TextView>();
- this.setOrientation(LinearLayout.VERTICAL);
- horizontalScrollview = new HorizontalScrollView(mContext);
- horizontalScrollview.setPadding(5, 5, 5, 5);
- horizontalScrollview.setLayoutParams(new LayoutParams(
- LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
- letterLinear = new LinearLayout(mContext);
- // letterLinear.setPadding(5, 5, 5, 5);
- letterLinear.setOrientation(LinearLayout.HORIZONTAL);
- letterLinear.setLayoutParams(new LayoutParams(
- LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
- // for (int i = 0; i < 3; i++) {
- LinearLayout rowletter = new LinearLayout(mContext);
- rowletter.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
- rowletter.setPadding(10, 0, 0, 0);
- for (int j = 0; j < letters.length; j++) {
- btnTag = new PlanTextView(mContext);
- btnTag.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
- LayoutParams.WRAP_CONTENT));
- btnTag.setText(letters[j].toString());
- btnTag.setPadding(6, 6, 6, 6);
- btnTag.setTextSize(20);
- btnTag.setId(j + 1);
- listBtnTag.add(btnTag);
- final int index = j;
- btnTag.setOnClickListener(new OnClickListener() {
- private boolean stateChanged = true;
- private boolean flag;
- private LinearLayout yelloDetailsLinearLayout1;
- private LinearLayout innerYello1;
- @SuppressLint("NewApi")
- public void onClick(View v) {
- yelloDetailsLinearLayout1 = new LinearLayout(mContext);
- yelloDetailsLinearLayout1.setOrientation(LinearLayout.HORIZONTAL);
- yelloDetailsLinearLayout1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
- innerYello1 = new LinearLayout(mContext);
- // letterLinear.setPadding(5, 5, 5, 5);
- innerYello1.setOrientation(LinearLayout.HORIZONTAL);
- innerYello1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
- // displayYello(btnTag.getText().toString());
- List<String> sorted = new ArrayList<String>();
- sorted = SortedList(listBtnTag.get(index).getText()
- .toString(), yellonameList);
- if (sorted.size() == 0) {
- Toast.makeText(mContext, "No Yello Page Found",
- Toast.LENGTH_SHORT).show();
- } else {
- for (int i = 0; i < sorted.size(); i++) {
- LinearLayout rowletter1 = new LinearLayout(mContext);
- rowletter1.setOrientation(LinearLayout.VERTICAL);
- rowletter1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
- rowletter1.setPadding(10, 0, 0, 0);
- TextView tvde = new TextView(mContext);
- tvde.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
- Button btnNumber = new Button(mContext);
- btnNumber.setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
- String[] spits = sorted.get(i).toString().split("\\,");
- tvde.setText("Your Selected=" + spits[0].toString());
- btnNumber.setText(spits[1].toString());
- rowletter1.addView(tvde);
- rowletter1.addView(btnNumber);
- innerYello1.addView(rowletter1);
- flag=true;
- }
- yelloDetailsLinearLayout1.addView(innerYello1);
- horizontalScrollview.addView(yelloDetailsLinearLayout1);
- }
- for (int i = 0; i < listBtnTag.size(); i++) {
- if (v.getId() == index) {
- // reset background to default;
- listBtnTag.get(index).setBackgroundResource(
- R.drawable.circel_off);
- } else {
- listBtnTag.get(index).setBackgroundResource(
- R.drawable.circel_on);
- }
- stateChanged = !stateChanged;
- }
- }
- });
- rowletter.addView(btnTag);
- }
- this.addView(rowletter);
- this.addView(horizontalScrollview);
- // }
- }
- /**
- * Purpose: 2:37:53 PM Jan 12, 2015
- */
- protected void displayYello(String charcter) {
- // TODO Auto-generated method stub
- List<String> sorted = new ArrayList<String>();
- sorted = SortedList(charcter, yellonameList);
- for (int i = 0; i < sorted.size(); i++) {
- Log.i("TAG", "sorted " + sorted.size() + " ==");
- tvde = new TextView(mContext);
- tvde.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
- LayoutParams.WRAP_CONTENT));
- btnNumber = new Button(mContext);
- btnNumber.setLayoutParams(new LayoutParams(
- LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
- String[] spits = sorted.get(i).toString().split("\\,");
- tvde.setText("Your Selected=" + spits[0].toString());
- btnNumber.setText(spits[1].toString());
- yelloDetailsLinearLayout.addView(tvde);
- yelloDetailsLinearLayout.addView(btnNumber);
- this.addView(yelloDetailsLinearLayout);
- }
- }
- /**
- * Purpose: 2:40:02 PM Jan 12, 2015
- */
- private List<String> SortedList(String charcter, List<String> yellonameList2) {
- Log.e("Galiya", "charcter==" + charcter + " yellonameList2="
- + yellonameList2.size());
- List<String> MySortStrings = new ArrayList<String>();
- for (int i = 0; i < yellonameList2.size(); i++) {
- if (yellonameList2.get(i).startsWith(charcter.toUpperCase())) {
- MySortStrings.add(yellonameList2.get(i));
- }
- }
- return MySortStrings;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement