B4A Library [BETA] ahaShareLibrary

[LIB] [B4A SourceCode] ahaShareLibrary

Hi!

As we all have the Problems with sharing Text/Pictures via Intents and Facebook, I decided to write a small library that get rid of this Problem. It's very easy to use and takes all the work away from you :)

You can share Text, Pictures, Documents.....



It's still beta, so please report any Bugs/Wishes.

Usage is very simple:
B4X:
Dim Share as ahaShare
Share.initialize(Me, "Share")
Share.FaceBookAppID = "xxxx"
Share.FaceBookRedirectUri = "http://www.xxxxxx.xxx/"
Share.Share("Test-Subject","Test-Text")
After sharing, the Finished Event is called
B4X:
Sub Share_Finished
   ..your code here
End Sub
Screenshot :
attachment.php


PS: As you can see you can customize nearly everything:
attachment.php
attachment.php
attachment.php



This library is written in B4A :)

I hope you like it :)
  • ahaShare
    Methods:
    • IsInitialized As Boolean
      Tests whether the object has been initialized.
    • Addfile (Directory As String, Filename As String) As String
      Adds a file to the Intent
      <B>Attention: file.DirAssets and file.dirInternal will <I>NOT></I> work as Directory!!</B>
    • Addpackagefilter (PackageFilter As String) As String
      Adds a packagefilter. Packages with the given names will not be shown in the ContentChooser
      Example1: "com.google.android.keep" to hide Google Keep from the choosable Apps
      Example2: "synology" hides every Synology-App
    • Clearfiles As String
      Clears all added files
    • Initialize (Module As Object, EventName As String) As String
      Initializes the Library

      <B>Normal Library usage:</B>
      -----------------------
      <code>Dim Share as ahaShare
      Share.initialize(me, "Share")
      Share.FaceBookAppID = "xxxx"
      Share.FaceBookRedirectUri = "http://www.xxxxxx.xxx/"
      Share.Share("Test-Subject","Test-Text")</code>

      Event Finished will be raised when Sharing is finished:
      Sub Share_Finished
      ..your code here (i.e deleting temp files,...)
      End Sub

      <B>That's it :)</B>
    • Sshare (Subject As String, Text As String) As String
      Starts the ContentChooser
    Properties:
    • buttonnormalcolor As Int
      Color of the unpressed Buttons
      Standard: colors.white
    • buttonpressedcolor As Int
      Color of the pressed Button
      Standard: Colors.RGB(29,162,235)
    • cornerradius As Int
      Corner radius of the Buttons
    • facebookappid As String
      Your Facebook AppID. Needed for publishing to FaceBook.
      Tutorial by NJDude: <link>http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/17739-tutorial-post-facebook-wall-via-b4a-app.html|http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/17739-tutorial-post-facebook-wall-via-b4a-app.html</link>
      Attention: If not set, FaceBook will not be available to share with
    • facebookredirecturi As String
      Your Facebook RedirectUri. Needed for publishing to FaceBook.
      Tutorial by NJDude: <link>http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/17739-tutorial-post-facebook-wall-via-b4a-app.html|http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/17739-tutorial-post-facebook-wall-via-b4a-app.html</link>
      Attention: If not set, FaceBook will not be available to share with
    • headerbackcolor As Int
      BackColor of the Header
      Standard: Colors.Transparent
    • headertext As String
      HeaderText of the ContentChooser
      Standard: Choose
    • headertextcolor As Int
      TextColor of the Header
      Standard: Colors.RGB(49,182,255)
    • headertextsize As Int
      TextSize of the Header
      Standard: 22
    • intenttype As String
      IntentType, for example "text/*" for Text, "image/jpeg" for jpg, "image/png" for png etc..
    • linecolor As Int
      Color of the Seperatorline below the Header
      Standard: Colors.RGB(49,182,255)
    • padding As Int
      Padding
      Standard: 10dip
    • panelcolor As Int
      Color of the ContentChooser Panel
      Standard: Colors.white
    • sendingtofacebookfinishedstring As String
      The String displayed as ToastMessage after Sending to Facebook succeeded
      Standard: "Posted to Facebook"
    • sendingtofacebookstring As String
      The String displayed in the ProgressDialog while sending to FaceBook
      Standard: "Posting to Facebook..."
    • shadowcolor As Int
      Color of the Background Shadow.
      Use colors.rgb(x,x,x) for opaque background, colors.argb(x,x,x,x) for Transparency
      Standard: Colors.ARGB(150,0,0,0)
    • subject As String
      Subject (for E-Mail,..) set as android.intent.extra.SUBJECT
    • text As String
      The Message. Set as android.intent.extra.TEXT
    • textcolor As Int
      Textcolor of the Names of the displayed Packages
      Standard: Colors.Black
    • textsize As Int
      TextSize of the Names of the displayed Packages.
      Standard: 14
    • AppButtonWidth As Int
      Width of the Buttons
      Standard: 160dip
    • AppButtonHeight As Int
      Height of the Buttons
      Standard: 120dip
    • AppIconSize As Int
      Size of the Images on the Buttons
      Standard: 48dip
    • HeaderHeight As Int
      Height of the Header
      Standard: 60dip
Generated with Warwounds Library reference generator
---------------
Version 0.6
New:
_Finished Event added

Version 0.7
New:
Long click on the App-Symbol opens the Android Application Settings for the clicked app (as the original contentchooser
Fixed: Last line of Icons was not displayed. (Thanks to derez!!)
Change: More icons are displayed at once (Height of the Buttons reduced)

Version 0.8
New:
AppButtonWidth: sets the width of the Buttons
AppButtonHeight: sets the height of the Buttons
AppIconSize: Sets width & height of the AppIcons
HeaderHeight: Sets the height of the Header
Fixed: Error handling in all Subs

Version 1.0
Beta finished :)
SourceCode attached
 

Attachments

  • Example.zip
    42.3 KB · Views: 499
  • Screenshot.png
    Screenshot.png
    45.6 KB · Views: 1,288
  • Screenshot2.png
    Screenshot2.png
    30.6 KB · Views: 1,264
  • ScreenshotXS.png
    ScreenshotXS.png
    25.1 KB · Views: 1,199
  • ScreenshotS.png
    ScreenshotS.png
    33.7 KB · Views: 1,197
  • ahaShareLibrary.zip
    22.1 KB · Views: 512
  • ahaShareSource.zip
    126.2 KB · Views: 386
Last edited:

derez

Expert
Licensed User
I have tested Facebook, gmail and email - works like charm :)
Is it possible to select which of the six options will show ?
Thank you !

Edit: Google+ opens the page, the message is displayed but not the photo, and it fails sending. Maybe the problem is in my settings.
 
Last edited:

RiverRaid

Active Member
Licensed User
Hi!

Thanks for the reply :)

What exactly do you mean by
Is it possible to select which of the six options will show ?
PS: It shows more than 6 Options, try to scroll :) The lib imitates the normal ContentChooser with extras :)

If you like to filter a specific app out, you can do it via AddPackageFilter
And you can set manually the intenttype (IntentType = "image/jpeg" for example). Standardintenttype is "Text/*"


Edit: Google+ opens the page, the message is displayed but not the photo, and it fails sending. Maybe the problem is in my settings.
Hmm.. thats strange.. I just tried it on my Nexus 4 nd tf700, there it works..
 
Last edited:

derez

Expert
Licensed User
The problem was mine, g+ needed update.
I'll try what you sugest later on.

Edit:
It does not scroll !
In portrait I get eight icons in two lines of four, in landscape only seven in one line.
 
Last edited:

RiverRaid

Active Member
Licensed User
You are right...

It only scrolls if there are more icons than the Dialog can display (Scrollview)

In portrait I get eight icons in two lines of four, in landscape only seven in one line.
THANK YOU!!!:sign0098: You found the first bug :)

I had to change
B4X:
scvApps.Panel.Height =row * IconHeight
into
B4X:
scvApps.Panel.Height =(row+1) * IconHeight
*lol* No it works correctly..

Zip in the first post is updated
 
Last edited:

korshkov

Member
Licensed User
On tablet with Android 4.1.2 write error:
java.lang.NoClassDefFoundError: at.ahadev.b4a.ahashare.ahashare

B4A Ver: 2.52
Path for android.jar: C:\Android\android-sdk\platforms\android-14\android.jar
 

canalrun

Well-Known Member
Licensed User
Zip in the first post is updated

Thanks for this sharing library. I am working on an app that shares by e-mail but this is the obvious extension for everything sharing.

I tried a few things that seem to work well – when I tried twitter, the twitter app closed saying "sorry this has closed", but the problem may very well be that I did not even know I had twitter on the phone.

One thing I noticed is that on my two devices the icons, text and spacing appeared comically large compared with things displayed in other commercial apps or within the app I'm creating.

I wonder if it may not be better to allow the developer/user of the library to create the display of shareable places. Upon initialize your library would populate a list that includes the icon, text, and ID for calling back into your library when the user has made a selection. You could provide a Show method that would display the item selection panel that you presently have or the developer could use the information from the list to display his own selection panel formatted to integrate cleanly into his app.

Could I ask a question about Facebook? I am extremely unfamiliar with Facebook. When looking at other posts and tutorials on this forum mentioning Facebook they all mention something about a FaceBookAppID. What is the purpose of this? When a user of my app shares something via Facebook it should go to their Facebook account (Wall?). I do not want to be involved in any way. Is this possible?

Thanks,
Barry.
 

RiverRaid

Active Member
Licensed User
One thing I noticed is that on my two devices the icons, text and spacing appeared comically large compared with things displayed in other commercial apps or within the app I'm creating.
Can you post a screenshot? It should look like the picture in the first post.

I wonder if it may not be better to allow the developer/user of the library to create the display of shareable places. Upon initialize your library would populate a list that includes the icon, text, and ID for calling back into your library when the user has made a selection.
Good idea! Maybe I'm adding this feature so that you will have full control... either letting do the lib the whole work, or getting the Apps-List, do your own GUI and send back the userdescision to the lib...

When looking at other posts and tutorials on this forum mentioning Facebook they all mention something about a FaceBookAppID. What is the purpose of this? When a user of my app shares something via Facebook it should go to their Facebook account (Wall?). I do not want to be involved in any way. Is this possible?
Short answer: No :( Detail: In Android, you can share something via intents. That works perfect for everything except Facebook. Facebook will start, but the companyrules doesn't allow you to prefill the text, so its useless. You have to create a Facebook - App, get an Api-key and URL. With this information, you can log in with OAuth and Post the message.

The whole posting, loggingin etc is done by the lib for you. You hast have to get API-Key and URL and assign it.
More details and a goot tutorial is available here:
Tutorial from NJDude
 
Last edited:

canalrun

Well-Known Member
Licensed User
Can you post a screenshot? It should look like the picture in the first post.

Hello,
Yes it does look like the picture below on my HTC Amaze, screen size 540x960. On my Samsung Vibrant, screen size 480x800, it displays as a single long column.

I have attached a screenshot showing the Share screen and two other screens, one page of the list of apps, and a file list from ES File Manager.

I guess in reality the Share screen is not oversized, as I thought. If I were doing it, I would probably make the Share screen 80% of the Activity.Width, I would have three or four icons in a row similar to the application list, I would scrunch things vertically a little, and I would have text lines wrap to the next line as done in the app list. But, that's me – I am sure others would do it differently.

Thanks,
Barry.
 

Attachments

  • ahaShare.jpg
    ahaShare.jpg
    58.4 KB · Views: 191
Last edited:

RiverRaid

Active Member
Licensed User
korshkov said:
Yes. Phone library is 2.1
Hmm.. then I don't know, sorry. I have added a new version with full error handling. Could you try it?

canalrun said:
I would have three or four icons in a row similar to the application list, I would scrunch things vertically a little, and I would have text lines wrap to the next line as done in the app list.
Now you can do it :sign0060:

attachment.php
B4X:
Share.AppButtonHeight = 100dip
Share.AppButtonWidth = 80dip
attachment.php
B4X:
Share.AppButtonHeight = 60dip
Share.AppButtonWidth = 60dip
Share.AppIconSize = 32dip
Share.TextSize = 10
Share.HeaderTextSize = 16
Share.HeaderHeight = 30dip
 

Attachments

  • ScreenshotS.png
    ScreenshotS.png
    33.7 KB · Views: 949
  • ScreenshotXS.png
    ScreenshotXS.png
    25.1 KB · Views: 946

derez

Expert
Licensed User
you can set manually the intenttype (IntentType = "image/jpeg" for example).

Using IntentType I get this error:

Error description: Array expected.
Occurred on line: 33
Share.IntentType("text/*")
Word: (

The same when using an array of string.

If you like to filter a specific app out, you can do it via AddPackageFilter
I added a filter :
B4X:
Share.Addpackagefilter ("com.yixia.vplayer")
but the VPlayer still shows.

Canalrun wrote:
I wonder if it may not be better to allow the developer/user of the library to create the display of shareable places.
I support +1 . If I want to integrate this library to an app, it should be displayed according to the app screens.
 
Last edited:

RiverRaid

Active Member
Licensed User
Using IntentType I get this error:
The same when using an array of string.
I added a filter :
B4X:
Share.Addpackagefilter ("com.yixia.vplayer")
but the VPlayer still shows.

Thats really strange, i just tested it...
a.IntentType = "image/jpeg" => No error
a.AddPackageFilter("devian.tubemate.home") filters out tubemate..?

Can I send you the source and you test it?

I support +1 . If I want to integrate this library to an app, it should be displayed according to the app screens.
I think I will post a small tutorial how i made this lib than everyone can do whatever he/she likes :) This lib was made for my projects (and will be used like it is) and if you want to make your own GUI, its far better to do your own coding (no code ovehead).

Edit: Here is the Tutorial
 
Last edited:
Top