What I want to accomplish is the following:
Create a custom component with it's own interface and interaction
Create a .jar with that custom component
Consume that .jar in another Android project and be able to edit some of it's values
I've done since now:
1. Create a custom component and extract it's jar following this link
The content of the custom component looks like this:
The main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Yes!! I'm a custom component!"
/>
</LinearLayout>
With it's MainActivity:
public class MainActivity extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
And it's own AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test_uc"
android:versionCode="1"
android:versionName="1.0">
<application android:label="#string/app_name">
<activity android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
2. Add it on my main project.
3. Use it in my main xml project like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, MyActivity"
/>
<test_uc android:layout_height="fill_parent" /> // SEE THE ITEM HERE
</LinearLayout>
But if I go to check the interface, I can't see the test_uc content, or modify anything of it.
So, my question is:
How to build a custom component, build it as a jar file, add it on a main project and be able to use it's properties or even see it in my interface?
Please, I'm a bit lost on this. Any idea will be really thankful!!!!
What I ended up doing in my case, was:
Create an Activity.
Give that activity to the user.
Use it as a library.
As a .jar is only a compressed acivity, that was enought for my purpose.
I did this because in my case, I had to make some event subscriptions, and this way was easier for the user.
Related
I want to add a map control to my android app.
To do this I have got the latest xamarin.forms and xamarin.forms.maps packages from Nuget.
My code behind logic does nothing at all, and my axml page looks like as below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/optionsContainerLinearLayout">
//Other UI elements
<maps:Map>
</maps:Map>
</LinearLayout>
...
</LinearLayout>
Note I've but no tags within maps:Map so as to provide minimal chance for errors. Note that when I populate this map with more properties as directly below, the code still breaks in the same way:
<map:Map
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/mockMapView">
</map:Map>
When I run this application, it breaks on SetContentView() with the error:
Didn't find class "android.view.Map" on path: DexPathList
[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.geosolve.pavestate2-fJtHBLcT2gY6AlUrxcOOVg==/base.apk"],
nativeLibraryDirectories=[/data/app/com.geosolve.pavestate2-fJtHBLcT2gY6AlUrxcOOVg==/lib/x86, /data/app/com.geosolve.pavestate2-fJtHBLcT2gY6AlUrxcOOVg==/base.apk!/lib/x86, /system/lib]]
I've got another sample xamarin application I downloaded which runs fine on my emulator, so I don't think the emulator is the problem.
I have my API key being used by this other application as well, so I don't think the API key is the problem either.
My androidManifest.xml looks like so:
...
<application android:allowBackup="true" android:icon="#mipmap/icon" android:label="#string/app_name" android:roundIcon="#mipmap/icon" android:supportsRtl="true" android:theme="#style/GeosolveApp">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="(My API Key)" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
...
Any help as to why this isn;'t just showing up like you would expect?
For Xamarin.Android,we usually install the Xamarin.GooglePlayServices.Maps package from NuGet.
And add the map in your xaml like:
Declaratively :
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
class="com.google.android.gms.maps.SupportMapFragment" />
Programmatically :
var mapFrag = MapFragment.NewInstance();
activity.FragmentManager.BeginTransaction()
.Add(Resource.Id.map_container, mapFrag, "map_fragment")
.Commit();
the more you could read Google Maps.
I have been reading Google's android tutorial and I got a problem... In the tutorial they explain the XML elements (EditText and Button) and in the end they say how to tun the program to see the button + the text field.
The problem is, that the emulator doesn't show them.. just a black screen.
I even tried adding this line to the onCreate function -
System.out.println("Hello World!");
but still the emulator is showing only black screen..
Here's the .java main file - http://pastebin.com/G5J9YjNe
And the XML files (I mentioned what code is what file) - http://pastebin.com/VnRwAfMW
What should I do?
Thanks a lot for everyone who will help!
System.out.println("Hello World!");
does not print any thing on screen. it can seen on Consol. i tried below code and working fine for me.
// Main Activity
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.kuchbhi);
System.out.println("Hello World!");
}
Layout /.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="#+id/text_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="enter text" />
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Send" />
</LinearLayout>
Manifest file ..
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
try this code and let me know what u see.
I tried your source code and it is working fine for me. see screen
Update
After adding the following style and setting it for my application, I have gotten it draw the whole screen:
<resources>
<style name="app_theme" parent="android:Theme.NoTitleBar">
<item name="android:windowBackground">#color/green</item>
</style>
</resources>
While developing my first Android app I've realized that my apps' views never span the entire screen whereas other sample projects I have downloaded do. To test this I have created a basic activity class and set the background of a TextView to green to see how much it is spanning. Forgive me if this is a stupid question but I am new to this.
Here is the screenshot:
Here is the complete HomeActivity Source:
public class HomeActivity extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Here is the layout file (/res/layout/main.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Hello World, StackOverflow"
android:background="#00FF00"
/>
</LinearLayout>
and here is a screenshot of another app in the emulator working fine, spanning the whole window:
Edit
I edited my XML file to now be:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00FF00"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Hello World, StackOverflow"
/>
</LinearLayout>
Then cleaned and built, ran and got the same exact view.
Edit 2
I removed the "vertical" orientation line as requested, no change.
Here is my AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blah.blah.myCrap"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:label="#string/app_name" >
<activity android:name="HomeActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Added the following to my manifest under <application>
<supports-screens android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true" />
Still the wrong size.
It's coming fine on Android 2.2 emulator
Check your manifest to see if it supports different screen sizes. You can find more information in this QA ( fill_parent is not filling entire screen in LinearLayout )
Apparently, if you don't specify that it supports small, normal, large, anydensity screen sizes, you can have issues with layouts not filling the entire screen.
I am new to Android SDK,but I know JAVA a little.I am on SDK v4.The problem is that,I tried to make 'HelloWidget' Home Screen Widget (with just a text box),and when I try to run the project,the console gives me
No Launcher Activity Found!
The application will only sync the package to the device!
And my app is nowhere to be found in the AVD.I had tried putting the .MAIN and Launcher in Intent filter,but no good.Here are my files:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ax.startup"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<!-- Broadcast Receiver that will process AppWidget updates -->
<receiver android:name=".AxStartup" android:label="AxStartup">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#layout/startup_info" />
</receiver>
</application>
</manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HELLO WORLD" />
</LinearLayout>
startup_info.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:text="ITS WORKING DUDE!"
android:minWidth="146dip"
android:minHeight="72dip"
android:updatePeriodMillis="10000"
android:initialLayout="#layout/startup_info">
<requestFocus />
</EditText>
</LinearLayout>
Java file
package ax.startup;
import android.appwidget.AppWidgetProvider;
public class AxStartup extends AppWidgetProvider {
}
I followed the tutorial from here:
http://www.helloandroid.com/files/xmaswidget/android_howto-hellowidget.pdf
And another strange problem is that when I long press on desktop,only options to change wallpaper is coming.There is no 'Add to Home Screen' or 'Widgets' or any other menu!!!
Please tell me what is the problem.
An application widget can not be launched with a MAIN action, only activities. Also, if your app only has an application widget you will not see an app icon. The log messages are saying that the app was deployed to the emulator but you must start the app widget manually.
Go to the home screen on the device and do a long-press on the screen. You will get a menu to add an element to the home screen. One of the options will be "Widgets". Select that and navigate to your app widget. Your app widget will now be on the home screen.
Trying to get an Android 2.2 application to start up with a SurfaceView as the base view with a button placed atop it located near the bottom of the screen. So far, no luck. It crashes every time it attempts to launch. I've checked to make sure that the activity is registered in the manifest.
Here's my java code:
public class Dragable extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
and here's my main.xml:
<?xml version="1.0" encoding="utf-8"?>
<SurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/surface_home"
>
<Button
android:id="#+id/add_new"
android:text="#string/add_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
</SurfaceView>
and my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Dragable"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
and here's my error:
11-29 11:58:52.620: ERROR/AndroidRuntime(512): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.Dragable}: java.lang.ClassCastException: android.view.SurfaceView
Can't seem to find anything related doing searches on SO. My appologies if this has been asked before.
Now I see the problem. SurfaceView is not a container, I mean it does not extends ViewGroup, so you can't put a Button inside a SurfaceView. What you can do is wrapping the SurfaceView and the Button within a RelativeLayout.
You are not using any container to place components. Use this and make changes
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SurfaceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/surface_home"
>
<Button
android:id="#+id/add_new"
android:text="#string/add_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
/>
</SurfaceView>
</FrameLayout>