AndroidPlot - XYplot doesn't show up on graphical layout in xml - android

I'm fairly new in the android developing scene, however I have done a few dead simple applications to get an understanding of what the workflow would be like in the environment.
I'm having a difficulty running the example program called SimpleXYPlotExample and here's the code, manifest, main.xml and activity.java, respectively. I know this is a user error of some sort, but it would be great if someone could give me some helpful pointers as to what I'm doing wrong.
At first, all the code was broken, but I realized i forgot to import the library in. Now that I have done so, I try to run the program on my nexus s and it just crashes as it enters it.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="6"
android:targetSdkVersion="16"/>
<application android:label="SimpleXYPlotExample"
android:icon="#drawable/icon"
android:debuggable="true"
android:hardwareAccelerated="false">
<activity android:name=".MyActivity"
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>
<?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"
>
<com.androidplot.xy.XYPlot
android:id="#+id/mySimpleXYPlot"
android:layout_width="fill_parent"
android:layout_height="150px"
android:layout_marginTop="10px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
andsroidplot.title="A Simple XYPlot Example"
androidplot.ticksPerRangeLabel="4"
androidplot.ticksPerDomainLabel="2"
androidplot.gridPadding="4dp|4dp|4dp|4dp"
/>
</LinearLayout>
package com.example;
import java.util.Arrays;
import android.app.Activity;
import android.os.Bundle;
import com.androidplot.series.XYSeries;
import com.androidplot.ui.AnchorPosition;
import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XLayoutStyle;
import com.androidplot.xy.XYPlot;
import com.androidplot.xy.YLayoutStyle;
public class MyActivity extends Activity
{
private XYPlot plot;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// initialize our XYPlot reference:
plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
// add a new series
XYSeries mySeries = new SimpleXYSeries(
Arrays.asList(0, 25, 55, 2, 80, 30, 99, 0, 44, 6),
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "series1");
plot.addSeries(mySeries, new LineAndPointFormatter(
getApplicationContext(), R.xml.f1));
// reposition the domain label to look a little cleaner:
plot.position(plot.getDomainLabelWidget(), // the widget to position
45, // x position value, in this case 45 pixels
XLayoutStyle.ABSOLUTE_FROM_LEFT, // how the x position value is applied, in this case from the left
0, // y position value
YLayoutStyle.ABSOLUTE_FROM_BOTTOM, // how the y position is applied, in this case from the bottom
AnchorPosition.LEFT_BOTTOM); // point to use as the origin of the widget being positioned
plot.centerOnRangeOrigin(60);
plot.centerOnDomainOrigin(5);
}
}
This may be contributed by the fact that the plot doesn't even show up on the graphical layout. This is what it looks like with this code:
http://imgur.com/qYl96Zi
As you can see, I have imported the androidplot library. Please advise.

The screenshot appears to be from the eclipse gui editor, which as the exception mentions does not support the setShadowLayer method and thus will not render. That's just a limitation with Eclipse and not a bug in your code or the library.
Normally to be able to answer questions regarding why Androidplot is crashing you'd need to supply the corresponding stack trace. I did however notice this typo in your xml:
andsroidplot.title="A Simple XYPlot Example"
As far as getting a working WYSIWYG editor my personal suggestion would be to give either IntelliJ IDEA or Android Studio (built on the current EAP version IntelliJ IDEA) a try. Both are free and both are in (IMHO) far superior IDE's.

Related

Can't access the main window/layout from my Activity

This is the start of a simple app to initially display some TextViews and Buttons.
I want to avoid using layout managers by getting the dimensions of the main window/layout and using that to hard-code the components any way I want.
But my main Activity can't get non-zero data about the main window/layout.
I don't know if it's supposed to be this way or if I'm doing something dumb, and would appreciate some help.
This is a command line project using Ant under win10 and outputting to a USB'd phone.
I've updated the SDK Manager to Android 6.0 (API 23) with Android Tools 24.4.1 and installed v23.2 of the Android Support Lib, although Ant seems to think differently as you can see in my previous message which has the Ant output:
-build-setup:
[getbuildtools] Using latest Build Tools: 21.1.2.
I don't know if that makes a difference, but not in this case I think.
The next two files are complete as far as they go.
I would have included more but the way the website mangles my code doesn't encourage uploading to it.
It might have helped if I could have comprehended the 'How to Format' but (A) I didn't even see it before my first post and (B) I don't understand it now.
There are far too many instructions and too much jargon; e.g. what is a backtick?
Can't there be a simple format that will take everything you throw at it?
main.xml
========
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
package="com.Chatterton.Peter.ChessClock"
android:id="#+id/main_window"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="#+id/time_text_view_left"
android:text="top_left"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<Button
android:layout_alignParentBottom="true"
...
There are a total of 4 components, one per corner, with the same layout_width and height.
ChessClockActivity.java
=======================
package com.Chatterton.Peter.ChessClock;
import android.app.Activity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.content.Intent;
import android.app.Activity;
import android.os.Bundle;
import android.graphics.Color;
import android.widget.TextView;
import android.util.Log;
public class ChessClockActivity extends Activity
{
public int winOriginX=10, winOriginY=20, winWidth=44, winHeight=66;
#Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout mainLayout = (RelativeLayout)findViewById( R.id.main_window );
int mainWidth = mainLayout.getWidth();
int mainHeight = mainLayout.getHeight();
Log.d( "clox", "mainLayout=" + mainLayout );
Log.d( "clox", "main W/H=" + mainWidth + "/" + mainWidth );
...
Screen Results:
It shows the last component displayed -- full-size -- with its text.
logcat results:
===============
D:\Android\ChessClock>adb shell
shell#android:/ $ logcat clox:D *:S
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
D/clox (27214): mainLayout=android.widget.RelativeLayout#41755b80
D/clox (27214): main W/H=0/0
**
They have no size at this point of the initialization process.
Click here to an answer that will let you access the sizes of your components after they have been displayed.
Or perhaps you can get the window size and figure the placement of your components by that value......
Answer here

Air StageWebView Leaflet map images are jagged on android

i wanted to incororate a Leaflet Map into an ios and android air mobile application using the StageWebView class.
Unfortunately the quality of the map images is so jagged, that it is hard to make out the streetnames. There seems to be some minor scaling going on.
For test purposes i used the Leaflet tutorial mal at http://leafletjs.com/examples/quick-start-example.html
When viewed in the Android browser ( chrome ) the images look fine.
Here is some simple code to show the issue:
package {
import flash.display.MovieClip;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.media.StageWebView;
import flash.geom.Rectangle;
import flash.desktop.NativeApplication;
import flash.utils.setTimeout;
public class Main extends MovieClip{
private var _stageWebView:StageWebView
public function Main()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
setTimeout( init, 100 );
}
private function init():void {
_stageWebView = new StageWebView();
_stageWebView.stage = this.stage;
_stageWebView.viewPort = new Rectangle( 0, 0, stage.stageHeight, stage.stageWidth );
_stageWebView.loadURL( "http://leafletjs.com/examples/quick-start-example.html" );
}
}
}
Any ideas? Does it have to do with a resolution problem maybe?
Thanks
The problem that you got is a rendering problem which you can avoid by enabling hardware acceleration (force GPU rendering) when it's supported of course.
Beginning in Android 3.0 (API level 11), the Android 2D rendering pipeline supports hardware acceleration, meaning that all drawing operations that are performed on a View's canvas use the GPU.
So to force GPU rendering, you can :
1 - Enable hardware acceleration in your application's manifest file, where you should set the android:hardwareAccelerated attribute of the application element to true :
<android>
<manifestAdditions>
<![CDATA[
<manifest>
<application android:hardwareAccelerated="true"/>
</manifest>
]]>
</manifestAdditions>
</android>
And this is an example of a full manifest file (my test browser-app.xml) :
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<application xmlns="http://ns.adobe.com/air/application/19.0">
<id>browser</id>
<versionNumber>1.0.0</versionNumber>
<versionLabel/>
<filename>browser</filename>
<description/>
<name>browser</name>
<copyright/>
<initialWindow>
<content>browser.swf</content>
<systemChrome>standard</systemChrome>
<transparent>false</transparent>
<visible>true</visible>
<fullScreen>false</fullScreen>
<renderMode>auto</renderMode>
<autoOrients>true</autoOrients>
</initialWindow>
<icon/>
<customUpdateUI>false</customUpdateUI>
<allowBrowserInvocation>false</allowBrowserInvocation>
<android>
<manifestAdditions>
<![CDATA[
<manifest>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:hardwareAccelerated="true"/>
</manifest>
]]>
</manifestAdditions>
</android>
</application>
then you have just to publish your AIR app, you will get something like this :
and you can see the result when I comment <application android:hardwareAccelerated="true"/> :
2 - You can also force GPU rendering from the Developer Options of your Android device :
and you can get the same result even when <application android:hardwareAccelerated="true"/> is commented :
That's all !
Hope that can help.
If you change it to use nativeMode new StageWebView(true) it solves the problem for me but the mouse/touch events don't work :/

Create field layout/main in type R -- unable to resolve

I am new to Android programming and was about to run an android application.
I got the R.layout cannot be resolved to a variable error. When I imported com.package.r; and deleted the android.r it didnt do anything. the error went off after i cleaned the project but then it gave an error on r.layout.activity_main (convert to activity_list...). The code snippet is attached.
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Menu;
import com.procedure.culture.R;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);`
I have restarted eclipse and cleaned the project a million times, but in vain. everything in the activity_main.xml has been commented. but the error is still there. Kindly help.
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#A1F5F8" >
<!--
<TextView
android:id="#+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title"
android:textColor="#000000"
android:textSize="30dp"
/>
-->
TRY the following:
1.check whether there are bugs in XML files.
2.Try to rebulid your application
3.Check for any missing library files.
Also from your question don't import r package. Its auto generated file. Remove all imports regarding r.
Probably there may be some bugs in your XML files. Check that..
Sometimes while cleaning multiple times android loses reference to R(e.g R.id...)
Also avoid running other party's app and copy code in your created app.
Avoid setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) instead set orientation in manifest file:
<activity
android:name=".activity.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation">
While I was searching for an error on R, I read somewhere to uncheck the Java Builder. I did that but it gave me the error in this question thread. So now when I checked the Java builder, the errors have gone. Also, I was trying to add an imageview in the xml when the errors started popping. I commented it but nothing happened. Now when the errors have gone, I de-commented it but cant see the image in the application.
Anyway, thanks for your help guys! :)

How to decrease TextView text size in Android 4.0?

(EDIT: problem fixed. See answer below)
I am stuck with this issue and it blocks a release so every help will be greatly appreciated.
Below is a trivial program that demonstrates the issue. I built it with the latest SDK (R19). It works well on gingerbread but fails on ICS. When the text size is increased (10 -> 30 -> 50) the text field height grows as expected but when the text size is reduced (50 -> 10), the text field has the full height, as if the text size is 50.
Anybody can reproduce it? Any suggestion for a workaround to make reduction in text size working properly?
Main activity:
package test.resize;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class ResizeTestActivity extends Activity {
private int mNextTextSize = 10;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView textView = (TextView) findViewById(R.id.text0);
findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Cycle to next text size in {10, 30, 50}
textView.setText("Text Size " + mNextTextSize);
textView.append("\uFEFF"); // <--- THE FIX (see answer below)
textView.setTextSize(mNextTextSize);
// textView.requestLayout(); // does not help
// textView.invalidate(); // does not help
mNextTextSize = (mNextTextSize >= 50) ? 10 : (mNextTextSize + 20);
}
});
}
}
Main layout:
<?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="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click To Cycle Text Size" />
<TextView android:id="#+id/text0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dip"
android:background="#ffffff00"
android:text=""/>
</LinearLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.resize"
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=".ResizeTestActivity"
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>
Answering my own question. Apparantly this is a reported bug.
http://code.google.com/p/android/issues/detail?id=22493
Adding
tv.append("\uFEFF"); // zero width space
after setting the TextView text solves the problem.
Note: if you are using custom font, make sure it contains the \uFEFF character. If not, you may also have problems with single line ellipsis.
Add textView.requestLayout() or textView.invalidate() after setting the new text size. I'm fairly certain one of those should do the trick.

Unable to resolve activity for: Intent

I am having a problem in running Android unit test. I got this error when I tried to run a simple test.
Here's the log:
Blockquote
java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.wsandroid.Activities/.SplashActivity }
at android.app.Instrumentation.startActivitySync(Instrumentation.java:371)
at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:120)
at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:98)
at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:87)
at com.wsandroid.test.activity.TestEULA.setUp(TestEULA.java:15)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
This error occurs for Android less than 2.2. It works fine for Android 2.2 emulator. Yet Android 2.2 emulator has a bug of sending a key twice even though we only press it one. Application to be tested runs on Android 2.2 platform.
Appreciate if anyone of you can help me.
Dzung.
This can also be cause by a missing
Make sure you have a corresponding entry in your manifest.
<activity android:name=".SplashActivity" ...
I had a similar problem with a simple test project for an app that was just a splash screen. I found that I had implemented the constructor wrong. My initial implementation of the constructor was this...
public SplashScreenTest(){
super("com.mycomp.myapp.SplashScreen", SplashScreen.class);
}
After some beating my head against the wall, I somehow decided to remove the SplashScreen from the pkg argument of super(). My successful implementation is now like this...
public SplashScreenTest() {
super("com.mycomp.myapp", SplashScreen.class);
}
I hope that this helps you or others solve the problem.
Try to check your Manifest.xml file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tablet.test"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="android.test.runner" />
</application>
<uses-sdk android:minSdkVersion="8" />
<!-- This line below! -->
<instrumentation android:targetPackage="com.tablet.tablet"
android:name="android.test.InstrumentationTestRunner" />
</manifest>
You need to check the following line:
<instrumentation android:targetPackage="com.tablet.tablet"
android:name="android.test.InstrumentationTestRunner" />
So the targetPackage must be the same as in your code.
I had specific similar problem while using the AndroidAnnotations lib.
Later, I found out it was due to forgetting to use the generated class (MyActivity_ instead of MyActivity).
In my case the problem was that TestFragmentActivity, meaning the Activity used in our test
extends ActivityInstrumentationTestCase2<TestFragmentActivity>
must be available in the package defined in Manifest.xml as targetPackage:
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="de.my.androidhd" />
My solution was to move TestFragmentActivity into tested application package.
For the keys being sent twice issue, are you sure you're not now getting both the Down and Up actions? I had this issue when using Robotium, and generated this to make things easier:
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.widget.EditText;
import com.jayway.android.robotium.solo.Solo;
public static void type(Solo robot, EditText edit, String text) {
int index = 0;
//Find the index of this control, as Robotium doesn't seem to like R.id
for (int i = 0; i < robot.getCurrentEditTexts().size(); i++) {
if (robot.getCurrentEditTexts().get(i).getId() == edit.getId()) {
index = i;
}
}
robot.clickOnEditText(index);
KeyCharacterMap map = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
KeyEvent[] events = map.getEvents(text.toCharArray());
for (int event = 0; event < events.length; event++) {
if (events[event].getAction() == KeyEvent.ACTION_DOWN) {
robot.sendKey(events[event].getKeyCode());
}
}
}
I've had two activities with same name in different packages. Issue was about importing from the wrong package. I spend much time on it maybe it will save someone some time.

Categories

Resources