BlackBerry-how to change Manager background image? - user-interface

I am trying to create a tool bar with background color different from the screen background,
i am using the following code
getMainManager().add(mToolbarManager = new HorizontalFieldManager());
mToolbarManager.add(mBtn = new BitmapButtonField(mBmpNor, mBmpFoc,
mBmpAct));
Background bg = BackgroundFactory.createSolidBackground(Color.BLACK);
mToolbarManager.setBackground(bg);
mToolbarManager.add(mBtn = new BitmapButtonField(mBmpNor, mBmpFoc,
mBmpAct));
but it doesn't effect the background of toolbarmanager, while setting the background of mainmanager works fine

I got it , i used call HorizontalFieldManager constructor with USE_ALL_WIDTH parameter

hey i know 1 more way that i used:
class Mymanager extends Manager
{
final Bitmap back = Bitmap.getBitmapResource("back.png");
Mymanager ()
{
super(Manager.NO_VERTICAL_SCROLL);
}
public void paint(Graphics g)
{
g.drawBitmap(0,0,back.getWidth(),back.getHeight,back,0,0);
}
}
no add components to this manager

Related

PdfCleanUpTool SetRedactionColor

Is there a way to use PdfCleanUpTool so that the RedactionColor is transparent (i.e., it çshows the color of the actual background), instead of having to choose one.
I don't know why, but using PdfCleanUpTool.CleanUp() crashed (after adding the locations). However, this did the job (PdfCleaner.AutoSweepCleanUp):
public static void RemoveTexts(PdfDocument pdfDoc, List<Regex> regexes)
{
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
foreach (Regex rgx in regexes)
{
RegexBasedCleanupStrategy rbCS = new RegexBasedCleanupStrategy(rgx);
rbCS.SetRedactionColor(null);
strategy.Add(rbCS);
}
PdfCleaner.AutoSweepCleanUp(pdfDoc, strategy);
}

Is there a Xamarin Mvvmcross Android Shared Element Navigation example?

I'm trying to get this animation/transition working in my Xamarin Android application with Mvx.
I have a recyclerview with cards. When tapping on a card, I now call:
private void TimeLineAdapterOnItemClick(object sender, int position)
{
TimeLineAdapter ta = (TimeLineAdapter) sender;
var item = ta.Items[position];
int photoNum = position + 1;
Toast.MakeText(Activity, "This is photo number " + photoNum, ToastLength.Short).Show();
ViewModel.ShowDetails(item.Id);
}
I'm trying to find out how to translate this java navigation with transition to Xamarin with Mvvmcross:
ActivityOptionsCompat options =
ActivityOptionsCompat.MakeSceneTransitionAnimation(this, imageView, getString(R.string.activity_image_trans));
startActivity(intent, options.toBundle());
I know that within Mvx you can make use of custom presenters, but how do I get hold of, for example, the ImageView of the tapped Card within the RecyclerView which I would like to 'transform' to the new ImageView on the new Activity?
Thanks!
.
Is there a Xamarin Mvvmcross Android Shared Element Navigation
example?
I do not believe so.
I know that within Mvx you can make use of custom presenters, but how
do I get hold of, for example, the ImageView of the tapped Card within
the RecyclerView which I would like to 'transform' to the new
ImageView on the new Activity?
The easiest way that I can think of to achieve the sharing of control elements you want to transition is via the use of view tags and a presentation bundle when using ShowViewModel.
I would suggest making some changes to your Adapter Click handler to include the view of the ViewHolder being selected (See GitHub repo for example with EventArgs). That way you can interact with the ImageView and set a tag that can be used later to identity it.
private void TimeLineAdapterOnItemClick(object sender, View e)
{
var imageView = e.FindViewById<ImageView>(Resource.Id.imageView);
imageView.Tag = "anim_image";
ViewModel.ShowDetails(imageView.Tag.ToString());
}
Then in your ViewModel, send that tag via a presentationBundle.
public void ShowDetails(string animationTag)
{
var presentationBundle = new MvxBundle(new Dictionary<string, string>
{
["Animate_Tag"] = animationTag
});
ShowViewModel<DetailsViewModel>(presentationBundle: presentationBundle);
}
Then create a custom presenter to pickup the presentationBundle and handle the creating of new activity with the transition. The custom presenter which makes use of the tag to find the element that you want to transition and include the ActivityOptionsCompat in the starting of the new activity. This example is using a MvxFragmentsPresenter but if you are not making use of fragments and using MvxAndroidViewPresenter the solution would be almost identical (Override Show instead and no constructor required).
public class SharedElementFragmentsPresenter : MvxFragmentsPresenter
{
public SharedElementFragmentsPresenter(IEnumerable<Assembly> AndroidViewAssemblies)
: base(AndroidViewAssemblies)
{
}
protected override void ShowActivity(MvxViewModelRequest request, MvxViewModelRequest fragmentRequest = null)
{
if (InterceptPresenter(request))
return;
Show(request, fragmentRequest);
}
private bool InterceptPresenter(MvxViewModelRequest request)
{
if ((request.PresentationValues?.ContainsKey("Animate_Tag") ?? false)
&& request.PresentationValues.TryGetValue("Animate_Tag", out var controlTag))
{
var intent = CreateIntentForRequest(request);
var control = Activity.FindViewById(Android.Resource.Id.Content).FindViewWithTag(controlTag);
control.Tag = null;
var transitionName = control.GetTransitionNameSupport();
if (string.IsNullOrEmpty(transitionName))
{
Mvx.Warning($"A {nameof(transitionName)} is required in order to animate a control.");
return false;
}
var activityOptions = ActivityOptionsCompat.MakeSceneTransitionAnimation(Activity, control, transitionName);
Activity.StartActivity(intent, activityOptions.ToBundle());
return true;
}
return false;
}
}
GetTransitionNameSupport is an extension method that just does a platform API check when getting the TransitionName.
public static string GetTransitionNameSupport(this ImageView imageView)
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
return imageView.TransitionName;
return string.Empty;
}
The final step would be to register the custom presenter in you Setup.cs
protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
var mvxPresenter = new SharedElementFragmentsPresenter(AndroidViewAssemblies);
Mvx.RegisterSingleton<IMvxAndroidViewPresenter>(mvxPresenter);
return mvxPresenter;
}
You can check the repo on GitHub which demonstrates this example. The solution is designed so that the presenter does not have to care about the type of the control that is being transitioned. A control only requires a tag used to identify it. The example in the repo also allows for specifying multiple control elements that you want to transition (I did not want to include more complexity in the example above).

how to wait for the android activity to fully resume after calling ZXing qr scanner

I have an application which when starting requests a qr code from the user, and according to the qr scanned, a different fragment is loaded in the activity
I am using ZXing mobile scanner to do this
unfortunatelly the scanner returns a reply way before it shuts down and returns to the calling activity
this means that when I call the transaction code to replace the current fragment with the new one, the activity is not yet in the foreground so nothing happens
To solve this I created a ManualResetEvent (I'm using Xamarin, but I will use a Semaphore when I have to convert this to Android Studio) that I set before starting the scan , and then reset in the OnResume part of the activity
this seems to solve the problem, but it feels like there is a much better solution
Is there something I am missing?
thanks in advance for any help you can provide
Edit: the code I am currently using
public class MyActivity : Activity {
ManualResetEvent _has_resumed = new ManualResetEvent(false);
.....
protected override void OnResume() {
base.OnResume();
_has_resumed.Set();
}
......
void scan_qr(Action<string> finished_callback) {
#region initialize the scanner
MobileBarcodeScanner scanner = new MobileBarcodeScanner();
MobileBarcodeScanningOptions options = new MobileBarcodeScanningOptions();
options.UseNativeScanning = true; //use native scan
options.AutoRotate = false;//do not rotate the screen
options.PossibleFormats = new List<BarcodeFormat> { BarcodeFormat.QR_CODE }; // only allow qr_codes;
#endregion
#region perform the actual scan, when it finishes return to the main thread and execute the callback
_has_resumed.Reset();
scanner.Scan(this, options) //do scan
.ContinueWith(result => {
_has_resumed.WaitOne();
return result.Result;
})//wait until the activity has resumed
.ContinueWith((task_result) => { //then return the result
Result result = task_result.Result;
if (result == null) {
show_toast( Resource.String.questions_select_error_no_qr_scanned );
} else {
finished_callback(result.Text);
}
}, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
#endregion
}
}

set 2 images in gridview onitemclick

I am new to android and java world hardly 3 months working on it. Hence please help with me. I have gridview which display default images. My requirement is when user click on the item set product image for some time e.g. 2/3 seconds and again display default image. Please let me know how can I handle this. Sample code will be appreciated.
Currently I have following non working code which always show default image
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View imgView,
int position, long id) {
ImageAdapter adapter = (ImageAdapter) parent.getAdapter();
ImageView imageView = (ImageView) imgView;
imageView.setImageResource(R.drawable.productImage);
Thread.sleep(1000);
imageView.setImageResource(R.drawable.bg_default_card);
}
});
I found the workaround. I create object of Runnable and set image to default image in run method
I put following code in onItemClick event. I create one class level variable for imageview e.g. imgView1 assign the clicked image to imgView1 onItemClick event
//create runable object
Runnable r1 = new Runnable() {
public void run() {
//check imageView1 not null
if (imgView1 != null) {
//set image to default
imgView1.setImageResource(R.drawable.bg_default_card);
}
}
};
//call runnable after some interval
imgView1.postDelayed(r1, 500);
Thank you.

How can I add a button to the stage in flex using only as3?

I am using the Flex SDK within visual studio and trying to dynamically add a button to the stage. Here is a quick example of what I am doing.
public class Test extends Sprite
{
public function Test()
{
init();
}
private function init():void
{
var btnBrowse:Button = new Button();
btnBrowse.label = "Browse";
btnBrowse.x = 0;
btnBrowse.y = 0;
btnBrowse.width=100;
btnBrowse.height=100;
addChild(btnBrowse);
}
}
Nothing seems to show up and the screen is still empty. I am importing mx.controls.* for the button. Could that create an issue since I am not using mxml only as3?
You can't use Flex framework controls in an AS3 Only project. If you are trying to avoid MXML then just create a new Flex Project where the root tag is like:
<FooApplication xmlns="*"/>
And create a new AS3 Class like:
package {
import mx.core.Application;
public class FooApplication extends Application {
// now override something like createChildren to add a button.
}
}
Try changing the base class from Sprite to Canvas.

Resources