List of usage examples for android.widget RelativeLayout addView
public void addView(View child)
Adds a child view.
From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java
private RelativeLayout createParticipantView(MemberStatusTO ms) { RelativeLayout rl = new RelativeLayout(this); int rlW = UIUtils.convertDipToPixels(this, 55); rl.setLayoutParams(new RelativeLayout.LayoutParams(rlW, rlW)); getLayoutInflater().inflate(R.layout.avatar, rl); ImageView avatar = (ImageView) rl.getChildAt(rl.getChildCount() - 1); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(avatar.getLayoutParams()); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); avatar.setLayoutParams(params);//from w w w . java2 s . c o m setAvatar(avatar, ms.member); ImageView statusView = new ImageView(this); int w = UIUtils.convertDipToPixels(this, 12); RelativeLayout.LayoutParams iconParams = new RelativeLayout.LayoutParams(w, w); iconParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); iconParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); statusView.setLayoutParams(iconParams); statusView.setAdjustViewBounds(true); statusView.setScaleType(ScaleType.CENTER_CROP); setStatusIcon(statusView, ms); rl.addView(statusView); return rl; }
From source file:fr.cph.chicago.core.adapter.FavoritesAdapter.java
@NonNull private LinearLayout createBikeLine(@NonNull final BikeStation bikeStation, final boolean firstLine) { final LinearLayout.LayoutParams lineParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);/*from ww w . j a va2 s .co m*/ final LinearLayout line = new LinearLayout(context); line.setOrientation(LinearLayout.HORIZONTAL); line.setLayoutParams(lineParams); // Left final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); final RelativeLayout left = new RelativeLayout(context); left.setLayoutParams(leftParam); final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); availableParam.addRule(RelativeLayout.RIGHT_OF, lineId); availableParam.setMargins(pixelsHalf, 0, 0, 0); final TextView boundCustomTextView = new TextView(context); boundCustomTextView.setText(activity.getString(R.string.bike_available_docks)); boundCustomTextView.setSingleLine(true); boundCustomTextView.setLayoutParams(availableParam); boundCustomTextView.setTextColor(grey5); int availableId = Util.generateViewId(); boundCustomTextView.setId(availableId); final RelativeLayout.LayoutParams availableValueParam = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); availableValueParam.addRule(RelativeLayout.RIGHT_OF, availableId); availableValueParam.setMargins(pixelsHalf, 0, 0, 0); final TextView amountBike = new TextView(context); final String text = firstLine ? activity.getString(R.string.bike_available_bikes) : activity.getString(R.string.bike_available_docks); boundCustomTextView.setText(text); final Integer data = firstLine ? bikeStation.getAvailableBikes() : bikeStation.getAvailableDocks(); if (data == null) { amountBike.setText("?"); amountBike.setTextColor(ContextCompat.getColor(context, R.color.orange)); } else { amountBike.setText(String.valueOf(data)); final int color = data == 0 ? R.color.red : R.color.green; amountBike.setTextColor(ContextCompat.getColor(context, color)); } amountBike.setLayoutParams(availableValueParam); left.addView(lineIndication); left.addView(boundCustomTextView); left.addView(amountBike); line.addView(left); return line; }
From source file:org.openremote.android.console.AppSettingsActivity.java
/** * It contains a list view to display custom servers, * "Add" button to add custom server, "Delete" button to delete custom server. * The custom servers would be saved in customServers.xml. If click a list item, it would be saved as current server. * //w ww. j a v a2 s . co m * @return the linear layout */ private LinearLayout constructCustomServersView() { LinearLayout custumeView = new LinearLayout(this); custumeView.setOrientation(LinearLayout.VERTICAL); custumeView.setPadding(20, 5, 5, 0); custumeView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); ArrayList<String> customServers = new ArrayList<String>(); initCustomServersFromFile(customServers); RelativeLayout buttonsView = new RelativeLayout(this); buttonsView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 80)); Button addServer = new Button(this); addServer.setWidth(80); RelativeLayout.LayoutParams addServerLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); addServerLayout.addRule(RelativeLayout.CENTER_HORIZONTAL); addServer.setLayoutParams(addServerLayout); addServer.setText("Add"); addServer.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(); intent.setClass(AppSettingsActivity.this, AddServerActivity.class); startActivityForResult(intent, Constants.REQUEST_CODE); } }); Button deleteServer = new Button(this); deleteServer.setWidth(80); RelativeLayout.LayoutParams deleteServerLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); deleteServerLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); deleteServer.setLayoutParams(deleteServerLayout); deleteServer.setText("Delete"); deleteServer.setOnClickListener(new OnClickListener() { @SuppressWarnings("unchecked") public void onClick(View v) { int checkedPosition = customListView.getCheckedItemPosition(); if (!(checkedPosition == ListView.INVALID_POSITION)) { customListView.setItemChecked(checkedPosition, false); ((ArrayAdapter<String>) customListView.getAdapter()) .remove(customListView.getItemAtPosition(checkedPosition).toString()); currentServer = ""; AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer); writeCustomServerToFile(); } } }); buttonsView.addView(addServer); buttonsView.addView(deleteServer); customListView = new ListView(this); customListView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 200)); customListView.setCacheColorHint(0); final ArrayAdapter<String> serverListAdapter = new ArrayAdapter<String>(appSettingsView.getContext(), R.layout.server_list_item, customServers); customListView.setAdapter(serverListAdapter); customListView.setItemsCanFocus(true); customListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); if (currentCustomServerIndex != -1) { customListView.setItemChecked(currentCustomServerIndex, true); currentServer = (String) customListView.getItemAtPosition(currentCustomServerIndex); } customListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { currentServer = (String) parent.getItemAtPosition(position); AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer); writeCustomServerToFile(); requestPanelList(); checkAuthentication(); requestAccess(); } }); custumeView.addView(customListView); custumeView.addView(buttonsView); requestPanelList(); checkAuthentication(); requestAccess(); return custumeView; }
From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java
private View handleBuses(final int position, @NonNull final ViewGroup parent) { final LayoutInflater vi = (LayoutInflater) parent.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View convertView = vi.inflate(R.layout.list_nearby, parent, false); // Bus//from ww w. j av a 2 s .c o m final int index = position - stations.size(); final BusStop busStop = busStops.get(index); final ImageView imageView = (ImageView) convertView.findViewById(R.id.icon); imageView.setImageDrawable( ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_directions_bus_white_24dp)); final TextView routeView = (TextView) convertView.findViewById(R.id.station_name); routeView.setText(busStop.getName()); final LinearLayout resultLayout = (LinearLayout) convertView.findViewById(R.id.nearby_results); final Map<String, List<BusArrival>> arrivalsForStop = busArrivals.get(busStop.getId(), new HashMap<>()); Stream.of(arrivalsForStop.entrySet()).forEach(entry -> { final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); final RelativeLayout insideLayout = new RelativeLayout(context); insideLayout.setLayoutParams(leftParam); insideLayout.setPadding(line1PaddingColor * 2, stopsPaddingTop, 0, 0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { insideLayout.setBackground(ContextCompat.getDrawable(parent.getContext(), R.drawable.any_selector)); } final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams stopParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); stopParam.addRule(RelativeLayout.RIGHT_OF, lineId); stopParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0); final LinearLayout stopLayout = new LinearLayout(context); stopLayout.setOrientation(LinearLayout.VERTICAL); stopLayout.setLayoutParams(stopParam); int stopId = Util.generateViewId(); stopLayout.setId(stopId); final RelativeLayout.LayoutParams boundParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); boundParam.addRule(RelativeLayout.RIGHT_OF, stopId); final LinearLayout boundLayout = new LinearLayout(context); boundLayout.setOrientation(LinearLayout.HORIZONTAL); final String direction = entry.getKey(); final List<BusArrival> busArrivals = entry.getValue(); final String routeId = busArrivals.get(0).getRouteId(); final TextView bound = new TextView(context); final String routeIdText = routeId + " (" + direction + "): "; bound.setText(routeIdText); bound.setTextColor(ContextCompat.getColor(context, R.color.grey_5)); boundLayout.addView(bound); Stream.of(busArrivals).forEach(busArrival -> { final TextView timeView = new TextView(context); final String timeLeftDueDelay = busArrival.getTimeLeftDueDelay() + " "; timeView.setText(timeLeftDueDelay); timeView.setTextColor(ContextCompat.getColor(context, R.color.grey)); timeView.setLines(1); timeView.setEllipsize(TruncateAt.END); boundLayout.addView(timeView); }); stopLayout.addView(boundLayout); insideLayout.addView(lineIndication); insideLayout.addView(stopLayout); resultLayout.addView(insideLayout); }); convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, busStop.getId(), busStop.getPosition().getLatitude(), busStop.getPosition().getLongitude())); return convertView; }
From source file:org.openremote.android.console.AppSettingsActivity.java
/** * Creates the auto layout./*from www. ja va2 s . c o m*/ * It contains toggle button to switch auto state, two text view to indicate auto messages. * * @return the relative layout */ private RelativeLayout createAutoLayout() { RelativeLayout autoLayout = new RelativeLayout(this); autoLayout.setPadding(10, 5, 10, 10); autoLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 80)); TextView autoText = new TextView(this); RelativeLayout.LayoutParams autoTextLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); autoTextLayout.addRule(RelativeLayout.ALIGN_PARENT_LEFT); autoTextLayout.addRule(RelativeLayout.CENTER_VERTICAL); autoText.setLayoutParams(autoTextLayout); autoText.setText("Auto Discovery"); ToggleButton autoButton = new ToggleButton(this); autoButton.setWidth(150); RelativeLayout.LayoutParams autoButtonLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); autoButtonLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); autoButtonLayout.addRule(RelativeLayout.CENTER_VERTICAL); autoButton.setLayoutParams(autoButtonLayout); autoButton.setChecked(autoMode); autoButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { appSettingsView.removeViewAt(2); currentServer = ""; if (isChecked) { IPAutoDiscoveryServer.isInterrupted = false; appSettingsView.addView(constructAutoServersView(), 2); } else { IPAutoDiscoveryServer.isInterrupted = true; appSettingsView.addView(constructCustomServersView(), 2); } AppSettingsModel.setAutoMode(AppSettingsActivity.this, isChecked); } }); TextView infoText = new TextView(this); RelativeLayout.LayoutParams infoTextLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); infoTextLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); infoTextLayout.addRule(RelativeLayout.ALIGN_PARENT_LEFT); infoText.setLayoutParams(infoTextLayout); infoText.setTextSize(10); infoText.setText("Turn off auto-discovery to input controller url manually."); autoLayout.addView(autoText); autoLayout.addView(autoButton); autoLayout.addView(infoText); return autoLayout; }
From source file:org.cafemember.ui.LaunchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Date now = new Date(); /*int year = now.getYear(); int month = now.getMonth();// ww w.java 2s . co m int day = now.getDay(); now.getDate(); long curr = 147083220000l; if(System.currentTimeMillis() > curr ){ Toast.makeText(this," . ? ",Toast.LENGTH_LONG).show(); finish(); }*/ ApplicationLoader.postInitApplication(); NativeCrashManager.handleDumpFiles(this); if (!UserConfig.isClientActivated()) { Intent intent = getIntent(); if (intent != null && intent.getAction() != null && (Intent.ACTION_SEND.equals(intent.getAction()) || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE))) { super.onCreate(savedInstanceState); finish(); return; } if (intent != null && !intent.getBooleanExtra("fromIntro", false)) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("logininfo2", MODE_PRIVATE); Map<String, ?> state = preferences.getAll(); if (state.isEmpty()) { Intent intent2 = new Intent(this, IntroActivity.class); startActivity(intent2); super.onCreate(savedInstanceState); finish(); return; } } } requestWindowFeature(Window.FEATURE_NO_TITLE); setTheme(R.style.Theme_TMessages); getWindow().setBackgroundDrawableResource(R.drawable.transparent); super.onCreate(savedInstanceState); Theme.loadRecources(this); if (UserConfig.passcodeHash.length() != 0 && UserConfig.appLocked) { UserConfig.lastPauseTime = ConnectionsManager.getInstance().getCurrentTime(); } int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { AndroidUtilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId); } actionBarLayout = new ActionBarLayout(this); drawerLayoutContainer = new DrawerLayoutContainer(this); setContentView(drawerLayoutContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (AndroidUtilities.isTablet()) { getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); RelativeLayout launchLayout = new RelativeLayout(this); drawerLayoutContainer.addView(launchLayout); FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) launchLayout.getLayoutParams(); layoutParams1.width = LayoutHelper.MATCH_PARENT; layoutParams1.height = LayoutHelper.MATCH_PARENT; launchLayout.setLayoutParams(layoutParams1); backgroundTablet = new ImageView(this); backgroundTablet.setScaleType(ImageView.ScaleType.CENTER_CROP); backgroundTablet.setImageResource(R.drawable.cats); launchLayout.addView(backgroundTablet); RelativeLayout.LayoutParams relativeLayoutParams = (RelativeLayout.LayoutParams) backgroundTablet .getLayoutParams(); relativeLayoutParams.width = LayoutHelper.MATCH_PARENT; relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; backgroundTablet.setLayoutParams(relativeLayoutParams); launchLayout.addView(actionBarLayout); relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams(); relativeLayoutParams.width = LayoutHelper.MATCH_PARENT; relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; actionBarLayout.setLayoutParams(relativeLayoutParams); rightActionBarLayout = new ActionBarLayout(this); launchLayout.addView(rightActionBarLayout); relativeLayoutParams = (RelativeLayout.LayoutParams) rightActionBarLayout.getLayoutParams(); relativeLayoutParams.width = AndroidUtilities.dp(320); relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; rightActionBarLayout.setLayoutParams(relativeLayoutParams); rightActionBarLayout.init(rightFragmentsStack); rightActionBarLayout.setDelegate(this); shadowTabletSide = new FrameLayout(this); shadowTabletSide.setBackgroundColor(0x40295274); launchLayout.addView(shadowTabletSide); relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTabletSide.getLayoutParams(); relativeLayoutParams.width = AndroidUtilities.dp(1); relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; shadowTabletSide.setLayoutParams(relativeLayoutParams); shadowTablet = new FrameLayout(this); shadowTablet.setVisibility(View.GONE); shadowTablet.setBackgroundColor(0x7F000000); launchLayout.addView(shadowTablet); relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTablet.getLayoutParams(); relativeLayoutParams.width = LayoutHelper.MATCH_PARENT; relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; shadowTablet.setLayoutParams(relativeLayoutParams); shadowTablet.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (!actionBarLayout.fragmentsStack.isEmpty() && event.getAction() == MotionEvent.ACTION_UP) { float x = event.getX(); float y = event.getY(); int location[] = new int[2]; layersActionBarLayout.getLocationOnScreen(location); int viewX = location[0]; int viewY = location[1]; if (layersActionBarLayout.checkTransitionAnimation() || x > viewX && x < viewX + layersActionBarLayout.getWidth() && y > viewY && y < viewY + layersActionBarLayout.getHeight()) { return false; } else { if (!layersActionBarLayout.fragmentsStack.isEmpty()) { for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) { layersActionBarLayout .removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0)); a--; } layersActionBarLayout.closeLastFragment(true); } return true; } } return false; } }); shadowTablet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); layersActionBarLayout = new ActionBarLayout(this); layersActionBarLayout.setRemoveActionBarExtraHeight(true); layersActionBarLayout.setBackgroundView(shadowTablet); layersActionBarLayout.setUseAlphaAnimations(true); layersActionBarLayout.setBackgroundResource(R.drawable.boxshadow); launchLayout.addView(layersActionBarLayout); relativeLayoutParams = (RelativeLayout.LayoutParams) layersActionBarLayout.getLayoutParams(); relativeLayoutParams.width = AndroidUtilities.dp(530); relativeLayoutParams.height = AndroidUtilities.dp(528); layersActionBarLayout.setLayoutParams(relativeLayoutParams); layersActionBarLayout.init(layerFragmentsStack); layersActionBarLayout.setDelegate(this); layersActionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer); layersActionBarLayout.setVisibility(View.GONE); } else { drawerLayoutContainer.addView(actionBarLayout, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } ListView listView = new ListView(this) { @Override public boolean hasOverlappingRendering() { return false; } }; listView.setBackgroundColor(0xffffffff); listView.setAdapter(drawerLayoutAdapter = new DrawerLayoutAdapter(this)); listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); drawerLayoutContainer.setDrawerLayout(listView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); Point screenSize = AndroidUtilities.getRealScreenSize(); layoutParams.width = AndroidUtilities.isTablet() ? AndroidUtilities.dp(320) : Math.min(screenSize.x, screenSize.y) - AndroidUtilities.dp(56); layoutParams.height = LayoutHelper.MATCH_PARENT; listView.setLayoutParams(layoutParams); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // if (position == 12) { presentFragment(new SettingsActivity()); drawerLayoutContainer.closeDrawer(false); } else if (position == 11) { try { RulesActivity his = new RulesActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 2) { Defaults def = Defaults.getInstance(); boolean open = def.openOnJoin(); def.setOpenOnJoin(!open); if (view instanceof TextCheckCell) { ((TextCheckCell) view).setChecked(!open); } } else if (position == 4) { try { HistoryActivity his = new HistoryActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 3) { Intent telegram = new Intent(Intent.ACTION_VIEW, Uri.parse("https://telegram.me/cafemember")); startActivity(telegram); drawerLayoutContainer.closeDrawer(false); } else if (position == 5) { try { FAQActivity his = new FAQActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 6) { Intent telegram = new Intent(Intent.ACTION_VIEW, Uri.parse("https://telegram.me/" + Defaults.getInstance().getSupport())); startActivity(telegram); drawerLayoutContainer.closeDrawer(false); } else if (position == 7) { try { HelpActivity his = new HelpActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 8) { try { AddRefActivity his = new AddRefActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 9) { try { Log.d("TAB", "Triggering"); ShareActivity his = new ShareActivity(); Log.d("TAB", "Triggered"); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 10) { try { // TransfareActivity his = new TransfareActivity(); // presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } } }); drawerLayoutContainer.setParentActionBarLayout(actionBarLayout); actionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer); actionBarLayout.init(mainFragmentsStack); actionBarLayout.setDelegate(this); ApplicationLoader.loadWallpaper(); passcodeView = new PasscodeView(this); drawerLayoutContainer.addView(passcodeView); FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) passcodeView.getLayoutParams(); layoutParams1.width = LayoutHelper.MATCH_PARENT; layoutParams1.height = LayoutHelper.MATCH_PARENT; passcodeView.setLayoutParams(layoutParams1); NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeOtherAppActivities, this); currentConnectionState = ConnectionsManager.getInstance().getConnectionState(); NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout); NotificationCenter.getInstance().addObserver(this, NotificationCenter.mainUserInfoChanged); NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeOtherAppActivities); NotificationCenter.getInstance().addObserver(this, NotificationCenter.didUpdatedConnectionState); NotificationCenter.getInstance().addObserver(this, NotificationCenter.needShowAlert); NotificationCenter.getInstance().addObserver(this, NotificationCenter.wasUnableToFindCurrentLocation); if (Build.VERSION.SDK_INT < 14) { NotificationCenter.getInstance().addObserver(this, NotificationCenter.screenStateChanged); } if (actionBarLayout.fragmentsStack.isEmpty()) { if (!UserConfig.isClientActivated()) { actionBarLayout.addFragmentToStack(new LoginActivity()); drawerLayoutContainer.setAllowOpenDrawer(false, false); } else { dialogsFragment = new DialogsActivity(null); actionBarLayout.addFragmentToStack(dialogsFragment); drawerLayoutContainer.setAllowOpenDrawer(true, false); } try { if (savedInstanceState != null) { String fragmentName = savedInstanceState.getString("fragment"); if (fragmentName != null) { Bundle args = savedInstanceState.getBundle("args"); switch (fragmentName) { case "chat": if (args != null) { ChatActivity chat = new ChatActivity(args); if (actionBarLayout.addFragmentToStack(chat)) { chat.restoreSelfArgs(savedInstanceState); } } break; case "settings": { SettingsActivity settings = new SettingsActivity(); actionBarLayout.addFragmentToStack(settings); settings.restoreSelfArgs(savedInstanceState); break; } case "group": if (args != null) { GroupCreateFinalActivity group = new GroupCreateFinalActivity(args); if (actionBarLayout.addFragmentToStack(group)) { group.restoreSelfArgs(savedInstanceState); } } break; case "channel": if (args != null) { ChannelCreateActivity channel = new ChannelCreateActivity(args); if (actionBarLayout.addFragmentToStack(channel)) { channel.restoreSelfArgs(savedInstanceState); } } break; case "edit": if (args != null) { ChannelEditActivity channel = new ChannelEditActivity(args); if (actionBarLayout.addFragmentToStack(channel)) { channel.restoreSelfArgs(savedInstanceState); } } break; case "chat_profile": if (args != null) { ProfileActivity profile = new ProfileActivity(args); if (actionBarLayout.addFragmentToStack(profile)) { profile.restoreSelfArgs(savedInstanceState); } } break; case "wallpapers": { WallpapersActivity settings = new WallpapersActivity(); actionBarLayout.addFragmentToStack(settings); settings.restoreSelfArgs(savedInstanceState); break; } } } } } catch (Exception e) { FileLog.e("tmessages", e); } } else { boolean allowOpen = true; if (AndroidUtilities.isTablet()) { allowOpen = actionBarLayout.fragmentsStack.size() <= 1 && layersActionBarLayout.fragmentsStack.isEmpty(); if (layersActionBarLayout.fragmentsStack.size() == 1 && layersActionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) { allowOpen = false; } } if (actionBarLayout.fragmentsStack.size() == 1 && actionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) { allowOpen = false; } drawerLayoutContainer.setAllowOpenDrawer(allowOpen, false); } handleIntent(getIntent(), false, savedInstanceState != null, false); needLayout(); final View view = getWindow().getDecorView().getRootView(); view.getViewTreeObserver() .addOnGlobalLayoutListener(onGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int height = view.getMeasuredHeight(); if (height > AndroidUtilities.dp(100) && height < AndroidUtilities.displaySize.y && height + AndroidUtilities.dp(100) > AndroidUtilities.displaySize.y) { AndroidUtilities.displaySize.y = height; FileLog.e("tmessages", "fix display size y to " + AndroidUtilities.displaySize.y); } } }); }
From source file:com.derrick.movies.MovieDetailsActivity.java
private void setTrailers(Videos videos) { videosList = videos.getResults();//from w ww .j a v a 2 s . com int size = videosList.size(); if (size == 1) { txt_title_trailer.setText("Trailer"); } for (int i = 0; i < size; i++) { Result result = videosList.get(i); String url = IMAGE_YOUTUBE + result.getKey() + YOUTUBE_QUALITY; ImageView imageView; ImageView imageView_play; TextView txt_name; ViewGroup.LayoutParams lp = new RelativeLayout.LayoutParams(70, 70); ViewGroup.LayoutParams lp2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); RelativeLayout relativeLayout = new RelativeLayout(this); relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); if (size == 1) { imageView = new ImageView(getApplicationContext()); imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); } else { imageView = new ImageView(getApplicationContext()); imageView .setLayoutParams(new RelativeLayout.LayoutParams(500, ViewGroup.LayoutParams.MATCH_PARENT)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); } imageView_play = new ImageView(getApplicationContext()); imageView_play.setLayoutParams(lp); RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) imageView_play .getLayoutParams(); layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); imageView_play.setLayoutParams(layoutParams); imageView_play.setScaleType(ImageView.ScaleType.CENTER_CROP); Drawable drawable = getResources() .getDrawable(getResources().getIdentifier("play", "drawable", getPackageName())); imageView_play.setImageDrawable(drawable); txt_name = new TextView(getApplicationContext()); txt_name.setLayoutParams(lp2); RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) txt_name.getLayoutParams(); layoutParams2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); layoutParams2.setMargins(8, 8, 8, 16); txt_name.setLayoutParams(layoutParams2); txt_name.setTypeface(robotoCondensed); txt_name.setText(result.getName()); txt_name.setTextColor(getResources().getColor(R.color.colorWhite)); Glide.with(getBaseContext()).load(url).diskCacheStrategy(DiskCacheStrategy.ALL) .listener(new RequestListener<String, GlideDrawable>() { @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return false; } @Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { return false; } }).into(imageView); // trailerSlider.addView(imageView_play); relativeLayout.addView(imageView); relativeLayout.addView(imageView_play); relativeLayout.addView(txt_name); trailerSlider.addView(relativeLayout); } }
From source file:org.onebusaway.android.ui.ArrivalsListAdapterStyleB.java
@Override protected void initView(final View view, CombinedArrivalInfoStyleB combinedArrivalInfoStyleB) { final ArrivalInfo stopInfo = combinedArrivalInfoStyleB.getArrivalInfoList().get(0); final ObaArrivalInfo arrivalInfo = stopInfo.getInfo(); final Context context = getContext(); LayoutInflater inflater = LayoutInflater.from(context); TextView routeName = (TextView) view.findViewById(R.id.routeName); TextView destination = (TextView) view.findViewById(R.id.routeDestination); // TableLayout that we will fill with TableRows of arrival times TableLayout arrivalTimesLayout = (TableLayout) view.findViewById(R.id.arrivalTimeLayout); arrivalTimesLayout.removeAllViews(); Resources r = view.getResources(); ImageButton starBtn = (ImageButton) view.findViewById(R.id.route_star); starBtn.setColorFilter(r.getColor(R.color.theme_primary)); ImageButton mapImageBtn = (ImageButton) view.findViewById(R.id.mapImageBtn); mapImageBtn.setColorFilter(r.getColor(R.color.theme_primary)); ImageButton routeMoreInfo = (ImageButton) view.findViewById(R.id.route_more_info); routeMoreInfo.setColorFilter(r.getColor(R.color.switch_thumb_normal_material_dark)); starBtn.setImageResource(/*from ww w .j a v a2s . c o m*/ stopInfo.isRouteAndHeadsignFavorite() ? R.drawable.focus_star_on : R.drawable.focus_star_off); starBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Show dialog for setting route favorite RouteFavoriteDialogFragment dialog = new RouteFavoriteDialogFragment.Builder( stopInfo.getInfo().getRouteId(), stopInfo.getInfo().getHeadsign()) .setRouteShortName(stopInfo.getInfo().getShortName()) .setRouteLongName(stopInfo.getInfo().getRouteLongName()) .setStopId(stopInfo.getInfo().getStopId()) .setFavorite(!stopInfo.isRouteAndHeadsignFavorite()).build(); dialog.setCallback(new RouteFavoriteDialogFragment.Callback() { @Override public void onSelectionComplete(boolean savedFavorite) { if (savedFavorite) { mFragment.refreshLocal(); } } }); dialog.show(mFragment.getFragmentManager(), RouteFavoriteDialogFragment.TAG); } }); // Setup map mapImageBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFragment.showRouteOnMap(stopInfo); } }); // Setup more routeMoreInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFragment.showListItemMenu(view, stopInfo); } }); routeName.setText(arrivalInfo.getShortName()); destination.setText(MyTextUtils.toTitleCase(arrivalInfo.getHeadsign())); // Loop through the arrival times and create the TableRows that contains the data for (int i = 0; i < combinedArrivalInfoStyleB.getArrivalInfoList().size(); i++) { final ArrivalInfo arrivalRow = combinedArrivalInfoStyleB.getArrivalInfoList().get(i); final ObaArrivalInfo tempArrivalInfo = arrivalRow.getInfo(); long scheduledTime = tempArrivalInfo.getScheduledArrivalTime(); // Create a new row to be added final TableRow tr = (TableRow) inflater.inflate(R.layout.arrivals_list_tr_template_style_b, null); // Layout and views to inflate from XML templates RelativeLayout layout; TextView scheduleView, estimatedView, statusView; View divider; if (i == 0) { // Use larger styled layout/view for next arrival time layout = (RelativeLayout) inflater.inflate(R.layout.arrivals_list_rl_template_style_b_large, null); scheduleView = (TextView) inflater .inflate(R.layout.arrivals_list_tv_template_style_b_schedule_large, null); estimatedView = (TextView) inflater .inflate(R.layout.arrivals_list_tv_template_style_b_estimated_large, null); statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_large, null); } else { // Use smaller styled layout/view for further out times layout = (RelativeLayout) inflater.inflate(R.layout.arrivals_list_rl_template_style_b_small, null); scheduleView = (TextView) inflater .inflate(R.layout.arrivals_list_tv_template_style_b_schedule_small, null); estimatedView = (TextView) inflater .inflate(R.layout.arrivals_list_tv_template_style_b_estimated_small, null); statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_small, null); } // Set arrival times and status in views scheduleView.setText(DateUtils.formatDateTime(context, scheduledTime, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT)); if (arrivalRow.getPredicted()) { long eta = arrivalRow.getEta(); if (eta == 0) { estimatedView.setText(R.string.stop_info_eta_now); } else { estimatedView.setText(eta + " min"); } } else { estimatedView.setText(R.string.stop_info_eta_unknown); } statusView.setText(arrivalRow.getStatusText()); int colorCode = arrivalRow.getColor(); statusView.setBackgroundResource(R.drawable.round_corners_style_b_status); GradientDrawable d = (GradientDrawable) statusView.getBackground(); d.setColor(context.getResources().getColor(colorCode)); int alpha; if (i == 0) { // Set next arrival alpha = (int) (1.0f * 255); // X percent transparency } else { // Set smaller rows alpha = (int) (.35f * 255); // X percent transparency } d.setAlpha(alpha); // Set padding on status view int pSides = UIUtils.dpToPixels(context, 5); int pTopBottom = UIUtils.dpToPixels(context, 2); statusView.setPadding(pSides, pTopBottom, pSides, pTopBottom); // Add TextViews to layout layout.addView(scheduleView); layout.addView(statusView); layout.addView(estimatedView); // Make sure the TextViews align left/center/right of parent relative layout RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) scheduleView.getLayoutParams(); params1.addRule(RelativeLayout.ALIGN_PARENT_LEFT); params1.addRule(RelativeLayout.CENTER_VERTICAL); scheduleView.setLayoutParams(params1); RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) statusView.getLayoutParams(); params2.addRule(RelativeLayout.CENTER_IN_PARENT); // Give status view a little extra margin int p = UIUtils.dpToPixels(context, 3); params2.setMargins(p, p, p, p); statusView.setLayoutParams(params2); RelativeLayout.LayoutParams params3 = (RelativeLayout.LayoutParams) estimatedView.getLayoutParams(); params3.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); params3.addRule(RelativeLayout.CENTER_VERTICAL); estimatedView.setLayoutParams(params3); // Add layout to TableRow tr.addView(layout); // Add the divider, if its not the first row if (i != 0) { int dividerHeight = UIUtils.dpToPixels(context, 1); divider = inflater.inflate(R.layout.arrivals_list_divider_template_style_b, null); divider.setLayoutParams( new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, dividerHeight)); arrivalTimesLayout.addView(divider); } // Add click listener tr.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFragment.showListItemMenu(tr, arrivalRow); } }); // Add TableRow to container layout arrivalTimesLayout.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT)); } // Show or hide reminder for this trip ContentValues values = null; if (mTripsForStop != null) { values = mTripsForStop.getValues(arrivalInfo.getTripId()); } if (values != null) { String reminderName = values.getAsString(ObaContract.Trips.NAME); TextView reminder = (TextView) view.findViewById(R.id.reminder); if (reminderName.length() == 0) { reminderName = context.getString(R.string.trip_info_noname); } reminder.setText(reminderName); Drawable d = reminder.getCompoundDrawables()[0]; d = DrawableCompat.wrap(d); DrawableCompat.setTint(d.mutate(), view.getResources().getColor(R.color.theme_primary)); reminder.setCompoundDrawables(d, null, null, null); reminder.setVisibility(View.VISIBLE); } else { // Explicitly set reminder to invisible because we might be reusing // this view. View reminder = view.findViewById(R.id.reminder); reminder.setVisibility(View.GONE); } }
From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java
private View handleTrains(final int position, View convertView, @NonNull final ViewGroup parent) { // Train/* w w w . j a v a 2s . c om*/ final Station station = stations.get(position); final Set<TrainLine> trainLines = station.getLines(); TrainViewHolder viewHolder; if (convertView == null || convertView.getTag() == null) { final LayoutInflater vi = (LayoutInflater) parent.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = vi.inflate(R.layout.list_nearby, parent, false); viewHolder = new TrainViewHolder(); viewHolder.resultLayout = (LinearLayout) convertView.findViewById(R.id.nearby_results); viewHolder.stationNameView = (TextView) convertView.findViewById(R.id.station_name); viewHolder.imageView = (ImageView) convertView.findViewById(R.id.icon); viewHolder.details = new HashMap<>(); viewHolder.arrivalTime = new HashMap<>(); convertView.setTag(viewHolder); } else { viewHolder = (TrainViewHolder) convertView.getTag(); } viewHolder.stationNameView.setText(station.getName()); viewHolder.imageView .setImageDrawable(ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_train_white_24dp)); for (final TrainLine trainLine : trainLines) { if (trainArrivals.indexOfKey(station.getId()) != -1) { final List<Eta> etas = trainArrivals.get(station.getId()).getEtas(trainLine); if (etas.size() != 0) { final LinearLayout llv; boolean cleanBeforeAdd = false; if (viewHolder.details.containsKey(trainLine)) { llv = viewHolder.details.get(trainLine); cleanBeforeAdd = true; } else { final LinearLayout llh = new LinearLayout(context); llh.setOrientation(LinearLayout.HORIZONTAL); llh.setPadding(line1PaddingColor, stopsPaddingTop, 0, 0); llv = new LinearLayout(context); llv.setOrientation(LinearLayout.VERTICAL); llv.setPadding(line1PaddingColor, 0, 0, 0); llh.addView(llv); viewHolder.resultLayout.addView(llh); viewHolder.details.put(trainLine, llv); } final List<String> keysCleaned = new ArrayList<>(); for (final Eta eta : etas) { final Stop stop = eta.getStop(); final String key = station.getName() + "_" + trainLine.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName(); if (viewHolder.arrivalTime.containsKey(key)) { final RelativeLayout insideLayout = viewHolder.arrivalTime.get(key); final TextView timing = (TextView) insideLayout.getChildAt(2); if (cleanBeforeAdd && !keysCleaned.contains(key)) { timing.setText(""); keysCleaned.add(key); } final String timingText = timing.getText() + eta.getTimeLeftDueDelay() + " "; timing.setText(timingText); } else { final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); final RelativeLayout insideLayout = new RelativeLayout(context); insideLayout.setLayoutParams(leftParam); final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, trainLine); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); availableParam.addRule(RelativeLayout.RIGHT_OF, lineId); availableParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0); final TextView stopName = new TextView(context); final String destName = eta.getDestName() + ": "; stopName.setText(destName); stopName.setTextColor(ContextCompat.getColor(parent.getContext(), R.color.grey_5)); stopName.setLayoutParams(availableParam); int availableId = Util.generateViewId(); stopName.setId(availableId); final RelativeLayout.LayoutParams availableValueParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); availableValueParam.addRule(RelativeLayout.RIGHT_OF, availableId); availableValueParam.setMargins(0, 0, 0, 0); final TextView timing = new TextView(context); final String timeLeftDueDelay = eta.getTimeLeftDueDelay() + " "; timing.setText(timeLeftDueDelay); timing.setTextColor(ContextCompat.getColor(parent.getContext(), R.color.grey)); timing.setLines(1); timing.setEllipsize(TruncateAt.END); timing.setLayoutParams(availableValueParam); insideLayout.addView(lineIndication); insideLayout.addView(stopName); insideLayout.addView(timing); llv.addView(insideLayout); viewHolder.arrivalTime.put(key, insideLayout); } } } } } convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, station.getId(), station.getStopsPosition().get(0).getLatitude(), station.getStopsPosition().get(0).getLongitude())); return convertView; }