List of usage examples for android.net Uri encode
public static String encode(String s)
From source file:com.android.exchange.service.EasServerConnection.java
private String makeUserString() { if (sDeviceId == null) { sDeviceId = new AccountServiceProxy(mContext).getDeviceId(); if (sDeviceId == null) { LogUtils.e(TAG, "Could not get device id, defaulting to '0'"); sDeviceId = "0"; }//from w w w .j a v a2 s. co m } return "&User=" + Uri.encode(mHostAuth.mLogin) + "&DeviceId=" + sDeviceId + "&DeviceType=" + DEVICE_TYPE; }
From source file:com.github.kanata3249.ffxieq.android.AtmaSelector.java
@Override public boolean onContextItemSelected(MenuItem item) { Atma food = getDAO().instantiateAtma(mLongClickingItemId); String name = food.getName(); Intent intent;//from w w w . j a v a 2 s .c o m if (food != null) { String[] urls = getResources().getStringArray(R.array.SearchURIs); String url; url = null; switch (item.getItemId()) { case R.id.WebSearch0: url = urls[0]; break; case R.id.WebSearch1: url = urls[1]; break; case R.id.WebSearch2: url = urls[2]; break; case R.id.WebSearch3: url = urls[3]; break; case R.id.WebSearch4: url = urls[4]; break; case R.id.WebSearch5: url = urls[5]; break; case R.id.WebSearch6: url = urls[6]; break; case R.id.WebSearch7: url = urls[7]; break; default: url = null; break; } if (url != null) { intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url + Uri.encode(name.split("\\+")[0]))); startActivity(intent); return true; } } return super.onContextItemSelected(item); }
From source file:com.windigo.RestApiMethodMetadata.java
/** * Convert given plain class to query parameters * for get requests//from w ww . j ava 2s. co m * * @param object * @return {@link String} of url encoded query params url * @throws IllegalAccessException * @throws IllegalArgumentException */ @SuppressWarnings("unchecked") private List<NameValuePair> parseQueryParamsWith(Object object) throws IllegalAccessException, IllegalArgumentException { Map<String, Object> fieldParams; try { //Checking if passed object is already a map fieldParams = (Map<String, Object>) object; } catch (ClassCastException cce) { Class<?> paramClass = object.getClass(); Field[] fields = paramClass.getDeclaredFields(); fieldParams = new HashMap<String, Object>(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; field.setAccessible(true); fieldParams.put(field.getName(), field.get(object)); } } List<NameValuePair> vals = new ArrayList<NameValuePair>(); for (Map.Entry<String, Object> queryParamEntry : fieldParams.entrySet()) { if (queryParamEntry.getValue() != null) { String value = Uri.encode(queryParamEntry.getValue().toString()); vals.add(new BasicNameValuePair(queryParamEntry.getKey(), value)); } } return vals; }
From source file:com.tapjoy.TapjoyConnectCore.java
/** * Constructs the generic URL parameters without an App ID. * This is the base method for generating the URL parameters. * Does NOT include://from w ww. j a va2 s .c o m * app_id (App ID) * publisher_user_id (publisher user ID) * referrer (for referral tracking) * verifier/timestamp * @return Generic URL parameters without app ID. */ private static String getParamsWithoutAppID() { String urlParams = ""; // Construct the url parameters. urlParams += TapjoyConstants.TJC_ANDROID_ID + "=" + androidID + "&"; // If this flag is set, then send sha2_udid instead of udid. if (getFlagValue(TapjoyConnectFlag.SHA_2_UDID) != null && getFlagValue(TapjoyConnectFlag.SHA_2_UDID).equals("true")) { urlParams += TapjoyConstants.TJC_SHA2_DEVICE_ID_NAME + "=" + Uri.encode(sha2DeviceID) + "&"; } else { urlParams += TapjoyConstants.TJC_DEVICE_ID_NAME + "=" + Uri.encode(deviceID) + "&"; } // Mac address. if (macAddress != null && macAddress.length() > 0) { // Only send SHA-1 mac_address. //urlParams += TapjoyConstants.TJC_DEVICE_MAC_ADDRESS + "=" + Uri.encode(macAddress) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_SHA1_MAC_ADDRESS + "=" + Uri.encode(sha1MacAddress) + "&"; } // Serial ID. if (serialID != null && serialID.length() > 0) { urlParams += TapjoyConstants.TJC_DEVICE_SERIAL_ID + "=" + Uri.encode(serialID) + "&"; } urlParams += TapjoyConstants.TJC_DEVICE_NAME + "=" + Uri.encode(deviceModel) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_MANUFACTURER + "=" + Uri.encode(deviceManufacturer) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_TYPE_NAME + "=" + Uri.encode(deviceType) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_OS_VERSION_NAME + "=" + Uri.encode(deviceOSVersion) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_COUNTRY_CODE + "=" + Uri.encode(deviceCountryCode) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_LANGUAGE + "=" + Uri.encode(deviceLanguage) + "&"; urlParams += TapjoyConstants.TJC_APP_VERSION_NAME + "=" + Uri.encode(appVersion) + "&"; urlParams += TapjoyConstants.TJC_CONNECT_LIBRARY_VERSION_NAME + "=" + Uri.encode(libraryVersion) + "&"; urlParams += TapjoyConstants.TJC_PLATFORM + "=" + Uri.encode(platformName) + "&"; // Virtual Currency Multiplier urlParams += TapjoyConstants.TJC_CURRENCY_MULTIPLIER + "=" + Uri.encode(Float.toString(currencyMultiplier)); // Add carrier name. if (carrierName.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_CARRIER_NAME + "=" + Uri.encode(carrierName); } // Carrier country code. if (carrierCountryCode.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_CARRIER_COUNTRY_CODE + "=" + Uri.encode(carrierCountryCode); } // MCC if (mobileCountryCode.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_MOBILE_COUNTRY_CODE + "=" + Uri.encode(mobileCountryCode); } // MNC if (mobileNetworkCode.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_MOBILE_NETWORK_CODE + "=" + Uri.encode(mobileNetworkCode); } // Add device density and screen layout size. if (deviceScreenDensity.length() > 0 && deviceScreenLayoutSize.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_DEVICE_SCREEN_DENSITY + "=" + Uri.encode(deviceScreenDensity) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_SCREEN_LAYOUT_SIZE + "=" + Uri.encode(deviceScreenLayoutSize); } // Connection type connectionType = getConnectionType(); if (connectionType.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_CONNECTION_TYPE + "=" + Uri.encode(connectionType); } // Plugin if (plugin.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_PLUGIN + "=" + Uri.encode(plugin); } // SDK type. if (sdkType.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_SDK_TYPE + "=" + Uri.encode(sdkType); } // App store/market name. if (marketName.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_MARKET_NAME + "=" + Uri.encode(marketName); } return urlParams; }
From source file:com.appnexus.opensdk.ANJAMImplementation.java
private static void loadResult(WebView webView, String cb, List<BasicNameValuePair> paramsList) { StringBuilder params = new StringBuilder(); params.append("cb=").append(cb != null ? cb : "-1"); if (paramsList != null) { for (BasicNameValuePair pair : paramsList) { if ((pair.getName() != null) && (pair.getValue() != null)) { params.append("&").append(pair.getName()).append("=").append(Uri.encode(pair.getValue())); }//from ww w. ja v a 2 s . c om } } String url = String.format("javascript:window.sdkjs.client.result(\"%s\")", params.toString()); webView.loadUrl(url); }
From source file:it.rainbowbreeze.keepmoving.ui.TimetableActivity.java
@Override public void sendToWear(int fragmentPos) { int notificationId = 001; // Build intent for notification content Intent viewIntent = new Intent(this, TimetableActivity.class); viewIntent.putExtra(EXTRA_EVENT_ID, 100); PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, viewIntent, 0); Intent mapIntent = new Intent(Intent.ACTION_VIEW); Uri geoUri = Uri.parse("geo:0,0?q=" + Uri.encode("Piazza Duomo Milano")); mapIntent.setData(geoUri);/*from w w w.j av a 2s . com*/ PendingIntent mapPendingIntent = PendingIntent.getActivity(this, 0, mapIntent, 0); NotificationCompat.Action mapAction = new NotificationCompat.Action(android.R.drawable.ic_menu_delete, getString(R.string.common_map_title), mapPendingIntent); String notificationGroup = "aaa_groups"; Bitmap bmpSeaPanorama = BitmapFactory.decodeResource(getResources(), R.drawable.seapanorama); Bitmap bmpMountainsPanorama = BitmapFactory.decodeResource(getResources(), R.drawable.mountainspanorama); // Specify the 'big view' content to display the long // event description that may not fit the normal content text. NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle() .setBigContentTitle("Titolo del bigcontent").bigText( "Questo e' il testo davvero lungo della notifica, penso che potresti vederlo tutto solo se apri la notifica a tutto schermo"); Notification secondPageNotification = new NotificationCompat.Builder(this).setStyle(bigStyle).build(); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle() .setBigContentTitle("Titolo inboxStyle").setSummaryText("Breve summary test") .addLine("Nuova riga di testo 1").addLine("Nuova riga di testo 2"); Notification thirdPageNotification = new NotificationCompat.Builder(this).setStyle(inboxStyle).build(); NotificationCompat.BigPictureStyle pictureStyle = new NotificationCompat.BigPictureStyle() .bigPicture(bmpMountainsPanorama) //on Wear, it doesn't work, use WearExtender.setBackground or Notification.setLargeIcon .setSummaryText("Summary text").setBigContentTitle("Content Title"); Notification forthPageNotification = new NotificationCompat.Builder(this).setStyle(pictureStyle).build(); //setLargeIcon: put in every stacked notification to change background on wear or add it // to stack summary so all wear stacked notifications get it. Or call setBackground on // wear extender for the stack summary notification (see tutorial docs) Notification stack1Notification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.type_tube) .setContentTitle("Stack 1 map") .setContentText("See the map, plus text of first stacked notification. Could be very long!") .setGroup(notificationGroup).setSortKey("1").addAction(mapAction).build(); Notification stack2Notification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.type_tube) .setContentTitle("Stack 2") .setContentText( "This time you're reading the second log text of the stacked notification. Again, it could be very long!") .setGroup(notificationGroup).setSortKey("2").build(); Notification stackSummary = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.type_tube) //.setLargeIcon(bmpSeaPanorama) .setContentTitle("New stack notifications in your wear") .setContentText("Watch your wear for some stack notifications") .setStyle(new NotificationCompat.InboxStyle().addLine("Stack notification 1") .addLine("Stack notification 2").setBigContentTitle("2 stack notifications") .setSummaryText("Open your wear")) .setGroup(notificationGroup).setGroupSummary(true).build(); WearableExtender extender = new WearableExtender().addAction(mapAction).addPage(secondPageNotification) .addPage(thirdPageNotification).addPage(forthPageNotification).setHintHideIcon(true) .setBackground(bmpMountainsPanorama); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(android.R.drawable.ic_dialog_info).setLargeIcon(bmpSeaPanorama).setStyle(pictureStyle) .setAutoCancel(true).setContentTitle("Notifica di prova") .setContentText("Testo della notifica di prova").setContentIntent(viewPendingIntent) .extend(extender); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); // Build the notification and issues it with notification manager. notificationManager.notify(notificationId + 100, notificationBuilder.build()); //for stack notifications // notificationManager.notify(notificationId, stack1Notification); //for wear // notificationManager.notify(notificationId+1, stack2Notification); //for wear // notificationManager.notify(notificationId+2, stackSummary); //for device /* GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle connectionHint) { mLogManager.d(LOG_TAG, "onConnected: " + connectionHint); // Now you can use the data layer API } @Override public void onConnectionSuspended(int cause) { mLogManager.d(LOG_TAG, "onConnectionSuspended: " + cause); } }) .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult result) { mLogManager.d(LOG_TAG, "onConnectionFailed: " + result); } }) .addApi(Wearable.API) .build(); PutDataMapRequest dataMap = PutDataMapRequest.create("/count"); dataMap.getDataMap().putInt(COUNT_KEY, count++); PutDataRequest request = dataMap.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi .putDataItem(mGoogleApiClient, request); */ }
From source file:com.andrew.apollo.ui.activities.SearchActivity.java
/** * {@inheritDoc}//from w w w.j ava 2 s.co m */ @Override public Loader<Cursor> onCreateLoader(final int id, final Bundle args) { final Uri uri = Uri.parse("content://media/external/audio/search/fancy/" + Uri.encode(mFilterString)); final String[] projection = new String[] { BaseColumns._ID, MediaStore.Audio.Media.MIME_TYPE, MediaStore.Audio.Artists.ARTIST, MediaStore.Audio.Albums.ALBUM, MediaStore.Audio.Media.TITLE, "data1", "data2" }; return new CursorLoader(this, uri, projection, null, null, null); }
From source file:org.openhab.habdroid.ui.OpenHABWidgetAdapter.java
@SuppressWarnings("deprecation") @Override// w w w . j ava2 s . c o m 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.kupriyanov.android.apps.translate.service.WorkerThread.java
/*** * [Optional] doTranslateTask time to complete and repeatedly updates the UI. * //from w w w . j a v a2s . c o m * @param bundle * Bundle of extra information. */ private void doTranslateTask(final Bundle bundle) { if (bundle != null) { String pageContent = ""; Bundle outBundle = new Bundle(); try { prepareUserAgent(mMyService.getApplicationContext()); /* * detect language */ String strQueryTargetLanguage = "https://www.googleapis.com/language/translate/v2/detect?key=" + Setup.API_KEY_GOOGLETRANSLATE + "&q=" + Uri.encode(bundle.getString("TEXT")); String strSourceLanguage = detectLanguage(strQueryTargetLanguage); /* * translate */ String strQuery2 = "https://www.googleapis.com/language/translate/v2?key=" + Setup.API_KEY_GOOGLETRANSLATE + "&q=" + Uri.encode(bundle.getString("TEXT")) + "&source=" + strSourceLanguage + "&target=" + bundle.getString("LANGUAGE_TO") + "&prettyprint=true"; Log.d(TAG, "[REQUEST2->]:" + strQuery2); pageContent = getPageContent2(strQuery2, false); // strQuery = Uri.encode(strQuery); outBundle.putString("TRANSLATION", pageContent); mUiQueue.postToUi(Type.FINISHED_TRANSLATION, outBundle, false); } catch (ApiException e) { Log.e(TAG, "Couldn't contact API", e); outBundle.putString("EXCEPTION", "Couldn't contact API"); mUiQueue.postToUi(Type.FINISHED_TRANSLATION_WITH_ERROR, outBundle, false); } catch (ParseException e) { Log.e(TAG, "Couldn't parse API response", e); outBundle.putString("EXCEPTION", "Couldn't parse API response"); mUiQueue.postToUi(Type.FINISHED_TRANSLATION_WITH_ERROR, outBundle, false); } } }
From source file:com.github.kanata3249.ffxieq.android.VWAtmaLevelSelectorActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { Atma atma = getDAO().instantiateVWAtma(mLongClickingItemId); String name = atma.getName(); Intent intent;/* www . j a v a2s. c om*/ if (atma != null) { String[] urls = getResources().getStringArray(R.array.SearchURIs); String url; url = null; switch (item.getItemId()) { case R.id.WebSearch0: url = urls[0]; break; case R.id.WebSearch1: url = urls[1]; break; case R.id.WebSearch2: url = urls[2]; break; case R.id.WebSearch3: url = urls[3]; break; case R.id.WebSearch4: url = urls[4]; break; case R.id.WebSearch5: url = urls[5]; break; case R.id.WebSearch6: url = urls[6]; break; case R.id.WebSearch7: url = urls[7]; break; default: url = null; break; } if (url != null) { intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url + Uri.encode(name.split("[\\+?i(]")[0]))); startActivity(intent); return true; } } return super.onContextItemSelected(item); }