-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7833 from brave/pr7817_deprecate_bap_modal_androi…
…d_1.20.x Deprecate bap modal android (uplift to 1.20.x)
- Loading branch information
Showing
17 changed files
with
429 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
android/java/org/chromium/chrome/browser/DeprecateBAPModalDialogFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package org.chromium.chrome.browser; | ||
|
||
import android.content.DialogInterface; | ||
import android.content.res.Configuration; | ||
import android.os.Bundle; | ||
import android.util.DisplayMetrics; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.WindowManager; | ||
import android.widget.Button; | ||
import android.widget.LinearLayout; | ||
|
||
import androidx.appcompat.widget.AppCompatImageView; | ||
import androidx.fragment.app.DialogFragment; | ||
|
||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.browser.util.ConfigurationUtils; | ||
import org.chromium.ui.base.DeviceFormFactor; | ||
|
||
public class DeprecateBAPModalDialogFragment | ||
extends DialogFragment implements View.OnClickListener { | ||
@Override | ||
public void onConfigurationChanged(Configuration newConfig) { | ||
super.onConfigurationChanged(newConfig); | ||
setDialogParams(); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() { | ||
@Override | ||
public boolean onKey(android.content.DialogInterface dialog, int keyCode, | ||
android.view.KeyEvent event) { | ||
if ((keyCode == android.view.KeyEvent.KEYCODE_BACK)) { | ||
dismiss(); | ||
return true; | ||
} else | ||
return false; | ||
} | ||
}); | ||
setDialogParams(); | ||
} | ||
|
||
@Override | ||
public View onCreateView( | ||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
return inflater.inflate(R.layout.fragment_deprecate_bap_modal_dialog, container, false); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, Bundle savedInstanceState) { | ||
Button mDoneButton = view.findViewById(R.id.btn_done); | ||
mDoneButton.setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View view) { | ||
dismiss(); | ||
} | ||
|
||
private void setDialogParams() { | ||
DisplayMetrics displayMetrics = new DisplayMetrics(); | ||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); | ||
int mDeviceHeight = displayMetrics.heightPixels; | ||
int mDeviceWidth = displayMetrics.widthPixels; | ||
|
||
WindowManager.LayoutParams params = getDialog().getWindow().getAttributes(); | ||
boolean isTablet = DeviceFormFactor.isNonMultiDisplayContextOnTablet(getActivity()); | ||
boolean isLandscape = ConfigurationUtils.isLandscape(getActivity()); | ||
if (isTablet) { | ||
params.width = (int) (0.5 * mDeviceWidth); | ||
} else { | ||
if (isLandscape) { | ||
params.width = (int) (0.5 * mDeviceWidth); | ||
} else { | ||
params.width = (int) (0.9 * mDeviceWidth); | ||
} | ||
} | ||
params.height = LinearLayout.LayoutParams.WRAP_CONTENT; | ||
getDialog().getWindow().setAttributes(params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.