Pop-Up Window at inital start up, of android application - android

I am trying to find a code that will do a popup at the initial start up on an installed app. Much like a changelog that is starting to appear in more and more apps.
I have found some similar codes, but being a beginner I haven't been able to figure out where to exactly put the code in and I always have tons of errors that still do not work once I try and fix them.
I am working in Eclipse with an android project, and I'm using a webview to show a website.
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_height="fill_parent" android:layout_width="fill_parent" android:scrollbarAlwaysDrawVerticalTrack="false"/>
</LinearLayout>
Java File:
package com.A2Ddesigners.WhatThe;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.KeyEvent;
public class Whatthe extends Activity {
WebView webview;
/** Called when the activity is first created. */
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new HelloWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.setInitialScale(50);
webview.getSettings().setUseWideViewPort(true);
webview.loadUrl("http://mdsitest2.com/");
}
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}

Using My this code you can show popup on any type of view on intial time of activity.
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
public class PopupDispaly extends Activity {
private PopupWindow outComePopup;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tiwter_login);
final View anyView = findViewById(R.id.popo_up); // define heade your view
anyView.postDelayed(new Runnable() {
#Override
public void run() {
callFirstToolTip(anyView);
}
}, 5000); // hear you can put your delay time like 5000 mls
}
public void callFirstToolTip(View view) {
Log.i("Started Info","popup");
View layout = LayoutInflater.from(PopupDispaly.this).inflate(R.layout.popup_copy_delete, null); // define hear your layout file id.
LinearLayout layCopyDelete = (LinearLayout) layout.findViewById(R.id.layCopyDelete);// hear define your id of sub lay like LinearLayout.
outComePopup = new PopupWindow(layout);
outComePopup.setFocusable(true);
layCopyDelete.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
outComePopup.setWidth(layCopyDelete.getMeasuredWidth());
outComePopup.setHeight(layCopyDelete.getMeasuredHeight());
outComePopup.setBackgroundDrawable(getResources().getDrawable(android.R.color.transparent));
outComePopup.setOutsideTouchable(true);
outComePopup.showAsDropDown(view);
}
}
And my Custome View layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/got_it_bg"
android:layout_gravity="center_horizontal"
android:id="#+id/layCopyDelete"
android:layout_marginLeft="100dp"
android:orientation="horizontal">
</LinearLayout>

Sounds like you should use a custom dialog box. http://developer.android.com/guide/topics/ui/dialogs.html
There's a code example at the bottom of the page. To show it, you can call onCreateDialog(int) from inside your main activity in its onCreate() method.

PopupWindow.showAsDropDown() in a delayed process can solve this problem, you can execute the show popupWindow in onCreate() method by 0.5s delay.

You should use PopupWindow.showAtLocation but use the post method of the one of the views on your activity. you can also use the root view of the activity using findViewById(android.R.id.content).
You code should look like this:
View anyView = findViewById(R.id.anyView);
anyView.post(new Runnable()
{
#Override
public void run()
{
// Create and show PopupWindow
}
});

Related

How to make two diffrent Activities to use the same layout Android

Below code works fine, but it opens a new layout and shows the toast message. but i wanted it to show toast & popup menus on the current layout. I'm working on popup menu project, i want to show popup menu on same layout. Thanks in Advance.
MainMactivity.java
package com.example.twoact;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button b1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent openpopactivity = new Intent(MainActivity.this,
MainActivity2.class);
startActivity(openpopactivity);
}
});
}
}
MainActivity2.java
package com.example.twoact;
import android.widget.Toast;
import android.os.Bundle;
import android.os.Handler;
public class MainActivity2 extends MainActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Handler().postDelayed(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "ya am in",
Toast.LENGTH_SHORT).show();
}
}, 1000);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.twoact.MainActivity"
tools:ignore="MergeRootFrame" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="142dp"
android:text="Button" />
</RelativeLayout>
You can use Popup menu and Popup window. in this you can use your custom layout so you can get your view as window in same activity.
Popup window will be good option because it is since API LEVEL 1
please refer this docs and example 1,example 2
And Popup Menu is since API LEVEL 11. so you have to manage for lower version
docs for Popup Menu and example
popup window

youtube output on my app without using a standard browser with webview

I want to put the webversion of youtube in my application where you can do everything(like watch and search videos,..) without using a standard browser. I have written this code but every time pop ups which browser I want to use (like Google chrome,..)but I want to let it display on my appscreen and I have set the permission of internet already.
here the code:
youtube.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
youtube.java:
package com.example.listentomusic;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class Youtube extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.youtube);
WebView wv = (WebView)findViewById(R.id.webView1);
wv.loadUrl("http://www.youtube.com");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
You need to create your CustomWebViewClient & set it to your webView.
Like this -
private class CustomWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
Now set this CustomeWebViewClient to your webView-
WV.setWebViewClient(new CustomWebViewClient());
Also main(String[] args) is of no use, remove it.

how can I display a interactive map in webview?

I am trying to display a interactive map that I have created with imapbuilder. The problem is when i load it in my webview I just get a blank screen. I have tried everything (am just wondering if my device can't handle flash have got sgs2 and Motorola xoom2 10.1in tablet with ICS on both).
Here is my code for XML.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
For my .java;
import android.os.Bundle;
import android.app.Activity;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
public class MainActivity extends Activity {
private Handler mHandler = new Handler();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags
(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
WebView view=(WebView)findViewById(R.id.webview);
view.getSettings().setPluginsEnabled(true);
view.loadUrl("file:///android_asset/Interactive.htm");
view.addJavascriptInterface(new MyJavaScriptInterface(), "Android");
}
final class MyJavaScriptInterface
{
public void ProcessJavaScript(final String scriptname, final String args)
{
mHandler.post(new Runnable()
{
public void run()
{
//Do your activities
}
});
}
}
}
In my assets folder is the Interactive.htm and sub folder with the flash files and stuff exported from the software I used.
So where am I going wrong?
Did you add this permission to your manifest file?
<uses-permission android:name="android.permission.INTERNET" />

Android Webview scroll is misbehaving when loading a flash website

I am opening a simple flash based website in my webview using following code:
Java Code:
package com.sample.webview;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
public class SampleWebViewActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final WebView webView = (WebView) findViewById(R.id.webview);
final ProgressDialog progress = new ProgressDialog(this);
progress.setMessage("loading");
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progress.show();
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progress.dismiss();
}
});
Button mButton = (Button) findViewById(R.id.button);
mButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
webView.loadUrl("http://www.fusioncharts.com/demos/features/#linkedcharts-for-easy-drill-down");
}
});
}
}
Main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Load URL" />
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5dp" />
</LinearLayout>
Now when the page is loaded completely and i am trying to scroll down to view rest of the content, the webview is coming on top of "Load URL" button. Check the screenshot:
while it should look like:
Please suggest, what should i do so that it works correctly.
Edit: I am using a Galaxy Note(OSv2.3.5) with the latest version of both Flash Player and Adobe Air installed.
I have also tried this things but I think the only solution to do this is by using only a single webview in your xml, so, you don't have other native controls.
This is really broken on Android. If you try to use the Build in topbar it will also go behind the flash. I'd really recommend you go away (far away) from flash. There is some discussions about it on google groups and some on stackoverflow but all ends without any good results. The only good suggestion I found was using flash to cover other flash components =/

How to implement click the certain area to do to action?

This is an example of facebook sliding menu.
When sliding, there is 20% space user can see which is similar with facebook. Facebook implements it with clicking anywhere of this 20% and the menu is slide back.
How to implement this?
One way of doing that is as following with OnTouchListener on your activity. You can detect exactly where is touched on the screen.
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;
import android.widget.Toast;
public class AndroidTestActivity extends Activity implements OnTouchListener {
LinearLayout main;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
main = (LinearLayout) findViewById(R.id.main_layout);
main.setOnTouchListener(this); // you need to set the touch listener for your view. And every element around the detection area.
}
public boolean onTouch(View v, MotionEvent e) {
if(e.getX() <= main.getWidth() / 5) {
Toast.makeText(this, "In the %20..", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
}
You also need to id your main layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

Categories

Resources