List of usage examples for android.widget LinearLayout setTag
public void setTag(final Object tag)
From source file:org.zywx.wbpalmstar.plugin.uexPopoverMenu.EUExPopoverMenu.java
private void showPopoverMenu(double x, double y, int direction, String bgColorStr, String dividerColor, String textColor, int textSize, JSONArray data) { LinearLayout rootView = (LinearLayout) LayoutInflater.from(mContext) .inflate(finder.getLayoutId("plugin_uex_popovermenu"), null); final PopupWindow popupWindow = new PopupWindow(rootView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true); popupWindow.setContentView(rootView); ////from w w w .jav a 2s. com rootView.setBackgroundColor(Color.parseColor(bgColorStr)); popupWindow.setContentView(rootView); //popupWindow? popupWindow.setBackgroundDrawable(new BitmapDrawable()); popupWindow.setOutsideTouchable(true); int length = data.length(); List<ItemData> itemDataList = new ArrayList<ItemData>(); try { for (int i = 0; i < length; i++) { ItemData item = new ItemData(); String icon = data.getJSONObject(i).optString("icon", ""); if (!hasIcon && !TextUtils.isEmpty(icon)) { hasIcon = true; } if (hasIcon) { item.setIcon(data.getJSONObject(i).getString("icon")); } item.setText(data.getJSONObject(i).getString("text")); itemDataList.add(item); } } catch (JSONException e) { e.printStackTrace(); } for (int i = 0; i < length; i++) { LinearLayout linearLayout = new LinearLayout(mContext); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); if (hasIcon) { ImageView imageView = new ImageView(mContext); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); String imagePath = itemDataList.get(i).getIcon(); imageView.setImageBitmap(getBitmapFromPath(imagePath)); imageView.setPadding(DensityUtil.dip2px(mContext, 5), 0, 0, 0); linearLayout.addView(imageView); } TextView tvText = new TextView(mContext); LinearLayout.LayoutParams tvLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tvLayoutParams.gravity = Gravity.CENTER_VERTICAL; tvText.setLayoutParams(tvLayoutParams); tvText.setPadding(DensityUtil.dip2px(mContext, 5), 0, DensityUtil.dip2px(mContext, 8), 0); tvText.setText(itemDataList.get(i).getText()); tvText.setTextColor(Color.parseColor(textColor)); tvText.setTextSize(textSize); linearLayout.addView(tvText); linearLayout.setTag(i); linearLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { callBackPluginJs(CALLBACK_ITEM_SELECTED, String.valueOf(v.getTag())); if (popupWindow != null && popupWindow.isShowing()) { popupWindow.dismiss(); } } }); rootView.addView(linearLayout); // View dividerLine = new View(mContext); dividerLine.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, DensityUtil.dip2px(mContext, 1))); dividerLine.setBackgroundColor(Color.parseColor(dividerColor)); rootView.addView(dividerLine); } int gravityParam; switch (direction) { case 0: gravityParam = Gravity.LEFT | Gravity.TOP; break; case 1: gravityParam = Gravity.RIGHT | Gravity.TOP; break; case 2: gravityParam = Gravity.LEFT | Gravity.BOTTOM; break; case 3: gravityParam = Gravity.RIGHT | Gravity.BOTTOM; break; default: gravityParam = Gravity.LEFT | Gravity.TOP; break; } popupWindow.showAtLocation(mBrwView.getRootView(), gravityParam, (int) x, (int) y); }
From source file:no.barentswatch.fiskinfo.BaseActivity.java
/** * This functions creates a dialog which allows the user to export different * map layers./*w w w . j a v a2 s. c o m*/ * * @param ActivityContext * The context of the current activity. * @return True if the export succeeded, false otherwise. */ public boolean exportMapLayerToUser(Context activityContext) { LayoutInflater layoutInflater = getLayoutInflater(); View view = layoutInflater.inflate(R.layout.dialog_export_metadata, (null)); Button downloadButton = (Button) view.findViewById(R.id.metadataDownloadButton); Button cancelButton = (Button) view.findViewById(R.id.cancel_button); final AlertDialog builder = new AlertDialog.Builder(activityContext).create(); builder.setTitle(R.string.map_export_metadata_title); builder.setView(view); final AtomicReference<String> selectedHeader = new AtomicReference<String>(); final AtomicReference<String> selectedFormat = new AtomicReference<String>(); final ExpandableListView expListView = (ExpandableListView) view .findViewById(R.id.exportMetadataMapServices); final List<String> listDataHeader = new ArrayList<String>(); final HashMap<String, List<String>> listDataChild = new HashMap<String, List<String>>(); final Map<String, String> nameToApiNameResolver = new HashMap<String, String>(); JSONArray availableSubscriptions = getSharedCacheOfAvailableSubscriptions(); if (availableSubscriptions == null) { availableSubscriptions = authenticatedGetRequestToBarentswatchAPIService( getString(R.string.my_page_geo_data_service)); setSharedCacheOfAvailableSubscriptions(availableSubscriptions); } for (int i = 0; i < availableSubscriptions.length(); i++) { try { JSONObject currentSub = availableSubscriptions.getJSONObject(i); nameToApiNameResolver.put(currentSub.getString("Name"), currentSub.getString("ApiName")); listDataHeader.add(currentSub.getString("Name")); List<String> availableDownloadFormatsOfCurrentLayer = new ArrayList<String>(); JSONArray availableFormats = currentSub.getJSONArray("Formats"); for (int j = 0; j < availableFormats.length(); j++) { availableDownloadFormatsOfCurrentLayer.add(availableFormats.getString(j)); } listDataChild.put(listDataHeader.get(i), availableDownloadFormatsOfCurrentLayer); System.out .println("item: " + currentSub.getString("Name") + ", " + currentSub.getString("ApiName")); } catch (JSONException e) { e.printStackTrace(); Log.d("ExportMapLAyerToUser", "Invalid JSON returned from API CALL"); return false; } } final ExpandableListAdapter listAdapter = new ExpandableListAdapter(activityContext, listDataHeader, listDataChild); expListView.setAdapter(listAdapter); // Listview on child click listener expListView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { selectedHeader.set(nameToApiNameResolver.get(listDataHeader.get(groupPosition))); selectedHeader.set(listDataHeader.get(groupPosition)); selectedFormat.set(listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition)); LinearLayout currentlySelected = (LinearLayout) parent.findViewWithTag("currentlySelectedRow"); if (currentlySelected != null) { currentlySelected.getChildAt(0).setBackgroundColor(Color.WHITE); currentlySelected.setTag(null); } ((LinearLayout) v).getChildAt(0).setBackgroundColor(Color.rgb(214, 214, 214)); v.setTag("currentlySelectedRow"); return true; } }); downloadButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { new DownloadMapLayerFromBarentswatchApiInBackground() .execute(nameToApiNameResolver.get(selectedHeader.get()), selectedFormat.get()); builder.dismiss(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { builder.dismiss(); } }); builder.setCanceledOnTouchOutside(false); builder.show(); return true; }
From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void showThemeDialog() { final int checkedItem = Arrays.asList(Preferences.VALUES_THEME).indexOf(Preferences.getTheme()); Resources resources = getResources(); float density = ResourceUtils.obtainDensity(resources); ScrollView scrollView = new ScrollView(this); LinearLayout outer = new LinearLayout(this); outer.setOrientation(LinearLayout.VERTICAL); int outerPadding = (int) (16f * density); outer.setPadding(outerPadding, outerPadding, outerPadding, outerPadding); scrollView.addView(outer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); final AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.action_change_theme) .setView(scrollView).setNegativeButton(android.R.string.cancel, null).create(); View.OnClickListener listener = v -> { int index = (int) v.getTag(); if (index != checkedItem) { Preferences.setTheme(Preferences.VALUES_THEME[index]); recreate();/*from w w w . j a v a2s . c om*/ } dialog.dismiss(); }; int circleSize = (int) (56f * density); int itemPadding = (int) (12f * density); LinearLayout inner = null; for (int i = 0; i < Preferences.ENTRIES_THEME.length; i++) { if (i % 3 == 0) { inner = new LinearLayout(this); inner.setOrientation(LinearLayout.HORIZONTAL); outer.addView(inner, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); } LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.setGravity(Gravity.CENTER); layout.setBackgroundResource( ResourceUtils.getResourceId(this, android.R.attr.selectableItemBackground, 0)); layout.setPadding(0, itemPadding, 0, itemPadding); layout.setOnClickListener(listener); layout.setTag(i); inner.addView(layout, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); View view = new View(this); int colorBackgroundAttr = Preferences.VALUES_THEME_COLORS[i][0]; int colorPrimaryAttr = Preferences.VALUES_THEME_COLORS[i][1]; int colorAccentAttr = Preferences.VALUES_THEME_COLORS[i][2]; Resources.Theme theme = getResources().newTheme(); theme.applyStyle(Preferences.VALUES_THEME_IDS[i], true); TypedArray typedArray = theme .obtainStyledAttributes(new int[] { colorBackgroundAttr, colorPrimaryAttr, colorAccentAttr }); view.setBackground(new ThemeChoiceDrawable(typedArray.getColor(0, 0), typedArray.getColor(1, 0), typedArray.getColor(2, 0))); typedArray.recycle(); if (C.API_LOLLIPOP) { view.setElevation(6f * density); } layout.addView(view, circleSize, circleSize); TextView textView = new TextView(this, null, android.R.attr.textAppearanceListItem); textView.setSingleLine(true); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setText(Preferences.ENTRIES_THEME[i]); if (C.API_LOLLIPOP) { textView.setAllCaps(true); textView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f); } else { textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f); } textView.setGravity(Gravity.CENTER_HORIZONTAL); textView.setPadding(0, (int) (8f * density), 0, 0); layout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); if (i + 1 == Preferences.ENTRIES_THEME.length && Preferences.ENTRIES_THEME.length % 3 != 0) { if (Preferences.ENTRIES_THEME.length % 3 == 1) { inner.addView(new View(this), 0, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); } inner.addView(new View(this), new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); } } dialog.show(); }
From source file:org.linphone.InCallActivity.java
private void displayCall(Resources resources, LinphoneCall call, int index) { String sipUri = call.getRemoteAddress().asStringUriOnly(); LinphoneAddress lAddress;//from www . j a v a 2s .c o m try { lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri); } catch (LinphoneCoreException e) { Log.e("Incall activity cannot parse remote address", e); lAddress = LinphoneCoreFactory.instance().createLinphoneAddress("uknown", "unknown", "unkonown"); } // Control Row LinearLayout callView = (LinearLayout) inflater.inflate(R.layout.active_call_control_row, container, false); callView.setId(index + 1); setContactName(callView, lAddress, sipUri, resources); displayCallStatusIconAndReturnCallPaused(callView, call); setRowBackground(callView, index); registerCallDurationTimer(callView, call); callsList.addView(callView); // Image Row LinearLayout imageView = (LinearLayout) inflater.inflate(R.layout.active_call_image_row, container, false); Contact contact = ContactsManager.getInstance() .findContactWithAddress(imageView.getContext().getContentResolver(), lAddress); if (contact != null) { displayOrHideContactPicture(imageView, contact.getPhotoUri(), contact.getThumbnailUri(), false); } else { displayOrHideContactPicture(imageView, null, null, false); } callsList.addView(imageView); callView.setTag(imageView); callView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (v.getTag() != null) { View imageView = (View) v.getTag(); if (imageView.getVisibility() == View.VISIBLE) imageView.setVisibility(View.GONE); else imageView.setVisibility(View.VISIBLE); callsList.invalidate(); } } }); }
From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java
private View makeView(boolean icon, boolean watcher, boolean closeable, float density) { int size = (int) (48f * density); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setGravity(Gravity.CENTER_VERTICAL); ImageView iconView = null;/*w ww . java 2 s. com*/ if (icon) { iconView = new ImageView(context); iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); linearLayout.addView(iconView, (int) (24f * density), size); } TextView textView = makeCommonTextView(false); linearLayout.addView(textView, new LinearLayout.LayoutParams(0, size, 1)); WatcherView watcherView = null; if (watcher) { watcherView = new WatcherView(context); linearLayout.addView(watcherView, size, size); } ImageView closeView = null; if (!watcher && closeable) { closeView = new ImageView(context); closeView.setScaleType(ImageView.ScaleType.CENTER); closeView.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonCancel, 0)); closeView.setBackgroundResource(ResourceUtils.getResourceId(context, android.R.attr.borderlessButtonStyle, android.R.attr.background, 0)); linearLayout.addView(closeView, size, size); closeView.setOnClickListener(closeButtonListener); } ViewHolder holder = new ViewHolder(); holder.icon = iconView; holder.text = textView; holder.extra = watcherView != null ? watcherView : closeView; linearLayout.setTag(holder); int layoutLeftDp = 0; int layoutRightDp = 0; int textLeftDp; int textRightDp; if (C.API_LOLLIPOP) { textLeftDp = 16; textRightDp = 16; if (icon) { layoutLeftDp = 16; textLeftDp = 32; } if (watcher || closeable) { layoutRightDp = 4; textRightDp = 8; } } else { textLeftDp = 8; textRightDp = 8; if (icon) { layoutLeftDp = 8; textLeftDp = 6; textView.setAllCaps(true); } if (watcher || closeable) { layoutRightDp = 0; textRightDp = 0; } } linearLayout.setPadding((int) (layoutLeftDp * density), 0, (int) (layoutRightDp * density), 0); textView.setPadding((int) (textLeftDp * density), 0, (int) (textRightDp * density), 0); return linearLayout; }
From source file:de.grobox.liberario.TripsActivity.java
private void addTrips(final TableLayout main, List<Trip> trip_list, boolean append) { if (trip_list != null) { // reverse order of trips if they should be prepended if (!append) { ArrayList<Trip> tempResults = new ArrayList<Trip>(trip_list); Collections.reverse(tempResults); trip_list = tempResults;//from w w w .j av a 2 s . c o m } for (final Trip trip : trip_list) { final LinearLayout trip_layout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.trip, null); TableRow row = (TableRow) trip_layout.findViewById(R.id.tripTableRow); // Locations TextView fromView = (TextView) row.findViewById(R.id.fromView); fromView.setText(trip.from.uniqueShortName()); TextView toView = ((TextView) row.findViewById(R.id.toView)); toView.setText(trip.to.uniqueShortName()); // Departure Time and Delay TextView departureTimeView = (TextView) row.findViewById(R.id.departureTimeView); TextView departureDelayView = (TextView) row.findViewById(R.id.departureDelayView); if (trip.getFirstPublicLeg() != null) { LiberarioUtils.setDepartureTimes(this, departureTimeView, departureDelayView, trip.getFirstPublicLeg().departureStop); } else { departureTimeView.setText(DateUtils.getTime(this, trip.getFirstDepartureTime())); } // Arrival Time and Delay TextView arrivalTimeView = (TextView) row.findViewById(R.id.arrivalTimeView); TextView arrivalDelayView = (TextView) row.findViewById(R.id.arrivalDelayView); if (trip.getLastPublicLeg() != null) { LiberarioUtils.setArrivalTimes(this, arrivalTimeView, arrivalDelayView, trip.getLastPublicLeg().arrivalStop); } else { arrivalTimeView.setText(DateUtils.getTime(this, trip.getLastArrivalTime())); } // Duration TextView durationView = (TextView) trip_layout.findViewById(R.id.durationView); durationView .setText(DateUtils.getDuration(trip.getFirstDepartureTime(), trip.getLastArrivalTime())); // Transports FlowLayout lineLayout = (FlowLayout) trip_layout.findViewById(R.id.lineLayout); // for each leg for (final Leg leg : trip.legs) { if (leg instanceof Trip.Public) { LiberarioUtils.addLineBox(this, lineLayout, ((Public) leg).line); } else if (leg instanceof Trip.Individual) { LiberarioUtils.addWalkingBox(this, lineLayout); } } // remember trip in view for onClick event trip_layout.setTag(trip); // make trip details fold out and in on click trip_layout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { View v = main.getChildAt(main.indexOfChild(view) + 1); if (v != null) { if (v.getVisibility() == View.GONE) { v.setVisibility(View.VISIBLE); } else if (v.getVisibility() == View.VISIBLE) { v.setVisibility(View.GONE); } } } }); trip_layout.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { selectTrip(view, trip_layout); return true; } }); // show more button for trip details final ImageView showMoreView = (ImageView) trip_layout.findViewById(R.id.showMoreView); showMoreView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectTrip(view, trip_layout); } }); // Create container for trip details fragment FrameLayout fragmentContainer = new FrameLayout(this); fragmentContainer.setId(mContainerId); fragmentContainer.setVisibility(View.GONE); // Create a new Fragment to be placed in the activity layout TripDetailFragment tripDetailFragment = new TripDetailFragment(); // In case this activity was started with special instructions from an // Intent, pass the Intent's extras to the fragment as arguments Bundle bundle = new Bundle(); bundle.putSerializable("de.schildbach.pte.dto.Trip", trip); bundle.putSerializable("de.schildbach.pte.dto.Trip.from", from); bundle.putSerializable("de.schildbach.pte.dto.Trip.to", to); tripDetailFragment.setArguments(bundle); // Add the fragment to the 'fragment_container' FrameLayout getSupportFragmentManager().beginTransaction().add(mContainerId, tripDetailFragment).commit(); mContainerId++; if (append) { trip_layout.addView(LiberarioUtils.getDivider(this)); main.addView(trip_layout); main.addView(fragmentContainer); } else { trip_layout.addView(LiberarioUtils.getDivider(this), 0); main.addView(trip_layout, 0); main.addView(fragmentContainer, 1); } } // end foreach trip } else { // TODO offer option to query again for trips } }
From source file:org.xingjitong.InCallActivity.java
private void displayCall(Resources resources, LinphoneCall call, int index) { String sipUri = call.getRemoteAddress().asStringUriOnly(); LinphoneAddress lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri); // Control Row LinearLayout callView = (LinearLayout) inflater.inflate(R.layout.active_call_control_row, container, false); setContactPhone(callView, lAddress, sipUri, resources); //yyppcallingfun del //displayCallStatusIconAndReturnCallPaused(callView, call); setRowBackground(callView, index);/*from ww w. java 2 s . c o m*/ registerCallDurationTimer(callView, call); callsList.addView(callView); // Image Row LinearLayout imageView = (LinearLayout) inflater.inflate(R.layout.active_call_image_row, container, false); Uri pictureUri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress, imageView.getContext().getContentResolver()); final TextView name = (TextView) imageView.findViewById(R.id.call_name); //yyppcalling //yyppcallingui add //callhint = (TextView) imageView.findViewById(R.id.incall_callhint); phone = sipUri.substring(sipUri.indexOf(":") + 1, sipUri.indexOf("@")); if (phone.startsWith("01") && !phone.startsWith("010")) { phone = phone.substring(1); } else if (phone.startsWith("51201")) { phone = phone.substring(4); } else if (phone.startsWith("512")) { phone = phone.substring(3); } if (!phone.startsWith("1") && !phone.startsWith("0")) { phone = "0" + phone; } handler.post(new Runnable() { @Override public void run() { String n = ContactDB.Instance().getName(phone); if (!n.equals(phone) && n != null) { name.invalidate(); name.setText(n); } } }); displayOrHideContactPicture(imageView, pictureUri, false); callsList.addView(imageView); callView.setTag(imageView); callView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (v.getTag() != null) { View imageView = (View) v.getTag(); if (imageView.getVisibility() == View.VISIBLE) imageView.setVisibility(View.GONE); else imageView.setVisibility(View.VISIBLE); callsList.invalidate(); } } }); }
From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java
private View makeHeader(ViewGroup parent, boolean button, float density) { if (C.API_LOLLIPOP) { LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); View divider = makeSimpleDivider(); int paddingTop = divider.getPaddingBottom(); divider.setPadding(divider.getPaddingLeft(), divider.getPaddingTop(), divider.getPaddingRight(), 0); linearLayout.addView(divider, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout linearLayout2 = new LinearLayout(context); linearLayout2.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(linearLayout2, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); TextView textView = makeCommonTextView(true); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, (int) (32f * density), 1); layoutParams.setMargins((int) (16f * density), paddingTop, (int) (16f * density), (int) (8f * density)); linearLayout2.addView(textView, layoutParams); ViewHolder holder = new ViewHolder(); holder.text = textView;/*from w w w. jav a 2 s . co m*/ if (button) { ImageView imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.CENTER); imageView.setBackgroundResource(ResourceUtils.getResourceId(context, android.R.attr.borderlessButtonStyle, android.R.attr.background, 0)); imageView.setOnClickListener(headerButtonListener); imageView.setImageAlpha(0x5e); int size = (int) (48f * density); layoutParams = new LinearLayout.LayoutParams(size, size); layoutParams.rightMargin = (int) (4f * density); linearLayout2.addView(imageView, layoutParams); holder.extra = imageView; holder.icon = imageView; } linearLayout.setTag(holder); return linearLayout; } else { View view = LayoutInflater.from(context) .inflate(ResourceUtils.getResourceId(context, android.R.attr.preferenceCategoryStyle, android.R.attr.layout, android.R.layout.preference_category), parent, false); ViewHolder holder = new ViewHolder(); holder.text = (TextView) view.findViewById(android.R.id.title); if (button) { int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); view.measure(measureSpec, measureSpec); int size = view.getMeasuredHeight(); if (size == 0) { size = (int) (32f * density); } FrameLayout frameLayout = new FrameLayout(context); frameLayout.addView(view); view = frameLayout; ImageView imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); int padding = (int) (4f * density); imageView.setPadding(padding, padding, padding, padding); frameLayout.addView(imageView, new FrameLayout.LayoutParams((int) (48f * density), size, Gravity.END)); View buttonView = new View(context); buttonView.setBackgroundResource( ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0)); buttonView.setOnClickListener(headerButtonListener); frameLayout.addView(buttonView, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); holder.extra = buttonView; holder.icon = imageView; } view.setTag(holder); return view; } }
From source file:cm.aptoide.pt.MainActivity.java
private void loadUItopapps() { ((ToggleButton) featuredView.findViewById(R.id.toggleButton1)).setOnCheckedChangeListener(null); Cursor c = db.getFeaturedTopApps(); values = new ArrayList<HashMap<String, String>>(); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { HashMap<String, String> item = new HashMap<String, String>(); item.put("name", c.getString(1)); item.put("icon", db.getIconsPath(0, Category.TOPFEATURED) + c.getString(4)); item.put("rating", c.getString(5)); item.put("id", c.getString(0)); item.put("apkid", c.getString(7)); item.put("vercode", c.getString(8)); item.put("vername", c.getString(2)); item.put("downloads", c.getString(6)); if (values.size() == 26) { break; }/* ww w. j a v a2 s . c o m*/ values.add(item); } c.close(); runOnUiThread(new Runnable() { public void run() { LinearLayout ll = (LinearLayout) featuredView.findViewById(R.id.container); ll.removeAllViews(); LinearLayout llAlso = new LinearLayout(MainActivity.this); llAlso.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); llAlso.setOrientation(LinearLayout.HORIZONTAL); for (int i = 0; i != values.size(); i++) { LinearLayout txtSamItem = (LinearLayout) getLayoutInflater().inflate(R.layout.row_grid_item, null); ((TextView) txtSamItem.findViewById(R.id.name)).setText(values.get(i).get("name")); // ((TextView) txtSamItem.findViewById(R.id.version)) // .setText(getString(R.string.version) +" "+ // values.get(i).get("vername")); ((TextView) txtSamItem.findViewById(R.id.downloads)).setText( "(" + values.get(i).get("downloads") + " " + getString(R.string.downloads) + ")"); String hashCode = (values.get(i).get("apkid") + "|" + values.get(i).get("vercode")) + ""; cm.aptoide.com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage( values.get(i).get("icon"), (ImageView) txtSamItem.findViewById(R.id.icon), hashCode); // imageLoader.DisplayImage(-1, values.get(i).get("icon"), // (ImageView) txtSamItem.findViewById(R.id.icon), // mContext); float stars = 0f; try { stars = Float.parseFloat(values.get(i).get("rating")); } catch (Exception e) { stars = 0f; } ((RatingBar) txtSamItem.findViewById(R.id.rating)).setRating(stars); ((RatingBar) txtSamItem.findViewById(R.id.rating)).setIsIndicator(true); txtSamItem.setPadding(10, 0, 0, 0); txtSamItem.setTag(values.get(i).get("id")); txtSamItem.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 100, 1)); // txtSamItem.setOnClickListener(featuredListener); txtSamItem.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent i = new Intent(MainActivity.this, ApkInfo.class); long id = Long.parseLong((String) arg0.getTag()); i.putExtra("_id", id); i.putExtra("top", true); i.putExtra("category", Category.TOPFEATURED.ordinal()); startActivity(i); } }); txtSamItem.measure(0, 0); if (i % 2 == 0) { ll.addView(llAlso); llAlso = new LinearLayout(MainActivity.this); llAlso.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 100)); llAlso.setOrientation(LinearLayout.HORIZONTAL); llAlso.addView(txtSamItem); } else { llAlso.addView(txtSamItem); } } ll.addView(llAlso); SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mContext); // System.out.println(sPref.getString("app_rating", // "All").equals( // "Mature")); ((ToggleButton) featuredView.findViewById(R.id.toggleButton1)) .setChecked(!sPref.getBoolean("matureChkBox", false)); ((ToggleButton) featuredView.findViewById(R.id.toggleButton1)) .setOnCheckedChangeListener(adultCheckedListener); } }); }
From source file:cm.aptoide.pt.MainActivity.java
private void loadRecommended() { if (Login.isLoggedIn(mContext)) { ((TextView) featuredView.findViewById(R.id.recommended_text)).setVisibility(View.GONE); } else {// ww w . jav a2 s. c o m ((TextView) featuredView.findViewById(R.id.recommended_text)).setVisibility(View.VISIBLE); } new Thread(new Runnable() { private ArrayList<HashMap<String, String>> valuesRecommended; public void run() { loadUIRecommendedApps(); File f = null; try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); NetworkUtils utils = new NetworkUtils(); BufferedInputStream bis = new BufferedInputStream( utils.getInputStream("http://webservices.aptoide.com/webservices/listUserBasedApks/" + Login.getToken(mContext) + "/10/xml", null, null, mContext), 8 * 1024); f = File.createTempFile("abc", "abc"); OutputStream out = new FileOutputStream(f); byte buf[] = new byte[1024]; int len; while ((len = bis.read(buf)) > 0) out.write(buf, 0, len); out.close(); bis.close(); String hash = Md5Handler.md5Calc(f); ViewApk parent_apk = new ViewApk(); parent_apk.setApkid("recommended"); if (!hash.equals(db.getItemBasedApksHash(parent_apk.getApkid()))) { // Database.database.beginTransaction(); db.deleteItemBasedApks(parent_apk); sp.parse(f, new HandlerItemBased(parent_apk)); db.insertItemBasedApkHash(hash, parent_apk.getApkid()); // Database.database.setTransactionSuccessful(); // Database.database.endTransaction(); loadUIRecommendedApps(); } } catch (Exception e) { e.printStackTrace(); } if (f != null) f.delete(); } private void loadUIRecommendedApps() { valuesRecommended = db.getItemBasedApksRecommended("recommended"); runOnUiThread(new Runnable() { public void run() { LinearLayout ll = (LinearLayout) featuredView.findViewById(R.id.recommended_container); ll.removeAllViews(); LinearLayout llAlso = new LinearLayout(MainActivity.this); llAlso.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); llAlso.setOrientation(LinearLayout.HORIZONTAL); if (valuesRecommended.isEmpty()) { if (Login.isLoggedIn(mContext)) { TextView tv = new TextView(mContext); tv.setText(R.string.no_recommended_apps); tv.setTextAppearance(mContext, android.R.attr.textAppearanceMedium); tv.setPadding(10, 10, 10, 10); ll.addView(tv); } } else { for (int i = 0; i != valuesRecommended.size(); i++) { LinearLayout txtSamItem = (LinearLayout) getLayoutInflater() .inflate(R.layout.row_grid_item, null); ((TextView) txtSamItem.findViewById(R.id.name)) .setText(valuesRecommended.get(i).get("name")); ImageLoader.getInstance().displayImage(valuesRecommended.get(i).get("icon"), (ImageView) txtSamItem.findViewById(R.id.icon)); float stars = 0f; try { stars = Float.parseFloat(valuesRecommended.get(i).get("rating")); } catch (Exception e) { stars = 0f; } ((RatingBar) txtSamItem.findViewById(R.id.rating)).setIsIndicator(true); ((RatingBar) txtSamItem.findViewById(R.id.rating)).setRating(stars); txtSamItem.setPadding(10, 0, 0, 0); // ((TextView) // txtSamItem.findViewById(R.id.version)) // .setText(getString(R.string.version) +" "+ // valuesRecommended.get(i).get("vername")); ((TextView) txtSamItem.findViewById(R.id.downloads)) .setText("(" + valuesRecommended.get(i).get("downloads") + " " + getString(R.string.downloads) + ")"); txtSamItem.setTag(valuesRecommended.get(i).get("_id")); txtSamItem.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 100, 1)); // txtSamItem.setOnClickListener(featuredListener); txtSamItem.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent i = new Intent(MainActivity.this, ApkInfo.class); long id = Long.parseLong((String) arg0.getTag()); i.putExtra("_id", id); i.putExtra("top", true); i.putExtra("category", Category.ITEMBASED.ordinal()); startActivity(i); } }); txtSamItem.measure(0, 0); if (i % 2 == 0) { ll.addView(llAlso); llAlso = new LinearLayout(MainActivity.this); llAlso.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 100)); llAlso.setOrientation(LinearLayout.HORIZONTAL); llAlso.addView(txtSamItem); } else { llAlso.addView(txtSamItem); } } ll.addView(llAlso); } } }); } }).start(); }