I tried to add Field.FOCUSABLE to my bitmap declaration
Bitmap _fire=Bitmap.getBitmapResource("fire.png",Field.FOCUSABLE);
But the method doesn't accept such arguments.
Any other possible way of making my display bitmap image in focus.
Try to use style in BitmapField:
BitmapField _fireField = new BitmapField(_fire, Field.FOCUSABLE) {
protected void onFocus(int direction) {
super.onFocus(direction);
Application.getApplication().invokeLater(new Runnable() {
public void run() {
Dialog.inform("Focus came to BitmapField");
}
});
}
};
Related
I have a loading gif for all backend requests. Prior to Charm 5.0.0, it worked fine in which the loading gif would show, backend would finish what it needed to, then the loading gif would be hidden. Now, the loading gif shows, but it doesn't hide.
addLayerFactory(LOADING_GIF, () -> new Layer() {
private final Node root;
private final double sizeX = getGlassPane().getWidth();
private final double sizeY = getGlassPane().getHeight();
{
ProgressIndicator loading = new ProgressIndicator();
loading.setRadius(50);
loading.setStyle("-fx-text-fill:white");
root = new StackPane(loading);
root.setStyle("-fx-background-color: rgba(0,0,0,0);");
getChildren().add(root);
this.setStyle("-fx-background-color:rgba(255,255,255,0.7)");
this.setShowTransitionFactory(v -> {
FadeInTransition ft = new FadeInTransition(v);
ft.setRate(2);
return ft;
});
}
#Override
public void show() {
this.setBackgroundFade(0.0);
super.show();
Layer pane = this;
Task<Integer> task = new Task<Integer>() {
#Override
protected Integer call() throws Exception {
int iterations = 0;
int max = DataService.readOutTime / 1000;
while (iterations <= max) {
Thread.sleep(1000);
iterations++;
}
Platform.runLater(new Runnable() {
#Override
public void run() {
if (pane.isVisible()) {
pane.setShowTransitionFactory(v -> {
FadeOutTransition ft = new FadeOutTransition(v);
ft.setRate(2);
return ft;
});
pane.hide();
MobileApplication.getInstance().showMessage("There was an error in sending your data.");
}
}
});
return iterations;
}
};
Thread thread = new Thread(task);
thread.start();
}
#Override
public void hide() {
this.setBackgroundFade(0.0);
super.hide();
}
#Override
public void layoutChildren() {
root.setVisible(isShowing());
if (!isShowing()) {
return;
}
root.resize(sizeX, sizeY);
resizeRelocate((getGlassPane().getWidth() - sizeX) / 2, (getGlassPane().getHeight() - sizeY) / 2, sizeX, sizeY);
}
});
I have a couple of utility methods that show and hide the loader:
public void showLoader() {
MobileApplication.getInstance().showLayer(App.LOADING_GIF);
}
public void hideLoader() {
MobileApplication.getInstance().hideLayer(App.LOADING_GIF);
}
Interestingly, the custom timeout I created (to hide the loader in case there is a stall in the backend) doesn't hide the layer either.
There is an issue with your code: you are overriding Layer::layoutChildren, but you are not calling super.layoutChildren().
If you check the JavaDoc:
Override this method to add the layout logic for your layer. Care should be taken to call this method in overriden methods for proper functioning of the Layer.
This means that you are getting rid of some important parts of the Layer control, such as animations, events and visibility control.
This should work:
#Override
public void layoutChildren() {
super.layoutChildren();
root.setVisible(isShowing());
if (!isShowing()) {
return;
}
root.resize(sizeX, sizeY);
resizeRelocate(getGlassPane().getWidth() - sizeX) / 2, getGlassPane().getHeight() - sizeY) / 2, sizeX, sizeY);
}
On a side note, for the hide transition, you should use setHideTransitionFactory.
So this is what I have done to solve this. From the Gluon Docs on the hide() method:
If this layer is showing, calling this method will hide it. If a hide transition is present, it is played before hiding the Layer. Care should be taken to call this only once LifecycleEvent.SHOWN has been fired.
Thus, I was realizing that the response from the backend was coming before the layer was fully shown. Thus, I modified the overridden hide() method as follows:
#Override
public void hide() {
if (this.isShowing()) {
this.setOnShown(e -> {
this.setBackgroundFade(0.0);
super.hide();
});
} else {
super.hide();
}
}
So if the layer is still in LifecycleEvent.SHOWING mode when being told to hide, make sure that it hides when it is shown. Otherwise it is already shown so hide it.
Is there a way to implement the Android.Views.SoftInput.AdjustResize to a specific page/control (e.g. a grid) rather than inserting it into App.xaml.cs or MainActivity.cs ?Since it is affecting my other pages when the keyboard is being shown.
Thanks!
I have solved my problem. What I did was to implement in on my page.xaml.cs on
protected override void OnAppearing()
{
base.OnAppearing();
App.Current.On<Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
}
This would resize your window when the keyboard is being shown when the page appears, and if you want to retain the normal behaviour of your Entry or other elements that will show your keyboard use this code:
protected override void OnDisappearing()
{
base.OnDisappearing();
App.Current.On<Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Pan);
}
The WindowSoftInputModeAdjust.Pan is the default behaviour of Android when a keyboard is being shown. This way when your page disappears, the settings will go back to default.
As supplement to #jbtamares' solution, I created an extension method which allows to easily revert to the original resize mode once the affected page disappears.
The extension method tracks the original resize modes once UseWindowSoftInputModeAdjust is called on the page. ResetWindowSoftInputModeAdjust reads the original resize mode and sets it accordingly.
This is the code of the extension method:
public static class PageExtensions
{
private static readonly IDictionary<Type, WindowSoftInputModeAdjust> OriginalWindowSoftInputModeAdjusts = new Dictionary<Type, WindowSoftInputModeAdjust>();
public static void UseWindowSoftInputModeAdjust(this Page page, WindowSoftInputModeAdjust windowSoftInputModeAdjust)
{
var platformElementConfiguration = Xamarin.Forms.Application.Current.On<Android>();
var pageType = page.GetType();
if (!OriginalWindowSoftInputModeAdjusts.ContainsKey(pageType))
{
var originalWindowSoftInputModeAdjust = platformElementConfiguration.GetWindowSoftInputModeAdjust();
OriginalWindowSoftInputModeAdjusts.Add(pageType, originalWindowSoftInputModeAdjust);
}
platformElementConfiguration.UseWindowSoftInputModeAdjust(windowSoftInputModeAdjust);
}
public static void ResetWindowSoftInputModeAdjust(this Page page)
{
var pageType = page.GetType();
if (OriginalWindowSoftInputModeAdjusts.TryGetValue(pageType, out var originalWindowSoftInputModeAdjust))
{
OriginalWindowSoftInputModeAdjusts.Remove(pageType);
var platformElementConfiguration = Xamarin.Forms.Application.Current.On<Android>();
platformElementConfiguration.UseWindowSoftInputModeAdjust(originalWindowSoftInputModeAdjust);
}
}
}
And here is how you apply it in the page:
public partial class LoginPage : ContentPage
{
public LoginPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
this.UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
}
protected override void OnDisappearing()
{
base.OnDisappearing();
this.ResetWindowSoftInputModeAdjust();
}
}
Hope this helps. Let me know if you find any problems with the code posted above.
But the image is still in orginal shape. Any solution? Please look at the codes
CircularView circularimage1= (CircularView)findViewById(R.id.customView);
Glide.with(this.getApplicationContext()).load(R.drawable.picture1)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new ViewTarget<CircularImageView, GlideDrawable>(circularimage1) {
#Override
public void onResourceReady(GlideDrawable resource, GlideAnimation anim) {
CircularView myView = this.view;
// Set your resource on myView and/or start your animation here.
Log.e(TAG, "onResourceReady: "+myView.getBorderWidth() );
myView.setImageDrawable(resource.getCurrent());
myView.setBorderWidth(2);
Log.e(TAG, "onResourceReady: "+myView.getBorderWidth() );
myView.setBorderColor(R.color.yellow);
}
});
#Override
public void getSize(SizeReadyCallback cb) {
//You can pass whatever width/height value you want using the following function
cb.onSizeReady(....)
}
You need to override the getSize() function
can anyone help me for solving the below question.
I am making an application for blackberry in that from one bitmapField i have to invoke a new screen by clicking on the bitmapField. I want the code for the same... how to invoke a new screen by clicking on a bitmapField... and i am using blackberry JDE 4.7
Try making the BitmapField focusable
BitmapField bm = new BitmapField(bitmap, BitmapField.FOCUSABLE);
This might help
BitmapField bmpField = new BitmapField(bitmap, BitmapField.FOCUSABLE)
protected boolean navigationClick(int status, int time)
{
if(bmpField.isFocus)
{
UiApplication.getUiApplication().pushScreen(new MyScreen());
}
return true;
}
}
i have used on a Storm and it works.
If even this does not work, u can go ahead and use touchEvent instead of navigationClick
This must work
BitmapField bmpField = new BitmapField(bitmap, BitmapField.FOCUSABLE){
protected void drawFocus(Graphics graphics, boolean on){
//the simplies way to draw a rectangle and this will be the focus
}
protected boolean navigationClick(int status, int time)
{
//write here your code what you want to run the user clicks to the bitmap
//try something like this
UiApplication.getUiApplication().pushScreen(new MyScreen());
return true;
}
}
I have custom drawn fields which are focusable.
Normally the default focus color is Blue which obviously doesn't match to every theme.
So can you give me efficient or non efficient ideas to change the color of the focus?
Thanks
Why don't you use skin or even custom drawing? Also remember to
check getVisualState() == VISUAL_STATE_FOCUS
remember to override and supress applyTheme method
alt text http://img515.imageshack.us/img515/4286/checkfocus.jpg
class FCheckBoxField extends CheckboxField {
public FCheckBoxField(String label, boolean value) {
super(label, value);
}
protected void paint(Graphics g) {
if (getVisualState() == VISUAL_STATE_FOCUS) {
int c = g.getColor();
g.setColor(Color.CRIMSON);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(c);
}
super.paint(g);
}
protected void applyTheme(Graphics arg0, boolean arg1) {
}
}