Java Code Examples for android.support.design.widget.BottomSheetBehavior#from()

The following examples show how to use android.support.design.widget.BottomSheetBehavior#from() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From AndroidWallet with GNU General Public License v3.0 7 votes vote down vote up
private void showAccountNotExistDialog(BaseInvokeModel baseInvokeModel, BaseInfo baseInfo) {
    bottomSheetDialog = new BottomSheetDialog(MainActivity.this);
    DialogAuthorAccountNotExistBinding binding = DataBindingUtil.inflate(LayoutInflater.from(Utils.getContext()), R.layout.dialog_author_account_not_exist, null, false);
    bottomSheetDialog.setContentView(binding.getRoot());
    // 设置dialog 完全显示
    View parent = (View) binding.getRoot().getParent();
    BottomSheetBehavior behavior = BottomSheetBehavior.from(parent);
    binding.getRoot().measure(0, 0);
    behavior.setPeekHeight(binding.getRoot().getMeasuredHeight());
    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) parent.getLayoutParams();
    params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
    parent.setLayoutParams(params);
    bottomSheetDialog.setCanceledOnTouchOutside(false);
    final ConfrimDialogViewModel confrimDialogViewModel = new ConfrimDialogViewModel(getApplication());
    confrimDialogViewModel.setBaseInfo(baseInvokeModel, baseInfo);
    binding.setViewModel(confrimDialogViewModel);
    bottomSheetDialog.show();
}
 
Example 2
Source File: WorldMapDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void collapseSheet(Dialog dialog)
{
    if (dialog == null) {
        return;
    }

    BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
    FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);
    if (layout != null)
    {
        BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
        behavior.setHideable(false);
        behavior.setSkipCollapsed(false);
        behavior.setPeekHeight((int)(dialogHeader.getHeight() + getResources().getDimension(R.dimen.dialog_margin) * 2));
        behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
    }
}
 
Example 3
Source File: MoonDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void expandSheet(DialogInterface dialog)
{
    if (dialog == null) {
        return;
    }

    BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
    FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
    if (layout != null)
    {
        BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
        behavior.setHideable(false);
        behavior.setSkipCollapsed(true);
        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }
}
 
Example 4
Source File: LightMapDialog.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void expandSheet(DialogInterface dialog)
{
    if (dialog != null) {
        BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
        FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
        if (layout != null) {
            BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
            behavior.setHideable(false);
            behavior.setSkipCollapsed(true);
            behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
        }
    }
}
 
Example 5
Source File: MainActivity.java    From CircularReveal with MIT License 6 votes vote down vote up
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  ButterKnife.bind(this);

  final ViewRevealManager revealManager = new ViewRevealManager();
  final SpringViewAnimatorManager springManager = new SpringViewAnimatorManager();
  springManager.setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY);
  springManager.setStiffness(SpringForce.STIFFNESS_LOW);

  parent.setViewRevealManager(revealManager);

  settingsView.addSwitch("Enable Spring", false, new CompoundButton.OnCheckedChangeListener() {
    @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      parent.setViewRevealManager(isChecked ? springManager : revealManager);
    }
  });
  settingsView.setAnimatorManager(springManager);

  final BottomSheetBehavior behavior = BottomSheetBehavior.from(settingsView);
  behavior.setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_peek_height));
  behavior.setSkipCollapsed(false);
  behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
 
Example 6
Source File: EditProfilePresenterImpl.java    From Saude-no-Mapa with MIT License 6 votes vote down vote up
private void setupBottomSheetDialog() {
    mBottomSheetDialog = new BottomSheetDialog(mContext);
    View dialogView = LayoutInflater.from(mContext)
            .inflate(R.layout.dialog_bottom_sheet_profile, null);

    RecyclerView avatarRecycler = (RecyclerView) dialogView.findViewById(R.id.avatar_recycler);
    avatarRecycler.setHasFixedSize(true);
    avatarRecycler.setLayoutManager(new GridLayoutManager(mContext, 3, GridLayoutManager.VERTICAL, false));

    avatarRecycler.setAdapter(new AvatarAdapter(mContext, this));

    mBottomSheetDialog.setContentView(dialogView);

    dialogView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

    BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View) dialogView.getParent());
    mBehavior.setPeekHeight(dialogView.getMeasuredHeight() + 200);

    mBottomSheetDialog.show();
}
 
Example 7
Source File: ToolBarSampleSnar.java    From CoordinatorLayoutExample with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_first);
    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    mRlBottomSheet = (RelativeLayout) findViewById(R.id.rl_bottom_sheet);
    mFrom = BottomSheetBehavior.from(mRlBottomSheet);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    // 该属性必须在setSupportActionBar之前 调用
    mToolbar.setTitle("ToolBarSample");
    setSupportActionBar(mToolbar);

    initListener();
    initData();
}
 
Example 8
Source File: PicDialog.java    From PicKing with Apache License 2.0 5 votes vote down vote up
public PicDialog(Context context) {
    super(context, R.style.AppNoActionBarTheme);
    setOwnerActivity((Activity) context);
    setContentView(R.layout.dialog_pic);

    StatusBarUtil.MIUISetStatusBarLightMode(getOwnerActivity(), true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        View decorView = getWindow().getDecorView();
        int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
        decorView.setSystemUiVisibility(option);
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }

    ButterKnife.bind(this);

    if ((boolean) SPUtils.get(getContext(), AppConfig.click_to_back, false))
        photoDraweeView.setOnViewTapListener(new OnViewTapListener() {
            @Override
            public void onViewTap(View view, float x, float y) {
                dismiss();
            }
        });

    photoDraweeView.setAllowParentInterceptOnEdge(false);
    photoDraweeView.setEnableDraweeMatrix(false);

    for (AppCompatImageButton imageButton : imageButtons)
        imageButton.setOnClickListener(this);

    getWindow().setWindowAnimations(R.style.dialogStyle);

    behavior = BottomSheetBehavior.from(findViewById(R.id.bottom_view));
}
 
Example 9
Source File: BoxingBottomSheetActivity.java    From boxing with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_boxing_bottom_sheet);
    createToolbar();

    FrameLayout bottomSheet = (FrameLayout) findViewById(R.id.content_layout);
    mBehavior = BottomSheetBehavior.from(bottomSheet);
    mBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

    mImage = (ImageView) findViewById(R.id.media_result);
    mImage.setOnClickListener(this);
}
 
Example 10
Source File: HelpDialog.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private void expandSheet(DialogInterface dialog)
{
    if (dialog != null) {
        BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
        FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet);  // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
        if (layout != null) {
            BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
            behavior.setHideable(false);
            behavior.setSkipCollapsed(false);
            behavior.setPeekHeight(200);
            behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
        }
    }
}
 
Example 11
Source File: BottomSheetActivity.java    From CoordinatorLayoutExample with Apache License 2.0 5 votes vote down vote up
@Override
protected void initView() {
    setOnClickListener(this, R.id.btnBehavior, R.id.btnDialog,R.id.btn_baidumap);

    View bottomSheet = findViewById(R.id.bottom_sheet);
    if (bottomSheet != null) {
        behavior = BottomSheetBehavior.from(bottomSheet);
        behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
    }
}
 
Example 12
Source File: WinnerDeclarationActivity.java    From 1Rramp-Android with MIT License 5 votes vote down vote up
private void initializeObjects() {
  progressDialog = new ProgressDialog(this);
  dataStore = new DataStore();
  steemPostCreator = new SteemPostCreator();
  steemPostCreator.setSteemPostCreatorCallback(this);
  rankableCompetitionItemRecyclerAdapter = new RankableCompetitionItemRecyclerAdapter(this);
  competitionWinnerSelectionList.setLayoutManager(new LinearLayoutManager(this));
  rankableCompetitionItemRecyclerAdapter.setRankableCompetitionItemListener(this);
  competitionWinnerSelectionList.setAdapter(rankableCompetitionItemRecyclerAdapter);
  sheetBehavior = BottomSheetBehavior.from(bottomSheet);
  sheetBehavior.setHideable(false);
  shortlistedWinnersMap = new HashMap<>();
  title.setText(String.format("Winners of: %s", mCompetitionTitle));
  invalidateWinnerList();
}
 
Example 13
Source File: LoginPresenterImpl.java    From Saude-no-Mapa with MIT License 5 votes vote down vote up
@Override
public void onReactivateAccountClicked() {
    mIsValidationFromDialog = true;
    mBottomSheetDialog = new BottomSheetDialog(mContext);

    View dialogView = LayoutInflater.from(mContext).inflate(R.layout.dialog_bottom_sheet_reactivate_account, null);
    mBottomViews = new ReactivateViews();
    ButterKnife.bind(mBottomViews, dialogView);

    mInteractor.validateReactivateForms(mBottomViews.loginEmailEdit, mBottomViews.loginPasswordEdit, this);

    mBottomViews.loginGoogleButton.setSize(SignInButton.SIZE_STANDARD);
    mBottomViews.loginGoogleButton.setScopes(mGso.getScopeArray());

    mBottomViews.filterButton.setOnClickListener(v -> {
        requestReactivateNormalAccount();
    });

    mBottomViews.loginGoogleButton.setOnClickListener(v -> {
        googleLoginClicked();
    });

    mBottomViews.loginFacebookButton.setOnClickListener(v -> {
        facebookLoginClicked();
    });

    mBottomSheetDialog.setContentView(dialogView);

    mBottomViews.bottomSheet.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

    BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View) dialogView.getParent());
    mBehavior.setPeekHeight(mBottomViews.bottomSheet.getMeasuredHeight() + 200);

    mBottomSheetDialog.setOnDismissListener(dialog -> {
        mIsValidationFromDialog = false;
    });

    mBottomSheetDialog.show();
}
 
Example 14
Source File: PlacesOnMapActivity.java    From Travel-Mate with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_places_on_map);
    ButterKnife.bind(this);
    editTextSearch.addTextChangedListener(this);
    Intent intent = getIntent();
    mCity = (City) intent.getSerializableExtra(EXTRA_MESSAGE_CITY_OBJECT);
    String type = intent.getStringExtra(EXTRA_MESSAGE_TYPE);
    mHandler = new Handler(Looper.getMainLooper());
    SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mToken = mSharedPreferences.getString(USER_TOKEN, null);
    sheetBehavior = BottomSheetBehavior.from(layoutBottomSheet);
    mMap = findViewById(R.id.map);
    setTitle(mCity.getNickname());
    mMarker = this.getDrawable(R.drawable.ic_radio_button_checked_orange_24dp);
    mDefaultMarker = this.getDrawable(R.drawable.marker_default);
    switch (type) {
        case "restaurant":
            mMode = "eat-drink";
            mIcon = R.drawable.restaurant;
            break;
        case "hangout":
            mMode = "going-out,leisure-outdoor";
            mIcon = R.drawable.hangout;
            break;
        case "monument":
            mMode = "sights-museums";
            mIcon = R.drawable.monuments;
            break;
        default:
            mMode = "shopping";
            mIcon = R.drawable.shopping_icon;
            break;
    }
    getPlaces();
    initMap();
    setTitle("Places");
    Objects.requireNonNull(getSupportActionBar()).setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
 
Example 15
Source File: RadialTransformationActivity.java    From CircularReveal with MIT License 4 votes vote down vote up
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_sample_2);
  ButterKnife.bind(this);

  Picasso.with(this)
      .load("http://camp-campbell.com/wp-content/uploads/2014/09/847187872-san-francisco.jpg")
      .resizeDimen(R.dimen.radial_card_width, R.dimen.radial_card_height)
      .centerCrop()
      .into(sanFranciscoView);

  videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override public void onPrepared(MediaPlayer mp) {
      mp.setLooping(true);
    }
  });
  videoView.setVideoURI(Uri.parse(VIDEO_URL));
  videoView.start();

  final GestureDetector detector = new GestureDetector(this, tapDetector);

  for (int i = 0; i < stack.getChildCount(); i++) {
    View view = stack.getChildAt(i);
    view.setOnTouchListener(new View.OnTouchListener() {
      @Override public boolean onTouch(View v, MotionEvent event) {
        return detector.onTouchEvent(event);
      }
    });
  }

  final ViewRevealManager revealManager = new ViewRevealManager();
  final SpringViewAnimatorManager springManager = new SpringViewAnimatorManager();
  springManager.setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY);
  springManager.setStiffness(SpringForce.STIFFNESS_LOW);

  stack.setViewRevealManager(revealManager);

  settingsView.addSwitch("Enable Spring", false, new CompoundButton.OnCheckedChangeListener() {
    @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      stack.setViewRevealManager(isChecked ? springManager : revealManager);
    }
  });
  settingsView.setAnimatorManager(springManager);

  final BottomSheetBehavior behavior = BottomSheetBehavior.from(settingsView);
  behavior.setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_peek_height));
  behavior.setSkipCollapsed(false);
  behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
 
Example 16
Source File: ScrollingActivity.java    From Android-Multi-Theme-UI with Apache License 2.0 4 votes vote down vote up
private void initBottomSheet(){
    // get the bottom sheet view
    LinearLayout llBottomSheet = (LinearLayout) findViewById(R.id.bottom_sheet);

    // init the bottom sheet behavior
    mBottomSheetBehavior = BottomSheetBehavior.from(llBottomSheet);

    SwitchCompat switchCompat = findViewById(R.id.switch_dark_mode);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mIsNightMode = b;
            int delayTime = 200;
            if(mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED){
                delayTime = 400;
                mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
            }
            compoundButton.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if(mIsNightMode){
                        getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                    }else{
                        getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                    }
                }
            },delayTime);

        }
    });

    mRecyclerView = findViewById(R.id.recyclerView);

    mAdapter = new ThemeAdapter(mThemeList, new RecyclerViewClickListener() {
        @Override
        public void onClick(View view, int position) {
            mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
            view.postDelayed(new Runnable() {
                @Override
                public void run() {
                    ScrollingActivity.this.recreate();
                }
            },400);
        }
    });

    RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getApplicationContext(),4);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.setAdapter(mAdapter);
}
 
Example 17
Source File: AppListViewModel.java    From island with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("MethodMayBeStatic") public final void onBottomSheetClick(final View view) {
	final BottomSheetBehavior bottom_sheet = BottomSheetBehavior.from(view);
	bottom_sheet.setState(BottomSheetBehavior.STATE_EXPANDED);
}
 
Example 18
Source File: EstablishmentPresenterImpl.java    From Saude-no-Mapa with MIT License 4 votes vote down vote up
private void showFilterBottomSheetDialog() {
    mIsFiltered = false;
    BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(mContext);
    View dialogView = LayoutInflater.from(mContext).inflate(R.layout.dialog_bottom_sheet_filter, null);
    FilterViews bottomViews = new FilterViews();
    ButterKnife.bind(bottomViews, dialogView);

    mCurrentFilterTitle = bottomViews.filterTitle;
    updateCurrentFilterTitle();

    bottomViews.redeAtendimentoSpinner.setAdapter(getRedeAtendimentoAdapter());
    bottomViews.categoriaSpinner.setAdapter(getCategoriaSpinner());

    RxAdapterView.itemSelections(bottomViews.redeAtendimentoSpinner).subscribe(integer -> {
        doFilter(bottomViews);
    });

    RxAdapterView.itemSelections(bottomViews.categoriaSpinner).subscribe(integer -> {
        doFilter(bottomViews);
    });

    RxCompoundButton.checkedChanges(bottomViews.vinculoSusCheckbox).subscribe(isChecked -> {
        doFilter(bottomViews);
    });

    RxCompoundButton.checkedChanges(bottomViews.atendimentoUrgencialCheckbox).subscribe(isChecked -> {
        doFilter(bottomViews);
    });

    RxCompoundButton.checkedChanges(bottomViews.atendimentoAmbulatorialCheckbox).subscribe(isChecked -> {
        doFilter(bottomViews);
    });

    RxCompoundButton.checkedChanges(bottomViews.centroCirurgicoCheckbox).subscribe(isChecked -> {
        doFilter(bottomViews);
    });

    RxCompoundButton.checkedChanges(bottomViews.obstetraCheckbox).subscribe(isChecked -> {
        doFilter(bottomViews);
    });

    RxCompoundButton.checkedChanges(bottomViews.neoNatalCheckbox).subscribe(isChecked -> {
        doFilter(bottomViews);
    });

    RxCompoundButton.checkedChanges(bottomViews.dialiseCheckbox).subscribe(isChecked -> {
        doFilter(bottomViews);
    });

    bottomViews.filterButton.setOnClickListener(view -> {
        mIsFiltered = true;
        mInteractor.clearMarkers(mMap);
        showMapPins(mFilteredEstablishmentList);
        mInteractor.animateCameraToAllEstablishments(mMap);
        bottomSheetDialog.dismiss();
    });

    bottomSheetDialog.setContentView(dialogView);
    bottomSheetDialog.getWindow().findViewById(R.id.design_bottom_sheet)
            .setBackgroundResource(R.color.default_dialog_background);

    dialogView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

    BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View) dialogView.getParent());
    mBehavior.setPeekHeight((int) (mView.getMapContainerHeight() + 400));

    bottomSheetDialog.setOnDismissListener(dialogInterface -> {
        if (!mIsFiltered) {
            mFilteredEstablishmentList.clear();
            mFilteredEstablishmentList.addAll(mEstablishmentList);
        }
    });

    bottomSheetDialog.show();
}
 
Example 19
Source File: SaleNHAssetActivity.java    From AndroidWallet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initViewObservable() {
    dialog = new BottomSheetDialog(this);
    DialogSaleNhassetConfirmLayoutBinding binding = DataBindingUtil.inflate(LayoutInflater.from(Utils.getContext()), R.layout.dialog_sale_nhasset_confirm_layout, null, false);
    dialog.setContentView(binding.getRoot());
    View parent = (View) binding.getRoot().getParent();
    BottomSheetBehavior behavior = BottomSheetBehavior.from(parent);
    binding.getRoot().measure(0, 0);
    behavior.setPeekHeight(binding.getRoot().getMeasuredHeight());
    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) parent.getLayoutParams();
    params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
    parent.setLayoutParams(params);
    dialog.setCanceledOnTouchOutside(false);
    final SaleNhConfirmViewModel orderConfirmViewModel = new SaleNhConfirmViewModel(getApplication());
    binding.setViewModel(orderConfirmViewModel);
    viewModel.uc.saleNHNBtnObservable.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
        @Override
        public void onPropertyChanged(Observable observable, int i) {
            try {
                if (TextUtils.isEmpty(viewModel.salePricesAmount.get())) {
                    ToastUtils.showShort(R.string.module_mine_nh_asset_sale_price_hint);
                    return;
                }
                if (TextUtils.isEmpty(viewModel.saleValidTime.get())) {
                    ToastUtils.showShort(R.string.module_mine_nh_asset_sale_valid_time_hint);
                    return;
                }

                if (TextUtils.equals(viewModel.saleValidTime.get(), "0")) {
                    ToastUtils.showShort(R.string.module_mine_nh_asset_sale_valid_time_less_than_one);
                    return;
                }

                if (Long.valueOf(Objects.requireNonNull(viewModel.saleValidTime.get())) > viewModel.saleValidTimeMax) {
                    viewModel.saleValidTime.set(String.valueOf(viewModel.saleValidTimeMax));
                    return;
                }

                if (new BigDecimal(viewModel.salePricesAmount.get()).compareTo(BigDecimal.ZERO) < 0) {
                    ToastUtils.showShort(R.string.module_mine_sale_nh_price_error);
                    return;
                }
                SaleNHAssetParamsModel saleNHAssetParamsModel = new SaleNHAssetParamsModel();
                saleNHAssetParamsModel.setNhAssetId(nhAssetModelBean.id);
                saleNHAssetParamsModel.setPriceAmount(viewModel.salePricesAmount.get());
                saleNHAssetParamsModel.setPriceSymbol(viewModel.salePricesSymbol.get());
                saleNHAssetParamsModel.setOrderMemo(viewModel.saleMemo.get());
                saleNHAssetParamsModel.setValidTime(Long.parseLong(viewModel.saleValidTime.get()));
                orderConfirmViewModel.setSaleInfoData(saleNHAssetParamsModel);
                dialog.show();
            } catch (Exception e) {
            }
        }
    });

    viewModel.uc.choosePriceSymbolObservable.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
        @Override
        public void onPropertyChanged(Observable sender, int propertyId) {
            Bundle bundle = new Bundle();
            bundle.putInt(IntentKeyGlobal.SALE_TO_SYMBOL_SELECT, IntentKeyGlobal.GET_CONTACT);
            ARouter.getInstance().
                    build(RouterActivityPath.ACTIVITY_SYMBOL_LIST).
                    with(bundle).
                    navigation(SaleNHAssetActivity.this, IntentKeyGlobal.REQ_SYMBOL_SELECT_CODE);
        }
    });
}
 
Example 20
Source File: InvokeTransferActivity.java    From AndroidWallet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initViewObservable() {
    dialog = new BottomSheetDialog(InvokeTransferActivity.this);
    DialogTransferPayConfirmBinding binding = DataBindingUtil.inflate(LayoutInflater.from(Utils.getContext()), R.layout.dialog_transfer_pay_confirm, null, false);
    dialog.setContentView(binding.getRoot());
    // 设置dialog 完全显示
    View parent = (View) binding.getRoot().getParent();
    BottomSheetBehavior behavior = BottomSheetBehavior.from(parent);
    binding.getRoot().measure(0, 0);
    behavior.setPeekHeight(binding.getRoot().getMeasuredHeight());
    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) parent.getLayoutParams();
    params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
    parent.setLayoutParams(params);
    dialog.setCanceledOnTouchOutside(false);
    final OrderConfirmViewModel orderConfirmViewModel = new OrderConfirmViewModel(getApplication());
    binding.setViewModel(orderConfirmViewModel);
    viewModel.uc.invokeTransferConfirmObservable.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
        @Override
        public void onPropertyChanged(Observable observable, int i) {
            if (transferInvokeModel.getExpired() > 0 && System.currentTimeMillis() > transferInvokeModel.getExpired()) {
                finish();
                IntentUtils.jumpToDappWithError(InvokeTransferActivity.this, baseInvokeModel, transferInvokeModel.getActionId(), "request expired!");
                return;
            }

            if (TextUtils.isEmpty(transferInvokeModel.getFrom())) {
                finish();
                IntentUtils.jumpToDappWithError(InvokeTransferActivity.this, baseInvokeModel,
                        transferInvokeModel.getActionId(), Utils.getString(R.string.transferAccountName_empty));
                return;
            }

            if (TextUtils.isEmpty(transferInvokeModel.getTo())) {
                finish();
                IntentUtils.jumpToDappWithError(InvokeTransferActivity.this, baseInvokeModel,
                        transferInvokeModel.getActionId(), Utils.getString(R.string.module_asset_receivablesAccountName_empty));
                return;
            }

            if (TextUtils.isEmpty(String.valueOf(transferInvokeModel.getAmount()))) {
                finish();
                IntentUtils.jumpToDappWithError(InvokeTransferActivity.this, baseInvokeModel,
                        transferInvokeModel.getActionId(), Utils.getString(R.string.module_asset_transfer_amount_empty));
                return;
            }

            if (TextUtils.equals(transferInvokeModel.getFrom(), transferInvokeModel.getTo())) {
                finish();
                IntentUtils.jumpToDappWithError(InvokeTransferActivity.this, baseInvokeModel,
                        transferInvokeModel.getActionId(), Utils.getString(R.string.module_asset_transfer_account_can_not_yourself));
                return;
            }
            NumberFormat instance = NumberFormat.getInstance();
            instance.setGroupingUsed(false);
            instance.setMaximumFractionDigits(transferInvokeModel.getPrecision());
            TransferParamsModel transferParamsModel = new TransferParamsModel();
            transferParamsModel.setAccountName(transferInvokeModel.getFrom());
            transferParamsModel.setReceivablesAccountName(transferInvokeModel.getTo());
            transferParamsModel.setTransferAmount(instance.format(transferInvokeModel.getAmount()));
            transferParamsModel.setTransferMemo(transferInvokeModel.getMemo());
            transferParamsModel.setTransferSymbol(transferInvokeModel.getSymbol());
            orderConfirmViewModel.setTransferInfoData(transferParamsModel);
            dialog.show();
        }
    });

    viewModel.uc.invokeTransferCancelObservable.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
        @Override
        public void onPropertyChanged(Observable sender, int propertyId) {
            finish();
            IntentUtils.jumpToDappWithCancel(InvokeTransferActivity.this, baseInvokeModel, transferInvokeModel.getActionId());
        }
    });
}