While debugging on USB I just wanted to expand WebView to fullscreen. Unfortunately, white screen appeared and nothing after it. I really do not know what to do. I made CustomView and everything seemed fine. Here is my code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
filmkey = "<iframe width=\"96%\" height=\"96%\" src=\"https://www.youtube.com/embed/EtMOgsWEAmQ\" frameborder=\"0\" allowfullscreen></iframe>";
screen=(WebView)findViewById(R.id.webView);
screen.getSettings().setJavaScriptEnabled(true);
String myvideokey = filmkey;
screen.loadData(myvideokey, "text/html", "utf-8");
screen.setWebChromeClient(new WebChromeClient(){
#Override
public void onShowCustomView(View view, CustomViewCallback callback) {
super.onShowCustomView(view, callback);
}
#Override
public void onHideCustomView() {
super.onHideCustomView();
}
});
}
try the following Code. In this on full screen i created a View which will become full Screen.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
screen.restoreState(savedInstanceState);
}
setContentView(R.layout.activity_support);
filmkey = "<iframe width=\"96%\" height=\"96%\" src=\"https://www.youtube.com/embed/EtMOgsWEAmQ\" frameborder=\"0\" allowfullscreen></iframe>";
screen=(WebView)findViewById(R.id.webview);
screen.getSettings().setJavaScriptEnabled(true);
String myvideokey = filmkey;
screen.loadData(myvideokey, "text/html", "utf-8");
CustomWebChromeClient custom = new CustomWebChromeClient();
screen.setWebChromeClient(custom);
}
and the custom WebChromeClient is
class `CustomWebChromeClient` extends WebChromeClient{
#Override
public void onShowCustomView(View view, final CustomViewCallback callback) {
super.onShowCustomView(view, callback);
Dialog dialog = new Dialog(SupportActivity.this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
view.setBackgroundColor(Color.TRANSPARENT);
dialog.setContentView(view);
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialog) {
callback.onCustomViewHidden();
}
});
dialog.show();
}
#Override
public void onHideCustomView() {
super.onHideCustomView();
}
}
and also make sure you use all these methods in the activity to handle with the data in webView.
#Override
protected void onResume() {
super.onResume();
screen.onResume();
}
#Override
protected void onPause() {
super.onPause();
screen.onPause();
}
#Override
protected void onStop() {
super.onStop();
screen.stopLoading();
}
#Override
protected void onDestroy() {
super.onDestroy();
screen.destroy();
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
screen.saveState(outState);
}
I hope it helps.
Related
Mapbox not Working With Fragments and bottom navigation
I get a blank page when i run the app , i am using bottom navigation bar and inside the fragment i run the mapbox code , i am trying to add Mapbox view inside the fragment .. i tried to implement the map box inside onViewCreated() but it doesn't work either.
.
.
.
.
public class TrackingFragment extends Fragment implements OnMapReadyCallback, PermissionsListener {
private PermissionsManager permissionsManager;
private MapboxMap map;
private MapView mapView;
public TrackingFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Mapbox.getInstance(getContext(), getString(R.string.access_token));
View view = inflater.inflate(R.layout.fragment_tracking,container,false);
mapView = (MapView) view.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
return view;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
#Override
public void onStart() {
super.onStart();
mapView.onStart();
}
#Override
public void onResume() {
super.onResume();
mapView.onResume();
}
#Override
public void onPause() {
super.onPause();
mapView.onPause();
}
#Override
public void onStop() {
super.onStop();
mapView.onStop();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
#Override
public void onDestroyView() {
super.onDestroyView();
mapView.onDestroy();
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
#Override
public void onMapReady(MapboxMap mapboxMap) {
map = mapboxMap;
map.setStyle(Style.DARK);
}
private void enableLocation() {
// the permission is granted.
if (PermissionsManager.areLocationPermissionsGranted(getContext())) {
//tracking();
} else {
// the permissions is not granted.
permissionsManager = new PermissionsManager(this);
//here we request for location from user
permissionsManager.requestLocationPermissions(getActivity());
}
}
#Override
public void onExplanationNeeded(List<String> permissionsToExplain) {
}
#Override
public void onPermissionResult(boolean granted) {
if (granted) {
enableLocation();
}
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
I want to know how to implement AdMob rewarded video ads in a list view?
I'm using the source code from here
and I want to use it in this class StickerPackDetailsActivity.java
and the layout is gonna like this
![layout][1]
I want to lock add to WhatsApp and unlock it by watching video reward.
but this stickerdetails showed from listview from
![here][2]
so, how to implement video reward ads only in 1 specified item of the listview not all of them?
public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener {
private RewardedVideoAd mRewardedVideoAd;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this,"ca-app-pub111111111");
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
listitem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
loadRewardedVideoAd();
}
});
}
private void loadRewardedVideoAd() {
mRewardedVideoAd.loadAd("ca-app-pub-",
new AdRequest.Builder().build());
}
#Override
public void onRewardedVideoAdLoaded() {
}
#Override
public void onRewardedVideoAdOpened() {
}
#Override
public void onRewardedVideoStarted() {
}
#Override
public void onRewardedVideoAdClosed() {
loadRewardedVideoAd();
}
#Override
public void onRewarded(RewardItem rewardItem) {
}
#Override
public void onRewardedVideoAdLeftApplication() {
}
#Override
public void onRewardedVideoAdFailedToLoad(int i) {
}
#Override
public void onRewardedVideoCompleted() {
}
#Override
protected void onPause() {
mRewardedVideoAd.pause(this);
super.onPause();
}
#Override
protected void onResume() {
mRewardedVideoAd.resume(this);
super.onResume();
}
}
I want to make this progress visible when it is required and hide its footer area. Please help me I don't know exactly what to do.
I tried progressBarFooter.setVisibility(View.VISIBLE);and progressBarFooter.setVisibility(View.GONE); didn't work.
public class MainActivity extends AppCompatActivity {
ProgressBar superProgressBar;
WebView superWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
superProgressBar= findViewById(R.id.myProgressBar);
superWebView= findViewById(R.id.myWebView);
superProgressBar.setMax(100);
superWebView.loadUrl("http");
superWebView.getSettings().setJavaScriptEnabled(true);
superWebView.setWebViewClient(new WebViewClient());
superWebView.setWebChromeClient(new WebChromeClient(){
#Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
superProgressBar.setProgress(newProgress);
}
#Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
getSupportActionBar().setTitle(title);
}
});
}
#Override
public void onBackPressed(){
if (superWebView.canGoBack()){
superWebView.goBack();
}
else {
finish();
}
}
}
here is a way to control the progress bar.
superWebView.setWebChromeClient(new WebChromeClient(){
#Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if(progress < 100 && pbar.getVisibility() == ProgressBar.GONE){
superProgressBar.setVisibility(ProgressBar.VISIBLE);
}
superProgressBar.setProgress(progress);
if(progress == 100) {
superProgressBar.setVisibility(ProgressBar.GONE);
}
}
...
});
I have a Runnable on a UIThread updating a SeekBar while a MediaPlayer is playing. Yet, when I switch to another activity my application crashes with an exception cause the Runnable keeps on forever even after the MediaPlayer has been destroyed.
This is my code:
public class Guide extends AppCompatActivity implements MediaPlayer.OnPreparedListener {
Button back;
private MediaPlayer m_audio_player;
private Handler m_handler_seek_bar = new Handler();
private SeekBar m_seek_bar;
private Runnable m_seek_bar_runnable;
private void set_up_audio(){
m_audio_player = MediaPlayer.create(this, g_audio[NativeLib.get_active_landmark()] );
m_audio_player.setOnPreparedListener(this);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_guide);
implement_back_button();
set_up_audio();
}
#Override
protected void onStart() {
super.onStart();
set_up_seek_bar();
}
private void set_up_seek_bar() {
m_seek_bar = (SeekBar) findViewById(R.id.seek_bar);
m_seek_bar.setMax(m_audio_player.getDuration());
m_seek_bar_runnable = new Runnable() {
#Override
public void run() {
if(m_audio_player != null ){
m_seek_bar.setProgress(m_audio_player.getCurrentPosition());
}
m_handler_seek_bar.postDelayed(this, 1000);
}
};
// update Seekbar on UI thread
Guide.this.runOnUiThread(m_seek_bar_runnable);
m_seek_bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) { }
#Override
public void onStartTrackingTouch(SeekBar seekBar) {}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(m_audio_player != null && fromUser){
m_audio_player.seekTo(progress);
}
}
});
}
#Override
protected void onStop() {
if (debug_mode) Log.d(TAG, "onStop");
if (m_audio_player.isPlaying()) {
m_audio_player.stop();
}
m_audio_player.release();
super.onStop();
findViewById(R.id.activity_guide).removeCallbacks(m_seek_bar_runnable);
}
// return button
private void implement_back_button() {
final Intent intent = new Intent(/* pointing at some other activity */);
back = (Button) findViewById(R.id.back_button);
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(intent);
}
});
}
}
You need to use:
m_handler_seek_bar.removeCallbacks(m_seek_bar_runnable);
to remove the runnable from handler
#Override
protected void onStop() {
if (debug_mode) Log.d(TAG, "onStop");
if (m_audio_player.isPlaying()) {
m_audio_player.stop();
}
m_audio_player.release();
m_handler_seek_bar.removeCallbacks(m_seek_bar_runnable);
super.onStop();
}
Alternatively you can override the onPause() method of the activity:
#Override
protected void onPause() {
m_handler_seek_bar.removeCallbacks(m_seek_bar_runnable);
super.onPause();
}
Remove all the callbacks from the Handler in onStop using handler.removeCallbacks
I want to implement the ...
#Override
public void onBackPressed() {
}
However, I get an error message saying, "Annotations are not allowed here". I need this method to be implemented here. Is there an alternative?
public class supbreh extends Appbreh
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent_breh);
if (myBundle != null) {
String name = myBundle.getString("workout");
ShowDetails(name);
}
}
private void ShowAbDetails(String mName) {
if(mName.equals("abs1")){
#Override
public void onBackPressed() { //"Not Allowed here"
}
}
void onBackPressed ()
Called when the activity has detected the user's press of the back
key. The default implementation simply finishes the current activity,
but you can override this to do whatever you want.
In here you can't declare this method inside another method .
Only override it in that one Activity
#Override
public void onBackPressed()
{
super.onBackPressed();
}
FYI
#Override
public void onBackPressed() {
Intent intent = new Intent(IndividualAbsWorkout.this, IndividualAbsWorkout.class);
startActivity(intent);
}
You can override onBackPressed as normal and call the method in ShowAbDetails() method like below.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent_breh);
if (myBundle != null) {
String name = myBundle.getString("workout");
ShowDetails(name);
}
}
private void ShowAbDetails(String mName) {
if(mName.equals("abs1")){
onBackPressed();
}
}
#Override
public void onBackPressed() {
// your logic here
}