I would like to work out what is required to make a simple standard table in a native android app compliant to WCAG 2.0.
I thinking about the requirement 1.3.1 Info and Relationships: Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text. (Level A)
I habe specially poblems with the requirememt of having headers in tables. I even don't know whether it is possible to reach this aim.
For a example of a simple table I took this one https://developer.android.com/guide/topics/ui/layout/grid.html
Thanks in advance.
Best regards
Petra Ritter, accessibility consultant, Foundation access for all
http://www.access-for-all.ch/en/
It is very simple.
Declare a Popupwindow and View as below.
PopupWindow layoutWindow;
View javaLayoutView;
JavaClassName _activity = this;
Write a Java Void method.
In this method add code below.
below will increase speed. if PopupWindow has a somthing method will not go longer else will go further.
if(layoutWindow != null)
return;
Assiggn Activity to this thread.
_activity = this;
Calling the method from Native side will not run directly because our activity is Native Activity since. So it will execute in Ui Thread.
this.runOnUiThread(new Runnable(){
#Override
public void run(){
// Make a Inflator Layout. Our XML Layout will work on this.
LayoutInflater lF =
(LayoutInflator)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
javaLayoutView = lF.inflate(R.layout.layoutfile, null);
layoutWindow = new PopupWindow( javaLayoutView, LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
LinearLayout mainLayout = new LinearLayout(_activity);
MarginLayoutParams params = new
MarginLayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
params.setMargin(0, 0, 0, 0);
_activity.setContentView(mainLayout, params);
layoutWindow.showAtLocation(mainLayout, Gravity.TOP, 0, 0);
layoutWindow.update();
}
});
Here your layout file will be executed on LinearLayout doesn't matter what layout you used in XML. Here by changing LayoutParams.MATCH_PARENT you can change the width and height.
The line layoutWindow.showAtLocation(mainLayout, Gravity.TOP, 0, 0); will make render your layout over Native Activity,
Remember that If you change anything after layoutWindow.update() must recall it to take effect.
This will damn sure work !!!
Related
I'm trying to make my own basic 'help overlay'. I have achieved this much so far
this was done by calling the addContentView with an instance of a custom view passed in. However i will only be able to hide the custom view instead of completely removing it after I am done with it.
It is very basic so far so there is no flair or pizazz yet. I am trying to further improve its ease of use. https://stackoverflow.com/a/10217050/3194316 this stack overflow answer suggests setting the content view to a dynamically created Framelayout and inflating the views. I have added the code
FrameLayout layout = new FrameLayout((Context) activity);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
layout.setLayoutParams(layoutParams);
View parentView = activity.getWindow().getDecorView().findViewById(android.R.id.content);
((ViewGroup) parentView.getParent()).removeAllViews();
activity.setContentView(layout);
layout.addView(parentView);
layout.addView(this);
where this is an instance of the custom view that sets the overlay shown below. activity is an instance of the activity in which this is presented in. I was at first getting an error that the parentView already had a parent, so this is why View parentView = activity.getWindow().getDecorView().findViewById(android.R.id.content);
((ViewGroup) parentView.getParent()).removeAllViews(); was added. I am now unforunately receiving a stack overflow error, and I cannot seem to understand why. Is there a better approach to this situation?
SOLUTION
Wrapping everything in a popup window allows the entire overlay to be dismissed properly by the android System.
FrameLayout layout = new FrameLayout(context.get());
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
layout.setLayoutParams(layoutParams);
LayoutInflater inflater = (LayoutInflater) context.get().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View overlayBase = inflater.inflate(R.layout.help_frame, null, false);
layout.addView(this);
layout.addView(overlayBase);
popupWindow = new PopupWindow(context.get());
popupWindow.setContentView(layout);
popupWindow.setWindowLayoutMode(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
popupWindow.showAtLocation(this, Gravity.CENTER, 0, 0);
context was a class level WeakReference variable for the custom view, instantiated when the constructor was called
In case anyone is interested, here is the code I used to create the popupwindow
Here is the (not final) result
If you want a dynamically appearing View anchored to another View you should use a PopupWindow
Is there a simple example of the PopupWindow class using Android v2.0?
I'm trying to show a simple prompt dialog fragment programatically. I've extended SherlockFragmentActivity, and coded a custom SherlockDialogFragment implementation in it.
(I'm using ActionbarSherlock library, but I think the problem doesn't have to do with it, and would also be observed using regular ActionBar and Fragments).
This is the overriden oncreateDialog method inside the custom FragmentActivity class:
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
//Skipped section. Setting positive, negative buttons, title, message on builder.
efPsw = new EditText(getActivity());
// Hacky margin stuff (yeah, I know it's dirty)
DisplayMetrics displaymetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int smallestSide = Math.min(displaymetrics.heightPixels, displaymetrics.widthPixels);
int margin = (int)(0.5 * ((double) smallestSide));
efPsw.setTransformationMethod(PasswordTransformationMethod.getInstance());
FrameLayout fl = new FrameLayout(getActivity());
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(margin, 0, margin, 0);
fl.addView(efPsw, layoutParams);
builder.setView(fl);
return builder.create();
}
When I show the fragment, the inner framelayout is not shown (looks like an invisible rectangle that grows in height with each typed character). I'm not sure what am I doing wrong here, but certainly something must be wrong, since if I put the edittext in setView everything works fine (but without margin).
Thanks in advance.
it looks like you are making the margin half the smallest side, which in portrait mode would make your margin the entire screen. i would start by reducing the margin.
you can apply the margins directly to the EditText using the setLayoutParams() method. That would eliminate the FrameLayout.
I am currently playing an rtsp live streaming source using a VideoView. This works fine.
The VideoView is initially inside a fragment with other elements, in 'normal' state, and I am trying to implement a fullscreen toggle button.
To go to fullscreen mode, I am removing the VideoView from its parent (a LinearLayout), and then adding it to another LinearLayout, added on top of everything else using getActivity().addContentView(), here's the code:
LayoutInflater lf = getActivity().getLayoutInflater();
vFullScreen = lf.inflate(R.layout.full_screen, myViewGroup, false);
LinearLayout fullscreenCont = (LinearLayout) vFullScreen.findViewById(R.id.fullscreen_container);
((ViewGroup) vsPlayer.getParent()).removeView(vsPlayer);
fullscreenCont.addView(vsPlayer);
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
getActivity().addContentView(vFullScreen, params);
The problem is that the video goes black once it's removed from the original parent view.
What I'm trying to achieve it's to preserve the video instance to avoid having to reconnect/buffer again, but I don't know how to preserve the video playback during this switching of parents, any ideas?
EDIT:
If I suspend the videoView and then resume it, like this:
LayoutInflater lf = getActivity().getLayoutInflater();
vFullScreen = lf.inflate(R.layout.full_screen, myViewGroup, false);
LinearLayout fullscreenCont = (LinearLayout) vFullScreen.findViewById(R.id.fullscreen_container);
vsPlayer.getVideoView().suspend();
((ViewGroup) vsPlayer.getParent()).removeView(vsPlayer);
fullscreenCont.addView(vsPlayer);
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
getActivity().addContentView(vFullScreen, params);
vsPlayer.getVideoView().resume();
the video play is interrupted (goes black for a few noticeable seconds) but then resumes, wich is a lot better, not perfect because it takes too long to resume play.
Another not so good part is that the methods suspend() and resume() of the class VideoView are available from API level 8 and up, and I need to be compatible with API level 7
Is your problem that the VideoView you're using goes black and temporarily lingers in between the switching of the views?
If so, I've been trying to figure out the cause of that issue for a solid week now. I haven't been able to figure out the actual cause, but my workaround does prevent the VideoView from persisting through screen changes:
public void hideVideoView(){
runOnUiThread(new Runnable() {
public void run() {
findViewById(R.id.yourVideoView).setVisibility(View.INVISIBLE);
}
});
}
I'm basically just setting the view to invisible whenever the view gets switched, and if the view is reloaded I just set it back to View.Visible
This probably won´t :) resolve your problem, but you could seek to the position you where at before removing the VideoView:
long progress = vsPlayer.getCurrentPosition();
LayoutInflater lf = getActivity().getLayoutInflater();
vFullScreen = lf.inflate(R.layout.full_screen, myViewGroup, false);
LinearLayout fullscreenCont = (LinearLayout) vFullScreen.findViewById(R.id.fullscreen_container);
((ViewGroup) vsPlayer.getParent()).removeView(vsPlayer);
fullscreenCont.addView(vsPlayer);
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
getActivity().addContentView(vFullScreen, params);
vsPlayer.seekTo(progress);
I actually had the same issue some time ago.. What i ended up doing was to change the layoutparams of the VideoView to match_parent instead of removing it.
mVideoView.getLayoutParams().width = LayoutParams.MATCH_PARENT;
mVideoView.getLayoutParams().height = LayoutParams.MATCH_PARENT;
I want to know is there any way to use native TextView or any other layout of android inside BaseAndEngine Activity.
My application is using Andengine for one of its whole screen. This screen is extended from BaseAndEngine and I need to use some native view like textview inside that screen. Because Andengine does not work fine for Arabic text and I need to show some Arabic text on gaming screen.
OR if possible how to show Arabic text in changeable text in Andengine. As changeable text write Arabic from left to right in reverse order.
Of course you can.
Check this code out - basically you override onSetContentView, then you can set whatever you want.
#Override
protected void onSetContentView() {
final FrameLayout frameLayout = new FrameLayout(this);
final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT);
this.mRenderSurfaceView = new RenderSurfaceView(this);
mRenderSurfaceView.setRenderer(mEngine);
final FrameLayout.LayoutParams surfaceViewLayoutParams = new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
//Create any other views you want here, and add them to the frameLayout.
this.setContentView(frameLayout, frameLayoutLayoutParams);
}
(This method goes to your subclass of BaseGameActivity.)
You could also do it through xml, but I think this method is more clear.
You can use Andengine for Arabic and Persian fonts too. But in a different manner. to do that you need to create a Sprite and add a bitmap to it. before that you draw your text on that bitmap.
the following code is an example that draw the Persian/Arabians text and attach it to a sprite. so we can attach the sprite to our scene.
this is an example to show how we can do that, so you can adjust the bitmap and text size by yourself.
if your device support Persian/Arabians, this code will work properly. if the text does not appear in your scene, change its position, it is out of screen
the example code function will print the "Persian Golf" in Persian/Arabians.
private void persianGolfPrinter(){
BitmapTextureAtlas mBitmapTextureAtlas = new BitmapTextureAtlas(ResourceManager.getInstance().gameActivity.getTextureManager(), 400, 800, TextureOptions.BILINEAR);
ITextureRegion mDecoratedBalloonTextureRegion;
final IBitmapTextureAtlasSource baseTextureSource = new EmptyBitmapTextureAtlasSource(400, 800);
final IBitmapTextureAtlasSource decoratedTextureAtlasSource = new BaseBitmapTextureAtlasSourceDecorator(baseTextureSource) {
#Override
protected void onDecorateBitmap(Canvas pCanvas) throws Exception {
this.mPaint.setColor(Color.BLACK);
this.mPaint.setStyle(Style.FILL);
this.mPaint.setTextSize(32f);
this.mPaint.setTextAlign(Align.CENTER);
pCanvas.drawText("خلیج فارس", 150, 150, this.mPaint);
}
#Override
public BaseBitmapTextureAtlasSourceDecorator deepCopy() {
throw new DeepCopyNotSupportedException();
}
};
mDecoratedBalloonTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromSource(mBitmapTextureAtlas, decoratedTextureAtlasSource, 0, 0);
mBitmapTextureAtlas.load();
Sprite test = new Sprite(0,0,mDecoratedBalloonTextureRegion,ResourceManager.getInstance().engine.getVertexBufferObjectManager());
this.attachChild(test);
}
don't use android textview... it makes your game ugly ....
You cannot use them directly in AndEngine, because the objects in Andengine are OpenGL objects. But you can use android OS to draw a bitmap of any standard view, and then create a texture and a sprite from that view. This is less than optimum for a case such as arabic text, but it will work. Be careful about memory leaks as you create the bitmaps of your views.
I want to create a relative Layout dynamically through code with 2 Textviews one below the other.How to implement android:layout_below property through code in Android.
can anyone help me in sorting out this issue.
Thanks in Advance,
final TextView upperTxt = (...)
upperTxt.setId(12345);
final TextView lowerTxt = (...);
final RelativeLayout.LayoutParams params = RelativeLayout.LayoutParams(this, null);
params.addRule(RelativeLayout.BELOW, 12345);
lowerTxt.setLayoutParams(params);
Here is my solution for my special Problem.
In case the username wouldn't be found in the db i had to create a RelativeLayout that looks like the xml-generated one.
// text view appears on top of the edit text
enterNameRequest = new TextView(mainActivity.getApplicationContext());
// fill the view with a string from strings.xml
enterNameRequest.setText(mainActivity.getResources().getString(R.string.enterNameRequest));
// edit text appears below text view and above button
enterName = new EditText(mainActivity.getApplicationContext());
enterName.setId(667);
// button appears at the bottom of the relative layout
saveUserName = new Button(mainActivity.getApplicationContext());
saveUserName.setText(mainActivity.getResources().getString(R.string.useUserName));
saveUserName.setId(666);
// generate the relative layout
RelativeLayout layout = new RelativeLayout(mainActivity.getApplicationContext());
layout.setId(668);
// set a background graphic by its id
layout.setBackgroundDrawable(mainActivity.getApplicationContext().getResources().getDrawable(R.drawable.background_head_neutral));
// runtime told me that i MUST use width and height parameters!
LayoutParams params2 = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params2.addRule(RelativeLayout.ABOVE, 666);
enterName.setLayoutParams(params2);
LayoutParams params3 = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params3.addRule(RelativeLayout.ABOVE, 667);
enterNameRequest.setLayoutParams(params3);
LayoutParams params4 = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params4.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 668);
saveUserName.setLayoutParams(params4);
// add views
layout.addView(enterNameRequest);
layout.addView(enterName);
layout.addView(saveUserName);
/* todo: set button action */
mainActivity.setContentView(layout);
What i found out additionally:
It is not so good to manipulate the layout manually from within java!
You should better use a new Activity and set a new layout in it.
This way, the application-code is readable a lot better!
I even tried to set several layouts (not manually, but wit setContentView) in one activity, and it turned out that i didn't know where what was accessing what else... Also, i had a great problem in adding onClickListeners... so you better use -- android:onClick="myButtonMethod" -- in your button tag in the xml and have a method in your according activity, which uses the layout, like this:
public void myButtonMethod(View v){
// do stuff
}
This improves performance because you are not using additional Listeners - but you use the already available Listener that is bound to your activity in every case.
u can try this
LinearLayout.LayoutParams leftMarginParams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);``
leftMarginParams.leftMargin = 50;
Button btn1 = new Button(this);
btn1.setText("Button1");
linLayout.addView(btn1, leftMarginParams)