Advertisement
Guest User

Untitled

a guest
Jan 13th, 2015
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  1.  
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.List;
  5.  
  6.  
  7. import android.annotation.SuppressLint;
  8. import android.content.Context;
  9. import android.graphics.Color;
  10. import android.graphics.drawable.ShapeDrawable;
  11. import android.graphics.drawable.shapes.OvalShape;
  12. import android.util.Log;
  13. import android.view.View;
  14. import android.view.ViewGroup;
  15. import android.widget.AdapterView;
  16. import android.widget.AdapterView.OnItemClickListener;
  17. import android.widget.Button;
  18. import android.widget.HorizontalScrollView;
  19. import android.widget.LinearLayout.LayoutParams;
  20. import android.widget.ArrayAdapter;
  21. import android.widget.GridView;
  22. import android.widget.LinearLayout;
  23. import android.widget.RelativeLayout;
  24. import android.widget.TextView;
  25. import android.widget.Toast;
  26.  
  27. public class YelloPageAds extends LinearLayout {
  28.  
  29. /**
  30. * @param context
  31. */
  32. Context mContext;
  33. String url;
  34. LinearLayout letterLinear, yelloDetailsLinearLayout , innerYello;
  35. private PlanTextView btnTag;
  36. private List<TextView> listBtnTag;
  37. RelativeLayout relativeLayout;
  38. TextView tvde;
  39. Button btnNumber;
  40.  
  41. HorizontalScrollView horizontalScrollview;
  42. private String[] yelloname;
  43. private List<String> yellonameList;
  44. static final String[] letters = new String[] { "A", "B", "C", "D", "E",
  45. "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
  46. "S", "T", "U", "V", "W", "X", "Y", "Z" };
  47.  
  48. public YelloPageAds(Context context) {
  49. super(context);
  50. // TODO Auto-generated constructor stub
  51. }
  52.  
  53. public YelloPageAds(Context context, String yelloUrl) {
  54. super(context);
  55. // TODO Auto-generated constructor stub
  56. mContext = context;
  57. url = yelloUrl;
  58.  
  59. yelloname = getResources().getStringArray(R.array.yelloname);
  60. yellonameList = Arrays.asList(yelloname);
  61.  
  62. listBtnTag = new ArrayList<TextView>();
  63. this.setOrientation(LinearLayout.VERTICAL);
  64.  
  65. horizontalScrollview = new HorizontalScrollView(mContext);
  66. horizontalScrollview.setPadding(5, 5, 5, 5);
  67. horizontalScrollview.setLayoutParams(new LayoutParams(
  68. LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
  69.  
  70. letterLinear = new LinearLayout(mContext);
  71. // letterLinear.setPadding(5, 5, 5, 5);
  72. letterLinear.setOrientation(LinearLayout.HORIZONTAL);
  73. letterLinear.setLayoutParams(new LayoutParams(
  74. LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  75.  
  76.  
  77. // for (int i = 0; i < 3; i++) {
  78. LinearLayout rowletter = new LinearLayout(mContext);
  79. rowletter.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
  80. rowletter.setPadding(10, 0, 0, 0);
  81.  
  82. for (int j = 0; j < letters.length; j++) {
  83. btnTag = new PlanTextView(mContext);
  84. btnTag.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
  85. LayoutParams.WRAP_CONTENT));
  86. btnTag.setText(letters[j].toString());
  87. btnTag.setPadding(6, 6, 6, 6);
  88. btnTag.setTextSize(20);
  89. btnTag.setId(j + 1);
  90. listBtnTag.add(btnTag);
  91. final int index = j;
  92. btnTag.setOnClickListener(new OnClickListener() {
  93. private boolean stateChanged = true;
  94. private boolean flag;
  95. private LinearLayout yelloDetailsLinearLayout1;
  96. private LinearLayout innerYello1;
  97.  
  98. @SuppressLint("NewApi")
  99. public void onClick(View v) {
  100. yelloDetailsLinearLayout1 = new LinearLayout(mContext);
  101. yelloDetailsLinearLayout1.setOrientation(LinearLayout.HORIZONTAL);
  102. yelloDetailsLinearLayout1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  103.  
  104. innerYello1 = new LinearLayout(mContext);
  105. // letterLinear.setPadding(5, 5, 5, 5);
  106. innerYello1.setOrientation(LinearLayout.HORIZONTAL);
  107. innerYello1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
  108. // displayYello(btnTag.getText().toString());
  109.  
  110. List<String> sorted = new ArrayList<String>();
  111. sorted = SortedList(listBtnTag.get(index).getText()
  112. .toString(), yellonameList);
  113. if (sorted.size() == 0) {
  114. Toast.makeText(mContext, "No Yello Page Found",
  115. Toast.LENGTH_SHORT).show();
  116. } else {
  117.  
  118.  
  119. for (int i = 0; i < sorted.size(); i++) {
  120.  
  121. LinearLayout rowletter1 = new LinearLayout(mContext);
  122. rowletter1.setOrientation(LinearLayout.VERTICAL);
  123. rowletter1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
  124. rowletter1.setPadding(10, 0, 0, 0);
  125.  
  126. TextView tvde = new TextView(mContext);
  127. tvde.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
  128.  
  129. Button btnNumber = new Button(mContext);
  130. btnNumber.setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
  131.  
  132. String[] spits = sorted.get(i).toString().split("\\,");
  133. tvde.setText("Your Selected=" + spits[0].toString());
  134.  
  135. btnNumber.setText(spits[1].toString());
  136. rowletter1.addView(tvde);
  137. rowletter1.addView(btnNumber);
  138. innerYello1.addView(rowletter1);
  139. flag=true;
  140. }
  141. yelloDetailsLinearLayout1.addView(innerYello1);
  142. horizontalScrollview.addView(yelloDetailsLinearLayout1);
  143. }
  144. for (int i = 0; i < listBtnTag.size(); i++) {
  145. if (v.getId() == index) {
  146. // reset background to default;
  147. listBtnTag.get(index).setBackgroundResource(
  148. R.drawable.circel_off);
  149. } else {
  150. listBtnTag.get(index).setBackgroundResource(
  151. R.drawable.circel_on);
  152. }
  153. stateChanged = !stateChanged;
  154. }
  155.  
  156. }
  157. });
  158. rowletter.addView(btnTag);
  159.  
  160. }
  161.  
  162. this.addView(rowletter);
  163. this.addView(horizontalScrollview);
  164. // }
  165. }
  166.  
  167. /**
  168. * Purpose: 2:37:53 PM Jan 12, 2015
  169. */
  170. protected void displayYello(String charcter) {
  171. // TODO Auto-generated method stub
  172.  
  173. List<String> sorted = new ArrayList<String>();
  174. sorted = SortedList(charcter, yellonameList);
  175. for (int i = 0; i < sorted.size(); i++) {
  176.  
  177. Log.i("TAG", "sorted " + sorted.size() + " ==");
  178. tvde = new TextView(mContext);
  179. tvde.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
  180. LayoutParams.WRAP_CONTENT));
  181.  
  182. btnNumber = new Button(mContext);
  183. btnNumber.setLayoutParams(new LayoutParams(
  184. LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  185.  
  186. String[] spits = sorted.get(i).toString().split("\\,");
  187.  
  188. tvde.setText("Your Selected=" + spits[0].toString());
  189. btnNumber.setText(spits[1].toString());
  190.  
  191. yelloDetailsLinearLayout.addView(tvde);
  192. yelloDetailsLinearLayout.addView(btnNumber);
  193.  
  194. this.addView(yelloDetailsLinearLayout);
  195. }
  196.  
  197. }
  198.  
  199. /**
  200. * Purpose: 2:40:02 PM Jan 12, 2015
  201. */
  202. private List<String> SortedList(String charcter, List<String> yellonameList2) {
  203. Log.e("Galiya", "charcter==" + charcter + " yellonameList2="
  204. + yellonameList2.size());
  205. List<String> MySortStrings = new ArrayList<String>();
  206. for (int i = 0; i < yellonameList2.size(); i++) {
  207. if (yellonameList2.get(i).startsWith(charcter.toUpperCase())) {
  208. MySortStrings.add(yellonameList2.get(i));
  209. }
  210. }
  211. return MySortStrings;
  212. }
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement