Exemple #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.publish_layout, container, false);

            Publish              = (Button)view.FindViewById(Resource.Id.publishBtn);
            Message              = (EditText)view.FindViewById(Resource.Id.MessageInput);
            PublishedMsg         = (ListView)view.FindViewById(Resource.Id.listView2);
            MsglistArrayAdapter  = new MessageAdapter(Activity.ApplicationContext, MsgList);
            PublishedMsg.Adapter = MsglistArrayAdapter;
            MsglistArrayAdapter.NotifyDataSetChanged();
            RegisterForContextMenu(PublishedMsg);

            Publish.Click += delegate
            {
                if (Message.Text.Length != 0)
                {
                    Log.Info(MainActivity.TAG, "HMS start publish...");
                    Policy    policy    = new Policy.Builder().SetTtlSeconds(Policy.PolicyTtlSecondsDefault).Build();
                    PutOption putOption = new PutOption.Builder().SetPolicy(policy).SetCallback(new MyPutCallback()).Build();
                    MainActivity.sMessageEngine.Put(new Message(System.Text.Encoding.UTF8.GetBytes(Message.Text)), putOption).AddOnCompleteListener(new TaskListener(Activity.ApplicationContext, " Put Message")).AddOnFailureListener(new TaskListener(Activity.ApplicationContext, " Put Message"));
                    Log.Debug(MainActivity.TAG, "PutOption: Policy= " + putOption.Policy.ToString());
                }
                else
                {
                    Toast.MakeText(Activity.ApplicationContext, "Please enter a Message", ToastLength.Long).Show();
                }
            };

            return(view);
        }
Exemple #2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.subscribe_layout, container, false);

            Subscribe           = (Button)view.FindViewById(Resource.Id.subscribeBtn);
            CapturedMsg         = (ListView)view.FindViewById(Resource.Id.listView1);
            MsglistArrayAdapter = new MessageAdapter(Activity.ApplicationContext, MsgList);
            CapturedMsg.Adapter = MsglistArrayAdapter;
            MsglistArrayAdapter.NotifyDataSetChanged();
            Subscribe.Click += delegate
            {
                if (Subscribe.Text == "Subscribe")
                {
                    Log.Info(MainActivity.TAG, "HMS start Subscribe...");
                    Subscribe.Text = "Subscribed";
                    Policy    policy    = new Policy.Builder().SetTtlSeconds(Policy.PolicyTtlSecondsInfinite).Build();
                    GetOption GetOption = new GetOption.Builder().SetPolicy(policy).SetCallback(new MyGetCallback()).Build();
                    MainActivity.sMessageEngine.Get(msgHandlerImple, GetOption).AddOnCompleteListener(new TaskListener(Activity.ApplicationContext, " Get Message")).AddOnFailureListener(new TaskListener(Activity.ApplicationContext, " Get Message"));
                    Log.Debug(MainActivity.TAG, "GetOption: Policy= " + GetOption.Policy.ToString());
                }
                else
                {
                    Log.Info(MainActivity.TAG, "HMS start Unsubscribe...");
                    Subscribe.Text = "Subscribe";
                    MainActivity.sMessageEngine.Unget(msgHandlerImple).AddOnCompleteListener(new TaskListener(Activity.ApplicationContext, " Unget Message")).AddOnFailureListener(new TaskListener(Activity.ApplicationContext, " Unget Message"));
                }
            };

            return(view);
        }