I want to add a button to MediaController. So I extended MediaController class, created a button and added it into the frame layout. But the newly added button is not reflecting while running.
Please find the code below
public class VideoController extends MediaController {
private Button searchButton;
public VideoController(Context context) {
super(context);
searchButton = new Button(context);
searchButton.setText("Search");
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.RIGHT;
System.out.println("Adding a button");
addView(searchButton, params);
//updateViewLayout(this, params);
}
#Override
public void hide() {
}
}
what I am doing wrong here. Any suggestions will be helpful.
Thanks in advance.
You have to override setAnchorView in your VideoController class:
#Override
public void setAnchorView(View view) {
super.setAnchorView(view);
Button searchButton = new Button(context);
searchButton.setText("Search");
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.RIGHT;
addView(searchButton, params);
}
Actually that happens because media controller's view is constructed later (in makeControllerView method). So you need to override it and add button there.
Unfortunately, it is hidden at the moment. And overriding setAnchorView seems the best solution.
Related
I'm using
SKStoreReviewController.RequestReview ();
in a dependency service for Xamarin.Forms. However this is now deprecated from iOS 14. And I want to know how to integrate with the new
UIWindowScene
requestReview(in windowScene: UIWindowScene)
in Xamarin.Forms
First, you can try to add SKStoreReviewController.RequestReview(Window.WindowScene) in the FinishedLaunching method of your xxx.ios->AppDelegate.cs; start the project to see if it is correct.
If the above method goes wrong, using DependencyService is the right way to go.
Here is the interface code:
public interface MyInterface
{
void RequestReview();
}
Here is the implementation method of the interface in ios:
[assembly: Dependency(typeof(MyInterfaceImpl))]
namespace App19.iOS
{
public class MyInterfaceImpl : MyInterface
{
public void RequestReview()
{
var myv = UIDevice.CurrentDevice.CheckSystemVersion(14, 0);
if (myv)
{
UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow();
SKStoreReviewController.RequestReview(window.WindowScene);
}
else
{
SKStoreReviewController.RequestReview();
}
}
}
}
You can call it in the OnStart method inside APP.xaml.cs:
protected override void OnStart()
{
if (Device.RuntimePlatform == Device.iOS)
{
DependencyService.Get<IReviewService>().RequestReview();
}
}
I might have a solution:
using StoreKit;
using UIKit;
public void RequestReview(){
var scene = UIApplication.SharedApplication.KeyWindow.WindowScene;
if (scene is null)
{
//handle the scene being null here
return;
}
SKStoreReviewController.RequestReview(scene);
}
I've found multiple ways of getting the current scene and they both worked when I tested them:
var scene = UIApplication.SharedApplication.KeyWindow.WindowScene;
var alsoScene = UIApplication.SharedApplication.Delegate.GetWindow()?.WindowScene;
You can read more about the difference between the two in this issue
The complete solution where you check the iOS version in order to call the right thing might look like this
using StoreKit;
using UIKit;
public void RequestReview()
{
var isIos14OrAbove = UIDevice.CurrentDevice.CheckSystemVersion(14, 0);
if (isIos14OrAbove)
{
var scene = UIApplication.SharedApplication.KeyWindow.WindowScene;
if (scene is null)
{
//handle the scene being null here
return;
}
SKStoreReviewController.RequestReview(scene);
}
else
{
SKStoreReviewController.RequestReview();
}
}
Hope this helps.
I want my dialog to stick to the start but it always comes in the center.
i will give you example==>
Following is the code -->Onclick image -->Dialog Appears==>
Dialog dialog; //your dialog declaration
//
//
//
oncreate(){
imageView = (ImageView) findViewById(R.id.customProfileGridImg);
dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.activity);
Window window = dialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.START |Gravity.TOP; //change direction as per your requirement
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.show();
}
});
}
I want to wait until "next" button is pressed then continue
child.addChild(tmp);
childrenAdded.Push(tmp);
neighbor.GetComponent.<Renderer>().material.mainTexture = null;
-WAIT UNTIL CLICK ON NEXT BUTTON THEN CONTINUE-
toExpand.Push(tmp);
any idea? I tried:
while(true) {
if(GUI.Button(Rect(500,680 ,100,30),"Next"))
break
}
But it doesn't work; it freezes.
Instead of waiting, you can just have your code called when the button is clicked, like this:
void OnGUI() {
if(GUI.Button(Rect(500,680 ,100,30),"Next"))
toExpand.Push(tmp);
}
}
If possible, consider using Unity 4.6 or later so you can use the new UI which is much easier work with.
You can use Toggle button instead of button so you controll a boolean with toogle and loops what you need in your Update or LateUpdate function like this:
private Rect myRect = new Rect(500,680 ,100,30);
private bool myToggle = false;
void OnGui() {
myToggle = GUI.Toogle(myRect, myToggle, "Next");
}
void Update() {
if(myToggle){
// what I need to create while true;
}
}
Note that is not a good practice to create a new Rect every OnGUI cycle because it runs more than once per frame and it will create a performance issue.
Reading your code again may I could've misinterpreted your needing so if you could clarify what you really what your code to do would be easier to help.
Also, if you just need a "wizard" like sequence of actions I suggest you to take a look on delegates and use something like this:
delegate void MyDelegate();
private MyDelegate myDelegate;
private Rect myRect = new Rect(500,680 ,100,30);
void Start () {
myDelegate = FirstFunction;
}
void FirstFunction() {
// will execute until next button is clicked
}
void SecondFunction() {
// will execute after next button is clicked
}
void OnGui() {
if(GUI.Button(myRect, "Next")) {
myDelegate = SecondFunction;
}
}
I am programatically showing the soft keyboard when a layout is loaded on a button click.
I am showing the softkeyboard only when the textfield has focus. It works fine. But when I call the same method at another place in the code(not a button click) then the soft keyboard does not show up. Below is my code. Please point out where I went wrong.
public void showNewView() {
setContentView(R.layout.activity_main);
this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
isRegisterScreen = true;
final EditText text1 = (EditText) findViewById(R.id.label1);
final EditText text2 = (EditText) findViewById(R.id.label2);
final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
text1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
inputManager.showSoftInput(labelText, InputMethodManager.SHOW_IMPLICIT);
}else{
inputManager.hideSoftInputFromWindow(text1.getWindowToken(), 0);
}
}
});
text2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
inputManager.showSoftInput(text2, InputMethodManager.SHOW_IMPLICIT);
}else{
inputManager.hideSoftInputFromWindow(phoneText.getWindowToken(), 0);
}
}
});
text1.requestFocus();
}
I am developing a GWT application that render a text on a canvas. I want to resize the canvas whenever browser window resized. The problem is if I used Window.addResizeHandler, the rendering process with each resize will be very slow. So I need a way to resize the canvas only when the user release the mouse button after finishing resize. Is there anyway to do that?
You could add a delay, so that the resize is only processed after the window hasn't been resized for some number of milliseconds:
Window.addResizeHandler(new ResizeHandler() {
Timer resizeTimer = new Timer() {
#Override
public void run() {
doComplexLayoutCalculations();
}
};
#Override
public void onResize(ResizeEvent event) {
resizeTimer.cancel();
resizeTimer.schedule(250);
}
});
Window.addResizeHandler(new ResizeHandler() {
#Override
public void onResize(ResizeEvent event) {
Scheduler.get().scheduleDeferred(
new Scheduler.ScheduledCommand() {
public void execute() {
// layout stuff
}
});
}
});