In my app, I have added a settings tab like this.
internal static class AccountSettings
{
public static void Initialise()
{
SettingsPane settingsPane = SettingsPane.GetForCurrentView();
settingsPane.CommandsRequested += settingsPane_CommandsRequested;
}
private static void settingsPane_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
SettingsCommand accountSettings = new SettingsCommand("accSettings", "Account Settings", (uiCommand) =>
{
ShowSettingsPanel();
});
args.Request.ApplicationCommands.Add(accountSettings);
}
private static void ShowSettingsPanel()
{
var flyout = new SettingsFlyout();
flyout.Title = "Account Settings";
flyout.Content = new AccountSettingsPage();
flyout.Show();
}
}
and I am calling
AccountSettings.Initialise()
from App.xaml.cs
It adds this tab in the setting but by default there is one Permissions tab already added which shows the app permissions. How can I remove this permissions tab?
You cannot remove Permission from Settings flyout. You can only add your custom commands to it.
Related
I'm newbie in android and I'm trying to develop some applications. But last two weeks I've been stuck in this code. In short, I have two buttons in a layout. These buttons are Add and delete button. If I clicked the add button, add will be disabled and delete will be enabled. Or if I clicked the delete, delete will be disabled add will be enabled. I want to save state of these two buttons (which one is clicked) and get the last clicked state on create. But the problem is it's not working. When I open the app both buttons are show disable state. Or not saving either. Never working.
public class UserVideoInfoActivity2 extends AppCompatActivity {
SharedPreferences.Editor editor;
SharedPreferences preferences;
SharedPreferences.Editor editor2;
SharedPreferences preferences2;
Button buttonadd;
Button buttondelete;
private static final String ADD = "ADD_KEY";
private final static String DELETE = "DELETE_KEY";
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_video_info_layout_2);
buttonadd = (Button) findViewById(R.id.buttonaddlayout);
buttondelete = (Button) findViewById(R.id.buttondeletelayout);
preferences = getSharedPreferences(ADD, Context.MODE_PRIVATE);
preferences2 = getSharedPreferences(DELETE, Context.MODE_PRIVATE);
buttonadd.setEnabled(GetState());
buttondelete.setEnabled(GetState2());
buttonadd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
buttonadd.setEnabled(false);
buttondelete.setEnabled(true);
SaveState(buttonadd.isEnabled());
}
});
buttondelete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
buttonadd.setEnabled(true);
buttondelete.setEnabled(false);
SaveState2(buttondelete.isEnabled());
}
});
}
private void SaveState(boolean isChecked) {
editor = preferences.edit();
editor.putBoolean(ADD, isChecked);
editor.commit();
}
private void SaveState2(boolean isChecked2) {
editor2 = preferences2.edit();
editor2.putBoolean(DELETE, isChecked2);
editor2.commit();
}
public boolean GetState() {
return preferences.getBoolean(ADD, false );
}
public boolean GetState2() {
return preferences2.getBoolean(DELETE, false);
}
}
<Button
android:id="#+id/buttondeletelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="delete" />
I have a page called MapPage.xaml and a code behind called MapPage.xaml.cs. In my android project, I have another file called CustomMapRenderer.cs. In the CustomMapRenderer.cs file, I need to retrieve the item selected variable in a XAML picker found in my MapPage.xaml file, which changes when a user picks an option in my XAML picker.
How to I reference the picker from my CustomMapRenderer.cs?
In the CustomMapRenderer.cs file, I need to retrieve the item selected variable in a XAML picker found in my MapPage.xaml file, which changes when a user picks an option in my XAML picker.
If you followed the official doc Customizing a Map to create your CustomMapRenderer, then in PCL, there should be a class which inherits from Map, for example:
public class CustomMap : Map
{
}
Then, if your picker is another control in your MainPage, you can create a bindable property for your CustomMap, and override OnElementPropertyChanged in your renderer to get this property when it changed.
For example, in PCL:
public class MapWithMyZoomControl : Map
{
public ZoomState MyZoom
{
get { return (ZoomState)GetValue(MyZoomProperty); }
set { SetValue(MyZoomProperty, value); }
}
public static readonly BindableProperty MyZoomProperty =
BindableProperty.Create(
propertyName: "MyZoom",
returnType: typeof(ZoomState),
declaringType: typeof(MapWithMyZoomControl),
defaultValue: ZoomState.normal,
propertyChanged: OnZoomPropertyChanged);
public static void OnZoomPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
}
public enum ZoomState
{
normal,
zoomin,
zoomout
}
}
And in its renderer:
public class MapWithMyZoomControlRenderer : MapRenderer, IOnMapReadyCallback
{
private GoogleMap map;
public void OnMapReady(GoogleMap googleMap)
{
map = googleMap;
map.UiSettings.ZoomControlsEnabled = false;
}
protected override void OnElementChanged(ElementChangedEventArgs<Map> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
// Unsubscribe
}
if (e.NewElement != null)
{
var formsMap = (MapWithMyZoomControl)e.NewElement;
((MapView)Control).GetMapAsync(this);
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
var element = Element as MapWithMyZoomControl;
if (e.PropertyName == "MyZoom" && map != null)
{
if (element.MyZoom == MapWithMyZoomControl.ZoomState.zoomin)
{
map.AnimateCamera(CameraUpdateFactory.ZoomIn());
}
else if (element.MyZoom == MapWithMyZoomControl.ZoomState.zoomout)
{
map.AnimateCamera(CameraUpdateFactory.ZoomOut());
}
element.MyZoom = MapWithMyZoomControl.ZoomState.normal;
}
}
}
Out of this map control, I use buttons to control to zoom the map:
map.MyZoom = MapWithMyZoomControl.ZoomState.zoomin;
It'a a demo, but you can modify it to make property connected to your picker.
What I'm trying to do is change the default backgrounds of a custom DialogFragment that I have written. Normally, I would do this by changing the XML layout file, however, for a DialogFragment these buttons don't exist in the layout file.
In essence, I'm trying to get access to the setPositiveButton, setNegativeButton and setNeutral buttons in order to modify them. Alternatively, I would next try to do this by getting them by id, however, since they aren't defined in a layout file, I do not have a corresponding id for them. I've found plenty examples of how to modify the rest of the layout, but I can't find anywhere that positive/neutral/negative buttons are modifiable.
Ideally, I could do this in the following block of code:
.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
...
}
})
Thanks in advance.
Here is the code ... The button instance is valid only after the dialog created. Hope this helps you.
public static class CustomDialog extends DialogFragment
{
public static CustomDialog newInstance()
{
return new CustomDialog();
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
super.onCreateDialog(savedInstanceState);
Builder builder = new AlertDialog.Builder(getActivity());
AlertDialog dialog = builder.create();
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK",new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "CANCEL",new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
return dialog;
}
#Override
public void onStart()
{
super.onStart();
Button pButton = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
Button nButton = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_NEGATIVE);
pButton.setBackgroundColor(getResources().getColor(R.color.Blue));
nButton.setBackgroundColor(getResources().getColor(R.color.Green));
}
}
I am new to eclipse plugin and SWT. I am designing a view part with some functionalities.
But the only problem is that I have to Launch it as a eclipse plugin to check.
Is there any way that we can call this from that main(String[] args) method?
I am posting my sample viewpart code
public class View extends ViewPart {
public static Display display=new Display();
public static final String ID = "Test.View"; //$NON-NLS-1$
private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
public View() {
}
/**
* Create contents of the view part.
* #param parent
*/
#Override
public void createPartControl(Composite parent) {
Composite container = toolkit.createComposite(parent, SWT.NONE);
toolkit.paintBordersFor(container);
{
Label lblNewLabel = new Label(container, SWT.NONE);
lblNewLabel.setBounds(25, 46, 49, 13);
toolkit.adapt(lblNewLabel, true, true);
lblNewLabel.setText("New Label");
}
Spinner spinner = new Spinner(container, SWT.BORDER);
spinner.setBounds(88, 105, 47, 21);
toolkit.adapt(spinner);
toolkit.paintBordersFor(spinner);
DragSource dragSource = new DragSource(container, DND.DROP_MOVE);
DropTarget dropTarget = new DropTarget(container, DND.DROP_MOVE);
Canvas canvas = new Canvas(container, SWT.NONE);
canvas.setBounds(94, 161, 174, 148);
toolkit.adapt(canvas);
toolkit.paintBordersFor(canvas);
createActions();
initializeToolBar();
initializeMenu();
}
public void dispose() {
toolkit.dispose();
super.dispose();
}
/**
* Create the actions.
*/
private void createActions() {
// Create the actions
}
/**
* Initialize the toolbar.
*/
private void initializeToolBar() {
IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
}
/**
* Initialize the menu.
*/
private void initializeMenu() {
IMenuManager manager = getViewSite().getActionBars().getMenuManager();
}
#Override
public void setFocus() {
// Set the focus
}
Can I write something like
public static void main(String[] args){
View v=new View();
Shell shell=new Shell(display);
v.createPartControl(shell);
}
Not really, Eclipse views are part of RCP and depend on a its infrastructure. You can create a small RCP application which only shows your view instead.
Having public static Display display=new Display(); in your view is completely wrong! There is certainly a Display already by the time your code runs, which can be accessed by Display.getDefault() (on any thread) or Display.getCurrent() (on GUI thread).
I want to make a loginpage for my website, but im confused in what to use and where to put the functions that would validate the authentication, and keep how can it keep track of sessions.
Should I do it in the controller, and use xlst?
If you are just interested in creating a registration page/ login page, I would recommend reading this article.
The following code snippet comes from that article, which shows you the Login usercontrol:
public partial class Login : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
/*--- Set the navigation url for the Register hyperlink ---*/
var registerHyperLink = (HyperLink)uxLogin.FindControl("RegisterHyperLink");
registerHyperLink.NavigateUrl = "~/Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
uxLogin.RememberMeSet = false;
if (!IsPostBack)
{
/*--- Restore remembered username(?) ---*/
var c = Request.Cookies["username"];
if (c == null)
{
uxUsernameTextBox.Text = "";
}
else
{
uxUsernameTextBox.Text = c.Value;
uxLogin.RememberMeSet = true;
}
}
}
protected TextBox uxUsernameTextBox { get { return uxLogin.FindControl("UserName") as TextBox; } }
protected void uxLogin_LoggedIn(object sender, EventArgs e)
{
/*--- Inits ---*/
var url = Request.QueryString["url"];
/*--- Remember/Forget Username ---*/
if (uxLogin.RememberMeSet)
Response.SetCookie("username", uxUsernameTextBox.Text, 365);
else
Response.DeleteCookie("username", Request);
/*--- Redirect (?) ---*/
if (url == null)
{
Response.Redirect("~/"); // Main page for authenticated users
}
else
{
var url2 = Server.UrlDecode(url);
Response.Redirect(url2);
}
}
/* This field and the LoggingIn and LoginError event procedures place the user
in the correct domain for the current site. This way the user doesn't have
to specify the domain, logging in (for example) as "johndoe" instead of
"domain\johndoe". */
private string _usernameEntered = string.Empty;
protected void uxLogin_LoggingIn(object sender, LoginCancelEventArgs e)
{
var domainUser = Sitecore.Context.Domain.GetFullName(uxLogin.UserName);
if (System.Web.Security.Membership.GetUser(domainUser) != null)
{
_usernameEntered = uxLogin.UserName;
uxLogin.UserName = domainUser;
}
}
protected void uxLogin_LoginError(object sender, EventArgs e)
{
uxLogin.UserName = _usernameEntered;
}
}
In general: Sitecore keeps track of the logged in user for you, all you need to do is have the secure pages deny read rights for the Anonymous user. You can then allow read rights for all users with a specific role assigned to them. For more information on this, check this StackOverflow question (and it's answer, of course).