List of usage examples for android.widget LinearLayout getContext
@ViewDebug.CapturedViewProperty public final Context getContext()
From source file:com.hughes.android.dictionary.DictionaryActivity.java
private void onCreateSetupActionBarAndSearchView() { ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false); final LinearLayout customSearchView = new LinearLayout(getSupportActionBar().getThemedContext()); final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); customSearchView.setLayoutParams(layoutParams); listView.setOnItemClickListener(new OnItemClickListener() { @Override//ww w. j av a 2 s . c o m public void onItemClick(AdapterView<?> parent, View view, int row, long id) { onListItemClick(getListView(), view, row, id); } }); languageButton = new ImageButton(customSearchView.getContext()); languageButton.setScaleType(ScaleType.FIT_CENTER); languageButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { onLanguageButtonClick(); } }); languageButton.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { onLanguageButtonLongClick(v.getContext()); return true; } }); languageButton.setAdjustViewBounds(true); LinearLayout.LayoutParams lpb = new LinearLayout.LayoutParams(application.languageButtonPixels, LinearLayout.LayoutParams.MATCH_PARENT); customSearchView.addView(languageButton, lpb); searchView = new SearchView(getSupportActionBar().getThemedContext()); // Get rid of search icon, it takes up too much space. // There is still text saying "search" in the search field. searchView.setIconifiedByDefault(true); searchView.setIconified(false); searchView.setQueryHint(getString(R.string.searchText)); searchView.setSubmitButtonEnabled(false); searchView.setInputType(InputType.TYPE_CLASS_TEXT); searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI | // EditorInfo.IME_FLAG_NO_FULLSCREEN | // Requires API // 11 EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS); onQueryTextListener = new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { Log.d(LOG, "OnQueryTextListener: onQueryTextSubmit: " + searchView.getQuery()); hideKeyboard(); return true; } @Override public boolean onQueryTextChange(String newText) { Log.d(LOG, "OnQueryTextListener: onQueryTextChange: " + searchView.getQuery()); onSearchTextChange(searchView.getQuery().toString()); return true; } }; searchView.setOnQueryTextListener(onQueryTextListener); searchView.setFocusable(true); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, FrameLayout.LayoutParams.WRAP_CONTENT, 1); customSearchView.addView(searchView, lp); actionBar.setCustomView(customSearchView); actionBar.setDisplayShowCustomEnabled(true); // Avoid wasting space on large left inset Toolbar tb = (Toolbar) customSearchView.getParent(); tb.setContentInsetsRelative(0, 0); }
From source file:org.rm3l.ddwrt.tiles.status.bandwidth.BandwidthMonitoringTile.java
@Override public void onLoadFinished(@NotNull Loader<None> loader, @Nullable None data) { //Set tiles/*from ww w. j a va 2s . com*/ Log.d(LOG_TAG, "onLoadFinished: loader=" + loader + " / data=" + data); //noinspection ConstantConditions if (data == null || bandwidthMonitoringIfaceData.getData().isEmpty()) { data = (None) new None().setException(new DDWRTNoDataException("No Data!")); } @NotNull final TextView errorPlaceHolderView = (TextView) this.layout .findViewById(R.id.tile_status_bandwidth_monitoring_error); @Nullable final Exception exception = data.getException(); if (!(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { if (exception == null) { errorPlaceHolderView.setVisibility(View.GONE); } @NotNull final LinearLayout graphPlaceHolder = (LinearLayout) this.layout .findViewById(R.id.tile_status_bandwidth_monitoring_graph_placeholder); final Map<String, EvictingQueue<DataPoint>> dataCircularBuffer = bandwidthMonitoringIfaceData.getData(); long maxX = System.currentTimeMillis() + 5000; long minX = System.currentTimeMillis() - 5000; double maxY = 10; double minY = 1.; final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); final XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); for (final Map.Entry<String, EvictingQueue<DataPoint>> entry : dataCircularBuffer.entrySet()) { final String iface = entry.getKey(); final EvictingQueue<DataPoint> dataPoints = entry.getValue(); final XYSeries series = new XYSeries(iface); for (final DataPoint point : dataPoints) { final long x = point.getTimestamp(); final double y = point.getValue(); series.add(x, y); maxX = Math.max(maxX, x); minX = Math.min(minX, x); maxY = Math.max(maxY, y); minY = Math.min(minY, y); } // Now we add our series dataset.addSeries(series); // Now we create the renderer final XYSeriesRenderer renderer = new XYSeriesRenderer(); renderer.setLineWidth(2); Integer ifaceColor = colorsCache.get(iface); if (ifaceColor == null) { //Generate a Random Color, excluding 'white' (because graph background is already white) ifaceColor = Color.argb(255, randomColorGen.nextInt(255), randomColorGen.nextInt(255), randomColorGen.nextInt(255)); colorsCache.put(iface, ifaceColor); } renderer.setColor(ifaceColor); // Include low and max value renderer.setDisplayBoundingPoints(true); // we add point markers renderer.setPointStyle(PointStyle.POINT); renderer.setPointStrokeWidth(1); mRenderer.addSeriesRenderer(renderer); } // We want to avoid black border mRenderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00)); // transparent margins // Disable Pan on two axis mRenderer.setPanEnabled(false, false); mRenderer.setYAxisMax(maxY + 10); mRenderer.setYAxisMin(minY); mRenderer.setXAxisMin(minX); mRenderer.setXAxisMax(maxX + 10); mRenderer.setShowGrid(false); mRenderer.setClickEnabled(false); mRenderer.setZoomEnabled(true); mRenderer.setPanEnabled(false); mRenderer.setZoomRate(6.0f); mRenderer.setShowLabels(true); mRenderer.setFitLegend(true); mRenderer.setInScroll(true); final GraphicalView chartView = ChartFactory.getTimeChartView(graphPlaceHolder.getContext(), dataset, mRenderer, null); chartView.repaint(); graphPlaceHolder.addView(chartView, 0); } if (exception != null && !(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { //noinspection ThrowableResultOfMethodCallIgnored final Throwable rootCause = Throwables.getRootCause(exception); errorPlaceHolderView.setText("Error: " + (rootCause != null ? rootCause.getMessage() : "null")); final Context parentContext = this.mParentFragmentActivity; errorPlaceHolderView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { //noinspection ThrowableResultOfMethodCallIgnored if (rootCause != null) { Toast.makeText(parentContext, rootCause.getMessage(), Toast.LENGTH_LONG).show(); } } }); errorPlaceHolderView.setVisibility(View.VISIBLE); } else { if (bandwidthMonitoringIfaceData.getData().isEmpty()) { errorPlaceHolderView.setText("Error: No Data!"); errorPlaceHolderView.setVisibility(View.VISIBLE); } } doneWithLoaderInstance(this, loader, R.id.tile_status_bandwidth_monitoring_togglebutton_title, R.id.tile_status_bandwidth_monitoring_togglebutton_separator); Log.d(LOG_TAG, "onLoadFinished(): done loading!"); }
From source file:org.rm3l.ddwrt.tiles.status.bandwidth.BandwidthWANMonitoringTile.java
@Override public void onLoadFinished(Loader<None> loader, None data) { Log.d(LOG_TAG, "onLoadFinished: loader=" + loader + " / data=" + data); layout.findViewById(R.id.tile_status_bandwidth_monitoring_graph_loading_view).setVisibility(View.GONE); layout.findViewById(R.id.tile_status_bandwidth_monitoring_graph_placeholder).setVisibility(View.VISIBLE); //noinspection ConstantConditions if (data == null || bandwidthMonitoringIfaceData.getData().isEmpty()) { data = (None) new None().setException(new DDWRTNoDataException("No Data!")); }/*from w w w . j ava 2s .c o m*/ @NotNull final TextView errorPlaceHolderView = (TextView) this.layout .findViewById(R.id.tile_status_bandwidth_monitoring_error); @Nullable final Exception exception = data.getException(); if (!(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { if (exception == null) { errorPlaceHolderView.setVisibility(View.GONE); } ((TextView) this.layout.findViewById(R.id.tile_status_bandwidth_monitoring_title)) .setText(this.mParentFragmentActivity.getResources().getString(R.string.bandwidth_usage_mb) + (!Strings.isNullOrEmpty(wanIface) ? (": " + wanIface) : "")); @NotNull final LinearLayout graphPlaceHolder = (LinearLayout) this.layout .findViewById(R.id.tile_status_bandwidth_monitoring_graph_placeholder); final Map<String, EvictingQueue<BandwidthMonitoringTile.DataPoint>> dataCircularBuffer = bandwidthMonitoringIfaceData .getData(); long maxX = System.currentTimeMillis() + 5000; long minX = System.currentTimeMillis() - 5000; double maxY = 10; double minY = 1.; final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); final XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); for (final Map.Entry<String, EvictingQueue<BandwidthMonitoringTile.DataPoint>> entry : dataCircularBuffer .entrySet()) { final String iface = entry.getKey(); final EvictingQueue<BandwidthMonitoringTile.DataPoint> dataPoints = entry.getValue(); final XYSeries series = new XYSeries(iface); for (final BandwidthMonitoringTile.DataPoint point : dataPoints) { final long x = point.getTimestamp(); final double y = point.getValue(); series.add(x, y); maxX = Math.max(maxX, x); minX = Math.min(minX, x); maxY = Math.max(maxY, y); minY = Math.min(minY, y); } // Now we add our series dataset.addSeries(series); // Now we create the renderer final XYSeriesRenderer renderer = new XYSeriesRenderer(); renderer.setLineWidth(2); Integer ifaceColor = colorsCache.get(iface); if (ifaceColor == null) { //Generate a Random Color, excluding 'white' (because graph background is already white) ifaceColor = Color.argb(255, randomColorGen.nextInt(255), randomColorGen.nextInt(255), randomColorGen.nextInt(255)); colorsCache.put(iface, ifaceColor); } renderer.setColor(ifaceColor); // Include low and max value renderer.setDisplayBoundingPoints(true); // we add point markers renderer.setPointStyle(PointStyle.POINT); renderer.setPointStrokeWidth(1); mRenderer.addSeriesRenderer(renderer); } // We want to avoid black border mRenderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00)); // transparent margins // Disable Pan on two axis mRenderer.setPanEnabled(false, false); mRenderer.setYAxisMax(maxY + 10); mRenderer.setYAxisMin(minY); mRenderer.setXAxisMin(minX); mRenderer.setXAxisMax(maxX + 10); mRenderer.setShowGrid(false); mRenderer.setClickEnabled(false); mRenderer.setZoomEnabled(true); mRenderer.setPanEnabled(false); mRenderer.setZoomRate(6.0f); mRenderer.setShowLabels(true); mRenderer.setFitLegend(true); mRenderer.setInScroll(true); final GraphicalView chartView = ChartFactory.getTimeChartView(graphPlaceHolder.getContext(), dataset, mRenderer, null); chartView.repaint(); graphPlaceHolder.addView(chartView, 0); } if (exception != null && !(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { //noinspection ThrowableResultOfMethodCallIgnored final Throwable rootCause = Throwables.getRootCause(exception); errorPlaceHolderView.setText("Error: " + (rootCause != null ? rootCause.getMessage() : "null")); final Context parentContext = this.mParentFragmentActivity; errorPlaceHolderView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { //noinspection ThrowableResultOfMethodCallIgnored if (rootCause != null) { Toast.makeText(parentContext, rootCause.getMessage(), Toast.LENGTH_LONG).show(); } } }); errorPlaceHolderView.setVisibility(View.VISIBLE); } else { if (bandwidthMonitoringIfaceData.getData().isEmpty()) { errorPlaceHolderView.setText("Error: No Data!"); errorPlaceHolderView.setVisibility(View.VISIBLE); } } doneWithLoaderInstance(this, loader, R.id.tile_status_bandwidth_monitoring_togglebutton_title, R.id.tile_status_bandwidth_monitoring_togglebutton_separator); Log.d(LOG_TAG, "onLoadFinished(): done loading!"); }
From source file:org.ambient.control.config.EditConfigFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // integrate object into existing configuration after child fragment has data left for us via onIntegrate. We do the // integration here after the arguments and bundles have been restored. We cannot merge the values in onCreate() because // it will only be called from android when the fragment instance has been removed before. e.g. screen rotation. if (this.valueToIntegrate != null) { this.integrateConfiguration(this.valueToIntegrate); }// w w w. j a v a 2 s . c om try { ScrollView result = (ScrollView) inflater.inflate(R.layout.fragment_edit_config, container, false); LinearLayout content = (LinearLayout) result.findViewById(R.id.linearLayoutEditConfigContent); // init the maps for grouped and sorted fields Map<Integer, Map<Integer, Field>> sortedMap = new TreeMap<Integer, Map<Integer, Field>>(); // and a simple list for those fields which have no sort description List<Field> unsortedList = new ArrayList<Field>(); // create groups if class description is present and defines some ClassDescription description = beanToEdit.getClass().getAnnotation(ClassDescription.class); if (description != null) { for (Group currentGroup : description.groups()) { Map<Integer, Field> category = new TreeMap<Integer, Field>(); sortedMap.put(currentGroup.position(), category); } } else { // create a default group sortedMap.put(0, new TreeMap<Integer, Field>()); } // sort fields that are annotated in groups for (final Field field : beanToEdit.getClass().getFields()) { // only use field with typedef annotation. the rest of the // fields will be ignored if (field.isAnnotationPresent(TypeDef.class)) { if (field.isAnnotationPresent(Presentation.class)) { // put into groups Presentation presentation = field.getAnnotation(Presentation.class); sortedMap.get(presentation.groupPosition()).put(presentation.position(), field); } else { // or to unsorted group if no information for sorting is // present unsortedList.add(field); } } } // if no sorted values haven been drawn we create a default group on // screen and put all unsorted values in there. if some have been // drawn we put them into a "misc" group. we could do a check at the // beginning if several groups have been filled and so on. but we // render them first and get the information as result of that. boolean sortedValuesDrawn = false; for (Integer currentCategoryId : sortedMap.keySet()) { if (sortedMap.get(currentCategoryId).isEmpty()) { continue; } LinearLayout categoryView = (LinearLayout) inflater.inflate(R.layout.layout_editconfig_group_header, null); TextView title = (TextView) categoryView.findViewById(R.id.textViewGroupHeader); TextView descriptionTextView = (TextView) categoryView.findViewById(R.id.textViewGroupDescription); content.addView(categoryView); if (currentCategoryId == 0) { // draw allgemein for category 0. if an group with id 0 is // described the values will be overwritten in next step title.setText("ALLGEMEIN"); descriptionTextView.setVisibility(View.GONE); } // draw the category header and a description if present if (description != null) { for (Group currentGroup : description.groups()) { if (currentGroup.position() == currentCategoryId) { title.setText(currentGroup.name()); if (currentGroup.description().isEmpty() == false) { descriptionTextView.setText(currentGroup.description()); descriptionTextView.setVisibility(View.VISIBLE); } else { descriptionTextView.setVisibility(View.GONE); } break; } } } // draw all handlers for the fields in this category Map<Integer, Field> values = sortedMap.get(currentCategoryId); for (Field field : values.values()) { addFieldToView(inflater, beanToEdit, content, field); // we are shure that the default or a special category have // been used. if there are unsorted values put them into an // additional group later sortedValuesDrawn = true; } } // draw a header for unsorted fields if class description provided // categories for the other fields if (sortedValuesDrawn && unsortedList.isEmpty() == false) { LinearLayout categoryFurther = (LinearLayout) inflater .inflate(R.layout.layout_editconfig_group_header, null); TextView title = (TextView) categoryFurther.findViewById(R.id.textViewGroupHeader); title.setText("WEITERE"); TextView descriptionTextView = (TextView) categoryFurther .findViewById(R.id.textViewGroupDescription); descriptionTextView.setVisibility(View.GONE); content.addView(categoryFurther); } // draw the handlers for (Field currentField : unsortedList) { addFieldToView(inflater, beanToEdit, content, currentField); } // default text if no fields are annotated if (sortedValuesDrawn == false && unsortedList.isEmpty()) { TextView tv = new TextView(content.getContext()); tv.setText("Dieses Objekt wird nicht konfiguriert"); content.addView(tv); } return result; } catch (Exception e) { Log.e(LOG, "could not create View for bean: " + beanToEdit.getClass().getName(), e); return null; } }