@SuppressLint("NewApi") private static void downloadMedia(Object sourceButton, Object mMedia) { Field contextField = XposedHelpers.findFirstFieldByExactType(sourceButton.getClass(), Context.class); if (mContext == null) { try { mContext = (Context) contextField.get(sourceButton); } catch (Exception e) { e.printStackTrace(); log("Failed to get Context"); return; } } log("Downloading media..."); Object mMediaType = getObjectField(mMedia, "b"); Field[] mMediaFields = mMedia.getClass().getDeclaredFields(); for (Field iField : mMediaFields) { String fieldType = iField.getClass().getName(); if (fieldType.contains("com.instagram.model") && !fieldType.contains("people")) { try { mMediaType = iField.get(mMedia); } catch (Exception e) { log("Failed to get MediaType class"); Toast.makeText( mContext, ResourceHelper.getString(mContext, R.string.mediatype_error), Toast.LENGTH_LONG) .show(); e.printStackTrace(); return; } } } Object videoType = getStaticObjectField(mMediaType.getClass(), "b"); String linkToDownload; String filenameExtension; String descriptionType; int descriptionTypeId = R.string.photo; if (mMediaType.equals(videoType)) { linkToDownload = (String) getObjectField(mMedia, "E"); filenameExtension = "mp4"; descriptionType = "video"; descriptionTypeId = R.string.video; } else { linkToDownload = (String) getObjectField(mMedia, "s"); filenameExtension = "jpg"; descriptionType = "photo"; descriptionTypeId = R.string.photo; } // Construct filename // username_imageId.jpg descriptionType = ResourceHelper.getString(mContext, descriptionTypeId); String toastMessage = ResourceHelper.getString(mContext, R.string.downloading, descriptionType); Toast.makeText(mContext, toastMessage, Toast.LENGTH_SHORT).show(); Object mUser = getObjectField(mMedia, "p"); String userName = (String) getObjectField(mUser, "b"); String userFullName = (String) getObjectField(mUser, "c"); String itemId = (String) getObjectField(mMedia, "t"); String fileName = userName + "_" + itemId + "." + filenameExtension; if (TextUtils.isEmpty(userFullName)) { userFullName = userName; } File directory = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .getAbsolutePath() + "/Instagram"); if (!directory.exists()) directory.mkdirs(); String notificationTitle = ResourceHelper.getString(mContext, R.string.username_thing, userFullName, descriptionType); String description = ResourceHelper.getString(mContext, R.string.instagram_item, descriptionType); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(linkToDownload)); request.setTitle(notificationTitle); request.setDescription(description); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } request.setDestinationInExternalPublicDir( Environment.DIRECTORY_DOWNLOADS, "Instagram/" + fileName); DownloadManager manager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE); manager.enqueue(request); }
private void appendBasePath(StringBuilder builder) { if (contract == null) { builder.append(helper.getBaseResourcePath()); } else { builder.append(helper.getBaseContractsPath()).append('/').append(contract); } }
public void testEqualsOnResourceAndRelatedClasses() throws Exception { // validate the behavior of getInputStream() for a webapp-based resource ResourceHandler handler = getFacesContext().getApplication().getResourceHandler(); assertTrue(handler != null); Object x = handler.createResource("duke-nv.gif", "nvLibrary", "image/gif"), y = handler.createResource("duke-nv.gif", "nvLibrary", "image/gif"), z = handler.createResource("duke-nv.gif", "nvLibrary", "image/gif"); this.verifyEqualsContractPositive(x, y, z); y = handler.createResource("simple.css"); assertFalse(x.equals(y)); VersionInfo viA = new VersionInfo("1.0", null), viB = new VersionInfo("1.0", null), viC = new VersionInfo("1.0", null); this.verifyEqualsContractPositive(viA, viB, viC); ResourceHelper helper = new ClasspathResourceHelper(); FacesContext context = this.getFacesContext(); LibraryInfo liA = helper.findLibrary("vLibrary-jar", null, null, context), liB = helper.findLibrary("vLibrary-jar", null, null, context), liC = helper.findLibrary("vLibrary-jar", null, null, context); this.verifyEqualsContractPositive(liA, liB, liC); liB = helper.findLibrary("vLibrary", null, null, context); assertFalse(liA.equals(liB)); }
public void testGetScheme() throws Exception { assertEquals("file:", ResourceHelper.getScheme("file:myfile.txt")); assertEquals("classpath:", ResourceHelper.getScheme("classpath:myfile.txt")); assertEquals("http:", ResourceHelper.getScheme("http:www.foo.com")); assertEquals(null, ResourceHelper.getScheme("www.foo.com")); assertEquals(null, ResourceHelper.getScheme("myfile.txt")); }
public void testIsHttp() throws Exception { assertFalse(ResourceHelper.isHttpUri("direct:foo")); assertFalse(ResourceHelper.isHttpUri("")); assertFalse(ResourceHelper.isHttpUri(null)); assertTrue(ResourceHelper.isHttpUri("http://camel.apache.org")); assertTrue(ResourceHelper.isHttpUri("https://camel.apache.org")); }
@Override public NodeRef deployResource( RepositoryLocation targetLocation, UpdateStrategy updateStrategy, String encoding, String mimetype, Resource resource, QName nodeType) throws IOException { final NodeRef existingNode = resourceHelper.findNodeForResource(resource, targetLocation); if (existingNode == null) { final NodeRef nodeRef = createNode(resource, targetLocation, encoding, mimetype, nodeType); logger.debug("Deployed {} as new node {}.", resource, nodeRef); return nodeRef; } else { if (updateStrategy.updateNode(resource, existingNode)) { updateNode(resource, existingNode); logger.debug("Updated {} to existing node {}.", resource, existingNode); } else { logger.debug( "No changes detected between resource {} and node {}.", resource, existingNode); } return existingNode; } }
@Override public float getDimension(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); if (value != null) { String v = value.getValue(); if (v != null) { if (v.equals(BridgeConstants.FILL_PARENT)) { return LayoutParams.FILL_PARENT; } else if (v.equals(BridgeConstants.WRAP_CONTENT)) { return LayoutParams.WRAP_CONTENT; } if (ResourceHelper.stringToFloat(v, mTmpValue) && mTmpValue.type == TypedValue.TYPE_DIMENSION) { return mTmpValue.getDimension(mMetrics); } } } // id was not found or not resolved. Throw a NotFoundException. throwException(id); // this is not used since the method above always throws return 0; }
@SuppressLint("NewApi") private static final void showRequiresDonatePackage(final Context context) { String title = ResourceHelper.getString(context, R.string.requires_donation_package_title); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { String message = ResourceHelper.getString(context, R.string.requires_donation_package_message); String positiveButton = ResourceHelper.getString(context, R.string.go_to_play_store); AlertDialog.Builder builder = new AlertDialog.Builder(context, android.R.style.Theme_Holo_Light_Dialog); builder.setTitle(title); builder.setMessage(message); builder.setPositiveButton( positiveButton, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String url = "market://details?id=com.mohammadag.xposedinstagramdownloaderdonate"; Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url)); intent.setPackage("com.android.vending"); try { context.startActivity(intent); } catch (ActivityNotFoundException e) { String playStoreNotFound = ResourceHelper.getString(context, R.string.play_store_not_found); Toast.makeText(context, playStoreNotFound, Toast.LENGTH_SHORT).show(); } } }); builder.create().show(); } else { String url = "market://details?id=com.mohammadag.xposedinstagramdownloaderdonate"; Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url)); intent.setPackage("com.android.vending"); Toast.makeText(context, title, Toast.LENGTH_SHORT).show(); try { context.startActivity(intent); } catch (ActivityNotFoundException e) { String playStoreNotFound = ResourceHelper.getString(context, R.string.play_store_not_found); Toast.makeText(context, playStoreNotFound, Toast.LENGTH_SHORT).show(); } } }
public void testAppendParameters() throws Exception { Map<String, Object> params = new LinkedHashMap<String, Object>(); params.put("foo", 123); params.put("bar", "yes"); // should clear the map after usage assertEquals( "http://localhost:8080/data?foo=123&bar=yes", ResourceHelper.appendParameters("http://localhost:8080/data", params)); assertEquals(0, params.size()); }
@Override public boolean fillTypedValue(String data, TypedValue typedValue) { try { typedValue.type = TypedValue.TYPE_INT_COLOR_ARGB8; typedValue.data = ResourceHelper.getColor(data); typedValue.assetCookie = 0; return true; } catch (NumberFormatException nfe) { return false; } }
protected final FlushAction<K, V, A> buildFlushAction(MapperPair<K, V, A> mapperPair) { final A actionKey = mapperPair.getActionKey(); final String prefix = getOutputFilePrefix(actionKey); final File flushDir = new File(outDir, prefix); return buildFlushAction( actionKey, flushDir, ResourceHelper.buildNameGenerator(prefix + "-", ".gz", numDigits, chainNum), maxPairs, buildFlushFileStrategy()); }
/** * Lists all buildings on the planet with the given location. * * @param player Player. * @param location Planet location. * @return All buildings on the planet. */ @GET @ApiOperation(value = "Get all buildings on a planet") public BuildingsResponse getBuildings( @Auth @ApiParam(access = "internal") Player player, @PathParam("location") @ApiParam("Planet location") String location) { Preconditions.checkNotNull(player, "player"); Preconditions.checkNotNull(location, "location"); Planet planet = ResourceHelper.findPlanetWithLocationAndOwner(planetService, location, player); Buildings buildings = buildingService.findBuildingsOnPlanet(planet); return new BuildingsResponse(Functional.mapToList(buildings, BuildingMapper::fromBuilding)); }
@Override public Drawable getDrawable(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); if (value != null) { return ResourceHelper.getDrawable(value.getValue(), mContext, value.isFramework()); } // id was not found or not resolved. Throw a NotFoundException. throwException(id); // this is not used since the method above always throws return null; }
public void testLoadFileNotFound() throws Exception { CamelContext context = new DefaultCamelContext(); context.start(); try { ResourceHelper.resolveMandatoryResourceAsInputStream( context, "file:src/test/resources/notfound.txt"); fail("Should not find file"); } catch (FileNotFoundException e) { assertTrue(e.getMessage().contains("notfound.txt")); } context.stop(); }
public void testLoadClasspathDefault() throws Exception { CamelContext context = new DefaultCamelContext(); context.start(); InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(context, "log4j2.properties"); assertNotNull(is); String text = context.getTypeConverter().convertTo(String.class, is); assertNotNull(text); assertTrue(text.contains("log4j")); is.close(); context.stop(); }
public void testLoadClasspathNotFound() throws Exception { CamelContext context = new DefaultCamelContext(); context.start(); try { ResourceHelper.resolveMandatoryResourceAsInputStream(context, "classpath:notfound.txt"); fail("Should not find file"); } catch (FileNotFoundException e) { assertEquals( "Cannot find resource: classpath:notfound.txt in classpath for URI: classpath:notfound.txt", e.getMessage()); } context.stop(); }
public void testLoadClasspathAsUrl() throws Exception { CamelContext context = new DefaultCamelContext(); context.start(); URL url = ResourceHelper.resolveMandatoryResourceAsUrl( context.getClassResolver(), "classpath:log4j2.properties"); assertNotNull(url); String text = context.getTypeConverter().convertTo(String.class, url); assertNotNull(text); assertTrue(text.contains("log4j")); context.stop(); }
/** Sets the response locale if changeResponseLocale attribute is true */ public int doEndTag() throws JspException { if (_changeResponseLocale) { // set the locale for the response Locale bundleLocale = _bundle.getLocale(); if ((bundleLocale != null) && !("".equals(bundleLocale.getLanguage()))) { pageContext.getResponse().setLocale(bundleLocale); } } // cache the bundle for use by message tags within this request ResourceHelper.setBundle(pageContext, _bundle, _scope); return EVAL_PAGE; }
@Override public void getValue(int id, TypedValue outValue, boolean resolveRefs) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); if (value != null) { String v = value.getValue(); if (v != null) { if (ResourceHelper.stringToFloat(v, outValue)) { return; } } } // id was not found or not resolved. Throw a NotFoundException. throwException(id); }
public void testLoadRegistry() throws Exception { SimpleRegistry registry = new SimpleRegistry(); registry.put("myBean", "This is a log4j logging configuation file"); CamelContext context = new DefaultCamelContext(registry); context.start(); InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(context, "ref:myBean"); assertNotNull(is); String text = context.getTypeConverter().convertTo(String.class, is); assertNotNull(text); assertTrue(text.contains("log4j")); is.close(); context.stop(); }
@Override public int getColor(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); if (value != null) { try { return ResourceHelper.getColor(value.getValue()); } catch (NumberFormatException e) { return 0; } } // id was not found or not resolved. Throw a NotFoundException. throwException(id); // this is not used since the method above always throws return 0; }
@Override public int getDimensionPixelSize(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); if (value != null) { String v = value.getValue(); if (v != null) { if (ResourceHelper.stringToFloat(v, mTmpValue) && mTmpValue.type == TypedValue.TYPE_DIMENSION) { return TypedValue.complexToDimensionPixelSize(mTmpValue.data, mMetrics); } } } // id was not found or not resolved. Throw a NotFoundException. throwException(id); // this is not used since the method above always throws return 0; }
public void testLoadFileWithSpace() throws Exception { CamelContext context = new DefaultCamelContext(); context.start(); createDirectory("target/my space"); FileUtil.copyFile( new File("src/test/resources/log4j2.properties"), new File("target/my space/log4j2.properties")); InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream( context, "file:target/my%20space/log4j2.properties"); assertNotNull(is); String text = context.getTypeConverter().convertTo(String.class, is); assertNotNull(text); assertTrue(text.contains("log4j")); is.close(); context.stop(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.showdetails); final ImageView imageView = (ImageView) findViewById(R.id.image); final TextView view = (TextView) findViewById(R.id.viewBox); final Button button = (Button) findViewById(R.id.backBtn); button.setOnClickListener(this); Intent intent = getIntent(); final HashMap<String, String> item = (HashMap<String, String>) intent.getSerializableExtra("Item"); final Bitmap pic = (Bitmap) intent.getParcelableExtra("Pic"); imageView.setImageBitmap(pic); StringBuilder builder = new StringBuilder(); final String title = item.get(EbayItem.TITLE); final String price = item.get("Current Price"); final String location = item.get("Location"); final String shipping = item.get("Shipping Cost"); final String time = item.get("Time Left"); final String ShippingTo = item.get("Shipping To"); final String listing = item.get("Listing Type"); final String empty = " - "; builder.append("TITLE : " + (title == null ? empty : title) + "\n"); builder.append("PRICE : " + (price == null ? empty : price) + "\n"); builder.append("LOCATION : " + (location == null ? empty : location) + "\n"); builder.append("SHIPPING : " + (shipping == null ? empty : shipping) + "\n"); builder.append("TIME LEFT : " + (time == null ? empty : EbayItem.convertTime(time)) + "\n"); builder.append("SHIPPING TO : " + (ShippingTo == null ? empty : ShippingTo) + "\n"); builder.append("LISTING TYPE : " + (listing == null ? empty : listing)); view.setText("\n" + builder.toString()); button.setBackgroundResource(ResourceHelper.getButtonSelector()); overridePendingTransition(R.anim.appear, R.anim.disapear); }
@Override public boolean fillTypedValue(String data, TypedValue typedValue) { return ResourceHelper.parseFloatAttribute(null, data, typedValue, false); }
@Override public int asInt(TypedResource typedResource) { return ResourceHelper.getColor(typedResource.asString().trim()); }