Home>

surroundings:

Host:win10 Development environment:android studio 2.2 preview 3

Explanation:

Two methods implement the dialog box that pops up at the bottom:

dialog dialogfragment

Recommended for dialogfragment

Effect picture:

Layout file dialog_select_call.xml:

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent">
  <relativelayout
    android:id="@ + id/layout_voice"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@ color/white">
    <textview
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignparentstart="true"
      android:layout_centerinparent="true"
      android:textsize="16sp"
      android:textcolor="@ color/black"
      android:layout_marginleft="16dp"
      android:layout_marginright="16dp"
      android:layout_margintop="16dp"
      android:layout_marginbottom="16dp"
      android:text="Voice Class" />
  </relativelayout>
  <view
    android:layout_width="fill_parent"
    android:layout_height="0.1dp"
    android:background="#b4b4b4"
    android:layout_marginleft="16dp"
    android:layout_marginright="16dp" />
  <relativelayout
    android:id="@ + id/layout_video"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@ color/white">
    <textview
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignparentstart="true"
      android:layout_centerinparent="true"
      android:textsize="16sp"
      android:textcolor="@ color/black"
      android:layout_marginleft="16dp"
      android:layout_marginright="16dp"
      android:layout_margintop="16dp"
      android:layout_marginbottom="16dp"
      android:text="Video Class" />
  </relativelayout>
  <view
    android:layout_width="fill_parent"
    android:layout_height="0.1dp"
    android:background="#b4b4b4"
    android:layout_marginleft="16dp"
    android:layout_marginright="16dp" />
  <relativelayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@ color/white">
    <button
      android:id="@ + id/cancel"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Cancel"
      android:layout_marginleft="16dp"
      android:layout_marginright="16dp"
      android:layout_margintop="16dp"
      android:layout_marginbottom="16dp" />
  </relativelayout>
</linearlayout>

dialog implementation source code:

initialization:

private void dialogselectcallinit () {
    dialogselectcall=new dialog (this, r.style.dialogpopbottom);
    view inflate=layoutinflater.from (this) .inflate (r.layout.dialog_select_call, null);
    dialogselectcall.setcontentview (inflate);
    window dialogwindow=dialogselectcall.getwindow ();
    dialogwindow.setgravity (gravity.bottom);
    windowmanager.layoutparams lp=dialogwindow.getattributes ();
    lp.x=0;
    lp.y=0;
    lp.width=getresources (). getdisplaymetrics (). widthpixels;
    dialogwindow.setattributes (lp);
    relativelayout layoutvoice=(relativelayout) inflate.findviewbyid (r.id.layout_voice);
    relativelayout layoutvideo=(relativelayout) inflate.findviewbyid (r.id.layout_video);
    button buttoncancel=(button) inflate.findviewbyid (r.id.cancel);
    rxview.clicks (layoutvoice)
        .throttlefirst (2, timeunit.seconds)
        .compose (this.binduntilevent (activityevent.destroy))
        .subscribe (v->{
//dialogselectcall.cancel ();
          voicesessionactivity.startactivitycallout (this, userid);
        });
    rxview.clicks (layoutvideo)
        .throttlefirst (2, timeunit.seconds)
        .compose (this.binduntilevent (activityevent.destroy))
        .subscribe (v->{
//dialogselectcall.cancel ();
//videosessionactivity.startactivitycallout (this, userid);
        });
    rxview.clicks (buttoncancel)
        .throttlefirst (2, timeunit.seconds)
        .compose (this.binduntilevent (activityevent.destroy))
        .subscribe (v->dialogselectcall.cancel ());
    rxview.touches (layoutvoice, motionevent->{
      deallayouttouch (layoutvoice, motionevent);
      return false;
    }). compose (this.binduntilevent (activityevent.destroy)). subscribe (motionevent->());
    rxview.touches (layoutvideo, motionevent->{
      deallayouttouch (layoutvideo, motionevent);
      return false;
    }). compose (this.binduntilevent (activityevent.destroy)). subscribe (motionevent->());
  }
  private void deallayouttouch (view v, motionevent event) {
    switch (event.getaction ()) {
      case motionevent.action_down:
        v.setbackgroundcolor (color.rgb (200, 200, 200));
        break;
      case motionevent.action_up:
        v.setbackgroundcolor (color.white);
        break;
    }
  }

Show dialog:

dialogselectcall.show ()

dialogfragment implementation source code:

Defines a class selectcalldialog.java inheriting dialogfragment

package com.bazhangkeji.classroom.common;
import android.app.dialog;
import android.app.fragmentmanager;
import android.graphics.color;
import android.os.bundle;
import android.support.annotation.nonnull;
import android.view.gravity;
import android.view.layoutinflater;
import android.view.motionevent;
import android.view.view;
import android.view.viewgroup;
import android.view.window;
import android.view.windowmanager;
import android.widget.button;
import android.widget.relativelayout;
import com.bazhangkeji.classroom.r;
import com.bazhangkeji.classroom.session.videosessionactivity;
import com.bazhangkeji.classroom.session.voicesessionactivity;
import com.jakewharton.rxbinding2.view.rxview;
import com.trello.rxlifecycle2.android.fragmentevent;
import com.trello.rxlifecycle2.components.rxdialogfragment;
import java.util.concurrent.timeunit;
public class selectcalldialog extends rxdialogfragment {
  private dialog dialog;
  private string userid;
  /**
   * Initialization. Must be called once
   * @param userid:target user id
   * /
  public void init (string userid) {
    this.userid=userid;
  }
  @nonnull
  @override
  public dialog oncreatedialog (bundle savedinstancestate) {
    dialog=new dialog (getactivity (), r.style.dialogpopbottom);
    view inflate=layoutinflater.from (getactivity ()). inflate (r.layout.dialog_select_call, null);
    dialog.setcontentview (inflate);
    dialog.setcanceledontouchoutside (true);
    window window=dialog.getwindow ();
    windowmanager.layoutparams lp=window.getattributes ();
    lp.gravity=gravity.bottom;
    lp.width=windowmanager.layoutparams.match_parent;
    window.setattributes (lp);
    relativelayout layoutvoice=(relativelayout) inflate.findviewbyid (r.id.layout_voice);
    relativelayout layoutvideo=(relativelayout) inflate.findviewbyid (r.id.layout_video);
    button buttoncancel=(button) dialog.findviewbyid (r.id.cancel);
    rxview.clicks (layoutvoice)
        .throttlefirst (2, timeunit.seconds)
        .compose (this.binduntilevent (fragmentevent.destroy))
        .subscribe (v->{
          dialog.cancel ();
          voicesessionactivity.startactivitycallout (getactivity (), userid);
        });
    rxview.clicks (layoutvideo)
        .throttlefirst (2, timeunit.seconds)
        .compose (this.binduntilevent (fragmentevent.destroy))
        .subscribe (v->{
          dialog.cancel ();
          videosessionactivity.startactivitycallout (getactivity (), userid);
        });
    rxview.clicks (buttoncancel)
        .throttlefirst (2, timeunit.seconds)
        .compose (this.binduntilevent (fragmentevent.destroy))
        .subscribe (v->dialog.cancel ());
    rxview.touches (layoutvoice, motionevent->{
      deallayouttouch (layoutvoice, motionevent);
      return false;
    }). compose (this.binduntilevent (fragmentevent.destroy)). subscribe (motionevent->());
    rxview.touches (layoutvideo, motionevent->{
      deallayouttouch (layoutvideo, motionevent);
      return false;
    }). compose (this.binduntilevent (fragmentevent.destroy)). subscribe (motionevent->());
    return dialog;
  }
  private void deallayouttouch (view v, motionevent event) {
    switch (event.getaction ()) {
      case motionevent.action_down:
        v.setbackgroundcolor (color.rgb (200, 200, 200));
        break;
      case motionevent.action_up:
        v.setbackgroundcolor (color.white);
        break;
    }
  }
}

Initialize parameters before displaying the dialog:

selectcalldialog.init (userid);

After the dialog is displayed:

selectcalldialog.show (getfragmentmanager (), "");
  • Previous Introduction to ASP Basics Part 3 (ASP Scripting Basics)
  • Next How to optimize MongoDB performance (five simple steps)