List of usage examples for android.content Context LAYOUT_INFLATER_SERVICE
String LAYOUT_INFLATER_SERVICE
To view the source code for android.content Context LAYOUT_INFLATER_SERVICE.
Click Source Link
From source file:it.jaschke.alexandria.model.view.BookDetailViewModel.java
/** * Removes all views from the {@link LinearLayout} and adds new ones for * the specified instances of {@link Category}. * * @param container {@link LinearLayout} that will contain the categories. * @param categories the instances of {@link Category} to be placed in the * container./* w w w . j av a 2s . c o m*/ */ @BindingAdapter({ "bind:categories" }) public static void loadCategoryViews(LinearLayout container, List<Category> categories) { container.removeAllViews(); if (categories == null || categories.isEmpty()) { return; } LayoutInflater inflater = (LayoutInflater) container.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (Category category : categories) { CategoryListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item_category, container, false); CategoryListItemViewModel itemViewModel = new CategoryListItemViewModel(); itemViewModel.setCategory(category); binding.setViewModel(itemViewModel); container.addView(binding.getRoot()); } }
From source file:org.openhab.habdroid.ui.OpenHABWidgetAdapter.java
@SuppressWarnings("deprecation") @Override//from ww w.j a v a 2 s . c om public View getView(int position, View convertView, ViewGroup parent) { /* TODO: This definitely needs some huge refactoring */ final RelativeLayout widgetView; TextView labelTextView; TextView valueTextView; int widgetLayout; String[] splitString; OpenHABWidget openHABWidget = getItem(position); int screenWidth = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay().getWidth(); switch (this.getItemViewType(position)) { case TYPE_FRAME: widgetLayout = R.layout.openhabwidgetlist_frameitem; break; case TYPE_GROUP: widgetLayout = R.layout.openhabwidgetlist_groupitem; break; case TYPE_SECTIONSWITCH: widgetLayout = R.layout.openhabwidgetlist_sectionswitchitem; break; case TYPE_SWITCH: widgetLayout = R.layout.openhabwidgetlist_switchitem; break; case TYPE_ROLLERSHUTTER: widgetLayout = R.layout.openhabwidgetlist_rollershutteritem; break; case TYPE_TEXT: widgetLayout = R.layout.openhabwidgetlist_textitem; break; case TYPE_SLIDER: widgetLayout = R.layout.openhabwidgetlist_slideritem; break; case TYPE_IMAGE: widgetLayout = R.layout.openhabwidgetlist_imageitem; break; case TYPE_SELECTION: widgetLayout = R.layout.openhabwidgetlist_selectionitem; break; case TYPE_SETPOINT: widgetLayout = R.layout.openhabwidgetlist_setpointitem; break; case TYPE_CHART: widgetLayout = R.layout.openhabwidgetlist_chartitem; break; case TYPE_VIDEO: widgetLayout = R.layout.openhabwidgetlist_videoitem; break; case TYPE_VIDEO_MJPEG: widgetLayout = R.layout.openhabwidgetlist_videomjpegitem; break; case TYPE_WEB: widgetLayout = R.layout.openhabwidgetlist_webitem; break; case TYPE_COLOR: widgetLayout = R.layout.openhabwidgetlist_coloritem; break; default: widgetLayout = R.layout.openhabwidgetlist_genericitem; break; } if (convertView == null) { widgetView = new RelativeLayout(getContext()); String inflater = Context.LAYOUT_INFLATER_SERVICE; LayoutInflater vi; vi = (LayoutInflater) getContext().getSystemService(inflater); vi.inflate(widgetLayout, widgetView, true); } else { widgetView = (RelativeLayout) convertView; } // Process the colour attributes Integer iconColor = openHABWidget.getIconColor(); Integer labelColor = openHABWidget.getLabelColor(); Integer valueColor = openHABWidget.getValueColor(); // Process widgets icon image MySmartImageView widgetImage = (MySmartImageView) widgetView.findViewById(R.id.widgetimage); // Some of widgets, for example Frame doesnt' have an icon, so... if (widgetImage != null) { if (openHABWidget.getIcon() != null) { // This is needed to escape possible spaces and everything according to rfc2396 String iconUrl = openHABBaseUrl + "images/" + Uri.encode(openHABWidget.getIcon() + ".png"); // Log.d(TAG, "Will try to load icon from " + iconUrl); // Now set image URL widgetImage.setImageUrl(iconUrl, R.drawable.blank_icon, openHABUsername, openHABPassword); if (iconColor != null) widgetImage.setColorFilter(iconColor); else widgetImage.clearColorFilter(); } } TextView defaultTextView = new TextView(widgetView.getContext()); // Get TextView for widget label and set it's color labelTextView = (TextView) widgetView.findViewById(R.id.widgetlabel); // Change label color only for non-frame widgets if (labelColor != null && labelTextView != null && this.getItemViewType(position) != TYPE_FRAME) { Log.d(TAG, String.format("Setting label color to %d", labelColor)); labelTextView.setTextColor(labelColor); } else if (labelTextView != null && this.getItemViewType(position) != TYPE_FRAME) labelTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor()); // Get TextView for widget value and set it's color valueTextView = (TextView) widgetView.findViewById(R.id.widgetvalue); if (valueColor != null && valueTextView != null) { Log.d(TAG, String.format("Setting value color to %d", valueColor)); valueTextView.setTextColor(valueColor); } else if (valueTextView != null) valueTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor()); defaultTextView = null; switch (getItemViewType(position)) { case TYPE_FRAME: if (labelTextView != null) { labelTextView.setText(openHABWidget.getLabel()); if (valueColor != null) labelTextView.setTextColor(valueColor); } widgetView.setClickable(false); if (openHABWidget.getLabel().length() > 0) { // hide empty frames widgetView.setVisibility(View.VISIBLE); labelTextView.setVisibility(View.VISIBLE); } else { widgetView.setVisibility(View.GONE); labelTextView.setVisibility(View.GONE); } break; case TYPE_GROUP: if (labelTextView != null && valueTextView != null) { splitString = openHABWidget.getLabel().split("\\[|\\]"); labelTextView.setText(splitString[0]); if (splitString.length > 1) { // We have some value valueTextView.setText(splitString[1]); } else { // This is needed to clean up cached TextViews valueTextView.setText(""); } } break; case TYPE_SECTIONSWITCH: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) labelTextView.setText(splitString[0]); if (splitString.length > 1 && valueTextView != null) { // We have some value valueTextView.setText(splitString[1]); } else { // This is needed to clean up cached TextViews valueTextView.setText(""); } RadioGroup sectionSwitchRadioGroup = (RadioGroup) widgetView.findViewById(R.id.sectionswitchradiogroup); // As we create buttons in this radio in runtime, we need to remove all // exiting buttons first sectionSwitchRadioGroup.removeAllViews(); sectionSwitchRadioGroup.setTag(openHABWidget); Iterator<OpenHABWidgetMapping> sectionMappingIterator = openHABWidget.getMappings().iterator(); while (sectionMappingIterator.hasNext()) { OpenHABWidgetMapping widgetMapping = sectionMappingIterator.next(); SegmentedControlButton segmentedControlButton = (SegmentedControlButton) LayoutInflater .from(sectionSwitchRadioGroup.getContext()) .inflate(R.layout.openhabwidgetlist_sectionswitchitem_button, sectionSwitchRadioGroup, false); segmentedControlButton.setText(widgetMapping.getLabel()); segmentedControlButton.setTag(widgetMapping.getCommand()); if (openHABWidget.getItem() != null && widgetMapping.getCommand() != null) { if (widgetMapping.getCommand().equals(openHABWidget.getItem().getState())) { segmentedControlButton.setChecked(true); } else { segmentedControlButton.setChecked(false); } } else { segmentedControlButton.setChecked(false); } segmentedControlButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Log.i(TAG, "Button clicked"); RadioGroup group = (RadioGroup) view.getParent(); if (group.getTag() != null) { OpenHABWidget radioWidget = (OpenHABWidget) group.getTag(); SegmentedControlButton selectedButton = (SegmentedControlButton) view; if (selectedButton.getTag() != null) { sendItemCommand(radioWidget.getItem(), (String) selectedButton.getTag()); } } } }); sectionSwitchRadioGroup.addView(segmentedControlButton); } sectionSwitchRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { OpenHABWidget radioWidget = (OpenHABWidget) group.getTag(); SegmentedControlButton selectedButton = (SegmentedControlButton) group.findViewById(checkedId); if (selectedButton != null) { Log.d(TAG, "Selected " + selectedButton.getText()); Log.d(TAG, "Command = " + (String) selectedButton.getTag()); // radioWidget.getItem().sendCommand((String)selectedButton.getTag()); sendItemCommand(radioWidget.getItem(), (String) selectedButton.getTag()); } } }); break; case TYPE_SWITCH: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); SwitchCompat switchSwitch = (SwitchCompat) widgetView.findViewById(R.id.switchswitch); if (openHABWidget.hasItem()) { if (openHABWidget.getItem().getStateAsBoolean()) { switchSwitch.setChecked(true); } else { switchSwitch.setChecked(false); } } switchSwitch.setTag(openHABWidget.getItem()); switchSwitch.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { SwitchCompat switchSwitch = (SwitchCompat) v; OpenHABItem linkedItem = (OpenHABItem) switchSwitch.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) if (!switchSwitch.isChecked()) { sendItemCommand(linkedItem, "ON"); } else { sendItemCommand(linkedItem, "OFF"); } return false; } }); break; case TYPE_COLOR: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); ImageButton colorUpButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_up); ImageButton colorDownButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_down); ImageButton colorColorButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_color); colorUpButton.setTag(openHABWidget.getItem()); colorDownButton.setTag(openHABWidget.getItem()); colorColorButton.setTag(openHABWidget.getItem()); colorUpButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton colorButton = (ImageButton) v; OpenHABItem colorItem = (OpenHABItem) colorButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(colorItem, "ON"); return false; } }); colorDownButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton colorButton = (ImageButton) v; OpenHABItem colorItem = (OpenHABItem) colorButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(colorItem, "OFF"); return false; } }); colorColorButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton colorButton = (ImageButton) v; OpenHABItem colorItem = (OpenHABItem) colorButton.getTag(); if (colorItem != null) { if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { Log.d(TAG, "Time to launch color picker!"); ColorPickerDialog colorDialog = new ColorPickerDialog(widgetView.getContext(), new OnColorChangedListener() { public void colorChanged(float[] hsv, View v) { Log.d(TAG, "New color HSV = " + hsv[0] + ", " + hsv[1] + ", " + hsv[2]); String newColor = String.valueOf(hsv[0]) + "," + String.valueOf(hsv[1] * 100) + "," + String.valueOf(hsv[2] * 100); OpenHABItem colorItem = (OpenHABItem) v.getTag(); sendItemCommand(colorItem, newColor); } }, colorItem.getStateAsHSV()); colorDialog.setTag(colorItem); colorDialog.show(); } } return false; } }); break; case TYPE_ROLLERSHUTTER: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); ImageButton rollershutterUpButton = (ImageButton) widgetView.findViewById(R.id.rollershutterbutton_up); ImageButton rollershutterStopButton = (ImageButton) widgetView .findViewById(R.id.rollershutterbutton_stop); ImageButton rollershutterDownButton = (ImageButton) widgetView .findViewById(R.id.rollershutterbutton_down); rollershutterUpButton.setTag(openHABWidget.getItem()); rollershutterStopButton.setTag(openHABWidget.getItem()); rollershutterDownButton.setTag(openHABWidget.getItem()); rollershutterUpButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton rollershutterButton = (ImageButton) v; OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem, "UP"); return false; } }); rollershutterStopButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton rollershutterButton = (ImageButton) v; OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem, "STOP"); return false; } }); rollershutterDownButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton rollershutterButton = (ImageButton) v; OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem, "DOWN"); return false; } }); break; case TYPE_TEXT: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) if (splitString.length > 0) { labelTextView.setText(splitString[0]); } else { labelTextView.setText(openHABWidget.getLabel()); } if (valueTextView != null) if (splitString.length > 1) { // If value is not empty, show TextView valueTextView.setVisibility(View.VISIBLE); valueTextView.setText(splitString[1]); } else { // If value is empty, hide TextView to fix vertical alignment of label valueTextView.setVisibility(View.GONE); valueTextView.setText(""); } break; case TYPE_SLIDER: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) labelTextView.setText(splitString[0]); SeekBar sliderSeekBar = (SeekBar) widgetView.findViewById(R.id.sliderseekbar); if (openHABWidget.hasItem()) { sliderSeekBar.setTag(openHABWidget.getItem()); sliderSeekBar.setProgress(openHABWidget.getItem().getStateAsFloat().intValue()); sliderSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } public void onStartTrackingTouch(SeekBar seekBar) { Log.d(TAG, "onStartTrackingTouch position = " + seekBar.getProgress()); } public void onStopTrackingTouch(SeekBar seekBar) { Log.d(TAG, "onStopTrackingTouch position = " + seekBar.getProgress()); OpenHABItem sliderItem = (OpenHABItem) seekBar.getTag(); // sliderItem.sendCommand(String.valueOf(seekBar.getProgress())); if (sliderItem != null && seekBar != null) sendItemCommand(sliderItem, String.valueOf(seekBar.getProgress())); } }); if (volumeUpWidget == null) { volumeUpWidget = sliderSeekBar; volumeDownWidget = sliderSeekBar; } } break; case TYPE_IMAGE: MySmartImageView imageImage = (MySmartImageView) widgetView.findViewById(R.id.imageimage); imageImage.setImageUrl(ensureAbsoluteURL(openHABBaseUrl, openHABWidget.getUrl()), false, openHABUsername, openHABPassword); // ViewGroup.LayoutParams imageLayoutParams = imageImage.getLayoutParams(); // float imageRatio = imageImage.getDrawable().getIntrinsicWidth()/imageImage.getDrawable().getIntrinsicHeight(); // imageLayoutParams.height = (int) (screenWidth/imageRatio); // imageImage.setLayoutParams(imageLayoutParams); if (openHABWidget.getRefresh() > 0) { imageImage.setRefreshRate(openHABWidget.getRefresh()); refreshImageList.add(imageImage); } break; case TYPE_CHART: MySmartImageView chartImage = (MySmartImageView) widgetView.findViewById(R.id.chartimage); //Always clear the drawable so no images from recycled views appear chartImage.setImageDrawable(null); OpenHABItem chartItem = openHABWidget.getItem(); Random random = new Random(); String chartUrl = ""; if (chartItem != null) { if (chartItem.getType().equals("GroupItem")) { chartUrl = openHABBaseUrl + "chart?groups=" + chartItem.getName() + "&period=" + openHABWidget.getPeriod() + "&random=" + String.valueOf(random.nextInt()); } else { chartUrl = openHABBaseUrl + "chart?items=" + chartItem.getName() + "&period=" + openHABWidget.getPeriod() + "&random=" + String.valueOf(random.nextInt()); } if (openHABWidget.getService() != null && openHABWidget.getService().length() > 0) { chartUrl += "&service=" + openHABWidget.getService(); } } Log.d(TAG, "Chart url = " + chartUrl); if (chartImage == null) Log.e(TAG, "chartImage == null !!!"); ViewGroup.LayoutParams chartLayoutParams = chartImage.getLayoutParams(); chartLayoutParams.height = (int) (screenWidth / 2); chartImage.setLayoutParams(chartLayoutParams); chartUrl += "&w=" + String.valueOf(screenWidth); chartUrl += "&h=" + String.valueOf(screenWidth / 2); chartImage.setImageUrl(chartUrl, false, openHABUsername, openHABPassword); // TODO: This is quite dirty fix to make charts look full screen width on all displays if (openHABWidget.getRefresh() > 0) { chartImage.setRefreshRate(openHABWidget.getRefresh()); refreshImageList.add(chartImage); } Log.d(TAG, "chart size = " + chartLayoutParams.width + " " + chartLayoutParams.height); break; case TYPE_VIDEO: VideoView videoVideo = (VideoView) widgetView.findViewById(R.id.videovideo); Log.d(TAG, "Opening video at " + openHABWidget.getUrl()); // TODO: This is quite dirty fix to make video look maximum available size on all screens WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); ViewGroup.LayoutParams videoLayoutParams = videoVideo.getLayoutParams(); videoLayoutParams.height = (int) (wm.getDefaultDisplay().getWidth() / 1.77); videoVideo.setLayoutParams(videoLayoutParams); // We don't have any event handler to know if the VideoView is on the screen // so we manage an array of all videos to stop them when user leaves the page if (!videoWidgetList.contains(videoVideo)) videoWidgetList.add(videoVideo); // Start video if (!videoVideo.isPlaying()) { videoVideo.setVideoURI(Uri.parse(openHABWidget.getUrl())); videoVideo.start(); } Log.d(TAG, "Video height is " + videoVideo.getHeight()); break; case TYPE_VIDEO_MJPEG: Log.d(TAG, "Video is mjpeg"); ImageView mjpegImage = (ImageView) widgetView.findViewById(R.id.mjpegimage); MjpegStreamer mjpegStreamer = new MjpegStreamer(openHABWidget.getUrl(), this.openHABUsername, this.openHABPassword, this.getContext()); mjpegStreamer.setTargetImageView(mjpegImage); mjpegStreamer.start(); if (!mjpegWidgetList.contains(mjpegStreamer)) mjpegWidgetList.add(mjpegStreamer); break; case TYPE_WEB: WebView webWeb = (WebView) widgetView.findViewById(R.id.webweb); if (openHABWidget.getHeight() > 0) { ViewGroup.LayoutParams webLayoutParams = webWeb.getLayoutParams(); webLayoutParams.height = openHABWidget.getHeight() * 80; webWeb.setLayoutParams(webLayoutParams); } webWeb.setWebViewClient( new AnchorWebViewClient(openHABWidget.getUrl(), this.openHABUsername, this.openHABPassword)); webWeb.getSettings().setJavaScriptEnabled(true); webWeb.loadUrl(openHABWidget.getUrl()); break; case TYPE_SELECTION: int spinnerSelectedIndex = -1; if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); final Spinner selectionSpinner = (Spinner) widgetView.findViewById(R.id.selectionspinner); selectionSpinner.setOnItemSelectedListener(null); ArrayList<String> spinnerArray = new ArrayList<String>(); Iterator<OpenHABWidgetMapping> mappingIterator = openHABWidget.getMappings().iterator(); while (mappingIterator.hasNext()) { OpenHABWidgetMapping openHABWidgetMapping = mappingIterator.next(); spinnerArray.add(openHABWidgetMapping.getLabel()); if (openHABWidgetMapping.getCommand() != null && openHABWidget.getItem() != null) if (openHABWidgetMapping.getCommand().equals(openHABWidget.getItem().getState())) { spinnerSelectedIndex = spinnerArray.size() - 1; } } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this.getContext(), android.R.layout.simple_spinner_item, spinnerArray); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); selectionSpinner.setAdapter(spinnerAdapter); selectionSpinner.setTag(openHABWidget); if (spinnerSelectedIndex >= 0) { Log.d(TAG, "Setting spinner selected index to " + String.valueOf(spinnerSelectedIndex)); selectionSpinner.setSelection(spinnerSelectedIndex); } else { Log.d(TAG, "Not setting spinner selected index"); } selectionSpinner.post(new Runnable() { @Override public void run() { selectionSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int index, long id) { Log.d(TAG, "Spinner item click on index " + index); Spinner spinner = (Spinner) parent; String selectedLabel = (String) spinner.getAdapter().getItem(index); Log.d(TAG, "Spinner onItemSelected selected label = " + selectedLabel); OpenHABWidget openHABWidget = (OpenHABWidget) parent.getTag(); if (openHABWidget != null) { Log.d(TAG, "Label selected = " + openHABWidget.getMapping(index).getLabel()); Iterator<OpenHABWidgetMapping> mappingIterator = openHABWidget.getMappings() .iterator(); while (mappingIterator.hasNext()) { OpenHABWidgetMapping openHABWidgetMapping = mappingIterator.next(); if (openHABWidgetMapping.getLabel().equals(selectedLabel)) { Log.d(TAG, "Spinner onItemSelected found match with " + openHABWidgetMapping.getCommand()); if (openHABWidget.getItem() != null && openHABWidget.getItem().getState() != null) { // Only send the command for selection of selected command will change the state if (!openHABWidget.getItem().getState() .equals(openHABWidgetMapping.getCommand())) { Log.d(TAG, "Spinner onItemSelected selected label command != current item state"); sendItemCommand(openHABWidget.getItem(), openHABWidgetMapping.getCommand()); } } else if (openHABWidget.getItem() != null && openHABWidget.getItem().getState() == null) { Log.d(TAG, "Spinner onItemSelected selected label command and state == null"); sendItemCommand(openHABWidget.getItem(), openHABWidgetMapping.getCommand()); } } } } // if (!openHABWidget.getItem().getState().equals(openHABWidget.getMapping(index).getCommand())) // sendItemCommand(openHABWidget.getItem(), // openHABWidget.getMapping(index).getCommand()); } public void onNothingSelected(AdapterView<?> arg0) { } }); } }); break; case TYPE_SETPOINT: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) labelTextView.setText(splitString[0]); if (valueTextView != null) if (splitString.length > 1) { // If value is not empty, show TextView valueTextView.setVisibility(View.VISIBLE); valueTextView.setText(splitString[1]); } Button setPointMinusButton = (Button) widgetView.findViewById(R.id.setpointbutton_minus); Button setPointPlusButton = (Button) widgetView.findViewById(R.id.setpointbutton_plus); setPointMinusButton.setTag(openHABWidget); setPointPlusButton.setTag(openHABWidget); setPointMinusButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Log.d(TAG, "Minus"); OpenHABWidget setPointWidget = (OpenHABWidget) v.getTag(); float currentValue = setPointWidget.getItem().getStateAsFloat(); currentValue = currentValue - setPointWidget.getStep(); if (currentValue < setPointWidget.getMinValue()) currentValue = setPointWidget.getMinValue(); if (currentValue > setPointWidget.getMaxValue()) currentValue = setPointWidget.getMaxValue(); sendItemCommand(setPointWidget.getItem(), String.valueOf(currentValue)); } }); setPointPlusButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Log.d(TAG, "Plus"); OpenHABWidget setPointWidget = (OpenHABWidget) v.getTag(); float currentValue = setPointWidget.getItem().getStateAsFloat(); currentValue = currentValue + setPointWidget.getStep(); if (currentValue < setPointWidget.getMinValue()) currentValue = setPointWidget.getMinValue(); if (currentValue > setPointWidget.getMaxValue()) currentValue = setPointWidget.getMaxValue(); sendItemCommand(setPointWidget.getItem(), String.valueOf(currentValue)); } }); if (volumeUpWidget == null) { volumeUpWidget = setPointPlusButton; volumeDownWidget = setPointMinusButton; } break; default: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); break; } LinearLayout dividerLayout = (LinearLayout) widgetView.findViewById(R.id.listdivider); if (dividerLayout != null) { if (position < this.getCount() - 1) { if (this.getItemViewType(position + 1) == TYPE_FRAME) { dividerLayout.setVisibility(View.GONE); // hide dividers before frame widgets } else { dividerLayout.setVisibility(View.VISIBLE); // show dividers for all others } } else { // last widget in the list, hide divider dividerLayout.setVisibility(View.GONE); } } return widgetView; }
From source file:com.github.riotopsys.shoppinglist.activity.ShoppingListPreview.java
private void addNewList() { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.add_list_dialog, null); new AlertDialog.Builder(this).setTitle(R.string.add_list_dialog_title).setView(view) .setPositiveButton(R.string.done, new OnClickListener() { @Override/* w ww. j av a2 s.com*/ public void onClick(DialogInterface dialog, int which) { EditText editText = (EditText) ((AlertDialog) dialog).findViewById(R.id.list_name); String text = editText.getText().toString(); if (!text.equals("")) { ShoppingList shoppingList = mShoppingListCollection .createItem(ShoppingListPreview.this); shoppingList.setName(ShoppingListPreview.this, text); mShoppingListCollectionAdapter.notifyDataSetChanged(editText.getContext()); mViewPager.setCurrentItem(mShoppingListCollectionAdapter.getPositionOf(shoppingList), true); } else { Toast.makeText(getBaseContext(), R.string.name_reqd, Toast.LENGTH_LONG).show(); } } }).setNegativeButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create().show(); }
From source file:com.github.omadahealth.slidepager.lib.views.SlideView.java
/** * Bind the view and init the listeners and attrs * * @param context//from w ww.j av a2s .c o m */ private void init(Context context, TypedArray attributes, int pagePosition, OnSlidePageChangeListener pageListener) { if (!isInEditMode()) { this.mPagePosition = pagePosition; this.mUserPageListener = pageListener; this.mAttributes = attributes; LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mBinding = DataBindingUtil.inflate(inflater, R.layout.view_slide, this, true); mAnimationSet = new AnimatorSet(); injectViews(); setListeners(); loadStyledAttributes(attributes); } }
From source file:com.achep.base.ui.DialogBuilder.java
private View createSkeleton() { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout rootLayout = (LinearLayout) inflater.inflate(R.layout.dialog_main_skeleton, new FrameLayout(mContext), false); TextView titleView = (TextView) rootLayout.findViewById(R.id.title); if (Device.hasLollipopApi()) { // The dividers are quite ugly with material design. rootLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE); }/* www . ja v a 2s. c o m*/ if (mTitleText == null && mIcon == null) { rootLayout.removeView(titleView); } else { if (mTitleText != null) titleView.setText(mTitleText); if (mIcon != null) titleView.setCompoundDrawablesWithIntrinsicBounds(mIcon, null, null, null); } return rootLayout; }
From source file:com.irccloud.android.fragment.ServerReorderFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Context ctx = getActivity();/* ww w. j a v a 2 s.c o m*/ if (ctx == null) return null; LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.reorderservers, null); init(v); listView.setCacheColorHint(0xfff3f3f3); Dialog d = new AlertDialog.Builder(ctx).setTitle("Connections").setView(v) .setNegativeButton("Done", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { NetworkConnection.getInstance().removeHandler(ServerReorderFragment.this); } }).create(); return d; }
From source file:com.radicaldynamic.groupinform.application.Collect.java
public void showCustomToast(String message) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.toast_view, null); // Set the text in the view TextView tv = (TextView) view.findViewById(R.id.message); tv.setText(message);/*from ww w . j a v a 2 s. c o m*/ Toast t = new Toast(this); t.setView(view); t.setDuration(Toast.LENGTH_SHORT); t.setGravity(Gravity.CENTER, 0, 0); t.show(); }
From source file:com.amaze.filemanager.fragments.preference_fragments.Preffrag.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceUtils.reset();//from w ww. ja v a 2 s . c o m // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences); sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); final int th1 = Integer.parseInt(sharedPref.getString("theme", "0")); theme = th1 == 2 ? PreferenceUtils.hourOfDay() : th1; findPreference("donate").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { ((com.amaze.filemanager.activities.Preferences) getActivity()).donate(); return false; } }); findPreference("columns").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { final String[] sort = getResources().getStringArray(R.array.columns); MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity()); if (theme == 1) a.theme(Theme.DARK); a.title(R.string.gridcolumnno); int current = Integer.parseInt(sharedPref.getString("columns", "-1")); current = current == -1 ? 0 : current; if (current != 0) current = current - 1; a.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() { @Override public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { sharedPref.edit().putString("columns", "" + (which != 0 ? sort[which] : "" + -1)).commit(); dialog.dismiss(); return true; } }); a.build().show(); return true; } }); findPreference("theme").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { String[] sort = getResources().getStringArray(R.array.theme); int current = Integer.parseInt(sharedPref.getString("theme", "0")); MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity()); if (theme == 1) a.theme(Theme.DARK); a.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() { @Override public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { sharedPref.edit().putString("theme", "" + which).commit(); dialog.dismiss(); restartPC(getActivity()); return true; } }); a.title(R.string.theme); a.build().show(); return true; } }); findPreference("colors").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { ((com.amaze.filemanager.activities.Preferences) getActivity()).selectItem(1); return true; } }); final CheckBx rootmode = (CheckBx) findPreference("rootmode"); rootmode.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { boolean b = sharedPref.getBoolean("rootmode", false); if (b) { if (RootTools.isAccessGiven()) { rootmode.setChecked(true); } else { rootmode.setChecked(false); Toast.makeText(getActivity(), getResources().getString(R.string.rootfailure), Toast.LENGTH_LONG).show(); } } else { rootmode.setChecked(false); } return false; } }); // Authors Preference preference4 = (Preference) findPreference("authors"); preference4.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity()); skin = PreferenceUtils.getPrimaryColorString(sharedPref); int fab_skin = Color.parseColor(PreferenceUtils.getAccentString(sharedPref)); if (theme == 1) a.theme(Theme.DARK); a.positiveText(R.string.close); a.positiveColor(fab_skin); LayoutInflater layoutInflater = (LayoutInflater) getActivity() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = layoutInflater.inflate(R.layout.authors, null); a.customView(view, true); a.title(R.string.authors); a.callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog materialDialog) { materialDialog.cancel(); } @Override public void onNegative(MaterialDialog materialDialog) { } }); /*a.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.cancel(); } });*/ a.build().show(); final Intent intent = new Intent(Intent.ACTION_VIEW); TextView googlePlus1 = (TextView) view.findViewById(R.id.googlePlus1); googlePlus1.setTextColor(Color.parseColor(skin)); TextView googlePlus2 = (TextView) view.findViewById(R.id.googlePlus2); googlePlus2.setTextColor(Color.parseColor(skin)); TextView git1 = (TextView) view.findViewById(R.id.git1); git1.setTextColor(Color.parseColor(skin)); TextView git2 = (TextView) view.findViewById(R.id.git2); git2.setTextColor(Color.parseColor(skin)); googlePlus1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { intent.setData(Uri.parse("https://plus.google.com/u/0/110424067388738907251/")); startActivity(intent); } }); googlePlus2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { intent.setData(Uri.parse("https://plus.google.com/+VishalNehra/")); startActivity(intent); } }); git1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { intent.setData(Uri.parse("https://github.com/arpitkh96")); startActivity(intent); } }); git2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { intent.setData(Uri.parse("https://github.com/vishal0071")); startActivity(intent); } }); // icon credits TextView textView = (TextView) view.findViewById(R.id.icon_credits); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setLinksClickable(true); textView.setText(Html.fromHtml(getActivity().getString(R.string.icon_credits))); return false; } }); // Changelog Preference preference1 = (Preference) findPreference("changelog"); preference1.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity()); if (theme == 1) a.theme(Theme.DARK); a.title(R.string.changelog); a.content(Html.fromHtml(getActivity().getString(R.string.changelog_version_9) + getActivity().getString(R.string.changelog_change_9) + getActivity().getString(R.string.changelog_version_8) + getActivity().getString(R.string.changelog_change_8) + getActivity().getString(R.string.changelog_version_7) + getActivity().getString(R.string.changelog_change_7) + getActivity().getString(R.string.changelog_version_6) + getActivity().getString(R.string.changelog_change_6) + getActivity().getString(R.string.changelog_version_5) + getActivity().getString(R.string.changelog_change_5) + getActivity().getString(R.string.changelog_version_4) + getActivity().getString(R.string.changelog_change_4) + getActivity().getString(R.string.changelog_version_3) + getActivity().getString(R.string.changelog_change_3) + getActivity().getString(R.string.changelog_version_2) + getActivity().getString(R.string.changelog_change_2) + getActivity().getString(R.string.changelog_version_1) + getActivity().getString(R.string.changelog_change_1))); a.negativeText(R.string.close); a.positiveText(R.string.fullChangelog); int fab_skin = Color.parseColor(PreferenceUtils.getAccentString(sharedPref)); a.positiveColor(fab_skin); a.negativeColor(fab_skin); a.callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog materialDialog) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/arpitkh96/AmazeFileManager/commits/master")); startActivity(intent); } @Override public void onNegative(MaterialDialog materialDialog) { materialDialog.cancel(); } }).build().show(); return false; } }); // Open Source Licenses Preference preference2 = (Preference) findPreference("os"); //Defining dialog layout final Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Holo_Light_DialogWhenLarge_NoActionBar); //dialog.setTitle("Open-Source Licenses"); LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE); final View dialog_view = inflater.inflate(R.layout.open_source_licenses, null); dialog.setContentView(dialog_view); preference2.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { WebView wv = (WebView) dialog_view.findViewById(R.id.webView1); PreferenceUtils preferenceUtils = new PreferenceUtils(); wv.loadData(PreferenceUtils.LICENCE_TERMS, "text/html", null); dialog.show(); return false; } }); // Feedback Preference preference3 = (Preference) findPreference("feedback"); preference3.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "arpitkh96@gmail.com", null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback : Amaze File Manager"); Toast.makeText(getActivity(), getActivity().getFilesDir().getPath(), Toast.LENGTH_SHORT).show(); File f = new File(getActivity().getExternalFilesDir("internal"), "log.txt"); if (f.exists()) { emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); } startActivity(Intent.createChooser(emailIntent, getResources().getString(R.string.feedback))); return false; } }); // rate Preference preference5 = (Preference) findPreference("rate"); preference5.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent intent1 = new Intent(Intent.ACTION_VIEW); intent1.setData(Uri.parse("market://details?id=com.amaze.filemanager")); startActivity(intent1); return false; } }); // studio Preference studio = findPreference("studio"); studio.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { COUNT++; if (COUNT >= 5) { if (toast != null) toast.cancel(); toast = Toast.makeText(getActivity(), "Studio Mode : " + COUNT, Toast.LENGTH_SHORT); toast.show(); sharedPref.edit().putInt("studio", Integer.parseInt(Integer.toString(COUNT) + "000")).apply(); } else { sharedPref.edit().putInt("studio", 0).apply(); } return false; } }); // G+ gplus = (CheckBx) findPreference("plus_pic"); gplus.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (gplus.isChecked()) { boolean b = checkGplusPermission(); if (!b) requestGplusPermission(); } return false; } }); if (BuildConfig.IS_VERSION_FDROID) gplus.setEnabled(false); // Colored navigation bar }
From source file:com.orbar.pxdemo.ImageView.FivePXImageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(TAG, "onCreateView"); final View rootView = inflater.inflate(R.layout.fragment_five_px_image, container, false); getReusableViews(rootView);/*from ww w . j a v a 2s . c om*/ // Set the attributes for the custom ActionBar actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowCustomEnabled(true); actionBar.setDisplayShowTitleEnabled(false); // Set the placeholder until download finishes. actionBar.setIcon(R.drawable.ic_launcher); // get the ImageBean that was clicked Bundle bundle = this.getArguments(); mFiveZeroZeroImageBean = (FiveZeroZeroImageBean) bundle.getParcelable(ARG_IMAGE_BEAN); // Inflate the custom action bar layout LayoutInflater inflator = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View actionView = inflator.inflate(R.layout.actionbar_five_px_image, null); // set the title and user name in the action bar TextView imageTitle = (TextView) actionView.findViewById(R.id.image_title); TextView imageuserName = (TextView) actionView.findViewById(R.id.image_username); imageTitle.setText(mFiveZeroZeroImageBean.getName()); imageuserName.setText(mFiveZeroZeroImageBean.getUserBean().getUserName()); actionBar.setCustomView(actionView); // get reference to userAccountLayout in the action bar userAccountLayout = (RelativeLayout) actionView.findViewById(R.id.image_account_layout); // Download the user image in Extra Small size. No Picasso for this image. mDownloadUserImage = new DownloadUserImage(); mDownloadUserImage.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mFiveZeroZeroImageBean.getUserBean().getUserpicURL(USER_IMAGE_SIZE.LARGE)); // Setup the Sliding Panel layout mSlidingPaneLayout.setShadowDrawable(getResources().getDrawable(R.drawable.above_shadow)); mSlidingPaneLayout.setAnchorPoint(0.2f); mSlidingPaneLayout.setDragView(imageControlsLayout); mSlidingPaneLayout.setEnableDragViewTouchEvents(true); // Download the Image and put it into a zoom-able and pan-able imageview. ImageView mImageView = (ImageView) rootView.findViewById(R.id.image); // The MAGIC happens here! mAttacher = new PhotoViewAttacher(mImageView); Picasso.with(getActivity()) // .load(mFiveZeroZeroImageBean.getImageUrl(IMAGE_SIZE.ORIGINAL)) //.placeholder(image.getDrawable()) // Use the smaller image while downloading the higher resolution image .error(android.R.drawable.stat_notify_error) // The error image .into(mImageView, new Callback() { @Override public void onError() { } // When finished loading, update the attacher @Override public void onSuccess() { mAttacher.update(); } }); //mAttacher.setOnPhotoTapListener(new PhotoTapListener()); // Setup the comments ListView mCommentsAdapter = new CommentsAdapter(getActivity(), mFiveZeroZeroImageBean.getCommentBeans()); commentsListView.setAdapter(mCommentsAdapter); // set the comment count imageComments.setText(Integer.toString(mFiveZeroZeroImageBean.getCommentsCount())); imageLikes.setText(Integer.toString(mFiveZeroZeroImageBean.getVotesCount())); imageFavorites.setText(Integer.toString(mFiveZeroZeroImageBean.getFavoritesCount())); // get the last page number (we want to add pages in reverse order (newest first) pageNumber.set((int) Math.ceil(mFiveZeroZeroImageBean.getCommentsCount() / 20.0)); mFiveZeroZeroImageAPIBuilder = new FiveZeroZeroImageAPIBuilder().setPageNum(pageNumber.get()); mLoadCommentsList = new LoadCommentsList(getActivity(), mFiveZeroZeroImageAPIBuilder, mLoginManager, mFiveZeroZeroImageBean, loadingMore, stopLoadingData, pageNumber); mLoadCommentsList.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); mLoadImageDetailsList = new LoadImageDetailsList(getActivity(), mFiveZeroZeroImageAPIBuilder, mLoginManager, mFiveZeroZeroImageBean); mLoadImageDetailsList.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); return rootView; }
From source file:com.maxwen.wallpaper.board.fragments.dialogs.DirectoryChooserDialog.java
private ArrayAdapter<File> createListAdapter(List<File> items) { return new ArrayAdapter<File>(getActivity(), R.layout.folder_item, R.id.folder_name, items) { @Override/*w w w .j av a 2 s.c o m*/ public View getView(int position, View convertView, ViewGroup parent) { View item = null; if (convertView == null) { final LayoutInflater inflater = (LayoutInflater) getActivity() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); item = inflater.inflate(R.layout.folder_item, null); } else { item = convertView; } TextView tv = (TextView) item.findViewById(R.id.folder_name); File f = mSubDirs.get(position); tv.setText(f.getName()); if (f.isFile()) { tv.setTextColor(mTextColorDisabled); } else { tv.setTextColor(mTextColor); } return item; } }; }